Custom Bukkit event ServerStopEvent

This commit is contained in:
Marc Baloup 2023-07-15 16:25:26 +02:00
parent 5fb17be4c7
commit d047be35d9
2 changed files with 53 additions and 0 deletions

View File

@ -1,5 +1,6 @@
package fr.pandacube.lib.paper; package fr.pandacube.lib.paper;
import fr.pandacube.lib.paper.event.ServerStopEvent;
import fr.pandacube.lib.paper.json.PaperJson; import fr.pandacube.lib.paper.json.PaperJson;
import fr.pandacube.lib.paper.modules.PerformanceAnalysisManager; import fr.pandacube.lib.paper.modules.PerformanceAnalysisManager;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
@ -15,6 +16,7 @@ public class PandaLibPaper {
public static void onEnable() { public static void onEnable() {
PerformanceAnalysisManager.getInstance(); // initialize PerformanceAnalysisManager.getInstance(); // initialize
ServerStopEvent.init();
} }

View File

@ -0,0 +1,51 @@
package fr.pandacube.lib.paper.event;
import fr.pandacube.lib.paper.util.BukkitEvent;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.ServerEvent;
import org.jetbrains.annotations.NotNull;
public class ServerStopEvent extends ServerEvent {
private static final HandlerList handlers = new HandlerList();
@NotNull
@Override
public HandlerList getHandlers() {
return handlers;
}
@NotNull
public static HandlerList getHandlerList() {
return handlers;
}
private static boolean hasTriggered = false;
public static void init() {
BukkitEvent.register(new Listener() {
@EventHandler(priority = EventPriority.LOWEST)
public void onPluginDisable(PluginDisableEvent event) {
if (!Bukkit.isStopping())
return;
if (hasTriggered)
return;
hasTriggered = true;
new ServerStopEvent().callEvent();
}
});
}
}