Improve PlaceholderAPI integration

This commit is contained in:
Magnus Ulf 2019-01-20 14:09:04 +01:00
parent bb9a72dbf6
commit 9a66681e52
2 changed files with 28 additions and 2 deletions

View File

@ -1,6 +1,11 @@
package com.massivecraft.factions.integration.placeholderapi; package com.massivecraft.factions.integration.placeholderapi;
import com.massivecraft.massivecore.Integration; 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 public class IntegrationPlaceholderAPI extends Integration
{ {
@ -22,7 +27,26 @@ public class IntegrationPlaceholderAPI extends Integration
@Override @Override
public void setIntegrationActiveInner(boolean active) public void setIntegrationActiveInner(boolean active)
{ {
PlaceholderAPIPlugin.getInstance().getExpansionManager().registerExpansion(PlaceholderFactions.get());
}
public static void ensureRegistered()
{
if (PlaceholderFactions.get().isRegistered()) return;
PlaceholderFactions.get().register(); 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);
}
} }

View File

@ -19,16 +19,19 @@ public class PlaceholderFactions extends PlaceholderExpansion
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override
public String getIdentifier() public String getIdentifier()
{ {
return "factions"; return "factions";
} }
@Override
public String getAuthor() public String getAuthor()
{ {
return "Madus"; return "Madus";
} }
@Override
public String getVersion() public String getVersion()
{ {
return Factions.get().getDescription().getVersion(); return Factions.get().getDescription().getVersion();
@ -37,9 +40,7 @@ public class PlaceholderFactions extends PlaceholderExpansion
@Override @Override
public String onPlaceholderRequest(Player player, String params) public String onPlaceholderRequest(Player player, String params)
{ {
System.out.println("A");
if (player == null) return null; if (player == null) return null;
System.out.println("B");
MPlayer mplayer = MPlayer.get(player); MPlayer mplayer = MPlayer.get(player);
@ -59,4 +60,5 @@ public class PlaceholderFactions extends PlaceholderExpansion
} }
return null; return null;
} }
} }