mob type is optional for create command

This commit is contained in:
aPunch 2012-02-05 07:02:47 -06:00
parent 4067a85bce
commit 6c47757453
2 changed files with 14 additions and 11 deletions

View File

@ -34,26 +34,26 @@ public class NPCCommands {
@Command(
aliases = { "npc" },
usage = "create [name] [type] (character)",
usage = "create [name] (type) (character)",
desc = "Create a new NPC",
modifiers = { "create" },
min = 3,
min = 2,
max = 4)
@Permission("npc.create")
@Requirements
public void createNPC(CommandContext args, Player player, NPC npc) {
CreatureType type = CreatureType.MONSTER; // Default human type
try {
type = CreatureType.valueOf(args.getString(2).toUpperCase().replace('-', '_'));
} catch (IllegalArgumentException ex) {
Messaging.sendError(player, "'" + args.getString(2) + "' is not a valid mob type. Using default NPC.");
}
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);
}
CreatureType type = CreatureType.MONSTER; // Default NPC type
if (args.argsLength() != 2)
try {
type = CreatureType.valueOf(args.getString(2).toUpperCase().replace('-', '_'));
} catch (IllegalArgumentException ex) {
Messaging.sendError(player, "'" + args.getString(2) + "' is not a valid mob type. Using default NPC.");
}
NPC create = npcManager.createNPC(type, name);
String successMsg = ChatColor.GREEN + "You created " + StringHelper.wrap(create.getName());
boolean success = true;

View File

@ -65,8 +65,11 @@ public class Inventory implements Trait {
Map<Enchantment, Integer> enchantments = new HashMap<Enchantment, Integer>();
for (DataKey subKey : key.getRelative("enchantments").getSubKeys()) {
Enchantment enchantment = Enchantment.getByName(subKey.name().toUpperCase().replace('-', '_'));
if (enchantment != null)
enchantments.put(enchantment, subKey.getInt(""));
if (enchantment != null && enchantment.canEnchantItem(item))
enchantments.put(
enchantment,
subKey.getInt("") <= enchantment.getMaxLevel() ? subKey.getInt("") : enchantment
.getMaxLevel());
}
item.addEnchantments(enchantments);
}