Remap CraftBukkit to Mojang+Yarn Mappings

By: Initial Source <noreply+automated@papermc.io>
This commit is contained in:
CraftBukkit/Spigot
2024-12-11 22:26:55 +01:00
parent a265d64138
commit 30e4583dbe
1780 changed files with 44628 additions and 41274 deletions

View File

@@ -18,7 +18,7 @@ import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import net.minecraft.SystemUtils;
import net.minecraft.Util;
import net.minecraft.server.dedicated.DedicatedServer;
import net.minecraft.world.item.component.ResolvableProfile;
import org.apache.commons.lang.StringUtils;
@@ -97,38 +97,38 @@ public final class CraftPlayerProfile implements PlayerProfile {
@Override
public UUID getUniqueId() {
return (Objects.equals(uniqueId, SystemUtils.NIL_UUID)) ? null : uniqueId;
return (Objects.equals(this.uniqueId, Util.NIL_UUID)) ? null : this.uniqueId;
}
@Override
public String getName() {
return (StringUtils.isBlank(name)) ? null : name;
return (StringUtils.isBlank(this.name)) ? null : this.name;
}
@Nullable
public @Nullable
Property getProperty(String propertyName) {
return Iterables.getFirst(properties.get(propertyName), null);
return Iterables.getFirst(this.properties.get(propertyName), null);
}
void setProperty(String propertyName, @Nullable Property property) {
public void setProperty(String propertyName, @Nullable Property property) {
// Assert: (property == null) || property.getName().equals(propertyName)
removeProperty(propertyName);
this.removeProperty(propertyName);
if (property != null) {
properties.put(property.name(), property);
this.properties.put(property.name(), property);
}
}
void removeProperty(String propertyName) {
properties.removeAll(propertyName);
this.properties.removeAll(propertyName);
}
void rebuildDirtyProperties() {
textures.rebuildPropertyIfDirty();
this.textures.rebuildPropertyIfDirty();
}
@Override
public CraftPlayerTextures getTextures() {
return textures;
return this.textures;
}
@Override
@@ -142,12 +142,12 @@ public final class CraftPlayerProfile implements PlayerProfile {
@Override
public boolean isComplete() {
return (getUniqueId() != null) && (getName() != null) && !textures.isEmpty();
return (this.getUniqueId() != null) && (this.getName() != null) && !this.textures.isEmpty();
}
@Override
public CompletableFuture<PlayerProfile> update() {
return CompletableFuture.supplyAsync(this::getUpdatedProfile, SystemUtils.backgroundExecutor());
return CompletableFuture.supplyAsync(this::getUpdatedProfile, Util.backgroundExecutor());
}
private CraftPlayerProfile getUpdatedProfile() {
@@ -155,12 +155,12 @@ public final class CraftPlayerProfile implements PlayerProfile {
GameProfile profile = this.buildGameProfile();
// If missing, look up the uuid by name:
if (profile.getId().equals(SystemUtils.NIL_UUID)) {
if (profile.getId().equals(Util.NIL_UUID)) {
profile = server.getProfileCache().get(profile.getName()).orElse(profile);
}
// Look up properties such as the textures:
if (!profile.getId().equals(SystemUtils.NIL_UUID)) {
if (!profile.getId().equals(Util.NIL_UUID)) {
ProfileResult newProfile = server.getSessionService().fetchProfile(profile.getId(), true);
if (newProfile != null) {
profile = newProfile.profile();
@@ -174,7 +174,7 @@ public final class CraftPlayerProfile implements PlayerProfile {
// built ResolvableProfile don't affect the use of this profile in other contexts.
@Nonnull
public ResolvableProfile buildResolvableProfile() {
rebuildDirtyProperties();
this.rebuildDirtyProperties();
return new ResolvableProfile(Optional.ofNullable(this.name), Optional.ofNullable(this.uniqueId), this.properties);
}
@@ -182,27 +182,27 @@ public final class CraftPlayerProfile implements PlayerProfile {
// built GameProfiles don't affect the use of this profile in other contexts.
@Nonnull
public GameProfile buildGameProfile() {
rebuildDirtyProperties();
GameProfile profile = new GameProfile(uniqueId, name);
profile.getProperties().putAll(properties);
this.rebuildDirtyProperties();
GameProfile profile = new GameProfile(this.uniqueId, this.name);
profile.getProperties().putAll(this.properties);
return profile;
}
@Override
public String toString() {
rebuildDirtyProperties();
this.rebuildDirtyProperties();
StringBuilder builder = new StringBuilder();
builder.append("CraftPlayerProfile [uniqueId=");
builder.append(uniqueId);
builder.append(this.uniqueId);
builder.append(", name=");
builder.append(name);
builder.append(this.name);
builder.append(", properties=");
builder.append(toString(properties));
builder.append(CraftPlayerProfile.toString(this.properties));
builder.append("]");
return builder.toString();
}
private static String toString(@Nonnull PropertyMap propertyMap) {
public static String toString(@Nonnull PropertyMap propertyMap) {
StringBuilder builder = new StringBuilder();
builder.append("{");
propertyMap.asMap().forEach((propertyName, properties) -> {
@@ -218,12 +218,12 @@ public final class CraftPlayerProfile implements PlayerProfile {
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof CraftPlayerProfile other)) return false;
if (!Objects.equals(uniqueId, other.uniqueId)) return false;
if (!Objects.equals(name, other.name)) return false;
if (!Objects.equals(this.uniqueId, other.uniqueId)) return false;
if (!Objects.equals(this.name, other.name)) return false;
rebuildDirtyProperties();
this.rebuildDirtyProperties();
other.rebuildDirtyProperties();
if (!equals(properties, other.properties)) return false;
if (!CraftPlayerProfile.equals(this.properties, other.properties)) return false;
return true;
}
@@ -246,11 +246,11 @@ public final class CraftPlayerProfile implements PlayerProfile {
@Override
public int hashCode() {
rebuildDirtyProperties();
this.rebuildDirtyProperties();
int result = 1;
result = 31 * result + Objects.hashCode(uniqueId);
result = 31 * result + Objects.hashCode(name);
result = 31 * result + hashCode(properties);
result = 31 * result + Objects.hashCode(this.uniqueId);
result = 31 * result + Objects.hashCode(this.name);
result = 31 * result + CraftPlayerProfile.hashCode(this.properties);
return result;
}
@@ -274,9 +274,9 @@ public final class CraftPlayerProfile implements PlayerProfile {
map.put("uniqueId", this.uniqueId.toString());
}
if (this.name != null) {
map.put("name", getName());
map.put("name", this.getName());
}
rebuildDirtyProperties();
this.rebuildDirtyProperties();
if (!this.properties.isEmpty()) {
List<Object> propertiesData = new ArrayList<>();
this.properties.forEach((propertyName, property) -> propertiesData.add(CraftProfileProperty.serialize(property)));

View File

@@ -14,7 +14,7 @@ import javax.annotation.Nullable;
import org.bukkit.craftbukkit.util.JsonHelper;
import org.bukkit.profile.PlayerTextures;
final class CraftPlayerTextures implements PlayerTextures {
public final class CraftPlayerTextures implements PlayerTextures {
static final String PROPERTY_NAME = "textures";
private static final String MINECRAFT_HOST = "textures.minecraft.net";
@@ -24,8 +24,8 @@ final class CraftPlayerTextures implements PlayerTextures {
// Null represents an unset texture and is therefore valid.
if (url == null) return;
Preconditions.checkArgument(url.getHost().equals(MINECRAFT_HOST), "Expected host '%s' but got '%s'", MINECRAFT_HOST, url.getHost());
Preconditions.checkArgument(url.getPath().startsWith(MINECRAFT_PATH), "Expected path starting with '%s' but got '%s", MINECRAFT_PATH, url.getPath());
Preconditions.checkArgument(url.getHost().equals(CraftPlayerTextures.MINECRAFT_HOST), "Expected host '%s' but got '%s'", CraftPlayerTextures.MINECRAFT_HOST, url.getHost());
Preconditions.checkArgument(url.getPath().startsWith(CraftPlayerTextures.MINECRAFT_PATH), "Expected path starting with '%s' but got '%s", CraftPlayerTextures.MINECRAFT_PATH, url.getPath());
}
@Nullable
@@ -71,37 +71,37 @@ final class CraftPlayerTextures implements PlayerTextures {
this.profile = profile;
}
void copyFrom(@Nonnull PlayerTextures other) {
public void copyFrom(@Nonnull PlayerTextures other) {
if (other == this) return;
Preconditions.checkArgument(other instanceof CraftPlayerTextures, "Expecting CraftPlayerTextures, got %s", other.getClass().getName());
CraftPlayerTextures otherTextures = (CraftPlayerTextures) other;
clear();
this.clear();
Property texturesProperty = otherTextures.getProperty();
profile.setProperty(PROPERTY_NAME, texturesProperty);
this.profile.setProperty(CraftPlayerTextures.PROPERTY_NAME, texturesProperty);
if (texturesProperty != null
&& (!Objects.equals(profile.getUniqueId(), otherTextures.profile.getUniqueId())
|| !Objects.equals(profile.getName(), otherTextures.profile.getName()))) {
&& (!Objects.equals(this.profile.getUniqueId(), otherTextures.profile.getUniqueId())
|| !Objects.equals(this.profile.getName(), otherTextures.profile.getName()))) {
// We might need to rebuild the textures property for this profile:
// TODO Only rebuild if the textures property actually stores an incompatible profileId/playerName?
ensureLoaded();
markDirty();
rebuildPropertyIfDirty();
this.ensureLoaded();
this.markDirty();
this.rebuildPropertyIfDirty();
}
}
private void ensureLoaded() {
if (loaded) return;
loaded = true;
if (this.loaded) return;
this.loaded = true;
Property property = getProperty();
Property property = this.getProperty();
if (property == null) return;
data = CraftProfileProperty.decodePropertyValue(property.value());
if (data != null) {
JsonObject texturesMap = JsonHelper.getObjectOrNull(data, "textures");
loadSkin(texturesMap);
loadCape(texturesMap);
loadTimestamp();
this.data = CraftProfileProperty.decodePropertyValue(property.value());
if (this.data != null) {
JsonObject texturesMap = JsonHelper.getObjectOrNull(this.data, "textures");
this.loadSkin(texturesMap);
this.loadCape(texturesMap);
this.loadTimestamp();
}
}
@@ -111,12 +111,12 @@ final class CraftPlayerTextures implements PlayerTextures {
if (texture == null) return;
String skinUrlString = JsonHelper.getStringOrNull(texture, "url");
this.skin = parseUrl(skinUrlString);
this.skinModel = loadSkinModel(texture);
this.skin = CraftPlayerTextures.parseUrl(skinUrlString);
this.skinModel = CraftPlayerTextures.loadSkinModel(texture);
// Special case: If a skin is present, but no skin model, we use the default classic skin model.
if (skinModel == null && skin != null) {
skinModel = SkinModel.CLASSIC;
if (this.skinModel == null && this.skin != null) {
this.skinModel = SkinModel.CLASSIC;
}
}
@@ -127,7 +127,7 @@ final class CraftPlayerTextures implements PlayerTextures {
if (metadata == null) return null;
String skinModelName = JsonHelper.getStringOrNull(metadata, "model");
return parseSkinModel(skinModelName);
return CraftPlayerTextures.parseSkinModel(skinModelName);
}
private void loadCape(@Nullable JsonObject texturesMap) {
@@ -136,12 +136,12 @@ final class CraftPlayerTextures implements PlayerTextures {
if (texture == null) return;
String skinUrlString = JsonHelper.getStringOrNull(texture, "url");
this.cape = parseUrl(skinUrlString);
this.cape = CraftPlayerTextures.parseUrl(skinUrlString);
}
private void loadTimestamp() {
if (data == null) return;
JsonPrimitive timestamp = JsonHelper.getPrimitiveOrNull(data, "timestamp");
if (this.data == null) return;
JsonPrimitive timestamp = JsonHelper.getPrimitiveOrNull(this.data, "timestamp");
if (timestamp == null) return;
try {
@@ -151,100 +151,100 @@ final class CraftPlayerTextures implements PlayerTextures {
}
private void markDirty() {
dirty = true;
this.dirty = true;
// Clear any cached but no longer valid data:
data = null;
timestamp = 0L;
this.data = null;
this.timestamp = 0L;
}
@Override
public boolean isEmpty() {
ensureLoaded();
return (skin == null) && (cape == null);
this.ensureLoaded();
return (this.skin == null) && (this.cape == null);
}
@Override
public void clear() {
profile.removeProperty(PROPERTY_NAME);
loaded = false;
data = null;
timestamp = 0L;
skin = null;
skinModel = SkinModel.CLASSIC;
cape = null;
dirty = false;
this.profile.removeProperty(CraftPlayerTextures.PROPERTY_NAME);
this.loaded = false;
this.data = null;
this.timestamp = 0L;
this.skin = null;
this.skinModel = SkinModel.CLASSIC;
this.cape = null;
this.dirty = false;
}
@Override
public URL getSkin() {
ensureLoaded();
return skin;
this.ensureLoaded();
return this.skin;
}
@Override
public void setSkin(URL skinUrl) {
setSkin(skinUrl, SkinModel.CLASSIC);
this.setSkin(skinUrl, SkinModel.CLASSIC);
}
@Override
public void setSkin(URL skinUrl, SkinModel skinModel) {
validateTextureUrl(skinUrl);
CraftPlayerTextures.validateTextureUrl(skinUrl);
if (skinModel == null) skinModel = SkinModel.CLASSIC;
// This also loads the textures if necessary:
if (Objects.equals(getSkin(), skinUrl) && Objects.equals(getSkinModel(), skinModel)) return;
if (Objects.equals(this.getSkin(), skinUrl) && Objects.equals(this.getSkinModel(), skinModel)) return;
this.skin = skinUrl;
this.skinModel = (skinUrl != null) ? skinModel : SkinModel.CLASSIC;
markDirty();
this.markDirty();
}
@Override
public SkinModel getSkinModel() {
ensureLoaded();
return skinModel;
this.ensureLoaded();
return this.skinModel;
}
@Override
public URL getCape() {
ensureLoaded();
return cape;
this.ensureLoaded();
return this.cape;
}
@Override
public void setCape(URL capeUrl) {
validateTextureUrl(capeUrl);
CraftPlayerTextures.validateTextureUrl(capeUrl);
// This also loads the textures if necessary:
if (Objects.equals(getCape(), capeUrl)) return;
if (Objects.equals(this.getCape(), capeUrl)) return;
this.cape = capeUrl;
markDirty();
this.markDirty();
}
@Override
public long getTimestamp() {
ensureLoaded();
return timestamp;
this.ensureLoaded();
return this.timestamp;
}
@Override
public boolean isSigned() {
if (dirty) return false;
Property property = getProperty();
if (this.dirty) return false;
Property property = this.getProperty();
return property != null && CraftProfileProperty.hasValidSignature(property);
}
@Nullable
Property getProperty() {
rebuildPropertyIfDirty();
return profile.getProperty(PROPERTY_NAME);
this.rebuildPropertyIfDirty();
return this.profile.getProperty(CraftPlayerTextures.PROPERTY_NAME);
}
void rebuildPropertyIfDirty() {
if (!dirty) return;
public void rebuildPropertyIfDirty() {
if (!this.dirty) return;
// Assert: loaded
dirty = false;
this.dirty = false;
if (isEmpty()) {
profile.removeProperty(PROPERTY_NAME);
if (this.isEmpty()) {
this.profile.removeProperty(CraftPlayerTextures.PROPERTY_NAME);
return;
}
@@ -256,23 +256,23 @@ final class CraftPlayerTextures implements PlayerTextures {
// The order of Json object elements is important.
JsonObject propertyData = new JsonObject();
if (skin != null) {
if (this.skin != null) {
JsonObject texturesMap = JsonHelper.getOrCreateObject(propertyData, "textures");
JsonObject skinTexture = JsonHelper.getOrCreateObject(texturesMap, MinecraftProfileTexture.Type.SKIN.name());
skinTexture.addProperty("url", skin.toExternalForm());
skinTexture.addProperty("url", this.skin.toExternalForm());
// Special case: If the skin model is classic (i.e. default), omit it.
// Assert: skinModel != null
if (skinModel != SkinModel.CLASSIC) {
if (this.skinModel != SkinModel.CLASSIC) {
JsonObject metadata = JsonHelper.getOrCreateObject(skinTexture, "metadata");
metadata.addProperty("model", skinModel.name().toLowerCase(Locale.ROOT));
metadata.addProperty("model", this.skinModel.name().toLowerCase(Locale.ROOT));
}
}
if (cape != null) {
if (this.cape != null) {
JsonObject texturesMap = JsonHelper.getOrCreateObject(propertyData, "textures");
JsonObject skinTexture = JsonHelper.getOrCreateObject(texturesMap, MinecraftProfileTexture.Type.CAPE.name());
skinTexture.addProperty("url", cape.toExternalForm());
skinTexture.addProperty("url", this.cape.toExternalForm());
}
this.data = propertyData;
@@ -280,28 +280,28 @@ final class CraftPlayerTextures implements PlayerTextures {
// We use the compact formatter here since this is more likely to match the output of existing popular tools
// that also create profiles with custom textures:
String encodedTexturesData = CraftProfileProperty.encodePropertyValue(propertyData, CraftProfileProperty.JsonFormatter.COMPACT);
Property property = new Property(PROPERTY_NAME, encodedTexturesData);
profile.setProperty(PROPERTY_NAME, property);
Property property = new Property(CraftPlayerTextures.PROPERTY_NAME, encodedTexturesData);
this.profile.setProperty(CraftPlayerTextures.PROPERTY_NAME, property);
}
private JsonObject getData() {
ensureLoaded();
rebuildPropertyIfDirty();
return data;
this.ensureLoaded();
this.rebuildPropertyIfDirty();
return this.data;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("CraftPlayerTextures [data=");
builder.append(getData());
builder.append(this.getData());
builder.append("]");
return builder.toString();
}
@Override
public int hashCode() {
Property property = getProperty();
Property property = this.getProperty();
return (property == null) ? 0 : CraftProfileProperty.hashCode(property);
}
@@ -310,7 +310,7 @@ final class CraftPlayerTextures implements PlayerTextures {
if (this == obj) return true;
if (!(obj instanceof CraftPlayerTextures)) return false;
CraftPlayerTextures other = (CraftPlayerTextures) obj;
Property property = getProperty();
Property property = this.getProperty();
Property otherProperty = other.getProperty();
return CraftProfileProperty.equals(property, otherProperty);
}

View File

@@ -20,7 +20,7 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.bukkit.craftbukkit.configuration.ConfigSerializationUtil;
final class CraftProfileProperty {
public final class CraftProfileProperty {
/**
* Different JSON formatting styles to use for encoded property values.
@@ -36,7 +36,7 @@ final class CraftProfileProperty {
@Override
public String format(JsonElement jsonElement) {
return gson.toJson(jsonElement);
return this.gson.toJson(jsonElement);
}
};
@@ -54,7 +54,7 @@ final class CraftProfileProperty {
}
public static boolean hasValidSignature(@Nonnull Property property) {
return property.hasSignature() && PUBLIC_KEYS.keys(ServicesKeyType.PROFILE_PROPERTY).stream().anyMatch((key) -> key.validateProperty(property));
return property.hasSignature() && CraftProfileProperty.PUBLIC_KEYS.keys(ServicesKeyType.PROFILE_PROPERTY).stream().anyMatch((key) -> key.validateProperty(property));
}
@Nullable
@@ -68,7 +68,7 @@ final class CraftProfileProperty {
@Nullable
public static JsonObject decodePropertyValue(@Nonnull String encodedPropertyValue) {
String json = decodeBase64(encodedPropertyValue);
String json = CraftProfileProperty.decodeBase64(encodedPropertyValue);
if (json == null) return null;
try {
JsonElement jsonElement = JsonParser.parseString(json);