Skip to content

Commit

Permalink
Account for game profile changes (#2549)
Browse files Browse the repository at this point in the history
  • Loading branch information
tal5 committed Oct 19, 2023
1 parent e347bd9 commit 0b8b6d9
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 31 deletions.
Expand Up @@ -190,7 +190,7 @@ public PlayerProfile fillPlayerProfile(PlayerProfile playerProfile) {
profile = minecraftServer.getProfileCache().get(playerProfile.getName()).orElse(null);
}
if (profile == null) {
profile = new GameProfile(playerProfile.getUniqueId(), playerProfile.getName());
profile = ProfileEditorImpl.getGameProfileNoProperties(playerProfile);
}
Property textures = profile.getProperties().containsKey("textures") ? Iterables.getFirst(profile.getProperties().get("textures"), null) : null;
if (textures == null || !textures.hasSignature() || profile.getName() == null || profile.getId() == null) {
Expand Down
Expand Up @@ -5,6 +5,7 @@
import com.denizenscript.denizen.nms.util.jnbt.CompoundTag;
import com.denizenscript.denizen.nms.util.jnbt.CompoundTagBuilder;
import com.denizenscript.denizen.nms.v1_20.ReflectionMappingsInfo;
import com.denizenscript.denizen.nms.v1_20.impl.ProfileEditorImpl;
import com.denizenscript.denizen.nms.v1_20.impl.jnbt.CompoundTagImpl;
import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizen.utilities.VanillaTagHelper;
Expand All @@ -13,7 +14,6 @@
import com.denizenscript.denizencore.utilities.debugging.Debug;
import com.google.common.collect.Iterables;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderSet;
Expand Down Expand Up @@ -100,11 +100,7 @@ public PlayerProfile getPlayerProfile(Skull skull) {

@Override
public void setPlayerProfile(Skull skull, PlayerProfile playerProfile) {
GameProfile gameProfile = new GameProfile(playerProfile.getUniqueId(), playerProfile.getName());
if (playerProfile.hasTexture()) {
gameProfile.getProperties().put("textures",
new Property("textures", playerProfile.getTexture(), playerProfile.getTextureSignature()));
}
GameProfile gameProfile = ProfileEditorImpl.getGameProfile(playerProfile);
try {
craftSkull_profile.set(skull, gameProfile);
}
Expand Down
@@ -1,19 +1,19 @@
package com.denizenscript.denizen.nms.v1_20.helpers;

import com.denizenscript.denizen.nms.v1_20.impl.entities.CraftFakePlayerImpl;
import com.denizenscript.denizen.nms.v1_20.impl.entities.EntityFakeArrowImpl;
import com.denizenscript.denizen.nms.v1_20.impl.entities.EntityFakePlayerImpl;
import com.denizenscript.denizen.nms.v1_20.impl.entities.EntityItemProjectileImpl;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import com.denizenscript.denizen.nms.NMSHandler;
import com.denizenscript.denizen.nms.interfaces.CustomEntityHelper;
import com.denizenscript.denizen.nms.interfaces.FakeArrow;
import com.denizenscript.denizen.nms.interfaces.FakePlayer;
import com.denizenscript.denizen.nms.interfaces.ItemProjectile;
import com.denizenscript.denizen.nms.util.PlayerProfile;
import com.denizenscript.denizen.nms.v1_20.impl.ProfileEditorImpl;
import com.denizenscript.denizen.nms.v1_20.impl.entities.CraftFakePlayerImpl;
import com.denizenscript.denizen.nms.v1_20.impl.entities.EntityFakeArrowImpl;
import com.denizenscript.denizen.nms.v1_20.impl.entities.EntityFakePlayerImpl;
import com.denizenscript.denizen.nms.v1_20.impl.entities.EntityItemProjectileImpl;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import com.mojang.authlib.GameProfile;
import net.minecraft.server.level.ClientInformation;
import net.minecraft.server.level.ServerLevel;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -113,10 +113,7 @@ else if (skin == null && !name.matches(".*[^A-Za-z0-9_].*")) {
UUID uuid = UUID.randomUUID();
playerProfile.setUniqueId(uuid);

GameProfile gameProfile = new GameProfile(playerProfile.getUniqueId(), playerProfile.getName());
gameProfile.getProperties().put("textures",
new Property("textures", playerProfile.getTexture(), playerProfile.getTextureSignature()));

GameProfile gameProfile = ProfileEditorImpl.getGameProfile(playerProfile);
final EntityFakePlayerImpl fakePlayer = new EntityFakePlayerImpl(worldServer.getServer(), worldServer, gameProfile, ClientInformation.createDefault(), doAdd);

fakePlayer.forceSetPositionRotation(location.getX(), location.getY(), location.getZ(),
Expand Down
Expand Up @@ -6,6 +6,7 @@
import com.denizenscript.denizen.nms.util.jnbt.IntArrayTag;
import com.denizenscript.denizen.nms.util.jnbt.Tag;
import com.denizenscript.denizen.nms.v1_20.ReflectionMappingsInfo;
import com.denizenscript.denizen.nms.v1_20.impl.ProfileEditorImpl;
import com.denizenscript.denizen.nms.v1_20.impl.jnbt.CompoundTagImpl;
import com.denizenscript.denizen.objects.ItemTag;
import com.denizenscript.denizen.utilities.FormattedTextHelper;
Expand Down Expand Up @@ -230,16 +231,7 @@ public PlayerProfile getSkullSkin(ItemStack is) {

@Override
public ItemStack setSkullSkin(ItemStack itemStack, PlayerProfile playerProfile) {
GameProfile gameProfile = new GameProfile(playerProfile.getUniqueId(), playerProfile.getName());
if (playerProfile.hasTexture()) {
gameProfile.getProperties().get("textures").clear();
if (playerProfile.getTextureSignature() != null) {
gameProfile.getProperties().put("textures", new Property("textures", playerProfile.getTexture(), playerProfile.getTextureSignature()));
}
else {
gameProfile.getProperties().put("textures", new Property("textures", playerProfile.getTexture()));
}
}
GameProfile gameProfile = ProfileEditorImpl.getGameProfile(playerProfile);
net.minecraft.world.item.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack);
net.minecraft.nbt.CompoundTag tag = nmsItemStack.hasTag() ? nmsItemStack.getTag() : new net.minecraft.nbt.CompoundTag();
tag.put("SkullOwner", NbtUtils.writeGameProfile(new net.minecraft.nbt.CompoundTag(), gameProfile));
Expand Down
Expand Up @@ -405,7 +405,7 @@ public void sendPlayerInfoAddPacket(Player player, EnumSet<ProfileEditMode> edit
case UPDATE_LISTED -> ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LISTED;
});
}
GameProfile profile = new GameProfile(id, name);
GameProfile profile = new GameProfile(id, name != null ? name : ProfileEditorImpl.EMPTY_NAME);
if (texture != null) {
profile.getProperties().put("textures", new Property("textures", texture, signature));
}
Expand Down
Expand Up @@ -32,6 +32,9 @@

public class ProfileEditorImpl extends ProfileEditor {

public static final String EMPTY_NAME = "";
public static final UUID NIL_UUID = new UUID(0L, 0L);

@Override
protected void updatePlayer(final Player player, final boolean isSkinChanging) {
final ServerPlayer nmsPlayer = ((CraftPlayer) player).getHandle();
Expand Down Expand Up @@ -116,8 +119,14 @@ public static ClientboundPlayerInfoUpdatePacket createInfoPacket(EnumSet<Clientb
return playerInfoUpdatePacket;
}

private static GameProfile getGameProfile(PlayerProfile playerProfile) {
GameProfile gameProfile = new GameProfile(playerProfile.getUniqueId(), playerProfile.getName());
public static GameProfile getGameProfileNoProperties(PlayerProfile playerProfile) {
UUID uuid = playerProfile.getUniqueId();
String name = playerProfile.getName();
return new GameProfile(uuid != null ? uuid : NIL_UUID, name != null ? name : EMPTY_NAME);
}

public static GameProfile getGameProfile(PlayerProfile playerProfile) {
GameProfile gameProfile = getGameProfileNoProperties(playerProfile);
if (playerProfile.hasTexture()) {
gameProfile.getProperties().put("textures", new Property("textures", playerProfile.getTexture(), playerProfile.getTextureSignature()));
}
Expand Down

0 comments on commit 0b8b6d9

Please sign in to comment.