diff --git a/Core/src/main/java/com/plotsquared/core/command/Add.java b/Core/src/main/java/com/plotsquared/core/command/Add.java index b9b250287..a5d35d9ec 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Add.java +++ b/Core/src/main/java/com/plotsquared/core/command/Add.java @@ -106,7 +106,7 @@ public class Add extends Command { .hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_TRUST))) { player.sendMessage( TranslatableCaption.of("errors.invalid_player"), - Template.of("value", PlayerManager.getName(uuid)) + Template.of("value", PlayerManager.resolveName(uuid).getComponent(player)) ); iterator.remove(); continue; @@ -114,7 +114,7 @@ public class Add extends Command { if (plot.isOwner(uuid)) { player.sendMessage( TranslatableCaption.of("member.already_added"), - Template.of("player", PlayerManager.getName(uuid)) + Template.of("player", PlayerManager.resolveName(uuid).getComponent(player)) ); iterator.remove(); continue; @@ -122,7 +122,7 @@ public class Add extends Command { if (plot.getMembers().contains(uuid)) { player.sendMessage( TranslatableCaption.of("member.already_added"), - Template.of("player", PlayerManager.getName(uuid)) + Template.of("player", PlayerManager.resolveName(uuid).getComponent(player)) ); iterator.remove(); continue; diff --git a/Core/src/main/java/com/plotsquared/core/command/Deny.java b/Core/src/main/java/com/plotsquared/core/command/Deny.java index e03fb554b..0c925dd76 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Deny.java +++ b/Core/src/main/java/com/plotsquared/core/command/Deny.java @@ -125,7 +125,7 @@ public class Deny extends SubCommand { } else if (plot.getDenied().contains(uuid)) { player.sendMessage( TranslatableCaption.of("member.already_added"), - Template.of("player", PlayerManager.getName(uuid)) + Template.of("player", PlayerManager.resolveName(uuid).getComponent(player)) ); return; } else { diff --git a/Core/src/main/java/com/plotsquared/core/command/Owner.java b/Core/src/main/java/com/plotsquared/core/command/Owner.java index 8360aa07f..661d70665 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Owner.java +++ b/Core/src/main/java/com/plotsquared/core/command/Owner.java @@ -142,7 +142,7 @@ public class Owner extends SetCommand { if (plot.isOwner(uuid)) { player.sendMessage( TranslatableCaption.of("member.already_owner"), - Template.of("player", PlayerManager.getName(uuid, false)) + Template.of("player", PlayerManager.resolveName(uuid, false).getComponent(player)) ); return; } @@ -151,7 +151,7 @@ public class Owner extends SetCommand { if (other == null) { player.sendMessage( TranslatableCaption.of("errors.invalid_player_offline"), - Template.of("player", PlayerManager.getName(uuid)) + Template.of("player", PlayerManager.resolveName(uuid).getComponent(player)) ); return; } diff --git a/Core/src/main/java/com/plotsquared/core/command/Trust.java b/Core/src/main/java/com/plotsquared/core/command/Trust.java index f437ae1cf..80111f4b7 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Trust.java +++ b/Core/src/main/java/com/plotsquared/core/command/Trust.java @@ -112,7 +112,7 @@ public class Trust extends Command { .hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_TRUST))) { player.sendMessage( TranslatableCaption.of("errors.invalid_player"), - Template.of("value", PlayerManager.getName(uuid)) + Template.of("value", PlayerManager.resolveName(uuid).getComponent(player)) ); iterator.remove(); continue; @@ -120,7 +120,7 @@ public class Trust extends Command { if (currentPlot.isOwner(uuid)) { player.sendMessage( TranslatableCaption.of("member.already_added"), - Template.of("value", PlayerManager.getName(uuid)) + Template.of("value", PlayerManager.resolveName(uuid).getComponent(player)) ); iterator.remove(); continue; @@ -128,7 +128,7 @@ public class Trust extends Command { if (currentPlot.getTrusted().contains(uuid)) { player.sendMessage( TranslatableCaption.of("member.already_added"), - Template.of("value", PlayerManager.getName(uuid)) + Template.of("value", PlayerManager.resolveName(uuid).getComponent(player)) ); iterator.remove(); continue; diff --git a/Core/src/main/java/com/plotsquared/core/configuration/caption/Templates.java b/Core/src/main/java/com/plotsquared/core/configuration/caption/Templates.java index e6771f928..cc2c5b62d 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/caption/Templates.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/caption/Templates.java @@ -70,7 +70,7 @@ public final class Templates { * @return Generated template */ public static @NonNull Template of(final @NonNull String key, final @NonNull UUID uuid) { - final String username = PlayerManager.getName(uuid); + final String username = PlayerManager.resolveName(uuid).getComponent(LocaleHolder.console()); return Template.of(key, username); } diff --git a/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java b/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java index a3911a69e..776ee6694 100644 --- a/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java +++ b/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java @@ -321,7 +321,7 @@ public class PlotListener { } if ((lastPlot != null) && plot.getId().equals(lastPlot.getId()) && plot.hasOwner()) { final UUID plotOwner = plot.getOwnerAbs(); - String owner = PlayerManager.getName(plotOwner, false); + String owner = PlayerManager.resolveName(plotOwner, false).getComponent(player); Caption header = fromFlag ? StaticCaption.of(title) : TranslatableCaption.of("titles" + ".title_entered_plot"); Caption subHeader = fromFlag ? StaticCaption.of(subtitle) : TranslatableCaption.of("titles" + diff --git a/Core/src/main/java/com/plotsquared/core/plot/Plot.java b/Core/src/main/java/com/plotsquared/core/plot/Plot.java index a65a00342..b94bd889d 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/Plot.java +++ b/Core/src/main/java/com/plotsquared/core/plot/Plot.java @@ -2838,7 +2838,7 @@ public class Plot { if (time != 0) { seen = TimeUtil.secToTime(time); } else { - seen = TranslatableCaption.of("info.known").getComponent(player); + seen = TranslatableCaption.of("info.unknown").getComponent(player); } } } else { diff --git a/Core/src/main/java/com/plotsquared/core/plot/PlotModificationManager.java b/Core/src/main/java/com/plotsquared/core/plot/PlotModificationManager.java index 85e0fbdb8..bef13a243 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/PlotModificationManager.java +++ b/Core/src/main/java/com/plotsquared/core/plot/PlotModificationManager.java @@ -30,6 +30,7 @@ import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.ConfigurationUtil; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.caption.Caption; +import com.plotsquared.core.configuration.caption.LocaleHolder; import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.database.DBFunc; import com.plotsquared.core.events.PlotComponentSetEvent; @@ -358,7 +359,8 @@ public final class PlotModificationManager { if (createSign) { queue.setCompleteTask(() -> TaskManager.runTaskAsync(() -> { for (Plot current : plots) { - current.getPlotModificationManager().setSign(PlayerManager.getName(current.getOwnerAbs())); + current.getPlotModificationManager().setSign(PlayerManager.resolveName(current.getOwnerAbs()).getComponent( + LocaleHolder.console())); } })); } diff --git a/Core/src/main/java/com/plotsquared/core/util/PlayerManager.java b/Core/src/main/java/com/plotsquared/core/util/PlayerManager.java index 5f95cab1b..aac7e4fd2 100644 --- a/Core/src/main/java/com/plotsquared/core/util/PlayerManager.java +++ b/Core/src/main/java/com/plotsquared/core/util/PlayerManager.java @@ -27,7 +27,9 @@ package com.plotsquared.core.util; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Settings; +import com.plotsquared.core.configuration.caption.Caption; import com.plotsquared.core.configuration.caption.LocaleHolder; +import com.plotsquared.core.configuration.caption.StaticCaption; import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.database.DBFunc; import com.plotsquared.core.player.ConsolePlayer; @@ -162,7 +164,9 @@ public abstract class PlayerManager
, T> { * * @param owner Owner UUID * @return The player's name, None, Everyone or Unknown + * @deprecated Use {@link #resolveName(UUID)} */ + @Deprecated(forRemoval = true, since = "TODO") public static @NonNull String getName(final @Nullable UUID owner) { return getName(owner, true); } @@ -173,7 +177,9 @@ public abstract class PlayerManager
, T> { * @param owner Owner UUID * @param blocking Whether or not the operation can be blocking * @return The player's name, None, Everyone or Unknown + * @deprecated Use {@link #resolveName(UUID, boolean)} */ + @Deprecated(forRemoval = true, since = "TODO") public static @NonNull String getName(final @Nullable UUID owner, final boolean blocking) { if (owner == null) { TranslatableCaption.of("info.none"); @@ -203,6 +209,57 @@ public abstract class PlayerManager
, T> { return name; } + /** + * Attempts to resolve the username by an uuid + *
+ * Note: blocks the thread until the name was resolved or failed + * + * @param owner The UUID of the owner + * @return A caption containing either the name, {@code None}, {@code Everyone} or {@code Unknown} + * @see #resolveName(UUID, boolean) + * @since TODO + */ + public static @NonNull Caption resolveName(final @Nullable UUID owner) { + return resolveName(owner, true); + } + + /** + * Attempts to resolve the username by an uuid + * + * @param owner The UUID of the owner + * @param blocking If the operation should block the current thread for {@link Settings.UUID#BLOCKING_TIMEOUT} milliseconds + * @return A caption containing either the name, {@code None}, {@code Everyone} or {@code Unknown} + * @since TODO + */ + public static @NonNull Caption resolveName(final @Nullable UUID owner, final boolean blocking) { + if (owner == null) { + return TranslatableCaption.of("info.none"); + } + if (owner.equals(DBFunc.EVERYONE)) { + return TranslatableCaption.of("info.everyone"); + } + if (owner.equals(DBFunc.SERVER)) { + return TranslatableCaption.of("info.server"); + } + 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 TranslatableCaption.of("info.unknown"); + } + return StaticCaption.of(name); + } + /** * Remove a player from the player map * diff --git a/Core/src/main/java/com/plotsquared/core/util/placeholders/PlaceholderRegistry.java b/Core/src/main/java/com/plotsquared/core/util/placeholders/PlaceholderRegistry.java index 3bdcc46bd..f832061f5 100644 --- a/Core/src/main/java/com/plotsquared/core/util/placeholders/PlaceholderRegistry.java +++ b/Core/src/main/java/com/plotsquared/core/util/placeholders/PlaceholderRegistry.java @@ -116,7 +116,7 @@ public final class PlaceholderRegistry { } try { - return PlayerManager.getName(plotOwner, false); + return PlayerManager.resolveName(plotOwner, false).getComponent(player); } catch (final Exception ignored) { } return legacyComponent(TranslatableCaption.of("info.unknown"), player);