基本完成版版

This commit is contained in:
yuyu 2024-06-30 20:08:20 +08:00
parent d2dff8b7b4
commit 057b9e834d
2 changed files with 55 additions and 10 deletions

2
.idea/dataSources.xml generated
View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="@localhost" uuid="b791558a-98e8-4d1c-99ea-dec1bcf43726">
<data-source source="LOCAL" name="@localhost" uuid="278268e3-ebca-4a7f-8f37-e28ccf9cb0d6">
<driver-ref>mysql.8</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>

View File

@ -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<GermGuiSlot> 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的所有物品槽并且返回到玩家背包中