From e05d81748229f71d4d6a0958cbf9487da482ca91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Thu, 9 Jul 2020 16:38:46 +0200 Subject: [PATCH] Fix plot owner placeholder. Fixes PS-62. --- .../bukkit/placeholder/Placeholders.java | 22 +++++---------- .../com/plotsquared/core/util/MainUtil.java | 27 ++++++++++++++++--- 2 files changed, 31 insertions(+), 18 deletions(-) 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 5457dbe0f..c61b29f37 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/Placeholders.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/Placeholders.java @@ -26,17 +26,16 @@ package com.plotsquared.bukkit.placeholder; import com.plotsquared.core.PlotSquared; -import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.flag.GlobalFlagContainer; import com.plotsquared.core.plot.flag.PlotFlag; +import com.plotsquared.core.util.MainUtil; import me.clip.placeholderapi.PlaceholderAPIPlugin; import me.clip.placeholderapi.expansion.PlaceholderExpansion; import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import java.util.Set; import java.util.UUID; public class Placeholders extends PlaceholderExpansion { @@ -117,23 +116,16 @@ public class Placeholders extends PlaceholderExpansion { return plot.getAlias(); } case "currentplot_owner": { - final Set o = plot.getOwners(); - if (o == null || o.isEmpty()) { - return ""; - } - final UUID uid = (UUID) o.toArray()[0]; - if (uid == null) { + final UUID plotOwner = plot.getOwnerAbs(); + if (plotOwner == null) { return ""; } - String name = PlotSquared.get().getImpromptuUUIDPipeline() - .getSingle(uid, Settings.UUID.BLOCKING_TIMEOUT); + try { + return MainUtil.getName(plotOwner, false); + } catch (final Exception ignored) {} - if (name != null) { - return name; - } - - name = Bukkit.getOfflinePlayer(uid).getName(); + final String name = Bukkit.getOfflinePlayer(plotOwner).getName(); return name != null ? name : "unknown"; } case "currentplot_members": { diff --git a/Core/src/main/java/com/plotsquared/core/util/MainUtil.java b/Core/src/main/java/com/plotsquared/core/util/MainUtil.java index 9e2a78853..9f79f3273 100644 --- a/Core/src/main/java/com/plotsquared/core/util/MainUtil.java +++ b/Core/src/main/java/com/plotsquared/core/util/MainUtil.java @@ -372,10 +372,21 @@ public class MainUtil { /** * Get the name from a UUID. * - * @param owner + * @param owner Owner UUID * @return The player's name, None, Everyone or Unknown */ - @NotNull public static String getName(UUID owner) { + @NotNull public static String getName(@Nullable UUID owner) { + return getName(owner, true); + } + + /** + * Get the name from a UUID. + * + * @param owner Owner UUID + * @param blocking Whether or not the operation can be blocking + * @return The player's name, None, Everyone or Unknown + */ + @NotNull public static String getName(@Nullable final UUID owner, final boolean blocking) { if (owner == null) { return Captions.NONE.getTranslated(); } @@ -385,7 +396,17 @@ public class MainUtil { if (owner.equals(DBFunc.SERVER)) { return Captions.SERVER.getTranslated(); } - String name = PlotSquared.get().getImpromptuUUIDPipeline().getSingle(owner, Settings.UUID.BLOCKING_TIMEOUT); + final String name; + if (blocking) { + name = PlotSquared.get().getImpromptuUUIDPipeline().getSingle(owner, Settings.UUID.BLOCKING_TIMEOUT); + } else { + final UUIDMapping uuidMapping = PlotSquared.get().getImpromptuUUIDPipeline().getImmediately(owner); + if (uuidMapping != null) { + name = uuidMapping.getUsername(); + } else { + name = null; + } + } if (name == null) { return Captions.UNKNOWN.getTranslated(); }