From 7b7e10d6cc91fbe28e85115e346bf0fa1f084d74 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 8 Mar 2021 10:56:22 +0100 Subject: [PATCH] Move RedstoneListener.tick to TPSUtils for AutostartTime --- .../bausystem/world/RedstoneListener.java | 19 ++++++------------- .../de/steamwar/bausystem/world/TPSUtils.java | 10 ++++++++++ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java index e905f35..db8dca1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java @@ -21,7 +21,6 @@ package de.steamwar.bausystem.world; import de.steamwar.bausystem.BauSystem; import de.steamwar.inventory.SWItem; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -45,14 +44,6 @@ import java.util.Map; public class RedstoneListener implements Listener { - private static long currentTick = 0; - - static { - Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> { - currentTick++; - }, 1, 1); - } - private static class RedstoneTester { private final Player player; @@ -72,17 +63,17 @@ public class RedstoneListener implements Listener { return; } if (loc1.equals(location)) { - if (currentTick - lastTick > 100) { + if (TPSUtils.currentTick.get() - lastTick > 100) { tick = null; } - lastTick = currentTick; + lastTick = TPSUtils.currentTick.get(); if (tick == null) { - tick = currentTick; + tick = TPSUtils.currentTick.get(); } return; } 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(); sendLocation(event.getPlayer(), "POS2", block.getLocation()); break; + default: + break; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/TPSUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/world/TPSUtils.java index 563e01a..aca15f6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/TPSUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/TPSUtils.java @@ -26,6 +26,8 @@ import de.steamwar.core.TPSWatcher; import de.steamwar.core.VersionedRunnable; import org.bukkit.Bukkit; +import java.util.function.Supplier; + public class TPSUtils { private TPSUtils() { @@ -36,12 +38,20 @@ public class TPSUtils { private static long nanoOffset = 0; private static long nanoDOffset = 0; + private static long ticksSinceServerStart = 0; + @SuppressWarnings("java:S4276") + public static final Supplier currentTick = () -> ticksSinceServerStart; + public static void init() { VersionedRunnable.call(new VersionedRunnable(() -> warp = false, 8), new VersionedRunnable(() -> { Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> nanoOffset += nanoDOffset, 1, 1); TPSUtils_15.init(() -> nanoOffset); }, 15)); + + Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> { + ticksSinceServerStart++; + }, 1, 1); } public static void setTPS(double tps) {