disallow names greater than 16 characters in length as per vanilla spec

This commit is contained in:
aPunch 2012-02-05 04:24:11 -06:00
parent 368628094c
commit 10a9319aa4
2 changed files with 51 additions and 14 deletions

View File

@ -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);

View File

@ -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