SteamWar/BauSystem2.0
Archiviert
12
0

Add starting of TNTSimulator
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2022-06-11 16:53:49 +02:00
Ursprung 11ae4721f6
Commit 9155bd7070
6 geänderte Dateien mit 63 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -83,7 +83,7 @@ public class SimulatorCommand extends SWCommand {
BauSystem.MESSAGE.send("SIMULATOR_NOT_EXISTS", p);
return;
}
// SimulatorStorage.start(name);
tntSimulator.start();
}
@Mapper("simulators")

Datei anzeigen

@ -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<Integer, Map<Integer, Set<Pair<Runnable, Integer>>>> 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<Pair<Integer, Set<Pair<Runnable, Integer>>>> 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<Integer, Set<Pair<Runnable, Integer>>> pair : elements) {
Map<Runnable, Integer> counts = new HashMap<>();
pair.getValue().forEach(runnableIntegerPair -> {
counts.put(runnableIntegerPair.getKey(), runnableIntegerPair.getValue());
});
List<Runnable> 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);
});
}
}

Datei anzeigen

@ -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:

Datei anzeigen

@ -47,7 +47,7 @@ public interface SimulatorElement {
void hide(SimulatorEntityShowMode showMode);
SWItem menu(Player p);
void locations(Map<Integer, Map<Integer, Pair<Runnable, Integer>>> result); // Ticks to subtick order to spawning runnable to count of activations
void locations(Map<Integer, Map<Integer, Set<Pair<Runnable, Integer>>>> result); // Ticks to subtick order to spawning runnable to count of activations
// Observer
default void change() {

Datei anzeigen

@ -163,10 +163,11 @@ public class TNTElement implements SimulatorElement {
}
@Override
public void locations(Map<Integer, Map<Integer, Pair<Runnable, Integer>>> result) {
public void locations(Map<Integer, Map<Integer, Set<Pair<Runnable, Integer>>>> 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));

Datei anzeigen

@ -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<Integer, Map<Integer, Pair<Runnable, Integer>>> result) {
public void locations(Map<Integer, Map<Integer, Set<Pair<Runnable, Integer>>>> result) {
if (disabled) return;
elements.forEach(tntElement -> {
tntElement.locations(result);