mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 05:06:44 +01:00
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:
parent
6073b96317
commit
6f4d2f6d5a
@ -106,7 +106,7 @@ public class Add extends Command {
|
|||||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_TRUST))) {
|
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_TRUST))) {
|
||||||
player.sendMessage(
|
player.sendMessage(
|
||||||
TranslatableCaption.of("errors.invalid_player"),
|
TranslatableCaption.of("errors.invalid_player"),
|
||||||
Template.of("value", PlayerManager.getName(uuid))
|
Template.of("value", PlayerManager.resolveName(uuid).getComponent(player))
|
||||||
);
|
);
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
continue;
|
continue;
|
||||||
@ -114,7 +114,7 @@ public class Add extends Command {
|
|||||||
if (plot.isOwner(uuid)) {
|
if (plot.isOwner(uuid)) {
|
||||||
player.sendMessage(
|
player.sendMessage(
|
||||||
TranslatableCaption.of("member.already_added"),
|
TranslatableCaption.of("member.already_added"),
|
||||||
Template.of("player", PlayerManager.getName(uuid))
|
Template.of("player", PlayerManager.resolveName(uuid).getComponent(player))
|
||||||
);
|
);
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
continue;
|
continue;
|
||||||
@ -122,7 +122,7 @@ public class Add extends Command {
|
|||||||
if (plot.getMembers().contains(uuid)) {
|
if (plot.getMembers().contains(uuid)) {
|
||||||
player.sendMessage(
|
player.sendMessage(
|
||||||
TranslatableCaption.of("member.already_added"),
|
TranslatableCaption.of("member.already_added"),
|
||||||
Template.of("player", PlayerManager.getName(uuid))
|
Template.of("player", PlayerManager.resolveName(uuid).getComponent(player))
|
||||||
);
|
);
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
continue;
|
continue;
|
||||||
|
@ -125,7 +125,7 @@ public class Deny extends SubCommand {
|
|||||||
} else if (plot.getDenied().contains(uuid)) {
|
} else if (plot.getDenied().contains(uuid)) {
|
||||||
player.sendMessage(
|
player.sendMessage(
|
||||||
TranslatableCaption.of("member.already_added"),
|
TranslatableCaption.of("member.already_added"),
|
||||||
Template.of("player", PlayerManager.getName(uuid))
|
Template.of("player", PlayerManager.resolveName(uuid).getComponent(player))
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
|
@ -142,7 +142,7 @@ public class Owner extends SetCommand {
|
|||||||
if (plot.isOwner(uuid)) {
|
if (plot.isOwner(uuid)) {
|
||||||
player.sendMessage(
|
player.sendMessage(
|
||||||
TranslatableCaption.of("member.already_owner"),
|
TranslatableCaption.of("member.already_owner"),
|
||||||
Template.of("player", PlayerManager.getName(uuid, false))
|
Template.of("player", PlayerManager.resolveName(uuid, false).getComponent(player))
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -151,7 +151,7 @@ public class Owner extends SetCommand {
|
|||||||
if (other == null) {
|
if (other == null) {
|
||||||
player.sendMessage(
|
player.sendMessage(
|
||||||
TranslatableCaption.of("errors.invalid_player_offline"),
|
TranslatableCaption.of("errors.invalid_player_offline"),
|
||||||
Template.of("player", PlayerManager.getName(uuid))
|
Template.of("player", PlayerManager.resolveName(uuid).getComponent(player))
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,7 @@ public class Trust extends Command {
|
|||||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_TRUST))) {
|
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_TRUST))) {
|
||||||
player.sendMessage(
|
player.sendMessage(
|
||||||
TranslatableCaption.of("errors.invalid_player"),
|
TranslatableCaption.of("errors.invalid_player"),
|
||||||
Template.of("value", PlayerManager.getName(uuid))
|
Template.of("value", PlayerManager.resolveName(uuid).getComponent(player))
|
||||||
);
|
);
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
continue;
|
continue;
|
||||||
@ -120,7 +120,7 @@ public class Trust extends Command {
|
|||||||
if (currentPlot.isOwner(uuid)) {
|
if (currentPlot.isOwner(uuid)) {
|
||||||
player.sendMessage(
|
player.sendMessage(
|
||||||
TranslatableCaption.of("member.already_added"),
|
TranslatableCaption.of("member.already_added"),
|
||||||
Template.of("value", PlayerManager.getName(uuid))
|
Template.of("value", PlayerManager.resolveName(uuid).getComponent(player))
|
||||||
);
|
);
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
continue;
|
continue;
|
||||||
@ -128,7 +128,7 @@ public class Trust extends Command {
|
|||||||
if (currentPlot.getTrusted().contains(uuid)) {
|
if (currentPlot.getTrusted().contains(uuid)) {
|
||||||
player.sendMessage(
|
player.sendMessage(
|
||||||
TranslatableCaption.of("member.already_added"),
|
TranslatableCaption.of("member.already_added"),
|
||||||
Template.of("value", PlayerManager.getName(uuid))
|
Template.of("value", PlayerManager.resolveName(uuid).getComponent(player))
|
||||||
);
|
);
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
continue;
|
continue;
|
||||||
|
@ -70,7 +70,7 @@ public final class Templates {
|
|||||||
* @return Generated template
|
* @return Generated template
|
||||||
*/
|
*/
|
||||||
public static @NonNull Template of(final @NonNull String key, final @NonNull UUID uuid) {
|
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);
|
return Template.of(key, username);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -321,7 +321,7 @@ public class PlotListener {
|
|||||||
}
|
}
|
||||||
if ((lastPlot != null) && plot.getId().equals(lastPlot.getId()) && plot.hasOwner()) {
|
if ((lastPlot != null) && plot.getId().equals(lastPlot.getId()) && plot.hasOwner()) {
|
||||||
final UUID plotOwner = plot.getOwnerAbs();
|
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" +
|
Caption header = fromFlag ? StaticCaption.of(title) : TranslatableCaption.of("titles" +
|
||||||
".title_entered_plot");
|
".title_entered_plot");
|
||||||
Caption subHeader = fromFlag ? StaticCaption.of(subtitle) : TranslatableCaption.of("titles" +
|
Caption subHeader = fromFlag ? StaticCaption.of(subtitle) : TranslatableCaption.of("titles" +
|
||||||
|
@ -2838,7 +2838,7 @@ public class Plot {
|
|||||||
if (time != 0) {
|
if (time != 0) {
|
||||||
seen = TimeUtil.secToTime(time);
|
seen = TimeUtil.secToTime(time);
|
||||||
} else {
|
} else {
|
||||||
seen = TranslatableCaption.of("info.known").getComponent(player);
|
seen = TranslatableCaption.of("info.unknown").getComponent(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -30,6 +30,7 @@ import com.plotsquared.core.PlotSquared;
|
|||||||
import com.plotsquared.core.configuration.ConfigurationUtil;
|
import com.plotsquared.core.configuration.ConfigurationUtil;
|
||||||
import com.plotsquared.core.configuration.Settings;
|
import com.plotsquared.core.configuration.Settings;
|
||||||
import com.plotsquared.core.configuration.caption.Caption;
|
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.configuration.caption.TranslatableCaption;
|
||||||
import com.plotsquared.core.database.DBFunc;
|
import com.plotsquared.core.database.DBFunc;
|
||||||
import com.plotsquared.core.events.PlotComponentSetEvent;
|
import com.plotsquared.core.events.PlotComponentSetEvent;
|
||||||
@ -358,7 +359,8 @@ public final class PlotModificationManager {
|
|||||||
if (createSign) {
|
if (createSign) {
|
||||||
queue.setCompleteTask(() -> TaskManager.runTaskAsync(() -> {
|
queue.setCompleteTask(() -> TaskManager.runTaskAsync(() -> {
|
||||||
for (Plot current : plots) {
|
for (Plot current : plots) {
|
||||||
current.getPlotModificationManager().setSign(PlayerManager.getName(current.getOwnerAbs()));
|
current.getPlotModificationManager().setSign(PlayerManager.resolveName(current.getOwnerAbs()).getComponent(
|
||||||
|
LocaleHolder.console()));
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,9 @@ package com.plotsquared.core.util;
|
|||||||
|
|
||||||
import com.plotsquared.core.PlotSquared;
|
import com.plotsquared.core.PlotSquared;
|
||||||
import com.plotsquared.core.configuration.Settings;
|
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.LocaleHolder;
|
||||||
|
import com.plotsquared.core.configuration.caption.StaticCaption;
|
||||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||||
import com.plotsquared.core.database.DBFunc;
|
import com.plotsquared.core.database.DBFunc;
|
||||||
import com.plotsquared.core.player.ConsolePlayer;
|
import com.plotsquared.core.player.ConsolePlayer;
|
||||||
@ -162,7 +164,9 @@ public abstract class PlayerManager<P extends PlotPlayer<? extends T>, T> {
|
|||||||
*
|
*
|
||||||
* @param owner Owner UUID
|
* @param owner Owner UUID
|
||||||
* @return The player's name, None, Everyone or Unknown
|
* @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) {
|
public static @NonNull String getName(final @Nullable UUID owner) {
|
||||||
return getName(owner, true);
|
return getName(owner, true);
|
||||||
}
|
}
|
||||||
@ -173,7 +177,9 @@ public abstract class PlayerManager<P extends PlotPlayer<? extends T>, T> {
|
|||||||
* @param owner Owner UUID
|
* @param owner Owner UUID
|
||||||
* @param blocking Whether or not the operation can be blocking
|
* @param blocking Whether or not the operation can be blocking
|
||||||
* @return The player's name, None, Everyone or Unknown
|
* @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) {
|
public static @NonNull String getName(final @Nullable UUID owner, final boolean blocking) {
|
||||||
if (owner == null) {
|
if (owner == null) {
|
||||||
TranslatableCaption.of("info.none");
|
TranslatableCaption.of("info.none");
|
||||||
@ -203,6 +209,57 @@ public abstract class PlayerManager<P extends PlotPlayer<? extends T>, T> {
|
|||||||
return name;
|
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
|
* Remove a player from the player map
|
||||||
*
|
*
|
||||||
|
@ -116,7 +116,7 @@ public final class PlaceholderRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return PlayerManager.getName(plotOwner, false);
|
return PlayerManager.resolveName(plotOwner, false).getComponent(player);
|
||||||
} catch (final Exception ignored) {
|
} catch (final Exception ignored) {
|
||||||
}
|
}
|
||||||
return legacyComponent(TranslatableCaption.of("info.unknown"), player);
|
return legacyComponent(TranslatableCaption.of("info.unknown"), player);
|
||||||
|
Loading…
Reference in New Issue
Block a user