From 4d261ce6e8a92141101d4fd0c330b492dd48b3dc Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Thu, 9 May 2019 15:39:22 +0300 Subject: [PATCH] [#1034] sane handling of large delay options --- .../djrapitops/plan/system/tasks/BukkitTaskSystem.java | 9 ++++++--- .../plan/system/tasks/bukkit/PingCountTimerBukkit.java | 7 +++++-- .../djrapitops/plan/system/tasks/BungeeTaskSystem.java | 9 ++++++--- .../plan/system/tasks/bungee/PingCountTimerBungee.java | 10 +++++----- .../src/main/java/com/djrapitops/plan/db/SQLDB.java | 4 ++++ .../djrapitops/plan/system/tasks/SpongeTaskSystem.java | 9 ++++++--- .../plan/system/tasks/sponge/PingCountTimerSponge.java | 10 +++++----- .../plan/system/tasks/VelocityTaskSystem.java | 9 ++++++--- .../system/tasks/velocity/PingCountTimerVelocity.java | 10 +++++----- 9 files changed, 48 insertions(+), 29 deletions(-) diff --git a/Plan/bukkit/src/main/java/com/djrapitops/plan/system/tasks/BukkitTaskSystem.java b/Plan/bukkit/src/main/java/com/djrapitops/plan/system/tasks/BukkitTaskSystem.java index 364c53215..e39ebf73b 100644 --- a/Plan/bukkit/src/main/java/com/djrapitops/plan/system/tasks/BukkitTaskSystem.java +++ b/Plan/bukkit/src/main/java/com/djrapitops/plan/system/tasks/BukkitTaskSystem.java @@ -90,9 +90,12 @@ public class BukkitTaskSystem extends ServerTaskSystem { public void enable() { super.enable(); try { - plugin.registerListener(pingCountTimer); - long startDelay = TimeAmount.toTicks(config.get(TimeSettings.PING_SERVER_ENABLE_DELAY), TimeUnit.MILLISECONDS); - registerTask(pingCountTimer).runTaskTimer(startDelay, 40L); + Long pingDelay = config.get(TimeSettings.PING_SERVER_ENABLE_DELAY); + if (pingDelay < TimeUnit.HOURS.toMillis(1L)) { + plugin.registerListener(pingCountTimer); + long startDelay = TimeAmount.toTicks(pingDelay, TimeUnit.MILLISECONDS); + registerTask(pingCountTimer).runTaskTimer(startDelay, 40L); + } } catch (ExceptionInInitializerError | NoClassDefFoundError ignore) { // Running CraftBukkit } diff --git a/Plan/bukkit/src/main/java/com/djrapitops/plan/system/tasks/bukkit/PingCountTimerBukkit.java b/Plan/bukkit/src/main/java/com/djrapitops/plan/system/tasks/bukkit/PingCountTimerBukkit.java index 40390b164..3d98d62ba 100644 --- a/Plan/bukkit/src/main/java/com/djrapitops/plan/system/tasks/bukkit/PingCountTimerBukkit.java +++ b/Plan/bukkit/src/main/java/com/djrapitops/plan/system/tasks/bukkit/PingCountTimerBukkit.java @@ -64,7 +64,6 @@ public class PingCountTimerBukkit extends AbsRunnable implements Listener { //the server is pinging the client every 40 Ticks (2 sec) - so check it then //https://github.com/bergerkiller/CraftSource/blob/master/net.minecraft.server/PlayerConnection.java#L178 - public static final int PING_INTERVAL = 2 * 20; private static final boolean PING_METHOD_AVAILABLE; @@ -196,6 +195,10 @@ public class PingCountTimerBukkit extends AbsRunnable implements Listener { @EventHandler public void onPlayerJoin(PlayerJoinEvent joinEvent) { Player player = joinEvent.getPlayer(); + Long pingDelay = config.get(TimeSettings.PING_PLAYER_LOGIN_DELAY); + if (pingDelay >= TimeUnit.HOURS.toMillis(2L)) { + return; + } runnableFactory.create("Add Player to Ping list", new AbsRunnable() { @Override public void run() { @@ -203,7 +206,7 @@ public class PingCountTimerBukkit extends AbsRunnable implements Listener { addPlayer(player); } } - }).runTaskLater(TimeAmount.toTicks(config.get(TimeSettings.PING_PLAYER_LOGIN_DELAY), TimeUnit.MILLISECONDS)); + }).runTaskLater(TimeAmount.toTicks(pingDelay, TimeUnit.MILLISECONDS)); } @EventHandler diff --git a/Plan/bungeecord/src/main/java/com/djrapitops/plan/system/tasks/BungeeTaskSystem.java b/Plan/bungeecord/src/main/java/com/djrapitops/plan/system/tasks/BungeeTaskSystem.java index b34ead8a6..b2fb31e07 100644 --- a/Plan/bungeecord/src/main/java/com/djrapitops/plan/system/tasks/BungeeTaskSystem.java +++ b/Plan/bungeecord/src/main/java/com/djrapitops/plan/system/tasks/BungeeTaskSystem.java @@ -87,9 +87,12 @@ public class BungeeTaskSystem extends TaskSystem { registerTask(networkPageRefreshTask).runTaskTimerAsynchronously(1500, TimeAmount.toTicks(5L, TimeUnit.MINUTES)); registerTask(logsFolderCleanTask).runTaskLaterAsynchronously(TimeAmount.toTicks(30L, TimeUnit.SECONDS)); - plugin.registerListener(pingCountTimer); - long startDelay = TimeAmount.toTicks(config.get(TimeSettings.PING_SERVER_ENABLE_DELAY), TimeUnit.MILLISECONDS); - registerTask(pingCountTimer).runTaskTimer(startDelay, PingCountTimerBungee.PING_INTERVAL); + Long pingDelay = config.get(TimeSettings.PING_SERVER_ENABLE_DELAY); + if (pingDelay < TimeUnit.HOURS.toMillis(1L)) { + plugin.registerListener(pingCountTimer); + long startDelay = TimeAmount.toTicks(pingDelay, TimeUnit.MILLISECONDS); + registerTask(pingCountTimer).runTaskTimer(startDelay, 40L); + } registerTask(playersPageRefreshTask) .runTaskTimerAsynchronously(TimeAmount.toTicks(5L, TimeUnit.MINUTES), TimeAmount.toTicks(5L, TimeUnit.MINUTES)); diff --git a/Plan/bungeecord/src/main/java/com/djrapitops/plan/system/tasks/bungee/PingCountTimerBungee.java b/Plan/bungeecord/src/main/java/com/djrapitops/plan/system/tasks/bungee/PingCountTimerBungee.java index 6d36301d0..b9245fb62 100644 --- a/Plan/bungeecord/src/main/java/com/djrapitops/plan/system/tasks/bungee/PingCountTimerBungee.java +++ b/Plan/bungeecord/src/main/java/com/djrapitops/plan/system/tasks/bungee/PingCountTimerBungee.java @@ -52,10 +52,6 @@ import java.util.concurrent.TimeUnit; @Singleton public class PingCountTimerBungee extends AbsRunnable implements Listener { - //the server is pinging the client every 40 Ticks (2 sec) - so check it then - //https://github.com/bergerkiller/CraftSource/blob/master/net.minecraft.server/PlayerConnection.java#L178 - public static final int PING_INTERVAL = 2 * 20; - private final Map>> playerHistory; private final PlanConfig config; @@ -121,6 +117,10 @@ public class PingCountTimerBungee extends AbsRunnable implements Listener { @EventHandler public void onPlayerJoin(ServerConnectedEvent joinEvent) { ProxiedPlayer player = joinEvent.getPlayer(); + Long pingDelay = config.get(TimeSettings.PING_PLAYER_LOGIN_DELAY); + if (pingDelay >= TimeUnit.HOURS.toMillis(2L)) { + return; + } runnableFactory.create("Add Player to Ping list", new AbsRunnable() { @Override public void run() { @@ -128,7 +128,7 @@ public class PingCountTimerBungee extends AbsRunnable implements Listener { addPlayer(player); } } - }).runTaskLater(TimeAmount.toTicks(config.get(TimeSettings.PING_PLAYER_LOGIN_DELAY), TimeUnit.MILLISECONDS)); + }).runTaskLater(TimeAmount.toTicks(pingDelay, TimeUnit.MILLISECONDS)); } @EventHandler diff --git a/Plan/common/src/main/java/com/djrapitops/plan/db/SQLDB.java b/Plan/common/src/main/java/com/djrapitops/plan/db/SQLDB.java index 3790ab0e2..f92e7c793 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/db/SQLDB.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/db/SQLDB.java @@ -115,6 +115,10 @@ public abstract class SQLDB extends AbstractDatabase { transactionExecutor.shutdown(); try { Long waitMs = config.getOrDefault(TimeSettings.DB_TRANSACTION_FINISH_WAIT_DELAY, TimeUnit.SECONDS.toMillis(20L)); + if (waitMs > TimeUnit.MINUTES.toMillis(5L)) { + logger.warn(TimeSettings.DB_TRANSACTION_FINISH_WAIT_DELAY.getPath() + " was set to over 5 minutes, using 5 min instead."); + waitMs = TimeUnit.MINUTES.toMillis(5L); + } if (!transactionExecutor.awaitTermination(waitMs, TimeUnit.MILLISECONDS)) { List unfinished = transactionExecutor.shutdownNow(); int unfinishedCount = unfinished.size(); diff --git a/Plan/sponge/src/main/java/com/djrapitops/plan/system/tasks/SpongeTaskSystem.java b/Plan/sponge/src/main/java/com/djrapitops/plan/system/tasks/SpongeTaskSystem.java index 57acc4e88..14c163177 100644 --- a/Plan/sponge/src/main/java/com/djrapitops/plan/system/tasks/SpongeTaskSystem.java +++ b/Plan/sponge/src/main/java/com/djrapitops/plan/system/tasks/SpongeTaskSystem.java @@ -82,9 +82,12 @@ public class SpongeTaskSystem extends ServerTaskSystem { public void enable() { super.enable(); - plugin.registerListener(pingCountTimer); - long startDelay = TimeAmount.toTicks(config.get(TimeSettings.PING_SERVER_ENABLE_DELAY), TimeUnit.MILLISECONDS); - registerTask(pingCountTimer).runTaskTimer(startDelay, PingCountTimerSponge.PING_INTERVAL); + Long pingDelay = config.get(TimeSettings.PING_SERVER_ENABLE_DELAY); + if (pingDelay < TimeUnit.HOURS.toMillis(1L)) { + plugin.registerListener(pingCountTimer); + long startDelay = TimeAmount.toTicks(pingDelay, TimeUnit.MILLISECONDS); + registerTask(pingCountTimer).runTaskTimer(startDelay, 40L); + } // +40 ticks / 2 seconds so that update check task runs first. long storeDelay = TimeAmount.toTicks(config.get(TimeSettings.CONFIG_UPDATE_INTERVAL), TimeUnit.MILLISECONDS) + 40; diff --git a/Plan/sponge/src/main/java/com/djrapitops/plan/system/tasks/sponge/PingCountTimerSponge.java b/Plan/sponge/src/main/java/com/djrapitops/plan/system/tasks/sponge/PingCountTimerSponge.java index 682e18da1..e17fbeef7 100644 --- a/Plan/sponge/src/main/java/com/djrapitops/plan/system/tasks/sponge/PingCountTimerSponge.java +++ b/Plan/sponge/src/main/java/com/djrapitops/plan/system/tasks/sponge/PingCountTimerSponge.java @@ -48,10 +48,6 @@ import java.util.concurrent.TimeUnit; */ public class PingCountTimerSponge extends AbsRunnable { - //the server is pinging the client every 40 Ticks (2 sec) - so check it then - //https://github.com/bergerkiller/CraftSource/blob/master/net.minecraft.server/PlayerConnection.java#L178 - public static final int PING_INTERVAL = 2 * 20; - private final Map>> playerHistory; private final PlanConfig config; @@ -117,6 +113,10 @@ public class PingCountTimerSponge extends AbsRunnable { @Listener public void onPlayerJoin(ClientConnectionEvent.Join joinEvent) { Player player = joinEvent.getTargetEntity(); + Long pingDelay = config.get(TimeSettings.PING_PLAYER_LOGIN_DELAY); + if (pingDelay >= TimeUnit.HOURS.toMillis(2L)) { + return; + } runnableFactory.create("Add Player to Ping list", new AbsRunnable() { @Override public void run() { @@ -124,7 +124,7 @@ public class PingCountTimerSponge extends AbsRunnable { addPlayer(player); } } - }).runTaskLater(TimeAmount.toTicks(config.get(TimeSettings.PING_PLAYER_LOGIN_DELAY), TimeUnit.MILLISECONDS)); + }).runTaskLater(TimeAmount.toTicks(pingDelay, TimeUnit.MILLISECONDS)); } @Listener diff --git a/Plan/velocity/src/main/java/com/djrapitops/plan/system/tasks/VelocityTaskSystem.java b/Plan/velocity/src/main/java/com/djrapitops/plan/system/tasks/VelocityTaskSystem.java index 276e47d4b..d4c91cf0e 100644 --- a/Plan/velocity/src/main/java/com/djrapitops/plan/system/tasks/VelocityTaskSystem.java +++ b/Plan/velocity/src/main/java/com/djrapitops/plan/system/tasks/VelocityTaskSystem.java @@ -87,9 +87,12 @@ public class VelocityTaskSystem extends TaskSystem { registerTask(networkPageRefreshTask).runTaskTimerAsynchronously(1500, TimeAmount.toTicks(5L, TimeUnit.MINUTES)); registerTask(logsFolderCleanTask).runTaskLaterAsynchronously(TimeAmount.toTicks(30L, TimeUnit.SECONDS)); - plugin.registerListener(pingCountTimer); - long startDelay = TimeAmount.toTicks(config.get(TimeSettings.PING_SERVER_ENABLE_DELAY), TimeUnit.MILLISECONDS); - registerTask(pingCountTimer).runTaskTimer(startDelay, PingCountTimerVelocity.PING_INTERVAL); + Long pingDelay = config.get(TimeSettings.PING_SERVER_ENABLE_DELAY); + if (pingDelay < TimeUnit.HOURS.toMillis(1L)) { + plugin.registerListener(pingCountTimer); + long startDelay = TimeAmount.toTicks(pingDelay, TimeUnit.MILLISECONDS); + registerTask(pingCountTimer).runTaskTimer(startDelay, 40L); + } registerTask(playersPageRefreshTask).runTaskTimerAsynchronously(TimeAmount.toTicks(5L, TimeUnit.MINUTES), TimeAmount.toTicks(5L, TimeUnit.MINUTES)); diff --git a/Plan/velocity/src/main/java/com/djrapitops/plan/system/tasks/velocity/PingCountTimerVelocity.java b/Plan/velocity/src/main/java/com/djrapitops/plan/system/tasks/velocity/PingCountTimerVelocity.java index 74c9f193b..22fe8a298 100644 --- a/Plan/velocity/src/main/java/com/djrapitops/plan/system/tasks/velocity/PingCountTimerVelocity.java +++ b/Plan/velocity/src/main/java/com/djrapitops/plan/system/tasks/velocity/PingCountTimerVelocity.java @@ -53,10 +53,6 @@ import java.util.concurrent.TimeUnit; @Singleton public class PingCountTimerVelocity extends AbsRunnable { - //the server is pinging the client every 40 Ticks (2 sec) - so check it then - //https://github.com/bergerkiller/CraftSource/blob/master/net.minecraft.server/PlayerConnection.java#L178 - public static final int PING_INTERVAL = 2 * 20; - final Map>> playerHistory; private final PlanVelocity plugin; @@ -125,6 +121,10 @@ public class PingCountTimerVelocity extends AbsRunnable { @Subscribe public void onPlayerJoin(ServerConnectedEvent joinEvent) { Player player = joinEvent.getPlayer(); + Long pingDelay = config.get(TimeSettings.PING_PLAYER_LOGIN_DELAY); + if (pingDelay >= TimeUnit.HOURS.toMillis(2L)) { + return; + } runnableFactory.create("Add Player to Ping list", new AbsRunnable() { @Override public void run() { @@ -132,7 +132,7 @@ public class PingCountTimerVelocity extends AbsRunnable { addPlayer(player); } } - }).runTaskLater(TimeAmount.toTicks(config.get(TimeSettings.PING_PLAYER_LOGIN_DELAY), TimeUnit.MILLISECONDS)); + }).runTaskLater(TimeAmount.toTicks(pingDelay, TimeUnit.MILLISECONDS)); } @Subscribe