From c7d6c57320430eb8f1fd02a342a7f15ede87ca7f Mon Sep 17 00:00:00 2001 From: aro Date: Sun, 22 Jan 2023 15:57:55 +0100 Subject: [PATCH] refactor: much cleaner internals --- .../nicko/disguise/ActionResult.java | 11 +++- .../net/artelnatif/nicko/impl/Internals.java | 33 +++++++++++- .../net/artelnatif/nicko/impl/v1_17_R1.java | 48 ++++++------------ .../net/artelnatif/nicko/impl/v1_18_R1.java | 48 ++++++------------ .../net/artelnatif/nicko/impl/v1_18_R2.java | 50 ++++++------------- .../net/artelnatif/nicko/impl/v1_19_R1.java | 50 ++++++------------- .../net/artelnatif/nicko/impl/v1_19_R2.java | 39 ++++----------- 7 files changed, 110 insertions(+), 169 deletions(-) diff --git a/nicko-core/src/main/java/net/artelnatif/nicko/disguise/ActionResult.java b/nicko-core/src/main/java/net/artelnatif/nicko/disguise/ActionResult.java index 0716dd2..fab2a43 100644 --- a/nicko-core/src/main/java/net/artelnatif/nicko/disguise/ActionResult.java +++ b/nicko-core/src/main/java/net/artelnatif/nicko/disguise/ActionResult.java @@ -2,9 +2,10 @@ package net.artelnatif.nicko.disguise; import net.artelnatif.nicko.i18n.I18NDict; -public class ActionResult { +public class ActionResult { private final I18NDict errorMessage; private boolean error = false; + private R result; public ActionResult(I18NDict errorMessage) { this.error = true; @@ -15,6 +16,14 @@ public class ActionResult { this.errorMessage = null; } + public void setResult(R result) { + this.result = result; + } + + public R getResult() { + return result; + } + public boolean isError() { return error; } diff --git a/nicko-core/src/main/java/net/artelnatif/nicko/impl/Internals.java b/nicko-core/src/main/java/net/artelnatif/nicko/impl/Internals.java index da503a9..2588392 100644 --- a/nicko-core/src/main/java/net/artelnatif/nicko/impl/Internals.java +++ b/nicko-core/src/main/java/net/artelnatif/nicko/impl/Internals.java @@ -1,13 +1,44 @@ package net.artelnatif.nicko.impl; +import net.artelnatif.nicko.NickoBukkit; import net.artelnatif.nicko.disguise.NickoProfile; import net.artelnatif.nicko.disguise.ActionResult; +import net.artelnatif.nicko.i18n.I18NDict; +import net.artelnatif.nicko.mojang.MojangAPI; +import net.artelnatif.nicko.mojang.MojangSkin; import org.bukkit.entity.Player; +import java.io.IOException; +import java.util.Optional; +import java.util.concurrent.ExecutionException; + public interface Internals { void updateSelf(Player player); void updateOthers(Player player); - ActionResult updateProfile(Player player, NickoProfile profile, boolean skinChange, boolean reset); + ActionResult updateProfile(Player player, NickoProfile profile, boolean skinChange, boolean reset); + + default ActionResult fetchSkinTextures(NickoProfile profile, boolean reset) { + Optional skin; + try { + final MojangAPI mojang = NickoBukkit.getInstance().getMojangAPI(); + final Optional uuid = mojang.getUUID(profile.getSkin()); + if (uuid.isPresent()) { + skin = (reset ? mojang.getSkinWithoutCaching(uuid.get()) : mojang.getSkin(uuid.get())); + if (skin.isEmpty()) { + return new ActionResult<>(I18NDict.Error.SKIN_FAIL_MOJANG); + } + + final ActionResult actionResult = new ActionResult<>(); + actionResult.setResult(skin.get()); + return actionResult; + } + return new ActionResult<>(I18NDict.Error.NAME_FAIL_MOJANG); + } catch (ExecutionException e) { + return new ActionResult<>(I18NDict.Error.SKIN_FAIL_CACHE); + } catch (IOException e) { + return new ActionResult<>(I18NDict.Error.NAME_FAIL_MOJANG); + } + } } diff --git a/v1_17_R1/src/main/java/net/artelnatif/nicko/impl/v1_17_R1.java b/v1_17_R1/src/main/java/net/artelnatif/nicko/impl/v1_17_R1.java index 34e12d1..6ca5cd1 100644 --- a/v1_17_R1/src/main/java/net/artelnatif/nicko/impl/v1_17_R1.java +++ b/v1_17_R1/src/main/java/net/artelnatif/nicko/impl/v1_17_R1.java @@ -3,11 +3,8 @@ package net.artelnatif.nicko.impl; import com.mojang.authlib.GameProfile; import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.PropertyMap; -import net.artelnatif.nicko.NickoBukkit; import net.artelnatif.nicko.disguise.ActionResult; import net.artelnatif.nicko.disguise.NickoProfile; -import net.artelnatif.nicko.i18n.I18NDict; -import net.artelnatif.nicko.mojang.MojangAPI; import net.artelnatif.nicko.mojang.MojangSkin; import net.minecraft.network.chat.IChatBaseComponent; import net.minecraft.network.protocol.game.*; @@ -24,10 +21,6 @@ import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerTeleportEvent; -import java.io.IOException; -import java.util.Optional; -import java.util.concurrent.ExecutionException; - public class v1_17_R1 implements Internals { @Override public void updateSelf(Player player) { @@ -70,41 +63,28 @@ public class v1_17_R1 implements Internals { } @Override - public ActionResult updateProfile(Player player, NickoProfile profile, boolean skinChange, boolean reset) { - final CraftPlayer craftPlayer = (CraftPlayer) player; - final EntityPlayer entityPlayer = craftPlayer.getHandle(); + public ActionResult updateProfile(Player player, NickoProfile profile, boolean skinChange, boolean reset) { final boolean changeOnlyName = profile.getSkin() != null && !profile.getSkin().equalsIgnoreCase(player.getName()); final String profileName = profile.getName() == null ? player.getName() : profile.getName(); - Optional skin; - final PacketPlayOutPlayerInfo remove = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.e, entityPlayer); - final PacketPlayOutPlayerInfo add = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.a); + final CraftPlayer craftPlayer = (CraftPlayer) player; + final EntityPlayer entityPlayer = craftPlayer.getHandle(); final GameProfile gameProfile = new GameProfile(player.getUniqueId(), profileName); if (skinChange || changeOnlyName) { - try { - final MojangAPI mojang = NickoBukkit.getInstance().getMojangAPI(); - final Optional uuid = mojang.getUUID(profile.getSkin()); - if (uuid.isPresent()) { - skin = (reset ? mojang.getSkinWithoutCaching(uuid.get()) : mojang.getSkin(uuid.get())); - if (skin.isPresent()) { - final PropertyMap properties = gameProfile.getProperties(); - properties.removeAll("textures"); - properties.put("textures", new Property("textures", skin.get().value(), skin.get().signature())); - updateSelf(player); - } else { - return new ActionResult(I18NDict.Error.SKIN_FAIL_MOJANG); - } - } else { - return new ActionResult(I18NDict.Error.NAME_FAIL_MOJANG); - } - } catch (ExecutionException e) { - return new ActionResult(I18NDict.Error.SKIN_FAIL_CACHE); - } catch (IOException e) { - return new ActionResult(I18NDict.Error.UNEXPECTED_ERROR); + final ActionResult skinFetch = fetchSkinTextures(profile, reset); + if (!skinFetch.isError()) { + final MojangSkin skin = skinFetch.getResult(); + final PropertyMap properties = gameProfile.getProperties(); + properties.removeAll("textures"); + properties.put("textures", new Property("textures", skin.value(), skin.signature())); + updateSelf(player); } } + final PacketPlayOutPlayerInfo remove = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.e, entityPlayer); + final PacketPlayOutPlayerInfo add = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.a); + add.b().clear(); add.b().add(new PacketPlayOutPlayerInfo.PlayerInfoData(gameProfile, player.getPing(), @@ -116,6 +96,6 @@ public class v1_17_R1 implements Internals { onlineEntityPlayer.b.sendPacket(add); }); updateOthers(player); - return new ActionResult(); + return new ActionResult<>(); } } diff --git a/v1_18_R1/src/main/java/net/artelnatif/nicko/impl/v1_18_R1.java b/v1_18_R1/src/main/java/net/artelnatif/nicko/impl/v1_18_R1.java index 0ee1635..dbfb5dc 100644 --- a/v1_18_R1/src/main/java/net/artelnatif/nicko/impl/v1_18_R1.java +++ b/v1_18_R1/src/main/java/net/artelnatif/nicko/impl/v1_18_R1.java @@ -3,11 +3,8 @@ package net.artelnatif.nicko.impl; import com.mojang.authlib.GameProfile; import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.PropertyMap; -import net.artelnatif.nicko.NickoBukkit; import net.artelnatif.nicko.disguise.ActionResult; import net.artelnatif.nicko.disguise.NickoProfile; -import net.artelnatif.nicko.i18n.I18NDict; -import net.artelnatif.nicko.mojang.MojangAPI; import net.artelnatif.nicko.mojang.MojangSkin; import net.minecraft.network.chat.IChatBaseComponent; import net.minecraft.network.protocol.game.*; @@ -24,10 +21,6 @@ import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerTeleportEvent; -import java.io.IOException; -import java.util.Optional; -import java.util.concurrent.ExecutionException; - public class v1_18_R1 implements Internals { @Override public void updateSelf(Player player) { @@ -72,41 +65,28 @@ public class v1_18_R1 implements Internals { } @Override - public ActionResult updateProfile(Player player, NickoProfile profile, boolean skinChange, boolean reset) { - final CraftPlayer craftPlayer = (CraftPlayer) player; - final EntityPlayer entityPlayer = craftPlayer.getHandle(); + public ActionResult updateProfile(Player player, NickoProfile profile, boolean skinChange, boolean reset) { final boolean changeOnlyName = profile.getSkin() != null && !profile.getSkin().equalsIgnoreCase(player.getName()); final String profileName = profile.getName() == null ? player.getName() : profile.getName(); - Optional skin; - final PacketPlayOutPlayerInfo remove = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.e, entityPlayer); - final PacketPlayOutPlayerInfo add = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.a); + final CraftPlayer craftPlayer = (CraftPlayer) player; + final EntityPlayer entityPlayer = craftPlayer.getHandle(); final GameProfile gameProfile = new GameProfile(player.getUniqueId(), profileName); if (skinChange || changeOnlyName) { - try { - final MojangAPI mojang = NickoBukkit.getInstance().getMojangAPI(); - final Optional uuid = mojang.getUUID(profile.getSkin()); - if (uuid.isPresent()) { - skin = (reset ? mojang.getSkinWithoutCaching(uuid.get()) : mojang.getSkin(uuid.get())); - if (skin.isPresent()) { - final PropertyMap properties = gameProfile.getProperties(); - properties.removeAll("textures"); - properties.put("textures", new Property("textures", skin.get().value(), skin.get().signature())); - updateSelf(player); - } else { - return new ActionResult(I18NDict.Error.SKIN_FAIL_MOJANG); - } - } else { - return new ActionResult(I18NDict.Error.NAME_FAIL_MOJANG); - } - } catch (ExecutionException e) { - return new ActionResult(I18NDict.Error.SKIN_FAIL_CACHE); - } catch (IOException e) { - return new ActionResult(I18NDict.Error.UNEXPECTED_ERROR); + final ActionResult skinFetch = fetchSkinTextures(profile, reset); + if (!skinFetch.isError()) { + final MojangSkin skin = skinFetch.getResult(); + final PropertyMap properties = gameProfile.getProperties(); + properties.removeAll("textures"); + properties.put("textures", new Property("textures", skin.value(), skin.signature())); + updateSelf(player); } } + final PacketPlayOutPlayerInfo remove = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.e, entityPlayer); + final PacketPlayOutPlayerInfo add = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.a); + add.b().clear(); add.b().add(new PacketPlayOutPlayerInfo.PlayerInfoData(gameProfile, player.getPing(), @@ -118,6 +98,6 @@ public class v1_18_R1 implements Internals { onlineEntityPlayer.b.a(add); }); updateOthers(player); - return new ActionResult(); + return new ActionResult<>(); } } diff --git a/v1_18_R2/src/main/java/net/artelnatif/nicko/impl/v1_18_R2.java b/v1_18_R2/src/main/java/net/artelnatif/nicko/impl/v1_18_R2.java index 1076dd0..cd76223 100644 --- a/v1_18_R2/src/main/java/net/artelnatif/nicko/impl/v1_18_R2.java +++ b/v1_18_R2/src/main/java/net/artelnatif/nicko/impl/v1_18_R2.java @@ -3,11 +3,8 @@ package net.artelnatif.nicko.impl; import com.mojang.authlib.GameProfile; import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.PropertyMap; -import net.artelnatif.nicko.NickoBukkit; import net.artelnatif.nicko.disguise.ActionResult; import net.artelnatif.nicko.disguise.NickoProfile; -import net.artelnatif.nicko.i18n.I18NDict; -import net.artelnatif.nicko.mojang.MojangAPI; import net.artelnatif.nicko.mojang.MojangSkin; import net.minecraft.core.Holder; import net.minecraft.network.chat.IChatBaseComponent; @@ -25,10 +22,6 @@ import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerTeleportEvent; -import java.io.IOException; -import java.util.Optional; -import java.util.concurrent.ExecutionException; - public class v1_18_R2 implements Internals { @Override public void updateSelf(Player player) { @@ -72,41 +65,28 @@ public class v1_18_R2 implements Internals { } @Override - public ActionResult updateProfile(Player player, NickoProfile profile, boolean skinChange, boolean reset) { - final CraftPlayer craftPlayer = (CraftPlayer) player; - final EntityPlayer entityPlayer = craftPlayer.getHandle(); + public ActionResult updateProfile(Player player, NickoProfile profile, boolean skinChange, boolean reset) { final boolean changeOnlyName = profile.getSkin() != null && !profile.getSkin().equalsIgnoreCase(player.getName()); final String profileName = profile.getName() == null ? player.getName() : profile.getName(); - Optional skin; - final PacketPlayOutPlayerInfo remove = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.e, entityPlayer); - final PacketPlayOutPlayerInfo add = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.a); + final CraftPlayer craftPlayer = (CraftPlayer) player; + final EntityPlayer entityPlayer = craftPlayer.getHandle(); final GameProfile gameProfile = new GameProfile(player.getUniqueId(), profileName); if (skinChange || changeOnlyName) { - try { - final MojangAPI mojang = NickoBukkit.getInstance().getMojangAPI(); - final Optional uuid = mojang.getUUID(profile.getSkin()); - if (uuid.isPresent()) { - skin = (reset ? mojang.getSkinWithoutCaching(uuid.get()) : mojang.getSkin(uuid.get())); - if (skin.isPresent()) { - final PropertyMap properties = gameProfile.getProperties(); - properties.removeAll("textures"); - properties.put("textures", new Property("textures", skin.get().value(), skin.get().signature())); - updateSelf(player); - } else { - return new ActionResult(I18NDict.Error.SKIN_FAIL_MOJANG); - } - } else { - return new ActionResult(I18NDict.Error.NAME_FAIL_MOJANG); - } - } catch (ExecutionException e) { - return new ActionResult(I18NDict.Error.SKIN_FAIL_CACHE); - } catch (IOException e) { - return new ActionResult(I18NDict.Error.UNEXPECTED_ERROR); + final ActionResult skinFetch = fetchSkinTextures(profile, reset); + if (!skinFetch.isError()) { + final MojangSkin skin = skinFetch.getResult(); + final PropertyMap properties = gameProfile.getProperties(); + properties.removeAll("textures"); + properties.put("textures", new Property("textures", skin.value(), skin.signature())); + updateSelf(player); } } + final PacketPlayOutPlayerInfo remove = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.e, entityPlayer); + final PacketPlayOutPlayerInfo add = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.a); + add.b().clear(); add.b().add(new PacketPlayOutPlayerInfo.PlayerInfoData(gameProfile, player.getPing(), @@ -118,6 +98,6 @@ public class v1_18_R2 implements Internals { onlineEntityPlayer.b.a(add); }); updateOthers(player); - return new ActionResult(); + return new ActionResult<>(); } -} +} \ No newline at end of file diff --git a/v1_19_R1/src/main/java/net/artelnatif/nicko/impl/v1_19_R1.java b/v1_19_R1/src/main/java/net/artelnatif/nicko/impl/v1_19_R1.java index c8ead05..e7cba66 100644 --- a/v1_19_R1/src/main/java/net/artelnatif/nicko/impl/v1_19_R1.java +++ b/v1_19_R1/src/main/java/net/artelnatif/nicko/impl/v1_19_R1.java @@ -3,11 +3,8 @@ package net.artelnatif.nicko.impl; import com.mojang.authlib.GameProfile; import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.PropertyMap; -import net.artelnatif.nicko.NickoBukkit; import net.artelnatif.nicko.disguise.ActionResult; import net.artelnatif.nicko.disguise.NickoProfile; -import net.artelnatif.nicko.i18n.I18NDict; -import net.artelnatif.nicko.mojang.MojangAPI; import net.artelnatif.nicko.mojang.MojangSkin; import net.minecraft.network.chat.IChatBaseComponent; import net.minecraft.network.protocol.game.*; @@ -24,9 +21,7 @@ import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerTeleportEvent; -import java.io.IOException; import java.util.Optional; -import java.util.concurrent.ExecutionException; public class v1_19_R1 implements Internals { @Override @@ -70,44 +65,29 @@ public class v1_19_R1 implements Internals { } @Override - public ActionResult updateProfile(Player player, NickoProfile profile, boolean skinChange, boolean reset) { - final CraftPlayer craftPlayer = (CraftPlayer) player; - final EntityPlayer entityPlayer = craftPlayer.getHandle(); + public ActionResult updateProfile(Player player, NickoProfile profile, boolean skinChange, boolean reset) { final boolean changeOnlyName = profile.getSkin() != null && !profile.getSkin().equalsIgnoreCase(player.getName()); final String profileName = profile.getName() == null ? player.getName() : profile.getName(); - Optional skin; - final PacketPlayOutPlayerInfo add = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.a); - final PacketPlayOutPlayerInfo remove = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.e, entityPlayer); - - // "It's a Surprise Tool That Will Help Us Later!" - final ProfilePublicKey.a key = remove.b().get(0).e(); + final CraftPlayer craftPlayer = (CraftPlayer) player; + final EntityPlayer entityPlayer = craftPlayer.getHandle(); final GameProfile gameProfile = new GameProfile(player.getUniqueId(), profileName); if (skinChange || changeOnlyName) { - try { - final MojangAPI mojang = NickoBukkit.getInstance().getMojangAPI(); - final Optional uuid = mojang.getUUID(profile.getSkin()); - if (uuid.isPresent()) { - skin = (reset ? mojang.getSkinWithoutCaching(uuid.get()) : mojang.getSkin(uuid.get())); - if (skin.isPresent()) { - final PropertyMap properties = gameProfile.getProperties(); - properties.removeAll("textures"); - properties.put("textures", new Property("textures", skin.get().value(), skin.get().signature())); - updateSelf(player); - } else { - return new ActionResult(I18NDict.Error.SKIN_FAIL_MOJANG); - } - } else { - return new ActionResult(I18NDict.Error.NAME_FAIL_MOJANG); - } - } catch (ExecutionException e) { - return new ActionResult(I18NDict.Error.SKIN_FAIL_CACHE); - } catch (IOException e) { - return new ActionResult(I18NDict.Error.NAME_FAIL_MOJANG); + final ActionResult skinFetch = fetchSkinTextures(profile, reset); + if (!skinFetch.isError()) { + final MojangSkin skin = skinFetch.getResult(); + final PropertyMap properties = gameProfile.getProperties(); + properties.removeAll("textures"); + properties.put("textures", new Property("textures", skin.value(), skin.signature())); + updateSelf(player); } } + final PacketPlayOutPlayerInfo add = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.a); + final PacketPlayOutPlayerInfo remove = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.e, entityPlayer); + // "It's a Surprise Tool That Will Help Us Later!" + final ProfilePublicKey.a key = remove.b().get(0).e(); add.b().clear(); add.b().add(new PacketPlayOutPlayerInfo.PlayerInfoData(gameProfile, @@ -122,6 +102,6 @@ public class v1_19_R1 implements Internals { onlineEntityPlayer.b.a(add); }); updateOthers(player); - return new ActionResult(); + return new ActionResult<>(); } } diff --git a/v1_19_R2/src/main/java/net/artelnatif/nicko/impl/v1_19_R2.java b/v1_19_R2/src/main/java/net/artelnatif/nicko/impl/v1_19_R2.java index d7092fb..c1463a7 100644 --- a/v1_19_R2/src/main/java/net/artelnatif/nicko/impl/v1_19_R2.java +++ b/v1_19_R2/src/main/java/net/artelnatif/nicko/impl/v1_19_R2.java @@ -6,8 +6,6 @@ import com.mojang.authlib.properties.PropertyMap; import net.artelnatif.nicko.NickoBukkit; import net.artelnatif.nicko.disguise.ActionResult; import net.artelnatif.nicko.disguise.NickoProfile; -import net.artelnatif.nicko.i18n.I18NDict; -import net.artelnatif.nicko.mojang.MojangAPI; import net.artelnatif.nicko.mojang.MojangSkin; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.RemoteChatSession; @@ -25,10 +23,8 @@ import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerTeleportEvent; -import java.io.IOException; import java.lang.reflect.Field; import java.util.*; -import java.util.concurrent.ExecutionException; public class v1_19_R2 implements Internals { @Override @@ -73,37 +69,21 @@ public class v1_19_R2 implements Internals { } @Override - public ActionResult updateProfile(Player player, NickoProfile profile, boolean skinChange, boolean reset) { + public ActionResult updateProfile(Player player, NickoProfile profile, boolean skinChange, boolean reset) { final boolean changeOnlyName = profile.getSkin() != null && !profile.getSkin().equalsIgnoreCase(player.getName()); final String profileName = profile.getName() == null ? player.getName() : profile.getName(); - Optional skin; final ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle(); final GameProfile gameProfile = new GameProfile(player.getUniqueId(), profileName); - final ClientboundPlayerInfoRemovePacket remove = new ClientboundPlayerInfoRemovePacket(List.of(player.getUniqueId())); - if (skinChange || changeOnlyName) { - try { - final MojangAPI mojang = NickoBukkit.getInstance().getMojangAPI(); - final Optional uuid = mojang.getUUID(profile.getSkin()); - if (uuid.isPresent()) { - skin = (reset ? mojang.getSkinWithoutCaching(uuid.get()) : mojang.getSkin(uuid.get())); - if (skin.isPresent()) { - final PropertyMap properties = gameProfile.getProperties(); - properties.removeAll("textures"); - properties.put("textures", new Property("textures", skin.get().value(), skin.get().signature())); - updateSelf(player); - } else { - return new ActionResult(I18NDict.Error.SKIN_FAIL_MOJANG); - } - } else { - return new ActionResult(I18NDict.Error.NAME_FAIL_MOJANG); - } - } catch (ExecutionException e) { - return new ActionResult(I18NDict.Error.SKIN_FAIL_CACHE); - } catch (IOException e) { - return new ActionResult(I18NDict.Error.NAME_FAIL_MOJANG); + final ActionResult skinFetch = fetchSkinTextures(profile, reset); + if (!skinFetch.isError()) { + final MojangSkin skin = skinFetch.getResult(); + final PropertyMap properties = gameProfile.getProperties(); + properties.removeAll("textures"); + properties.put("textures", new Property("textures", skin.value(), skin.signature())); + updateSelf(player); } } @@ -113,6 +93,7 @@ public class v1_19_R2 implements Internals { ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LATENCY, ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LISTED), Collections.singletonList(serverPlayer)); + final ClientboundPlayerInfoRemovePacket remove = new ClientboundPlayerInfoRemovePacket(List.of(player.getUniqueId())); if (serverPlayer.getChatSession() == null) { NickoBukkit.getInstance().getLogger().warning("Chat Session of " + serverPlayer.displayName + " is undefined." + @@ -142,7 +123,7 @@ public class v1_19_R2 implements Internals { onlinePlayer.connection.send(init); }); updateOthers(player); - return new ActionResult(); + return new ActionResult<>(); } private void spoofPlayerInfoPacket(Object object, Object newValue) {