优化gui
This commit is contained in:
parent
057b9e834d
commit
d591378938
@ -44,6 +44,11 @@ public class JdbcSqlClass {
|
||||
//注册驱动
|
||||
Class.forName(JdbcSqlClass.driver);
|
||||
|
||||
//判断是否因为长时间闲置导致连接丢失
|
||||
if (con.isClosed()){
|
||||
con = DriverManager.getConnection(JdbcSqlClass.url, JdbcSqlClass.user, JdbcSqlClass.password);
|
||||
}
|
||||
|
||||
//获取执行者对象
|
||||
Statement stmt = con.createStatement();
|
||||
|
||||
@ -56,6 +61,7 @@ public class JdbcSqlClass {
|
||||
|
||||
public static void initTable() {
|
||||
try {
|
||||
//此处获取连接并保存
|
||||
con = DriverManager.getConnection(JdbcSqlClass.url, JdbcSqlClass.user, JdbcSqlClass.password);
|
||||
|
||||
Statement connection = getConnection();
|
||||
|
@ -11,6 +11,7 @@ import com.yuyu.srdisassemble.pojo.CanDisItem;
|
||||
import com.yuyu.srdisassemble.pojo.DisProduct;
|
||||
import com.yuyu.srdisassemble.pojo.DisassembleData;
|
||||
import com.yuyu.srdisassemble.utils.MinUtil;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
@ -61,7 +62,8 @@ public class SassembleGuiService extends GermGuiScreen {
|
||||
}
|
||||
|
||||
private void savePauseSlots(){
|
||||
GermGuiScroll scroll = (GermGuiScroll) this.temporarilyBoxScreen.getGuiPart("scroll");
|
||||
GermGuiCanvas canvas = (GermGuiCanvas) this.temporarilyBoxScreen.getGuiPart("canvas");
|
||||
GermGuiScroll scroll = (GermGuiScroll) canvas.getGuiPart("scroll");
|
||||
for (int i = 1; i <= 16 ; i++){
|
||||
String slotName = "slot_"+i;
|
||||
GermGuiSlot slot = (GermGuiSlot) scroll.getGuiPart(slotName);
|
||||
@ -86,13 +88,6 @@ public class SassembleGuiService extends GermGuiScreen {
|
||||
if (germGuiSlot.getItemStack().getType() == Material.AIR){
|
||||
germGuiSlot.setItemStack(item);
|
||||
return;
|
||||
}else {
|
||||
ItemStack itemStack = germGuiSlot.getItemStack();
|
||||
if (itemStack.getAmount() < itemStack.getMaxStackSize() && itemStack.getItemMeta().getDisplayName().equals(item.getItemMeta().getDisplayName())){
|
||||
itemStack.setAmount(itemStack.getAmount()+1);
|
||||
germGuiSlot.setItemStack(itemStack);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -113,16 +108,17 @@ public class SassembleGuiService extends GermGuiScreen {
|
||||
|
||||
public void boolGui(){
|
||||
if (data.getId() != 0 && data.getTargetIndex() != null) {
|
||||
GermGuiSlot disassembleSlot = (GermGuiSlot) this.getGuiPart("disassembleSlot");
|
||||
GermGuiCanvas bgCanvas = (GermGuiCanvas) this.getGuiPart("background");
|
||||
GermGuiSlot disassembleSlot = (GermGuiSlot) bgCanvas.getGuiPart("disassembleSlot");
|
||||
disassembleSlot.setInteract(false);
|
||||
//此处为获取分解的物品的item
|
||||
disassembleSlot.setItemStack(SrItemAPI.getItem(data.getTargetIndex(),
|
||||
new HashMap<>(),null,true,true));
|
||||
|
||||
GermGuiGif fire = (GermGuiGif) this.getGuiPart("fire");
|
||||
GermGuiTexture men1 = (GermGuiTexture) this.getGuiPart("men1");
|
||||
GermGuiTexture doorPause = (GermGuiTexture) this.getGuiPart("doorPause");
|
||||
GermGuiGif door = (GermGuiGif) this.getGuiPart("door");
|
||||
GermGuiGif fire = (GermGuiGif) bgCanvas.getGuiPart("fire");
|
||||
GermGuiTexture men1 = (GermGuiTexture) bgCanvas.getGuiPart("men1");
|
||||
GermGuiTexture doorPause = (GermGuiTexture) bgCanvas.getGuiPart("doorPause");
|
||||
GermGuiGif door = (GermGuiGif) bgCanvas.getGuiPart("door");
|
||||
|
||||
men1.setEnable(false);
|
||||
fire.setEnable(true);
|
||||
@ -135,7 +131,8 @@ public class SassembleGuiService extends GermGuiScreen {
|
||||
if (calculateMinutesDifference <= 0) {
|
||||
//执行语句说明分解完成
|
||||
this.disassembleComplete();
|
||||
if ((boolean)disassembleSlot.getInteract() == true && disassemble){
|
||||
if ((boolean)disassembleSlot.getInteract()){
|
||||
|
||||
JdbcSqlClass.deleteData(data.getId());
|
||||
|
||||
//赋予产物后把火关掉,门打开
|
||||
@ -169,7 +166,8 @@ public class SassembleGuiService extends GermGuiScreen {
|
||||
|
||||
|
||||
public void openPauseBox(){
|
||||
GermGuiButton germGuiButton = (GermGuiButton)this.getGuiPart("pauseBoxButton");
|
||||
GermGuiCanvas bgCanvas = (GermGuiCanvas) this.getGuiPart("background");
|
||||
GermGuiButton germGuiButton = (GermGuiButton)bgCanvas.getGuiPart("pauseBoxButton");
|
||||
germGuiButton.registerCallbackHandler(((player, btn) -> {
|
||||
|
||||
if (this.temporarilyBoxScreen.isOpened()){
|
||||
@ -186,40 +184,42 @@ public class SassembleGuiService extends GermGuiScreen {
|
||||
*/
|
||||
public void registerDisassemble() {
|
||||
//获取画布
|
||||
GermGuiCanvas canvas = (GermGuiCanvas)this.getGuiPart("canvas");
|
||||
GermGuiCanvas bgCanvas = (GermGuiCanvas) this.getGuiPart("background");
|
||||
GermGuiCanvas cCanvas = (GermGuiCanvas) this.getGuiPart("confirmCanvas");
|
||||
//通过画布获取按键
|
||||
GermGuiButton confirmButton = (GermGuiButton) canvas.getGuiPart("confirmButton");
|
||||
GermGuiButton cancleButton = (GermGuiButton) canvas.getGuiPart("cancleButton");
|
||||
GermGuiButton germGuiButton =(GermGuiButton) this.getGuiPart("youhu");
|
||||
GermGuiSlot disassembleSlot = (GermGuiSlot) this.getGuiPart("disassembleSlot");
|
||||
GermGuiButton confirmButton = (GermGuiButton) cCanvas.getGuiPart("confirmButton");
|
||||
GermGuiButton cancleButton = (GermGuiButton) cCanvas.getGuiPart("cancleButton");
|
||||
GermGuiButton germGuiButton =(GermGuiButton) bgCanvas.getGuiPart("youhu");
|
||||
GermGuiSlot disassembleSlot = (GermGuiSlot) bgCanvas.getGuiPart("disassembleSlot");
|
||||
|
||||
confirmButton.registerCallbackHandler((player, btn) -> {
|
||||
this.disassemble(player);
|
||||
canvas.setEnable(false);
|
||||
cCanvas.setEnable(false);
|
||||
},GermGuiButton.EventType.LEFT_CLICK);
|
||||
|
||||
//取消事件
|
||||
cancleButton.registerCallbackHandler((player, btn) -> {
|
||||
//取消事件,关闭画布gui
|
||||
canvas.setEnable(false);
|
||||
cCanvas.setEnable(false);
|
||||
},GermGuiButton.EventType.LEFT_CLICK);
|
||||
|
||||
//油壶按钮绑定的事件触发画布显示
|
||||
germGuiButton.registerCallbackHandler((player, btn) -> {
|
||||
if ((boolean)disassembleSlot.getInteract()) {
|
||||
canvas.setEnable(true);
|
||||
cCanvas.setEnable(true);
|
||||
}
|
||||
},GermGuiButton.EventType.LEFT_CLICK);
|
||||
}
|
||||
|
||||
public void disassemble(Player player){
|
||||
|
||||
GermGuiSlot disassembleSlot = (GermGuiSlot) this.getGuiPart("disassembleSlot");
|
||||
GermGuiCanvas bgCanvas = (GermGuiCanvas) this.getGuiPart("background");
|
||||
GermGuiSlot disassembleSlot = (GermGuiSlot) bgCanvas.getGuiPart("disassembleSlot");
|
||||
if ((boolean)disassembleSlot.getInteract() == false){
|
||||
//正在分解某种物品
|
||||
return;
|
||||
}
|
||||
ItemStack itemStack = disassembleSlot.getItemStack();
|
||||
|
||||
if (itemStack.getType() == Material.AIR || itemStack == null) {
|
||||
player.sendMessage(Color.RED+"在熔炉物品框中放上可分解的物品!");
|
||||
return;
|
||||
@ -235,16 +235,29 @@ public class SassembleGuiService extends GermGuiScreen {
|
||||
return;
|
||||
}
|
||||
disassembleSlot.setInteract(false);//关闭交互
|
||||
|
||||
int amount = itemStack.getAmount();
|
||||
if (amount > 1){
|
||||
ItemStack itemStack1 = itemStack.clone();
|
||||
itemStack1.setAmount(amount - 1);
|
||||
player.getInventory().addItem(itemStack1);
|
||||
player.sendMessage(ChatColor.GREEN+"多余的物品放进背包!");
|
||||
}
|
||||
|
||||
itemStack.setAmount(1);
|
||||
|
||||
disassembleSlot.setItemStack(itemStack);
|
||||
//上方if语句通过表示该物品可以分解
|
||||
//假如启动按钮是油壶,
|
||||
GermGuiGif door = (GermGuiGif) this.getGuiPart("door");
|
||||
GermGuiGif door = (GermGuiGif) bgCanvas.getGuiPart("door");
|
||||
door.setCycle(1);
|
||||
door.setPause(14);
|
||||
if ((boolean)door.getEnable() == true){
|
||||
return;
|
||||
}
|
||||
GermGuiTexture men1 = (GermGuiTexture) this.getGuiPart("men1");
|
||||
GermGuiTexture men1 = (GermGuiTexture) bgCanvas.getGuiPart("men1");
|
||||
men1.setEnable(false);
|
||||
GermGuiGif fire = (GermGuiGif) this.getGuiPart("fire");
|
||||
GermGuiGif fire = (GermGuiGif) bgCanvas.getGuiPart("fire");
|
||||
fire.setEnable(true);
|
||||
door.setEnable(true);
|
||||
this.data = new DisassembleData(player.getName(),
|
||||
@ -262,18 +275,14 @@ public class SassembleGuiService extends GermGuiScreen {
|
||||
|
||||
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
|
||||
|
||||
// executor.schedule(() ->{
|
||||
// //打开暂存箱
|
||||
// temporarilyBoxScreen.openChildGui(playerHost);
|
||||
//
|
||||
// },1,TimeUnit.SECONDS);
|
||||
|
||||
executor.scheduleAtFixedRate(() -> {
|
||||
int calculateMinutesDifference = MinUtil.calculateMinutesDifference(data.getDisassembleTime());
|
||||
if (calculateMinutesDifference <= 0) {
|
||||
//执行语句说明分解完成
|
||||
this.disassembleComplete();
|
||||
if ((boolean)disassembleSlot.getInteract() == true && disassemble){
|
||||
if ((boolean)disassembleSlot.getInteract()){
|
||||
|
||||
JdbcSqlClass.deleteData(data.getId());
|
||||
|
||||
//赋予产物后把火关掉,门打开
|
||||
@ -290,30 +299,14 @@ public class SassembleGuiService extends GermGuiScreen {
|
||||
//1分钟延迟,minTime分钟后执行
|
||||
|
||||
|
||||
|
||||
|
||||
// //此处写分解逻辑
|
||||
// int itemAmount = itemStack.getAmount();
|
||||
// //分解物品返回原胚,理论上是只能单次分解一个然后得到一个。
|
||||
// HashMap<String, DisProduct> stringDisProductHashMap = disProductHashMap.get(itemName);
|
||||
// float v = random.nextFloat();
|
||||
// ItemStack product = null;
|
||||
// for (DisProduct disProduct : stringDisProductHashMap.values()) {
|
||||
// if (disProduct.getProMax() > v && disProduct.getProMin() <= v){
|
||||
// product = SrItemAPI.getItem(disProduct.getIndexName(),new HashMap<>(),null,true,true);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// disassembleSlot.setInteract(true);
|
||||
// //赋予产物
|
||||
// disassembleSlot.setItemStack(product);
|
||||
}
|
||||
|
||||
/**
|
||||
* 此方法用于获取产物
|
||||
*/
|
||||
public void disassembleComplete(){
|
||||
GermGuiSlot disassembleSlot = (GermGuiSlot) this.getGuiPart("disassembleSlot");
|
||||
GermGuiCanvas bgCanvas = (GermGuiCanvas) this.getGuiPart("background");
|
||||
GermGuiSlot disassembleSlot = (GermGuiSlot) bgCanvas.getGuiPart("disassembleSlot");
|
||||
ItemStack itemStack = disassembleSlot.getItemStack();
|
||||
//此处写分解逻辑
|
||||
int itemAmount = itemStack.getAmount();
|
||||
|
Loading…
x
Reference in New Issue
Block a user