From 9a66681e52ad2ab30fb0e26e5500240688ee36bc Mon Sep 17 00:00:00 2001 From: Magnus Ulf Date: Sun, 20 Jan 2019 14:09:04 +0100 Subject: [PATCH] Improve PlaceholderAPI integration --- .../IntegrationPlaceholderAPI.java | 24 +++++++++++++++++++ .../placeholderapi/PlaceholderFactions.java | 6 +++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/com/massivecraft/factions/integration/placeholderapi/IntegrationPlaceholderAPI.java b/src/com/massivecraft/factions/integration/placeholderapi/IntegrationPlaceholderAPI.java index 689d8125..1c2f1c5b 100644 --- a/src/com/massivecraft/factions/integration/placeholderapi/IntegrationPlaceholderAPI.java +++ b/src/com/massivecraft/factions/integration/placeholderapi/IntegrationPlaceholderAPI.java @@ -1,6 +1,11 @@ package com.massivecraft.factions.integration.placeholderapi; import com.massivecraft.massivecore.Integration; +import me.clip.placeholderapi.PlaceholderAPIPlugin; +import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; public class IntegrationPlaceholderAPI extends Integration { @@ -22,7 +27,26 @@ public class IntegrationPlaceholderAPI extends Integration @Override public void setIntegrationActiveInner(boolean active) { + PlaceholderAPIPlugin.getInstance().getExpansionManager().registerExpansion(PlaceholderFactions.get()); + } + + public static void ensureRegistered() + { + if (PlaceholderFactions.get().isRegistered()) return; PlaceholderFactions.get().register(); } + + // If the PlaceholderAPI command is run to reload the config + // then we should reregister. + @EventHandler(priority = EventPriority.MONITOR) + public void lookForCommand(PlayerCommandPreprocessEvent event) + { + String str = event.getMessage(); + if (str.startsWith("/")) str = str.substring(1); + + if (!str.startsWith("papi")) return; + Bukkit.getScheduler().runTaskLater(this.getPlugin(), IntegrationPlaceholderAPI::ensureRegistered, 20L); + } + } diff --git a/src/com/massivecraft/factions/integration/placeholderapi/PlaceholderFactions.java b/src/com/massivecraft/factions/integration/placeholderapi/PlaceholderFactions.java index 3a5eb052..9b1e4f5e 100644 --- a/src/com/massivecraft/factions/integration/placeholderapi/PlaceholderFactions.java +++ b/src/com/massivecraft/factions/integration/placeholderapi/PlaceholderFactions.java @@ -19,16 +19,19 @@ public class PlaceholderFactions extends PlaceholderExpansion // OVERRIDE // -------------------------------------------- // + @Override public String getIdentifier() { return "factions"; } + @Override public String getAuthor() { return "Madus"; } + @Override public String getVersion() { return Factions.get().getDescription().getVersion(); @@ -37,9 +40,7 @@ public class PlaceholderFactions extends PlaceholderExpansion @Override public String onPlaceholderRequest(Player player, String params) { - System.out.println("A"); if (player == null) return null; - System.out.println("B"); MPlayer mplayer = MPlayer.get(player); @@ -59,4 +60,5 @@ public class PlaceholderFactions extends PlaceholderExpansion } return null; } + }