mirror of
https://github.com/PlaceholderAPI/PlaceholderAPI.git
synced 2024-11-26 04:25:18 +01:00
updated server load listener to be final, and to automatically unregister itself when done
This commit is contained in:
parent
d7b947ddad
commit
9631b087b3
@ -20,43 +20,42 @@
|
|||||||
*/
|
*/
|
||||||
package me.clip.placeholderapi.listeners;
|
package me.clip.placeholderapi.listeners;
|
||||||
|
|
||||||
import me.clip.placeholderapi.PlaceholderAPI;
|
|
||||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||||
import me.clip.placeholderapi.PlaceholderHook;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.server.ServerLoadEvent;
|
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) {
|
Bukkit.getPluginManager().registerEvents(this, plugin);
|
||||||
plugin = instance;
|
}
|
||||||
Bukkit.getPluginManager().registerEvents(this, instance);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method will be called when the server is first loaded
|
* This method will be called when the server is first loaded
|
||||||
* <p>
|
* <p>
|
||||||
* The goal of the method is to register all the expansions as soon as possible
|
* The goal of the method is to register all the expansions as soon as possible
|
||||||
* especially before players can join
|
* especially before players can join
|
||||||
* <p>
|
* <p>
|
||||||
* This will ensure no issues with expanions and hooks.
|
* This will ensure no issues with expansions and hooks.
|
||||||
*
|
*
|
||||||
* @param e the server load event
|
* @param event the server load event
|
||||||
*/
|
*/
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onServerLoad(ServerLoadEvent e) {
|
public void onServerLoad(@NotNull final ServerLoadEvent event)
|
||||||
plugin.getLogger().info("Placeholder expansion registration initializing...");
|
{
|
||||||
final Map<String, PlaceholderHook> alreadyRegistered = PlaceholderAPI.getPlaceholders();
|
HandlerList.unregisterAll(this);
|
||||||
plugin.getExpansionManager().registerAllExpansions();
|
plugin.getExpansionManager().initializeExpansions();
|
||||||
|
}
|
||||||
|
|
||||||
if (alreadyRegistered != null && !alreadyRegistered.isEmpty()) {
|
|
||||||
alreadyRegistered.forEach(PlaceholderAPI::registerPlaceholderHook);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user