don't persist temporary nicknames

This commit is contained in:
Draycia committed 2021-09-01 13:51:36 -07:00
1 parent 3b1987b5a2
commit f866157d97
5 files changed
+61 -3

No files matched your search

@@ -43,7 +43,10 @@ public class CarbonPlayerSerializerGson implements JsonSerializer<CarbonPlayerCo
) {
final JsonObject object = new JsonObject();
object.add("displayName", context.serialize(player.displayName()));
if (player.hasCustomDisplayName()) {
object.add("displayName", context.serialize(player.displayName()));
}
object.add("selectedChannel", context.serialize(player.selectedChannel()));
object.add("username", context.serialize(player.username()));
object.add("uuid", context.serialize(player.uuid()));
@@ -20,6 +20,7 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
protected boolean deafened = false;
protected @Nullable Component displayName;
protected transient @Nullable Component temporaryDisplayName; // Don't persist temp names
protected boolean muted = false;
protected @Nullable ChatChannel selectedChannel;
protected boolean spying = false;
@@ -58,6 +59,10 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
@Override
public @Nullable Component displayName() {
if (this.temporaryDisplayName != null) {
return this.temporaryDisplayName;
}
return this.displayName;
}
@@ -66,6 +71,12 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
this.displayName = displayName;
}
@Override
public void temporaryDisplayName(final @Nullable Component temporaryDisplayName) {
// TODO: support durations (expires after X time)
this.temporaryDisplayName = temporaryDisplayName;
}
@Override
public boolean hasPermission(final String permission) {
return false;
@@ -136,6 +147,11 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
return this.username;
}
@Override
public boolean hasCustomDisplayName() {
return this.displayName != null;
}
@Override
public UUID uuid() {
return this.uuid;