Skip to content

Commit

Permalink
Fix player NPCs not working with /npc name
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Aug 25, 2015
1 parent 03ef04a commit 767dfe1
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/main/java/net/citizensnpcs/npc/CitizensNPC.java
Expand Up @@ -17,6 +17,7 @@
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scoreboard.NameTagVisibility;

import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
Expand Down Expand Up @@ -67,7 +68,6 @@ public boolean despawn(DespawnReason reason) {
}
return false;
}

NPCDespawnEvent event = new NPCDespawnEvent(this, reason);
if (reason == DespawnReason.CHUNK_UNLOAD) {
event.setCancelled(Setting.KEEP_CHUNKS_LOADED.asBoolean());
Expand Down Expand Up @@ -237,12 +237,6 @@ public boolean spawn(Location at) {
LivingEntity entity = (LivingEntity) getEntity();
entity.setRemoveWhenFarAway(false);

if (!data().get(NPC.NAMEPLATE_VISIBLE_METADATA, true)) {
entity.setCustomName("");
} else {
entity.setCustomName(getFullName());
}

if (NMS.getStepHeight(entity) < 1) {
NMS.setStepHeight(NMS.getHandle(entity), 1);
}
Expand Down Expand Up @@ -291,8 +285,18 @@ public void update() {
&& getEntity().getWorld().getFullTime() % Setting.PACKET_UPDATE_DELAY.asInt() == 0) {
if (getEntity() instanceof LivingEntity) {
if (!getEntity().isCustomNameVisible()) {
getEntity().setCustomName("&2");
if (getEntity() instanceof Player && data().has(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA)) {
String teamName = data().get(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA);
Bukkit.getScoreboardManager().getMainScoreboard().getTeam(teamName)
.setNameTagVisibility(NameTagVisibility.NEVER);
}
getEntity().setCustomName("");
} else {
if (getEntity() instanceof Player && data().has(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA)) {
String teamName = data().get(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA);
Bukkit.getScoreboardManager().getMainScoreboard().getTeam(teamName)
.setNameTagVisibility(NameTagVisibility.ALWAYS);
}
getEntity().setCustomName(getFullName());
}
}
Expand Down

0 comments on commit 767dfe1

Please sign in to comment.