diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml index 269d90a..8c16e42 100644 --- a/.idea/dataSources.xml +++ b/.idea/dataSources.xml @@ -1,7 +1,7 @@ - + mysql.8 true com.mysql.cj.jdbc.Driver diff --git a/src/main/java/com/yuyu/srdisassemble/disassemeble/SassembleGuiService.java b/src/main/java/com/yuyu/srdisassemble/disassemeble/SassembleGuiService.java index d3f55d1..82c5413 100644 --- a/src/main/java/com/yuyu/srdisassemble/disassemeble/SassembleGuiService.java +++ b/src/main/java/com/yuyu/srdisassemble/disassemeble/SassembleGuiService.java @@ -17,6 +17,7 @@ import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Random; @@ -38,6 +39,7 @@ public class SassembleGuiService extends GermGuiScreen { private boolean disassemble = true; private Player playerHost; private GermGuiScreen temporarilyBoxScreen; + private List guiSlots = new ArrayList<>(); public SassembleGuiService(ConfigurationSection configurationSection, String guiName,Player playerHost) { super(guiName, configurationSection); @@ -48,6 +50,8 @@ public class SassembleGuiService extends GermGuiScreen { this.name = playerHost.getName(); this.getTemporarilyBox(); this.boolGui(); + this.savePauseSlots(); + this.openPauseBox(); this.setClosedHandler(((player, germGuiScreen) -> { //窗口关闭事件 this.returnItemStacks(player); @@ -56,6 +60,15 @@ public class SassembleGuiService extends GermGuiScreen { })); } + private void savePauseSlots(){ + GermGuiScroll scroll = (GermGuiScroll) this.temporarilyBoxScreen.getGuiPart("scroll"); + for (int i = 1; i <= 16 ; i++){ + String slotName = "slot_"+i; + GermGuiSlot slot = (GermGuiSlot) scroll.getGuiPart(slotName); + this.guiSlots.add(slot); + } + } + /** * 获取暂存箱对象 */ @@ -67,6 +80,23 @@ public class SassembleGuiService extends GermGuiScreen { } } + synchronized public void setItemToPauseBox(ItemStack item){ + for (int i = 0; i <= 15 ; i++){ + GermGuiSlot germGuiSlot = guiSlots.get(i); + 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; + } + } + } + } + /** * 用于关闭暂存箱 */ @@ -85,6 +115,7 @@ public class SassembleGuiService extends GermGuiScreen { if (data.getId() != 0 && data.getTargetIndex() != null) { GermGuiSlot disassembleSlot = (GermGuiSlot) this.getGuiPart("disassembleSlot"); disassembleSlot.setInteract(false); + //此处为获取分解的物品的item disassembleSlot.setItemStack(SrItemAPI.getItem(data.getTargetIndex(), new HashMap<>(),null,true,true)); @@ -99,12 +130,6 @@ public class SassembleGuiService extends GermGuiScreen { ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); - -// executor.schedule(() ->{ -// //打开暂存箱 -// temporarilyBoxScreen.openChildGui(playerHost); -// -// },100,TimeUnit.MILLISECONDS); executor.scheduleAtFixedRate(() -> { int calculateMinutesDifference = MinUtil.calculateMinutesDifference(data.getDisassembleTime()); if (calculateMinutesDifference <= 0) { @@ -127,9 +152,10 @@ public class SassembleGuiService extends GermGuiScreen { },0, 1 , TimeUnit.MINUTES); //0延迟,minTime分钟后执行 - }else { - this.openTemporarilyBox(); } +// else { +// this.openTemporarilyBox(); +// } } @@ -141,6 +167,20 @@ public class SassembleGuiService extends GermGuiScreen { } + + public void openPauseBox(){ + GermGuiButton germGuiButton = (GermGuiButton)this.getGuiPart("pauseBoxButton"); + germGuiButton.registerCallbackHandler(((player, btn) -> { + + if (this.temporarilyBoxScreen.isOpened()){ + this.temporarilyBoxScreen.close(); + }else { + this.temporarilyBoxScreen.openChildGui(this.playerHost); + } + + }),GermGuiButton.EventType.LEFT_CLICK); + } + /** * 注册分解事件 */ @@ -296,7 +336,12 @@ public class SassembleGuiService extends GermGuiScreen { } disassembleSlot.setInteract(true); //赋予产物 - disassembleSlot.setItemStack(product); +// disassembleSlot.setItemStack(product); + //物品框置空,产物放在暂存箱中 + disassembleSlot.setItemStack(null); + this.setItemToPauseBox(product); +// GermGuiScroll germGuiScroll = (GermGuiScroll) this.temporarilyBoxScreen.getGuiPart("scroll"); + } //遍历gui的所有物品槽,并且返回到玩家背包中