Skip to content

Commit

Permalink
Bugfix: cleared nicknames never update in PlayerList.
Browse files Browse the repository at this point in the history
Bump version to `0.13.1-beta`
  • Loading branch information
John-Paul-R committed Jul 12, 2021
1 parent 25a112d commit 609e588
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ org.gradle.jvmargs=-Xmx2048M
# Mod Properties
mod_name = Essential Commands
mod_id = essential_commands
mod_version = 0.13.0-beta
mod_version = 0.13.1-beta
maven_group = com.fibermc
archives_base_name = essential_commands

Expand Down
50 changes: 28 additions & 22 deletions src/main/java/com/fibermc/essentialcommands/PlayerData.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,41 +196,47 @@ public MutableText getFullNickname() {
}

public int setNickname(Text nickname) {
int resultCode = 0;
// Reset nickname
if (nickname == null) {
this.nickname = null;
reloadFullNickname();
return 1;
}
// Ensure nickname does not exceed max length
if (nickname.getString().length() > Config.NICKNAME_MAX_LENGTH) {
return -2;
}
// Ensure player has permissions required to set the specified nickname
boolean hasRequiredPerms = NicknameText.checkPerms(nickname, this.player.getCommandSource());
if (!hasRequiredPerms) {
resultCode = 1;
EssentialCommands.LOGGER.info(String.format(
"%s attempted to set nickname to '%s', with insufficient permissions to do so.",
this.player.getGameProfile().getName(),
nickname
"Cleared %s's nickname",
this.player.getGameProfile().getName()
));
return -1;
} else {
EssentialCommands.LOGGER.info(String.format(
"Set %s's nickname to '%s'.",
this.player.getGameProfile().getName(),
nickname
));
// Ensure nickname does not exceed max length
if (nickname.getString().length() > Config.NICKNAME_MAX_LENGTH) {
return -2;
}
// Ensure player has permissions required to set the specified nickname
boolean hasRequiredPerms = NicknameText.checkPerms(nickname, this.player.getCommandSource());
if (!hasRequiredPerms) {
EssentialCommands.LOGGER.info(String.format(
"%s attempted to set nickname to '%s', with insufficient permissions to do so.",
this.player.getGameProfile().getName(),
nickname
));
return -1;
} else {
EssentialCommands.LOGGER.info(String.format(
"Set %s's nickname to '%s'.",
this.player.getGameProfile().getName(),
nickname
));
}

// Set nickname
this.nickname = nickname;
}

// Set nickname
this.nickname = nickname;
reloadFullNickname();
PlayerDataManager.getInstance().markNicknameDirty(this);
this.markDirty();
// Return codes based on fail/success
// ex: caused by profanity filter.
return 0;
return resultCode;
}

public void save() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ public class Option<T> {
private final ValueParser<T> parser;
private T value;

public Option(String key, T defaultValue) {
this(key, defaultValue, (strValue) -> (T)strValue);
}

public Option(String key, T defaultValue, ValueParser<T> parser) {
this.key = key;
this.defaultValue = defaultValue;
Expand Down

0 comments on commit 609e588

Please sign in to comment.