SteamWar/BauSystem2.0
Archiviert
12
0

Fix tpslimit 0 with all necessary features
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2023-06-20 17:56:26 +02:00
Ursprung a317891685
Commit 6c6b17eb30
19 geänderte Dateien mit 97 neuen und 48 gelöschten Zeilen

Datei anzeigen

@ -21,6 +21,10 @@ package de.steamwar.bausystem;
import com.comphenix.tinyprotocol.TinyProtocol;
import de.steamwar.bausystem.configplayer.Config;
import de.steamwar.bausystem.features.tpslimit.FreezeUtils;
import de.steamwar.bausystem.features.tpslimit.TPSLimitUtils;
import de.steamwar.bausystem.features.tpslimit.TPSUtils;
import de.steamwar.bausystem.features.tpslimit.TPSWarpUtils;
import de.steamwar.bausystem.features.world.RamUsage;
import de.steamwar.bausystem.region.loader.PrototypeLoader;
import de.steamwar.bausystem.region.loader.RegionLoader;
@ -32,11 +36,16 @@ import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.logging.Level;
public class BauSystem extends JavaPlugin implements Listener {
@ -123,4 +132,45 @@ public class BauSystem extends JavaPlugin implements Listener {
}
}));
}
public static BukkitTask runTaskLater(Plugin plugin, Runnable runnable, long delay) {
return new BukkitRunnable() {
private int counter = 1;
@Override
public void run() {
if (FreezeUtils.isFrozen()) return;
if (counter >= delay) {
runnable.run();
cancel();
return;
}
counter++;
}
}.runTaskTimer(plugin, 0, 1);
}
public static BukkitTask runTaskTimer(Plugin plugin, Runnable runnable, long delay, long period) {
return new BukkitRunnable() {
private int counter = 1;
private boolean first = true;
@Override
public void run() {
if (FreezeUtils.isFrozen()) return;
if (counter >= (first ? delay : period)) {
first = false;
runnable.run();
counter = 1;
return;
}
counter++;
}
}.runTaskTimer(plugin, 0, 1);
}
public static void runTaskTimer(Plugin plugin, Consumer<BukkitTask> consumer, long delay, long period) {
AtomicReference<BukkitTask> task = new AtomicReference<>();
task.set(runTaskTimer(plugin, () -> consumer.accept(task.get()), delay, period));
}
}

Datei anzeigen

@ -88,7 +88,7 @@ public class AutostartListener implements Listener {
} else {
BauSystem.MESSAGE.send("AUTOSTART_MESSAGE_START", player);
}
regionStartTime.put(region, TPSUtils.currentTick.get());
regionStartTime.put(region, TPSUtils.currentRealTick.get());
}
@EventHandler
@ -101,7 +101,7 @@ public class AutostartListener implements Listener {
if (!regionStartTime.containsKey(region)) return;
if (!region.hasType(RegionType.TESTBLOCK)) return;
if (!region.inRegion(block.getLocation(), RegionType.TESTBLOCK, RegionExtensionType.EXTENSION)) return;
long tickDiff = TPSUtils.currentTick.get() - regionStartTime.remove(region);
long tickDiff = TPSUtils.currentRealTick.get() - regionStartTime.remove(region);
RegionUtils.message(region, player -> {
return BauSystem.MESSAGE.parse("AUTOSTART_MESSAGE_RESULT1", player, new SimpleDateFormat(BauSystem.MESSAGE.parse("AUTOSTART_MESSAGE_DATE_PATTERN", player)).format(new Date(tickDiff * 50)));
});

Datei anzeigen

@ -72,7 +72,7 @@ public class CannonDetector implements Listener {
return;
}
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
BauSystem.runTaskLater(BauSystem.getInstance(), () -> {
Map<CannonKey, List<TNTPrimed>> grouped = new HashMap<>();
velocities.forEach((tntPrimed, vector) -> {
grouped.computeIfAbsent(new CannonKey(round(tntPrimed.getLocation().toVector()), round(vector)), ignored -> new ArrayList<>()).add(tntPrimed);

Datei anzeigen

@ -71,7 +71,7 @@ public class Loader implements Listener {
if (currentElement >= elements.size()) {
currentElement = 0;
if (totalDelay == 0) {
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), this::next, 1);
BauSystem.runTaskLater(BauSystem.getInstance(), this::next, 1);
return;
}
totalDelay = 0;

Datei anzeigen

@ -46,7 +46,7 @@ public class LoaderRecorder implements Listener {
private Player player;
private List<LoaderElement> loaderElementList;
private long lastInteraction = TPSUtils.currentTick.get();
private long lastInteraction = TPSUtils.currentRealTick.get();
public LoaderRecorder(Player player, List<LoaderElement> loaderElementList) {
this.player = player;
@ -63,15 +63,15 @@ public class LoaderRecorder implements Listener {
private void addWaitTime(boolean last) {
if (loaderElementList.isEmpty()) {
lastInteraction = TPSUtils.currentTick.get();
lastInteraction = TPSUtils.currentRealTick.get();
return;
}
if (loaderElementList.get(loaderElementList.size() - 1) instanceof LoaderWait) {
return;
}
long diff = TPSUtils.currentTick.get() - lastInteraction;
long diff = TPSUtils.currentRealTick.get() - lastInteraction;
if (last && diff > 160) diff = 160;
lastInteraction = TPSUtils.currentTick.get();
lastInteraction = TPSUtils.currentRealTick.get();
loaderElementList.add(new LoaderWait(diff));
}
@ -165,10 +165,10 @@ public class LoaderRecorder implements Listener {
Long startTime = blockSet.remove(fromBlock.getLocation());
LoaderMovement loaderMovement = movementSet.remove(fromBlock.getLocation());
if (loaderMovement != null && startTime != null) {
loaderMovement.setInitialTicks(TPSUtils.currentTick.get() - startTime);
loaderMovement.setInitialTicks(TPSUtils.currentRealTick.get() - startTime);
}
blockSet.put(toBlock.getLocation(), TPSUtils.currentTick.get());
blockSet.put(toBlock.getLocation(), TPSUtils.currentRealTick.get());
addWaitTime(false);
loaderMovement = null;

Datei anzeigen

@ -112,7 +112,7 @@ public class LoaderMovement extends LoaderInteractionElement<LoaderMovement.Move
if (ticks >= 0) {
boolean finalWaitFor = waitFor;
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
BauSystem.runTaskLater(BauSystem.getInstance(), () -> {
if (blockData instanceof AnaloguePowerable) {
AnaloguePowerable analoguePowerable = (AnaloguePowerable) blockData;
analoguePowerable.setPower(0);

Datei anzeigen

@ -49,7 +49,7 @@ public class LoaderTNT implements LoaderElement {
public void execute(Runnable nextAction) {
Block block = location.getBlock();
if (block.getType() != Material.AIR && block.getType() != Material.WATER) {
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> execute(nextAction), 1);
BauSystem.runTaskLater(BauSystem.getInstance(), () -> execute(nextAction), 1);
return;
}

Datei anzeigen

@ -87,7 +87,7 @@ public class LoaderTicks extends LoaderInteractionElement<LoaderTicks.TicksSetti
update(powerable);
boolean finalWaitFor = waitFor;
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
BauSystem.runTaskLater(BauSystem.getInstance(), () -> {
powerable.setPowered(false);
location.getBlock().setBlockData(powerable, true);
update(powerable);

Datei anzeigen

@ -58,7 +58,7 @@ public class LoaderWait implements LoaderElement, Listener {
nextAction.run();
return;
}
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), nextAction, delay);
BauSystem.runTaskLater(BauSystem.getInstance(), nextAction, delay);
}
@Override

Datei anzeigen

@ -65,9 +65,9 @@ public class Loadtimer implements Listener {
this.region = region;
this.stage = Stage.WAITING;
Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance());
task = Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {
task = BauSystem.runTaskTimer(BauSystem.getInstance(), () -> {
if (stage == Stage.COUNTING) {
long timeSinceStart = TPSUtils.currentTick.get() - start;
long timeSinceStart = TPSUtils.currentRealTick.get() - start;
long timeSinceHalf = timeSinceStart / 2;
double timeSec = (timeSinceStart / 20d);
String sec = new DecimalFormat("#.#").format(timeSec);
@ -119,7 +119,7 @@ public class Loadtimer implements Listener {
public void onTntPlace(BlockPlaceEvent event) {
if (stage == Stage.WAITING) {
this.stage = Stage.COUNTING;
this.start = TPSUtils.currentTick.get();
this.start = TPSUtils.currentRealTick.get();
}
if (stage == Stage.COUNTING) {
@ -146,9 +146,9 @@ public class Loadtimer implements Listener {
public void onTntSpawn() {
if ((stage == Stage.COUNTING || stage == Stage.ACTIVATED)) {
stage = Stage.IGNITION;
ignite = TPSUtils.currentTick.get();
ignite = TPSUtils.currentRealTick.get();
if (activate == -1)
activate = TPSUtils.currentTick.get();
activate = TPSUtils.currentRealTick.get();
if (finishOnActive) {
stage = Stage.END;
print();
@ -160,14 +160,14 @@ public class Loadtimer implements Listener {
public void onTntExplode(EntityExplodeEvent event) {
if (region.inRegion(event.getLocation(), RegionType.BUILD, RegionExtensionType.EXTENSION) && stage == Stage.IGNITION) {
stage = Stage.END;
explode = TPSUtils.currentTick.get();
explode = TPSUtils.currentRealTick.get();
print();
delete();
}
}
private void setActivate() {
activate = TPSUtils.currentTick.get();
activate = TPSUtils.currentRealTick.get();
stage = Stage.ACTIVATED;
if (finishOnActive) {
print();

Datei anzeigen

@ -89,18 +89,18 @@ public class RedstonetesterUtils {
tick = null;
return;
}
if (TPSUtils.currentTick.get() - lastTick > 100) {
if (TPSUtils.currentRealTick.get() - lastTick > 100) {
tick = null;
}
if (loc1.equals(location)) {
lastTick = TPSUtils.currentTick.get();
lastTick = TPSUtils.currentRealTick.get();
if (tick == null) {
tick = TPSUtils.currentTick.get();
tick = TPSUtils.currentRealTick.get();
}
return;
}
if (tick != null && loc2.equals(location)) {
BauSystem.MESSAGE.send("RT_RESULT", player, (TPSUtils.currentTick.get() - tick), ((TPSUtils.currentTick.get() - tick) / 2.0));
BauSystem.MESSAGE.send("RT_RESULT", player, (TPSUtils.currentRealTick.get() - tick), ((TPSUtils.currentRealTick.get() - tick) / 2.0));
}
}

Datei anzeigen

@ -23,7 +23,6 @@ import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.utils.bossbar.BauSystemBossbar;
import de.steamwar.bausystem.utils.bossbar.BossBarService;
import de.steamwar.bausystem.utils.bossbar.RegionedBossbar;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@ -38,13 +37,9 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockFormEvent;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.block.EntityBlockFormEvent;
import org.bukkit.event.entity.EntityAirChangeEvent;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
@ -57,7 +52,7 @@ public class ShieldPrinting implements Listener {
private static final World WORLD = Bukkit.getWorlds().get(0);
static {
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {
BauSystem.runTaskTimer(BauSystem.getInstance(), () -> {
ShieldPrintingCommand.SHIELD_PRINTING_MAP.values().forEach(shieldPrinting -> {
shieldPrinting.fallingBlocks.replaceAll((entity, location) -> {
if (entity.isDead()) return null;

Datei anzeigen

@ -245,7 +245,7 @@ public class TNTSimulator {
});
AtomicInteger currentTick = new AtomicInteger(0);
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), bukkitTask -> {
BauSystem.runTaskTimer(BauSystem.getInstance(), bukkitTask -> {
int tick = currentTick.get();
if (tick > maxTick.get()) bukkitTask.cancel();
currentTick.incrementAndGet();

Datei anzeigen

@ -40,18 +40,18 @@ public class BlockCount {
private Region region;
private int count = 0;
private int tntCount = 0;
private final long tick = TPSUtils.currentTick.get();
private final long tick = TPSUtils.currentRealTick.get();
private long lastUpdate = TPSUtils.currentTick.get();
private long lastUpdate = TPSUtils.currentRealTick.get();
public BlockCount(Region region) {
this.region = region;
if (bukkitTask == null) {
bukkitTask = Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {
bukkitTask = BauSystem.runTaskTimer(BauSystem.getInstance(), () -> {
Set<Region> toRemove = new HashSet<>();
for (BlockCount blockCount : BlockCounter.blockCountMap.values()) {
if (TPSUtils.currentTick.get() - blockCount.lastUpdate < 60) {
if (TPSUtils.currentRealTick.get() - blockCount.lastUpdate < 60) {
continue;
}
toRemove.add(blockCount.region);
@ -74,6 +74,6 @@ public class BlockCount {
public void update(List<Block> blocks) {
count += blocks.size();
tntCount++;
lastUpdate = TPSUtils.currentTick.get();
lastUpdate = TPSUtils.currentRealTick.get();
}
}

Datei anzeigen

@ -31,7 +31,11 @@ public class TPSUtils {
private static long ticksSinceServerStart = 0;
public static final Supplier<Long> currentTick = () -> ticksSinceServerStart; // This is intended as Supplier<Long>
private static long realTicksSinceServerStart = 0;
public static final Supplier<Long> currentRealTick = () -> realTicksSinceServerStart; // This is intended as Supplier<Long>
static {
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> ticksSinceServerStart++, 1, 1);
BauSystem.runTaskTimer(BauSystem.getInstance(), () -> realTicksSinceServerStart++, 1, 1);
}
}

Datei anzeigen

@ -32,7 +32,7 @@ import java.util.function.Supplier;
public abstract class AutoTraceRecorder implements TraceRecorder {
protected boolean recording = false;
private long startTime = TPSUtils.currentTick.get();
private long startTime = TPSUtils.currentRealTick.get();
private long lastExplosion = 0;
private final Map<TNTPrimed, Record.TNTRecord> recordMap = new HashMap<>();
@ -40,7 +40,7 @@ public abstract class AutoTraceRecorder implements TraceRecorder {
private Supplier<Record> recordSupplier;
private Record.TNTRecord getRecord(TNTPrimed tntPrimed) {
return recordMap.computeIfAbsent(tntPrimed, __ -> record.spawn(TPSUtils.currentTick.get() - startTime));
return recordMap.computeIfAbsent(tntPrimed, __ -> record.spawn(TPSUtils.currentRealTick.get() - startTime));
}
protected abstract String getInactivityMessage();
@ -51,7 +51,7 @@ public abstract class AutoTraceRecorder implements TraceRecorder {
@Override
public final String scoreboard(Player player) {
if (recording) {
return BauSystem.MESSAGE.parse("TRACE_RECORD", player) + " §8| §e" + (TPSUtils.currentTick.get() - startTime) + " §7" + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE_TICKS", player);
return BauSystem.MESSAGE.parse("TRACE_RECORD", player) + " §8| §e" + (TPSUtils.currentRealTick.get() - startTime) + " §7" + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE_TICKS", player);
} else {
return BauSystem.MESSAGE.parse(getInactivityMessage(), player);
}
@ -59,7 +59,7 @@ public abstract class AutoTraceRecorder implements TraceRecorder {
private void startRecording() {
lastExplosion = 0;
startTime = TPSUtils.currentTick.get();
startTime = TPSUtils.currentRealTick.get();
record = recordSupplier.get();
recording = true;
}
@ -130,6 +130,6 @@ public abstract class AutoTraceRecorder implements TraceRecorder {
@Override
public long scriptTime() {
return TPSUtils.currentTick.get() - startTime;
return TPSUtils.currentRealTick.get() - startTime;
}
}

Datei anzeigen

@ -129,7 +129,7 @@ public class Recorder implements Listener {
}
{
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {
BauSystem.runTaskTimer(BauSystem.getInstance(), () -> {
tick();
tntTraceRecorderMap.keySet()
.stream()

Datei anzeigen

@ -31,13 +31,13 @@ import java.util.function.Supplier;
public class SimpleTraceRecorder implements TraceRecorder, ActiveTracer {
private final long startTime = TPSUtils.currentTick.get();
private final long startTime = TPSUtils.currentRealTick.get();
private final Map<TNTPrimed, Record.TNTRecord> recordMap = new HashMap<>();
private Record record;
@Override
public String scoreboard(Player player) {
return BauSystem.MESSAGE.parse("TRACE_RECORD", player) + " §8| §e" + (TPSUtils.currentTick.get() - startTime) + " §7" + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE_TICKS", player);
return BauSystem.MESSAGE.parse("TRACE_RECORD", player) + " §8| §e" + (TPSUtils.currentRealTick.get() - startTime) + " §7" + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE_TICKS", player);
}
@Override
@ -51,7 +51,7 @@ public class SimpleTraceRecorder implements TraceRecorder, ActiveTracer {
}
private Record.TNTRecord getRecord(TNTPrimed tntPrimed) {
return recordMap.computeIfAbsent(tntPrimed, __ -> record.spawn(TPSUtils.currentTick.get() - startTime));
return recordMap.computeIfAbsent(tntPrimed, __ -> record.spawn(TPSUtils.currentRealTick.get() - startTime));
}
@Override
@ -79,6 +79,6 @@ public class SimpleTraceRecorder implements TraceRecorder, ActiveTracer {
@Override
public long scriptTime() {
return TPSUtils.currentTick.get() - startTime;
return TPSUtils.currentRealTick.get() - startTime;
}
}

Datei anzeigen

@ -42,7 +42,7 @@ public class StoredRecords {
private static final Map<Region, List<Record>> records = new HashMap<>();
static {
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {
BauSystem.runTaskTimer(BauSystem.getInstance(), () -> {
replayLoops.forEach((region, playerSupplierMap) -> {
playerSupplierMap.forEach((player, integerSupplier) -> {
int tick = integerSupplier.get();