From 0fa99d7940059aaac73ab64146672b80615b80e5 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Thu, 23 Apr 2020 09:06:37 +0100 Subject: [PATCH] Never return null in Placeholder. Also slight cleanup. --- .../com/plotsquared/bukkit/BukkitMain.java | 2 +- .../bukkit/placeholder/Placeholders.java | 52 ++++++++++++------- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java index bb1bc1ae1..d253bc07b 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -200,7 +200,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain } if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { - new Placeholders(this).register(); + new Placeholders().register(); if (Settings.Enabled_Components.EXTERNAL_PLACEHOLDERS) { ChatFormatter.formatters.add(new PlaceholderFormatter()); } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/Placeholders.java b/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/Placeholders.java index c228dd898..d0ad0cfdb 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/Placeholders.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/Placeholders.java @@ -25,9 +25,8 @@ */ package com.plotsquared.bukkit.placeholder; -import com.plotsquared.bukkit.BukkitMain; -import com.plotsquared.core.plot.Plot; import com.plotsquared.core.player.PlotPlayer; +import com.plotsquared.core.plot.Plot; import com.plotsquared.core.util.uuid.UUIDHandler; import me.clip.placeholderapi.PlaceholderAPIPlugin; import me.clip.placeholderapi.expansion.PlaceholderExpansion; @@ -39,7 +38,7 @@ import java.util.UUID; public class Placeholders extends PlaceholderExpansion { - public Placeholders(BukkitMain plugin) { + public Placeholders() { } @Override @@ -64,26 +63,27 @@ public class Placeholders extends PlaceholderExpansion { @Override public String getVersion() { - return "2.3"; + return "2.4"; } @Override public String onPlaceholderRequest(Player p, String identifier) { final PlotPlayer pl = PlotPlayer.get(p.getName()); final Plot plot = pl.getCurrentPlot(); - if (pl == null) { - return ""; - } if (identifier.startsWith("has_plot_")) { - if (identifier.split("has_plot_").length != 2) return null; + if (identifier.split("has_plot_").length != 2) + return ""; identifier = identifier.split("has_plot_")[1]; - return pl.getPlotCount(identifier) > 0 ? PlaceholderAPIPlugin.booleanTrue() : PlaceholderAPIPlugin.booleanFalse(); + return pl.getPlotCount(identifier) > 0 ? + PlaceholderAPIPlugin.booleanTrue() : + PlaceholderAPIPlugin.booleanFalse(); } if (identifier.startsWith("plot_count_")) { - if (identifier.split("plot_count_").length != 2) return null; + if (identifier.split("plot_count_").length != 2) + return ""; identifier = identifier.split("plot_count_")[1]; return String.valueOf(pl.getPlotCount(identifier)); @@ -106,13 +106,20 @@ public class Placeholders extends PlaceholderExpansion { return ""; } final String name = UUIDHandler.getName(uid); - return (name != null) ? name : ((Bukkit.getOfflinePlayer(uid) != null) ? Bukkit.getOfflinePlayer(uid).getName() : "unknown"); + + return (name != null) ? + name : + ((Bukkit.getOfflinePlayer(uid).getName() != null) ? + Bukkit.getOfflinePlayer(uid).getName() : + "unknown"); } case "currentplot_world": { return p.getWorld().getName(); } case "has_plot": { - return (pl.getPlotCount() > 0) ? PlaceholderAPIPlugin.booleanTrue() : PlaceholderAPIPlugin.booleanFalse(); + return (pl.getPlotCount() > 0) ? + PlaceholderAPIPlugin.booleanTrue() : + PlaceholderAPIPlugin.booleanFalse(); } case "allowed_plot_count": { return String.valueOf(pl.getAllowedPlots()); @@ -124,10 +131,13 @@ public class Placeholders extends PlaceholderExpansion { if (pl.getCurrentPlot() == null) { return ""; } - if (pl.getCurrentPlot().getMembers() == null && pl.getCurrentPlot().getTrusted() == null) { + if (pl.getCurrentPlot().getMembers() == null + && pl.getCurrentPlot().getTrusted() == null) { return "0"; } - return String.valueOf(pl.getCurrentPlot().getMembers().size() + pl.getCurrentPlot().getTrusted().size()); + return String.valueOf( + pl.getCurrentPlot().getMembers().size() + pl.getCurrentPlot().getTrusted() + .size()); } case "currentplot_members_added": { if (pl.getCurrentPlot() == null) { @@ -157,25 +167,29 @@ public class Placeholders extends PlaceholderExpansion { return String.valueOf(pl.getCurrentPlot().getDenied().size()); } case "has_build_rights": { - return (pl.getCurrentPlot() != null) ? ((pl.getCurrentPlot().isAdded(pl.getUUID())) ? PlaceholderAPIPlugin.booleanTrue() : PlaceholderAPIPlugin.booleanFalse()) : ""; + return (pl.getCurrentPlot() != null) ? + ((pl.getCurrentPlot().isAdded(pl.getUUID())) ? + PlaceholderAPIPlugin.booleanTrue() : + PlaceholderAPIPlugin.booleanFalse()) : + ""; } case "currentplot_x": { if (pl.getCurrentPlot() == null) { return ""; } - return String.valueOf(plot.getId().x); + return String.valueOf(plot.getId().getX()); } case "currentplot_y": { if (pl.getCurrentPlot() == null) { return ""; } - return String.valueOf(plot.getId().y); + return String.valueOf(plot.getId().getY()); } case "currentplot_xy": { if (pl.getCurrentPlot() == null) { return ""; } - return pl.getCurrentPlot().getId().x + ";" + pl.getCurrentPlot().getId().y; + return pl.getCurrentPlot().getId().getX() + ";" + pl.getCurrentPlot().getId().getY(); } case "currentplot_rating": { if (pl.getCurrentPlot() == null) { @@ -192,6 +206,6 @@ public class Placeholders extends PlaceholderExpansion { default: break; } - return null; + return ""; } }