From 327dded73b8d000fe62d291a4e9eb26232392aec Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 22 Oct 2023 13:24:50 +0200 Subject: [PATCH] Consolidate Item Generation Fix Back arrow in element gui --- .../features/simulator2/data/Simulator.java | 7 +++ .../simulator2/data/SimulatorElement.java | 18 ++++++ .../simulator2/data/SimulatorGroup.java | 18 ++++++ .../gui/SimulatorGroupChooserGui.java | 61 ++++--------------- .../simulator2/gui/SimulatorGroupGui.java | 29 ++------- .../gui/SimulatorGroupSettingsGui.java | 13 +--- .../features/simulator2/gui/SimulatorGui.java | 47 +++----------- .../simulator2/gui/SimulatorRedstoneGui.java | 41 +++++++------ .../SimulatorRedstonePhaseSettingsGui.java | 2 +- .../gui/SimulatorRedstoneSettingsGui.java | 9 +-- .../simulator2/gui/SimulatorSettingsGui.java | 2 +- .../simulator2/gui/SimulatorTNTGui.java | 34 ++++++----- .../gui/SimulatorTNTPhaseSettingsGui.java | 2 +- .../gui/SimulatorTNTSettingsGui.java | 2 +- 14 files changed, 120 insertions(+), 165 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/Simulator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/Simulator.java index a856a54a..df486e6c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/Simulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/Simulator.java @@ -19,10 +19,13 @@ package de.steamwar.bausystem.features.simulator2.data; +import de.steamwar.inventory.InvCallback; +import de.steamwar.inventory.SWItem; import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; import org.bukkit.Material; +import org.bukkit.entity.Player; import java.util.ArrayList; import java.util.List; @@ -41,4 +44,8 @@ public class Simulator { simulatorGroup.move(x, y, z); }); } + + public SWItem toItem(Player player, InvCallback invCallback) { + return new SWItem(material, "§e" + name, invCallback); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java index 59e39852..3a5cf861 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java @@ -19,9 +19,12 @@ package de.steamwar.bausystem.features.simulator2.data; +import de.steamwar.inventory.InvCallback; +import de.steamwar.inventory.SWItem; import lombok.Getter; import lombok.Setter; import org.bukkit.Material; +import org.bukkit.entity.Player; import org.bukkit.util.Vector; import java.util.ArrayList; @@ -70,4 +73,19 @@ public abstract class SimulatorElement { position.setY(position.getY() + y); position.setZ(position.getZ() + z); } + + public SWItem toItem(Player player, InvCallback invCallback) { + List lore = new ArrayList<>(); + lore.add("§7Phase count§8:§e " + phases.size()); + lore.add("§7Tick§8:§e " + getBaseTick()); + lore.add(""); + lore.add("§7X§8:§e " + position.getX()); + lore.add("§7Y§8:§e " + position.getY()); + lore.add("§7Z§8:§e " + position.getZ()); + if (disabled) { + lore.add(""); + lore.add("§cDisabled"); + } + return new SWItem(material, "§e" + getName(), lore, disabled, invCallback); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java index db52d1c3..86bcba99 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java @@ -19,9 +19,12 @@ package de.steamwar.bausystem.features.simulator2.data; +import de.steamwar.inventory.InvCallback; +import de.steamwar.inventory.SWItem; import lombok.Getter; import lombok.Setter; import org.bukkit.Material; +import org.bukkit.entity.Player; import java.util.ArrayList; import java.util.Comparator; @@ -61,4 +64,19 @@ public class SimulatorGroup { simulatorElement.move(x, y, z); }); } + + public SWItem toItem(Player player, InvCallback groupCallback, InvCallback itemCallback) { + if (elements.size() == 1) { + return elements.get(0).toItem(player, itemCallback); + } else { + List lore = new ArrayList<>(); + lore.add("§7Element count§8:§e " + elements.size()); + lore.add("§7Tick§8:§e " + getBaseTick()); + if (disabled) { + lore.add(""); + lore.add("§cDisabled"); + } + return new SWItem(material, "§eGroup", lore, disabled, groupCallback); + } + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupChooserGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupChooserGui.java index 3a2e78f7..8cecb246 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupChooserGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupChooserGui.java @@ -23,17 +23,14 @@ import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; import de.steamwar.bausystem.features.simulator2.data.Simulator; import de.steamwar.bausystem.features.simulator2.data.SimulatorElement; import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup; -import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement; -import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorPageGui; -import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui; +import de.steamwar.inventory.InvCallback; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; -import java.util.ArrayList; -import java.util.List; +import java.util.stream.Collectors; public class SimulatorGroupChooserGui extends SimulatorPageGui { @@ -41,8 +38,8 @@ public class SimulatorGroupChooserGui extends SimulatorPageGui { private final SimulatorGroup parent; private final SimulatorBaseGui back; - public SimulatorGroupChooserGui(Player player, Simulator simulator, List data, SimulatorElement subject, SimulatorGroup parent, SimulatorBaseGui back){ - super(player, simulator, 6*9, data); + public SimulatorGroupChooserGui(Player player, Simulator simulator, SimulatorElement subject, SimulatorGroup parent, SimulatorBaseGui back) { + super(player, simulator, 6 * 9, simulator.getElements().stream().filter(e -> e != parent).collect(Collectors.toList())); this.subject = subject; this.parent = parent; this.back = back; @@ -50,11 +47,10 @@ public class SimulatorGroupChooserGui extends SimulatorPageGui { @Override public void headerAndFooter() { - simulator.getElements().removeIf(element -> element.getElements().isEmpty()); - - inventory.setItem(4, new SWItem(simulator.getMaterial(), "§e" + simulator.getName(), clickType -> {})); - if(parent.getElements().size() != 1){ - inventory.setItem(49 , new SWItem(Material.BARRIER, "§c Remove from Group", clickType -> { + inventory.setItem(4, new SWItem(simulator.getMaterial(), "§e" + simulator.getName(), clickType -> { + })); + if (parent.getElements().size() != 1) { + inventory.setItem(49, new SWItem(Material.BARRIER, "§cRemove from Group", clickType -> { SimulatorGroup newParent = new SimulatorGroup(); newParent.add(subject); simulator.getElements().add(newParent); @@ -63,51 +59,20 @@ public class SimulatorGroupChooserGui extends SimulatorPageGui { })); } } + @Override public String baseTitle() { - return "§eChoose group to add to or element, to create new group"; + return "Choose Group"; } @Override public SWItem convert(SimulatorGroup simulatorGroup) { - List> elements = simulatorGroup.getElements(); - if (elements.size() == 1) { - SimulatorElement element = elements.get(0); - List lore = new ArrayList<>(); - lore.add("§7Phase count§8:§e " + element.getPhases().size()); - lore.add("§7Tick§8:§e " + element.getBaseTick()); - lore.add(""); - lore.add("§7X§8:§e " + element.getPosition().getX()); - lore.add("§7Y§8:§e " + element.getPosition().getY()); - lore.add("§7Z§8:§e " + element.getPosition().getZ()); - if (element.isDisabled()) { - lore.add(""); - lore.add("§cDisabled"); - } - return new SWItem(element.getMaterial(), "§e" + element.getName(), lore, element.isDisabled(), clickType -> { - SimulatorGroup newParent = new SimulatorGroup(); - newParent.add(subject); - newParent.add(element); - simulatorGroup.getElements().remove(element); - parent.getElements().remove(subject); - simulator.getElements().add(newParent); - back.open(); - SimulatorWatcher.update(simulator); - }); - } - - List lore = new ArrayList<>(); - lore.add("§7Element count§8:§e " + elements.size()); - lore.add("§7Tick§8:§e " + simulatorGroup.getBaseTick()); - if (simulatorGroup.isDisabled()) { - lore.add(""); - lore.add("§cDisabled"); - } - return new SWItem(simulatorGroup.getMaterial(), "§eGroup", lore, simulatorGroup.isDisabled(), clickType -> { + InvCallback invCallback = clickType -> { simulatorGroup.add(subject); parent.getElements().remove(subject); back.open(); SimulatorWatcher.update(simulator); - }); + }; + return simulatorGroup.toItem(player, invCallback, invCallback); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java index 47dc1586..23a2354c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java @@ -32,10 +32,7 @@ import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; -import java.util.ArrayList; -import java.util.List; - -public class SimulatorGroupGui extends SimulatorPageGui> { //TODO Disolve group option ? +public class SimulatorGroupGui extends SimulatorPageGui> { private final SimulatorGroup simulatorGroup; private final SimulatorBaseGui back; @@ -64,16 +61,9 @@ public class SimulatorGroupGui extends SimulatorPageGui> { / back.open(); })); - List lore = new ArrayList<>(); - lore.add("§7Element count§8:§e " + data.size()); - lore.add("§7Tick§8:§e " + simulatorGroup.getBaseTick()); - if (simulatorGroup.isDisabled()) { - lore.add(""); - lore.add("§cDisabled"); - } - inventory.setItem(4, new SWItem(simulatorGroup.getMaterial(), "§eGroup", lore, simulatorGroup.isDisabled(), clickType -> { + inventory.setItem(4, simulatorGroup.toItem(player, clickType -> { new SimulatorMaterialGui(player, simulator, simulatorGroup::getMaterial, simulatorGroup::setMaterial, this).open(); - })); + }, clickType -> {})); inventory.setItem(48, new SWItem(Material.REPEATER, "§eSettings", clickType -> { new SimulatorGroupSettingsGui(player, simulator, simulatorGroup, this).open(); @@ -86,18 +76,7 @@ public class SimulatorGroupGui extends SimulatorPageGui> { / @Override public SWItem convert(SimulatorElement element) { - List lore = new ArrayList<>(); - lore.add("§7Phase count§8:§e " + element.getPhases().size()); - lore.add("§7Tick§8:§e " + element.getBaseTick()); - lore.add(""); - lore.add("§7X§8:§e " + element.getPosition().getX()); - lore.add("§7Y§8:§e " + element.getPosition().getY()); - lore.add("§7Z§8:§e " + element.getPosition().getZ()); - if (element.isDisabled()) { - lore.add(""); - lore.add("§cDisabled"); - } - return new SWItem(element.getMaterial(), "§e" + element.getName(), lore, element.isDisabled(), clickType -> { + return element.toItem(player, clickType -> { if (element instanceof TNTElement) { new SimulatorTNTGui(player, simulator, (TNTElement) element, simulatorGroup, this).open(); } else if (element instanceof RedstoneElement) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupSettingsGui.java index 2e335524..df5b06fe 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupSettingsGui.java @@ -28,9 +28,7 @@ import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; -import java.util.ArrayList; import java.util.Arrays; -import java.util.List; public class SimulatorGroupSettingsGui extends SimulatorBaseGui { @@ -61,16 +59,9 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui { })); // Material Chooser - List lore = new ArrayList<>(); - lore.add("§7Element count§8:§e " + simulatorGroup.getElements().size()); - lore.add("§7Tick§8:§e " + simulatorGroup.getBaseTick()); - if (simulatorGroup.isDisabled()) { - lore.add(""); - lore.add("§cDisabled"); - } - inventory.setItem(4, new SWItem(simulatorGroup.getMaterial(), "§eGroup", lore, simulatorGroup.isDisabled(), clickType -> { + inventory.setItem(4, simulatorGroup.toItem(player, clickType -> { new SimulatorMaterialGui(player, simulator, simulatorGroup::getMaterial, simulatorGroup::setMaterial, this).open(); - })); + }, clickType -> {})); // Base Tick int baseTicks = simulatorGroup.getBaseTick(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java index c4e233e6..932fc4a5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java @@ -30,11 +30,7 @@ import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -public class SimulatorGui extends SimulatorPageGui {//TODO Groupcreation +public class SimulatorGui extends SimulatorPageGui { public SimulatorGui(Player player, Simulator simulator) { super(player, simulator, 6 * 9, simulator.getElements()); @@ -49,7 +45,7 @@ public class SimulatorGui extends SimulatorPageGui {//TODO Group public void headerAndFooter() { simulator.getElements().removeIf(element -> element.getElements().isEmpty()); - inventory.setItem(4, new SWItem(simulator.getMaterial(), "§e" + simulator.getName(), clickType -> { + inventory.setItem(4, simulator.toItem(player, clickType -> { new SimulatorMaterialGui(player, simulator, simulator::getMaterial, simulator::setMaterial, this).open(); })); inventory.setItem(49, new SWItem(Material.REPEATER, "§eSettings", clickType -> { @@ -59,38 +55,15 @@ public class SimulatorGui extends SimulatorPageGui {//TODO Group @Override public SWItem convert(SimulatorGroup simulatorGroup) { - List> elements = simulatorGroup.getElements(); - if (elements.size() == 1) { - SimulatorElement element = elements.get(0); - List lore = new ArrayList<>(); - lore.add("§7Phase count§8:§e " + element.getPhases().size()); - lore.add("§7Tick§8:§e " + element.getBaseTick()); - lore.add(""); - lore.add("§7X§8:§e " + element.getPosition().getX()); - lore.add("§7Y§8:§e " + element.getPosition().getY()); - lore.add("§7Z§8:§e " + element.getPosition().getZ()); - if (element.isDisabled()) { - lore.add(""); - lore.add("§cDisabled"); - } - return new SWItem(element.getMaterial(), "§e" + element.getName(), lore, element.isDisabled(), clickType -> { - if (element instanceof TNTElement) { - new SimulatorTNTGui(player, simulator, (TNTElement) element, simulatorGroup,this).open(); - } else if (element instanceof RedstoneElement) { - new SimulatorRedstoneGui(player, simulator, simulatorGroup, (RedstoneElement) element, this).open(); - } - }); - } - - List lore = new ArrayList<>(); - lore.add("§7Element count§8:§e " + elements.size()); - lore.add("§7Tick§8:§e " + simulatorGroup.getBaseTick()); - if (simulatorGroup.isDisabled()) { - lore.add(""); - lore.add("§cDisabled"); - } - return new SWItem(simulatorGroup.getMaterial(), "§eGroup", lore, simulatorGroup.isDisabled(), clickType -> { + return simulatorGroup.toItem(player, clickType -> { new SimulatorGroupGui(player, simulator, simulatorGroup, this).open(); + }, clickType -> { + SimulatorElement element = simulatorGroup.getElements().get(0); + if (element instanceof TNTElement) { + new SimulatorTNTGui(player, simulator, (TNTElement) element, simulatorGroup,this).open(); + } else if (element instanceof RedstoneElement) { + new SimulatorRedstoneGui(player, simulator, simulatorGroup, (RedstoneElement) element, this).open(); + } }); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java index 23af0ac4..efb64277 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java @@ -35,17 +35,16 @@ import org.bukkit.event.inventory.ClickType; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.stream.Collectors; public class SimulatorRedstoneGui extends SimulatorScrollGui { - private final SimulatorGroup simulatorGroup; + private final SimulatorGroup parent; private final RedstoneElement redstone; private final SimulatorBaseGui back; - public SimulatorRedstoneGui(Player player, Simulator simulator, SimulatorGroup simulatorGroup, RedstoneElement redstone, SimulatorBaseGui back) { + public SimulatorRedstoneGui(Player player, Simulator simulator, SimulatorGroup parent, RedstoneElement redstone, SimulatorBaseGui back) { super(player, simulator, 6 * 9, redstone.getPhases()); - this.simulatorGroup = simulatorGroup; + this.parent = parent; this.redstone = redstone; this.back = back; } @@ -66,22 +65,28 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { // Back Arrow inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { - back.open(); + if (parent.getElements().contains(redstone)) { + back.open(); + } else { + SimulatorGroup newParent = simulator.getElements().stream() + .filter(simulatorGroup -> simulatorGroup.getElements().contains(redstone)) + .findFirst() + .orElse(null); + if (newParent == null) { + player.closeInventory(); + return; + } + SimulatorGui simulatorGui = new SimulatorGui(player, simulator); + if (newParent.getElements().size() == 1) { + simulatorGui.open(); + } else { + new SimulatorGroupGui(player, simulator, newParent, simulatorGui).open(); + } + } })); // Material Chooser - List lore = new ArrayList<>(); - lore.add("§7Activation count§8:§e " + data.size()); - lore.add("§7Tick§8:§e " + redstone.getBaseTick()); - lore.add(""); - lore.add("§7X§8:§e " + redstone.getPosition().getX()); - lore.add("§7Y§8:§e " + redstone.getPosition().getY()); - lore.add("§7Z§8:§e " + redstone.getPosition().getZ()); - if (redstone.isDisabled()) { - lore.add(""); - lore.add("§cDisabled"); - } - inventory.setItem(4, new SWItem(redstone.getMaterial(), "§eTNT", lore, redstone.isDisabled(), clickType -> { + inventory.setItem(4, redstone.toItem(player, clickType -> { new SimulatorMaterialGui(player, simulator, redstone::getMaterial, redstone::setMaterial, this).open(); })); @@ -92,7 +97,7 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { //Group chooser inventory.setItem(49, new SWItem(Material.LEAD, "§eMove", clickType -> { - new SimulatorGroupChooserGui(player, simulator, simulator.getElements().stream().filter( e -> e != simulatorGroup).collect(Collectors.toList()), redstone, simulatorGroup, this).open(); + new SimulatorGroupChooserGui(player, simulator, redstone, parent, this).open(); })); //Enable/Disable diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseSettingsGui.java index 0bce321f..7835261d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseSettingsGui.java @@ -62,7 +62,7 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui { })); // Material Chooser - inventory.setItem(4, new SWItem(redstoneElement.getMaterial(), "§eRedstone", clickType -> { + inventory.setItem(4, redstoneElement.toItem(player, clickType -> { new SimulatorMaterialGui(player, simulator, redstoneElement::getMaterial, redstoneElement::setMaterial, this).open(); })); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneSettingsGui.java index 692a6858..7152cc6f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneSettingsGui.java @@ -60,14 +60,7 @@ public class SimulatorRedstoneSettingsGui extends SimulatorBaseGui { })); // Material Chooser - List lore = new ArrayList<>(); - lore.add("§7Activation count§8:§e " + redstone.getPhases().size()); - lore.add("§7Tick§8:§e " + redstone.getBaseTick()); - if (redstone.isDisabled()) { - lore.add(""); - lore.add("§cDisabled"); - } - inventory.setItem(4, new SWItem(redstone.getMaterial(), "§eRedstone", lore, redstone.isDisabled(), clickType -> { + inventory.setItem(4, redstone.toItem(player, clickType -> { new SimulatorMaterialGui(player, simulator, redstone::getMaterial, redstone::setMaterial, this).open(); })); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorSettingsGui.java index d7d92bac..b9e75a5e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorSettingsGui.java @@ -51,7 +51,7 @@ public class SimulatorSettingsGui extends SimulatorBaseGui { })); // Material Chooser - inventory.setItem(4, new SWItem(simulator.getMaterial(), "§e" + simulator.getName(), clickType -> { + inventory.setItem(4, simulator.toItem(player, clickType -> { new SimulatorMaterialGui(player, simulator, simulator::getMaterial, simulator::setMaterial, this).open(); })); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java index d6dc192a..34906cd0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java @@ -67,22 +67,28 @@ public class SimulatorTNTGui extends SimulatorScrollGui { // Back Arrow inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { - back.open(); + if (parent.getElements().contains(tnt)) { + back.open(); + } else { + SimulatorGroup newParent = simulator.getElements().stream() + .filter(simulatorGroup -> simulatorGroup.getElements().contains(tnt)) + .findFirst() + .orElse(null); + if (newParent == null) { + player.closeInventory(); + return; + } + SimulatorGui simulatorGui = new SimulatorGui(player, simulator); + if (newParent.getElements().size() == 1) { + simulatorGui.open(); + } else { + new SimulatorGroupGui(player, simulator, newParent, simulatorGui).open(); + } + } })); // Material Chooser - List lore = new ArrayList<>(); - lore.add("§7Phase count§8:§e " + data.size()); - lore.add("§7Tick§8:§e " + tnt.getBaseTick()); - lore.add(""); - lore.add("§7X§8:§e " + tnt.getPosition().getX()); - lore.add("§7Y§8:§e " + tnt.getPosition().getY()); - lore.add("§7Z§8:§e " + tnt.getPosition().getZ()); - if (tnt.isDisabled()) { - lore.add(""); - lore.add("§cDisabled"); - } - inventory.setItem(4, new SWItem(tnt.getMaterial(), "§eTNT", lore, tnt.isDisabled(), clickType -> { + inventory.setItem(4, tnt.toItem(player, clickType -> { new SimulatorMaterialGui(player, simulator, tnt::getMaterial, tnt::setMaterial, this).open(); })); @@ -90,7 +96,7 @@ public class SimulatorTNTGui extends SimulatorScrollGui { new SimulatorTNTSettingsGui(player, simulator, tnt, this).open(); })); inventory.setItem(49, new SWItem(Material.LEAD, "§eMove", clickType -> { - new SimulatorGroupChooserGui(player, simulator, simulator.getElements().stream().filter( e -> e != parent).collect(Collectors.toList()), tnt, parent, this).open(); + new SimulatorGroupChooserGui(player, simulator, tnt, parent, this).open(); })); inventory.setItem(50, new SWItem(tnt.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, tnt.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { tnt.setDisabled(!tnt.isDisabled()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTPhaseSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTPhaseSettingsGui.java index 852eadd3..2f8d548a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTPhaseSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTPhaseSettingsGui.java @@ -62,7 +62,7 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui { })); // Material Chooser - inventory.setItem(4, new SWItem(tntElement.getMaterial(), "§TNT", clickType -> { + inventory.setItem(4, tntElement.toItem(player, clickType -> { new SimulatorMaterialGui(player, simulator, tntElement::getMaterial, tntElement::setMaterial, this).open(); })); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTSettingsGui.java index 1daf0ae4..074e86c4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTSettingsGui.java @@ -68,7 +68,7 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui { lore.add(""); lore.add("§cDisabled"); } - inventory.setItem(4, new SWItem(tnt.getMaterial(), "§eTNT", lore, tnt.isDisabled(), clickType -> { + inventory.setItem(4, tnt.toItem(player, clickType -> { new SimulatorMaterialGui(player, simulator, tnt::getMaterial, tnt::setMaterial, this).open(); }));