§ Colors are now ChatColors
CodeCleanup Implementation of Redstonetester
Dieser Commit ist enthalten in:
Ursprung
8c5edd8cfe
Commit
e2f0658f36
@ -36,7 +36,7 @@ import java.util.List;
|
||||
@Linked(LinkageType.COMMAND)
|
||||
public class TimeCommand extends SWCommand {
|
||||
|
||||
private static List<String> tabCompletions = Arrays.asList("0", "6000", "12000", "18000");
|
||||
private static final List<String> tabCompletions = Arrays.asList("0", "6000", "12000", "18000");
|
||||
|
||||
public TimeCommand() {
|
||||
super("time");
|
||||
@ -80,6 +80,7 @@ public class TimeCommand extends SWCommand {
|
||||
}, s -> tabCompletions);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public enum Time {
|
||||
NIGHT(18000),
|
||||
DAY(6000),
|
||||
|
@ -31,7 +31,7 @@ import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
@Linked(LinkageType.COMMAND)
|
||||
public class WorldSpawnCommand extends SWCommand {
|
||||
|
||||
private final World WORLD = Bukkit.getWorlds().get(0);
|
||||
private static final World WORLD = Bukkit.getWorlds().get(0);
|
||||
|
||||
public WorldSpawnCommand() {
|
||||
super("worldspawn");
|
||||
|
@ -43,9 +43,7 @@ public class RedstonetesterCommand extends SWCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(Player p) {
|
||||
VersionedRunnable.call(new VersionedRunnable(() -> {
|
||||
p.sendMessage(BauSystem.PREFIX + "Der RedstoneTester ist nicht in der 1.12 verfügbar");
|
||||
}, 8), new VersionedRunnable(() -> {
|
||||
VersionedRunnable.call(new VersionedRunnable(() -> p.sendMessage(BauSystem.PREFIX + "Der RedstoneTester ist nicht in der 1.12 verfügbar"), 8), new VersionedRunnable(() -> {
|
||||
p.sendMessage(BauSystem.PREFIX + "Messe die Zeit zwischen der Aktivierung zweier Redstone Komponenten");
|
||||
SWUtils.giveItemToPlayer(p, RedstonetesterUtils.WAND);
|
||||
}, 15));
|
||||
|
@ -82,17 +82,17 @@ public class RedstonetesterUtils {
|
||||
return;
|
||||
}
|
||||
if (loc1.equals(location)) {
|
||||
if (TPSUtils.currentTick.get() - lastTick > 100) {
|
||||
if (TPSUtils.currentTick.getAsLong() - lastTick > 100) {
|
||||
tick = null;
|
||||
}
|
||||
lastTick = TPSUtils.currentTick.get();
|
||||
lastTick = TPSUtils.currentTick.getAsLong();
|
||||
if (tick == null) {
|
||||
tick = TPSUtils.currentTick.get();
|
||||
tick = TPSUtils.currentTick.getAsLong();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (tick != null && loc2.equals(location)) {
|
||||
player.sendMessage(BauSystem.PREFIX + "Differenz" + ChatColor.DARK_GRAY + ": " + ChatColor.YELLOW + (TPSUtils.currentTick.get() - tick) + ChatColor.DARK_GRAY + " - " + ChatColor.GRAY + "in Ticks " + ChatColor.DARK_GRAY + "(" + ChatColor.GRAY + "Ticks/2 -> Redstoneticks" + ChatColor.DARK_GRAY + ")");
|
||||
player.sendMessage(BauSystem.PREFIX + "Differenz" + ChatColor.DARK_GRAY + ": " + ChatColor.YELLOW + (TPSUtils.currentTick.getAsLong() - tick) + ChatColor.DARK_GRAY + " - " + ChatColor.GRAY + "in Ticks " + ChatColor.DARK_GRAY + "(" + ChatColor.GRAY + "Ticks/2 -> Redstoneticks" + ChatColor.DARK_GRAY + ")");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,14 +44,11 @@ public class TPSLimitCommand extends SWCommand {
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private static TPSLimitCommand instance = null;
|
||||
|
||||
{
|
||||
instance = this;
|
||||
}
|
||||
|
||||
private List<String> tabCompletions = new ArrayList<>(Arrays.asList("0,5", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"));
|
||||
private final List<String> tabCompletions = new ArrayList<>(Arrays.asList("0,5", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"));
|
||||
|
||||
public TPSLimitCommand() {
|
||||
super("tpslimit");
|
||||
instance = this;
|
||||
if (TPSWarpUtils.isWarpAllowed()) {
|
||||
for (int i = 20; i <= 60; i += 5) {
|
||||
tabCompletions.add(i + "");
|
||||
@ -96,6 +93,7 @@ public class TPSLimitCommand extends SWCommand {
|
||||
}, s -> tabCompletions);
|
||||
}
|
||||
|
||||
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
||||
private boolean permissionCheck(Player player) {
|
||||
if (!Permission.hasPermission(player, Permission.WORLD)) {
|
||||
player.sendMessage(BauSystem.PREFIX + ChatColor.RED + "Du darfst hier nicht den TPS-Limiter nutzen");
|
||||
|
@ -32,19 +32,15 @@ public class TPSLimitUtils {
|
||||
private static final World WORLD = Bukkit.getWorlds().get(0);
|
||||
static double currentTPSLimit = 20;
|
||||
|
||||
private long lastTime = System.nanoTime();
|
||||
private long currentTime = System.nanoTime();
|
||||
|
||||
private double delay = 0;
|
||||
private int loops = 0;
|
||||
private long sleepDelay = 0;
|
||||
|
||||
private BukkitTask tpsLimiter = null;
|
||||
|
||||
void tpsLimiter() {
|
||||
delay = 20 / currentTPSLimit;
|
||||
loops = (int) Math.ceil(delay);
|
||||
sleepDelay = (long) (50 * delay) / loops;
|
||||
double delay = 20 / currentTPSLimit;
|
||||
int loops = (int) Math.ceil(delay);
|
||||
long sleepDelay = (long) (50 * delay) / loops;
|
||||
|
||||
TPSWarpUtils.setTPS(currentTPSLimit);
|
||||
if (currentTPSLimit >= 20) {
|
||||
@ -65,7 +61,7 @@ public class TPSLimitUtils {
|
||||
}
|
||||
|
||||
private void sleepUntilNextTick(long neededDelta) {
|
||||
lastTime = currentTime;
|
||||
long lastTime = currentTime;
|
||||
currentTime = System.nanoTime();
|
||||
|
||||
long timeDelta = (currentTime - lastTime) / 1000000;
|
||||
@ -83,6 +79,7 @@ public class TPSLimitUtils {
|
||||
return (double) Math.round(currentTPSLimit * 10.0D) / 10.0D;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static void setTPS(double d) {
|
||||
if (d < 0.5) d = 0.5;
|
||||
if (d > (TPSWarpUtils.isWarpAllowed() ? 60 : 20)) d = (TPSWarpUtils.isWarpAllowed() ? 60 : 20);
|
||||
|
@ -20,6 +20,7 @@
|
||||
package de.steamwar.bausystem.features.tpslimit;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import java.util.function.LongSupplier;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
@ -29,12 +30,10 @@ import java.util.function.Supplier;
|
||||
public class TPSUtils {
|
||||
|
||||
private static long ticksSinceServerStart = 0;
|
||||
public static final Supplier<Long> currentTick = () -> ticksSinceServerStart;
|
||||
public static final LongSupplier currentTick = () -> ticksSinceServerStart;
|
||||
|
||||
static {
|
||||
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {
|
||||
ticksSinceServerStart++;
|
||||
}, 1, 1);
|
||||
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> ticksSinceServerStart++, 1, 1);
|
||||
}
|
||||
|
||||
}
|
@ -32,6 +32,7 @@ public class TPSWarpUtils {
|
||||
private static long nanoOffset = 0;
|
||||
private static long nanoDOffset = 0;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static void init() {
|
||||
VersionedRunnable.call(new VersionedRunnable(() -> warp = false, 8),
|
||||
new VersionedRunnable(() -> {
|
||||
@ -53,6 +54,7 @@ public class TPSWarpUtils {
|
||||
return nanoDOffset > 0;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static double getTps(TPSWatcher.TPSType tpsType) {
|
||||
if (TPSWarpUtils.isWarping())
|
||||
return TPSWatcher.getTPS(tpsType, Math.max(TPSLimitUtils.getCurrentTPSLimit(), 20));
|
||||
|
@ -23,7 +23,6 @@ import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.linkage.LinkageType;
|
||||
import de.steamwar.bausystem.linkage.Linked;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
@ -46,6 +46,7 @@ public enum LinkageType {
|
||||
@Getter
|
||||
private final Predicate<Class<?>> linkagePredicate;
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
@Getter
|
||||
private Consumer<Object> linkageConsumer = o -> {};
|
||||
}
|
@ -78,11 +78,10 @@ public class LinkageUtils {
|
||||
private Object constructInstance(Class<?> clazz) {
|
||||
try {
|
||||
Constructor<?> constructor = clazz.getDeclaredConstructor();
|
||||
constructor.setAccessible(true);
|
||||
constructor.setAccessible(true); //NOSONAR
|
||||
return constructor.newInstance();
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e) {
|
||||
throw new SecurityException(e.getMessage(), e.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -33,6 +33,6 @@ public @interface Linked {
|
||||
@Retention(RetentionPolicy.CLASS)
|
||||
@Target({ElementType.TYPE})
|
||||
@interface Linkages {
|
||||
Linked[] value() default {};
|
||||
@SuppressWarnings("unused") Linked[] value() default {};
|
||||
}
|
||||
}
|
In neuem Issue referenzieren
Einen Benutzer sperren