From 68fa79335466b08f68d76648b4b6e78f92a49d79 Mon Sep 17 00:00:00 2001 From: darbyjack Date: Wed, 8 May 2019 22:22:01 -0500 Subject: [PATCH] Added documentation / explanation for the ServerLoadEvent --- .../ServerLoadEventListener.java | 38 ++++++++++++------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/src/main/java/me/clip/placeholderapi/ServerLoadEventListener.java b/src/main/java/me/clip/placeholderapi/ServerLoadEventListener.java index 8c68987..f34dfe3 100644 --- a/src/main/java/me/clip/placeholderapi/ServerLoadEventListener.java +++ b/src/main/java/me/clip/placeholderapi/ServerLoadEventListener.java @@ -1,6 +1,7 @@ package me.clip.placeholderapi; import java.util.Map; + import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -8,20 +9,29 @@ import org.bukkit.event.server.ServerLoadEvent; public class ServerLoadEventListener implements Listener { - private PlaceholderAPIPlugin plugin; + private PlaceholderAPIPlugin plugin; - public ServerLoadEventListener(PlaceholderAPIPlugin instance) { - plugin = instance; - Bukkit.getPluginManager().registerEvents(this, instance); - } - - @EventHandler - public void onServerLoad(ServerLoadEvent e) { - plugin.getLogger().info("Placeholder expansion registration initializing..."); - final Map alreadyRegistered = PlaceholderAPI.getPlaceholders(); - plugin.getExpansionManager().registerAllExpansions(); - if (alreadyRegistered != null && !alreadyRegistered.isEmpty()) { - alreadyRegistered.forEach(PlaceholderAPI::registerPlaceholderHook); + public ServerLoadEventListener(PlaceholderAPIPlugin instance) { + plugin = instance; + Bukkit.getPluginManager().registerEvents(this, instance); + } + + /** + * 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(); + if (alreadyRegistered != null && !alreadyRegistered.isEmpty()) { + alreadyRegistered.forEach(PlaceholderAPI::registerPlaceholderHook); + } } - } }