[#1029] Move bukkit bStats registration to server thread

This commit is contained in:
Rsl1122 2019-05-05 16:40:47 +03:00
parent d2391755df
commit eb78468f01

View File

@ -26,6 +26,7 @@ import com.djrapitops.plan.system.settings.theme.PlanColorScheme;
import com.djrapitops.plugin.BukkitPlugin; import com.djrapitops.plugin.BukkitPlugin;
import com.djrapitops.plugin.benchmarking.Benchmark; import com.djrapitops.plugin.benchmarking.Benchmark;
import com.djrapitops.plugin.command.ColorScheme; import com.djrapitops.plugin.command.ColorScheme;
import com.djrapitops.plugin.task.AbsRunnable;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import java.util.logging.Level; import java.util.logging.Level;
@ -52,8 +53,6 @@ public class Plan extends BukkitPlugin implements PlanPlugin {
locale = system.getLocaleSystem().getLocale(); locale = system.getLocaleSystem().getLocale();
system.enable(); system.enable();
new BStatsBukkit(this).registerMetrics();
logger.debug("Verbose debug messages are enabled."); logger.debug("Verbose debug messages are enabled.");
String benchTime = " (" + timings.end("Enable").map(Benchmark::toDurationString).orElse("-") + ")"; String benchTime = " (" + timings.end("Enable").map(Benchmark::toDurationString).orElse("-") + ")";
logger.info(locale.getString(PluginLang.ENABLED) + benchTime); logger.info(locale.getString(PluginLang.ENABLED) + benchTime);
@ -80,6 +79,19 @@ public class Plan extends BukkitPlugin implements PlanPlugin {
} }
} }
private void registerMetrics() {
Plan plugin = this;
// Spigot 1.14 requires Sync events to be fired from a server thread.
// Registering a service fires a sync event, and bStats registers a service,
// so this has to be run on the server thread.
runnableFactory.create("Register Metrics task", new AbsRunnable() {
@Override
public void run() {
new BStatsBukkit(plugin).registerMetrics();
}
}).runTask();
}
@Override @Override
public ColorScheme getColorScheme() { public ColorScheme getColorScheme() {
return PlanColorScheme.create(system.getConfigSystem().getConfig(), logger); return PlanColorScheme.create(system.getConfigSystem().getConfig(), logger);