From a2d408aea90c7dd1cdfb4481b9e81a88ed85e15e Mon Sep 17 00:00:00 2001 From: extendedclip Date: Sun, 5 May 2019 13:21:28 -0400 Subject: [PATCH] Possible solution for placeholders that register externally before PlaceholderAPI registers expansions --- .../java/me/clip/placeholderapi/PlaceholderAPIPlugin.java | 7 +++++++ .../me/clip/placeholderapi/ServerLoadEventListener.java | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java b/src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java index 258ca3b..48fd4e4 100644 --- a/src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java +++ b/src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java @@ -140,7 +140,14 @@ public class PlaceholderAPIPlugin extends JavaPlugin { @Override public void run() { getLogger().info("Placeholder expansion registration initializing..."); + //fetch any hooks that may have registered externally onEnable first otherwise they will be lost + final Map alreadyRegistered = PlaceholderAPI.getPlaceholders(); getExpansionManager().registerAllExpansions(); + if (alreadyRegistered != null && !alreadyRegistered.isEmpty()) { + alreadyRegistered.entrySet().stream().forEach(hook -> { + PlaceholderAPI.registerPlaceholderHook(hook.getKey(), hook.getValue()); + }); + } } }, 20*15); } diff --git a/src/main/java/me/clip/placeholderapi/ServerLoadEventListener.java b/src/main/java/me/clip/placeholderapi/ServerLoadEventListener.java index cff46b1..93a8be2 100644 --- a/src/main/java/me/clip/placeholderapi/ServerLoadEventListener.java +++ b/src/main/java/me/clip/placeholderapi/ServerLoadEventListener.java @@ -1,5 +1,6 @@ package me.clip.placeholderapi; +import java.util.Map; import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -17,6 +18,12 @@ public class ServerLoadEventListener implements Listener { @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.entrySet().stream().forEach(hook -> { + PlaceholderAPI.registerPlaceholderHook(hook.getKey(), hook.getValue()); + }); + } } }