Basic PlayerProfile API

Establishes base extension of profile systems for future edits too

== AT ==
public org.bukkit.craftbukkit.profile.CraftProfileProperty
public org.bukkit.craftbukkit.profile.CraftPlayerTextures
public org.bukkit.craftbukkit.profile.CraftPlayerTextures copyFrom(Lorg/bukkit/profile/PlayerTextures;)V
public org.bukkit.craftbukkit.profile.CraftPlayerTextures rebuildPropertyIfDirty()V
public org.bukkit.craftbukkit.profile.CraftPlayerProfile toString(Lcom/mojang/authlib/properties/PropertyMap;)Ljava/lang/String;
public org.bukkit.craftbukkit.profile.CraftPlayerProfile getProperty(Ljava/lang/String;)Lcom/mojang/authlib/properties/Property;
public org.bukkit.craftbukkit.profile.CraftPlayerProfile setProperty(Ljava/lang/String;Lcom/mojang/authlib/properties/Property;)V
This commit is contained in:
Aikar
2018-01-15 22:11:48 -05:00
parent 40654111d1
commit bb90110894
10 changed files with 621 additions and 15 deletions

View File

@@ -265,6 +265,9 @@ import org.yaml.snakeyaml.error.MarkedYAMLException;
import net.md_5.bungee.api.chat.BaseComponent; // Spigot
import javax.annotation.Nullable; // Paper
import javax.annotation.Nonnull; // Paper
public final class CraftServer implements Server {
private final String serverName = io.papermc.paper.ServerBuildInfo.buildInfo().brandName(); // Paper
private final String serverVersion;
@@ -310,6 +313,7 @@ public final class CraftServer implements Server {
static {
ConfigurationSerialization.registerClass(CraftOfflinePlayer.class);
ConfigurationSerialization.registerClass(CraftPlayerProfile.class);
ConfigurationSerialization.registerClass(com.destroystokyo.paper.profile.CraftPlayerProfile.class); // Paper
CraftItemFactory.instance();
CraftEntityFactory.instance();
}
@@ -2868,5 +2872,39 @@ public final class CraftServer implements Server {
public boolean suggestPlayerNamesWhenNullTabCompletions() {
return io.papermc.paper.configuration.GlobalConfiguration.get().commands.suggestPlayerNamesWhenNullTabCompletions;
}
@Override
public com.destroystokyo.paper.profile.PlayerProfile createProfile(@Nonnull UUID uuid) {
return createProfile(uuid, null);
}
@Override
public com.destroystokyo.paper.profile.PlayerProfile createProfile(@Nonnull String name) {
return createProfile(null, name);
}
@Override
public com.destroystokyo.paper.profile.PlayerProfile createProfile(@Nullable UUID uuid, @Nullable String name) {
Player player = uuid != null ? Bukkit.getPlayer(uuid) : (name != null ? Bukkit.getPlayerExact(name) : null);
if (player != null) return new com.destroystokyo.paper.profile.CraftPlayerProfile((CraftPlayer) player);
return new com.destroystokyo.paper.profile.CraftPlayerProfile(uuid, name);
}
@Override
public com.destroystokyo.paper.profile.PlayerProfile createProfileExact(@Nullable UUID uuid, @Nullable String name) {
Player player = uuid != null ? Bukkit.getPlayer(uuid) : (name != null ? Bukkit.getPlayerExact(name) : null);
if (player == null) {
return new com.destroystokyo.paper.profile.CraftPlayerProfile(uuid, name);
}
if (java.util.Objects.equals(uuid, player.getUniqueId()) && java.util.Objects.equals(name, player.getName())) {
return new com.destroystokyo.paper.profile.CraftPlayerProfile((CraftPlayer) player);
}
final com.destroystokyo.paper.profile.CraftPlayerProfile profile = new com.destroystokyo.paper.profile.CraftPlayerProfile(uuid, name);
profile.getGameProfile().getProperties().putAll(((CraftPlayer) player).getHandle().getGameProfile().getProperties());
return profile;
}
// Paper end
}

View File

@@ -31,7 +31,7 @@ import org.bukkit.profile.PlayerTextures;
import org.jetbrains.annotations.ApiStatus;
@SerializableAs("PlayerProfile")
public final class CraftPlayerProfile implements PlayerProfile {
public final class CraftPlayerProfile implements PlayerProfile, com.destroystokyo.paper.profile.SharedPlayerProfile { // Paper
@Nonnull
public static GameProfile validateSkullProfile(@Nonnull GameProfile gameProfile) {
@@ -132,8 +132,10 @@ public final class CraftPlayerProfile implements PlayerProfile {
}
}
void removeProperty(String propertyName) {
this.properties.removeAll(propertyName);
// Paper start - change return value for shared interface
public boolean removeProperty(String propertyName) {
return !this.properties.removeAll(propertyName).isEmpty();
// Paper end
}
void rebuildDirtyProperties() {
@@ -283,6 +285,7 @@ public final class CraftPlayerProfile implements PlayerProfile {
@Override
public Map<String, Object> serialize() {
// Paper - diff on change
Map<String, Object> map = new LinkedHashMap<>();
if (this.uniqueId != null) {
map.put("uniqueId", this.uniqueId.toString());
@@ -296,10 +299,12 @@ public final class CraftPlayerProfile implements PlayerProfile {
this.properties.forEach((propertyName, property) -> propertiesData.add(CraftProfileProperty.serialize(property)));
map.put("properties", propertiesData);
}
// Paper - diff on change
return map;
}
public static CraftPlayerProfile deserialize(Map<String, Object> map) {
// Paper - diff on change
UUID uniqueId = ConfigSerializationUtil.getUuid(map, "uniqueId", true);
String name = ConfigSerializationUtil.getString(map, "name", true);
@@ -313,7 +318,7 @@ public final class CraftPlayerProfile implements PlayerProfile {
profile.properties.put(property.name(), property);
}
}
// Paper - diff on change
return profile;
}
}

View File

@@ -48,7 +48,7 @@ public final class CraftPlayerTextures implements PlayerTextures {
}
}
private final CraftPlayerProfile profile;
private final com.destroystokyo.paper.profile.SharedPlayerProfile profile; // Paper
// The textures data is loaded lazily:
private boolean loaded = false;
@@ -67,7 +67,7 @@ public final class CraftPlayerTextures implements PlayerTextures {
// GameProfiles (even if these modifications are later reverted).
private boolean dirty = false;
CraftPlayerTextures(@Nonnull CraftPlayerProfile profile) {
public CraftPlayerTextures(@Nonnull com.destroystokyo.paper.profile.SharedPlayerProfile profile) { // Paper
this.profile = profile;
}