Possible solution for placeholders that register externally before PlaceholderAPI registers expansions

This commit is contained in:
extendedclip 2019-05-05 13:21:28 -04:00
parent 5386b7c23d
commit a2d408aea9
2 changed files with 14 additions and 0 deletions

View File

@ -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<String, PlaceholderHook> alreadyRegistered = PlaceholderAPI.getPlaceholders();
getExpansionManager().registerAllExpansions();
if (alreadyRegistered != null && !alreadyRegistered.isEmpty()) {
alreadyRegistered.entrySet().stream().forEach(hook -> {
PlaceholderAPI.registerPlaceholderHook(hook.getKey(), hook.getValue());
});
}
}
}, 20*15);
}

View File

@ -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<String, PlaceholderHook> alreadyRegistered = PlaceholderAPI.getPlaceholders();
plugin.getExpansionManager().registerAllExpansions();
if (alreadyRegistered != null && !alreadyRegistered.isEmpty()) {
alreadyRegistered.entrySet().stream().forEach(hook -> {
PlaceholderAPI.registerPlaceholderHook(hook.getKey(), hook.getValue());
});
}
}
}