From ac79e535053034227608799f2e2e93d9b92d80ea Mon Sep 17 00:00:00 2001 From: antony1060 Date: Tue, 22 Dec 2020 14:39:02 +0100 Subject: [PATCH 1/2] Fixed PAPI & added Lombok to pom.xml --- pom.xml | 10 ++- .../koth/hooks/PlaceholderAPIHook.java | 87 ++++++++++++------- 2 files changed, 64 insertions(+), 33 deletions(-) diff --git a/pom.xml b/pom.xml index 5c7b767..becb602 100644 --- a/pom.xml +++ b/pom.xml @@ -32,6 +32,14 @@ + + + org.projectlombok + lombok + 1.18.16 + provided + + org.spigotmc spigot-api @@ -46,7 +54,7 @@ me.clip placeholderapi - 2.0.8 + 2.10.9 provided diff --git a/src/subside/plugins/koth/hooks/PlaceholderAPIHook.java b/src/subside/plugins/koth/hooks/PlaceholderAPIHook.java index d766056..761ea5f 100644 --- a/src/subside/plugins/koth/hooks/PlaceholderAPIHook.java +++ b/src/subside/plugins/koth/hooks/PlaceholderAPIHook.java @@ -1,8 +1,9 @@ package subside.plugins.koth.hooks; +import me.clip.placeholderapi.expansion.PlaceholderExpansion; import org.bukkit.entity.Player; -import me.clip.placeholderapi.external.EZPlaceholderHook; +import org.jetbrains.annotations.NotNull; import subside.plugins.koth.KothPlugin; import subside.plugins.koth.areas.Koth; import subside.plugins.koth.gamemodes.RunningKoth; @@ -13,22 +14,45 @@ /** * Made in collaboration with F64_Rx <3 */ -public class PlaceholderAPIHook extends EZPlaceholderHook { +public class PlaceholderAPIHook extends PlaceholderExpansion { KothPlugin plugin; public PlaceholderAPIHook(KothPlugin plugin) { - super(plugin, "koth"); - this.plugin = plugin; } + @Override + public @NotNull String getIdentifier() { + return "koth"; + } + + @Override + public @NotNull String getAuthor() { + return String.join(", ", plugin.getDescription().getAuthors()); + } + + @Override + public @NotNull String getVersion() { + return plugin.getDescription().getVersion(); + } + + @Override + public boolean canRegister() { + return true; + } + + @Override + public boolean persist() { + return true; + } + @Override public String onPlaceholderRequest(Player player, String identifier) { if (player == null) { return ""; } - - + + // Loop over all all live KoTH's if(identifier.startsWith("live_")){ for(Koth koth : plugin.getKothHandler().getAvailableKoths()){ @@ -36,61 +60,61 @@ public String onPlaceholderRequest(Player player, String identifier) { if(replacer != null) return replacer; } } - + // Loop over all schedules. if(identifier.startsWith("next_")){ if(plugin.getScheduleHandler().getNextEvent() != null){ Schedule schedule = plugin.getScheduleHandler().getNextEvent(); if(schedule == null) return ""; - + if(schedule.getKoth().startsWith("$")){ String scheduleReplacer = replaceSchedulingHolders(identifier, "next_", schedule); if(scheduleReplacer != null) return scheduleReplacer; - + return "???"; } - + Koth koth = plugin.getKothHandler().getKoth(schedule.getKoth()); if(koth == null) return ""; - + String replacer = replaceHolders(identifier, "next_", koth, player); if(replacer != null) return replacer; } } - + // Check if there is a running KoTH if (plugin.getKothHandler().getRunningKoth() == null) return ""; - + RunningKoth rKoth = plugin.getKothHandler().getRunningKoth(); if (rKoth == null) return ""; - + String replacer = replaceHolders(identifier, "", rKoth.getKoth(), player); if(replacer != null) return replacer; - + return ""; } - + public String replaceHolders(String identifier, String prefix, Koth koth, Player player){ - + if (identifier.equals(prefix+"name")) return koth.getName(); if (identifier.equals(prefix+"x")) return koth.getMiddle().getBlockX() + ""; if (identifier.equals(prefix+"y")) return koth.getMiddle().getBlockY() + ""; if (identifier.equals(prefix+"z")) return koth.getMiddle().getBlockZ() + ""; if (identifier.equals(prefix+"world")) return koth.getMiddle().getWorld().getName(); - + if (identifier.equals(prefix+"player_inarea")) return koth.isInArea(player)?"True":"False"; - + if(identifier.equals(prefix+"nextevent")) return TimeObject.getTimeTillNextEvent(plugin, koth); - + if(identifier.equals(prefix+"lastwinner")){ if(koth.getLastWinner() == null) return ""; return koth.getLastWinner().getName(); } - + if(identifier.equals(prefix+"isrunning")) return koth.isRunning()?"True":"False"; - + if (identifier.equals(prefix+"loot_x")) { if (koth.getLootPos() == null) return "No Loot Set"; return "" + koth.getLootPos().getBlockX(); @@ -107,23 +131,23 @@ public String replaceHolders(String identifier, String prefix, Koth koth, Player if (koth.getLootPos() == null) return "No Loot Set"; return "" + koth.getLootPos().getWorld().getName(); } - + RunningKoth rKoth = koth.getRunningKoth(); if (rKoth != null){ return replaceRunningKothHolders(identifier, prefix, rKoth); } - - + + return null; } - + public String replaceSchedulingHolders(String identifier, String prefix, Schedule schedule){ if (identifier.equals(prefix+"nextevent")) return TimeObject.getTimeTillNextEvent(schedule); if (identifier.equals(prefix+"name")) return schedule.getKoth(); if (identifier.equals(prefix+"time")) return schedule.getTime(); return null; } - + public String replaceRunningKothHolders(String identifier, String prefix, RunningKoth rKoth){ if (identifier.equals(prefix+"time_secondsleft")) return "" + rKoth.getTimeObject().getSecondsLeft(); @@ -138,19 +162,18 @@ public String replaceRunningKothHolders(String identifier, String prefix, Runnin if (identifier.equals(prefix+"time_lengthinseconds")) return "" + rKoth.getTimeObject().getLengthInSeconds(); if (identifier.equals(prefix+"time_percentagecapped")) return "" + rKoth.getTimeObject().getPercentageCapped(); if (identifier.equals(prefix+"time_percentageleft")) return "" + rKoth.getTimeObject().getPercentageLeft(); - + if (identifier.equals(prefix+"currentcapper")) { if (rKoth.getCapper() == null) return Lang.HOOKS_PLACEHOLDERAPI_NOONECAPPING[0]; return rKoth.getCapper().getName(); } - - + + if (identifier.equals(prefix+"loot_name")) { if (rKoth.getLootChest() == null) return "No Loot Set"; return rKoth.getLootChest(); } - + return null; } - } From fed8fdf09a503aee3a423d833f2217b3e0afff80 Mon Sep 17 00:00:00 2001 From: antony1060 Date: Tue, 22 Dec 2020 14:41:00 +0100 Subject: [PATCH 2/2] Some additional fixes --- src/subside/plugins/koth/hooks/HookManager.java | 2 +- src/subside/plugins/koth/hooks/PlaceholderAPIHook.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/subside/plugins/koth/hooks/HookManager.java b/src/subside/plugins/koth/hooks/HookManager.java index 88c0c07..02730d9 100644 --- a/src/subside/plugins/koth/hooks/HookManager.java +++ b/src/subside/plugins/koth/hooks/HookManager.java @@ -29,7 +29,7 @@ public void onEnable(){ registerHook(new EssentialsVanishHook(this)); if(Bukkit.getServer().getPluginManager().isPluginEnabled("PlaceholderAPI")){ - new PlaceholderAPIHook(plugin).hook(); + new PlaceholderAPIHook(plugin).register(); } } diff --git a/src/subside/plugins/koth/hooks/PlaceholderAPIHook.java b/src/subside/plugins/koth/hooks/PlaceholderAPIHook.java index 761ea5f..a3df58f 100644 --- a/src/subside/plugins/koth/hooks/PlaceholderAPIHook.java +++ b/src/subside/plugins/koth/hooks/PlaceholderAPIHook.java @@ -47,7 +47,7 @@ public boolean persist() { } @Override - public String onPlaceholderRequest(Player player, String identifier) { + public String onPlaceholderRequest(Player player, @NotNull String identifier) { if (player == null) { return ""; }