From 86cba0e24c69ab5c49dfad6e5db4d71817aa864c Mon Sep 17 00:00:00 2001 From: DroppingAnvil Date: Wed, 29 Apr 2020 16:31:47 -0500 Subject: [PATCH] PlaceholderAPI expansion revamp --- .../factions/shop/ShopGUIFrame.java | 4 +-- .../util/ClipPlaceholderAPIManager.java | 30 ++++++++++++++++++- .../massivecraft/factions/zcore/util/TL.java | 4 ++- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/shop/ShopGUIFrame.java b/src/main/java/com/massivecraft/factions/shop/ShopGUIFrame.java index 30d376f0..5f7667c4 100644 --- a/src/main/java/com/massivecraft/factions/shop/ShopGUIFrame.java +++ b/src/main/java/com/massivecraft/factions/shop/ShopGUIFrame.java @@ -46,14 +46,14 @@ public class ShopGUIFrame { for (int a = 1; a <= items; a++) { String s = a + ""; int slot = FactionsPlugin.getInstance().getFileManager().getShop().fetchInt("items." + s + ".slot"); - ItemStack material = XMaterial.matchXMaterial(FactionsPlugin.getInstance().getFileManager().getShop().fetchString("items." + s + ".block")).get().parseItem(); + ItemStack item = XMaterial.matchXMaterial(FactionsPlugin.getInstance().getFileManager().getShop().fetchString("items." + s + ".block")).get().parseItem(); int cost = FactionsPlugin.getInstance().getFileManager().getShop().fetchInt("items." + s + ".cost"); String name = FactionsPlugin.getInstance().getFileManager().getShop().fetchString("items." + s + ".name"); boolean glowing = FactionsPlugin.getInstance().getFileManager().getShop().fetchBoolean("items." + s + ".glowing"); List lore = FactionsPlugin.getInstance().getFileManager().getShop().fetchStringList("items." + s + ".lore"); - ItemStack item = new ItemStack(material); + assert item != null; ItemMeta meta = item.getItemMeta(); meta.setDisplayName(FactionsPlugin.instance.color(name)); meta.addItemFlags(); diff --git a/src/main/java/com/massivecraft/factions/util/ClipPlaceholderAPIManager.java b/src/main/java/com/massivecraft/factions/util/ClipPlaceholderAPIManager.java index 663beac8..8d00c614 100644 --- a/src/main/java/com/massivecraft/factions/util/ClipPlaceholderAPIManager.java +++ b/src/main/java/com/massivecraft/factions/util/ClipPlaceholderAPIManager.java @@ -14,7 +14,10 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; +import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; import java.util.UUID; +import java.util.logging.Level; public class ClipPlaceholderAPIManager extends PlaceholderExpansion implements Relational { @@ -220,10 +223,35 @@ public class ClipPlaceholderAPIManager extends PlaceholderExpansion implements R Faction factionAtLocation = Board.getInstance().getFactionAt(new FLocation(player.getLocation())); return factionAtLocation != null ? factionAtLocation.getTag() : Factions.getInstance().getWilderness().getTag(); } + //If its not hardcoded lets try to grab it anyways + boolean targetFaction = false; + Object target = fPlayer; + String stripped = ""; + if (placeholder.startsWith("faction_")) { + targetFaction = true; + target = faction; + stripped = placeholder.replace("faction_", ""); + } else { + stripped = placeholder.replace("player_", ""); + } + try { + Object pulled; + if (targetFaction) { + pulled = Faction.class.getDeclaredMethod(stripped).invoke(target); + } else { + pulled = FPlayer.class.getDeclaredMethod(stripped).invoke(target); + } + return String.valueOf(pulled); + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + logInvalid(stripped); + } - return null; + return TL.PLACEHOLDERAPI_NULL.toString(); } + private static void logInvalid(String placeholder) { + FactionsPlugin.getInstance().getLogger().log(Level.INFO, "Invalid request through PlaceholderAPI for placeholder '" + placeholder + "'"); + } private int countOn(Faction f, Relation relation, Boolean status, FPlayer player) { int count = 0; diff --git a/src/main/java/com/massivecraft/factions/zcore/util/TL.java b/src/main/java/com/massivecraft/factions/zcore/util/TL.java index 9b8b4262..36003de7 100644 --- a/src/main/java/com/massivecraft/factions/zcore/util/TL.java +++ b/src/main/java/com/massivecraft/factions/zcore/util/TL.java @@ -1284,7 +1284,9 @@ public enum TL { WARMUPS_NOTIFY_FLIGHT("&eFlight will enable in &d%2$d &eseconds."), WARMUPS_NOTIFY_TELEPORT("&eYou will teleport to &d%1$s &ein &d%2$d &eseconds."), WARMUPS_ALREADY("&cYou are already warming up."), - WARMUPS_CANCELLED("&cYou have cancelled your warmup."); + WARMUPS_CANCELLED("&cYou have cancelled your warmup."), + + PLACEHOLDERAPI_NULL(""); public static SimpleDateFormat sdf; private static YamlConfiguration LANG;