diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java index c82c3273..ec7d535f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java @@ -83,7 +83,7 @@ public class SimulatorCommand extends SWCommand { BauSystem.MESSAGE.send("SIMULATOR_NOT_EXISTS", p); return; } - // SimulatorStorage.start(name); + tntSimulator.start(); } @Mapper("simulators") 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 57af3266..275ecab9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java @@ -19,13 +19,18 @@ package de.steamwar.bausystem.features.simulator; +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.configplayer.Config; import de.steamwar.bausystem.features.simulator.gui.TNTElementGUI; import de.steamwar.bausystem.features.simulator.gui.TNTSimulatorGui; import de.steamwar.bausystem.features.simulator.show.SimulatorEntityShowMode; import de.steamwar.bausystem.features.simulator.tnt.SimulatorElement; import de.steamwar.bausystem.features.simulator.tnt.TNTElement; import de.steamwar.bausystem.features.simulator.tnt.TNTGroup; +import de.steamwar.bausystem.features.tracer.record.RecordStateMachine; +import de.steamwar.bausystem.shared.Pair; import lombok.Getter; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -35,6 +40,7 @@ import yapion.hierarchy.types.YAPIONObject; import yapion.hierarchy.types.YAPIONType; import java.util.*; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; @Getter @@ -201,4 +207,53 @@ public class TNTSimulator { show(p); }); } + + public void start() { + Map>>> result = new HashMap<>(); + for (SimulatorElement element : tntElementList) { + element.locations(result); + } + + playerShowMode.forEach((player, simulatorEntityShowMode) -> { + boolean simulatorAutoTrace = Config.getInstance().get(player).getPlainValueOrDefault("simulatorAutoTrace", false); + if (simulatorAutoTrace) { + RecordStateMachine.commandSingle(); + player.performCommand("trace show"); + } + }); + + result.forEach((integer, integerSetMap) -> { + List>>> elements = new ArrayList<>(); + integerSetMap.forEach((integer2, set) -> { + elements.add(new Pair<>(integer2, set)); + }); + elements.sort(Comparator.comparingInt(Pair::getKey)); + + + Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { + for (Pair>> pair : elements) { + Map counts = new HashMap<>(); + pair.getValue().forEach(runnableIntegerPair -> { + counts.put(runnableIntegerPair.getKey(), runnableIntegerPair.getValue()); + }); + List order = new ArrayList<>(); + counts.forEach((runnable, integer1) -> { + order.add(runnable); + }); + Collections.shuffle(order); + + while (!counts.isEmpty()) { + for (Runnable runnable : order) { + if (counts.get(runnable) == 0) { + counts.remove(runnable); + continue; + } + runnable.run(); + counts.put(runnable, counts.get(runnable) - 1); + } + } + } + }, integer); + }); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java index e084493a..12e7f57f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java @@ -139,7 +139,7 @@ public class TNTSimulatorListener implements Listener { if (simulator == null) { return; } - System.out.println("Left click"); + simulator.start(); break; case RIGHT_CLICK_BLOCK: case RIGHT_CLICK_AIR: 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 fe44129c..501eb1fd 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 @@ -47,7 +47,7 @@ public interface SimulatorElement { void hide(SimulatorEntityShowMode showMode); SWItem menu(Player p); - void locations(Map>> result); // Ticks to subtick order to spawning runnable to count of activations + void locations(Map>>> result); // Ticks to subtick order to spawning runnable to count of activations // 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 2061a34c..011c4445 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 @@ -163,10 +163,11 @@ public class TNTElement implements SimulatorElement { } @Override - public void locations(Map>> result) { + public void locations(Map>>> result) { if (disabled) return; result.computeIfAbsent(getTickOffset(), ignore -> new HashMap<>()) - .computeIfAbsent(OrderUtils.order(order), ignore -> new Pair<>(() -> { + .computeIfAbsent(OrderUtils.order(order), ignore -> new HashSet<>()) + .add(new Pair<>(() -> { SimulatorStorage.WORLD.spawn(getPosition().toLocation(SimulatorStorage.WORLD), TNTPrimed.class, tntPrimed -> { tntPrimed.setFuseTicks(fuseTicks); if (!xVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setX(0)); 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 59cfa9d3..9ae10591 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 @@ -34,6 +34,7 @@ import yapion.hierarchy.types.YAPIONObject; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.stream.Collectors; @Getter @@ -136,7 +137,7 @@ public class TNTGroup implements SimulatorElement { } @Override - public void locations(Map>> result) { + public void locations(Map>>> result) { if (disabled) return; elements.forEach(tntElement -> { tntElement.locations(result);