Skip to content

Commit

Permalink
Experimental NPC skin_blob improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Mar 23, 2018
1 parent 4e49cf2 commit 3f45c22
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions plugin/src/main/java/net/aufdemrand/denizen/objects/dNPC.java
Expand Up @@ -27,6 +27,7 @@
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.trait.trait.Equipment;
import net.citizensnpcs.api.trait.trait.Owner;
import net.citizensnpcs.npc.skin.SkinnableEntity;
import net.citizensnpcs.trait.Anchors;
import net.citizensnpcs.trait.LookClose;
import net.citizensnpcs.trait.Poses;
Expand Down Expand Up @@ -1192,23 +1193,31 @@ public void adjust(Mechanism mechanism) {
// @name skin_blob
// @input Element
// @description
// Sets the skin blob of an NPC.
// Sets the skin blob of an NPC, in the form of "texture;signature;name".
// Call with no value to clear the value.
// @tags
// <n@npc.skin>
// -->
if (mechanism.matches("skin_blob")) {
if (!mechanism.hasValue()) {
getCitizen().data().remove(NPC.PLAYER_SKIN_TEXTURE_PROPERTIES_METADATA);
getCitizen().data().remove(NPC.PLAYER_SKIN_TEXTURE_PROPERTIES_SIGN_METADATA);
if (getCitizen().isSpawned()) {
getCitizen().despawn(DespawnReason.PENDING_RESPAWN);
getCitizen().spawn(getCitizen().getStoredLocation());
}
}
else {
String[] dat = mechanism.getValue().asString().split(";");
getCitizen().data().setPersistent(NPC.PLAYER_SKIN_TEXTURE_PROPERTIES_METADATA, dat[0]);
getCitizen().data().setPersistent(NPC.PLAYER_SKIN_TEXTURE_PROPERTIES_SIGN_METADATA, dat.length > 0 ? dat[1] : null);
}
if (getCitizen().isSpawned()) {
getCitizen().despawn(DespawnReason.PENDING_RESPAWN);
getCitizen().spawn(getCitizen().getStoredLocation());
if (dat.length > 1) {
getCitizen().data().setPersistent(NPC.PLAYER_SKIN_UUID_METADATA, dat[2]);
}
if (getCitizen().isSpawned() && getCitizen().getEntity() instanceof SkinnableEntity) {
((SkinnableEntity) getCitizen().getEntity()).setSkinPersistent(dat.length > 1 ? dat[2] : "unspecified", dat[0], dat.length > 0 ? dat[1] : null);
((SkinnableEntity) getCitizen().getEntity()).getSkinTracker().notifySkinChange(true);
}
}
}

Expand All @@ -1217,7 +1226,8 @@ public void adjust(Mechanism mechanism) {
// @name skin
// @input Element
// @description
// Sets the skin of an NPC.
// Sets the skin of an NPC by name.
// Call with no value to clear the value.
// @tags
// <n@npc.skin>
// -->
Expand Down

0 comments on commit 3f45c22

Please sign in to comment.