forked from SteamWar/SteamWar
Add BauSystem module
Fix ci java version Fix LinkageProcessor
This commit is contained in:
+131
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.features.tpslimit;
|
||||
|
||||
import com.comphenix.tinyprotocol.Reflection;
|
||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||
import de.steamwar.core.BountifulWrapper;
|
||||
import de.steamwar.core.ChatWrapper;
|
||||
import de.steamwar.core.Core;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@UtilityClass
|
||||
class PacketCache {
|
||||
|
||||
private static List<Object> packets = new ArrayList<>();
|
||||
private static Set<Entity> entities = new HashSet<>();
|
||||
private static BukkitTask task = null;
|
||||
|
||||
private static Class<?> vec3dClass = Reflection.getClass("{nms.world.phys}.Vec3D");
|
||||
private static Reflection.FieldAccessor<Object> zeroVec3d = (Reflection.FieldAccessor<Object>) Reflection.getField(vec3dClass, vec3dClass, 0);
|
||||
private static Object ZERO_VEC3D = zeroVec3d.get(null);
|
||||
private static Class<?> velocityPacketClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityVelocity");
|
||||
private static Reflection.ConstructorInvoker velocityPacketConstructor = Reflection.getConstructor(velocityPacketClass, int.class, vec3dClass);
|
||||
|
||||
private static Class<?> teleportPacketClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityTeleport");
|
||||
private static Class<?> entityClass = Reflection.getClass("{nms.world.entity}.Entity");
|
||||
private static Reflection.ConstructorInvoker teleportPacketConstructor = Reflection.getConstructor(teleportPacketClass, entityClass);
|
||||
|
||||
private static Class<?> craftEntityClass = Reflection.getClass("{obc}.entity.CraftEntity");
|
||||
private static Reflection.MethodInvoker getHandle = Reflection.getMethod(craftEntityClass, "getHandle");
|
||||
|
||||
private static Object noGravityDataWatcher = BountifulWrapper.impl.getDataWatcherObject(5, Boolean.class);
|
||||
private static Object fuseDataWatcher = BountifulWrapper.impl.getDataWatcherObject(8, Integer.class);
|
||||
|
||||
public void continuousSendCache() {
|
||||
if (task != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
createPackets();
|
||||
task = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
_sendCache();
|
||||
}
|
||||
}.runTaskTimer(Core.getInstance(), 1, 1);
|
||||
}
|
||||
|
||||
public void sendCache() {
|
||||
if (task != null) {
|
||||
task.cancel();
|
||||
task = null;
|
||||
}
|
||||
_sendCache();
|
||||
}
|
||||
|
||||
private void _sendCache() {
|
||||
createPackets();
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
for (Object packet : packets) {
|
||||
TinyProtocol.instance.sendPacket(player, packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void clearCache() {
|
||||
packets.clear();
|
||||
entities.clear();
|
||||
|
||||
if (task != null) {
|
||||
task.cancel();
|
||||
task = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void createPackets() {
|
||||
if (entities.stream().anyMatch(Entity::isDead)) {
|
||||
entities.clear();
|
||||
packets.clear();
|
||||
}
|
||||
List<Entity> entities = Bukkit.getWorlds().get(0).getEntities().stream()
|
||||
.filter(e -> !(e instanceof Player))
|
||||
.filter(e -> PacketCache.entities.add(e))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
for (Entity entity : entities) {
|
||||
packets.add(teleportPacketConstructor.invoke(getHandle.invoke(entity)));
|
||||
}
|
||||
for (Entity entity : entities) {
|
||||
packets.add(velocityPacketConstructor.invoke(entity.getEntityId(), ZERO_VEC3D));
|
||||
}
|
||||
for (Entity entity : entities) {
|
||||
packets.add(ChatWrapper.impl.getDataWatcherPacket(entity.getEntityId(), noGravityDataWatcher, true));
|
||||
}
|
||||
for (Entity entity : entities) {
|
||||
if (!(entity instanceof TNTPrimed)) continue;
|
||||
TNTPrimed tnt = (TNTPrimed) entity;
|
||||
int fuse = tnt.getFuseTicks();
|
||||
packets.add(ChatWrapper.impl.getDataWatcherPacket(entity.getEntityId(), fuseDataWatcher, fuse - (fuse % 5) + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.features.tpslimit;
|
||||
|
||||
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();
|
||||
register();
|
||||
}
|
||||
|
||||
@Register
|
||||
public void genericCommand(Player p, String... args) {
|
||||
BauSystem.MESSAGE.sendPrefixless("OTHER_TPS_HEAD", p);
|
||||
BauSystem.MESSAGE.sendPrefixless("OTHER_TPS_MESSAGE", p,
|
||||
TPSWatcher.getTPS(TPSWatcher.TPSType.ONE_SECOND),
|
||||
TPSWatcher.getTPS(TPSWatcher.TPSType.TEN_SECONDS),
|
||||
TPSWatcher.getTPS(TPSWatcher.TPSType.ONE_MINUTE),
|
||||
TPSWatcher.getTPS(TPSWatcher.TPSType.FIVE_MINUTES),
|
||||
TPSWatcher.getTPS(TPSWatcher.TPSType.TEN_MINUTES)
|
||||
);
|
||||
}
|
||||
|
||||
@Register
|
||||
public void genericCommand(Player p, TPSWatcher.TPSType type) {
|
||||
BauSystem.MESSAGE.sendPrefixless("OTHER_TPS_SINGLE", p, tpsSystem.getTPS(type));
|
||||
}
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.features.tpslimit;
|
||||
|
||||
import com.comphenix.tinyprotocol.Reflection;
|
||||
import lombok.Getter;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
|
||||
@UtilityClass
|
||||
public class TPSFreezeUtils {
|
||||
|
||||
private static Reflection.FieldAccessor<Boolean> fieldAccessor;
|
||||
@Getter
|
||||
private static final boolean canFreeze;
|
||||
|
||||
private static final Reflection.MethodInvoker getWorldHandle = Reflection.getTypedMethod(Reflection.getClass("{obc}.CraftWorld"), "getHandle", null);
|
||||
|
||||
@Getter
|
||||
private static boolean frozen = false;
|
||||
|
||||
private static final World world = Bukkit.getWorlds().get(0);
|
||||
|
||||
static {
|
||||
Reflection.FieldAccessor<Boolean> fieldAccessor;
|
||||
try {
|
||||
fieldAccessor = Reflection.getField(Reflection.getClass("{nms.server.level}.WorldServer"), "freezed", boolean.class);
|
||||
} catch (IllegalArgumentException e) {
|
||||
fieldAccessor = null;
|
||||
}
|
||||
canFreeze = fieldAccessor != null;
|
||||
TPSFreezeUtils.fieldAccessor = fieldAccessor;
|
||||
}
|
||||
|
||||
public void freeze() {
|
||||
setFreeze(world, true);
|
||||
}
|
||||
|
||||
public void unfreeze() {
|
||||
setFreeze(world, false);
|
||||
}
|
||||
|
||||
public boolean frozen() {
|
||||
return canFreeze && frozen;
|
||||
}
|
||||
|
||||
private void setFreeze(World world, boolean state) {
|
||||
if (canFreeze) {
|
||||
fieldAccessor.set(getWorldHandle.invoke(world), state);
|
||||
if (state) {
|
||||
PacketCache.continuousSendCache();
|
||||
} else {
|
||||
PacketCache.clearCache();
|
||||
}
|
||||
frozen = state;
|
||||
}
|
||||
}
|
||||
}
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2020 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.features.tpslimit;
|
||||
|
||||
import com.comphenix.tinyprotocol.Reflection;
|
||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||
import de.steamwar.bausystem.SWUtils;
|
||||
import de.steamwar.bausystem.utils.PlayerMovementWrapper;
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.core.TPSWatcher;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
@UtilityClass
|
||||
public class TPSLimitUtils {
|
||||
|
||||
private static long currentTime = System.nanoTime();
|
||||
private static BukkitTask tpsLimiter = null;
|
||||
private static Queue<Runnable> packetQueue = new ConcurrentLinkedQueue<>();
|
||||
|
||||
public void unlimit() {
|
||||
if (tpsLimiter != null) tpsLimiter.cancel();
|
||||
tpsLimiter = null;
|
||||
}
|
||||
|
||||
public void limit(double tps) {
|
||||
if (tpsLimiter != null) tpsLimiter.cancel();
|
||||
|
||||
double delay = 20 / tps;
|
||||
int loops = (int) Math.ceil(delay);
|
||||
long sleepDelay = (long) (50 * delay) / loops;
|
||||
|
||||
tpsLimiter = Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> {
|
||||
PacketCache.sendCache();
|
||||
for (int i = 0; i < loops; i++) {
|
||||
sleepUntilNextTick(sleepDelay);
|
||||
PacketCache.sendCache();
|
||||
while (true) {
|
||||
Runnable runnable = packetQueue.poll();
|
||||
if (runnable == null) break;
|
||||
runnable.run();
|
||||
}
|
||||
}
|
||||
PacketCache.clearCache();
|
||||
}, 0, 1);
|
||||
}
|
||||
|
||||
private void sleepUntilNextTick(long neededDelta) {
|
||||
long lastTime = currentTime;
|
||||
currentTime = System.nanoTime();
|
||||
|
||||
long timeDelta = (currentTime - lastTime) / 1000000;
|
||||
if (neededDelta - timeDelta < 0) return;
|
||||
|
||||
try {
|
||||
Thread.sleep(neededDelta - timeDelta);
|
||||
currentTime = System.nanoTime();
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
static {
|
||||
long timeInterval = 50;
|
||||
final long[] lastTime = {System.currentTimeMillis()};
|
||||
final double[] tps = {20.0};
|
||||
Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
if (currentTime > lastTime[0]) {
|
||||
tps[0] = (double)timeInterval / (double)(currentTime - lastTime[0]) * 20.0;
|
||||
}
|
||||
|
||||
lastTime[0] = currentTime;
|
||||
|
||||
Bukkit.getOnlinePlayers().forEach(player -> {
|
||||
SWUtils.sendToActionbar(player, String.valueOf((int) (tps[0] * 10.0) / 10.0));
|
||||
});
|
||||
}, timeInterval / 50L, timeInterval / 50L);
|
||||
}
|
||||
*/
|
||||
|
||||
private static final Class<?> position = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPosition");
|
||||
private static final Class<?> positionLook = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPositionLook");
|
||||
static {
|
||||
BiFunction<Player, Object, Object> positionSetter = (player, o) -> {
|
||||
if (tpsLimiter != null) {
|
||||
Object object = PlayerMovementWrapper.impl.convertToOut(player, o);
|
||||
packetQueue.add(() -> {
|
||||
PlayerMovementWrapper.impl.setPosition(player, o);
|
||||
Bukkit.getOnlinePlayers().forEach(p -> {
|
||||
if (p == player) return;
|
||||
TinyProtocol.instance.sendPacket(p, object);
|
||||
});
|
||||
});
|
||||
return null;
|
||||
}
|
||||
return o;
|
||||
};
|
||||
TinyProtocol.instance.addFilter(position, positionSetter);
|
||||
TinyProtocol.instance.addFilter(positionLook, positionSetter);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,393 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.features.tpslimit;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.bausystem.SWUtils;
|
||||
import de.steamwar.bausystem.linkage.specific.BauGuiItem;
|
||||
import de.steamwar.bausystem.region.GlobalRegion;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.utils.ScoreboardElement;
|
||||
import de.steamwar.bausystem.utils.TickEndEvent;
|
||||
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.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;
|
||||
import org.bukkit.boss.BarColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@Linked
|
||||
public class TPSSystem implements Listener {
|
||||
|
||||
@Getter
|
||||
private double currentTPSLimit = 20;
|
||||
|
||||
public double getTPS(TPSWatcher.TPSType tpsType) {
|
||||
return TPSWatcher.getTPSUnlimited(tpsType);
|
||||
}
|
||||
|
||||
public TPSSystem() {
|
||||
if (TPSFreezeUtils.isCanFreeze()) {
|
||||
new TPSFreezeCommand();
|
||||
new TickFreezeCommand();
|
||||
new TickStepCommand();
|
||||
}
|
||||
new TPSLimitCommand();
|
||||
new TickLimitCommand();
|
||||
if (Core.getVersion() >= 15 && Core.getVersion() <= 20) { // If 1.21 support is not directly present
|
||||
new TPSWarpCommand();
|
||||
new TickWarpCommand();
|
||||
if (TPSFreezeUtils.isCanFreeze()) {
|
||||
new TickWarpingCommand();
|
||||
}
|
||||
}
|
||||
new TPSDefaultCommand();
|
||||
new TickDefaultCommand();
|
||||
new TPSBaseCommand();
|
||||
new TickBaseCommand();
|
||||
}
|
||||
|
||||
private void setTPS(double tps) {
|
||||
if (currentlyStepping) {
|
||||
currentlyStepping = false;
|
||||
Bukkit.getOnlinePlayers().forEach(player -> {
|
||||
BossBarService.instance.remove(player, GlobalRegion.getInstance(), "TickStep");
|
||||
});
|
||||
}
|
||||
TPSWarpUtils.warp(tps);
|
||||
if (currentTPSLimit == 0 && tps != 0) {
|
||||
TPSFreezeUtils.unfreeze();
|
||||
}
|
||||
currentTPSLimit = tps;
|
||||
if (tps == 0) {
|
||||
TPSLimitUtils.unlimit();
|
||||
TPSFreezeUtils.freeze();
|
||||
} else if (tps < 20.0) {
|
||||
TPSLimitUtils.limit(tps);
|
||||
} else if (tps >= 20) {
|
||||
TPSLimitUtils.unlimit();
|
||||
}
|
||||
|
||||
Bukkit.getOnlinePlayers().forEach(player -> {
|
||||
if (currentTPSLimit == 0) {
|
||||
SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("TPSLIMIT_FROZEN", player));
|
||||
} else {
|
||||
SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("TPSLIMIT_SET", player, currentTPSLimit));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean currentlyStepping = false;
|
||||
private double currentLimit;
|
||||
private int stepsTotal;
|
||||
private int stepsLeft;
|
||||
|
||||
private void setSkip(int steps, double tpsLimitToUse) {
|
||||
currentLimit = tpsLimitToUse == 20 ? 0 : currentTPSLimit;
|
||||
setTPS(tpsLimitToUse);
|
||||
stepsLeft = steps;
|
||||
stepsTotal = steps;
|
||||
currentlyStepping = true;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onTickEnd(TickEndEvent event) {
|
||||
if (!currentlyStepping) return;
|
||||
if (stepsTotal > 1) {
|
||||
Bukkit.getOnlinePlayers().forEach(player -> {
|
||||
BauSystemBossbar bossbar = BossBarService.instance.get(player, GlobalRegion.getInstance(), "TickStep");
|
||||
bossbar.setColor(BarColor.YELLOW);
|
||||
bossbar.setTitle(BauSystem.MESSAGE.parse("TICK_BOSSBAR", player, (stepsTotal - stepsLeft), stepsTotal));
|
||||
bossbar.setProgress((stepsTotal - stepsLeft) / (double) stepsTotal);
|
||||
});
|
||||
}
|
||||
stepsLeft--;
|
||||
if (stepsLeft <= 0) {
|
||||
setTPS(currentLimit);
|
||||
}
|
||||
}
|
||||
|
||||
private class TPSBaseCommand extends SWCommand {
|
||||
|
||||
private TPSBaseCommand() {
|
||||
super("tpslimit");
|
||||
setMessage(BauSystem.MESSAGE);
|
||||
addDefaultHelpMessage("TPSLIMIT_HELP");
|
||||
}
|
||||
}
|
||||
|
||||
@AbstractSWCommand.PartOf(TPSBaseCommand.class)
|
||||
private class TPSFreezeCommand extends SWCommand {
|
||||
|
||||
private TPSFreezeCommand() {
|
||||
super("");
|
||||
}
|
||||
|
||||
@Register(value = "0", description = "TPSLIMIT_FREEZE_HELP")
|
||||
public void freeze(@Validator Player player) {
|
||||
setTPS(0);
|
||||
}
|
||||
}
|
||||
|
||||
@AbstractSWCommand.PartOf(TPSBaseCommand.class)
|
||||
private class TPSLimitCommand extends SWCommand {
|
||||
|
||||
private TPSLimitCommand() {
|
||||
super("");
|
||||
}
|
||||
|
||||
@Register(description = "TPSLIMIT_LIMIT_HELP")
|
||||
public void limit(@Validator Player player, @Min(doubleValue = 0.5) @Max(doubleValue = 20.0) double tpsLimit) {
|
||||
setTPS(tpsLimit);
|
||||
}
|
||||
}
|
||||
|
||||
@AbstractSWCommand.PartOf(TPSBaseCommand.class)
|
||||
private class TPSWarpCommand extends SWCommand {
|
||||
|
||||
private TPSWarpCommand() {
|
||||
super("");
|
||||
}
|
||||
|
||||
@Register(description = "TPSLIMIT_WARP_HELP")
|
||||
public void warp(@Validator Player player, @Min(doubleValue = 20.0, inclusive = false) double tpsLimit) {
|
||||
setTPS(tpsLimit);
|
||||
}
|
||||
}
|
||||
|
||||
@AbstractSWCommand.PartOf(TPSBaseCommand.class)
|
||||
private class TPSDefaultCommand extends SWCommand {
|
||||
|
||||
private TPSDefaultCommand() {
|
||||
super("");
|
||||
}
|
||||
|
||||
@Register(description = "TPSLIMIT_HELP")
|
||||
public void currentLimit(Player player) {
|
||||
BauSystem.MESSAGE.send("TPSLIMIT_CURRENT", player, currentTPSLimit);
|
||||
}
|
||||
|
||||
@Register(value = "default", description = "TPSLIMIT_DEFAULT_HELP")
|
||||
public void reset(@Validator Player player) {
|
||||
setTPS(20);
|
||||
}
|
||||
}
|
||||
|
||||
private class TickBaseCommand extends SWCommand {
|
||||
|
||||
public TickBaseCommand() {
|
||||
super("tick");
|
||||
setMessage(BauSystem.MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
@AbstractSWCommand.PartOf(TickBaseCommand.class)
|
||||
private class TickFreezeCommand extends SWCommand {
|
||||
|
||||
private TickFreezeCommand() {
|
||||
super("");
|
||||
}
|
||||
|
||||
@Register(value = {"rate", "0"}, description = "TICK_FREEZE_HELP")
|
||||
@Register(value = "freeze", description = "TICK_FREEZE_HELP_2")
|
||||
public void freeze(@Validator Player player) {
|
||||
setTPS(0);
|
||||
}
|
||||
|
||||
@Register(value = "unfreeze", description = "TICK_UNFREEZE_HELP")
|
||||
public void unfreeze(@Validator Player player) {
|
||||
setTPS(20);
|
||||
}
|
||||
}
|
||||
|
||||
@AbstractSWCommand.PartOf(TickBaseCommand.class)
|
||||
private class TickStepCommand extends SWCommand {
|
||||
|
||||
public TickStepCommand() {
|
||||
super("");
|
||||
}
|
||||
|
||||
@Register(value = "step", description = "TICK_STEPPING_HELP")
|
||||
public void step(@Validator Player player, @Min(intValue = 1) @OptionalValue("1") int steps) {
|
||||
setSkip(steps, 20);
|
||||
}
|
||||
}
|
||||
|
||||
@AbstractSWCommand.PartOf(TickBaseCommand.class)
|
||||
private class TickWarpingCommand extends SWCommand {
|
||||
|
||||
public TickWarpingCommand() {
|
||||
super("");
|
||||
}
|
||||
|
||||
@Register(value = "warp", description = "TICK_WARPING_HELP")
|
||||
public void warp(@Validator Player player, @Min(intValue = 1) @OptionalValue("1") int steps, @Min(doubleValue = 20) @OptionalValue("4000") double tps) {
|
||||
setSkip(steps, tps);
|
||||
}
|
||||
}
|
||||
|
||||
@AbstractSWCommand.PartOf(TickBaseCommand.class)
|
||||
private class TickLimitCommand extends SWCommand {
|
||||
|
||||
private TickLimitCommand() {
|
||||
super("");
|
||||
}
|
||||
|
||||
@Register(value = "rate", description = "TICK_LIMIT_HELP")
|
||||
public void limit(@Validator Player player, @Min(doubleValue = 0.5, inclusive = false) @Max(doubleValue = 20.0) double tpsLimit) {
|
||||
setTPS(tpsLimit);
|
||||
}
|
||||
}
|
||||
|
||||
@AbstractSWCommand.PartOf(TickBaseCommand.class)
|
||||
private class TickWarpCommand extends SWCommand {
|
||||
|
||||
private TickWarpCommand() {
|
||||
super("");
|
||||
}
|
||||
|
||||
@Register(value = "rate", description = "TICK_WARP_HELP")
|
||||
public void warp(@Validator Player player, @Min(doubleValue = 20.0, inclusive = false) double tpsLimit) {
|
||||
setTPS(tpsLimit);
|
||||
}
|
||||
}
|
||||
|
||||
@AbstractSWCommand.PartOf(TickBaseCommand.class)
|
||||
private class TickDefaultCommand extends SWCommand {
|
||||
|
||||
private TickDefaultCommand() {
|
||||
super("");
|
||||
}
|
||||
|
||||
@Register(value = "rate", description = "TICK_HELP")
|
||||
public void currentLimit(Player player) {
|
||||
BauSystem.MESSAGE.send("TPSLIMIT_CURRENT", player, currentTPSLimit);
|
||||
}
|
||||
|
||||
@Register(value = {"rate", "default"}, description = "TICK_DEFAULT_HELP")
|
||||
public void reset(@Validator Player player) {
|
||||
setTPS(20);
|
||||
}
|
||||
}
|
||||
|
||||
@Linked
|
||||
public static class TPSScoreboardElement implements ScoreboardElement {
|
||||
|
||||
@LinkedInstance
|
||||
public TPSSystem tpsSystem;
|
||||
|
||||
@Override
|
||||
public ScoreboardGroup getGroup() {
|
||||
return ScoreboardGroup.FOOTER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int order() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get(Region region, Player p) {
|
||||
if (tpsSystem != null && tpsSystem.currentlyStepping) {
|
||||
long time = System.currentTimeMillis() % 1000;
|
||||
if (time < 250) {
|
||||
return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TPS", p) + "§8: §7•••";
|
||||
} else if (time < 500) {
|
||||
return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TPS", p) + "§8: §e•§7••";
|
||||
} else if (time < 750) {
|
||||
return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TPS", p) + "§8: §7•§e•§7•";
|
||||
} else {
|
||||
return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TPS", p) + "§8: §7••§e•";
|
||||
}
|
||||
} 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.getTPS(TPSWatcher.TPSType.ONE_SECOND) + tpsLimit();
|
||||
}
|
||||
}
|
||||
|
||||
private String tpsColor() {
|
||||
double tps = tpsSystem.getTPS(TPSWatcher.TPSType.ONE_SECOND);
|
||||
if (tps > tpsSystem.getCurrentTPSLimit() * 0.9) {
|
||||
return "§a";
|
||||
}
|
||||
if (tps > tpsSystem.getCurrentTPSLimit() * 0.5) {
|
||||
return "§e";
|
||||
}
|
||||
return "§c";
|
||||
}
|
||||
|
||||
private String tpsLimit() {
|
||||
if (tpsSystem.getCurrentTPSLimit() == 20) {
|
||||
return "";
|
||||
}
|
||||
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.currentTPSLimit)), false, clickType -> {
|
||||
}).getItemStack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean click(ClickType click, Player p) {
|
||||
p.closeInventory();
|
||||
SWAnvilInv inv = new SWAnvilInv(p, BauSystem.MESSAGE.parse("TPSLIMIT_ANVIL_GUI", p));
|
||||
inv.setItem(Material.CLOCK);
|
||||
inv.setCallback(s -> p.performCommand("tpslimit " + s));
|
||||
inv.open();
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Permission permission() {
|
||||
return Permission.BUILD;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.features.tpslimit;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@UtilityClass
|
||||
public class TPSUtils {
|
||||
|
||||
private static long ticksSinceServerStart = 0;
|
||||
public static final Supplier<Long> currentTick = () -> ticksSinceServerStart; // This is intended as Supplier<Long>
|
||||
|
||||
private static long realTicksSinceServerStart = 0;
|
||||
public static final Supplier<Long> currentRealTick = () -> realTicksSinceServerStart; // This is intended as Supplier<Long>
|
||||
|
||||
static {
|
||||
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> ticksSinceServerStart++, 1, 1);
|
||||
BauSystem.runTaskTimer(BauSystem.getInstance(), () -> realTicksSinceServerStart++, 1, 1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user