2021-07-01 20:16:25 +00:00
|
|
|
package com.fastasyncworldedit.bukkit.adapter;
|
2019-04-30 16:19:10 +00:00
|
|
|
|
2020-01-29 19:33:41 +00:00
|
|
|
import co.aikar.timings.Timings;
|
2021-07-01 20:16:25 +00:00
|
|
|
import com.fastasyncworldedit.core.beta.implementation.queue.QueueHandler;
|
|
|
|
import com.fastasyncworldedit.bukkit.listener.ChunkListener;
|
2021-03-29 13:29:16 +00:00
|
|
|
import com.sk89q.worldedit.internal.util.LogManagerCompat;
|
|
|
|
import org.apache.logging.log4j.Logger;
|
2020-01-29 19:33:41 +00:00
|
|
|
import org.spigotmc.AsyncCatcher;
|
2019-04-30 16:19:10 +00:00
|
|
|
|
2020-10-05 17:41:41 +00:00
|
|
|
import java.lang.reflect.Method;
|
|
|
|
|
2019-04-30 16:19:10 +00:00
|
|
|
public class BukkitQueueHandler extends QueueHandler {
|
2021-03-29 13:29:16 +00:00
|
|
|
|
|
|
|
private static final Logger LOGGER = LogManagerCompat.getLogger();
|
|
|
|
|
2019-08-18 01:09:09 +00:00
|
|
|
private volatile boolean timingsEnabled;
|
|
|
|
private static boolean alertTimingsChange = true;
|
|
|
|
|
|
|
|
private static Method methodCheck;
|
|
|
|
static {
|
|
|
|
try {
|
|
|
|
methodCheck = Class.forName("co.aikar.timings.TimingsManager").getDeclaredMethod("recheckEnabled");
|
|
|
|
methodCheck.setAccessible(true);
|
2020-10-05 17:41:41 +00:00
|
|
|
} catch (Throwable ignored) {
|
|
|
|
}
|
2019-08-18 01:09:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void startSet(boolean parallel) {
|
|
|
|
ChunkListener.physicsFreeze = true;
|
|
|
|
if (parallel) {
|
|
|
|
try {
|
2020-01-29 19:33:41 +00:00
|
|
|
AsyncCatcher.enabled = false;
|
|
|
|
timingsEnabled = Timings.isTimingsEnabled();
|
|
|
|
if (timingsEnabled) {
|
|
|
|
if (alertTimingsChange) {
|
|
|
|
alertTimingsChange = false;
|
2021-03-29 13:29:16 +00:00
|
|
|
LOGGER.debug("Having `parallel-threads` > 1 interferes with the timings.");
|
2019-08-18 01:09:09 +00:00
|
|
|
}
|
2020-01-29 19:33:41 +00:00
|
|
|
Timings.setTimingsEnabled(false);
|
|
|
|
methodCheck.invoke(null);
|
2019-08-18 01:09:09 +00:00
|
|
|
}
|
|
|
|
} catch (Throwable e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void endSet(boolean parallel) {
|
|
|
|
ChunkListener.physicsFreeze = false;
|
|
|
|
if (parallel) {
|
|
|
|
try {
|
2020-01-29 19:33:41 +00:00
|
|
|
AsyncCatcher.enabled = true;
|
|
|
|
if (timingsEnabled) {
|
|
|
|
Timings.setTimingsEnabled(true);
|
2019-08-18 01:09:09 +00:00
|
|
|
methodCheck.invoke(null);
|
|
|
|
}
|
|
|
|
} catch (Throwable e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-11-11 21:02:28 +00:00
|
|
|
}
|