@@ -0,0 +1,63 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -13,11 +13,15 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.SystemUtils;
|
||||
import net.minecraft.server.dedicated.DedicatedServer;
|
||||
import net.minecraft.world.level.block.entity.TileEntitySkull;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.serialization.SerializableAs;
|
||||
@@ -88,7 +92,7 @@ public final class CraftPlayerProfile implements PlayerProfile {
|
||||
// Assert: (property == null) || property.getName().equals(propertyName)
|
||||
removeProperty(propertyName);
|
||||
if (property != null) {
|
||||
properties.put(property.getName(), property);
|
||||
properties.put(property.name(), property);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +139,12 @@ public final class CraftPlayerProfile implements PlayerProfile {
|
||||
|
||||
// Look up properties such as the textures:
|
||||
if (profile.getId() != null) {
|
||||
GameProfile newProfile = server.getSessionService().fillProfileProperties(profile, true);
|
||||
GameProfile newProfile;
|
||||
try {
|
||||
newProfile = TileEntitySkull.fillProfileTextures(profile).get().orElse(null); // TODO: replace with CompletableFuture
|
||||
} catch (InterruptedException | ExecutionException ex) {
|
||||
throw new RuntimeException("Exception filling profile textures", ex);
|
||||
}
|
||||
if (newProfile != null) {
|
||||
profile = newProfile;
|
||||
}
|
||||
@@ -149,7 +158,7 @@ public final class CraftPlayerProfile implements PlayerProfile {
|
||||
@Nonnull
|
||||
public GameProfile buildGameProfile() {
|
||||
rebuildDirtyProperties();
|
||||
GameProfile profile = new GameProfile(uniqueId, name);
|
||||
GameProfile profile = new CraftGameProfile(uniqueId, name);
|
||||
profile.getProperties().putAll(properties);
|
||||
return profile;
|
||||
}
|
||||
@@ -265,7 +274,7 @@ public final class CraftPlayerProfile implements PlayerProfile {
|
||||
for (Object propertyData : (List<?>) map.get("properties")) {
|
||||
Preconditions.checkArgument(propertyData instanceof Map, "Propertu data (%s) is not a valid Map", propertyData);
|
||||
Property property = CraftProfileProperty.deserialize((Map<?, ?>) propertyData);
|
||||
profile.properties.put(property.getName(), property);
|
||||
profile.properties.put(property.name(), property);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ final class CraftPlayerTextures implements PlayerTextures {
|
||||
Property property = getProperty();
|
||||
if (property == null) return;
|
||||
|
||||
data = CraftProfileProperty.decodePropertyValue(property.getValue());
|
||||
data = CraftProfileProperty.decodePropertyValue(property.value());
|
||||
if (data != null) {
|
||||
JsonObject texturesMap = JsonHelper.getObjectOrNull(data, "textures");
|
||||
loadSkin(texturesMap);
|
||||
|
||||
@@ -90,37 +90,37 @@ final class CraftProfileProperty {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("{");
|
||||
builder.append("name=");
|
||||
builder.append(property.getName());
|
||||
builder.append(property.name());
|
||||
builder.append(", value=");
|
||||
builder.append(property.getValue());
|
||||
builder.append(property.value());
|
||||
builder.append(", signature=");
|
||||
builder.append(property.getSignature());
|
||||
builder.append(property.signature());
|
||||
builder.append("}");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static int hashCode(@Nonnull Property property) {
|
||||
int result = 1;
|
||||
result = 31 * result + Objects.hashCode(property.getName());
|
||||
result = 31 * result + Objects.hashCode(property.getValue());
|
||||
result = 31 * result + Objects.hashCode(property.getSignature());
|
||||
result = 31 * result + Objects.hashCode(property.name());
|
||||
result = 31 * result + Objects.hashCode(property.value());
|
||||
result = 31 * result + Objects.hashCode(property.signature());
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean equals(@Nullable Property property, @Nullable Property other) {
|
||||
if (property == null || other == null) return (property == other);
|
||||
if (!Objects.equals(property.getValue(), other.getValue())) return false;
|
||||
if (!Objects.equals(property.getName(), other.getName())) return false;
|
||||
if (!Objects.equals(property.getSignature(), other.getSignature())) return false;
|
||||
if (!Objects.equals(property.value(), other.value())) return false;
|
||||
if (!Objects.equals(property.name(), other.name())) return false;
|
||||
if (!Objects.equals(property.signature(), other.signature())) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static Map<String, Object> serialize(@Nonnull Property property) {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("name", property.getName());
|
||||
map.put("value", property.getValue());
|
||||
map.put("name", property.name());
|
||||
map.put("value", property.value());
|
||||
if (property.hasSignature()) {
|
||||
map.put("signature", property.getSignature());
|
||||
map.put("signature", property.signature());
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user