Skip to content

Commit

Permalink
Add -h option to /npc name
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Nov 22, 2016
1 parent 58c5fc7 commit 2f7e4ea
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
12 changes: 8 additions & 4 deletions main/src/main/java/net/citizensnpcs/commands/NPCCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.bukkit.entity.Horse.Color;
import org.bukkit.entity.Horse.Style;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Ocelot;
import org.bukkit.entity.Player;
import org.bukkit.entity.Rabbit;
Expand Down Expand Up @@ -964,12 +963,17 @@ public void moveto(CommandContext args, CommandSender sender, NPC npc) throws Co
desc = "Toggle nameplate visibility",
min = 1,
max = 1,
flags = "h",
permission = "citizens.npc.name")
@Requirements(selected = true, ownership = true, livingEntity = true)
public void name(CommandContext args, CommandSender sender, NPC npc) {
LivingEntity entity = (LivingEntity) npc.getEntity();
entity.setCustomNameVisible(!entity.isCustomNameVisible());
npc.data().setPersistent(NPC.NAMEPLATE_VISIBLE_METADATA, entity.isCustomNameVisible());
String old = npc.data().<Object> get(NPC.NAMEPLATE_VISIBLE_METADATA, true).toString();
if (args.hasFlag('h')) {
old = "hover";
} else {
old = old.equals("hover") ? "true" : "" + !Boolean.parseBoolean(old);
}
npc.data().setPersistent(NPC.NAMEPLATE_VISIBLE_METADATA, old);
Messaging.sendTr(sender, Messages.NAMEPLATE_VISIBILITY_TOGGLED);
}

Expand Down
11 changes: 8 additions & 3 deletions main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ public void update() {
updateCounter = 0;
if (getEntity() instanceof LivingEntity) {
OptionStatus nameVisibility = OptionStatus.NEVER;
if (!getEntity().isCustomNameVisible()) {
if (!getEntity().isCustomNameVisible()
&& !data().<Object> get(NPC.NAMEPLATE_VISIBLE_METADATA, true).toString().equals("hover")) {
getEntity().setCustomName("");
} else {
nameVisibility = OptionStatus.ALWAYS;
Expand Down Expand Up @@ -311,8 +312,12 @@ public void update() {
}

if (getEntity() instanceof LivingEntity) {
boolean nameplateVisible = data().get(NPC.NAMEPLATE_VISIBLE_METADATA, true);
((LivingEntity) getEntity()).setCustomNameVisible(nameplateVisible);
String nameplateVisible = data().<Object> get(NPC.NAMEPLATE_VISIBLE_METADATA, true).toString();
if (nameplateVisible.equals("hover")) {
((LivingEntity) getEntity()).setCustomNameVisible(false);
} else {
((LivingEntity) getEntity()).setCustomNameVisible(Boolean.parseBoolean(nameplateVisible));
}
if (data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) {
NMS.setKnockbackResistance((LivingEntity) getEntity(), 1D);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,9 @@ protected void L() {
@Override
public void M() {
super.M();
if (npc != null)
if (npc != null) {
npc.update();
}
}

@Override
Expand Down

0 comments on commit 2f7e4ea

Please sign in to comment.