From e01ac8ac58b31e0fabe449f73609fd400d8f8b82 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 8 Apr 2024 17:20:23 +0200 Subject: [PATCH] Fix TPSSystem --- .../features/script/lua/libs/TpsLib.java | 6 +++- .../features/tpslimit/TPSCommand.java | 6 +++- .../features/tpslimit/TPSSystem.java | 29 ++++++++++--------- .../features/world/BauMemberUpdate.java | 14 --------- 4 files changed, 25 insertions(+), 30 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/TpsLib.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/TpsLib.java index 3b0b430d..1435aa44 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/TpsLib.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/TpsLib.java @@ -22,12 +22,16 @@ package de.steamwar.bausystem.features.script.lua.libs; import de.steamwar.bausystem.features.tpslimit.TPSSystem; import de.steamwar.core.TPSWatcher; import de.steamwar.linkage.Linked; +import de.steamwar.linkage.LinkedInstance; import org.bukkit.entity.Player; import org.luaj.vm2.LuaTable; @Linked public class TpsLib implements LuaLib { + @LinkedInstance + public TPSSystem tpsSystem; + @Override public Class parent() { return ServerLib.class; @@ -47,7 +51,7 @@ public class TpsLib implements LuaLib { tpsLib.set("fiveMinute", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.FIVE_MINUTES))); tpsLib.set("tenMinute", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.TEN_MINUTES))); tpsLib.set("current", getter(TPSWatcher::getTPS)); - tpsLib.set("limit", getter(TPSSystem.getInstance()::getCurrentTPSLimit)); + tpsLib.set("limit", getter(tpsSystem::getCurrentTPSLimit)); return tpsLib; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSCommand.java index a9267761..1b5b51eb 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSCommand.java @@ -23,11 +23,15 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.command.SWCommand; import de.steamwar.core.TPSWatcher; import de.steamwar.linkage.Linked; +import de.steamwar.linkage.LinkedInstance; import org.bukkit.entity.Player; @Linked public class TPSCommand extends SWCommand { + @LinkedInstance + public TPSSystem tpsSystem; + public TPSCommand() { super("tps"); unregister(); @@ -48,6 +52,6 @@ public class TPSCommand extends SWCommand { @Register public void genericCommand(Player p, TPSWatcher.TPSType type) { - BauSystem.MESSAGE.sendPrefixless("OTHER_TPS_SINGLE", p, TPSSystem.getInstance().getTPS(type)); + BauSystem.MESSAGE.sendPrefixless("OTHER_TPS_SINGLE", p, tpsSystem.getTPS(type)); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java index 6de8d252..5cb1e1b6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java @@ -31,13 +31,13 @@ import de.steamwar.bausystem.utils.bossbar.BauSystemBossbar; import de.steamwar.bausystem.utils.bossbar.BossBarService; import de.steamwar.command.AbstractSWCommand; import de.steamwar.command.SWCommand; -import de.steamwar.command.TypeValidator; import de.steamwar.core.Core; import de.steamwar.core.TPSWarpUtils; import de.steamwar.core.TPSWatcher; import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWItem; import de.steamwar.linkage.Linked; +import de.steamwar.linkage.LinkedInstance; import lombok.Getter; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -56,16 +56,11 @@ public class TPSSystem implements Listener { @Getter private double currentTPSLimit = 20; - @Getter - private static TPSSystem instance; - public double getTPS(TPSWatcher.TPSType tpsType) { return TPSWatcher.getTPSUnlimited(tpsType); } public TPSSystem() { - instance = this; - if (TPSFreezeUtils.isCanFreeze()) { new TPSFreezeCommand(); new TickFreezeCommand(); @@ -312,6 +307,9 @@ public class TPSSystem implements Listener { @Linked public static class TPSScoreboardElement implements ScoreboardElement { + @LinkedInstance + public TPSSystem tpsSystem; + @Override public ScoreboardGroup getGroup() { return ScoreboardGroup.FOOTER; @@ -324,7 +322,7 @@ public class TPSSystem implements Listener { @Override public String get(Region region, Player p) { - if (TPSSystem.getInstance() != null && TPSSystem.getInstance().currentlyStepping) { + if (tpsSystem != null && tpsSystem.currentlyStepping) { long time = System.currentTimeMillis() % 1000; if (time < 250) { return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TPS", p) + "§8: §7•••"; @@ -338,39 +336,42 @@ public class TPSSystem implements Listener { } else if (TPSFreezeUtils.frozen()) { return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TPS", p) + "§8: " + BauSystem.MESSAGE.parse("SCOREBOARD_TPS_FROZEN", p); } else { - return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TPS", p) + "§8: " + tpsColor() + TPSSystem.getInstance().getTPS(TPSWatcher.TPSType.ONE_SECOND) + tpsLimit(); + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TPS", p) + "§8: " + tpsColor() + tpsSystem.getTPS(TPSWatcher.TPSType.ONE_SECOND) + tpsLimit(); } } private String tpsColor() { - double tps = TPSSystem.getInstance().getTPS(TPSWatcher.TPSType.ONE_SECOND); - if (tps > TPSSystem.getInstance().getCurrentTPSLimit() * 0.9) { + double tps = tpsSystem.getTPS(TPSWatcher.TPSType.ONE_SECOND); + if (tps > tpsSystem.getCurrentTPSLimit() * 0.9) { return "§a"; } - if (tps > TPSSystem.getInstance().getCurrentTPSLimit() * 0.5) { + if (tps > tpsSystem.getCurrentTPSLimit() * 0.5) { return "§e"; } return "§c"; } private String tpsLimit() { - if (TPSSystem.getInstance().getCurrentTPSLimit() == 20) { + if (tpsSystem.getCurrentTPSLimit() == 20) { return ""; } - return "§8/§7" + TPSSystem.getInstance().getCurrentTPSLimit(); + return "§8/§7" + tpsSystem.getCurrentTPSLimit(); } } @Linked public static class TPSSystemBauGuiItem extends BauGuiItem { + @LinkedInstance + public TPSSystem tpsSystem; + public TPSSystemBauGuiItem() { super(19); } @Override public ItemStack getItem(Player player) { - return new SWItem(Material.CLOCK, BauSystem.MESSAGE.parse("TPSLIMIT_GUI_ITEM_NAME", player), Arrays.asList(BauSystem.MESSAGE.parse("TPSLIMIT_GUI_ITEM_LORE", player, TPSSystem.getInstance().currentTPSLimit)), false, clickType -> { + return new SWItem(Material.CLOCK, BauSystem.MESSAGE.parse("TPSLIMIT_GUI_ITEM_NAME", player), Arrays.asList(BauSystem.MESSAGE.parse("TPSLIMIT_GUI_ITEM_LORE", player, tpsSystem.currentTPSLimit)), false, clickType -> { }).getItemStack(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauMemberUpdate.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauMemberUpdate.java index 46c10ef1..d5aa97d5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauMemberUpdate.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauMemberUpdate.java @@ -25,7 +25,6 @@ import de.steamwar.bausystem.region.GlobalRegion; import de.steamwar.bausystem.utils.BauMemberUpdateEvent; import de.steamwar.bausystem.utils.bossbar.BauSystemBossbar; import de.steamwar.bausystem.utils.bossbar.BossBarService; -import de.steamwar.command.SWCommand; import de.steamwar.linkage.Linked; import de.steamwar.network.packets.PacketHandler; import de.steamwar.network.packets.server.BaumemberUpdatePacket; @@ -132,17 +131,4 @@ public class BauMemberUpdate extends PacketHandler implements Listener { } }, 1); } - - @Linked - public static class TestCommand extends SWCommand { // TODO: Remove before merge - - public TestCommand() { - super("test"); - } - - @Register - public void test(Player player) { - PacketHandler.handlePacket(new BaumemberUpdatePacket()); - } - } }