Fix: Missing Component returns + plot info on unknown plot owner (#3449)

* Fix: getName should return something

* Fix caption typo

* Deprecate old getName methods + add new methods for username retrieval

* Remove wildcard import

* Use @since TODO instead of hard coded version

* chore: Update `@since` tags to TODO

Co-authored-by: NotMyFault <mc.cache@web.de>
This commit is contained in:
Pierre Maurice Schwang 2022-01-19 15:56:31 +01:00 committed by GitHub
parent 6073b96317
commit 6f4d2f6d5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 73 additions and 14 deletions

View File

@ -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;

View File

@ -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 {

View File

@ -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;
}

View File

@ -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;

View File

@ -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);
}

View File

@ -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" +

View File

@ -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 {

View File

@ -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()));
}
}));
}

View File

@ -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<P extends PlotPlayer<? extends T>, 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<P extends PlotPlayer<? extends T>, 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<P extends PlotPlayer<? extends T>, T> {
return name;
}
/**
* Attempts to resolve the username by an uuid
* <p>
* <b>Note:</b> 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
*

View File

@ -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);