Change /npc skin

This commit is contained in:
fullwall 2014-04-04 14:50:07 +08:00
parent 5184efa09c
commit 54bd62c414
3 changed files with 22 additions and 19 deletions

View File

@ -48,7 +48,6 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityTargetEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerQuitEvent;
@ -130,7 +129,7 @@ public class EventListen implements Listener {
toRespawn.put(coord, npc);
if (Messaging.isDebugging()) {
Messaging
.debug("Despawned id", npc.getId(), "due to chunk unload at [" + coord.x + "," + coord.z + "]");
.debug("Despawned id", npc.getId(), "due to chunk unload at [" + coord.x + "," + coord.z + "]");
}
}
}
@ -212,14 +211,6 @@ public class EventListen implements Listener {
}
}, delay + 2);
}
if (event instanceof PlayerDeathEvent && !npc.data().get(NPC.PLAYER_SKIN_NAME_METADATA, "").isEmpty()) {
String skinName = npc.data().get(NPC.PLAYER_SKIN_NAME_METADATA, "");
PlayerDeathEvent pde = (PlayerDeathEvent) event;
pde.setDeathMessage(pde.getDeathMessage().replace(" " + skinName, " " + npc.getFullName())
.replace(skinName + " ", npc.getFullName() + " "));
}
}
@EventHandler(priority = EventPriority.HIGHEST)

View File

@ -66,6 +66,14 @@ public class SkeletonController extends MobEntityController {
}
}
@Override
public void bm() {
super.bm();
if (npc != null) {
npc.update();
}
}
@Override
public boolean bN() {
if (npc == null)
@ -79,13 +87,6 @@ public class SkeletonController extends MobEntityController {
return false; // shouldLeash
}
@Override
public void bm() {
super.bm();
if (npc != null)
npc.update();
}
@Override
public void collide(net.minecraft.server.v1_7_R2.Entity entity) {
// this method is called by both the entities involved - cancelling

View File

@ -35,8 +35,9 @@ public class PlayerSkin extends Trait {
public String getSkinName() {
String skin = npc.data().get(NPC.PLAYER_SKIN_NAME_METADATA, "");
if (skin.isEmpty())
if (skin.isEmpty()) {
skin = npc.getFullName();
}
return skin;
}
@ -63,7 +64,7 @@ public class PlayerSkin extends Trait {
npcEntity.data().set(NPC.HURT_SOUND_METADATA, "");
npcEntity.data().set(NPC.SHOULD_SAVE_METADATA, false);
npcEntity.spawn(npc.getStoredLocation());
if (name.isEmpty() || !(npcEntity.getEntity() instanceof Slime)) {
if (name.isEmpty()) {
((LivingEntity) npcEntity.getEntity()).addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 20
* 60 * 60 * 24 * 7, 1));
} else {
@ -99,6 +100,16 @@ public class PlayerSkin extends Trait {
nameCarriers.add(nameCarrier);
}
for (Entity entity : nameCarriers) {
if (entity instanceof LivingEntity) {
LivingEntity le = (LivingEntity) entity;
le.setRemainingAir(20);
if (!le.hasPotionEffect(PotionEffectType.INVISIBILITY)) {
((LivingEntity) entity).addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 20 * 60
* 60 * 24 * 7, 1));
}
}
}
}
public void setSkinName(String name) {