From 23b9d79dca7ac9bc5a021a248cb5ff4f81d56b7d Mon Sep 17 00:00:00 2001 From: Risto Lahtela <24460436+Rsl1122@users.noreply.github.com> Date: Sat, 8 Aug 2020 17:02:20 +0300 Subject: [PATCH] Moved bukkit ping method check to enable This static block was causing compatibility issues with some plugins that modify classes at runtime. Affects issues: - Possibly fixed #1492 - References https://github.com/konsolas/AAC-Issues/issues/1971 --- .../gathering/timed/BukkitPingCounter.java | 51 ++++++++++--------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/Plan/bukkit/src/main/java/com/djrapitops/plan/gathering/timed/BukkitPingCounter.java b/Plan/bukkit/src/main/java/com/djrapitops/plan/gathering/timed/BukkitPingCounter.java index 68429589a..e7b81dec8 100644 --- a/Plan/bukkit/src/main/java/com/djrapitops/plan/gathering/timed/BukkitPingCounter.java +++ b/Plan/bukkit/src/main/java/com/djrapitops/plan/gathering/timed/BukkitPingCounter.java @@ -65,12 +65,34 @@ public class BukkitPingCounter 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 - private static final boolean PING_METHOD_AVAILABLE; + private static boolean PING_METHOD_AVAILABLE; - private static final MethodHandle PING_FIELD; - private static final MethodHandle GET_HANDLE_METHOD; + private static MethodHandle PING_FIELD; + private static MethodHandle GET_HANDLE_METHOD; - static { + @Inject + public BukkitPingCounter( + PlanConfig config, + DBSystem dbSystem, + ServerInfo serverInfo, + RunnableFactory runnableFactory + ) { + BukkitPingCounter.loadPingMethodDetails(); + this.config = config; + this.dbSystem = dbSystem; + this.serverInfo = serverInfo; + this.runnableFactory = runnableFactory; + playerHistory = new HashMap<>(); + } + + private final Map>> playerHistory; + + private final PlanConfig config; + private final DBSystem dbSystem; + private final ServerInfo serverInfo; + private final RunnableFactory runnableFactory; + + private static void loadPingMethodDetails() { PING_METHOD_AVAILABLE = isPingMethodAvailable(); MethodHandle localHandle = null; @@ -103,27 +125,6 @@ public class BukkitPingCounter extends AbsRunnable implements Listener { PING_FIELD = localPing; } - private final Map>> playerHistory; - - private final PlanConfig config; - private final DBSystem dbSystem; - private final ServerInfo serverInfo; - private final RunnableFactory runnableFactory; - - @Inject - public BukkitPingCounter( - PlanConfig config, - DBSystem dbSystem, - ServerInfo serverInfo, - RunnableFactory runnableFactory - ) { - this.config = config; - this.dbSystem = dbSystem; - this.serverInfo = serverInfo; - this.runnableFactory = runnableFactory; - playerHistory = new HashMap<>(); - } - private static boolean isPingMethodAvailable() { try { //Only available in Paper