§ Colors are now ChatColors
CodeCleanup Implementation of Redstonetester
Dieser Commit ist enthalten in:
Ursprung
8c5edd8cfe
Commit
e2f0658f36
@ -31,7 +31,7 @@ public class BauSystem extends JavaPlugin implements Listener {
|
|||||||
@Getter
|
@Getter
|
||||||
private static BauSystem instance;
|
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
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
@ -46,4 +46,4 @@ public class BauSystem extends JavaPlugin implements Listener {
|
|||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -50,4 +50,4 @@ public enum Permission {
|
|||||||
public static boolean hasPermission(Player member, Permission permission) {
|
public static boolean hasPermission(Player member, Permission permission) {
|
||||||
return permission.hasPermission(member);
|
return permission.hasPermission(member);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -59,4 +59,4 @@ public class BauServer {
|
|||||||
return SteamwarUser.get(getOwner()).getId();
|
return SteamwarUser.get(getOwner()).getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -51,4 +51,4 @@ public class GamemodeCommand extends SWCommand {
|
|||||||
public void gamemodeCommand(final Player p, final GameMode gameMode) {
|
public void gamemodeCommand(final Player p, final GameMode gameMode) {
|
||||||
p.setGameMode(gameMode);
|
p.setGameMode(gameMode);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -47,4 +47,4 @@ public class TeleportCommand extends SWCommand {
|
|||||||
}
|
}
|
||||||
p.teleport(target, PlayerTeleportEvent.TeleportCause.COMMAND);
|
p.teleport(target, PlayerTeleportEvent.TeleportCause.COMMAND);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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),
|
||||||
@ -100,4 +101,4 @@ public class TimeCommand extends SWCommand {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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");
|
||||||
@ -46,4 +46,4 @@ public class WorldSpawnCommand extends SWCommand {
|
|||||||
public void genericCommand(Player p) {
|
public void genericCommand(Player p) {
|
||||||
p.teleport(WORLD.getSpawnLocation(), PlayerTeleportEvent.TeleportCause.COMMAND);
|
p.teleport(WORLD.getSpawnLocation(), PlayerTeleportEvent.TeleportCause.COMMAND);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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));
|
||||||
|
@ -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 + ")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,4 +83,4 @@ public class LockSchemCommand extends SWCommand {
|
|||||||
private void sendHelp(Player player) {
|
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");
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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");
|
||||||
@ -111,4 +109,4 @@ public class TPSLimitCommand extends SWCommand {
|
|||||||
private void sendInvalidArgumentMessage(Player player) {
|
private void sendInvalidArgumentMessage(Player player) {
|
||||||
player.sendMessage(BauSystem.PREFIX + ChatColor.RED + "Nur Zahlen zwischen 0,5 und " + (TPSWarpUtils.isWarpAllowed() ? 60 : 20) + ", und 'default' erlaubt.");
|
player.sendMessage(BauSystem.PREFIX + ChatColor.RED + "Nur Zahlen zwischen 0,5 und " + (TPSWarpUtils.isWarpAllowed() ? 60 : 20) + ", und 'default' erlaubt.");
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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);
|
||||||
@ -90,4 +87,4 @@ public class TPSLimitUtils {
|
|||||||
tpsLimiter();
|
tpsLimiter();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -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,9 +54,10 @@ 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));
|
||||||
return TPSWatcher.getTPS(tpsType);
|
return TPSWatcher.getTPS(tpsType);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -50,4 +50,4 @@ public class NightVisionCommand extends SWCommand {
|
|||||||
SWUtils.sendToActionbar(p, ChatColor.YELLOW + "Nightvision an");
|
SWUtils.sendToActionbar(p, ChatColor.YELLOW + "Nightvision an");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -50,4 +50,4 @@ public class SkullCommand extends SWCommand {
|
|||||||
is.setItemMeta(sm);
|
is.setItemMeta(sm);
|
||||||
SWUtils.giveItemToPlayer(p, is);
|
SWUtils.giveItemToPlayer(p, is);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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;
|
||||||
|
|
||||||
@ -53,4 +52,4 @@ public class SpeedCommand extends SWCommand {
|
|||||||
p.sendMessage(BauSystem.PREFIX + "Aktuelle geschwindigkeit: " + ChatColor.YELLOW + p.getFlySpeed() * 10F);
|
p.sendMessage(BauSystem.PREFIX + "Aktuelle geschwindigkeit: " + ChatColor.YELLOW + p.getFlySpeed() * 10F);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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 -> {};
|
||||||
}
|
}
|
@ -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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
@ -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 {};
|
||||||
}
|
}
|
||||||
}
|
}
|
In neuem Issue referenzieren
Einen Benutzer sperren