Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions changeset.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Fixes:

- Fix OPs being unable to set styled nicknames for other players when
`use_permissions_api` is `false` (#300). Nickname style permissions are now
checked against the player running the command.
- New config option, `nickname_style_perms_check_target` (default `false`),
restores the old behavior of checking the target player.
1 change: 1 addition & 0 deletions docs/Config-Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ The config file can be found at `config/EssentialCommands.properties`
| nickname_above_head | false | boolean |
| nickname_max_length | 32 | integer |
| nickname_prefix | {"text":"~","color":"red"} | MinecraftText |
| nickname_style_perms_check_target | false | boolean |
| nicknames_as_command_arg | Never | NicknameCommandArgMode |
| nicknames_in_player_list | true | boolean |
| nicknames_must_be_unique | false | boolean |
Expand Down
1 change: 1 addition & 0 deletions docs/Feature-Guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ The `<nickname>` is [MinecraftText](./Minecraft-Text.md), meaning it can be one
- `EssentialCommandsOnly` - Nicknames resolve and suggest only in Essential Commands
- `Everywhere` - Nicknames resolve and suggest in all commands (e.g. `/tp`, `/give`)
- `nicknames_must_be_unique` - Block nicknames that duplicate another player's nickname or match an existing username (case-insensitive) - Default: `false`
- `nickname_style_perms_check_target` - If `true`, nickname style permissions (color, fancy, hover, click) are checked against the player receiving the nickname instead of the player running the command (the behavior before #300 was fixed) - Default: `false`

## Utility Commands

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,27 @@ public static int runStringToText(CommandContext<CommandSourceStack> context) th

public static int exec(CommandContext<CommandSourceStack> context, Component rawNicknameText) throws CommandSyntaxException {
ServerPlayer targetPlayer = CommandUtil.getCommandTargetPlayer(context);
var sender = context.getSource();

var nicknameWithContext = ECPerms.check(context.getSource(), ECPerms.Registry.nickname_selector_and_ctx, 2)
var nicknameWithContext = ECPerms.check(sender, ECPerms.Registry.nickname_selector_and_ctx, 2)
? ComponentUtils.resolve(
ResolutionContext.builder()
.withSource(context.getSource())
.withSource(sender)
.withEntityOverride(targetPlayer)
.build(),
rawNicknameText,
0)
: rawNicknameText;

var nicknameText = ECPerms.check(context.getSource(), ECPerms.Registry.nickname_placeholders, 2)
var nicknameText = ECPerms.check(sender, ECPerms.Registry.nickname_placeholders, 2)
? TagParser.DEFAULT_SAFE.parseComponent(TextNode.convert(nicknameWithContext), ParserContext.of())
: nicknameWithContext;
int successCode = PlayerData.access(targetPlayer).setNickname(nicknameText);

var senderPlayer = context.getSource().getPlayer();
var senderFeedbackReceiver = FeedbackReceiver.ofSource(context.getSource());
int successCode = PlayerData.access(targetPlayer).setNickname(nicknameText, sender);

var ecText = ECText.access(senderPlayer);
var senderFeedbackReceiver = FeedbackReceiver.ofSource(sender);

var ecText = ECText.access(sender.getPlayer());

//inform command sender that the nickname has been set
if (successCode >= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public final class EssentialCommandsConfig extends Config<EssentialCommandsConfi
@ConfigOption public final Option<NicknameCommandArgMode> NICKNAMES_AS_COMMAND_ARG = new Option<>("nicknames_as_command_arg", NicknameCommandArgMode.Never, NicknameCommandArgMode::valueOf);
@ConfigOption public final Option<Boolean> NICKNAMES_MUST_BE_UNIQUE = new Option<>("nicknames_must_be_unique", false, Boolean::parseBoolean);
@ConfigOption public final Option<Boolean> NICKNAME_ABOVE_HEAD = new Option<>("nickname_above_head", false, Boolean::parseBoolean);
@ConfigOption public final Option<Boolean> NICKNAME_STYLE_PERMS_CHECK_TARGET = new Option<>("nickname_style_perms_check_target", false, Boolean::parseBoolean);
@ConfigOption public final Option<RtpCenter> RTP_CENTER = new Option<>("rtp_center", RtpCenter.spawn(), RtpCenter::parse, RtpCenter::serialize);
@ConfigOption public final Option<Integer> RTP_RADIUS = new Option<>("rtp_radius", 1000, ConfigUtil::parseInt);
@ConfigOption public final Option<Integer> RTP_MIN_RADIUS = new Option<>("rtp_min_radius", RTP_RADIUS.getValue(), (String s) -> parseIntOrDefault(s, RTP_RADIUS.getValue()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public final class EssentialCommandsConfigSnapshot {
public final int NICKNAME_MAX_LENGTH;
public final NicknameCommandArgMode NICKNAMES_AS_COMMAND_ARG;
public final boolean NICKNAMES_MUST_BE_UNIQUE;
public final boolean NICKNAME_STYLE_PERMS_CHECK_TARGET;
public final boolean NICKNAME_ABOVE_HEAD;
public final RtpCenter RTP_CENTER;
public final int RTP_RADIUS;
Expand Down Expand Up @@ -151,6 +152,7 @@ private EssentialCommandsConfigSnapshot(EssentialCommandsConfig config) {
this.NICKNAME_MAX_LENGTH = config.NICKNAME_MAX_LENGTH.getValue();
this.NICKNAMES_AS_COMMAND_ARG = config.NICKNAMES_AS_COMMAND_ARG.getValue();
this.NICKNAMES_MUST_BE_UNIQUE = config.NICKNAMES_MUST_BE_UNIQUE.getValue();
this.NICKNAME_STYLE_PERMS_CHECK_TARGET = config.NICKNAME_STYLE_PERMS_CHECK_TARGET.getValue();
this.NICKNAME_ABOVE_HEAD = config.NICKNAME_ABOVE_HEAD.getValue();
this.RTP_CENTER = config.RTP_CENTER.getValue();
this.RTP_RADIUS = config.RTP_RADIUS.getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,10 @@ public MutableComponent copyFullNickname() {
}

public int setNickname(Component nickname) {
return setNickname(nickname, this.player.createCommandSourceStack());
}

public int setNickname(Component nickname, CommandSourceStack actorPermsSrc) {
String oldNormalizedNickname = this.normalizedNickname;
int resultCode = 0;
// Reset nickname
Expand All @@ -530,23 +534,31 @@ public int setNickname(Component nickname) {
if (nickname.getString().length() > CONFIG.NICKNAME_MAX_LENGTH) {
return -2;
}

// By default, the person running the command needs the style permissions (color, fancy, etc.).
// nickname_style_perms_check_target=true restores the old behavior of checking the target player.
var permissionSource = CONFIG.NICKNAME_STYLE_PERMS_CHECK_TARGET
? this.player.createCommandSourceStack()
: actorPermsSrc;

// Ensure player has permissions required to set the specified nickname
boolean hasRequiredPerms = NicknameTextUtil.checkPerms(nickname, this.player.createCommandSourceStack());
boolean hasRequiredPerms = NicknameTextUtil.checkPerms(nickname, permissionSource);
if (!hasRequiredPerms) {
EssentialCommands.LOGGER.info(
"{} attempted to set nickname to '{}', with insufficient permissions to do so.",
"{} attempted to set {}'s nickname to '{}', with insufficient permissions to do so.",
permissionSource.getTextName(),
this.player.getGameProfile().name(),
nickname
);
return -1;
} else {
EssentialCommands.LOGGER.info(
"Set {}'s nickname to '{}'.",
this.player.getGameProfile().name(),
nickname
);
}

EssentialCommands.LOGGER.info(
"Set {}'s nickname to '{}'.",
this.player.getGameProfile().name(),
nickname
);

String candidateNormalized = normalizeNickname(nickname.getString());

if (CONFIG.NICKNAMES_MUST_BE_UNIQUE) {
Expand Down
Loading