diff --git a/README.md b/README.md index c5f1bd1..0728b1d 100755 --- a/README.md +++ b/README.md @@ -59,6 +59,12 @@ If you do not want to have NPCLib in your `plugins` folder, you need to use the **[Click here](https://github.com/JitseB/NPCLib/blob/master/DOCUMENTATION.md) for an elaborate explanation on how to use NPCLib in your next project.** +### Versioning +For NPCLib I use the follow versioning system: +* 1.x.x: Where the 1 indicates the major version of the library. When this number changes, it's highly likely there're big API changes. +* x.1.x: Where the 1 indicates the minor version of the library. When this number changes, a feature is added or a high priority bug is fixed. +* x.x.1: Where the 1 indicates another minor version of the library. When this number changes, a small bug has been fixed. + ### Building your own version 1. [Download](https://github.com/JitseB/NPCLib/archive/master.zip) or clone this repository. diff --git a/api/pom.xml b/api/pom.xml index 4bbea1a..ca1834b 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -8,7 +8,7 @@ npclib net.jitse - 2.6-SNAPSHOT + 2.7-SNAPSHOT npclib-api diff --git a/api/src/main/java/net/jitse/npclib/api/NPC.java b/api/src/main/java/net/jitse/npclib/api/NPC.java index c3db5ac..197a40e 100644 --- a/api/src/main/java/net/jitse/npclib/api/NPC.java +++ b/api/src/main/java/net/jitse/npclib/api/NPC.java @@ -137,12 +137,9 @@ public interface NPC { ItemStack getItem(NPCSlot slot); /** - * LABYMOD ONLY - * Let the NPC play an emote. - * (https://docs.labymod.net/pages/server/emote_api/) + * Update the skin for every play that can see the NPC. * - * @param receiver The player who should see the emote. - * @param emoteId The emote id (see link). + * @param skin The new skin for the NPC. */ - void forceLabyModEmote(Player receiver, int emoteId); + void updateSkin(Skin skin); } diff --git a/api/src/main/java/net/jitse/npclib/internal/NPCBase.java b/api/src/main/java/net/jitse/npclib/internal/NPCBase.java index 770e558..c295077 100644 --- a/api/src/main/java/net/jitse/npclib/internal/NPCBase.java +++ b/api/src/main/java/net/jitse/npclib/internal/NPCBase.java @@ -4,8 +4,6 @@ package net.jitse.npclib.internal; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; import com.mojang.authlib.GameProfile; import com.mojang.authlib.properties.Property; import net.jitse.npclib.NPCLib; @@ -17,7 +15,6 @@ import net.jitse.npclib.api.state.NPCSlot; import net.jitse.npclib.api.state.NPCState; import net.jitse.npclib.hologram.Hologram; import net.jitse.npclib.utilities.MathUtil; -import net.labymod.utilities.LMCUtils; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; @@ -61,7 +58,7 @@ public abstract class NPCBase implements NPC, NPCPacketHandler { public NPCLib getInstance() { return instance; } - + public UUID getUniqueId() { return uuid; } @@ -96,16 +93,6 @@ public abstract class NPCBase implements NPC, NPCPacketHandler { } } - @Override - public void forceLabyModEmote(Player receiver, int emoteId) { - JsonArray array = new JsonArray(); - JsonObject forcedEmote = new JsonObject(); - forcedEmote.addProperty("uuid", uuid.toString()); - forcedEmote.addProperty("emote_id", emoteId); - array.add(forcedEmote); - LMCUtils.sendLMCMessage(receiver, "emote_api", array); - } - public void disableFOV() { this.cosFOV = 0; } diff --git a/api/src/main/java/net/labymod/utilities/LMCUtils.java b/api/src/main/java/net/labymod/utilities/LMCUtils.java deleted file mode 100644 index d77d40b..0000000 --- a/api/src/main/java/net/labymod/utilities/LMCUtils.java +++ /dev/null @@ -1,153 +0,0 @@ -package net.labymod.utilities; - -import com.comphenix.tinyprotocol.Reflection; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; -import io.netty.handler.codec.DecoderException; -import io.netty.handler.codec.EncoderException; -import org.bukkit.entity.Player; - -import java.nio.charset.Charset; - -public class LMCUtils { - - private static final Class CRAFT_PLAYER_CLASS = Reflection.getCraftBukkitClass("CraftPlayer"); - private static final Reflection.MethodInvoker GET_HANDLE_METHOD = Reflection.getMethod(CRAFT_PLAYER_CLASS, "getHandle"); - private static final Class PLAYER_CONNECTION_CLASS = Reflection.getMinecraftClass("PlayerConnection"); - private static final Reflection.FieldAccessor PLAYER_CONNECTION_FIELD = Reflection.getField(Reflection.getMinecraftClass("EntityPlayer"), - "playerConnection", PLAYER_CONNECTION_CLASS); - private static final Reflection.MethodInvoker SEND_PACKET_METHOD = Reflection.getMethod(PLAYER_CONNECTION_CLASS, - "sendPacket", Reflection.getMinecraftClass("Packet")); - private static final Class PACKET_DATA_SERIALIZER_CLASS = Reflection.getMinecraftClass("PacketDataSerializer"); - private static final Reflection.ConstructorInvoker PACKET_DATA_SERIALIZER_CONSTRUCTOR = Reflection.getConstructor( - PACKET_DATA_SERIALIZER_CLASS, ByteBuf.class); - private static final Reflection.ConstructorInvoker PACKET_PLAY_OUT_CUSTOM_PAYLOAD_CONSTRUCTOR = Reflection.getConstructor( - Reflection.getMinecraftClass("PacketPlayOutCustomPayload"), String.class, PACKET_DATA_SERIALIZER_CLASS); - - /** - * Send a LMC message to the minecraft client - * - * @param player Minecraft Client - * @param key LMC message key - * @param messageContent json element - */ - public static void sendLMCMessage(Player player, String key, JsonElement messageContent) { - byte[] bytes = LMCUtils.getBytesToSend(key, messageContent.toString()); - - // 12/4/20, JMB: Converted into reflections for multi-version support: -// PacketDataSerializer pds = new PacketDataSerializer(Unpooled.wrappedBuffer(bytes)); -// PacketPlayOutCustomPayload payloadPacket = new PacketPlayOutCustomPayload("LMC", pds); -// ((CraftPlayer) player).getHandle().playerConnection.sendPacket(payloadPacket); - Object pds = PACKET_DATA_SERIALIZER_CONSTRUCTOR.invoke(Unpooled.wrappedBuffer(bytes)); - Object payloadPacket = PACKET_PLAY_OUT_CUSTOM_PAYLOAD_CONSTRUCTOR.invoke("LMC", pds); - SEND_PACKET_METHOD.invoke(PLAYER_CONNECTION_FIELD.get(GET_HANDLE_METHOD.invoke(CRAFT_PLAYER_CLASS.cast(player))), payloadPacket); - } - - /** - * Gets the bytes that are required to send the given message - * - * @param messageKey the message's key - * @param messageContents the message's contents - * @return the byte array that should be the payload - */ - public static byte[] getBytesToSend(String messageKey, String messageContents) { - // Getting an empty buffer - ByteBuf byteBuf = Unpooled.buffer(); - - // Writing the message-key to the buffer - writeString(byteBuf, messageKey); - - // Writing the contents to the buffer - writeString(byteBuf, messageContents); - - // Copying the buffer's bytes to the byte array - byte[] bytes = new byte[byteBuf.readableBytes()]; - byteBuf.readBytes(bytes); - - // Returning the byte array - return bytes; - } - - /** - * Writes a varint to the given byte buffer - * - * @param buf the byte buffer the int should be written to - * @param input the int that should be written to the buffer - */ - private static void writeVarIntToBuffer(ByteBuf buf, int input) { - while ((input & -128) != 0) { - buf.writeByte(input & 127 | 128); - input >>>= 7; - } - - buf.writeByte(input); - } - - /** - * Writes a string to the given byte buffer - * - * @param buf the byte buffer the string should be written to - * @param string the string that should be written to the buffer - */ - private static void writeString(ByteBuf buf, String string) { - byte[] abyte = string.getBytes(Charset.forName("UTF-8")); - - if (abyte.length > Short.MAX_VALUE) { - throw new EncoderException("String too big (was " + string.length() + " bytes encoded, max " + Short.MAX_VALUE + ")"); - } else { - writeVarIntToBuffer(buf, abyte.length); - buf.writeBytes(abyte); - } - } - - /** - * Reads a varint from the given byte buffer - * - * @param buf the byte buffer the varint should be read from - * @return the int read - */ - public static int readVarIntFromBuffer(ByteBuf buf) { - int i = 0; - int j = 0; - - byte b0; - do { - b0 = buf.readByte(); - i |= (b0 & 127) << j++ * 7; - if (j > 5) { - throw new RuntimeException("VarInt too big"); - } - } while ((b0 & 128) == 128); - - return i; - } - - /** - * Reads a string from the given byte buffer - * - * @param buf the byte buffer the string should be read from - * @param maxLength the string's max-length - * @return the string read - */ - public static String readString(ByteBuf buf, int maxLength) { - int i = readVarIntFromBuffer(buf); - - if (i > maxLength * 4) { - throw new DecoderException("The received encoded string buffer length is longer than maximum allowed (" + i + " > " + maxLength * 4 + ")"); - } else if (i < 0) { - throw new DecoderException("The received encoded string buffer length is less than zero! Weird string!"); - } else { - byte[] bytes = new byte[i]; - buf.readBytes(bytes); - - String s = new String(bytes, Charset.forName("UTF-8")); - if (s.length() > maxLength) { - throw new DecoderException("The received string length is longer than maximum allowed (" + i + " > " + maxLength + ")"); - } else { - return s; - } - } - } -} \ No newline at end of file diff --git a/nms/pom.xml b/nms/pom.xml index 0c2f738..d6ba164 100644 --- a/nms/pom.xml +++ b/nms/pom.xml @@ -8,7 +8,7 @@ net.jitse npclib - 2.6-SNAPSHOT + 2.7-SNAPSHOT npclib-nms diff --git a/nms/v1_10_R1/pom.xml b/nms/v1_10_R1/pom.xml index d4cd075..5143f19 100755 --- a/nms/v1_10_R1/pom.xml +++ b/nms/v1_10_R1/pom.xml @@ -8,7 +8,7 @@ net.jitse npclib-nms - 2.6-SNAPSHOT + 2.7-SNAPSHOT npclib-nms-v1_10_R1 diff --git a/nms/v1_10_R1/src/main/java/net/jitse/npclib/nms/v1_10_R1/NPC_v1_10_R1.java b/nms/v1_10_R1/src/main/java/net/jitse/npclib/nms/v1_10_R1/NPC_v1_10_R1.java index 58382f9..9d2c8ec 100755 --- a/nms/v1_10_R1/src/main/java/net/jitse/npclib/nms/v1_10_R1/NPC_v1_10_R1.java +++ b/nms/v1_10_R1/src/main/java/net/jitse/npclib/nms/v1_10_R1/NPC_v1_10_R1.java @@ -4,7 +4,10 @@ package net.jitse.npclib.nms.v1_10_R1; +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.properties.Property; import net.jitse.npclib.NPCLib; +import net.jitse.npclib.api.skin.Skin; import net.jitse.npclib.api.state.NPCSlot; import net.jitse.npclib.hologram.Hologram; import net.jitse.npclib.internal.MinecraftVersion; @@ -105,4 +108,19 @@ public class NPC_v1_10_R1 extends NPCBase { PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(entityId, nmsSlot, CraftItemStack.asNMSCopy(item)); playerConnection.sendPacket(packet); } + + @Override + public void updateSkin(Skin skin) { + GameProfile newProfile = new GameProfile(uuid, name); + newProfile.getProperties().get("textures").clear(); + newProfile.getProperties().put("textures", new Property("textures", skin.getValue(), skin.getSignature())); + this.packetPlayOutPlayerInfoAdd = new PacketPlayOutPlayerInfoWrapper().create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, newProfile, name); + for (Player player : Bukkit.getOnlinePlayers()) { + PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; + playerConnection.sendPacket(packetPlayOutPlayerInfoRemove); + playerConnection.sendPacket(packetPlayOutEntityDestroy); + playerConnection.sendPacket(packetPlayOutPlayerInfoAdd); + playerConnection.sendPacket(packetPlayOutNamedEntitySpawn); + } + } } diff --git a/nms/v1_11_R1/pom.xml b/nms/v1_11_R1/pom.xml index 75805b9..09ff4e7 100755 --- a/nms/v1_11_R1/pom.xml +++ b/nms/v1_11_R1/pom.xml @@ -8,7 +8,7 @@ net.jitse npclib-nms - 2.6-SNAPSHOT + 2.7-SNAPSHOT npclib-nms-v1_11_R1 diff --git a/nms/v1_11_R1/src/main/java/net/jitse/npclib/nms/v1_11_R1/NPC_v1_11_R1.java b/nms/v1_11_R1/src/main/java/net/jitse/npclib/nms/v1_11_R1/NPC_v1_11_R1.java index de491a5..dfb1151 100755 --- a/nms/v1_11_R1/src/main/java/net/jitse/npclib/nms/v1_11_R1/NPC_v1_11_R1.java +++ b/nms/v1_11_R1/src/main/java/net/jitse/npclib/nms/v1_11_R1/NPC_v1_11_R1.java @@ -4,7 +4,10 @@ package net.jitse.npclib.nms.v1_11_R1; +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.properties.Property; import net.jitse.npclib.NPCLib; +import net.jitse.npclib.api.skin.Skin; import net.jitse.npclib.api.state.NPCSlot; import net.jitse.npclib.hologram.Hologram; import net.jitse.npclib.internal.MinecraftVersion; @@ -105,4 +108,19 @@ public class NPC_v1_11_R1 extends NPCBase { PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(entityId, nmsSlot, CraftItemStack.asNMSCopy(item)); playerConnection.sendPacket(packet); } + + @Override + public void updateSkin(Skin skin) { + GameProfile newProfile = new GameProfile(uuid, name); + newProfile.getProperties().get("textures").clear(); + newProfile.getProperties().put("textures", new Property("textures", skin.getValue(), skin.getSignature())); + this.packetPlayOutPlayerInfoAdd = new PacketPlayOutPlayerInfoWrapper().create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, newProfile, name); + for (Player player : Bukkit.getOnlinePlayers()) { + PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; + playerConnection.sendPacket(packetPlayOutPlayerInfoRemove); + playerConnection.sendPacket(packetPlayOutEntityDestroy); + playerConnection.sendPacket(packetPlayOutPlayerInfoAdd); + playerConnection.sendPacket(packetPlayOutNamedEntitySpawn); + } + } } diff --git a/nms/v1_12_R1/pom.xml b/nms/v1_12_R1/pom.xml index c589cee..53ecc34 100755 --- a/nms/v1_12_R1/pom.xml +++ b/nms/v1_12_R1/pom.xml @@ -8,7 +8,7 @@ net.jitse npclib-nms - 2.6-SNAPSHOT + 2.7-SNAPSHOT npclib-nms-v1_12_R1 diff --git a/nms/v1_12_R1/src/main/java/net/jitse/npclib/nms/v1_12_R1/NPC_v1_12_R1.java b/nms/v1_12_R1/src/main/java/net/jitse/npclib/nms/v1_12_R1/NPC_v1_12_R1.java index 64350da..bd778f5 100755 --- a/nms/v1_12_R1/src/main/java/net/jitse/npclib/nms/v1_12_R1/NPC_v1_12_R1.java +++ b/nms/v1_12_R1/src/main/java/net/jitse/npclib/nms/v1_12_R1/NPC_v1_12_R1.java @@ -4,7 +4,10 @@ package net.jitse.npclib.nms.v1_12_R1; +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.properties.Property; import net.jitse.npclib.NPCLib; +import net.jitse.npclib.api.skin.Skin; import net.jitse.npclib.api.state.NPCSlot; import net.jitse.npclib.hologram.Hologram; import net.jitse.npclib.internal.MinecraftVersion; @@ -105,4 +108,19 @@ public class NPC_v1_12_R1 extends NPCBase { PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(entityId, nmsSlot, CraftItemStack.asNMSCopy(item)); playerConnection.sendPacket(packet); } + + @Override + public void updateSkin(Skin skin) { + GameProfile newProfile = new GameProfile(uuid, name); + newProfile.getProperties().get("textures").clear(); + newProfile.getProperties().put("textures", new Property("textures", skin.getValue(), skin.getSignature())); + this.packetPlayOutPlayerInfoAdd = new PacketPlayOutPlayerInfoWrapper().create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, newProfile, name); + for (Player player : Bukkit.getOnlinePlayers()) { + PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; + playerConnection.sendPacket(packetPlayOutPlayerInfoRemove); + playerConnection.sendPacket(packetPlayOutEntityDestroy); + playerConnection.sendPacket(packetPlayOutPlayerInfoAdd); + playerConnection.sendPacket(packetPlayOutNamedEntitySpawn); + } + } } diff --git a/nms/v1_13_R1/pom.xml b/nms/v1_13_R1/pom.xml index 8c2c8a6..5531578 100755 --- a/nms/v1_13_R1/pom.xml +++ b/nms/v1_13_R1/pom.xml @@ -8,7 +8,7 @@ net.jitse npclib-nms - 2.6-SNAPSHOT + 2.7-SNAPSHOT npclib-nms-v1_13_R1 diff --git a/nms/v1_13_R1/src/main/java/net/jitse/npclib/nms/v1_13_R1/NPC_v1_13_R1.java b/nms/v1_13_R1/src/main/java/net/jitse/npclib/nms/v1_13_R1/NPC_v1_13_R1.java index 0706ba4..af88de9 100755 --- a/nms/v1_13_R1/src/main/java/net/jitse/npclib/nms/v1_13_R1/NPC_v1_13_R1.java +++ b/nms/v1_13_R1/src/main/java/net/jitse/npclib/nms/v1_13_R1/NPC_v1_13_R1.java @@ -4,7 +4,10 @@ package net.jitse.npclib.nms.v1_13_R1; +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.properties.Property; import net.jitse.npclib.NPCLib; +import net.jitse.npclib.api.skin.Skin; import net.jitse.npclib.api.state.NPCSlot; import net.jitse.npclib.hologram.Hologram; import net.jitse.npclib.internal.MinecraftVersion; @@ -105,4 +108,19 @@ public class NPC_v1_13_R1 extends NPCBase { PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(entityId, nmsSlot, CraftItemStack.asNMSCopy(item)); playerConnection.sendPacket(packet); } + + @Override + public void updateSkin(Skin skin) { + GameProfile newProfile = new GameProfile(uuid, name); + newProfile.getProperties().get("textures").clear(); + newProfile.getProperties().put("textures", new Property("textures", skin.getValue(), skin.getSignature())); + this.packetPlayOutPlayerInfoAdd = new PacketPlayOutPlayerInfoWrapper().create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, newProfile, name); + for (Player player : Bukkit.getOnlinePlayers()) { + PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; + playerConnection.sendPacket(packetPlayOutPlayerInfoRemove); + playerConnection.sendPacket(packetPlayOutEntityDestroy); + playerConnection.sendPacket(packetPlayOutPlayerInfoAdd); + playerConnection.sendPacket(packetPlayOutNamedEntitySpawn); + } + } } diff --git a/nms/v1_13_R2/pom.xml b/nms/v1_13_R2/pom.xml index 655d447..10c0f26 100755 --- a/nms/v1_13_R2/pom.xml +++ b/nms/v1_13_R2/pom.xml @@ -8,7 +8,7 @@ net.jitse npclib-nms - 2.6-SNAPSHOT + 2.7-SNAPSHOT npclib-nms-v1_13_R2 diff --git a/nms/v1_13_R2/src/main/java/net/jitse/npclib/nms/v1_13_R2/NPC_v1_13_R2.java b/nms/v1_13_R2/src/main/java/net/jitse/npclib/nms/v1_13_R2/NPC_v1_13_R2.java index dc71cdb..b6fad8f 100755 --- a/nms/v1_13_R2/src/main/java/net/jitse/npclib/nms/v1_13_R2/NPC_v1_13_R2.java +++ b/nms/v1_13_R2/src/main/java/net/jitse/npclib/nms/v1_13_R2/NPC_v1_13_R2.java @@ -4,7 +4,10 @@ package net.jitse.npclib.nms.v1_13_R2; +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.properties.Property; import net.jitse.npclib.NPCLib; +import net.jitse.npclib.api.skin.Skin; import net.jitse.npclib.api.state.NPCSlot; import net.jitse.npclib.hologram.Hologram; import net.jitse.npclib.internal.MinecraftVersion; @@ -105,4 +108,19 @@ public class NPC_v1_13_R2 extends NPCBase { PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(entityId, nmsSlot, CraftItemStack.asNMSCopy(item)); playerConnection.sendPacket(packet); } + + @Override + public void updateSkin(Skin skin) { + GameProfile newProfile = new GameProfile(uuid, name); + newProfile.getProperties().get("textures").clear(); + newProfile.getProperties().put("textures", new Property("textures", skin.getValue(), skin.getSignature())); + this.packetPlayOutPlayerInfoAdd = new PacketPlayOutPlayerInfoWrapper().create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, newProfile, name); + for (Player player : Bukkit.getOnlinePlayers()) { + PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; + playerConnection.sendPacket(packetPlayOutPlayerInfoRemove); + playerConnection.sendPacket(packetPlayOutEntityDestroy); + playerConnection.sendPacket(packetPlayOutPlayerInfoAdd); + playerConnection.sendPacket(packetPlayOutNamedEntitySpawn); + } + } } diff --git a/nms/v1_14_R1/pom.xml b/nms/v1_14_R1/pom.xml index 44b2128..2e8357d 100755 --- a/nms/v1_14_R1/pom.xml +++ b/nms/v1_14_R1/pom.xml @@ -8,7 +8,7 @@ net.jitse npclib-nms - 2.6-SNAPSHOT + 2.7-SNAPSHOT npclib-nms-v1_14_R1 diff --git a/nms/v1_14_R1/src/main/java/net/jitse/npclib/nms/v1_14_R1/NPC_v1_14_R1.java b/nms/v1_14_R1/src/main/java/net/jitse/npclib/nms/v1_14_R1/NPC_v1_14_R1.java index f3eb2bc..8e36033 100755 --- a/nms/v1_14_R1/src/main/java/net/jitse/npclib/nms/v1_14_R1/NPC_v1_14_R1.java +++ b/nms/v1_14_R1/src/main/java/net/jitse/npclib/nms/v1_14_R1/NPC_v1_14_R1.java @@ -1,6 +1,9 @@ package net.jitse.npclib.nms.v1_14_R1; +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.properties.Property; import net.jitse.npclib.NPCLib; +import net.jitse.npclib.api.skin.Skin; import net.jitse.npclib.api.state.NPCSlot; import net.jitse.npclib.hologram.Hologram; import net.jitse.npclib.internal.MinecraftVersion; @@ -101,4 +104,19 @@ public class NPC_v1_14_R1 extends NPCBase { PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(entityId, nmsSlot, CraftItemStack.asNMSCopy(item)); playerConnection.sendPacket(packet); } + + @Override + public void updateSkin(Skin skin) { + GameProfile newProfile = new GameProfile(uuid, name); + newProfile.getProperties().get("textures").clear(); + newProfile.getProperties().put("textures", new Property("textures", skin.getValue(), skin.getSignature())); + this.packetPlayOutPlayerInfoAdd = new PacketPlayOutPlayerInfoWrapper().create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, newProfile, name); + for (Player player : Bukkit.getOnlinePlayers()) { + PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; + playerConnection.sendPacket(packetPlayOutPlayerInfoRemove); + playerConnection.sendPacket(packetPlayOutEntityDestroy); + playerConnection.sendPacket(packetPlayOutPlayerInfoAdd); + playerConnection.sendPacket(packetPlayOutNamedEntitySpawn); + } + } } diff --git a/nms/v1_15_R1/pom.xml b/nms/v1_15_R1/pom.xml index 3401c6e..5eb8842 100644 --- a/nms/v1_15_R1/pom.xml +++ b/nms/v1_15_R1/pom.xml @@ -8,7 +8,7 @@ net.jitse npclib-nms - 2.6-SNAPSHOT + 2.7-SNAPSHOT npclib-nms-v1_15_R1 diff --git a/nms/v1_15_R1/src/main/java/net/jitse/npclib/nms/v1_15_R1/NPC_v1_15_R1.java b/nms/v1_15_R1/src/main/java/net/jitse/npclib/nms/v1_15_R1/NPC_v1_15_R1.java index 6afe00f..044b54a 100644 --- a/nms/v1_15_R1/src/main/java/net/jitse/npclib/nms/v1_15_R1/NPC_v1_15_R1.java +++ b/nms/v1_15_R1/src/main/java/net/jitse/npclib/nms/v1_15_R1/NPC_v1_15_R1.java @@ -1,6 +1,9 @@ package net.jitse.npclib.nms.v1_15_R1; +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.properties.Property; import net.jitse.npclib.NPCLib; +import net.jitse.npclib.api.skin.Skin; import net.jitse.npclib.api.state.NPCSlot; import net.jitse.npclib.hologram.Hologram; import net.jitse.npclib.internal.MinecraftVersion; @@ -102,4 +105,19 @@ public class NPC_v1_15_R1 extends NPCBase { PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(entityId, nmsSlot, CraftItemStack.asNMSCopy(item)); playerConnection.sendPacket(packet); } + + @Override + public void updateSkin(Skin skin) { + GameProfile newProfile = new GameProfile(uuid, name); + newProfile.getProperties().get("textures").clear(); + newProfile.getProperties().put("textures", new Property("textures", skin.getValue(), skin.getSignature())); + this.packetPlayOutPlayerInfoAdd = new PacketPlayOutPlayerInfoWrapper().create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, newProfile, name); + for (Player player : Bukkit.getOnlinePlayers()) { + PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; + playerConnection.sendPacket(packetPlayOutPlayerInfoRemove); + playerConnection.sendPacket(packetPlayOutEntityDestroy); + playerConnection.sendPacket(packetPlayOutPlayerInfoAdd); + playerConnection.sendPacket(packetPlayOutNamedEntitySpawn); + } + } } diff --git a/nms/v1_8_R2/pom.xml b/nms/v1_8_R2/pom.xml index 8ccbee6..3a5b208 100755 --- a/nms/v1_8_R2/pom.xml +++ b/nms/v1_8_R2/pom.xml @@ -8,7 +8,7 @@ net.jitse npclib-nms - 2.6-SNAPSHOT + 2.7-SNAPSHOT npclib-nms-v1_8_R2 diff --git a/nms/v1_8_R2/src/main/java/net/jitse/npclib/nms/v1_8_R2/NPC_v1_8_R2.java b/nms/v1_8_R2/src/main/java/net/jitse/npclib/nms/v1_8_R2/NPC_v1_8_R2.java index 8b3eabd..bfea259 100755 --- a/nms/v1_8_R2/src/main/java/net/jitse/npclib/nms/v1_8_R2/NPC_v1_8_R2.java +++ b/nms/v1_8_R2/src/main/java/net/jitse/npclib/nms/v1_8_R2/NPC_v1_8_R2.java @@ -4,7 +4,10 @@ package net.jitse.npclib.nms.v1_8_R2; +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.properties.Property; import net.jitse.npclib.NPCLib; +import net.jitse.npclib.api.skin.Skin; import net.jitse.npclib.api.state.NPCSlot; import net.jitse.npclib.hologram.Hologram; import net.jitse.npclib.internal.MinecraftVersion; @@ -110,4 +113,19 @@ public class NPC_v1_8_R2 extends NPCBase { PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(entityId, slot.getSlot(), CraftItemStack.asNMSCopy(item)); playerConnection.sendPacket(packet); } + + @Override + public void updateSkin(Skin skin) { + GameProfile newProfile = new GameProfile(uuid, name); + newProfile.getProperties().get("textures").clear(); + newProfile.getProperties().put("textures", new Property("textures", skin.getValue(), skin.getSignature())); + this.packetPlayOutPlayerInfoAdd = new PacketPlayOutPlayerInfoWrapper().create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, newProfile, name); + for (Player player : Bukkit.getOnlinePlayers()) { + PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; + playerConnection.sendPacket(packetPlayOutPlayerInfoRemove); + playerConnection.sendPacket(packetPlayOutEntityDestroy); + playerConnection.sendPacket(packetPlayOutPlayerInfoAdd); + playerConnection.sendPacket(packetPlayOutNamedEntitySpawn); + } + } } diff --git a/nms/v1_8_R3/pom.xml b/nms/v1_8_R3/pom.xml index f41711a..ba2c4b3 100755 --- a/nms/v1_8_R3/pom.xml +++ b/nms/v1_8_R3/pom.xml @@ -8,7 +8,7 @@ net.jitse npclib-nms - 2.6-SNAPSHOT + 2.7-SNAPSHOT npclib-nms-v1_8_R3 diff --git a/nms/v1_8_R3/src/main/java/net/jitse/npclib/nms/v1_8_R3/NPC_v1_8_R3.java b/nms/v1_8_R3/src/main/java/net/jitse/npclib/nms/v1_8_R3/NPC_v1_8_R3.java index e961e3c..c1909e7 100755 --- a/nms/v1_8_R3/src/main/java/net/jitse/npclib/nms/v1_8_R3/NPC_v1_8_R3.java +++ b/nms/v1_8_R3/src/main/java/net/jitse/npclib/nms/v1_8_R3/NPC_v1_8_R3.java @@ -4,7 +4,10 @@ package net.jitse.npclib.nms.v1_8_R3; +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.properties.Property; import net.jitse.npclib.NPCLib; +import net.jitse.npclib.api.skin.Skin; import net.jitse.npclib.api.state.NPCSlot; import net.jitse.npclib.hologram.Hologram; import net.jitse.npclib.internal.MinecraftVersion; @@ -111,4 +114,19 @@ public class NPC_v1_8_R3 extends NPCBase { PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(entityId, slot.getSlot(), CraftItemStack.asNMSCopy(item)); playerConnection.sendPacket(packet); } + + @Override + public void updateSkin(Skin skin) { + GameProfile newProfile = new GameProfile(uuid, name); + newProfile.getProperties().get("textures").clear(); + newProfile.getProperties().put("textures", new Property("textures", skin.getValue(), skin.getSignature())); + this.packetPlayOutPlayerInfoAdd = new PacketPlayOutPlayerInfoWrapper().create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, newProfile, name); + for (Player player : Bukkit.getOnlinePlayers()) { + PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; + playerConnection.sendPacket(packetPlayOutPlayerInfoRemove); + playerConnection.sendPacket(packetPlayOutEntityDestroy); + playerConnection.sendPacket(packetPlayOutPlayerInfoAdd); + playerConnection.sendPacket(packetPlayOutNamedEntitySpawn); + } + } } diff --git a/nms/v1_9_R1/pom.xml b/nms/v1_9_R1/pom.xml index d400946..37fe2b9 100755 --- a/nms/v1_9_R1/pom.xml +++ b/nms/v1_9_R1/pom.xml @@ -8,7 +8,7 @@ net.jitse npclib-nms - 2.6-SNAPSHOT + 2.7-SNAPSHOT npclib-nms-v1_9_R1 diff --git a/nms/v1_9_R1/src/main/java/net/jitse/npclib/nms/v1_9_R1/NPC_v1_9_R1.java b/nms/v1_9_R1/src/main/java/net/jitse/npclib/nms/v1_9_R1/NPC_v1_9_R1.java index 3447b75..042e13f 100755 --- a/nms/v1_9_R1/src/main/java/net/jitse/npclib/nms/v1_9_R1/NPC_v1_9_R1.java +++ b/nms/v1_9_R1/src/main/java/net/jitse/npclib/nms/v1_9_R1/NPC_v1_9_R1.java @@ -4,7 +4,10 @@ package net.jitse.npclib.nms.v1_9_R1; +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.properties.Property; import net.jitse.npclib.NPCLib; +import net.jitse.npclib.api.skin.Skin; import net.jitse.npclib.api.state.NPCSlot; import net.jitse.npclib.hologram.Hologram; import net.jitse.npclib.internal.MinecraftVersion; @@ -105,4 +108,19 @@ public class NPC_v1_9_R1 extends NPCBase { PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(entityId, nmsSlot, CraftItemStack.asNMSCopy(item)); playerConnection.sendPacket(packet); } + + @Override + public void updateSkin(Skin skin) { + GameProfile newProfile = new GameProfile(uuid, name); + newProfile.getProperties().get("textures").clear(); + newProfile.getProperties().put("textures", new Property("textures", skin.getValue(), skin.getSignature())); + this.packetPlayOutPlayerInfoAdd = new PacketPlayOutPlayerInfoWrapper().create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, newProfile, name); + for (Player player : Bukkit.getOnlinePlayers()) { + PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; + playerConnection.sendPacket(packetPlayOutPlayerInfoRemove); + playerConnection.sendPacket(packetPlayOutEntityDestroy); + playerConnection.sendPacket(packetPlayOutPlayerInfoAdd); + playerConnection.sendPacket(packetPlayOutNamedEntitySpawn); + } + } } diff --git a/nms/v1_9_R2/pom.xml b/nms/v1_9_R2/pom.xml index 10379bf..5bc4b3b 100755 --- a/nms/v1_9_R2/pom.xml +++ b/nms/v1_9_R2/pom.xml @@ -8,7 +8,7 @@ net.jitse npclib-nms - 2.6-SNAPSHOT + 2.7-SNAPSHOT npclib-nms-v1_9_R2 diff --git a/nms/v1_9_R2/src/main/java/net/jitse/npclib/nms/v1_9_R2/NPC_v1_9_R2.java b/nms/v1_9_R2/src/main/java/net/jitse/npclib/nms/v1_9_R2/NPC_v1_9_R2.java index bc0fea6..8eb9dd4 100755 --- a/nms/v1_9_R2/src/main/java/net/jitse/npclib/nms/v1_9_R2/NPC_v1_9_R2.java +++ b/nms/v1_9_R2/src/main/java/net/jitse/npclib/nms/v1_9_R2/NPC_v1_9_R2.java @@ -4,7 +4,10 @@ package net.jitse.npclib.nms.v1_9_R2; +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.properties.Property; import net.jitse.npclib.NPCLib; +import net.jitse.npclib.api.skin.Skin; import net.jitse.npclib.api.state.NPCSlot; import net.jitse.npclib.hologram.Hologram; import net.jitse.npclib.internal.MinecraftVersion; @@ -105,4 +108,19 @@ public class NPC_v1_9_R2 extends NPCBase { PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(entityId, nmsSlot, CraftItemStack.asNMSCopy(item)); playerConnection.sendPacket(packet); } + + @Override + public void updateSkin(Skin skin) { + GameProfile newProfile = new GameProfile(uuid, name); + newProfile.getProperties().get("textures").clear(); + newProfile.getProperties().put("textures", new Property("textures", skin.getValue(), skin.getSignature())); + this.packetPlayOutPlayerInfoAdd = new PacketPlayOutPlayerInfoWrapper().create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, newProfile, name); + for (Player player : Bukkit.getOnlinePlayers()) { + PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; + playerConnection.sendPacket(packetPlayOutPlayerInfoRemove); + playerConnection.sendPacket(packetPlayOutEntityDestroy); + playerConnection.sendPacket(packetPlayOutPlayerInfoAdd); + playerConnection.sendPacket(packetPlayOutNamedEntitySpawn); + } + } } diff --git a/plugin/pom.xml b/plugin/pom.xml index d0f0b2d..7fa7944 100644 --- a/plugin/pom.xml +++ b/plugin/pom.xml @@ -8,7 +8,7 @@ net.jitse npclib - 2.6-SNAPSHOT + 2.7-SNAPSHOT npclib-plugin diff --git a/pom.xml b/pom.xml index eba84fc..c705314 100755 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ net.jitse npclib - 2.6-SNAPSHOT + 2.7-SNAPSHOT UTF-8