SPIGOT-7486: Alternate approach to null profile names

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot
2023-09-22 07:36:30 +10:00
parent fb7dc796d5
commit 3ff2a7bc12
7 changed files with 28 additions and 91 deletions

View File

@@ -1,63 +0,0 @@
package org.bukkit.craftbukkit.profile;
import com.mojang.authlib.GameProfile;
import java.util.UUID;
import net.minecraft.SystemUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
public final class CraftGameProfile extends GameProfile {
private final boolean nullId;
private final boolean nullName;
public CraftGameProfile(UUID id, String name) {
super((id == null) ? SystemUtils.NIL_UUID : id, (name == null) ? "" : name);
this.nullId = (id == null);
this.nullName = (name == null);
}
@Override
public UUID getId() {
return (nullId) ? null : super.getId();
}
@Override
public String getName() {
return (nullName) ? null : super.getName();
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
GameProfile that = (GameProfile) o;
if ((this.getId() != null) ? !this.getId().equals(that.getId()) : (that.getId() != null)) {
return false;
}
if ((this.getName() != null) ? !this.getName().equals(that.getName()) : (that.getName() != null)) {
return false;
}
return true;
}
@Override
public int hashCode() {
int result = (this.getId() != null) ? this.getId().hashCode() : 0;
result = 31 * result + ((this.getName() != null) ? this.getName().hashCode() : 0);
return result;
}
@Override
public String toString() {
return new ToStringBuilder(this)
.append("id", this.getId())
.append("name", this.getName())
.append("properties", this.getProperties())
.toString();
}
}

View File

@@ -56,8 +56,8 @@ public final class CraftPlayerProfile implements PlayerProfile {
public CraftPlayerProfile(UUID uniqueId, String name) {
Preconditions.checkArgument((uniqueId != null) || !StringUtils.isBlank(name), "uniqueId is null or name is blank");
this.uniqueId = uniqueId;
this.name = name;
this.uniqueId = (uniqueId == null) ? SystemUtils.NIL_UUID : uniqueId;
this.name = (name == null) ? "" : name;
}
// The Map of properties of the given GameProfile is not immutable. This captures a snapshot of the properties of
@@ -75,12 +75,12 @@ public final class CraftPlayerProfile implements PlayerProfile {
@Override
public UUID getUniqueId() {
return uniqueId;
return (uniqueId.equals(SystemUtils.NIL_UUID)) ? null : uniqueId;
}
@Override
public String getName() {
return name;
return (name.isEmpty()) ? null : name;
}
@Nullable
@@ -120,7 +120,7 @@ public final class CraftPlayerProfile implements PlayerProfile {
@Override
public boolean isComplete() {
return (uniqueId != null) && (name != null) && !textures.isEmpty();
return (getUniqueId() != null) && (getName() != null) && !textures.isEmpty();
}
@Override
@@ -133,12 +133,12 @@ public final class CraftPlayerProfile implements PlayerProfile {
GameProfile profile = this.buildGameProfile();
// If missing, look up the uuid by name:
if (profile.getId() == null) {
if (profile.getId().equals(SystemUtils.NIL_UUID)) {
profile = server.getProfileCache().get(profile.getName()).orElse(profile);
}
// Look up properties such as the textures:
if (profile.getId() != null) {
if (!profile.getId().equals(SystemUtils.NIL_UUID)) {
GameProfile newProfile;
try {
newProfile = TileEntitySkull.fillProfileTextures(profile).get().orElse(null); // TODO: replace with CompletableFuture
@@ -158,7 +158,7 @@ public final class CraftPlayerProfile implements PlayerProfile {
@Nonnull
public GameProfile buildGameProfile() {
rebuildDirtyProperties();
GameProfile profile = new CraftGameProfile(uniqueId, name);
GameProfile profile = new GameProfile(uniqueId, name);
profile.getProperties().putAll(properties);
return profile;
}
@@ -246,11 +246,11 @@ public final class CraftPlayerProfile implements PlayerProfile {
@Override
public Map<String, Object> serialize() {
Map<String, Object> map = new LinkedHashMap<>();
if (uniqueId != null) {
map.put("uniqueId", uniqueId.toString());
if (getUniqueId() != null) {
map.put("uniqueId", getUniqueId().toString());
}
if (name != null) {
map.put("name", name);
if (getName() != null) {
map.put("name", getName());
}
rebuildDirtyProperties();
if (!properties.isEmpty()) {