From 10a9319aa4429f9a0d2c9514f67760da14463aa3 Mon Sep 17 00:00:00 2001 From: aPunch Date: Sun, 5 Feb 2012 04:24:11 -0600 Subject: [PATCH] disallow names greater than 16 characters in length as per vanilla spec --- .../command/command/NPCCommands.java | 61 +++++++++++++++---- src/net/citizensnpcs/npc/NPCInventory.java | 4 +- 2 files changed, 51 insertions(+), 14 deletions(-) diff --git a/src/net/citizensnpcs/command/command/NPCCommands.java b/src/net/citizensnpcs/command/command/NPCCommands.java index 6062403c4..0a4e44432 100644 --- a/src/net/citizensnpcs/command/command/NPCCommands.java +++ b/src/net/citizensnpcs/command/command/NPCCommands.java @@ -32,8 +32,13 @@ public class NPCCommands { this.characterManager = characterManager; } - @Command(aliases = { "npc" }, usage = "create [name] [type] (character)", desc = "Create a new NPC", - modifiers = { "create" }, min = 3, max = 4) + @Command( + aliases = { "npc" }, + usage = "create [name] [type] (character)", + desc = "Create a new NPC", + modifiers = { "create" }, + min = 3, + max = 4) @Permission("npc.create") @Requirements public void createNPC(CommandContext args, Player player, NPC npc) { @@ -44,7 +49,12 @@ public class NPCCommands { Messaging.sendError(player, "'" + args.getString(2) + "' is not a valid mob type. Using default NPC."); } - NPC create = npcManager.createNPC(type, args.getString(1)); + String name = args.getString(1); + if (args.getString(1).length() > 16) { + Messaging.sendError(player, "NPC names cannot be longer than 16 characters. The name has been shortened."); + name = name.substring(0, 15); + } + NPC create = npcManager.createNPC(type, name); String successMsg = ChatColor.GREEN + "You created " + StringHelper.wrap(create.getName()); boolean success = true; if (args.argsLength() == 4) { @@ -72,8 +82,13 @@ public class NPCCommands { Messaging.send(player, successMsg); } - @Command(aliases = { "npc" }, usage = "despawn", desc = "Despawn an NPC", modifiers = { "despawn" }, min = 1, - max = 1) + @Command( + aliases = { "npc" }, + usage = "despawn", + desc = "Despawn an NPC", + modifiers = { "despawn" }, + min = 1, + max = 1) @Permission("npc.despawn") public void despawnNPC(CommandContext args, Player player, NPC npc) { npc.getTrait(Spawned.class).setSpawned(false); @@ -81,8 +96,13 @@ public class NPCCommands { Messaging.send(player, ChatColor.GREEN + "You despawned " + StringHelper.wrap(npc.getName()) + "."); } - @Command(aliases = { "npc" }, usage = "select [id]", desc = "Select an NPC", modifiers = { "select" }, min = 2, - max = 2) + @Command( + aliases = { "npc" }, + usage = "select [id]", + desc = "Select an NPC", + modifiers = { "select" }, + min = 2, + max = 2) @Permission("npc.select") @Requirements(ownership = true) public void selectNPC(CommandContext args, Player player, NPC npc) { @@ -99,8 +119,13 @@ public class NPCCommands { Messaging.sendWithNPC(player, Setting.SELECTION_MESSAGE.asString(), toSelect); } - @Command(aliases = { "npc" }, usage = "spawn [id]", desc = "Spawn an existing NPC", modifiers = { "spawn" }, - min = 2, max = 2) + @Command( + aliases = { "npc" }, + usage = "spawn [id]", + desc = "Spawn an existing NPC", + modifiers = { "spawn" }, + min = 2, + max = 2) @Permission("npc.spawn") @Requirements public void spawnNPC(CommandContext args, Player player, NPC npc) { @@ -127,16 +152,26 @@ public class NPCCommands { + " is already spawned at another location. Use '/npc tphere' to teleport the NPC to your location."); } - @Command(aliases = { "npc" }, usage = "tphere", desc = "Teleport an NPC to your location", - modifiers = { "tphere" }, min = 1, max = 1) + @Command( + aliases = { "npc" }, + usage = "tphere", + desc = "Teleport an NPC to your location", + modifiers = { "tphere" }, + min = 1, + max = 1) @Permission("npc.tphere") public void teleportNPCToPlayer(CommandContext args, Player player, NPC npc) { npc.getBukkitEntity().teleport(player, TeleportCause.COMMAND); Messaging.send(player, StringHelper.wrap(npc.getName()) + " was teleported to your location."); } - @Command(aliases = { "npc" }, usage = "tp", desc = "Teleport to an NPC", modifiers = { "tp", "teleport" }, min = 1, - max = 1) + @Command( + aliases = { "npc" }, + usage = "tp", + desc = "Teleport to an NPC", + modifiers = { "tp", "teleport" }, + min = 1, + max = 1) @Permission("npc.tp") public void teleportToNPC(CommandContext args, Player player, NPC npc) { player.teleport(npc.getBukkitEntity(), TeleportCause.COMMAND); diff --git a/src/net/citizensnpcs/npc/NPCInventory.java b/src/net/citizensnpcs/npc/NPCInventory.java index 4e1704461..866118e6e 100644 --- a/src/net/citizensnpcs/npc/NPCInventory.java +++ b/src/net/citizensnpcs/npc/NPCInventory.java @@ -12,11 +12,13 @@ import org.bukkit.inventory.Inventory; public class NPCInventory implements IInventory { private final int size = 36; private final CitizensNPC npc; + private final String name; private final ItemStack[] contents; private final Inventory inventory = new CraftInventory(this); public NPCInventory(CitizensNPC npc) { this.npc = npc; + name = npc.getName(); contents = new ItemStack[size]; } @@ -52,7 +54,7 @@ public class NPCInventory implements IInventory { @Override public String getName() { - return "Inventory"; + return name; } @Override