SteamWar/BauSystem2.0
Archiviert
12
0

§ Colors are now ChatColors

CodeCleanup
Implementation of Redstonetester
Dieser Commit ist enthalten in:
Zeanon 2021-04-17 16:43:27 +02:00
Ursprung 8c5edd8cfe
Commit e2f0658f36
20 geänderte Dateien mit 43 neuen und 49 gelöschten Zeilen

Datei anzeigen

@ -36,7 +36,7 @@ import java.util.List;
@Linked(LinkageType.COMMAND) @Linked(LinkageType.COMMAND)
public class TimeCommand extends SWCommand { 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() { public TimeCommand() {
super("time"); super("time");
@ -80,6 +80,7 @@ public class TimeCommand extends SWCommand {
}, s -> tabCompletions); }, s -> tabCompletions);
} }
@SuppressWarnings("unused")
public enum Time { public enum Time {
NIGHT(18000), NIGHT(18000),
DAY(6000), DAY(6000),

Datei anzeigen

@ -31,7 +31,7 @@ import org.bukkit.event.player.PlayerTeleportEvent;
@Linked(LinkageType.COMMAND) @Linked(LinkageType.COMMAND)
public class WorldSpawnCommand extends SWCommand { public class WorldSpawnCommand extends SWCommand {
private final World WORLD = Bukkit.getWorlds().get(0); private static final World WORLD = Bukkit.getWorlds().get(0);
public WorldSpawnCommand() { public WorldSpawnCommand() {
super("worldspawn"); super("worldspawn");

Datei anzeigen

@ -43,9 +43,7 @@ public class RedstonetesterCommand extends SWCommand {
@Register @Register
public void genericCommand(Player p) { public void genericCommand(Player p) {
VersionedRunnable.call(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 + "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"); p.sendMessage(BauSystem.PREFIX + "Messe die Zeit zwischen der Aktivierung zweier Redstone Komponenten");
SWUtils.giveItemToPlayer(p, RedstonetesterUtils.WAND); SWUtils.giveItemToPlayer(p, RedstonetesterUtils.WAND);
}, 15)); }, 15));

Datei anzeigen

@ -82,17 +82,17 @@ public class RedstonetesterUtils {
return; return;
} }
if (loc1.equals(location)) { if (loc1.equals(location)) {
if (TPSUtils.currentTick.get() - lastTick > 100) { if (TPSUtils.currentTick.getAsLong() - lastTick > 100) {
tick = null; tick = null;
} }
lastTick = TPSUtils.currentTick.get(); lastTick = TPSUtils.currentTick.getAsLong();
if (tick == null) { if (tick == null) {
tick = TPSUtils.currentTick.get(); tick = TPSUtils.currentTick.getAsLong();
} }
return; return;
} }
if (tick != null && loc2.equals(location)) { 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 + ")");
} }
} }

Datei anzeigen

@ -44,14 +44,11 @@ public class TPSLimitCommand extends SWCommand {
@Getter(AccessLevel.PACKAGE) @Getter(AccessLevel.PACKAGE)
private static TPSLimitCommand instance = null; private static TPSLimitCommand instance = null;
{ 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"));
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"));
public TPSLimitCommand() { public TPSLimitCommand() {
super("tpslimit"); super("tpslimit");
instance = this;
if (TPSWarpUtils.isWarpAllowed()) { if (TPSWarpUtils.isWarpAllowed()) {
for (int i = 20; i <= 60; i += 5) { for (int i = 20; i <= 60; i += 5) {
tabCompletions.add(i + ""); tabCompletions.add(i + "");
@ -96,6 +93,7 @@ public class TPSLimitCommand extends SWCommand {
}, s -> tabCompletions); }, s -> tabCompletions);
} }
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
private boolean permissionCheck(Player player) { private boolean permissionCheck(Player player) {
if (!Permission.hasPermission(player, Permission.WORLD)) { if (!Permission.hasPermission(player, Permission.WORLD)) {
player.sendMessage(BauSystem.PREFIX + ChatColor.RED + "Du darfst hier nicht den TPS-Limiter nutzen"); player.sendMessage(BauSystem.PREFIX + ChatColor.RED + "Du darfst hier nicht den TPS-Limiter nutzen");

Datei anzeigen

@ -32,19 +32,15 @@ public class TPSLimitUtils {
private static final World WORLD = Bukkit.getWorlds().get(0); private static final World WORLD = Bukkit.getWorlds().get(0);
static double currentTPSLimit = 20; static double currentTPSLimit = 20;
private long lastTime = System.nanoTime();
private long currentTime = System.nanoTime(); private long currentTime = System.nanoTime();
private double delay = 0;
private int loops = 0;
private long sleepDelay = 0;
private BukkitTask tpsLimiter = null; private BukkitTask tpsLimiter = null;
void tpsLimiter() { void tpsLimiter() {
delay = 20 / currentTPSLimit; double delay = 20 / currentTPSLimit;
loops = (int) Math.ceil(delay); int loops = (int) Math.ceil(delay);
sleepDelay = (long) (50 * delay) / loops; long sleepDelay = (long) (50 * delay) / loops;
TPSWarpUtils.setTPS(currentTPSLimit); TPSWarpUtils.setTPS(currentTPSLimit);
if (currentTPSLimit >= 20) { if (currentTPSLimit >= 20) {
@ -65,7 +61,7 @@ public class TPSLimitUtils {
} }
private void sleepUntilNextTick(long neededDelta) { private void sleepUntilNextTick(long neededDelta) {
lastTime = currentTime; long lastTime = currentTime;
currentTime = System.nanoTime(); currentTime = System.nanoTime();
long timeDelta = (currentTime - lastTime) / 1000000; long timeDelta = (currentTime - lastTime) / 1000000;
@ -83,6 +79,7 @@ public class TPSLimitUtils {
return (double) Math.round(currentTPSLimit * 10.0D) / 10.0D; return (double) Math.round(currentTPSLimit * 10.0D) / 10.0D;
} }
@SuppressWarnings("unused")
public static void setTPS(double d) { public static void setTPS(double d) {
if (d < 0.5) d = 0.5; if (d < 0.5) d = 0.5;
if (d > (TPSWarpUtils.isWarpAllowed() ? 60 : 20)) d = (TPSWarpUtils.isWarpAllowed() ? 60 : 20); if (d > (TPSWarpUtils.isWarpAllowed() ? 60 : 20)) d = (TPSWarpUtils.isWarpAllowed() ? 60 : 20);

Datei anzeigen

@ -20,6 +20,7 @@
package de.steamwar.bausystem.features.tpslimit; package de.steamwar.bausystem.features.tpslimit;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import java.util.function.LongSupplier;
import lombok.experimental.UtilityClass; import lombok.experimental.UtilityClass;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -29,12 +30,10 @@ import java.util.function.Supplier;
public class TPSUtils { public class TPSUtils {
private static long ticksSinceServerStart = 0; private static long ticksSinceServerStart = 0;
public static final Supplier<Long> currentTick = () -> ticksSinceServerStart; public static final LongSupplier currentTick = () -> ticksSinceServerStart;
static { static {
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> { Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> ticksSinceServerStart++, 1, 1);
ticksSinceServerStart++;
}, 1, 1);
} }
} }

Datei anzeigen

@ -32,6 +32,7 @@ public class TPSWarpUtils {
private static long nanoOffset = 0; private static long nanoOffset = 0;
private static long nanoDOffset = 0; private static long nanoDOffset = 0;
@SuppressWarnings("unused")
public static void init() { public static void init() {
VersionedRunnable.call(new VersionedRunnable(() -> warp = false, 8), VersionedRunnable.call(new VersionedRunnable(() -> warp = false, 8),
new VersionedRunnable(() -> { new VersionedRunnable(() -> {
@ -53,6 +54,7 @@ public class TPSWarpUtils {
return nanoDOffset > 0; return nanoDOffset > 0;
} }
@SuppressWarnings("unused")
public static double getTps(TPSWatcher.TPSType tpsType) { public static double getTps(TPSWatcher.TPSType tpsType) {
if (TPSWarpUtils.isWarping()) if (TPSWarpUtils.isWarping())
return TPSWatcher.getTPS(tpsType, Math.max(TPSLimitUtils.getCurrentTPSLimit(), 20)); return TPSWatcher.getTPS(tpsType, Math.max(TPSLimitUtils.getCurrentTPSLimit(), 20));

Datei anzeigen

@ -23,7 +23,6 @@ import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked; import de.steamwar.bausystem.linkage.Linked;
import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommand;
import io.netty.channel.ChannelHandler;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

Datei anzeigen

@ -46,6 +46,7 @@ public enum LinkageType {
@Getter @Getter
private final Predicate<Class<?>> linkagePredicate; private final Predicate<Class<?>> linkagePredicate;
@SuppressWarnings("FieldMayBeFinal")
@Getter @Getter
private Consumer<Object> linkageConsumer = o -> {}; private Consumer<Object> linkageConsumer = o -> {};
} }

Datei anzeigen

@ -78,11 +78,10 @@ public class LinkageUtils {
private Object constructInstance(Class<?> clazz) { private Object constructInstance(Class<?> clazz) {
try { try {
Constructor<?> constructor = clazz.getDeclaredConstructor(); Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true); constructor.setAccessible(true); //NOSONAR
return constructor.newInstance(); return constructor.newInstance();
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e) { } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e) {
throw new SecurityException(e.getMessage(), e.getCause()); throw new SecurityException(e.getMessage(), e.getCause());
} }
} }
} }

Datei anzeigen

@ -33,6 +33,6 @@ public @interface Linked {
@Retention(RetentionPolicy.CLASS) @Retention(RetentionPolicy.CLASS)
@Target({ElementType.TYPE}) @Target({ElementType.TYPE})
@interface Linkages { @interface Linkages {
Linked[] value() default {}; @SuppressWarnings("unused") Linked[] value() default {};
} }
} }