SteamWar/BauSystem2.0
Archiviert
12
0

Update 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 20:51:25 +02:00
Ursprung 9155bd7070
Commit 9ee33e8dcb

Datei anzeigen

@ -41,6 +41,7 @@ import yapion.hierarchy.types.YAPIONType;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
@Getter
@ -222,38 +223,42 @@ public class TNTSimulator {
}
});
AtomicInteger maxTick = new AtomicInteger(0);
Map<Integer, List<List<Pair<Runnable, Integer>>>> toSpawn = new HashMap<>();
result.forEach((integer, integerSetMap) -> {
List<Pair<Integer, Set<Pair<Runnable, Integer>>>> elements = new ArrayList<>();
integerSetMap.forEach((integer2, set) -> {
elements.add(new Pair<>(integer2, set));
List<Pair<Integer, Set<Pair<Runnable, Integer>>>> internal = new ArrayList<>();
integerSetMap.forEach((integer1, pairs) -> {
internal.add(new Pair<>(integer1, pairs));
});
elements.sort(Comparator.comparingInt(Pair::getKey));
internal.sort(Comparator.comparingInt(Pair::getKey));
toSpawn.put(integer, internal.stream().map(Pair::getValue).map(ArrayList::new).peek(Collections::shuffle).collect(Collectors.toList()));
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);
if (maxTick.get() < integer) {
maxTick.set(integer);
}
});
AtomicInteger currentTick = new AtomicInteger(0);
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), bukkitTask -> {
int tick = currentTick.get();
List<List<Pair<Runnable, Integer>>> toSpawnInTick = toSpawn.get(tick);
if (toSpawnInTick == null) return;
toSpawnInTick.forEach(pairs -> {
AtomicBoolean hasSomeLeft = new AtomicBoolean(true);
while(hasSomeLeft.get()) {
hasSomeLeft.set(false);
pairs.forEach(pair -> {
if (pair.getValue() > 0) {
hasSomeLeft.set(true);
pair.getKey().run();
pair.setValue(pair.getValue() - 1);
}
});
}
});
if (tick > maxTick.get()) bukkitTask.cancel();
currentTick.incrementAndGet();
}, 1, 1);
}
}