diff --git a/pom.xml b/pom.xml index 472bcc80..1ea5286c 100644 --- a/pom.xml +++ b/pom.xml @@ -295,6 +295,12 @@ PlayerVaults 3.6.0 + + me.clip + placeholderapi + 2.8.2 + provided + @@ -318,5 +324,9 @@ repo.mikeprimm.com http://repo.mikeprimm.com/ + + placeholderapi + http://repo.extendedclip.com/content/repositories/placeholderapi/ + diff --git a/src/main/java/com/massivecraft/factions/P.java b/src/main/java/com/massivecraft/factions/P.java index fbeb8c31..ad99ec7f 100644 --- a/src/main/java/com/massivecraft/factions/P.java +++ b/src/main/java/com/massivecraft/factions/P.java @@ -58,6 +58,7 @@ public class P extends MPlugin { public CmdAutoHelp cmdAutoHelp; private boolean hookedPlayervaults; + private PlaceholderAPIManager placeholderAPIManager; public P() { p = this; @@ -116,10 +117,20 @@ public class P extends MPlugin { // since some other plugins execute commands directly through this command interface, provide it this.getCommand(this.refCommand).setExecutor(this); + setupPlaceholderAPI(); postEnable(); this.loadSuccessful = true; } + private void setupPlaceholderAPI() { + Plugin plugin = getServer().getPluginManager().getPlugin("PlaceholderAPI"); + if (plugin != null && plugin.isEnabled()) { + this.placeholderAPIManager = new PlaceholderAPIManager(); + this.placeholderAPIManager.hook(); + log(Level.INFO, "Found PlaceholderAPI. Adding hooks."); + } + } + private boolean setupPermissions() { try { RegisteredServiceProvider rsp = getServer().getServicesManager().getRegistration(Permission.class); diff --git a/src/main/java/com/massivecraft/factions/util/PlaceholderAPIManager.java b/src/main/java/com/massivecraft/factions/util/PlaceholderAPIManager.java new file mode 100644 index 00000000..b55c9017 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/util/PlaceholderAPIManager.java @@ -0,0 +1,31 @@ +package com.massivecraft.factions.util; + +import com.massivecraft.factions.FPlayer; +import com.massivecraft.factions.FPlayers; +import com.massivecraft.factions.P; +import me.clip.placeholderapi.external.EZPlaceholderHook; +import org.bukkit.entity.Player; + +public class PlaceholderAPIManager extends EZPlaceholderHook { + + public PlaceholderAPIManager() { + super(P.p, "factionsuuid"); + } + + @Override + public String onPlaceholderRequest(Player player, String placeholder) { + if(player == null || placeholder == null) { + return ""; + } + + FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player); + switch(placeholder) { + case "faction": + return fPlayer.getFaction().getTag(); + case "power": + return String.valueOf(fPlayer.getPower()); + } + + return null; + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 7df77afd..662b3cff 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -2,7 +2,7 @@ name: Factions version: ${project.version} main: com.massivecraft.factions.P authors: [Olof Larsson, Brett Flannigan, drtshock] -softdepend: [PlayerVaults, PermissionsEx, Permissions, Essentials, EssentialsChat, HeroChat, iChat, LocalAreaChat, LWC, nChat, ChatManager, CAPI, AuthMe, Vault, Spout, WorldEdit, WorldGuard, AuthDB, CaptureThePoints, CombatTag, dynmap] +softdepend: [PlayerVaults, PlaceholderAPI, PermissionsEx, Permissions, Essentials, EssentialsChat, HeroChat, iChat, LocalAreaChat, LWC, nChat, ChatManager, CAPI, AuthMe, Vault, Spout, WorldEdit, WorldGuard, AuthDB, CaptureThePoints, CombatTag, dynmap] commands: factions: description: Reference command for Factions.