diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index f5415457..ee3a1402 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -40,6 +40,7 @@ SCOREBOARD_REGION = Region SCOREBOARD_TRACE = Trace SCOREBOARD_LOADER = Loader SCOREBOARD_TPS = TPS +SCOREBOARD_TPS_FROZEN = §e Eingefroren SCOREBOARD_TRACE_TICKS = Ticks diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/FreezeUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/FreezeUtils.java index 75703f76..e0d5804d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/FreezeUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/FreezeUtils.java @@ -19,8 +19,10 @@ package de.steamwar.bausystem.features.tpslimit; +import lombok.Getter; import lombok.experimental.UtilityClass; import net.minecraft.server.v1_15_R1.WorldServer; +import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; import yapion.utils.ReflectionsUtils; @@ -33,37 +35,35 @@ public class FreezeUtils { private static final Field field; public static final boolean freezeEnabled; + @Getter + private static boolean frozen = false; + + private static final World world; + static { field = ReflectionsUtils.getField(WorldServer.class, "freezed"); if (field != null) field.setAccessible(true); freezeEnabled = field != null; + world = Bukkit.getWorlds().get(0); } - public static void freeze(World world) { + public static void freeze() { setFreeze(world, true); } - public static void unfreeze(World world) { + public static void unfreeze() { setFreeze(world, false); } - public static boolean frozen(World world) { - if (freezeEnabled) { - try { - return (boolean) field.get(((CraftWorld) world).getHandle()); - } catch (IllegalAccessException e) { - // Ignored; - } - } - return false; + public static boolean frozen() { + return freezeEnabled && frozen; } private void setFreeze(World world, boolean state) { if (freezeEnabled) { try { - System.out.println(state + " " + frozen(world)); field.set(((CraftWorld) world).getHandle(), state); - System.out.println(state + " " + frozen(world)); + frozen = state; } catch (IllegalAccessException e) { // Ignored; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitCommand.java index 042ba479..a5a849e1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitCommand.java @@ -75,7 +75,7 @@ public class TPSLimitCommand extends SWCommand implements Enable { public void valueCommand(Player p, /*@DoubleRange(min = 0.5, max = 60)*/ double tpsLimitDouble) { if (!permissionCheck(p)) return; if (FreezeUtils.freezeEnabled && tpsLimitDouble == 0) { - FreezeUtils.freeze(p.getWorld()); + FreezeUtils.freeze(); TPSLimitUtils.currentTPSLimit = 20; TPSLimitUtils.tpsLimiter(); sendNewTPSLimitMessage(true); @@ -85,7 +85,7 @@ public class TPSLimitCommand extends SWCommand implements Enable { sendInvalidArgumentMessage(p); return; } - FreezeUtils.unfreeze(p.getWorld()); + FreezeUtils.unfreeze(); TPSLimitUtils.currentTPSLimit = tpsLimitDouble; TPSLimitUtils.tpsLimiter(); sendNewTPSLimitMessage(false); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TickCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TickCommand.java index 556ef5e3..b7dff9a1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TickCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TickCommand.java @@ -72,11 +72,9 @@ public class TickCommand extends SWCommand { Bukkit.getOnlinePlayers().forEach(player -> { SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("TICK_STEP", player, ticks)); }); - FreezeUtils.unfreeze(p.getWorld()); + FreezeUtils.unfreeze(); ticksLeft = new AtomicInteger(ticks); - disableTask = () -> { - FreezeUtils.freeze(p.getWorld()); - }; + disableTask = FreezeUtils::freeze; } @Register(value = {"warp"}, description = "TICK_WARP_HELP") @@ -87,16 +85,16 @@ public class TickCommand extends SWCommand { Bukkit.getOnlinePlayers().forEach(player -> { SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("TICK_WARP", player, ticks)); }); - boolean frozen = FreezeUtils.frozen(p.getWorld()); + boolean frozen = FreezeUtils.frozen(); double currentTPSLimit = TPSLimitUtils.currentTPSLimit; - TPSLimitUtils.currentTPSLimit = 120; + TPSLimitUtils.currentTPSLimit = 240; TPSLimitUtils.tpsLimiter(); - FreezeUtils.unfreeze(p.getWorld()); + FreezeUtils.unfreeze(); ticksLeft = new AtomicInteger(ticks); disableTask = () -> { if (frozen) { - FreezeUtils.freeze(p.getWorld()); + FreezeUtils.freeze(); } TPSLimitUtils.currentTPSLimit = currentTPSLimit; TPSLimitUtils.tpsLimiter(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java index 17865922..eb3144d2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java @@ -2,6 +2,7 @@ package de.steamwar.bausystem.features.world; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.loader.Loader; +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; @@ -85,7 +86,11 @@ public class BauScoreboard implements Listener { strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_LOADER", p) + "§8: " + BauSystem.MESSAGE.parse(loader != null ? loader.getStage().getChatValue() : "LOADER_OFF", p)); strings.add("§5"); - strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TPS", p) + "§8 " + tpsColor() + TPSWarpUtils.getTps(TPSWatcher.TPSType.ONE_SECOND) + tpsLimit()); + if (FreezeUtils.frozen()) { + strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TPS", p) + BauSystem.MESSAGE.parse("SCOREBOARD_TPS_FROZEN", p)); + } else { + strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TPS", p) + "§8 " + tpsColor() + TPSWarpUtils.getTps(TPSWatcher.TPSType.ONE_SECOND) + tpsLimit()); + } int i = strings.size(); HashMap result = new HashMap<>();