diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java index 2f4b0f8b..6ff78e19 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java @@ -94,7 +94,9 @@ public class SimulatorCursor implements Listener { @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { - calcCursor(event.getPlayer()); + Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { + calcCursor(event.getPlayer()); + }, 0); } @EventHandler diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorStorage.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorStorage.java index 9ad4701d..9ac84989 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorStorage.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorStorage.java @@ -29,6 +29,7 @@ import de.steamwar.bausystem.features.simulator.storage.SimulatorFormatSimulator import de.steamwar.bausystem.features.simulator.storage.SimulatorSaver; import de.steamwar.bausystem.features.simulator.storage.YAPIONFormatSimulatorLoader; import de.steamwar.bausystem.utils.ItemUtils; +import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWItem; import de.steamwar.linkage.Linked; import de.steamwar.linkage.MinVersion; @@ -133,6 +134,28 @@ public class SimulatorStorage implements Enable { return "Simulators"; } + @Override + public void headerAndFooter() { + inventory.setItem(49, new SWItem(Material.NAME_TAG, "§eCreate", clickType -> { + SWAnvilInv anvilInv = new SWAnvilInv(player, "Name"); + anvilInv.setCallback(s -> { + Simulator sim = SimulatorStorage.getSimulator(s); + if (sim != null) { + BauSystem.MESSAGE.send("SIMULATOR_NAME_ALREADY_EXISTS", player); + return; + } + if (!s.matches("[a-zA-Z_0-9-]+")) { + BauSystem.MESSAGE.send("SIMULATOR_NAME_INVALID", player); + return; + } + sim = new Simulator(s); + SimulatorStorage.addSimulator(s, sim); + SimulatorStorage.setSimulator(player, sim); + }); + anvilInv.open(); + })); + } + @Override public SWItem convert(Simulator simulator) { return simulator.toItem(player, clickType -> { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/SimulatorElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/SimulatorElement.java index df5b13a4..119143db 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/SimulatorElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/SimulatorElement.java @@ -73,7 +73,7 @@ public abstract class SimulatorElement { }); } - public void move(int x, int y, int z) { + public void move(double x, double y, double z) { position.setX(position.getX() + x); position.setY(position.getY() + y); position.setZ(position.getZ() + z); @@ -83,6 +83,8 @@ public abstract class SimulatorElement { public abstract Material getWorldDisabledMaterial(); + public abstract boolean canBeInGroup(SimulatorGroup simulatorGroup); + public Vector getWorldPos() { return position; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/SimulatorGroup.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/SimulatorGroup.java index 0e90903c..8031dd1c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/SimulatorGroup.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/SimulatorGroup.java @@ -30,7 +30,6 @@ import org.bukkit.entity.Player; import java.util.ArrayList; import java.util.Comparator; import java.util.List; -import java.util.Map; import java.util.function.BiConsumer; @Getter @@ -64,7 +63,7 @@ public final class SimulatorGroup { }); } - public void move(int x, int y, int z) { + public void move(double x, double y, double z) { elements.forEach(simulatorElement -> { simulatorElement.move(x, y, z); }); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstoneElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstoneElement.java index ac130e03..2eb7aca2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstoneElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstoneElement.java @@ -49,6 +49,11 @@ public final class RedstoneElement extends SimulatorElement { return Material.WHITE_STAINED_GLASS; } + @Override + public boolean canBeInGroup(SimulatorGroup simulatorGroup) { + return simulatorGroup.getElements().stream().allMatch(RedstoneElement.class::isInstance); + } + @Override public Vector getWorldPos() { return position.clone().add(new Vector(0.5, 0, 0.5)); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTElement.java index 36b10130..29e90d83 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTElement.java @@ -88,6 +88,11 @@ public final class TNTElement extends SimulatorElement { return Material.RED_STAINED_GLASS; } + @Override + public boolean canBeInGroup(SimulatorGroup simulatorGroup) { + return simulatorGroup.getElements().stream().allMatch(TNTElement.class::isInstance); + } + @Override public void open(Player player, Simulator simulator, SimulatorGroup group, SimulatorBaseGui back) { new SimulatorTNTGui(player, simulator, this, group, back).open(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupChooserGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupChooserGui.java index 9778c6c6..fabbfac3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupChooserGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupChooserGui.java @@ -39,7 +39,7 @@ public class SimulatorGroupChooserGui extends SimulatorPageGui { private final SimulatorBaseGui back; public SimulatorGroupChooserGui(Player player, Simulator simulator, SimulatorElement subject, SimulatorGroup parent, SimulatorBaseGui back) { - super(player, simulator, 6 * 9, simulator.getGroups().stream().filter(e -> e != parent).collect(Collectors.toList())); + super(player, simulator, 6 * 9, simulator.getGroups().stream().filter(e -> e != parent).filter(e -> subject.canBeInGroup(e)).collect(Collectors.toList())); this.subject = subject; this.parent = parent; this.back = back; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupGui.java index 06df5e5e..c3b8ee1a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupGui.java @@ -72,6 +72,11 @@ public class SimulatorGroupGui extends SimulatorPageGui> { back.open(); })); + inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> { + simulatorGroup.getElements().clear(); + SimulatorWatcher.update(simulator); + })); + inventory.setItem(4, simulatorGroup.toItem(player, clickType -> { if (simulatorGroup.getMaterial() == null) return; new SimulatorMaterialGui(player, simulator, simulatorGroup::getMaterial, simulatorGroup::setMaterial, this).open(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupSettingsGui.java index 4c1e8d74..873011f9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupSettingsGui.java @@ -22,11 +22,13 @@ package de.steamwar.bausystem.features.simulator.gui; import de.steamwar.bausystem.features.simulator.SimulatorWatcher; import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.bausystem.features.simulator.data.SimulatorGroup; +import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; +import org.bukkit.util.Vector; import java.util.Arrays; @@ -62,7 +64,8 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui { inventory.setItem(4, simulatorGroup.toItem(player, clickType -> { if (simulatorGroup.getMaterial() == null) return; new SimulatorMaterialGui(player, simulator, simulatorGroup::getMaterial, simulatorGroup::setMaterial, this).open(); - }, clickType -> {})); + }, clickType -> { + })); // Base Tick int baseTicks = simulatorGroup.getBaseTick(); @@ -89,36 +92,84 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui { SimulatorWatcher.update(simulator); }); + boolean allTNT = simulatorGroup.getElements().stream().allMatch(TNTElement.class::isInstance); + + if (allTNT) { + // Subpixel Alignment + inventory.setItem(21, new SWItem(Material.SUNFLOWER, "§7Align§8: §eCenter", clickType -> { + simulatorGroup.getElements().stream().map(TNTElement.class::cast).forEach(tnt -> { + tnt.align(new Vector(0.5, 0, 0.5)); + }); + SimulatorWatcher.update(simulator); + })); + + // Z + inventory.setItem(20, new SWItem(Material.OAK_BUTTON, "§7Align§8: §eNegativ Z", clickType -> { + simulatorGroup.getElements().stream().map(TNTElement.class::cast).forEach(tnt -> { + tnt.align(new Vector(0, 0, 0.49)); + }); + SimulatorWatcher.update(simulator); + })); + + inventory.setItem(22, new SWItem(Material.OAK_BUTTON, "§7Align§8: §ePositiv Z", clickType -> { + simulatorGroup.getElements().stream().map(TNTElement.class::cast).forEach(tnt -> { + tnt.align(new Vector(0, 0, 0.51)); + }); + SimulatorWatcher.update(simulator); + })); + + // X + inventory.setItem(12, new SWItem(Material.STONE_BUTTON, "§7Align§8: §eNegativ X", clickType -> { + simulatorGroup.getElements().stream().map(TNTElement.class::cast).forEach(tnt -> { + tnt.align(new Vector(0.49, 0, 0)); + }); + SimulatorWatcher.update(simulator); + })); + + inventory.setItem(30, new SWItem(Material.STONE_BUTTON, "§7Align§8: §ePositiv X", clickType -> { + simulatorGroup.getElements().stream().map(TNTElement.class::cast).forEach(tnt -> { + tnt.align(new Vector(0.51, 0, 0)); + }); + SimulatorWatcher.update(simulator); + })); + } + //Pos X - inventory.setItem(15, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { - simulatorGroup.move(clickType.isShiftClick() ? 5 : 1, 0, 0); + inventory.setItem(15, SWItem.getDye(10), "§e+1", Arrays.asList(allTNT ? "§7Shift§8: §e+0.0625" : "§7Shift§8: §e+5"), false, clickType -> { + simulatorGroup.move(clickType.isShiftClick() ? (allTNT ? 0.0625 : 5) : 1, 0, 0); SimulatorWatcher.update(simulator); }); - inventory.setItem(24, new SWItem(Material.PAPER, "§eX")); - inventory.setItem(33, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { - simulatorGroup.move(clickType.isShiftClick() ? -5 : -1, 0, 0); + inventory.setItem(24, new SWItem(Material.PAPER, "§eX", clickType -> { + // TODO: Change X Anvil GUI + })); + inventory.setItem(33, SWItem.getDye(1), "§e-1", Arrays.asList(allTNT ? "§7Shift§8: §e-0.0625" : "§7Shift§8: §e-5"), false, clickType -> { + simulatorGroup.move(clickType.isShiftClick() ? (allTNT ? -0.0625 : -5) : -1, 0, 0); SimulatorWatcher.update(simulator); }); //Pos Y - inventory.setItem(16, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { - simulatorGroup.move(0, clickType.isShiftClick() ? 5 : 1, 0); + inventory.setItem(16, SWItem.getDye(10), "§e+1", Arrays.asList(allTNT ? "§7Shift§8: §e+0.0625" : "§7Shift§8: §e+5"), false, clickType -> { + simulatorGroup.move(0, clickType.isShiftClick() ? (allTNT ? 0.0625 : 5) : 1, 0); SimulatorWatcher.update(simulator); }); - inventory.setItem(25, new SWItem(Material.PAPER, "§eY")); - inventory.setItem(34, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { - simulatorGroup.move(0, clickType.isShiftClick() ? -5 : -1, 0); + inventory.setItem(25, new SWItem(Material.PAPER, "§eY", clickType -> { + // TODO: Change Y Anvil GUI + })); + inventory.setItem(34, SWItem.getDye(1), "§e-1", Arrays.asList(allTNT ? "§7Shift§8: §e-0.0625" : "§7Shift§8: §e-5"), false, clickType -> { + simulatorGroup.move(0, clickType.isShiftClick() ? (allTNT ? -0.0625 : -5) : -1, 0); SimulatorWatcher.update(simulator); }); //Pos Z - inventory.setItem(17, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { - simulatorGroup.move(0, 0, clickType.isShiftClick() ? 5 : 1); + inventory.setItem(17, SWItem.getDye(10), "§e+1", Arrays.asList(allTNT ? "§7Shift§8: §e+0.0625" : "§7Shift§8: §e+5"), false, clickType -> { + simulatorGroup.move(0, 0, clickType.isShiftClick() ? (allTNT ? 0.0625 : 5) : 1); SimulatorWatcher.update(simulator); }); - inventory.setItem(26, new SWItem(Material.PAPER, "§eZ")); - inventory.setItem(35, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { - simulatorGroup.move(0, 0, clickType.isShiftClick() ? -5 : -1); + inventory.setItem(26, new SWItem(Material.PAPER, "§eZ", clickType -> { + // TODO: Change Z Anvil GUI + })); + inventory.setItem(35, SWItem.getDye(1), "§e-1", Arrays.asList(allTNT ? "§7Shift§8: §e-0.0625" : "§7Shift§8: §e-5"), false, clickType -> { + simulatorGroup.move(0, 0, clickType.isShiftClick() ? (allTNT ? -0.0625 : -5) : -1); SimulatorWatcher.update(simulator); }); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneGui.java index d934df37..81cc7f4e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneGui.java @@ -27,20 +27,25 @@ import de.steamwar.bausystem.features.simulator.data.redstone.RedstonePhase; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorScrollGui; import de.steamwar.inventory.SWItem; +import lombok.AllArgsConstructor; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; +import java.util.function.Consumer; +import java.util.function.Supplier; -public class SimulatorRedstoneGui extends SimulatorScrollGui { +public class SimulatorRedstoneGui extends SimulatorScrollGui { private final SimulatorGroup parent; private final RedstoneElement redstone; private final SimulatorBaseGui back; public SimulatorRedstoneGui(Player player, Simulator simulator, SimulatorGroup parent, RedstoneElement redstone, SimulatorBaseGui back) { - super(player, simulator, 6 * 9, redstone.getPhases()); + super(player, simulator, 6 * 9, new ArrayList<>()); this.parent = parent; this.redstone = redstone; this.back = back; @@ -59,7 +64,12 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { return; } - redstone.sort(); + data.clear(); + redstone.getPhases().forEach(redstonePhase -> { + data.add(new RedstoneSubPhase(true, redstonePhase)); + data.add(new RedstoneSubPhase(false, redstonePhase)); + }); + data.sort(null); // Back Arrow inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { @@ -80,6 +90,11 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { } })); + inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> { + redstone.getPhases().clear(); + SimulatorWatcher.update(simulator); + })); + // Material Chooser inventory.setItem(4, redstone.toItem(player, clickType -> { new SimulatorMaterialGui(player, simulator, redstone::getMaterial, redstone::setMaterial, this).open(); @@ -91,11 +106,11 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { })); // Group chooser - inventory.setItem(49, new SWItem(Material.LEAD, "§eMove", clickType -> { + inventory.setItem(49, new SWItem(Material.LEAD, "§eJoin Group", clickType -> { new SimulatorGroupChooserGui(player, simulator, redstone, redstone.getGroup(simulator), this).open(); })); - //Enable/Disable + // Enable/Disable inventory.setItem(50, new SWItem(redstone.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, redstone.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { redstone.setDisabled(!redstone.isDisabled()); SimulatorWatcher.update(simulator); @@ -103,25 +118,63 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { } @Override - public SWItem[] column(RedstonePhase redstoneSetting) { - SWItem redstone = new SWItem(Material.REDSTONE_BLOCK, "§eRedstone§8:§7 " + redstoneSetting.getTickOffset(), Arrays.asList("§7Activation Time§8:§e " + redstoneSetting.getLifetime(), "", "§7Middle-Click§8:§e Remove"), false, clickType -> { - if (clickType == ClickType.MIDDLE) this.redstone.getPhases().remove(redstoneSetting); - SimulatorWatcher.update(simulator); - }); - redstone.getItemStack().setAmount(Math.max(1, Math.min(redstoneSetting.getTickOffset(), 64))); + public SWItem[] column(RedstoneSubPhase redstoneSubPhase, int index) { + // TODO: Add to the phase edit menus and split those to better reflect the scroll gui state + int min; + if (index % 2 == 0 && index > 0) { + RedstoneSubPhase subPhase = data.get(index - 1); + min = subPhase.phase.getTickOffset() + subPhase.phase.getLifetime() + 1; + } else { + min = 0; + } - return new SWItem[]{ - new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> { - redstoneSetting.setTickOffset(redstoneSetting.getTickOffset() + (clickType.isShiftClick() ? 5 : 1)); + int max; + if (index % 2 == 0 && index < data.size() - 2) { + RedstoneSubPhase subPhase = data.get(index + 2); + max = subPhase.phase.getTickOffset() - redstoneSubPhase.phase.getLifetime() - 1; + } else if (index % 2 != 0 && index < data.size() - 1) { + RedstoneSubPhase subPhase = data.get(index + 1); + max = subPhase.phase.getTickOffset() - redstoneSubPhase.phase.getTickOffset() - 1; + } else { + max = Integer.MAX_VALUE - 5; + } + + List lore = new ArrayList<>(); + int time = redstoneSubPhase.phase.getTickOffset() + (redstoneSubPhase.place ? 0 : redstoneSubPhase.phase.getLifetime()); + if (redstoneSubPhase.place) { + lore.add("§7Time§8:§e " + time); + lore.add("§7Order§8:§e " + redstoneSubPhase.phase.getOrder()); + } else { + lore.add("§7Time§8:§e " + time); + lore.add("§7Activation Time§8:§e " + redstoneSubPhase.phase.getLifetime()); + } + lore.add(""); + lore.add("§7Click§8:§e Edit"); + lore.add("§7Middle-Click§8:§e Remove"); + SWItem redstone = new SWItem(redstoneSubPhase.place ? Material.REDSTONE_BLOCK : Material.STONE, redstoneSubPhase.place ? "§eActivate" : "§eDeactivate", lore, false, clickType -> { + if (clickType == ClickType.MIDDLE) { + this.redstone.getPhases().remove(redstoneSubPhase.phase); + SimulatorWatcher.update(simulator); + } else { + new SimulatorRedstonePhaseSettingsGui(player, simulator, this.redstone, redstoneSubPhase.phase, this).open(); + } + }); + redstone.getItemStack().setAmount(Math.max(1, Math.min(time, 64))); + + Supplier getter = redstoneSubPhase.place ? redstoneSubPhase.phase::getTickOffset : redstoneSubPhase.phase::getLifetime; + Consumer setter = redstoneSubPhase.place ? redstoneSubPhase.phase::setTickOffset : redstoneSubPhase.phase::setLifetime; + return new SWItem[] { + new SWItem(SWItem.getDye(getter.get() < max ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> { + setter.accept(Math.min(max, getter.get() + (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); }), redstone, - new SWItem(SWItem.getDye(redstoneSetting.getTickOffset() > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8:§e -5"), false, clickType -> { - redstoneSetting.setTickOffset(Math.max(0, redstoneSetting.getTickOffset() - (clickType.isShiftClick() ? 5 : 1))); + new SWItem(SWItem.getDye(getter.get() > min ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8:§e -5"), false, clickType -> { + setter.accept(Math.max(min, getter.get() - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); }), new SWItem(Material.ANVIL, "§eEdit Activation", clickType -> { - new SimulatorRedstonePhaseSettingsGui(player, simulator, this.redstone, redstoneSetting, this).open(); + new SimulatorRedstonePhaseSettingsGui(player, simulator, this.redstone, redstoneSubPhase.phase, this).open(); }), }; } @@ -132,7 +185,7 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> { addNewPhase(clickType.isShiftClick()); }), - new SWItem(Material.REDSTONE_BLOCK, "§eRedstone§8:§a New Phase", clickType -> { + new SWItem(Material.REDSTONE, "§eRedstone§8:§a New Phase", clickType -> { addNewPhase(false); }), new SWItem(SWItem.getDye(8), "§7", clickType -> { @@ -142,10 +195,39 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { private void addNewPhase(boolean shift) { RedstonePhase lastElement = redstone.getPhases().get(redstone.getPhases().size() - 1); - RedstonePhase newPhase = new RedstonePhase(lastElement.getTickOffset() + 1); + RedstonePhase newPhase = new RedstonePhase(lastElement.getTickOffset() + lastElement.getLifetime() + 1); if (shift) newPhase.setTickOffset(newPhase.getTickOffset() + 5); - scroll++; + scroll += 2; redstone.add(newPhase); SimulatorWatcher.update(simulator); } + + @AllArgsConstructor + public static class RedstoneSubPhase implements Comparable { + private boolean place; + private RedstonePhase phase; + + @Override + public int compareTo(RedstoneSubPhase o) { + int thisTick = phase.getTickOffset() + (place ? 0 : phase.getLifetime()); + int otherTick = o.phase.getTickOffset() + (o.place ? 0 : o.phase.getLifetime()); + + int compare = Integer.compare(thisTick, otherTick); + if (compare != 0) { + return compare; + } + + if (place && !o.place) { + return -1; + } + if (!place && o.place) { + return 1; + } + if (!place) { + return 0; + } + + return Integer.compare(phase.getOrder(), o.phase.getOrder()); + } + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java index 7b9fc71a..a6d6c944 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java @@ -80,28 +80,44 @@ public class SimulatorTNTGui extends SimulatorScrollGui { } })); + inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> { + tnt.getPhases().clear(); + SimulatorWatcher.update(simulator); + })); + // Material Chooser inventory.setItem(4, tnt.toItem(player, clickType -> { new SimulatorMaterialGui(player, simulator, tnt::getMaterial, tnt::setMaterial, this).open(); })); - inventory.setItem(48, new SWItem(Material.REPEATER, "§eSettings", clickType -> { + inventory.setItem(47, new SWItem(Material.REPEATER, "§eSettings", clickType -> { new SimulatorTNTSettingsGui(player, simulator, tnt, this).open(); })); - inventory.setItem(49, new SWItem(Material.LEAD, "§eMove", clickType -> { + inventory.setItem(48, new SWItem(Material.LEAD, "§eJoin Group", clickType -> { new SimulatorGroupChooserGui(player, simulator, tnt, tnt.getGroup(simulator), this).open(); })); - inventory.setItem(50, new SWItem(tnt.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, tnt.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { + inventory.setItem(50, new SWItem(Material.CHEST, parent.getElements().size() == 1 ? "§eMake Group" : "§eAdd another TNT to Group", clickType -> { + TNTElement tntElement = new TNTElement(tnt.getPosition().clone()); + tntElement.add(new TNTPhase()); + parent.add(tntElement); + new SimulatorGroupGui(player, simulator, parent, new SimulatorGui(player, simulator)).open(); + SimulatorWatcher.update(simulator); + })); + inventory.setItem(51, new SWItem(tnt.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, tnt.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { tnt.setDisabled(!tnt.isDisabled()); SimulatorWatcher.update(simulator); })); } @Override - 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"), "", "§7Middle-Click§8:§e Remove"), false, clickType -> { - if (clickType == ClickType.MIDDLE) this.tnt.getPhases().remove(tntSetting); - SimulatorWatcher.update(simulator); + public SWItem[] column(TNTPhase tntSetting, int index) { + 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"), "", "§7Click§8:§e Edit", "§7Middle-Click§8:§e Remove"), false, clickType -> { + if (clickType == ClickType.MIDDLE) { + this.tnt.getPhases().remove(tntSetting); + SimulatorWatcher.update(simulator); + } else { + new SimulatorTNTPhaseSettingsGui(player, simulator, this.tnt, tntSetting, this).open(); + } }); tnt.getItemStack().setAmount(Math.min(tntSetting.getCount(), 64)); @@ -127,7 +143,7 @@ public class SimulatorTNTGui extends SimulatorScrollGui { new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> { addNewPhase(clickType.isShiftClick()); }), - new SWItem(Material.TNT, "§eTNT§8:§a New Phase", clickType -> { + new SWItem(Material.GUNPOWDER, "§eTNT§8:§a New Phase", clickType -> { addNewPhase(false); }), new SWItem(SWItem.getDye(8), "§7", clickType -> { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorAnvilGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorAnvilGui.java index e492a304..380dc618 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorAnvilGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorAnvilGui.java @@ -25,8 +25,7 @@ import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; -import java.util.Objects; -import java.util.function.Consumer; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Function; public class SimulatorAnvilGui { @@ -37,11 +36,17 @@ public class SimulatorAnvilGui { if (defaultText == null) { anvilInv = new SWAnvilInv(player, title); } else { - anvilInv = new SWAnvilInv(player, title, defaultText); + anvilInv = new SWAnvilInv(player, title + ": " + defaultText); } + AtomicBoolean error = new AtomicBoolean(); anvilInv.addCloseCallback(() -> { Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { - back.open(); + if (error.get()) { + anvilInv.open(); + } else { + back.open(); + } + error.set(false); }, 0); }); anvilInv.setCallback(s -> { @@ -49,15 +54,15 @@ public class SimulatorAnvilGui { try { t = mapper.apply(s); } catch (NumberFormatException e) { - new SimulatorAnvilGui<>(player, title, s, mapper, value, back).open(); + error.set(true); return; } try { if (!value.apply(t)) { - new SimulatorAnvilGui<>(player, title, s, mapper, value, back).open(); + error.set(true); } - } finally { - back.open(); + } catch (Exception e) { + // Ignore } }); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorScrollGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorScrollGui.java index 1c6d30e5..a4cfbb5d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorScrollGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorScrollGui.java @@ -67,7 +67,7 @@ public abstract class SimulatorScrollGui extends SimulatorBaseGui { for (int i = 0; i < 9; i++) { if (scroll + i < data.size()) { T element = data.get(scroll + i); - SWItem[] column = column(element); + SWItem[] column = column(element, scroll + i); populateColumn(column, i); } else { SWItem[] column = lastColumn(); @@ -88,7 +88,7 @@ public abstract class SimulatorScrollGui extends SimulatorBaseGui { } } - public abstract SWItem[] column(T t); + public abstract SWItem[] column(T t, int index); public abstract SWItem[] lastColumn(); }