From 9631b087b3f2a87b0fc16a3ebc058ebf4a94783d Mon Sep 17 00:00:00 2001 From: Sxtanna Date: Wed, 22 Jul 2020 20:41:27 -0400 Subject: [PATCH] updated server load listener to be final, and to automatically unregister itself when done --- .../listeners/ServerLoadEventListener.java | 55 +++++++++---------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/src/main/java/me/clip/placeholderapi/listeners/ServerLoadEventListener.java b/src/main/java/me/clip/placeholderapi/listeners/ServerLoadEventListener.java index b1f38f7..018e452 100644 --- a/src/main/java/me/clip/placeholderapi/listeners/ServerLoadEventListener.java +++ b/src/main/java/me/clip/placeholderapi/listeners/ServerLoadEventListener.java @@ -20,43 +20,42 @@ */ package me.clip.placeholderapi.listeners; -import me.clip.placeholderapi.PlaceholderAPI; import me.clip.placeholderapi.PlaceholderAPIPlugin; -import me.clip.placeholderapi.PlaceholderHook; import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import org.bukkit.event.server.ServerLoadEvent; +import org.jetbrains.annotations.NotNull; -import java.util.Map; +public final class ServerLoadEventListener implements Listener +{ -public class ServerLoadEventListener implements Listener { + @NotNull + private final PlaceholderAPIPlugin plugin; - private final PlaceholderAPIPlugin plugin; + public ServerLoadEventListener(@NotNull final PlaceholderAPIPlugin plugin) + { + this.plugin = plugin; - public ServerLoadEventListener(PlaceholderAPIPlugin instance) { - plugin = instance; - Bukkit.getPluginManager().registerEvents(this, instance); - } + Bukkit.getPluginManager().registerEvents(this, plugin); + } - /** - * This method will be called when the server is first loaded - *

- * The goal of the method is to register all the expansions as soon as possible - * especially before players can join - *

- * This will ensure no issues with expanions and hooks. - * - * @param e the server load event - */ - @EventHandler - public void onServerLoad(ServerLoadEvent e) { - plugin.getLogger().info("Placeholder expansion registration initializing..."); - final Map alreadyRegistered = PlaceholderAPI.getPlaceholders(); - plugin.getExpansionManager().registerAllExpansions(); + /** + * This method will be called when the server is first loaded + *

+ * The goal of the method is to register all the expansions as soon as possible + * especially before players can join + *

+ * This will ensure no issues with expansions and hooks. + * + * @param event the server load event + */ + @EventHandler + public void onServerLoad(@NotNull final ServerLoadEvent event) + { + HandlerList.unregisterAll(this); + plugin.getExpansionManager().initializeExpansions(); + } - if (alreadyRegistered != null && !alreadyRegistered.isEmpty()) { - alreadyRegistered.forEach(PlaceholderAPI::registerPlaceholderHook); - } - } }