From 76b2bc386454fb25cc65269d8c15964d8a8c6b75 Mon Sep 17 00:00:00 2001 From: fullwall Date: Sat, 16 Mar 2013 15:06:04 +0800 Subject: [PATCH] add /npc nameplate command --- .../net/citizensnpcs/commands/NPCCommands.java | 14 +++++++++++++- .../trait/waypoint/WanderWaypointProvider.java | 10 +++++----- src/main/java/net/citizensnpcs/util/Messages.java | 1 + src/main/resources/messages_en.properties | 1 + 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/citizensnpcs/commands/NPCCommands.java b/src/main/java/net/citizensnpcs/commands/NPCCommands.java index f3043d405..20fe480ac 100644 --- a/src/main/java/net/citizensnpcs/commands/NPCCommands.java +++ b/src/main/java/net/citizensnpcs/commands/NPCCommands.java @@ -647,10 +647,22 @@ public class NPCCommands { } npc.getBukkitEntity().teleport(to, TeleportCause.COMMAND); - Messaging.sendTr(sender, Messages.MOVETO_TELEPORTED, npc.getName(), to); } + @Command( + aliases = { "npc" }, + modifiers = "nameplate", + desc = "Toggle nameplate visibility", + min = 1, + max = 1, + permission = "citizens.npc.nameplate") + @Requirements(selected = true, ownership = true, excludedTypes = EntityType.PLAYER) + public void nameplate(CommandContext args, CommandSender sender, NPC npc) { + npc.getBukkitEntity().setCustomNameVisible(!npc.getBukkitEntity().isCustomNameVisible()); + Messaging.sendTr(sender, Messages.NAMEPLATE_VISIBILITY_TOGGLED); + } + @Command(aliases = { "npc" }, desc = "Show basic NPC information", max = 0, permission = "citizens.npc.info") public void npc(CommandContext args, CommandSender sender, NPC npc) { Messaging.send(sender, StringHelper.wrapHeader(npc.getName())); diff --git a/src/main/java/net/citizensnpcs/trait/waypoint/WanderWaypointProvider.java b/src/main/java/net/citizensnpcs/trait/waypoint/WanderWaypointProvider.java index 03f9848cb..3de48544a 100644 --- a/src/main/java/net/citizensnpcs/trait/waypoint/WanderWaypointProvider.java +++ b/src/main/java/net/citizensnpcs/trait/waypoint/WanderWaypointProvider.java @@ -4,6 +4,7 @@ import net.citizensnpcs.api.CitizensAPI; import net.citizensnpcs.api.ai.Goal; import net.citizensnpcs.api.ai.goals.WanderGoal; import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.api.persistence.Persist; import net.citizensnpcs.api.util.DataKey; import org.bukkit.entity.Player; @@ -11,7 +12,10 @@ import org.bukkit.entity.Player; public class WanderWaypointProvider implements WaypointProvider { private Goal currentGoal; private volatile boolean paused; - private int xrange = DEFAULT_XRANGE, yrange = DEFAULT_YRANGE; + @Persist + private final int xrange = DEFAULT_XRANGE; + @Persist + private final int yrange = DEFAULT_YRANGE; @Override public WaypointEditor createEditor(Player player) { @@ -37,8 +41,6 @@ public class WanderWaypointProvider implements WaypointProvider { @Override public void load(DataKey key) { - xrange = key.getInt("xrange", DEFAULT_XRANGE); - yrange = key.getInt("yrange", DEFAULT_YRANGE); } @Override @@ -52,8 +54,6 @@ public class WanderWaypointProvider implements WaypointProvider { @Override public void save(DataKey key) { - key.setInt("xrange", xrange); - key.setInt("yrange", yrange); } @Override diff --git a/src/main/java/net/citizensnpcs/util/Messages.java b/src/main/java/net/citizensnpcs/util/Messages.java index 02a23d5f7..c285220e3 100644 --- a/src/main/java/net/citizensnpcs/util/Messages.java +++ b/src/main/java/net/citizensnpcs/util/Messages.java @@ -107,6 +107,7 @@ public class Messages { public static final String MONEY_WITHDRAWN = "citizens.economy.money-withdrawn"; public static final String MOVETO_FORMAT = "citizens.commands.npc.moveto.format"; public static final String MOVETO_TELEPORTED = "citizens.commands.npc.moveto.teleported"; + public static final String NAMEPLATE_VISIBILITY_TOGGLED = "citizens.commands.npc.nameplate.toggled"; public static final String NO_NPC_WITH_ID_FOUND = "citizens.commands.npc.spawn.missing-npc-id"; public static final String NO_STORED_SPAWN_LOCATION = "citizens.commands.npc.spawn.no-location"; public static final String NOT_LIVING_MOBTYPE = "citizens.commands.npc.create.not-living-mobtype"; diff --git a/src/main/resources/messages_en.properties b/src/main/resources/messages_en.properties index 79fbc3fb3..aef019025 100644 --- a/src/main/resources/messages_en.properties +++ b/src/main/resources/messages_en.properties @@ -45,6 +45,7 @@ citizens.commands.npc.lookclose.stopped=[[{0}]] will no longer rotate when playe citizens.commands.npc.mount.failed=Couldn''t mount [[{0}]]. citizens.commands.npc.moveto.format=Format is x:y:z(:world) or x y z( world). citizens.commands.npc.moveto.teleported=[[{0}]] teleported to {1}. +citizens.commands.npc.nameplate.toggled=Nameplate visibility toggled. citizens.commands.npc.owner.already-owner={0} is already the owner of {1}. citizens.commands.npc.owner.owner=[[{0}]]''s owner is [[{1}]]. citizens.commands.npc.owner.set-server=[[The server]] is now the owner of {0}.