Skip to content

Commit

Permalink
Allow different skins on fake_players, fix possible skin glitch when …
Browse files Browse the repository at this point in the history
…it's a skin's first use

For example: fake_player[name=Notch;skin=mcmonkey4eva] would create a
fake_player named "Notch" but with @mcmonkey4eva 's skin
  • Loading branch information
Morphan1 committed Feb 21, 2015
1 parent 0115332 commit f8a41c6
Showing 1 changed file with 20 additions and 2 deletions.
@@ -1,6 +1,7 @@
package net.aufdemrand.denizen.utilities.entity;

import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import net.aufdemrand.denizen.objects.properties.item.ItemSkullskin;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizen.utilities.debugging.dB;
Expand Down Expand Up @@ -47,18 +48,33 @@ public CraftFakePlayer(CraftServer server, EntityFakePlayer entity) {
@CreateEntity
public static Player createFakePlayer(Location location, ArrayList<Mechanism> mechanisms) {
String name = null;
String skin = null;
for (Mechanism mechanism : mechanisms) {
if (mechanism.matches("name"))
if (mechanism.matches("name")) {
name = mechanism.getValue().asString();
}
else if (mechanism.matches("skin")) {
skin = mechanism.getValue().asString();
}
}
if (name == null || name.length() == 0 || name.length() > 16) {
dB.echoError("You must specify a name with no more than 16 characters for FAKE_PLAYER entities!");
dB.echoError("You must specify a name with no more than 16 characters for FAKE_PLAYER names!");
return null;
}
if (skin != null && (skin.isEmpty() || skin.length() > 16)) {
dB.echoError("You must specify a name with no more than 16 characters for FAKE_PLAYER skins!");
}
CraftWorld world = (CraftWorld) location.getWorld();
WorldServer worldServer = world.getHandle();
GameProfile gameProfile = new GameProfile(null, name);
gameProfile = ItemSkullskin.fillGameProfile(gameProfile);
if (skin != null) {
gameProfile.getProperties().get("textures").clear();
GameProfile skinProfile = new GameProfile(null, skin);
skinProfile = ItemSkullskin.fillGameProfile(skinProfile);
for (Property texture : skinProfile.getProperties().get("textures"))
gameProfile.getProperties().put("textures", texture);
}
UUID uuid = UUID.randomUUID();
if (uuid.version() == 4) {
long msb = uuid.getMostSignificantBits();
Expand All @@ -73,8 +89,10 @@ public static Player createFakePlayer(Location location, ArrayList<Mechanism> me
fakePlayer.setPositionRotation(location.getX(), location.getY(), location.getZ(),
location.getYaw(), location.getPitch());
PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(fakePlayer);
PacketPlayOutPlayerInfo playerInfo = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, fakePlayer);
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
PacketHelper.sendPacket(player, spawnPacket);
PacketHelper.sendPacket(player, playerInfo);
}
return fakePlayer.getBukkitEntity();
}
Expand Down

0 comments on commit f8a41c6

Please sign in to comment.