diff --git a/api/src/main/java/net/techcable/npclib/nms/NMS.java b/api/src/main/java/net/techcable/npclib/nms/NMS.java
index ac0dba7..ce8d533 100644
--- a/api/src/main/java/net/techcable/npclib/nms/NMS.java
+++ b/api/src/main/java/net/techcable/npclib/nms/NMS.java
@@ -5,8 +5,6 @@
import net.techcable.npclib.NPC;
-import net.techcable.npclib.nms.skins.RateLimitedException;
-import net.techcable.npclib.util.ProfileUtils;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
@@ -18,19 +16,6 @@ public interface NMS {
public boolean isSupported(OptionalFeature feature);
public void look(Entity entity, float pitch, float yaw);
public Player spawnPlayer(Location toSpawn, String name, NPC npc);
-
- /**
- * Sets the skin of the npc
- *
- *
- * It is up to the implementation to choose whether or not to refresh the player's skin
- *
- *
- * @param npc the npc to set the skin of
- * @param skinProfile the npc's new skin
- * @return true if the npc is needed to respawn
- */
- public boolean setSkin(NPC npc, ProfileUtils.PlayerProfile skinProfile);
public NPC getAsNPC(Entity entity);
public void notifyOfEquipmentChange(Player[] toNotify, Player npc, int... slot);
diff --git a/api/src/main/java/net/techcable/npclib/nms/skins/RateLimitedException.java b/api/src/main/java/net/techcable/npclib/nms/skins/RateLimitedException.java
deleted file mode 100644
index 7b43ec0..0000000
--- a/api/src/main/java/net/techcable/npclib/nms/skins/RateLimitedException.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package net.techcable.npclib.nms.skins;
-
-public class RateLimitedException extends Exception {
-}
diff --git a/api/src/main/java/net/techcable/npclib/util/ProfileUtils.java b/api/src/main/java/net/techcable/npclib/util/ProfileUtils.java
index 59264b8..3ea1039 100644
--- a/api/src/main/java/net/techcable/npclib/util/ProfileUtils.java
+++ b/api/src/main/java/net/techcable/npclib/util/ProfileUtils.java
@@ -14,7 +14,6 @@
import java.util.Map;
import java.util.UUID;
-import net.techcable.npclib.nms.skins.RateLimitedException;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
@@ -61,7 +60,7 @@ public static PlayerProfile lookup(String name) {
* @param id look for a profile with this uuid
* @return a profile with the given id
*/
- public static PlayerProfile lookup(UUID id) throws RateLimitedException {
+ public static PlayerProfile lookup(UUID id) {
return lookupProperties(id);
}
@@ -134,15 +133,11 @@ private static List postNames(String[] names) { //This one doesn'
return profiles;
}
- private static PlayerProfile lookupProperties(UUID id) throws RateLimitedException {
+ private static PlayerProfile lookupProperties(UUID id) {
if (idCache.contains(id)) return idCache.get(id);
Object rawResponse = getJson("https://sessionserver.mojang.com/session/minecraft/profile/" + id.toString().replace("-", ""));
if (rawResponse == null || !(rawResponse instanceof JSONObject)) return null;
JSONObject response = (JSONObject) rawResponse;
- if (response.containsKey("errror")) {
- if (response.get("error").equals("TooManyRequestsException")) throw new RateLimitedException();
- return null;
- }
PlayerProfile profile = deserializeProfile(response);
if (profile == null) return null;
idCache.put(id, profile);
@@ -188,6 +183,7 @@ private static Object getJson(String rawUrl) {
URL url = new URL(rawUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
+
reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
StringBuffer result = new StringBuffer();
String line;
diff --git a/api/src/main/java/net/techcable/npclib/util/ReflectUtil.java b/api/src/main/java/net/techcable/npclib/util/ReflectUtil.java
index 70a3f1d..9ae3d1b 100644
--- a/api/src/main/java/net/techcable/npclib/util/ReflectUtil.java
+++ b/api/src/main/java/net/techcable/npclib/util/ReflectUtil.java
@@ -27,15 +27,6 @@ public static void setField(Field field, Object objToSet, Object value) {
throw new RuntimeException(e);
}
}
-
- public static T getField(Field field, Object objToSet) {
- field.setAccessible(true);
- try {
- return (T) field.get(objToSet);
- } catch (IllegalArgumentException | IllegalAccessException e) {
- throw new RuntimeException(e);
- }
- }
public static Method makeMethod(Class> clazz, String methodName, Class>... paramaters) {
try {
diff --git a/nms-v1_7_R3/src/main/java/net/techcable/npclib/nms/versions/v1_7_R3/EntityNPCPlayer.java b/nms-v1_7_R3/src/main/java/net/techcable/npclib/nms/versions/v1_7_R3/EntityNPCPlayer.java
index 3cd49c9..b8371d9 100644
--- a/nms-v1_7_R3/src/main/java/net/techcable/npclib/nms/versions/v1_7_R3/EntityNPCPlayer.java
+++ b/nms-v1_7_R3/src/main/java/net/techcable/npclib/nms/versions/v1_7_R3/EntityNPCPlayer.java
@@ -2,12 +2,15 @@
import java.util.UUID;
-import net.minecraft.server.v1_7_R3.*;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer;
+import net.minecraft.server.v1_7_R3.DamageSource;
+import net.minecraft.server.v1_7_R3.EntityPlayer;
+import net.minecraft.server.v1_7_R3.EnumGamemode;
+import net.minecraft.server.v1_7_R3.PlayerInteractManager;
import net.minecraft.util.com.mojang.authlib.GameProfile;
import net.minecraft.util.com.mojang.authlib.properties.Property;
import net.techcable.npclib.NPC;
@@ -17,8 +20,8 @@
@Getter
public class EntityNPCPlayer extends EntityPlayer {
private final NPC npc;
- public EntityNPCPlayer(NPC npc, String name, Location location, GameProfile profile) {
- super(NMS.getServer(), NMS.getHandle(location.getWorld()), profile, new PlayerInteractManager(NMS.getHandle(location.getWorld())));
+ public EntityNPCPlayer(NPC npc, String name, Location location) {
+ super(NMS.getServer(), NMS.getHandle(location.getWorld()), makeProfile(name, npc.getSkin()), new PlayerInteractManager(NMS.getHandle(location.getWorld())));
playerInteractManager.b(EnumGamemode.SURVIVAL); //MCP = initializeGameType
this.npc = npc;
playerConnection = new NPCConnection(this);
@@ -33,4 +36,17 @@ public boolean damageEntity(DamageSource source, float damage) {
}
return super.damageEntity(source, damage);
}
+ public static GameProfile makeProfile(String name, UUID skinId) {
+ GameProfile profile = new GameProfile(UUID.randomUUID(), name);
+ if (skinId != null) {
+ GameProfile skin = new GameProfile(skinId, null);
+ skin = NMS.getServer().av().fillProfileProperties(skin, true); //Srg = func_147130_as
+ if (skin.getProperties().get("textures") == null || !skin.getProperties().get("textures").isEmpty()) {
+ Property textures = skin.getProperties().get("textures").iterator().next();
+ profile.getProperties().put("textures", textures);
+ }
+ }
+ return profile;
+ }
+
}
\ No newline at end of file
diff --git a/nms-v1_7_R3/src/main/java/net/techcable/npclib/nms/versions/v1_7_R3/NMS.java b/nms-v1_7_R3/src/main/java/net/techcable/npclib/nms/versions/v1_7_R3/NMS.java
index 9df8a73..8189c0f 100644
--- a/nms-v1_7_R3/src/main/java/net/techcable/npclib/nms/versions/v1_7_R3/NMS.java
+++ b/nms-v1_7_R3/src/main/java/net/techcable/npclib/nms/versions/v1_7_R3/NMS.java
@@ -1,14 +1,25 @@
package net.techcable.npclib.nms.versions.v1_7_R3;
import java.lang.reflect.Field;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.UUID;
-import net.minecraft.server.v1_7_R3.*;
+import net.minecraft.server.v1_7_R3.ChunkCoordinates;
+import net.minecraft.server.v1_7_R3.Entity;
+import net.minecraft.server.v1_7_R3.EntityHuman;
+import net.minecraft.server.v1_7_R3.EntityLiving;
+import net.minecraft.server.v1_7_R3.EntityPlayer;
+import net.minecraft.server.v1_7_R3.IChatBaseComponent;
+import net.minecraft.server.v1_7_R3.MinecraftServer;
+import net.minecraft.server.v1_7_R3.Packet;
+import net.minecraft.server.v1_7_R3.PacketPlayOutEntityEquipment;
+import net.minecraft.server.v1_7_R3.World;
+import net.minecraft.server.v1_7_R3.WorldServer;
import net.minecraft.util.com.mojang.authlib.GameProfile;
-import net.minecraft.util.com.mojang.authlib.properties.Property;
import net.techcable.npclib.NPC;
import net.techcable.npclib.nms.OptionalFeature;
-import net.techcable.npclib.util.ProfileUtils;
import net.techcable.npclib.util.ReflectUtil;
import org.bukkit.Bukkit;
@@ -21,8 +32,6 @@
import org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
-import org.json.simple.JSONArray;
-import org.json.simple.JSONObject;
public class NMS implements net.techcable.npclib.nms.NMS {
@@ -65,42 +74,16 @@ public static void setHeadYaw(Entity entity, float yaw) {
handle.aM = yaw; //MCP = renderYawOffset
handle.aP = yaw; //MCP = prevRotationYawHead
}
-
- private Map profileMap = new HashMap<>();
+
@Override
public Player spawnPlayer(Location toSpawn, String name, NPC npc) {
- GameProfile profile = profileMap.get(npc.getUUID());
- if (profile == null) profile = new GameProfile(npc.getUUID(), npc.getName());
- EntityNPCPlayer player = new EntityNPCPlayer(npc, name, toSpawn, profile);
- profileMap.remove(npc.getUUID());
- WorldServer world = getHandle(toSpawn.getWorld());
+ EntityNPCPlayer player = new EntityNPCPlayer(npc, name, toSpawn);
+ WorldServer world = getHandle(toSpawn.getWorld());
world.addEntity(player);
look(player.getBukkitEntity(), toSpawn.getPitch(), toSpawn.getYaw());
return player.getBukkitEntity();
}
-
- @Override
- public boolean setSkin(NPC npc, ProfileUtils.PlayerProfile skinProfile) {
- GameProfile profile = makeProfile(npc, skinProfile);
- profileMap.put(npc.getUUID(), profile);
- return true;
- }
-
- private static GameProfile makeProfile(NPC npc, ProfileUtils.PlayerProfile skinProfile) {
- GameProfile profile = new GameProfile(npc.getUUID(), npc.getName());
- if (skinProfile.getProperties() != null) {
- for (Object obj : skinProfile.getProperties()) {
- JSONObject jsonProperty = (JSONObject) obj;
- String name = (String) jsonProperty.get("name");
- String value = (String) jsonProperty.get("value");
- String signature = jsonProperty.containsKey("signature") ? (String) jsonProperty.get("signature") : null;
- Property property = signature == null ? new Property(name, value) : new Property(name, value, signature);
- profile.getProperties().put(name, property);
- }
- }
- return profile;
- }
-
+
public static Entity getHandle(org.bukkit.entity.Entity bukkitEntity) {
if (!(bukkitEntity instanceof CraftEntity))
return null;
diff --git a/nms-v1_7_R4/pom.xml b/nms-v1_7_R4/pom.xml
index c0b8c19..1f13edb 100644
--- a/nms-v1_7_R4/pom.xml
+++ b/nms-v1_7_R4/pom.xml
@@ -13,13 +13,6 @@
nms-v1_7_R4
-
-
- org.bukkit
- bukkit
- 1.7.10-R0.1-SNAPSHOT
- provided
-
net.techcable.npclib
api
diff --git a/nms-v1_7_R4/src/main/java/net/techcable/npclib/nms/versions/v1_7_R4/EntityNPCPlayer.java b/nms-v1_7_R4/src/main/java/net/techcable/npclib/nms/versions/v1_7_R4/EntityNPCPlayer.java
index 624ab6b..cad3679 100644
--- a/nms-v1_7_R4/src/main/java/net/techcable/npclib/nms/versions/v1_7_R4/EntityNPCPlayer.java
+++ b/nms-v1_7_R4/src/main/java/net/techcable/npclib/nms/versions/v1_7_R4/EntityNPCPlayer.java
@@ -20,8 +20,8 @@
@Getter
public class EntityNPCPlayer extends EntityPlayer {
private final NPC npc;
- public EntityNPCPlayer(NPC npc, GameProfile profile, Location location) {
- super(NMS.getServer(), NMS.getHandle(location.getWorld()), profile, new PlayerInteractManager(NMS.getHandle(location.getWorld())));
+ public EntityNPCPlayer(NPC npc, String name, Location location) {
+ super(NMS.getServer(), NMS.getHandle(location.getWorld()), makeProfile(name, npc.getSkin()), new PlayerInteractManager(NMS.getHandle(location.getWorld())));
playerInteractManager.b(EnumGamemode.SURVIVAL); //MCP = initializeGameType
this.npc = npc;
playerConnection = new NPCConnection(this);
@@ -36,4 +36,17 @@ public boolean damageEntity(DamageSource source, float damage) {
}
return super.damageEntity(source, damage);
}
+
+ public static GameProfile makeProfile(String name, UUID skinId) {
+ GameProfile profile = new GameProfile(UUID.randomUUID(), name);
+ if (skinId != null) {
+ GameProfile skin = new GameProfile(skinId, null);
+ skin = NMS.getServer().av().fillProfileProperties(skin, true); //Srg = func_147130_as
+ if (skin.getProperties().get("textures") == null || !skin.getProperties().get("textures").isEmpty()) {
+ Property textures = skin.getProperties().get("textures").iterator().next();
+ profile.getProperties().put("textures", textures);
+ }
+ }
+ return profile;
+ }
}
diff --git a/nms-v1_7_R4/src/main/java/net/techcable/npclib/nms/versions/v1_7_R4/NMS.java b/nms-v1_7_R4/src/main/java/net/techcable/npclib/nms/versions/v1_7_R4/NMS.java
index 5e85b4b..0855d52 100644
--- a/nms-v1_7_R4/src/main/java/net/techcable/npclib/nms/versions/v1_7_R4/NMS.java
+++ b/nms-v1_7_R4/src/main/java/net/techcable/npclib/nms/versions/v1_7_R4/NMS.java
@@ -1,7 +1,10 @@
package net.techcable.npclib.nms.versions.v1_7_R4;
import java.lang.reflect.Field;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.UUID;
import net.minecraft.server.v1_7_R4.ChunkCoordinates;
import net.minecraft.server.v1_7_R4.Entity;
@@ -18,10 +21,8 @@
import net.minecraft.util.com.google.common.base.Predicate;
import net.minecraft.util.com.google.common.collect.Collections2;
import net.minecraft.util.com.mojang.authlib.GameProfile;
-import net.minecraft.util.com.mojang.authlib.properties.Property;
import net.techcable.npclib.NPC;
import net.techcable.npclib.nms.OptionalFeature;
-import net.techcable.npclib.util.ProfileUtils;
import net.techcable.npclib.util.ReflectUtil;
import org.bukkit.Bukkit;
@@ -35,7 +36,6 @@
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
-import org.json.simple.JSONObject;
public class NMS implements net.techcable.npclib.nms.NMS {
@@ -78,44 +78,19 @@ public static void setHeadYaw(Entity entity, float yaw) {
handle.aM = yaw; //MCP = renderYawOffset
handle.aP = yaw; //MCP = prevRotationYawHead
}
-
- private Map profileMap = new HashMap<>();
+
@Override
public Player spawnPlayer(Location toSpawn, String name, NPC npc) {
- GameProfile profile = profileMap.get(npc.getUUID()) != null ? profileMap.get(npc.getUUID()) : new GameProfile(npc.getUUID(), npc.getName());
- EntityNPCPlayer player = new EntityNPCPlayer(npc, profile, toSpawn);
+ EntityNPCPlayer player = new EntityNPCPlayer(npc, name, toSpawn);
if (ProtocolHack.isProtocolHack()) {
ProtocolHack.notifyOfSpawn(Bukkit.getOnlinePlayers(), player.getBukkitEntity());
}
WorldServer world = getHandle(toSpawn.getWorld());
- world.addEntity(player);
+ world.addEntity(player);
look(player.getBukkitEntity(), toSpawn.getPitch(), toSpawn.getYaw());
return player.getBukkitEntity();
}
-
- @Override
- public boolean setSkin(NPC npc, ProfileUtils.PlayerProfile skinProfile) {
- GameProfile profile = makeProfile(npc, skinProfile);
- profileMap.put(npc.getUUID(), profile);
- return true;
- }
-
- private static GameProfile makeProfile(NPC npc, ProfileUtils.PlayerProfile skinProfile) {
- GameProfile profile = new GameProfile(npc.getUUID(), npc.getName());
- if (skinProfile.getProperties() != null) {
- for (Object obj : skinProfile.getProperties()) {
- JSONObject jsonProperty = (JSONObject) obj;
- String name = (String) jsonProperty.get("name");
- String value = (String) jsonProperty.get("value");
- String signature = jsonProperty.containsKey("signature") ? (String) jsonProperty.get("signature") : null;
- Property property = signature == null ? new Property(name, value) : new Property(name, value, signature);
- profile.getProperties().put(name, property);
- }
- }
- return profile;
- }
-
-
+
public static Entity getHandle(org.bukkit.entity.Entity bukkitEntity) {
if (!(bukkitEntity instanceof CraftEntity))
return null;
@@ -213,7 +188,7 @@ public Player apply(NPC npc) {
return (Player) npc.getEntity();
}
});
- ProtocolHack.notifyOfSpawn(Arrays.asList(joined), npcEntities.toArray(new Player[npcEntities.size()]));
+ ProtocolHack.notifyOfSpawn(new Player[] {joined}, npcEntities.toArray(new Player[npcEntities.size()]));
}
}
diff --git a/nms-v1_7_R4/src/main/java/net/techcable/npclib/nms/versions/v1_7_R4/ProtocolHack.java b/nms-v1_7_R4/src/main/java/net/techcable/npclib/nms/versions/v1_7_R4/ProtocolHack.java
index 9c9ffc2..61670c0 100644
--- a/nms-v1_7_R4/src/main/java/net/techcable/npclib/nms/versions/v1_7_R4/ProtocolHack.java
+++ b/nms-v1_7_R4/src/main/java/net/techcable/npclib/nms/versions/v1_7_R4/ProtocolHack.java
@@ -1,8 +1,6 @@
package net.techcable.npclib.nms.versions.v1_7_R4;
import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.Collection;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
import org.bukkit.entity.Player;
@@ -19,13 +17,11 @@ private static EntityPlayer getHandle(Player bukkitPlayer) {
return ((CraftPlayer)bukkitPlayer).getHandle();
}
- private static EntityPlayer[] getHandles(Collection extends Player> bukkitPlayers) {
- EntityPlayer[] handles = new EntityPlayer[bukkitPlayers.size()];
- int i = 0;
- for (Player bukkitPlayer : bukkitPlayers) {
- handles[i] = getHandle(bukkitPlayer);
- i++;
- }
+ private static EntityPlayer[] getHandles(Player[] bukkitPlayers) {
+ EntityPlayer[] handles = new EntityPlayer[bukkitPlayers.length];
+ for (int i = 0; i < bukkitPlayers.length; i++) {
+ handles[i] = getHandle(bukkitPlayers[i]);
+ }
return handles;
}
@@ -38,9 +34,9 @@ public static boolean isProtocolHack() {
}
}
- public static void notifyOfSpawn(Collection extends Player> toNotify, Player... npcs) {
+ public static void notifyOfSpawn(Player[] toNotify, Player... npcs) {
Method addPlayer = ReflectUtil.makeMethod(getPlayerInfoClass(), "addPlayer", EntityPlayer.class);
- EntityPlayer[] handles = getHandles(Arrays.asList(npcs));
+ EntityPlayer[] handles = getHandles(npcs);
Packet[] packets = new Packet[handles.length];
for (int i = 0; i < handles.length; i++) {
EntityPlayer handle = handles[i];
@@ -50,9 +46,9 @@ public static void notifyOfSpawn(Collection extends Player> toNotify, Player..
sendPacketsTo(toNotify, packets);
}
- public static void notifyOfDespawn(Collection extends Player> toNotify, Player... npcs) {
+ public static void notifyOfDespawn(Player[] toNotify, Player... npcs) {
Method removePlayer = ReflectUtil.makeMethod(getPlayerInfoClass(), "removePlayer", EntityPlayer.class);
- EntityPlayer[] handles = getHandles(Arrays.asList(npcs));
+ EntityPlayer[] handles = getHandles(npcs);
Packet[] packets = new Packet[handles.length];
for (int i = 0; i < handles.length; i++) {
EntityPlayer handle = handles[i];
@@ -70,7 +66,7 @@ public static Class > getPlayerInfoClass() {
}
}
- public static void sendPacketsTo(Collection extends Player> recipients, Packet... packets) {
+ public static void sendPacketsTo(Player[] recipients, Packet... packets) {
EntityPlayer[] nmsRecipients = getHandles(recipients);
for (EntityPlayer recipient : nmsRecipients) {
if (recipient == null) continue;
diff --git a/nms-v1_8_R1/src/main/java/net/techcable/npclib/nms/versions/v1_8_R1/EntityNPCPlayer.java b/nms-v1_8_R1/src/main/java/net/techcable/npclib/nms/versions/v1_8_R1/EntityNPCPlayer.java
index 4fe278c..321ee7c 100644
--- a/nms-v1_8_R1/src/main/java/net/techcable/npclib/nms/versions/v1_8_R1/EntityNPCPlayer.java
+++ b/nms-v1_8_R1/src/main/java/net/techcable/npclib/nms/versions/v1_8_R1/EntityNPCPlayer.java
@@ -22,8 +22,8 @@
@Getter
public class EntityNPCPlayer extends EntityPlayer {
private final NPC npc;
- public EntityNPCPlayer(NPC npc, GameProfile profile, Location location) {
- super(NMS.getServer(), NMS.getHandle(location.getWorld()), profile, new PlayerInteractManager(NMS.getHandle(location.getWorld())));
+ public EntityNPCPlayer(NPC npc, String name, Location location) {
+ super(NMS.getServer(), NMS.getHandle(location.getWorld()), makeProfile(name, npc.getSkin()), new PlayerInteractManager(NMS.getHandle(location.getWorld())));
playerInteractManager.b(EnumGamemode.SURVIVAL); //MCP = initializeGameType ---- SRG=func_73077_b
this.npc = npc;
playerConnection = new NPCConnection(this);
@@ -38,4 +38,17 @@ public boolean damageEntity(DamageSource source, float damage) {
}
return super.damageEntity(source, damage);
}
+
+ public static GameProfile makeProfile(String name, UUID skinId) {
+ GameProfile profile = new GameProfile(UUID.randomUUID(), name);
+ if (skinId != null) {
+ GameProfile skin = new GameProfile(skinId, null);
+ skin = NMS.getServer().aB().fillProfileProperties(skin, true); //Srg = func_147130_as
+ if (skin.getProperties().get("textures") == null || !skin.getProperties().get("textures").isEmpty()) {
+ Property textures = skin.getProperties().get("textures").iterator().next();
+ profile.getProperties().put("textures", textures);
+ }
+ }
+ return profile;
+ }
}
diff --git a/nms-v1_8_R1/src/main/java/net/techcable/npclib/nms/versions/v1_8_R1/NMS.java b/nms-v1_8_R1/src/main/java/net/techcable/npclib/nms/versions/v1_8_R1/NMS.java
index 96a290d..c59d9ad 100644
--- a/nms-v1_8_R1/src/main/java/net/techcable/npclib/nms/versions/v1_8_R1/NMS.java
+++ b/nms-v1_8_R1/src/main/java/net/techcable/npclib/nms/versions/v1_8_R1/NMS.java
@@ -3,11 +3,20 @@
import java.lang.reflect.Field;
import java.util.*;
-import com.mojang.authlib.properties.Property;
-import net.minecraft.server.v1_8_R1.*;
+import net.minecraft.server.v1_8_R1.Entity;
+import net.minecraft.server.v1_8_R1.EntityHuman;
+import net.minecraft.server.v1_8_R1.EntityLiving;
+import net.minecraft.server.v1_8_R1.EntityPlayer;
+import net.minecraft.server.v1_8_R1.EnumPlayerInfoAction;
+import net.minecraft.server.v1_8_R1.IChatBaseComponent;
+import net.minecraft.server.v1_8_R1.MinecraftServer;
+import net.minecraft.server.v1_8_R1.Packet;
+import net.minecraft.server.v1_8_R1.PacketPlayOutPlayerInfo;
+import net.minecraft.server.v1_8_R1.PacketPlayOutEntityEquipment;
+import net.minecraft.server.v1_8_R1.World;
+import net.minecraft.server.v1_8_R1.WorldServer;
import net.techcable.npclib.NPC;
import net.techcable.npclib.nms.OptionalFeature;
-import net.techcable.npclib.util.ProfileUtils;
import net.techcable.npclib.util.ReflectUtil;
import com.google.common.base.Function;
@@ -26,7 +35,6 @@
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
-import org.json.simple.JSONObject;
public class NMS implements net.techcable.npclib.nms.NMS {
@@ -69,11 +77,10 @@ public static void setHeadYaw(Entity entity, float yaw) {
handle.aG = yaw; //MCP = renderYawOffset ---- SRG=field_70761_aq
handle.aJ = yaw; //MCP = prevRotationYawHead ---- SRG=field_70758_at
}
-
+
@Override
public Player spawnPlayer(Location toSpawn, String name, NPC npc) {
- GameProfile profile = skinMap.get(npc.getUUID()) == null ? new GameProfile(npc.getUUID(), npc.getName()) : skinMap.get(npc.getUUID());
- EntityNPCPlayer player = new EntityNPCPlayer(npc, profile, toSpawn);
+ EntityNPCPlayer player = new EntityNPCPlayer(npc, name, toSpawn);
sendPacketsTo(Bukkit.getOnlinePlayers(), new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, player));
WorldServer world = getHandle(toSpawn.getWorld());
world.addEntity(player);
@@ -81,44 +88,6 @@ public Player spawnPlayer(Location toSpawn, String name, NPC npc) {
return player.getBukkitEntity();
}
-
- private Map skinMap = new HashMap<>();
- private static final Field playerInfoActionField = PacketPlayOutPlayerInfo.class.getDeclaredFields()[0];
- private static final Field playerInfoDataListField = PacketPlayOutPlayerInfo.class.getDeclaredFields()[1];
- @Override
- public boolean setSkin(NPC npc, ProfileUtils.PlayerProfile skinProfile) {
- GameProfile profile = makeProfile(npc, skinProfile);
- if (npc.isSpawned()) {
- PacketPlayOutPlayerInfo removePacket = new PacketPlayOutPlayerInfo();
- ReflectUtil.setField(playerInfoActionField, removePacket, EnumPlayerInfoAction.REMOVE_PLAYER);
- List removePacketDataList = ReflectUtil.getField(playerInfoDataListField, removePacket);
- removePacketDataList.add(new PlayerInfoData(removePacket, profile, 0, null, null));
- PacketPlayOutPlayerInfo addPacket = new PacketPlayOutPlayerInfo();
- ReflectUtil.setField(playerInfoActionField, addPacket, EnumPlayerInfoAction.ADD_PLAYER);
- List addPlayerDataList = ReflectUtil.getField(playerInfoDataListField, removePacket);
- EntityPlayer handle = getHandle((Player) npc.getEntity());
- EnumGamemode gamemode = handle.playerInteractManager.getGameMode();
- IChatBaseComponent displayName = handle.getPlayerListName();
- addPlayerDataList.add(new PlayerInfoData(addPacket, profile, 0, gamemode, displayName));
- } else skinMap.put(npc.getUUID(), profile);
- return false;
- }
-
- private static GameProfile makeProfile(NPC npc, ProfileUtils.PlayerProfile skinProfile) {
- GameProfile profile = new GameProfile(npc.getUUID(), npc.getName());
- if (skinProfile == null || skinProfile.getProperties() != null) {
- for (Object obj : skinProfile.getProperties()) {
- JSONObject jsonProperty = (JSONObject) obj;
- String name = (String) jsonProperty.get("name");
- String value = (String) jsonProperty.get("value");
- String signature = jsonProperty.containsKey("signature") ? (String) jsonProperty.get("signature") : null;
- Property property = signature == null ? new Property(name, value) : new Property(name, value, signature);
- profile.getProperties().put(name, property);
- }
- }
- return profile;
- }
-
public static Entity getHandle(org.bukkit.entity.Entity bukkitEntity) {
if (!(bukkitEntity instanceof CraftEntity))
return null;
@@ -227,4 +196,4 @@ public EntityPlayer apply(NPC arg0) {
public void onDespawn(NPC npc) {
sendPacketsTo(Bukkit.getOnlinePlayers(), new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, getHandle((Player)npc.getEntity())));
}
-}
\ No newline at end of file
+}
diff --git a/nms-v1_8_R2/src/main/java/net/techcable/npclib/nms/versions/v1_8_R2/EntityNPCPlayer.java b/nms-v1_8_R2/src/main/java/net/techcable/npclib/nms/versions/v1_8_R2/EntityNPCPlayer.java
index ae36670..b964fb2 100644
--- a/nms-v1_8_R2/src/main/java/net/techcable/npclib/nms/versions/v1_8_R2/EntityNPCPlayer.java
+++ b/nms-v1_8_R2/src/main/java/net/techcable/npclib/nms/versions/v1_8_R2/EntityNPCPlayer.java
@@ -16,8 +16,8 @@
@Getter
public class EntityNPCPlayer extends EntityPlayer {
private final NPC npc;
- public EntityNPCPlayer(NPC npc, GameProfile profile, Location location) {
- super(NMS.getServer(), NMS.getHandle(location.getWorld()), profile, new PlayerInteractManager(NMS.getHandle(location.getWorld())));
+ public EntityNPCPlayer(NPC npc, String name, Location location) {
+ super(NMS.getServer(), NMS.getHandle(location.getWorld()), makeProfile(name, npc.getSkin()), new PlayerInteractManager(NMS.getHandle(location.getWorld())));
playerInteractManager.b(EnumGamemode.SURVIVAL); //MCP = initializeGameType ---- SRG=func_73077_b
this.npc = npc;
playerConnection = new NPCConnection(this);
diff --git a/nms-v1_8_R2/src/main/java/net/techcable/npclib/nms/versions/v1_8_R2/NMS.java b/nms-v1_8_R2/src/main/java/net/techcable/npclib/nms/versions/v1_8_R2/NMS.java
index 3d27ad1..000b17c 100644
--- a/nms-v1_8_R2/src/main/java/net/techcable/npclib/nms/versions/v1_8_R2/NMS.java
+++ b/nms-v1_8_R2/src/main/java/net/techcable/npclib/nms/versions/v1_8_R2/NMS.java
@@ -1,12 +1,19 @@
package net.techcable.npclib.nms.versions.v1_8_R2;
-import java.lang.reflect.Field;
-import java.util.*;
-
-import com.mojang.authlib.GameProfile;
-import com.mojang.authlib.properties.Property;
-import net.minecraft.server.v1_8_R2.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import net.minecraft.server.v1_8_R2.Entity;
+import net.minecraft.server.v1_8_R2.EntityHuman;
+import net.minecraft.server.v1_8_R2.EntityLiving;
+import net.minecraft.server.v1_8_R2.EntityPlayer;
import net.minecraft.server.v1_8_R2.PacketPlayOutPlayerInfo.EnumPlayerInfoAction;
+import net.minecraft.server.v1_8_R2.MinecraftServer;
+import net.minecraft.server.v1_8_R2.Packet;
+import net.minecraft.server.v1_8_R2.PacketPlayOutPlayerInfo;
+import net.minecraft.server.v1_8_R2.PacketPlayOutEntityEquipment;
+import net.minecraft.server.v1_8_R2.WorldServer;
import net.techcable.npclib.NPC;
import net.techcable.npclib.nms.OptionalFeature;
@@ -16,8 +23,8 @@
import com.google.common.collect.Collections2;
import com.google.common.collect.Iterables;
-import net.techcable.npclib.util.ProfileUtils;
-import net.techcable.npclib.util.ReflectUtil;
+import java.util.Arrays;
+
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_8_R2.CraftServer;
@@ -27,7 +34,6 @@
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
-import org.json.simple.JSONObject;
public class NMS implements net.techcable.npclib.nms.NMS {
@@ -73,53 +79,14 @@ public static void setHeadYaw(Entity entity, float yaw) {
@Override
public Player spawnPlayer(Location toSpawn, String name, NPC npc) {
- GameProfile profile = skinMap.get(npc.getUUID()) == null ? new GameProfile(npc.getUUID(), npc.getName()) : skinMap.get(npc.getUUID());
- EntityNPCPlayer player = new EntityNPCPlayer(npc, profile, toSpawn);
+ EntityNPCPlayer player = new EntityNPCPlayer(npc, name, toSpawn);
sendPacketsTo(Bukkit.getOnlinePlayers(), new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, player));
WorldServer world = getHandle(toSpawn.getWorld());
world.addEntity(player);
look(player.getBukkitEntity(), toSpawn.getPitch(), toSpawn.getYaw());
return player.getBukkitEntity();
}
-
-
- private Map skinMap = new HashMap<>();
- private static final Field playerInfoActionField = PacketPlayOutPlayerInfo.class.getDeclaredFields()[0];
- private static final Field playerInfoDataListField = PacketPlayOutPlayerInfo.class.getDeclaredFields()[1];
- @Override
- public boolean setSkin(NPC npc, ProfileUtils.PlayerProfile skinProfile) {
- GameProfile profile = makeProfile(npc, skinProfile);
- if (npc.isSpawned()) {
- PacketPlayOutPlayerInfo removePacket = new PacketPlayOutPlayerInfo();
- ReflectUtil.setField(playerInfoActionField, removePacket, EnumPlayerInfoAction.REMOVE_PLAYER);
- List removePacketDataList = ReflectUtil.getField(playerInfoDataListField, removePacket);
- removePacketDataList.add(removePacket.new PlayerInfoData(profile, 0, null, null));
- PacketPlayOutPlayerInfo addPacket = new PacketPlayOutPlayerInfo();
- ReflectUtil.setField(playerInfoActionField, addPacket, EnumPlayerInfoAction.ADD_PLAYER);
- List addPlayerDataList = ReflectUtil.getField(playerInfoDataListField, removePacket);
- EntityPlayer handle = getHandle((Player) npc.getEntity());
- WorldSettings.EnumGamemode gamemode = handle.playerInteractManager.getGameMode();
- IChatBaseComponent displayName = handle.getPlayerListName();
- addPlayerDataList.add(addPacket.new PlayerInfoData(profile, 0, gamemode, displayName));
- } else skinMap.put(npc.getUUID(), profile);
- return false;
- }
-
- private static GameProfile makeProfile(NPC npc, ProfileUtils.PlayerProfile skinProfile) {
- GameProfile profile = new GameProfile(npc.getUUID(), npc.getName());
- if (skinProfile == null || skinProfile.getProperties() != null) {
- for (Object obj : skinProfile.getProperties()) {
- JSONObject jsonProperty = (JSONObject) obj;
- String name = (String) jsonProperty.get("name");
- String value = (String) jsonProperty.get("value");
- String signature = jsonProperty.containsKey("signature") ? (String) jsonProperty.get("signature") : null;
- Property property = signature == null ? new Property(name, value) : new Property(name, value, signature);
- profile.getProperties().put(name, property);
- }
- }
- return profile;
- }
-
+
public static Entity getHandle(org.bukkit.entity.Entity bukkitEntity) {
if (!(bukkitEntity instanceof CraftEntity))
return null;
diff --git a/nms-v1_8_R3/src/main/java/net/techcable/npclib/nms/versions/v1_8_R3/EntityNPCPlayer.java b/nms-v1_8_R3/src/main/java/net/techcable/npclib/nms/versions/v1_8_R3/EntityNPCPlayer.java
index af1225b..2d0a906 100644
--- a/nms-v1_8_R3/src/main/java/net/techcable/npclib/nms/versions/v1_8_R3/EntityNPCPlayer.java
+++ b/nms-v1_8_R3/src/main/java/net/techcable/npclib/nms/versions/v1_8_R3/EntityNPCPlayer.java
@@ -1,6 +1,9 @@
package net.techcable.npclib.nms.versions.v1_8_R3;
+import java.util.UUID;
+
import com.mojang.authlib.GameProfile;
+import com.mojang.authlib.properties.Property;
import lombok.*;
import net.minecraft.server.v1_8_R3.DamageSource;
@@ -14,8 +17,8 @@
@Getter
public class EntityNPCPlayer extends EntityPlayer {
private final NPC npc;
- public EntityNPCPlayer(NPC npc, GameProfile profile, Location location) {
- super(NMS.getServer(), NMS.getHandle(location.getWorld()), profile, new PlayerInteractManager(NMS.getHandle(location.getWorld())));
+ public EntityNPCPlayer(NPC npc, String name, Location location) {
+ super(NMS.getServer(), NMS.getHandle(location.getWorld()), makeProfile(name, npc.getSkin()), new PlayerInteractManager(NMS.getHandle(location.getWorld())));
playerInteractManager.b(EnumGamemode.SURVIVAL); //MCP = initializeGameType ---- SRG=func_73077_b
this.npc = npc;
playerConnection = new NPCConnection(this);
@@ -30,4 +33,17 @@ public boolean damageEntity(DamageSource source, float damage) {
}
return super.damageEntity(source, damage);
}
+
+ public static GameProfile makeProfile(String name, UUID skinId) {
+ GameProfile profile = new GameProfile(UUID.randomUUID(), name);
+ if (skinId != null) {
+ GameProfile skin = new GameProfile(skinId, null);
+ skin = NMS.getServer().aD().fillProfileProperties(skin, true); //Srg = func_147130_as
+ if (skin.getProperties().get("textures") == null || !skin.getProperties().get("textures").isEmpty()) {
+ Property textures = skin.getProperties().get("textures").iterator().next();
+ profile.getProperties().put("textures", textures);
+ }
+ }
+ return profile;
+ }
}
diff --git a/nms-v1_8_R3/src/main/java/net/techcable/npclib/nms/versions/v1_8_R3/NMS.java b/nms-v1_8_R3/src/main/java/net/techcable/npclib/nms/versions/v1_8_R3/NMS.java
index a11633d..0ab1e82 100644
--- a/nms-v1_8_R3/src/main/java/net/techcable/npclib/nms/versions/v1_8_R3/NMS.java
+++ b/nms-v1_8_R3/src/main/java/net/techcable/npclib/nms/versions/v1_8_R3/NMS.java
@@ -1,12 +1,19 @@
package net.techcable.npclib.nms.versions.v1_8_R3;
-import java.lang.reflect.Field;
-import java.util.*;
-
-import com.mojang.authlib.GameProfile;
-import com.mojang.authlib.properties.Property;
-import net.minecraft.server.v1_8_R3.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import net.minecraft.server.v1_8_R3.Entity;
+import net.minecraft.server.v1_8_R3.EntityHuman;
+import net.minecraft.server.v1_8_R3.EntityLiving;
+import net.minecraft.server.v1_8_R3.EntityPlayer;
import net.minecraft.server.v1_8_R3.PacketPlayOutPlayerInfo.EnumPlayerInfoAction;
+import net.minecraft.server.v1_8_R3.MinecraftServer;
+import net.minecraft.server.v1_8_R3.Packet;
+import net.minecraft.server.v1_8_R3.PacketPlayOutPlayerInfo;
+import net.minecraft.server.v1_8_R3.PacketPlayOutEntityEquipment;
+import net.minecraft.server.v1_8_R3.WorldServer;
import net.techcable.npclib.NPC;
import net.techcable.npclib.nms.OptionalFeature;
@@ -16,8 +23,8 @@
import com.google.common.collect.Collections2;
import com.google.common.collect.Iterables;
-import net.techcable.npclib.util.ProfileUtils;
-import net.techcable.npclib.util.ReflectUtil;
+import java.util.Arrays;
+
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_8_R3.CraftServer;
@@ -27,7 +34,6 @@
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
-import org.json.simple.JSONObject;
public class NMS implements net.techcable.npclib.nms.NMS {
@@ -73,8 +79,7 @@ public static void setHeadYaw(Entity entity, float yaw) {
@Override
public Player spawnPlayer(Location toSpawn, String name, NPC npc) {
- GameProfile profile = skinMap.get(npc.getUUID()) != null ? skinMap.get(npc.getUUID()) : new GameProfile(npc.getUUID(), npc.getName());
- EntityNPCPlayer player = new EntityNPCPlayer(npc, profile, toSpawn);
+ EntityNPCPlayer player = new EntityNPCPlayer(npc, name, toSpawn);
sendPacketsTo(Bukkit.getOnlinePlayers(), new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, player));
WorldServer world = getHandle(toSpawn.getWorld());
world.addEntity(player);
@@ -82,44 +87,6 @@ public Player spawnPlayer(Location toSpawn, String name, NPC npc) {
return player.getBukkitEntity();
}
-
- private Map skinMap = new HashMap<>();
- private static final Field playerInfoActionField = PacketPlayOutPlayerInfo.class.getDeclaredFields()[0];
- private static final Field playerInfoDataListField = PacketPlayOutPlayerInfo.class.getDeclaredFields()[1];
- @Override
- public boolean setSkin(NPC npc, ProfileUtils.PlayerProfile skinProfile) {
- GameProfile profile = makeProfile(npc, skinProfile);
- if (npc.isSpawned()) {
- PacketPlayOutPlayerInfo removePacket = new PacketPlayOutPlayerInfo();
- ReflectUtil.setField(playerInfoActionField, removePacket, EnumPlayerInfoAction.REMOVE_PLAYER);
- List removePacketDataList = ReflectUtil.getField(playerInfoDataListField, removePacket);
- removePacketDataList.add(removePacket.new PlayerInfoData(profile, 0, null, null));
- PacketPlayOutPlayerInfo addPacket = new PacketPlayOutPlayerInfo();
- ReflectUtil.setField(playerInfoActionField, addPacket, EnumPlayerInfoAction.ADD_PLAYER);
- List addPlayerDataList = ReflectUtil.getField(playerInfoDataListField, removePacket);
- EntityPlayer handle = getHandle((Player) npc.getEntity());
- WorldSettings.EnumGamemode gamemode = handle.playerInteractManager.getGameMode();
- IChatBaseComponent displayName = handle.getPlayerListName();
- addPlayerDataList.add(addPacket.new PlayerInfoData(profile, 0, gamemode, displayName));
- } else skinMap.put(npc.getUUID(), profile);
- return false;
- }
-
- private static GameProfile makeProfile(NPC npc, ProfileUtils.PlayerProfile skinProfile) {
- GameProfile profile = new GameProfile(npc.getUUID(), npc.getName());
- if (skinProfile == null || skinProfile.getProperties() != null) {
- for (Object obj : skinProfile.getProperties()) {
- JSONObject jsonProperty = (JSONObject) obj;
- String name = (String) jsonProperty.get("name");
- String value = (String) jsonProperty.get("value");
- String signature = jsonProperty.containsKey("signature") ? (String) jsonProperty.get("signature") : null;
- Property property = signature == null ? new Property(name, value) : new Property(name, value, signature);
- profile.getProperties().put(name, property);
- }
- }
- return profile;
- }
-
public static Entity getHandle(org.bukkit.entity.Entity bukkitEntity) {
if (!(bukkitEntity instanceof CraftEntity))
return null;
diff --git a/nms/src/main/java/net/techcable/npclib/nms/NMSNPC.java b/nms/src/main/java/net/techcable/npclib/nms/NMSNPC.java
index da712a5..77699d2 100644
--- a/nms/src/main/java/net/techcable/npclib/nms/NMSNPC.java
+++ b/nms/src/main/java/net/techcable/npclib/nms/NMSNPC.java
@@ -9,7 +9,6 @@
import java.util.UUID;
import net.techcable.npclib.NPC;
-import net.techcable.npclib.nms.skins.RateLimitedException;
import net.techcable.npclib.util.ProfileUtils;
import net.techcable.npclib.util.ProfileUtils.PlayerProfile;
@@ -108,9 +107,6 @@ public void setName(String name) {
@Override
public boolean spawn(Location toSpawn) {
if (isSpawned()) return false;
- if (skin != null) {
- trySetSkin();
- }
Entity spawned = Util.spawn(toSpawn, getType(), getName(), this);
if (spawned != null) {
setEntity(spawned);
@@ -135,44 +131,13 @@ public boolean isProtected() {
public void setSkin(UUID skin) {
if (!Util.getNMS().isSupported(OptionalFeature.SKINS)) throw new UnsupportedOperationException();
this.skin = skin;
- trySetSkin();
+ if (isSpawned()) {
+ Location last = getEntity().getLocation();
+ getEntity().remove();
+ Util.spawn(last, EntityType.PLAYER, getName(), this);
+ }
}
-
- private void trySetSkin() {
- final PlayerProfile skinProfile;
- try {
- skinProfile = ProfileUtils.lookup(skin);
- if (Bukkit.isPrimaryThread()) {
- boolean respawnNeeded = Util.getNMS().setSkin(this, skinProfile);
- if (respawnNeeded && isSpawned()) {
- Location last = getEntity().getLocation();
- getEntity().remove();
- Util.spawn(last, EntityType.PLAYER, getName(), this);
- }
- } else {
- new BukkitRunnable() {
- @Override
- public void run() {
- boolean respawnNeeded = Util.getNMS().setSkin(NMSNPC.this, skinProfile);
- if (respawnNeeded && isSpawned()) {
- Location last = getEntity().getLocation();
- getEntity().remove();
- Util.spawn(last, EntityType.PLAYER, getName(), NMSNPC.this);
- }
- }
- }.runTask(registry.getPlugin());
- }
- } catch (RateLimitedException ex) {
- Bukkit.getLogger().info("[NPCLib] Unable to request uuid for npc " + getName() + ". Requesting again in 70 seconds.");
- new BukkitRunnable() {
- @Override
- public void run() {
- trySetSkin();
- }
- }.runTaskLaterAsynchronously(registry.getPlugin(), 1400);
- }
- }
-
+
@Override
public void setSkin(String skin) {
if (skin == null) return;