Support setting permanent skins

A permanent skin is set with ./npc skin -p name and will NOT change when
that player changes their skin, opening up lots more skin options.
To do this with code, set
npc.data().setPersistent(NPC.PLAYER_SKIN_UUID_METADATA, to the players
UUID/ Name and then
npc.data().setPersistent(NPC.PLAYER_SKIN_TEXTURE_PROPERTIES, "cache");
to tell the plugin to keep a permanent cache of their skin. Due to how
skins are implemented, these skins will work forever.
This commit is contained in:
sanjay900 2015-02-03 10:52:52 +13:00
parent 6d1d4e73e0
commit 8698312a87
2 changed files with 22 additions and 4 deletions

View File

@ -1229,11 +1229,12 @@ public class NPCCommands {
@Command( @Command(
aliases = { "npc" }, aliases = { "npc" },
usage = "skin (-c) [name]", usage = "skin (-c,b) [name]",
desc = "Sets an NPC's skin name", desc = "Sets an NPC's skin name, Use -b to save a skin snapshot that won't change",
modifiers = { "skin" }, modifiers = { "skin" },
min = 1, min = 1,
max = 2, max = 2,
flags = "cp",
permission = "citizens.npc.skin") permission = "citizens.npc.skin")
@Requirements(types = EntityType.PLAYER, selected = true, ownership = true) @Requirements(types = EntityType.PLAYER, selected = true, ownership = true)
public void skin(final CommandContext args, final CommandSender sender, final NPC npc) throws CommandException { public void skin(final CommandContext args, final CommandSender sender, final NPC npc) throws CommandException {
@ -1244,6 +1245,9 @@ public class NPCCommands {
if (args.argsLength() != 2) if (args.argsLength() != 2)
throw new CommandException(); throw new CommandException();
npc.data().setPersistent(NPC.PLAYER_SKIN_UUID_METADATA, args.getString(1)); npc.data().setPersistent(NPC.PLAYER_SKIN_UUID_METADATA, args.getString(1));
if (args.hasFlag('p')) {
npc.data().setPersistent(NPC.PLAYER_SKIN_TEXTURE_PROPERTIES, "cache");
}
skinName = args.getString(1); skinName = args.getString(1);
} }
Messaging.sendTr(sender, Messages.SKIN_SET, npc.getName(), skinName); Messaging.sendTr(sender, Messages.SKIN_SET, npc.getName(), skinName);

View File

@ -97,6 +97,7 @@ public class HumanController extends AbstractEntityController {
} }
private void updateSkin(final NPC npc, final WorldServer nmsWorld, GameProfile profile) { private void updateSkin(final NPC npc, final WorldServer nmsWorld, GameProfile profile) {
String skinUUID = npc.data().get(NPC.PLAYER_SKIN_UUID_METADATA); String skinUUID = npc.data().get(NPC.PLAYER_SKIN_UUID_METADATA);
if (skinUUID == null) { if (skinUUID == null) {
skinUUID = npc.getName(); skinUUID = npc.getName();
@ -107,7 +108,15 @@ public class HumanController extends AbstractEntityController {
ChatColor.stripColor(npc.data().<String> get(CACHED_SKIN_UUID_NAME_METADATA)))) { ChatColor.stripColor(npc.data().<String> get(CACHED_SKIN_UUID_NAME_METADATA)))) {
skinUUID = npc.data().get(CACHED_SKIN_UUID_METADATA); skinUUID = npc.data().get(CACHED_SKIN_UUID_METADATA);
} }
if (npc.data().has(PLAYER_SKIN_TEXTURE_PROPERTIES)&&npc.data().<String>get(PLAYER_SKIN_TEXTURE_PROPERTIES).equals("cache")) {
SKIN_THREAD.addRunnable(new SkinFetcher(new UUIDFetcher(skinUUID, npc), nmsWorld.getMinecraftServer().aB(),
npc));
return;
}
Property cached = TEXTURE_CACHE.get(skinUUID); Property cached = TEXTURE_CACHE.get(skinUUID);
if (npc.data().has(PLAYER_SKIN_TEXTURE_PROPERTIES)&&npc.data().has(PLAYER_SKIN_TEXTURE_PROPERTIES_SIGN)) {
cached = new Property("textures",npc.data().<String>get(PLAYER_SKIN_TEXTURE_PROPERTIES),npc.data().<String>get(PLAYER_SKIN_TEXTURE_PROPERTIES_SIGN));
}
if (cached != null) { if (cached != null) {
profile.getProperties().put("textures", cached); profile.getProperties().put("textures", cached);
} else { } else {
@ -158,7 +167,7 @@ public class HumanController extends AbstractEntityController {
} }
GameProfile skinProfile = null; GameProfile skinProfile = null;
Property cached = TEXTURE_CACHE.get(realUUID); Property cached = TEXTURE_CACHE.get(realUUID);
if (cached != null) { if (cached != null && !(npc.data().has(PLAYER_SKIN_TEXTURE_PROPERTIES)&&npc.data().<String>get(PLAYER_SKIN_TEXTURE_PROPERTIES).equals("cache"))) {
if (Messaging.isDebugging()) { if (Messaging.isDebugging()) {
Messaging Messaging
.debug("Using cached skin texture for NPC " + npc.getName() + " UUID " + npc.getUniqueId()); .debug("Using cached skin texture for NPC " + npc.getName() + " UUID " + npc.getUniqueId());
@ -185,7 +194,10 @@ public class HumanController extends AbstractEntityController {
Property textures = Iterables.getFirst(skinProfile.getProperties().get("textures"), null); Property textures = Iterables.getFirst(skinProfile.getProperties().get("textures"), null);
if (textures.getValue() == null || textures.getSignature() == null) if (textures.getValue() == null || textures.getSignature() == null)
return; return;
if (npc.data().has(PLAYER_SKIN_TEXTURE_PROPERTIES)&&npc.data().<String>get(PLAYER_SKIN_TEXTURE_PROPERTIES).equals("cache")) {
npc.data().setPersistent(PLAYER_SKIN_TEXTURE_PROPERTIES, textures.getValue());
npc.data().setPersistent(PLAYER_SKIN_TEXTURE_PROPERTIES_SIGN, textures.getSignature());
}
if (Messaging.isDebugging()) { if (Messaging.isDebugging()) {
Messaging.debug("Fetched skin texture for UUID " + realUUID + " for NPC " + npc.getName() Messaging.debug("Fetched skin texture for UUID " + realUUID + " for NPC " + npc.getName()
+ " UUID " + npc.getUniqueId()); + " UUID " + npc.getUniqueId());
@ -291,6 +303,8 @@ public class HumanController extends AbstractEntityController {
private static final String CACHED_SKIN_UUID_METADATA = "cached-skin-uuid"; private static final String CACHED_SKIN_UUID_METADATA = "cached-skin-uuid";
private static final String CACHED_SKIN_UUID_NAME_METADATA = "cached-skin-uuid-name"; private static final String CACHED_SKIN_UUID_NAME_METADATA = "cached-skin-uuid-name";
private static final String PLAYER_SKIN_TEXTURE_PROPERTIES = "player-skin-textures";
private static final String PLAYER_SKIN_TEXTURE_PROPERTIES_SIGN = "player-skin-signature";
private static Method MAKE_REQUEST; private static Method MAKE_REQUEST;
private static SkinThread SKIN_THREAD; private static SkinThread SKIN_THREAD;
private static final Map<String, Property> TEXTURE_CACHE = Maps.newConcurrentMap(); private static final Map<String, Property> TEXTURE_CACHE = Maps.newConcurrentMap();