From 1804dbc27d2bc6765a8be510d841e90ddb5527cd Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 15 Jun 2022 17:29:34 +0200 Subject: [PATCH] Fix sorting Signed-off-by: yoyosource --- .../bausystem/features/simulator/gui/TNTSimulatorGui.java | 2 ++ .../bausystem/features/simulator/tnt/SimulatorElement.java | 1 + .../bausystem/features/simulator/tnt/TNTElement.java | 5 +++++ .../steamwar/bausystem/features/simulator/tnt/TNTGroup.java | 5 +++++ 4 files changed, 13 insertions(+) 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 a9e53d3f..ac413908 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 @@ -36,6 +36,7 @@ import org.bukkit.util.Vector; import java.util.ArrayList; import java.util.Arrays; +import java.util.Comparator; import java.util.List; import java.util.function.Supplier; @@ -58,6 +59,7 @@ public class TNTSimulatorGui { swListEntryList.add(new SWListInv.SWListEntry<>(element.menu(player), element)); totalTNTCount += element.tntCount(); } + swListEntryList.sort(Comparator.comparing(o -> o.getObject().tick())); SWListInv inv = new SWListInv<>(player, BauSystem.MESSAGE.parse("SIMULATOR_GUI_NAME", player), false, swListEntryList, (clickType, simulatorElement) -> { if (simulatorElement instanceof TNTGroup) { 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 02692209..10ce5cd2 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 @@ -51,6 +51,7 @@ public interface SimulatorElement { SWItem menu(Player p); boolean locations(Map>>> result, Region region, Location location); // Ticks to subtick order to spawning runnable to count of activations int tntCount(); + int tick(); // Observer default void change() { 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 dd5ff1d4..7e122fff 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 @@ -203,6 +203,11 @@ public class TNTElement implements SimulatorElement { return disabled ? 0 : count; } + @Override + public int tick() { + return getTickOffset(); + } + public void setCount(int count) { if (count < 0) count = 1; if (count > 400) count = 400; 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 2951c1fb..47254fee 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 @@ -157,6 +157,11 @@ public class TNTGroup implements SimulatorElement { return elements.stream().mapToInt(TNTElement::tntCount).sum(); } + @Override + public int tick() { + return getTickOffset(); + } + public void setTickOffset(int tickOffset) { if (tickOffset < 0) tickOffset = 0; if (tickOffset > 400) tickOffset = 400;