Improve PlaceholderAPI integration
This commit is contained in:
parent
bb9a72dbf6
commit
9a66681e52
@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user