SteamWar/BauSystem2.0
Archiviert
12
0

Fix TPSSystem
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2024-04-08 17:20:23 +02:00
Ursprung 7ece12de47
Commit e01ac8ac58
4 geänderte Dateien mit 25 neuen und 30 gelöschten Zeilen

Datei anzeigen

@ -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<? extends LuaLib> 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;
}
}

Datei anzeigen

@ -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));
}
}

Datei anzeigen

@ -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();
}

Datei anzeigen

@ -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());
}
}
}