@Override public void onRightClick(Player player) { if (!PermissionManager.canCreate(player)) { Messaging.sendError( player, "You cannot tame this Evil NPC because you have reached the NPC creation limit."); return; } if (player.getItemInHand().getTypeId() != Settings.getInt("EvilTameItem")) return; if (random.nextInt(100) <= Settings.getInt("EvilTameChance")) { InventoryUtils.decreaseItemInHand(player); isTame = true; CreatureTask.despawn(this, NPCRemoveReason.OTHER); NPCManager.register( npc.getName(), player.getLocation(), player.getName(), NPCCreateReason.RESPAWN); player.sendMessage( ChatColor.GREEN + "You have tamed " + StringUtils.wrap(npc.getName()) + "! You can now toggle it to be any type."); } else { Messaging.send( player, this.npc, StringUtils.colourise(Settings.getString("ChatFormat").replace("%name%", npc.getName())) + ChatColor.WHITE + MessageUtils.getRandomMessage(Settings.getString("EvilFailedTameMessages"))); } }
@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 = "copy", desc = "copy an NPC", modifiers = "copy", min = 1, max = 1) @CommandPermissions("basic.modify.copy") public static void copy(CommandContext args, Player player, HumanNPC npc) { if (!PermissionManager.canCreate(player)) { player.sendMessage(MessageUtils.reachedNPCLimitMessage); return; } PropertyManager.save(npc); int newUID = NPCManager.register( npc.getName(), player.getLocation(), player.getName(), NPCCreateReason.COMMAND); HumanNPC newNPC = NPCManager.get(newUID); PropertyManager.copyNPCs(npc.getUID(), newUID); PropertyManager.load(newNPC); newNPC.teleport(player.getLocation()); newNPC.getNPCData().setLocation(player.getLocation()); player.sendMessage(StringUtils.wrap(npc.getName()) + " has been copied at your location."); }