优化gui

This commit is contained in:
yuyu 2024-08-09 14:32:11 +08:00
parent 90f2ee3cf5
commit 747789a3c4
6 changed files with 99 additions and 50 deletions

5
.idea/compiler.xml generated
View File

@ -11,4 +11,9 @@
</profile>
</annotationProcessing>
</component>
<component name="JavacSettings">
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
<module name="SrAppraise" options="-extdirs lib" />
</option>
</component>
</project>

11
pom.xml
View File

@ -18,6 +18,17 @@
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
<compilerArguments>
<extdirs>lib</extdirs><!--指定外部lib-->
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>

View File

@ -9,6 +9,7 @@ import com.yuyu.srappraise.pojo.AppraiseProduct;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
@ -34,12 +35,14 @@ public class AppraiseGuiService extends GermGuiScreen {
private HashMap<String,GermGuiSlot> germGuiSlotHashMap;
private List<ItemStack> itemStackHashMap;
private int index;
Random random;
public AppraiseGuiService(ConfigurationSection configurationSection, String guiName) {
super(guiName, configurationSection);
this.index = 0;
this.germGuiSlotHashMap = new HashMap<>();
this.itemStackHashMap = new ArrayList<>();
this.random = new Random();
// //TODO(此处绑定给 按钮绑定一个监听事件在监听事件中获取放入了物品槽位的物品然后鉴定)
this.getSoltGui();
this.soltRegister();
@ -311,7 +314,7 @@ public class AppraiseGuiService extends GermGuiScreen {
}
Random random = new Random();
HashMap<String,ItemStack> itemStacks= new LinkedHashMap<>();
//获取物品槽
GermGuiSlot slot_biomass = this.germGuiSlotHashMap.get("slotConsume");
@ -353,27 +356,36 @@ public class AppraiseGuiService extends GermGuiScreen {
HashMap<String, AppraiseProduct> stringAppraiseProductHashMap =
SrAppraise.getConfigManager().getAppraiseItemMap().get(itemName);
int countInt = SrAppraise.getConfigManager().getCountInt().get(itemName);
//如果同时鉴定多个
for (int i = 0; i < amount.get(); i++) {
//利用Random生成一个随机数来确定产物
float probility = random.nextFloat();
for (String product : stringAppraiseProductHashMap.keySet()) {
AppraiseProduct appraiseProduct = stringAppraiseProductHashMap.get(product);
if (probility >= appraiseProduct.getProMin() && probility < appraiseProduct.getProMax()) {
//概率通过获取该产物 TODO(此处注意appraiseProduct对象中的产物只能用来展示鉴定不能做出任何修改)
ItemStack item =
SrItemAPI.getItem(appraiseProduct.getIndexName(),new HashMap<>(),null,true,true);
//获取产物后将产物StringItemStack K-V 的形式存到map中
if (itemStacks.containsKey(product)) {
ItemStack itemStack1 = itemStacks.get(product);
itemStack1.setAmount(itemStack1.getAmount() + 1);
break;
}else {
itemStacks.put(product, item);
break;
}
}
// float probility = random.nextFloat();
// for (String product : stringAppraiseProductHashMap.keySet()) {
// AppraiseProduct appraiseProduct = stringAppraiseProductHashMap.get(product);
// if (probility >= appraiseProduct.getProMin() && probility < appraiseProduct.getProMax()) {
// //概率通过获取该产物 TODO(此处注意appraiseProduct对象中的产物只能用来展示鉴定不能做出任何修改)
// ItemStack item =
// SrItemAPI.getItem(appraiseProduct.getIndexName(),new HashMap<>(),null,true,true);
// //获取产物后将产物StringItemStack K-V 的形式存到map中
// if (itemStacks.containsKey(product)) {
// ItemStack itemStack1 = itemStacks.get(product);
// itemStack1.setAmount(itemStack1.getAmount() + 1);
// break;
// }else {
// itemStacks.put(product, item);
// break;
// }
// }
// }
String index1 = getIndex(itemName, countInt, stringAppraiseProductHashMap);
ItemStack item = SrItemAPI.getItem(index1, new HashMap<>(), clickPlayer, true, true);
if (itemStacks.containsKey(index1)) {
ItemStack itemStack1 = itemStacks.get(index1);
itemStack1.setAmount(itemStack1.getAmount()+1);
}else {
itemStacks.put(index1,item);
}
}
@ -444,4 +456,22 @@ public class AppraiseGuiService extends GermGuiScreen {
}, GermGuiButton.EventType.LEFT_CLICK);
}
public String getIndex(String itemName,int countInt, HashMap<String, AppraiseProduct> productS){
if (itemName == null || countInt == 0 || productS == null || productS.size() == 0){
SrAppraise.getInstance().getLogger().info(ChatColor.RED+"itemName|countInt|productS==null");
return null;
}
int rand = random.nextInt(countInt) + 1;
int start = 0;
//循环确定权重位置
for (String s : productS.keySet()){
AppraiseProduct appraiseProduct = productS.get(s);
if (rand >= start && rand <= start+appraiseProduct.getWeight()){
return appraiseProduct.getIndexName();
}
start += appraiseProduct.getWeight();
}
return null;
}
}

View File

@ -25,6 +25,7 @@ import java.util.logging.Logger;
public class ConfigManager {
//用于存放鉴定的物品,根据玩家放入的物品获取名称用于此map集合获取可能得到的物品集合然后随机数判断
private HashMap<String,HashMap<String, AppraiseProduct>> appraiseItemMap;
private HashMap<String,Integer> countInt;
private Plugin plugin;
public HashMap<String, HashMap<String, AppraiseProduct>> getAppraiseItemMap() {
@ -34,6 +35,7 @@ public class ConfigManager {
public ConfigManager(Plugin plugin) {
Logger logger = plugin.getLogger();
this.plugin = plugin;
this.countInt = new HashMap<>();
HashMap<String,HashMap<String, AppraiseProduct>> hashMapHashMap = new HashMap<>();
@ -59,21 +61,20 @@ public class ConfigManager {
//读取该物品可以得到的产物
List<String> productList = appraiseToProduct.getStringList("SrItem." + srItem);
int count = 0;
for (String product : productList){
//读取配置文件中的数据
Double proMax = itemAppraiseProduct.getDouble("SrItem."+srItem+"."+product+".probabilityMax");
Double proMin = itemAppraiseProduct.getDouble("SrItem."+srItem+"."+product+".probabilityMin");
int weight = itemAppraiseProduct.getInt("SrItem."+srItem+"."+product+".weight");
String index = itemAppraiseProduct.getString("SrItem."+srItem+"."+product+".index");
AppraiseProduct appraiseProduct = new AppraiseProduct(product, index, proMax, proMin);
AppraiseProduct appraiseProduct = new AppraiseProduct(product, index, weight);
count+=weight;
logger.info(ChatColor.AQUA+"鉴定物品:"+srItem+"产物:"+ appraiseProduct.toString());
//针对产物存放
productMap.put(product,appraiseProduct);
}
countInt.put(srItem,count);
//针对鉴定物品存放
hashMapHashMap.put(srItem,productMap);
}
@ -83,7 +84,7 @@ public class ConfigManager {
public void reloadConfig(){
appraiseItemMap.clear();
countInt.clear();
plugin.reloadConfig();
HashMap<String,HashMap<String, AppraiseProduct>> hashMapHashMap = new HashMap<>();
@ -110,25 +111,36 @@ public class ConfigManager {
//读取该物品可以得到的产物
List<String> productList = appraiseToProduct.getStringList("SrItem." + srItem);
int count = 0;
for (String product : productList){
//读取配置文件中的数据
Double proMax = itemAppraiseProduct.getDouble("SrItem."+srItem+"."+product+".probabilityMax");
Double proMin = itemAppraiseProduct.getDouble("SrItem."+srItem+"."+product+".probabilityMin");
int weight = itemAppraiseProduct.getInt("SrItem."+srItem+"."+product+".weight");
String index = itemAppraiseProduct.getString("SrItem."+srItem+"."+product+".index");
AppraiseProduct appraiseProduct = new AppraiseProduct(product, index, proMax, proMin);
AppraiseProduct appraiseProduct = new AppraiseProduct(product, index, weight);
this.plugin.getLogger().info(ChatColor.AQUA+"鉴定物品:"+srItem+"产物:"+ appraiseProduct.toString());
count+=weight;
//针对产物存放
productMap.put(product,appraiseProduct);
}
this.countInt.put(srItem,count);
//针对鉴定物品存放
hashMapHashMap.put(srItem,productMap);
}
this.appraiseItemMap = hashMapHashMap;
}
public void setAppraiseItemMap(HashMap<String, HashMap<String, AppraiseProduct>> appraiseItemMap) {
this.appraiseItemMap = appraiseItemMap;
}
public HashMap<String, Integer> getCountInt() {
return countInt;
}
public void setCountInt(HashMap<String, Integer> countInt) {
this.countInt = countInt;
}
}

View File

@ -19,10 +19,9 @@ public class AppraiseProduct {
private final String ItemName;
//物品的索引
private final String indexName;
//最大的概率
private final double ProMax;
//最小的概率
private final double ProMin;
//权重
private final int weight;
//获取ItemStack
private final ItemStack itemStack;
@ -34,19 +33,14 @@ public class AppraiseProduct {
return indexName;
}
public double getProMax() {
return ProMax;
public int getWeight() {
return weight;
}
public double getProMin() {
return ProMin;
}
public AppraiseProduct(String itemName, String indexName, double proMax, double proMin) {
public AppraiseProduct(String itemName, String indexName, int weight) {
ItemName = itemName;
this.indexName = indexName;
ProMax = proMax;
ProMin = proMin;
this.weight = weight;
this.itemStack = SrItemAPI.getItem(indexName,new HashMap<>(),null,true,true);
}
@ -59,8 +53,7 @@ public class AppraiseProduct {
return "AppraiseProduct{" +
"ItemName='" + ItemName + '\'' +
", indexName='" + indexName + '\'' +
", ProMax=" + ProMax +
", ProMin=" + ProMin +
",weight=" + weight +
", itemStack=" + itemStack +
'}';
}

View File

@ -1,10 +1,8 @@
SrItem:
巴尔伐楼伽的怨牙: #这一行填可以鉴定的物品
环齿原胚: #这下面填鉴定物品可以得到的结果
probabilityMax: 0.4 #概率,相当于一个转盘,多少到多少是这个产物,必定会有结果,比如[0,0.4],左闭右开的范围区间若随机到0则为此产物,0.4则跳过
probabilityMin: 0 #概率,相当于一个转盘,多少到多少是这个产物,必定会有结果,比如[0,0.4],左闭右开的范围区间若随机到0则为此产物,0.4则跳过
weight: 20 #概率,相当于一个转盘,多少到多少是这个产物,必定会有结果,比如[0,0.4],左闭右开的范围区间若随机到0则为此产物,0.4则跳过
index: public.material.巴尔伐楼伽的怨牙 #这里填材料的索引名
保密试作品HC-03原胚: #这下面填鉴定物品可以得到的结果
probabilityMax: 1 #概率
probabilityMin: 0.4 #概率
weight: 10
index: public.test.保密试作品HC-03原胚 #这里填材料的索引名