From f68d9620379ac65e3409a6bdd8bc5bc5bb2c826e Mon Sep 17 00:00:00 2001 From: aro Date: Sun, 22 Jan 2023 15:17:19 +0100 Subject: [PATCH] refactor: cleanup internals --- .../net/artelnatif/nicko/impl/v1_17_R1.java | 22 +++------------ .../net/artelnatif/nicko/impl/v1_18_R1.java | 22 +++------------ .../net/artelnatif/nicko/impl/v1_18_R2.java | 22 +++------------ .../net/artelnatif/nicko/impl/v1_19_R1.java | 28 ++++--------------- .../net/artelnatif/nicko/impl/v1_19_R2.java | 12 +------- 5 files changed, 18 insertions(+), 88 deletions(-) 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 176ffd9..34e12d1 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 @@ -4,8 +4,8 @@ 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.NickoProfile; 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; @@ -23,7 +23,6 @@ import org.bukkit.craftbukkit.v1_17_R1.CraftWorld; import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerTeleportEvent; -import org.bukkit.inventory.ItemStack; import java.io.IOException; import java.util.Optional; @@ -43,10 +42,8 @@ public class v1_17_R1 implements Internals { false); final boolean wasFlying = player.isFlying(); - final ItemStack itemOnCursor = player.getItemOnCursor(); entityPlayer.b.sendPacket(respawn); player.setFlying(wasFlying); - player.setItemOnCursor(itemOnCursor); player.teleport(player.getLocation(), PlayerTeleportEvent.TeleportCause.PLUGIN); player.updateInventory(); } @@ -57,19 +54,9 @@ public class v1_17_R1 implements Internals { final PacketPlayOutEntityDestroy destroy = new PacketPlayOutEntityDestroy(entityPlayer.getBukkitEntity().getEntityId()); final PacketPlayOutNamedEntitySpawn spawn = new PacketPlayOutNamedEntitySpawn(entityPlayer); - /* - BIT MASKS: - 0x01 Cape enabled - 0x02 Jacket enabled - 0x04 Left sleeve enabled - 0x08 Right sleeve enabled - 0x10 Left pants leg enabled - 0x20 Right pants leg enabled - 0x40 Hat enabled - */ final DataWatcher dataWatcher = entityPlayer.getDataWatcher(); final DataWatcherObject displayedSkinPartDataWatcher = new DataWatcherObject<>(17, DataWatcherRegistry.a); - dataWatcher.set(displayedSkinPartDataWatcher, (byte) 0x7f); // 127, all masks combined + dataWatcher.set(displayedSkinPartDataWatcher, (byte) 0x7f); final PacketPlayOutEntityMetadata entityMetadata = new PacketPlayOutEntityMetadata(entityPlayer.getBukkitEntity().getEntityId(), dataWatcher, true); Bukkit.getOnlinePlayers().forEach(online -> { @@ -77,8 +64,8 @@ public class v1_17_R1 implements Internals { if (onlineEntityPlayer.getBukkitEntity().getUniqueId() != player.getUniqueId()) { onlineEntityPlayer.b.sendPacket(destroy); onlineEntityPlayer.b.sendPacket(spawn); - onlineEntityPlayer.b.sendPacket(entityMetadata); } + onlineEntityPlayer.b.sendPacket(entityMetadata); }); } @@ -102,6 +89,7 @@ public class v1_17_R1 implements Internals { 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 { @@ -121,8 +109,6 @@ public class v1_17_R1 implements Internals { add.b().add(new PacketPlayOutPlayerInfo.PlayerInfoData(gameProfile, player.getPing(), EnumGamemode.getById(player.getGameMode().ordinal()), IChatBaseComponent.a(profileName))); - entityPlayer.b.sendPacket(remove); - entityPlayer.b.sendPacket(add); Bukkit.getOnlinePlayers().forEach(online -> { EntityPlayer onlineEntityPlayer = ((CraftPlayer) online).getHandle(); 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 a684336..0ee1635 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 @@ -4,8 +4,8 @@ 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.NickoProfile; 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; @@ -23,7 +23,6 @@ import org.bukkit.craftbukkit.v1_18_R1.CraftWorld; import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerTeleportEvent; -import org.bukkit.inventory.ItemStack; import java.io.IOException; import java.util.Optional; @@ -45,10 +44,8 @@ public class v1_18_R1 implements Internals { false); final boolean wasFlying = player.isFlying(); - final ItemStack itemOnCursor = player.getItemOnCursor(); entityPlayer.b.a(respawn); player.setFlying(wasFlying); - player.setItemOnCursor(itemOnCursor); player.teleport(player.getLocation(), PlayerTeleportEvent.TeleportCause.PLUGIN); player.updateInventory(); } @@ -59,19 +56,9 @@ public class v1_18_R1 implements Internals { final PacketPlayOutEntityDestroy destroy = new PacketPlayOutEntityDestroy(entityPlayer.getBukkitEntity().getEntityId()); final PacketPlayOutNamedEntitySpawn spawn = new PacketPlayOutNamedEntitySpawn(entityPlayer); - /* - BIT MASKS: - 0x01 Cape enabled - 0x02 Jacket enabled - 0x04 Left sleeve enabled - 0x08 Right sleeve enabled - 0x10 Left pants leg enabled - 0x20 Right pants leg enabled - 0x40 Hat enabled - */ final DataWatcher dataWatcher = entityPlayer.ai(); final DataWatcherObject displayedSkinPartDataWatcher = new DataWatcherObject<>(17, DataWatcherRegistry.a); - dataWatcher.b(displayedSkinPartDataWatcher, (byte) 0x7f); // 127, all masks combined + dataWatcher.b(displayedSkinPartDataWatcher, (byte) 0x7f); final PacketPlayOutEntityMetadata entityMetadata = new PacketPlayOutEntityMetadata(entityPlayer.getBukkitEntity().getEntityId(), dataWatcher, true); Bukkit.getOnlinePlayers().forEach(online -> { @@ -79,8 +66,8 @@ public class v1_18_R1 implements Internals { if (onlineEntityPlayer.getBukkitEntity().getUniqueId() != player.getUniqueId()) { onlineEntityPlayer.b.a(destroy); onlineEntityPlayer.b.a(spawn); - onlineEntityPlayer.b.a(entityMetadata); } + onlineEntityPlayer.b.a(entityMetadata); }); } @@ -104,6 +91,7 @@ public class v1_18_R1 implements Internals { 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 { @@ -123,8 +111,6 @@ public class v1_18_R1 implements Internals { add.b().add(new PacketPlayOutPlayerInfo.PlayerInfoData(gameProfile, player.getPing(), EnumGamemode.a(player.getGameMode().ordinal()), IChatBaseComponent.a(profileName))); - entityPlayer.b.a(remove); - entityPlayer.b.a(add); Bukkit.getOnlinePlayers().forEach(online -> { EntityPlayer onlineEntityPlayer = ((CraftPlayer) online).getHandle(); 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 3765a1d..1076dd0 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 @@ -4,8 +4,8 @@ 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.NickoProfile; 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; @@ -24,7 +24,6 @@ import org.bukkit.craftbukkit.v1_18_R2.CraftWorld; import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerTeleportEvent; -import org.bukkit.inventory.ItemStack; import java.io.IOException; import java.util.Optional; @@ -45,10 +44,8 @@ public class v1_18_R2 implements Internals { false); final boolean wasFlying = player.isFlying(); - final ItemStack itemOnCursor = player.getItemOnCursor(); entityPlayer.b.a(respawn); player.setFlying(wasFlying); - player.setItemOnCursor(itemOnCursor); player.teleport(player.getLocation(), PlayerTeleportEvent.TeleportCause.PLUGIN); player.updateInventory(); } @@ -59,19 +56,9 @@ public class v1_18_R2 implements Internals { final PacketPlayOutEntityDestroy destroy = new PacketPlayOutEntityDestroy(entityPlayer.getBukkitEntity().getEntityId()); final PacketPlayOutNamedEntitySpawn spawn = new PacketPlayOutNamedEntitySpawn(entityPlayer); - /* - BIT MASKS: - 0x01 Cape enabled - 0x02 Jacket enabled - 0x04 Left sleeve enabled - 0x08 Right sleeve enabled - 0x10 Left pants leg enabled - 0x20 Right pants leg enabled - 0x40 Hat enabled - */ final DataWatcher dataWatcher = entityPlayer.ai(); final DataWatcherObject displayedSkinPartDataWatcher = new DataWatcherObject<>(17, DataWatcherRegistry.a); - dataWatcher.b(displayedSkinPartDataWatcher, (byte) 0x7f); // 127, all masks combined + dataWatcher.b(displayedSkinPartDataWatcher, (byte) 0x7f); final PacketPlayOutEntityMetadata entityMetadata = new PacketPlayOutEntityMetadata(entityPlayer.getBukkitEntity().getEntityId(), dataWatcher, true); Bukkit.getOnlinePlayers().forEach(online -> { @@ -79,8 +66,8 @@ public class v1_18_R2 implements Internals { if (onlineEntityPlayer.getBukkitEntity().getUniqueId() != player.getUniqueId()) { onlineEntityPlayer.b.a(destroy); onlineEntityPlayer.b.a(spawn); - onlineEntityPlayer.b.a(entityMetadata); } + onlineEntityPlayer.b.a(entityMetadata); }); } @@ -104,6 +91,7 @@ public class v1_18_R2 implements Internals { 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 { @@ -123,8 +111,6 @@ public class v1_18_R2 implements Internals { add.b().add(new PacketPlayOutPlayerInfo.PlayerInfoData(gameProfile, player.getPing(), EnumGamemode.a(player.getGameMode().ordinal()), IChatBaseComponent.a(profileName))); - entityPlayer.b.a(remove); - entityPlayer.b.a(add); Bukkit.getOnlinePlayers().forEach(online -> { EntityPlayer onlineEntityPlayer = ((CraftPlayer) online).getHandle(); 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 9397406..c8ead05 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 @@ -4,8 +4,8 @@ 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.NickoProfile; 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; @@ -20,11 +20,9 @@ import net.minecraft.world.entity.player.ProfilePublicKey; import net.minecraft.world.level.EnumGamemode; import net.minecraft.world.level.World; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_19_R1.CraftWorld; import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerTeleportEvent; -import org.bukkit.inventory.ItemStack; import java.io.IOException; import java.util.Optional; @@ -35,11 +33,8 @@ public class v1_19_R1 implements Internals { public void updateSelf(Player player) { final EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle(); final ResourceKey levelResourceKey = entityPlayer.x().ab(); - final CraftWorld world = entityPlayer.s.getWorld(); - // last boolean is: "has death location" attribute, if true, the optional contains the death dimension and position. - // with the boolean being false, we don't need to provide a value, and thus we return an empty optional. final PacketPlayOutRespawn respawn = new PacketPlayOutRespawn(entityPlayer.x().Z(), - levelResourceKey, world.getSeed(), + levelResourceKey, entityPlayer.s.getWorld().getSeed(), entityPlayer.d.b(), entityPlayer.d.c(), false, false, @@ -47,10 +42,8 @@ public class v1_19_R1 implements Internals { Optional.empty()); final boolean wasFlying = player.isFlying(); - final ItemStack itemOnCursor = player.getItemOnCursor(); entityPlayer.b.a(respawn); player.setFlying(wasFlying); - player.setItemOnCursor(itemOnCursor); player.teleport(player.getLocation(), PlayerTeleportEvent.TeleportCause.PLUGIN); player.updateInventory(); } @@ -61,19 +54,9 @@ public class v1_19_R1 implements Internals { final PacketPlayOutEntityDestroy destroy = new PacketPlayOutEntityDestroy(entityPlayer.getBukkitEntity().getEntityId()); final PacketPlayOutNamedEntitySpawn spawn = new PacketPlayOutNamedEntitySpawn(entityPlayer); - /* - BIT MASKS: - 0x01 Cape enabled - 0x02 Jacket enabled - 0x04 Left sleeve enabled - 0x08 Right sleeve enabled - 0x10 Left pants leg enabled - 0x20 Right pants leg enabled - 0x40 Hat enabled - */ final DataWatcher dataWatcher = entityPlayer.ai(); final DataWatcherObject displayedSkinPartDataWatcher = new DataWatcherObject<>(17, DataWatcherRegistry.a); - dataWatcher.b(displayedSkinPartDataWatcher, (byte) 0x7f); // 127, all masks combined + dataWatcher.b(displayedSkinPartDataWatcher, (byte) 0x7f); final PacketPlayOutEntityMetadata entityMetadata = new PacketPlayOutEntityMetadata(entityPlayer.getBukkitEntity().getEntityId(), dataWatcher, true); Bukkit.getOnlinePlayers().forEach(online -> { @@ -81,8 +64,8 @@ public class v1_19_R1 implements Internals { if (onlineEntityPlayer.getBukkitEntity().getUniqueId() != player.getUniqueId()) { onlineEntityPlayer.b.a(destroy); onlineEntityPlayer.b.a(spawn); - onlineEntityPlayer.b.a(entityMetadata); } + onlineEntityPlayer.b.a(entityMetadata); }); } @@ -109,6 +92,7 @@ public class v1_19_R1 implements Internals { 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 { @@ -132,8 +116,6 @@ public class v1_19_R1 implements Internals { IChatBaseComponent.a(profileName), key)); // f mojang - entityPlayer.b.a(remove); - entityPlayer.b.a(add); Bukkit.getOnlinePlayers().forEach(online -> { EntityPlayer onlineEntityPlayer = ((CraftPlayer) online).getHandle(); onlineEntityPlayer.b.a(remove); 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 0dd558c..d7092fb 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 @@ -57,19 +57,9 @@ public class v1_19_R2 implements Internals { final ClientboundRemoveEntitiesPacket remove = new ClientboundRemoveEntitiesPacket(serverPlayer.getBukkitEntity().getEntityId()); final ClientboundAddEntityPacket add = new ClientboundAddEntityPacket(serverPlayer); - /* - BIT MASKS: - 0x01 Cape enabled - 0x02 Jacket enabled - 0x04 Left sleeve enabled - 0x08 Right sleeve enabled - 0x10 Left pants leg enabled - 0x20 Right pants leg enabled - 0x40 Hat enabled - */ final SynchedEntityData entityData = serverPlayer.getEntityData(); final EntityDataAccessor skinPartAccessor = new EntityDataAccessor<>(17, EntityDataSerializers.BYTE); - entityData.set(skinPartAccessor, (byte) 0x7f); // 127, all masks combined + entityData.set(skinPartAccessor, (byte) 0x7f); final ClientboundSetEntityDataPacket entityMetadata = new ClientboundSetEntityDataPacket(serverPlayer.getBukkitEntity().getEntityId(), entityData.getNonDefaultValues()); Bukkit.getOnlinePlayers().forEach(online -> {