From 68f81c8c3ed3f2d3216ed260b8a5eb9cd7b527a2 Mon Sep 17 00:00:00 2001 From: D4rkr34lm Date: Fri, 13 Oct 2023 12:02:55 +0200 Subject: [PATCH] Add last Phase and option for adding phase Refactored for coherent naming sceme --- .../simulator2/SimulatorTestCommand.java | 10 +++--- .../simulator2/data/SimulatorElement.java | 10 +++--- ...ulatorSetting.java => SimulatorPhase.java} | 7 ++-- .../data/redstone/RedstoneElement.java | 3 +- ...edstoneSetting.java => RedstonePhase.java} | 9 +++-- .../simulator2/data/tnt/TNTElement.java | 2 +- .../tnt/{TNTSetting.java => TNTPhase.java} | 8 +++-- .../simulator2/gui/SimulatorGroupGui.java | 2 +- .../features/simulator2/gui/SimulatorGui.java | 2 +- .../simulator2/gui/SimulatorRedstoneGui.java | 34 ++++++++++++------- ...=> SimulatorRedstonePhaseSettingsGui.java} | 16 ++++----- .../gui/SimulatorRedstoneSettingsGui.java | 4 +-- .../simulator2/gui/SimulatorTNTGui.java | 28 +++++++++++---- .../gui/SimulatorTNTSettingsGui.java | 2 +- ...java => SimulatorTntPhaseSettingsGui.java} | 20 +++++------ .../gui/base/SimulatorScrollGui.java | 29 ++++++++++++---- 16 files changed, 118 insertions(+), 68 deletions(-) rename BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/{SimulatorSetting.java => SimulatorPhase.java} (90%) rename BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/{RedstoneSetting.java => RedstonePhase.java} (76%) rename BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/{TNTSetting.java => TNTPhase.java} (85%) rename BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/{SimulatorRedstonePhaseGui.java => SimulatorRedstonePhaseSettingsGui.java} (89%) rename BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/{SimulatorTntPhaseGui.java => SimulatorTntPhaseSettingsGui.java} (88%) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorTestCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorTestCommand.java index 1117a766..82b7703e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorTestCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorTestCommand.java @@ -22,9 +22,9 @@ package de.steamwar.bausystem.features.simulator2; import de.steamwar.bausystem.features.simulator2.data.Simulator; import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup; import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement; -import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneSetting; +import de.steamwar.bausystem.features.simulator2.data.redstone.RedstonePhase; import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; -import de.steamwar.bausystem.features.simulator2.data.tnt.TNTSetting; +import de.steamwar.bausystem.features.simulator2.data.tnt.TNTPhase; import de.steamwar.bausystem.features.simulator2.gui.SimulatorGui; import de.steamwar.command.SWCommand; import de.steamwar.linkage.Linked; @@ -39,13 +39,13 @@ public class SimulatorTestCommand extends SWCommand { public SimulatorTestCommand() { super("simtest"); - SimulatorGroup group1 = new SimulatorGroup().add(new TNTElement(new Vector(0, 0, 0)).add(new TNTSetting())).add(new TNTElement(new Vector(0, 0, 0)).add(new TNTSetting())); + SimulatorGroup group1 = new SimulatorGroup().add(new TNTElement(new Vector(0, 0, 0)).add(new TNTPhase())).add(new TNTElement(new Vector(0, 0, 0)).add(new TNTPhase())); SIMULATOR.getElements().add(group1); - SimulatorGroup group2 = new SimulatorGroup().add(new TNTElement(new Vector(0, 0, 0)).add(new TNTSetting())); + SimulatorGroup group2 = new SimulatorGroup().add(new TNTElement(new Vector(0, 0, 0)).add(new TNTPhase())); SIMULATOR.getElements().add(group2); - SimulatorGroup group3 = new SimulatorGroup().add(new RedstoneElement(new Vector(0, 0, 0)).add(new RedstoneSetting())); + SimulatorGroup group3 = new SimulatorGroup().add(new RedstoneElement(new Vector(0, 0, 0)).add(new RedstonePhase())); SIMULATOR.getElements().add(group3); } 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 a218ea6b..1274f7c8 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 @@ -29,11 +29,11 @@ import java.util.List; @Getter @Setter -public abstract class SimulatorElement { +public abstract class SimulatorElement { protected Material material; protected final Vector position; protected boolean disabled = false; - protected final List settings = new ArrayList<>(); + protected final List phases = new ArrayList<>(); protected SimulatorElement(Material material, Vector position) { this.material = material; @@ -41,21 +41,21 @@ public abstract class SimulatorElement { } public SimulatorElement add(T setting) { - settings.add(setting); + phases.add(setting); return this; } public abstract String getName(); public int getBaseTick() { - return settings.stream() + return phases.stream() .mapToInt(value -> value.tickOffset) .min() .orElse(0); } public void changeBaseTicks(int tick) { - settings.forEach(t -> { + phases.forEach(t -> { t.tickOffset += tick; }); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorSetting.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorPhase.java similarity index 90% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorSetting.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorPhase.java index 46d5a151..c77c2396 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorSetting.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorPhase.java @@ -24,9 +24,12 @@ import lombok.Setter; @Getter @Setter -public abstract class SimulatorSetting { +public abstract class SimulatorPhase { public static final int ORDER_LIMIT = 64; - protected int tickOffset; + + protected int tickOffset = 0; protected int lifetime = 80; protected int order = 1; + + public SimulatorPhase(){}; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java index a633ac45..bea1c83d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java @@ -23,8 +23,7 @@ import de.steamwar.bausystem.features.simulator2.data.SimulatorElement; import org.bukkit.Material; import org.bukkit.util.Vector; -public class RedstoneElement extends SimulatorElement { - +public class RedstoneElement extends SimulatorElement { public RedstoneElement(Vector position) { super(Material.REDSTONE_BLOCK, position); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneSetting.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstonePhase.java similarity index 76% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneSetting.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstonePhase.java index 522f27a8..f22b3cee 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneSetting.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstonePhase.java @@ -19,7 +19,12 @@ package de.steamwar.bausystem.features.simulator2.data.redstone; -import de.steamwar.bausystem.features.simulator2.data.SimulatorSetting; +import de.steamwar.bausystem.features.simulator2.data.SimulatorPhase; +import org.bukkit.Material; -public class RedstoneSetting extends SimulatorSetting { +public class RedstonePhase extends SimulatorPhase { + public RedstonePhase(){}; + public RedstonePhase(int tickOffset){ + this.tickOffset = tickOffset; + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java index bbcfae6f..3eb27a82 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java @@ -23,7 +23,7 @@ import de.steamwar.bausystem.features.simulator2.data.SimulatorElement; import org.bukkit.Material; import org.bukkit.util.Vector; -public class TNTElement extends SimulatorElement { +public class TNTElement extends SimulatorElement { public TNTElement(Vector position) { super(Material.TNT, position); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTSetting.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTPhase.java similarity index 85% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTSetting.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTPhase.java index 58c64990..82bd03b6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTSetting.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTPhase.java @@ -19,18 +19,22 @@ package de.steamwar.bausystem.features.simulator2.data.tnt; -import de.steamwar.bausystem.features.simulator2.data.SimulatorSetting; +import de.steamwar.bausystem.features.simulator2.data.SimulatorPhase; import lombok.Getter; import lombok.Setter; @Getter @Setter -public class TNTSetting extends SimulatorSetting { +public class TNTPhase extends SimulatorPhase { private int count = 1; private boolean xJump = false; private boolean yJump = false; private boolean zJump = false; + public TNTPhase(){} + + public TNTPhase(int tickOffset){this.tickOffset = tickOffset;} + public boolean hasJump(){ if(xJump || yJump || zJump) return true; else return false; 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 c9a4c68e..c38edc90 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 @@ -85,7 +85,7 @@ public class SimulatorGroupGui extends SimulatorPageGui> { @Override public SWItem convert(SimulatorElement element) { List lore = new ArrayList<>(); - lore.add("§7Phase count§8:§e " + element.getSettings().size()); + 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()); 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 2b019260..309c8b70 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 @@ -67,7 +67,7 @@ public class SimulatorGui extends SimulatorPageGui { if (elements.size() == 1) { SimulatorElement element = elements.get(0); List lore = new ArrayList<>(); - lore.add("§7Phase count§8:§e " + element.getSettings().size()); + 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()); 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 08270b59..0f09eeab 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 @@ -23,8 +23,7 @@ import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; import de.steamwar.bausystem.features.simulator2.data.Simulator; import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup; import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement; -import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneSetting; -import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; +import de.steamwar.bausystem.features.simulator2.data.redstone.RedstonePhase; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorScrollGui; import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui; @@ -36,14 +35,14 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -public class SimulatorRedstoneGui extends SimulatorScrollGui { +public class SimulatorRedstoneGui extends SimulatorScrollGui { private final SimulatorGroup simulatorGroup; private final RedstoneElement redstoneElement; private final SimulatorBaseGui back; public SimulatorRedstoneGui(Player player, Simulator simulator, SimulatorGroup simulatorGroup, RedstoneElement redstoneElement, SimulatorBaseGui back) { - super(player, simulator, 6 * 9, redstoneElement.getSettings()); + super(player, simulator, 6 * 9, redstoneElement.getPhases()); this.simulatorGroup = simulatorGroup; this.redstoneElement = redstoneElement; this.back = back; @@ -56,12 +55,6 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { @Override public void headerAndFooter() { - if (redstoneElement.getSettings().isEmpty()) { - simulatorGroup.getElements().remove(redstoneElement); - back.open(); - return; - } - // TODO Sort Data List // Back Arrow @@ -100,10 +93,10 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { } @Override - public SWItem[] column(RedstoneSetting redstoneSetting) { + public SWItem[] column(RedstonePhase redstoneSetting) { SWItem redstone = new SWItem(Material.REDSTONE_BLOCK, "§eRedstone§8:§7 " + redstoneSetting.getTickOffset(), Arrays.asList("§7Fuse§8:§e " + redstoneSetting.getLifetime(), "", "§7Order§8:§e " + redstoneSetting.getOrder()), false, clickType -> { //Quick remove per rightclick - if (clickType.isRightClick()) redstoneElement.getSettings().remove(redstoneSetting); + if (clickType.isRightClick()) redstoneElement.getPhases().remove(redstoneSetting); SimulatorWatcher.update(simulator); }); redstone.getItemStack().setAmount(Math.max(1, Math.min(redstoneSetting.getTickOffset(), 64))); @@ -119,8 +112,23 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { SimulatorWatcher.update(simulator); }), new SWItem(Material.ANVIL, "§eEdit Activation", clickType -> { - new SimulatorRedstonePhaseGui(player, simulator, redstoneElement, redstoneSetting, this).open(); + new SimulatorRedstonePhaseSettingsGui(player, simulator, redstoneElement, redstoneSetting, this).open(); }), }; } + + @Override + public SWItem[] lastColumn() { + return new SWItem[] { + new SWItem(SWItem.getDye(10), "§aNew Phase", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> { + RedstonePhase lastElement = redstoneElement.getPhases().get(redstoneElement.getPhases().size() - 1); + RedstonePhase newPhase = new RedstonePhase(lastElement.getTickOffset() + 1); + if(clickType.isShiftClick()) newPhase.setTickOffset(newPhase.getTickOffset() + 4); + redstoneElement.add(newPhase); + SimulatorWatcher.update(simulator); + }), + new SWItem(Material.REDSTONE_BLOCK, "§eRedstone§8:§a New Phase", Arrays.asList(), false, clickType -> {}), + new SWItem(SWItem.getDye(8), "", Arrays.asList(), false, clickType -> {}), + }; + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseSettingsGui.java similarity index 89% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseGui.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseSettingsGui.java index fd8b992a..4479d75d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseSettingsGui.java @@ -21,9 +21,9 @@ package de.steamwar.bausystem.features.simulator2.gui; import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; import de.steamwar.bausystem.features.simulator2.data.Simulator; -import de.steamwar.bausystem.features.simulator2.data.SimulatorSetting; +import de.steamwar.bausystem.features.simulator2.data.SimulatorPhase; import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement; -import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneSetting; +import de.steamwar.bausystem.features.simulator2.data.redstone.RedstonePhase; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui; import de.steamwar.inventory.SWItem; @@ -32,12 +32,12 @@ import org.bukkit.entity.Player; import java.util.Arrays; -public class SimulatorRedstonePhaseGui extends SimulatorBaseGui { +public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui { private final RedstoneElement redstoneElement; - private final RedstoneSetting redstone; + private final RedstonePhase redstone; private final SimulatorBaseGui back; - public SimulatorRedstonePhaseGui(Player player, Simulator simulator, RedstoneElement redstoneElement, RedstoneSetting redstone, SimulatorBaseGui back) { + public SimulatorRedstonePhaseSettingsGui(Player player, Simulator simulator, RedstoneElement redstoneElement, RedstonePhase redstone, SimulatorBaseGui back) { super(player, simulator, 5 * 9); this.redstoneElement = redstoneElement; this.redstone = redstone; @@ -51,7 +51,7 @@ public class SimulatorRedstonePhaseGui extends SimulatorBaseGui { @Override public void populate() { - if (!redstoneElement.getSettings().contains(redstone)) { + if (!redstoneElement.getPhases().contains(redstone)) { back.open(); return; } @@ -68,7 +68,7 @@ public class SimulatorRedstonePhaseGui extends SimulatorBaseGui { // Delete inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> { - redstoneElement.getSettings().remove(redstone); + redstoneElement.getPhases().remove(redstone); back.open(); SimulatorWatcher.update(simulator); })); @@ -108,7 +108,7 @@ public class SimulatorRedstonePhaseGui extends SimulatorBaseGui { //Order int order = redstone.getOrder(); inventory.setItem(14, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { - redstone.setOrder(Math.min(SimulatorSetting.ORDER_LIMIT, order + (clickType.isShiftClick() ? 5 : 1))); + redstone.setOrder(Math.min(SimulatorPhase.ORDER_LIMIT, order + (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); }); 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 c191f862..6461eb80 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 @@ -49,7 +49,7 @@ public class SimulatorRedstoneSettingsGui extends SimulatorBaseGui { @Override public void populate() { - if (redstone.getSettings().isEmpty()) { + if (redstone.getPhases().isEmpty()) { back.open(); return; } @@ -61,7 +61,7 @@ public class SimulatorRedstoneSettingsGui extends SimulatorBaseGui { // Material Chooser List lore = new ArrayList<>(); - lore.add("§7Activation count§8:§e " + redstone.getSettings().size()); + lore.add("§7Activation count§8:§e " + redstone.getPhases().size()); lore.add("§7Tick§8:§e " + redstone.getBaseTick()); if (redstone.isDisabled()) { lore.add(""); 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 532cc38c..15451b16 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 @@ -21,8 +21,9 @@ package de.steamwar.bausystem.features.simulator2.gui; import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; import de.steamwar.bausystem.features.simulator2.data.Simulator; +import de.steamwar.bausystem.features.simulator2.data.redstone.RedstonePhase; import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; -import de.steamwar.bausystem.features.simulator2.data.tnt.TNTSetting; +import de.steamwar.bausystem.features.simulator2.data.tnt.TNTPhase; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorScrollGui; import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui; @@ -34,13 +35,13 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -public class SimulatorTNTGui extends SimulatorScrollGui { +public class SimulatorTNTGui extends SimulatorScrollGui { private TNTElement tntElement; private SimulatorBaseGui back; public SimulatorTNTGui(Player player, Simulator simulator, TNTElement tntElement, SimulatorBaseGui back) { - super(player, simulator, 6 * 9, tntElement.getSettings()); + super(player, simulator, 6 * 9, tntElement.getPhases()); this.tntElement = tntElement; this.back = back; } @@ -88,10 +89,10 @@ public class SimulatorTNTGui extends SimulatorScrollGui { } @Override - public SWItem[] column(TNTSetting tntSetting) { + public SWItem[] column(TNTPhase tntSetting) { SWItem tnt = new SWItem(Material.TNT, "§eTNT§8:§7 " + tntSetting.getCount(), Arrays.asList("§7Tick§8: §e" + tntSetting.getTickOffset(), "§7Fuse§8:§e " + tntSetting.getLifetime(), "", "§7Order§8:§e " + tntSetting.getOrder(), "", "§7X-Jump§8: " + (tntSetting.isXJump() ? "§aOn" : "§cOff"), "§7Y-Jump§8: " + (tntSetting.isYJump() ? "§aOn" : "§cOff"), "§7Z-Jump§8: " + (tntSetting.isZJump() ? "§aOn" : "§cOff")), false, clickType -> { //Quick remove per rightclick - if (clickType.isRightClick()) tntElement.getSettings().remove(tntSetting); + if (clickType.isRightClick()) tntElement.getPhases().remove(tntSetting); SimulatorWatcher.update(simulator); }); tnt.getItemStack().setAmount(Math.min(tntSetting.getCount(), 64)); @@ -107,8 +108,23 @@ public class SimulatorTNTGui extends SimulatorScrollGui { SimulatorWatcher.update(simulator); }), new SWItem(Material.ANVIL, "§eEdit Phase", clickType -> { - new SimulatorTntPhaseGui(player, simulator, tntElement, tntSetting, this).open(); + new SimulatorTntPhaseSettingsGui(player, simulator, tntElement, tntSetting, this).open(); }), }; } + + @Override + public SWItem[] lastColumn() { + return new SWItem[] { + new SWItem(SWItem.getDye(10), "§aNew Phase", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> { + TNTPhase lastElement = tntElement.getPhases().get(tntElement.getPhases().size() - 1); + TNTPhase newPhase = new TNTPhase(lastElement.getTickOffset() + 1); + if(clickType.isShiftClick()) newPhase.setCount(newPhase.getCount() + 4); + tntElement.add(newPhase); + SimulatorWatcher.update(simulator); + }), + new SWItem(Material.TNT, "§TNT§8:§a New Phase", Arrays.asList(), false, clickType -> {}), + new SWItem(SWItem.getDye(8), "", Arrays.asList(), false, clickType -> {}), + }; + } } 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 3f338eed..aaaed03e 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 @@ -57,7 +57,7 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui { // Material Chooser List lore = new ArrayList<>(); - lore.add("§7Phase count§8:§e " + tnt.getSettings().size()); + lore.add("§7Phase count§8:§e " + tnt.getPhases().size()); lore.add("§7Tick§8:§e " + tnt.getBaseTick()); if (tnt.isDisabled()) { lore.add(""); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTntPhaseGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTntPhaseSettingsGui.java similarity index 88% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTntPhaseGui.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTntPhaseSettingsGui.java index e9b3defd..3c0a7daf 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTntPhaseGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTntPhaseSettingsGui.java @@ -21,11 +21,9 @@ package de.steamwar.bausystem.features.simulator2.gui; import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; import de.steamwar.bausystem.features.simulator2.data.Simulator; -import de.steamwar.bausystem.features.simulator2.data.SimulatorSetting; -import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement; -import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneSetting; +import de.steamwar.bausystem.features.simulator2.data.SimulatorPhase; import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; -import de.steamwar.bausystem.features.simulator2.data.tnt.TNTSetting; +import de.steamwar.bausystem.features.simulator2.data.tnt.TNTPhase; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui; import de.steamwar.inventory.SWItem; @@ -34,12 +32,12 @@ import org.bukkit.entity.Player; import java.util.Arrays; -public class SimulatorTntPhaseGui extends SimulatorBaseGui{ +public class SimulatorTntPhaseSettingsGui extends SimulatorBaseGui{ private final TNTElement tntElement; - private final TNTSetting tnt; + private final TNTPhase tnt; private final SimulatorBaseGui back; - public SimulatorTntPhaseGui(Player player, Simulator simulator, TNTElement tntElement, TNTSetting tnt, SimulatorBaseGui back) { + public SimulatorTntPhaseSettingsGui(Player player, Simulator simulator, TNTElement tntElement, TNTPhase tnt, SimulatorBaseGui back) { super(player, simulator, 5 * 9); this.tntElement = tntElement; this.tnt = tnt; @@ -53,7 +51,7 @@ public class SimulatorTntPhaseGui extends SimulatorBaseGui{ @Override public void populate() { - if (!tntElement.getSettings().contains(tnt)) { + if (!tntElement.getPhases().contains(tnt)) { back.open(); return; } @@ -70,7 +68,7 @@ public class SimulatorTntPhaseGui extends SimulatorBaseGui{ //Delete inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> { - tntElement.getSettings().remove(tnt); + tntElement.getPhases().remove(tnt); back.open(); SimulatorWatcher.update(simulator); })); @@ -125,8 +123,8 @@ public class SimulatorTntPhaseGui extends SimulatorBaseGui{ //Order int order = tnt.getOrder(); - inventory.setItem(13, SWItem.getDye(order < SimulatorSetting.ORDER_LIMIT ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { - tnt.setOrder(Math.min(SimulatorSetting.ORDER_LIMIT, order + (clickType.isShiftClick() ? 5 : 1))); + inventory.setItem(13, SWItem.getDye(order < SimulatorPhase.ORDER_LIMIT ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + tnt.setOrder(Math.min(SimulatorPhase.ORDER_LIMIT, order + (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); }); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorScrollGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorScrollGui.java index a61a4971..ab1bd0a7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorScrollGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorScrollGui.java @@ -19,11 +19,15 @@ package de.steamwar.bausystem.features.simulator2.gui.base; +import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; import de.steamwar.bausystem.features.simulator2.data.Simulator; +import de.steamwar.bausystem.features.simulator2.data.redstone.RedstonePhase; import de.steamwar.core.Core; import de.steamwar.inventory.SWItem; +import org.bukkit.Material; import org.bukkit.entity.Player; +import java.util.Arrays; import java.util.List; public abstract class SimulatorScrollGui extends SimulatorBaseGui { // TODO: Last Column? @@ -36,7 +40,7 @@ public abstract class SimulatorScrollGui extends SimulatorBaseGui { // TODO: } private int maxScroll() { - return Math.max(0, Math.min(scroll, data.size() - 9)); + return Math.max(0, Math.min(scroll, data.size() - 9 + 1)); } @Override @@ -63,11 +67,16 @@ public abstract class SimulatorScrollGui extends SimulatorBaseGui { // TODO: } }); - for (int i = 0; i < Math.min(9, data.size()); i++) { - T element = data.get(scroll + i); - SWItem[] column = column(element); - for (int j = 0; j < column.length; j++) { - inventory.setItem(i + j * 9 + 9, column[j]); + for (int i = 0; i < 9; i++) { + if(i < data.size()){ + T element = data.get(scroll + i); + SWItem[] column = column(element); + populateColumn(column, i); + } + else { + SWItem[] column = lastColumn(); + populateColumn(column, i); + break; } } } @@ -76,5 +85,13 @@ public abstract class SimulatorScrollGui extends SimulatorBaseGui { // TODO: public void headerAndFooter() { } + + public void populateColumn(SWItem[] column, int index){ + for (int j = 0; j < column.length; j++) { + inventory.setItem(index + j * 9 + 9, column[j]); + } + } public abstract SWItem[] column(T t); + + public abstract SWItem[] lastColumn(); }