diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 0fc14d86..448669eb 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -567,6 +567,7 @@ SIMULATOR_GUI_TNT_GROUP_LORE_5 = §7y§8: §e{0} SIMULATOR_GUI_TNT_GROUP_LORE_6 = §7z§8: §e{0} SIMULATOR_GUI_TNT_DISABLED = §cDisabled SIMULATOR_GUI_NAME = Simulator +SIMULATOR_GUI_DELETE = §cDelete TNT SIMULATOR_GUI_START = §eStart SIMULATOR_GUI_AUTO_TRACE = §eAutoTrace§8: §7{0} SIMULATOR_GUI_MOVE_ALL = §eMove all diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index ace25e83..c2e2373a 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -558,6 +558,7 @@ SIMULATOR_GUI_TNT_GROUP_NAME = §eTNT Gruppe SIMULATOR_GUI_TNT_GROUP_LORE_1 = §7Elementanzahl§8: §e{0} SIMULATOR_GUI_TNT_DISABLED = §cDisabled SIMULATOR_GUI_NAME = Kanonensimulator +SIMULATOR_GUI_DELETE = §cTNT löschen SIMULATOR_GUI_START = §eStarten SIMULATOR_GUI_AUTO_TRACE = §eAutoTrace§8: §7{0} SIMULATOR_GUI_MOVE_ALL = §eAlle Verschieben diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java index c2b37750..c660e0b4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java @@ -156,12 +156,14 @@ public class TNTSimulator { return tntSpawns; } - public void remove(TNTElement tntElement) { - hide(tntElement); - tntElementList.remove(tntElement); + public void remove(SimulatorElement element) { + hide(element); + tntElementList.remove(element); Set toRemove = new HashSet<>(); for (SimulatorElement spawn : tntElementList) { - spawn.remove(tntElement); + if (element instanceof TNTElement) { + spawn.remove((TNTElement) element); + } if (spawn instanceof TNTGroup) { if (((TNTGroup) spawn).getElements().isEmpty()) { toRemove.add(spawn); @@ -170,7 +172,7 @@ public class TNTSimulator { } } tntElementList.removeAll(toRemove); - tntElement.close(); + element.close(); } public void change() { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTElementGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTElementGUI.java index 3bcb9271..3772e458 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTElementGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTElementGUI.java @@ -321,6 +321,9 @@ public class TNTElementGUI { tntGroup.add(newElement); tntElement.change(); + open(player, newElement, () -> TNTSimulatorGui.open(player, null, tntGroup, () -> new ArrayList<>(tntGroup.getElements()), () -> { + TNTSimulatorGui.open(player, tntSimulator, null, () -> new ArrayList<>(tntSimulator.getTntElementList()), null); + })); })); } else { inv.setItem(24, new SWItem()); @@ -332,8 +335,12 @@ public class TNTElementGUI { if (tntElement.hasParent()) { newElement.setTickOffset(tntElement.getOwnTickOffset() + 1); tntElement.getParent().add(newElement); + open(player, newElement, () -> TNTSimulatorGui.open(player, null, tntElement.getParent(), () -> new ArrayList<>(tntElement.getParent().getElements()), () -> { + TNTSimulatorGui.open(player, tntSimulator, null, () -> new ArrayList<>(tntSimulator.getTntElementList()), null); + })); } else { tntSimulator.getTntElementList().add(newElement); + open(player, newElement, () -> TNTSimulatorGui.open(player, tntSimulator, null, tntSimulator::getTntElementList, null)); } })); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTSimulatorGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTSimulatorGui.java index 4f965418..a9e53d3f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTSimulatorGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTSimulatorGui.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem.features.simulator.gui; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.configplayer.Config; +import de.steamwar.bausystem.features.simulator.SimulatorStorage; import de.steamwar.bausystem.features.simulator.TNTSimulator; import de.steamwar.bausystem.features.simulator.tnt.SimulatorElement; import de.steamwar.bausystem.features.simulator.tnt.TNTElement; @@ -70,17 +71,22 @@ public class TNTSimulatorGui { inv.setItem(47, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("SIMULATOR_BACK", player), clickType -> back.run())); } if (currentTntSimulator != null) { - inv.setItem(50, new SWItem(Material.MAGENTA_GLAZED_TERRACOTTA, BauSystem.MESSAGE.parse("SIMULATOR_GUI_MOVE_ALL", player), clickType -> { - moveAll(player, currentTntSimulator, () -> open(player, currentTntSimulator, currentTntGroup, simulatorElements, back)); - })); + if (totalTNTCount > 0) { + inv.setItem(48, new SWItem(Material.MAGENTA_GLAZED_TERRACOTTA, BauSystem.MESSAGE.parse("SIMULATOR_GUI_MOVE_ALL", player), clickType -> { + moveAll(player, currentTntSimulator, () -> open(player, currentTntSimulator, currentTntGroup, simulatorElements, back)); + })); + } boolean simulatorAutoTrace = Config.getInstance().get(player).getPlainValueOrDefault("simulatorAutoTrace", false); - inv.setItem(48, new SWItem(simulatorAutoTrace ? Material.CHAIN_COMMAND_BLOCK : Material.COMMAND_BLOCK, BauSystem.MESSAGE.parse("SIMULATOR_GUI_AUTO_TRACE", player, simulatorAutoTrace), clickType -> { + inv.setItem(47, new SWItem(simulatorAutoTrace ? Material.CHAIN_COMMAND_BLOCK : Material.COMMAND_BLOCK, BauSystem.MESSAGE.parse("SIMULATOR_GUI_AUTO_TRACE", player, simulatorAutoTrace), clickType -> { Config.getInstance().get(player).put("simulatorAutoTrace", !simulatorAutoTrace); open(player, currentTntSimulator, currentTntGroup, simulatorElements, back); })); } - inv.setItem(49, new SWItem(Material.TNT_MINECART, BauSystem.MESSAGE.parse("SIMULATOR_GUI_TOTAL_TNT", player, totalTNTCount), clickType -> {})); + SWItem swItem = new SWItem(Material.TNT_MINECART, BauSystem.MESSAGE.parse("SIMULATOR_GUI_TOTAL_TNT", player, totalTNTCount), clickType -> { + }); + swItem.getItemStack().setAmount(totalTNTCount); + inv.setItem(currentTntSimulator != null || currentTntGroup != null ? 50 : 49, swItem); if (currentTntGroup != null) { Runnable editObserver = () -> { List otherLore = new ArrayList<>(); @@ -96,7 +102,7 @@ public class TNTSimulatorGui { otherLore.add(""); otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_DISABLED", player)); } - inv.setItem(51, new SWItem(Material.ANVIL, BauSystem.MESSAGE.parse("SIMULATOR_EDIT_GROUP", player), otherLore, false, clickType -> { + inv.setItem(48, new SWItem(Material.ANVIL, BauSystem.MESSAGE.parse("SIMULATOR_EDIT_GROUP", player), otherLore, false, clickType -> { TNTGroupEditGUI.open(player, currentTntGroup, () -> open(player, currentTntSimulator, currentTntGroup, simulatorElements, back)); })); }; @@ -105,6 +111,20 @@ public class TNTSimulatorGui { inv.addCloseRunnable(() -> currentTntGroup.unregister(editObserver)); } + if (currentTntSimulator != null || currentTntGroup != null) { + inv.setItem(51, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("SIMULATOR_GUI_DELETE", player), clickType -> { + if (currentTntSimulator != null) { + currentTntSimulator.hide(); + currentTntSimulator.getTntElementList().forEach(SimulatorElement::close); + currentTntSimulator.getTntElementList().clear(); + player.closeInventory(); + } else { + TNTSimulator tntSimulator = SimulatorStorage.getSimulator(player.getInventory().getItemInMainHand()); + tntSimulator.remove(currentTntGroup); + } + })); + } + inv.open(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/SimulatorElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/SimulatorElement.java index f96fbda9..02692209 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/SimulatorElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/SimulatorElement.java @@ -78,6 +78,9 @@ public interface SimulatorElement { if (closeRunnable == null) return; closeRunnable.run(); }); + if (this instanceof TNTGroup) { + ((TNTGroup) this).getElements().forEach(SimulatorElement::close); + } } // API diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTElement.java index fe98d61d..dd5ff1d4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTElement.java @@ -165,7 +165,9 @@ public class TNTElement implements SimulatorElement { lore.add(""); lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_DISABLED", p)); } - return new SWItem(material, BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_SPAWN_NAME", p), lore, disabled, null); + SWItem swItem = new SWItem(material, BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_SPAWN_NAME", p), lore, disabled, null); + if (!disabled) swItem.getItemStack().setAmount(tntCount()); + return swItem; } @Override diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTGroup.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTGroup.java index d1d765ee..2951c1fb 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTGroup.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTGroup.java @@ -135,7 +135,9 @@ public class TNTGroup implements SimulatorElement { lore.add(""); lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_DISABLED", p)); } - return new SWItem(material, BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_GROUP_NAME", p), lore, disabled, null); + SWItem swItem = new SWItem(material, BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_GROUP_NAME", p), lore, disabled, null); + if (!disabled) swItem.getItemStack().setAmount(tntCount()); + return swItem; } @Override