From e2f0658f362695586d1451d4d77cb35c497fc952 Mon Sep 17 00:00:00 2001 From: Zeanon Date: Sat, 17 Apr 2021 16:43:27 +0200 Subject: [PATCH] =?UTF-8?q?=C2=A7=20Colors=20are=20now=20ChatColors=20Code?= =?UTF-8?q?Cleanup=20Implementation=20of=20Redstonetester?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/de/steamwar/bausystem/BauSystem.java | 4 ++-- .../src/de/steamwar/bausystem/Permission.java | 2 +- .../de/steamwar/bausystem/config/BauServer.java | 2 +- .../bausystem/features/other/GamemodeCommand.java | 2 +- .../bausystem/features/other/TeleportCommand.java | 2 +- .../bausystem/features/other/TimeCommand.java | 5 +++-- .../features/other/WorldSpawnCommand.java | 4 ++-- .../redstonetester/RedstonetesterCommand.java | 4 +--- .../redstonetester/RedstonetesterUtils.java | 8 ++++---- .../bausystem/features/team/LockSchemCommand.java | 2 +- .../features/tpslimit/TPSLimitCommand.java | 10 ++++------ .../features/tpslimit/TPSLimitUtils.java | 15 ++++++--------- .../bausystem/features/tpslimit/TPSUtils.java | 9 ++++----- .../bausystem/features/tpslimit/TPSWarpUtils.java | 4 +++- .../features/util/NightVisionCommand.java | 2 +- .../bausystem/features/util/SkullCommand.java | 2 +- .../bausystem/features/util/SpeedCommand.java | 3 +-- .../steamwar/bausystem/linkage/LinkageType.java | 3 ++- .../steamwar/bausystem/linkage/LinkageUtils.java | 5 ++--- .../src/de/steamwar/bausystem/linkage/Linked.java | 4 ++-- 20 files changed, 43 insertions(+), 49 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 17bc7978..8b472695 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -31,7 +31,7 @@ public class BauSystem extends JavaPlugin implements Listener { @Getter private static BauSystem instance; - public static final String PREFIX = ChatColor.YELLOW + "BauSystem" + ChatColor.DARK_GRAY + "»" + ChatColor.GRAY; + public static final String PREFIX = ChatColor.YELLOW + "BauSystem" + ChatColor.DARK_GRAY + "» " + ChatColor.GRAY; @Override public void onEnable() { @@ -46,4 +46,4 @@ public class BauSystem extends JavaPlugin implements Listener { public void onDisable() { } -} +} \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/Permission.java b/BauSystem_Main/src/de/steamwar/bausystem/Permission.java index 271cfd49..778bf4ca 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/Permission.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/Permission.java @@ -50,4 +50,4 @@ public enum Permission { public static boolean hasPermission(Player member, Permission permission) { return permission.hasPermission(member); } -} +} \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/config/BauServer.java b/BauSystem_Main/src/de/steamwar/bausystem/config/BauServer.java index f266d511..8bc86ac6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/config/BauServer.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/config/BauServer.java @@ -59,4 +59,4 @@ public class BauServer { return SteamwarUser.get(getOwner()).getId(); } -} +} \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/other/GamemodeCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/other/GamemodeCommand.java index 720a3157..18ef3580 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/other/GamemodeCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/other/GamemodeCommand.java @@ -51,4 +51,4 @@ public class GamemodeCommand extends SWCommand { public void gamemodeCommand(final Player p, final GameMode gameMode) { p.setGameMode(gameMode); } -} +} \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/other/TeleportCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/other/TeleportCommand.java index f9284a49..7d8bb4b1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/other/TeleportCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/other/TeleportCommand.java @@ -47,4 +47,4 @@ public class TeleportCommand extends SWCommand { } p.teleport(target, PlayerTeleportEvent.TeleportCause.COMMAND); } -} +} \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/other/TimeCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/other/TimeCommand.java index cfda095b..3b3f4e13 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/other/TimeCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/other/TimeCommand.java @@ -36,7 +36,7 @@ import java.util.List; @Linked(LinkageType.COMMAND) public class TimeCommand extends SWCommand { - private static List tabCompletions = Arrays.asList("0", "6000", "12000", "18000"); + private static final List 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), @@ -100,4 +101,4 @@ public class TimeCommand extends SWCommand { return value; } } -} +} \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/other/WorldSpawnCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/other/WorldSpawnCommand.java index 1b1fc6f2..73d6086a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/other/WorldSpawnCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/other/WorldSpawnCommand.java @@ -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"); @@ -46,4 +46,4 @@ public class WorldSpawnCommand extends SWCommand { public void genericCommand(Player p) { p.teleport(WORLD.getSpawnLocation(), PlayerTeleportEvent.TeleportCause.COMMAND); } -} +} \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/redstonetester/RedstonetesterCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/redstonetester/RedstonetesterCommand.java index b2accec3..e2863eb5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/redstonetester/RedstonetesterCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/redstonetester/RedstonetesterCommand.java @@ -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)); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/redstonetester/RedstonetesterUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/features/redstonetester/RedstonetesterUtils.java index ec101292..0af740fe 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/redstonetester/RedstonetesterUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/redstonetester/RedstonetesterUtils.java @@ -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 + ")"); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/team/LockSchemCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/team/LockSchemCommand.java index 97e12ec0..f17cde7b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/team/LockSchemCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/team/LockSchemCommand.java @@ -83,4 +83,4 @@ public class LockSchemCommand extends SWCommand { private void sendHelp(Player player) { player.sendMessage(ChatColor.DARK_GRAY + "/" + ChatColor.YELLOW + "schemlock " + ChatColor.DARK_GRAY + "[" + ChatColor.GRAY + "Owner" + ChatColor.DARK_GRAY + "] " + ChatColor.DARK_GRAY + "[" + ChatColor.GRAY + "Schematic" + ChatColor.DARK_GRAY + "] - " + ChatColor.GRAY + "Sperre eine Schematic"); } -} +} \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitCommand.java index e7d60b13..fac64595 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitCommand.java @@ -44,14 +44,11 @@ public class TPSLimitCommand extends SWCommand { @Getter(AccessLevel.PACKAGE) private static TPSLimitCommand instance = null; - { - instance = this; - } - - private List 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 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"); @@ -111,4 +109,4 @@ public class TPSLimitCommand extends SWCommand { private void sendInvalidArgumentMessage(Player player) { player.sendMessage(BauSystem.PREFIX + ChatColor.RED + "Nur Zahlen zwischen 0,5 und " + (TPSWarpUtils.isWarpAllowed() ? 60 : 20) + ", und 'default' erlaubt."); } -} +} \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitUtils.java index f8fd0724..d87edca2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitUtils.java @@ -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); @@ -90,4 +87,4 @@ public class TPSLimitUtils { tpsLimiter(); } -} +} \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSUtils.java index 30942bee..182dc9d0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSUtils.java @@ -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 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); } -} +} \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSWarpUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSWarpUtils.java index 2e2e465e..9ee9b52c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSWarpUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSWarpUtils.java @@ -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,9 +54,10 @@ 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)); return TPSWatcher.getTPS(tpsType); } -} +} \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/NightVisionCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/NightVisionCommand.java index fce30780..61084a03 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/NightVisionCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/NightVisionCommand.java @@ -50,4 +50,4 @@ public class NightVisionCommand extends SWCommand { SWUtils.sendToActionbar(p, ChatColor.YELLOW + "Nightvision an"); } } -} +} \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/SkullCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/SkullCommand.java index d478a924..05157b1f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/SkullCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/SkullCommand.java @@ -50,4 +50,4 @@ public class SkullCommand extends SWCommand { is.setItemMeta(sm); SWUtils.giveItemToPlayer(p, is); } -} +} \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/SpeedCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/SpeedCommand.java index 7823f610..91b1be7f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/SpeedCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/SpeedCommand.java @@ -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; @@ -53,4 +52,4 @@ public class SpeedCommand extends SWCommand { p.sendMessage(BauSystem.PREFIX + "Aktuelle geschwindigkeit: " + ChatColor.YELLOW + p.getFlySpeed() * 10F); } } -} +} \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/linkage/LinkageType.java b/BauSystem_Main/src/de/steamwar/bausystem/linkage/LinkageType.java index 8d1faf4f..5f16a7ca 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/linkage/LinkageType.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/linkage/LinkageType.java @@ -46,6 +46,7 @@ public enum LinkageType { @Getter private final Predicate> linkagePredicate; + @SuppressWarnings("FieldMayBeFinal") @Getter private Consumer linkageConsumer = o -> {}; -} +} \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/linkage/LinkageUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/linkage/LinkageUtils.java index bea77705..56b8be54 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/linkage/LinkageUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/linkage/LinkageUtils.java @@ -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()); } } - -} +} \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/linkage/Linked.java b/BauSystem_Main/src/de/steamwar/bausystem/linkage/Linked.java index 8206e9d7..430e589c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/linkage/Linked.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/linkage/Linked.java @@ -33,6 +33,6 @@ public @interface Linked { @Retention(RetentionPolicy.CLASS) @Target({ElementType.TYPE}) @interface Linkages { - Linked[] value() default {}; + @SuppressWarnings("unused") Linked[] value() default {}; } -} +} \ No newline at end of file