From d047be35d96c4e0cee5770065cad9998f930ca21 Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Sat, 15 Jul 2023 16:25:26 +0200 Subject: [PATCH] Custom Bukkit event ServerStopEvent --- .../fr/pandacube/lib/paper/PandaLibPaper.java | 2 + .../lib/paper/event/ServerStopEvent.java | 51 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 pandalib-paper/src/main/java/fr/pandacube/lib/paper/event/ServerStopEvent.java diff --git a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/PandaLibPaper.java b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/PandaLibPaper.java index c55e61d..c639524 100644 --- a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/PandaLibPaper.java +++ b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/PandaLibPaper.java @@ -1,5 +1,6 @@ package fr.pandacube.lib.paper; +import fr.pandacube.lib.paper.event.ServerStopEvent; import fr.pandacube.lib.paper.json.PaperJson; import fr.pandacube.lib.paper.modules.PerformanceAnalysisManager; import org.bukkit.plugin.Plugin; @@ -15,6 +16,7 @@ public class PandaLibPaper { public static void onEnable() { PerformanceAnalysisManager.getInstance(); // initialize + ServerStopEvent.init(); } diff --git a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/event/ServerStopEvent.java b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/event/ServerStopEvent.java new file mode 100644 index 0000000..a3ca473 --- /dev/null +++ b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/event/ServerStopEvent.java @@ -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(); + } + + }); + } + + +}