PlaceholderAPI expansion revamp

This commit is contained in:
DroppingAnvil 2020-04-29 16:31:47 -05:00 committed by droppinganvil
parent 69a4651e23
commit 86cba0e24c
3 changed files with 34 additions and 4 deletions

View File

@ -46,14 +46,14 @@ public class ShopGUIFrame {
for (int a = 1; a <= items; a++) { for (int a = 1; a <= items; a++) {
String s = a + ""; String s = a + "";
int slot = FactionsPlugin.getInstance().getFileManager().getShop().fetchInt("items." + s + ".slot"); 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"); int cost = FactionsPlugin.getInstance().getFileManager().getShop().fetchInt("items." + s + ".cost");
String name = FactionsPlugin.getInstance().getFileManager().getShop().fetchString("items." + s + ".name"); String name = FactionsPlugin.getInstance().getFileManager().getShop().fetchString("items." + s + ".name");
boolean glowing = FactionsPlugin.getInstance().getFileManager().getShop().fetchBoolean("items." + s + ".glowing"); boolean glowing = FactionsPlugin.getInstance().getFileManager().getShop().fetchBoolean("items." + s + ".glowing");
List<String> lore = FactionsPlugin.getInstance().getFileManager().getShop().fetchStringList("items." + s + ".lore"); List<String> lore = FactionsPlugin.getInstance().getFileManager().getShop().fetchStringList("items." + s + ".lore");
ItemStack item = new ItemStack(material); assert item != null;
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
meta.setDisplayName(FactionsPlugin.instance.color(name)); meta.setDisplayName(FactionsPlugin.instance.color(name));
meta.addItemFlags(); meta.addItemFlags();

View File

@ -14,7 +14,10 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.UUID; import java.util.UUID;
import java.util.logging.Level;
public class ClipPlaceholderAPIManager extends PlaceholderExpansion implements Relational { 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())); Faction factionAtLocation = Board.getInstance().getFactionAt(new FLocation(player.getLocation()));
return factionAtLocation != null ? factionAtLocation.getTag() : Factions.getInstance().getWilderness().getTag(); 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) { private int countOn(Faction f, Relation relation, Boolean status, FPlayer player) {
int count = 0; int count = 0;

View File

@ -1284,7 +1284,9 @@ public enum TL {
WARMUPS_NOTIFY_FLIGHT("&eFlight will enable in &d%2$d &eseconds."), 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_NOTIFY_TELEPORT("&eYou will teleport to &d%1$s &ein &d%2$d &eseconds."),
WARMUPS_ALREADY("&cYou are already warming up."), 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; public static SimpleDateFormat sdf;
private static YamlConfiguration LANG; private static YamlConfiguration LANG;