From 7d4acbdcac1f7fed5ef5fa43c6abc046e0df26ef Mon Sep 17 00:00:00 2001 From: MattBDev <4009945+MattBDev@users.noreply.github.com> Date: Wed, 29 Jan 2020 14:33:41 -0500 Subject: [PATCH] Remove some reflection from QueueHandler --- .../bukkit/adapter/BukkitQueueHandler.java | 39 +++++++------------ 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/BukkitQueueHandler.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/BukkitQueueHandler.java index eb0213c1d..8550f02b7 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/BukkitQueueHandler.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/BukkitQueueHandler.java @@ -2,26 +2,19 @@ package com.boydti.fawe.bukkit.adapter; import static org.slf4j.LoggerFactory.getLogger; +import co.aikar.timings.Timings; import com.boydti.fawe.beta.implementation.queue.QueueHandler; import com.boydti.fawe.bukkit.listener.ChunkListener; -import java.lang.reflect.Field; import java.lang.reflect.Method; +import org.spigotmc.AsyncCatcher; public class BukkitQueueHandler extends QueueHandler { private volatile boolean timingsEnabled; private static boolean alertTimingsChange = true; - private static Field fieldTimingsEnabled; - private static Field fieldAsyncCatcherEnabled; private static Method methodCheck; static { try { - fieldAsyncCatcherEnabled = Class.forName("org.spigotmc.AsyncCatcher").getField("enabled"); - fieldAsyncCatcherEnabled.setAccessible(true); - } catch (Throwable ignore) {} - try { - fieldTimingsEnabled = Class.forName("co.aikar.timings.Timings").getDeclaredField("timingsEnabled"); - fieldTimingsEnabled.setAccessible(true); methodCheck = Class.forName("co.aikar.timings.TimingsManager").getDeclaredMethod("recheckEnabled"); methodCheck.setAccessible(true); } catch (Throwable ignore){} @@ -32,19 +25,15 @@ public class BukkitQueueHandler extends QueueHandler { ChunkListener.physicsFreeze = true; if (parallel) { try { - if (fieldAsyncCatcherEnabled != null) { - fieldAsyncCatcherEnabled.set(null, false); - } - if (fieldTimingsEnabled != null) { - timingsEnabled = (boolean) fieldTimingsEnabled.get(null); - if (timingsEnabled) { - if (alertTimingsChange) { - alertTimingsChange = false; - getLogger(BukkitQueueHandler.class).debug("Having `parallel-threads` > 1 interferes with the timings."); - } - fieldTimingsEnabled.set(null, false); - methodCheck.invoke(null); + AsyncCatcher.enabled = false; + timingsEnabled = Timings.isTimingsEnabled(); + if (timingsEnabled) { + if (alertTimingsChange) { + alertTimingsChange = false; + getLogger(BukkitQueueHandler.class).debug("Having `parallel-threads` > 1 interferes with the timings."); } + Timings.setTimingsEnabled(false); + methodCheck.invoke(null); } } catch (Throwable e) { e.printStackTrace(); @@ -57,11 +46,9 @@ public class BukkitQueueHandler extends QueueHandler { ChunkListener.physicsFreeze = false; if (parallel) { try { - if (fieldAsyncCatcherEnabled != null) { - fieldAsyncCatcherEnabled.set(null, true); - } - if (fieldTimingsEnabled != null && timingsEnabled) { - fieldTimingsEnabled.set(null, true); + AsyncCatcher.enabled = true; + if (timingsEnabled) { + Timings.setTimingsEnabled(true); methodCheck.invoke(null); } } catch (Throwable e) {