SteamWar/BauSystem
Archiviert
13
0

Move RedstoneListener.tick to TPSUtils for AutostartTime

Dieser Commit ist enthalten in:
yoyosource 2021-03-08 10:56:22 +01:00
Ursprung 8922dd440c
Commit 7b7e10d6cc
2 geänderte Dateien mit 16 neuen und 13 gelöschten Zeilen

Datei anzeigen

@ -21,7 +21,6 @@ package de.steamwar.bausystem.world;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWItem;
import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@ -45,14 +44,6 @@ import java.util.Map;
public class RedstoneListener implements Listener { public class RedstoneListener implements Listener {
private static long currentTick = 0;
static {
Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> {
currentTick++;
}, 1, 1);
}
private static class RedstoneTester { private static class RedstoneTester {
private final Player player; private final Player player;
@ -72,17 +63,17 @@ public class RedstoneListener implements Listener {
return; return;
} }
if (loc1.equals(location)) { if (loc1.equals(location)) {
if (currentTick - lastTick > 100) { if (TPSUtils.currentTick.get() - lastTick > 100) {
tick = null; tick = null;
} }
lastTick = currentTick; lastTick = TPSUtils.currentTick.get();
if (tick == null) { if (tick == null) {
tick = currentTick; tick = TPSUtils.currentTick.get();
} }
return; return;
} }
if (tick != null && loc2.equals(location)) { if (tick != null && loc2.equals(location)) {
player.sendMessage(BauSystem.PREFIX + "Differenz§8: §e" + (currentTick - tick) + "§8 - §7in GameTicks"); player.sendMessage(BauSystem.PREFIX + "Differenz§8: §e" + (TPSUtils.currentTick.get() - tick) + "§8 - §7in GameTicks");
} }
} }
@ -115,6 +106,8 @@ public class RedstoneListener implements Listener {
playerMap.computeIfAbsent(event.getPlayer(), RedstoneTester::new).loc2 = block.getLocation(); playerMap.computeIfAbsent(event.getPlayer(), RedstoneTester::new).loc2 = block.getLocation();
sendLocation(event.getPlayer(), "POS2", block.getLocation()); sendLocation(event.getPlayer(), "POS2", block.getLocation());
break; break;
default:
break;
} }
} }

Datei anzeigen

@ -26,6 +26,8 @@ import de.steamwar.core.TPSWatcher;
import de.steamwar.core.VersionedRunnable; import de.steamwar.core.VersionedRunnable;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import java.util.function.Supplier;
public class TPSUtils { public class TPSUtils {
private TPSUtils() { private TPSUtils() {
@ -36,12 +38,20 @@ public class TPSUtils {
private static long nanoOffset = 0; private static long nanoOffset = 0;
private static long nanoDOffset = 0; private static long nanoDOffset = 0;
private static long ticksSinceServerStart = 0;
@SuppressWarnings("java:S4276")
public static final Supplier<Long> currentTick = () -> ticksSinceServerStart;
public static void init() { public static void init() {
VersionedRunnable.call(new VersionedRunnable(() -> warp = false, 8), VersionedRunnable.call(new VersionedRunnable(() -> warp = false, 8),
new VersionedRunnable(() -> { new VersionedRunnable(() -> {
Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> nanoOffset += nanoDOffset, 1, 1); Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> nanoOffset += nanoDOffset, 1, 1);
TPSUtils_15.init(() -> nanoOffset); TPSUtils_15.init(() -> nanoOffset);
}, 15)); }, 15));
Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> {
ticksSinceServerStart++;
}, 1, 1);
} }
public static void setTPS(double tps) { public static void setTPS(double tps) {