@CommandRequirements() @Command( aliases = "npc", usage = "create [name] (text)", desc = "create an NPC", modifiers = "create", min = 2) @CommandPermissions("basic.create") public static void create(CommandContext args, Player player, HumanNPC npc) { if (!PermissionManager.canCreate(player)) { player.sendMessage(MessageUtils.reachedNPCLimitMessage); return; } ArrayDeque<String> texts = new ArrayDeque<String>(); String firstArg = args.getString(1); if (args.argsLength() >= 3) { texts.add(args.getJoinedStrings(2)); } if (firstArg.length() > 16) { player.sendMessage( ChatColor.RED + "The name of this NPC will be truncated - max name length is 16."); firstArg = args.getString(1).substring(0, 16); } if (Economy.useEconPlugin()) { if (Economy.hasEnough(player, UtilityProperties.getPrice("basic.creation"))) { double paid = Economy.pay(player, UtilityProperties.getPrice("basic.creation")); if (paid > 0) { player.sendMessage( MessageUtils.getPaidMessage( player, "basic", "basic.creation", firstArg.replace("/", " "), false)); } } else { player.sendMessage(MessageUtils.getNoMoneyMessage(player, "basic.creation")); return; } } int UID = NPCManager.register( firstArg, player.getLocation(), player.getName(), NPCCreateReason.COMMAND); NPCDataManager.setText(UID, texts); HumanNPC created = NPCManager.get(UID); created.getNPCData().setOwner(player.getName()); Messaging.send(player, created, Settings.getString("CreationMessage")); NPCDataManager.selectNPC(player, NPCManager.get(UID)); Messaging.send(player, created, Settings.getString("SelectionMessage")); }
@Command( aliases = "npc", usage = "money (give|take) (amount)", desc = "control an npc's balance", modifiers = "money", min = 1, max = 3) public static void money(CommandContext args, Player player, HumanNPC npc) { switch (args.argsLength()) { case 1: if (PermissionManager.hasPermission(player, "citizens.basic.use.showmoney")) { player.sendMessage( StringUtils.wrap(npc.getName()) + " has " + StringUtils.wrap(Economy.format(npc.getBalance())) + "."); } else { player.sendMessage(MessageUtils.noPermissionsMessage); } break; case 3: if (!PermissionManager.hasPermission(player, "citizens.basic.modify.money")) { player.sendMessage(MessageUtils.noPermissionsMessage); return; } double amount; try { amount = Double.parseDouble(args.getString(2)); } catch (NumberFormatException e) { Messaging.sendError(player, "Invalid balance change amount entered."); return; } String keyword = "Took "; if (args.getString(1).contains("g")) { if (Economy.hasEnough(player, amount)) { keyword = "Gave "; Economy.pay(npc, -amount); Economy.pay(player, amount); } else { player.sendMessage( ChatColor.RED + "You don't have enough money for that! Need " + StringUtils.wrap( Economy.format(amount - Economy.getBalance(player.getName())), ChatColor.RED) + " more."); return; } } else if (args.getString(1).contains("t")) { if (Economy.hasEnough(npc, amount)) { Economy.pay(npc, amount); Economy.pay(player, -amount); } else { player.sendMessage( ChatColor.RED + "The npc doesn't have enough money for that! It needs " + StringUtils.wrap(Economy.format(amount - npc.getBalance()), ChatColor.RED) + " more in its balance."); return; } } else { player.sendMessage( ChatColor.RED + "Invalid argument type " + StringUtils.wrap(args.getString(1), ChatColor.RED) + "."); return; } player.sendMessage( ChatColor.GREEN + keyword + StringUtils.wrap(Economy.format(amount)) + " to " + StringUtils.wrap(npc.getName()) + ". Your balance is now " + StringUtils.wrap(Economy.getFormattedBalance(player.getName())) + "."); break; default: Messaging.sendError(player, "Incorrect syntax. See /npc help"); break; } }