@Command( aliases = "npc", usage = "color [color-code]", desc = "set the name color of an NPC", modifiers = "color", min = 2, max = 2) @CommandPermissions("basic.modify.color") public static void color(CommandContext args, Player player, HumanNPC npc) { if (!args.getString(1).substring(0, 1).equals("&")) { player.sendMessage(ChatColor.RED + "Use an & to specify color."); } else if (args.getString(1).length() != 2) { player.sendMessage(ChatColor.GRAY + "Use the format &(code). Example - &f = white."); } else { char colour = args.getString(1).charAt(1); if (ChatColor.getByChar(colour) == null) { player.sendMessage(ChatColor.RED + "Color code not recognised."); return; } npc.getNPCData().setColour(ChatColor.getByChar(colour)); NPCManager.setColour(npc.getUID(), npc.getOwner()); player.sendMessage( StringUtils.wrapFull( "{" + npc.getName() + "}'s name color is now " + args.getString(1).replace("&", "\u00A7") + "this}.")); } }
@CommandRequirements(requireSelected = true) @Command(aliases = "npc", desc = "view information for an NPC", max = 0) @CommandPermissions("basic.use.info") public static void npc(CommandContext args, CommandSender sender, HumanNPC npc) { sender.sendMessage(ChatColor.GREEN + StringUtils.listify(StringUtils.wrap(npc.getName()))); sender.sendMessage(ChatColor.GREEN + "ID: " + StringUtils.wrap(npc.getUID())); sender.sendMessage(ChatColor.GREEN + "Owner: " + StringUtils.wrap(npc.getOwner())); sender.sendMessage(ChatColor.GREEN + "Types:"); if (npc.types().size() == 0) { sender.sendMessage(ChatColor.RED + " None"); return; } for (CitizensNPC type : npc.types()) { sender.sendMessage(ChatColor.GRAY + " - " + StringUtils.wrap(type.getType().getName())); } }
@Command( aliases = "npc", usage = "rename [name]", desc = "rename an NPC", modifiers = "rename", min = 2, max = 2) @CommandPermissions("basic.modify.rename") public static void rename(CommandContext args, Player player, HumanNPC npc) { String name = args.getString(1); if (name.length() > 16) { player.sendMessage( ChatColor.RED + "Max name length is 16 - NPC name length will be truncated."); name = name.substring(0, 16); } NPCManager.rename(npc.getUID(), name, npc.getOwner()); player.sendMessage( ChatColor.GREEN + StringUtils.wrap(npc.getName()) + "'s name was set to " + StringUtils.wrap(name) + "."); }
@Override public void run() { for (HumanNPC npc : CitizensManager.getList().values()) { if (npc.isType("guard")) { Guard guard = npc.getType("guard"); if (guard.isAttacking()) { boolean cancel = false; if (!npc.getHandle().hasTarget() || !guard.isAggressive()) { cancel = true; } else if (npc.getHandle().hasTarget() && !LocationUtils.withinRange( npc.getBaseLocation(), npc.getHandle().getTarget().getLocation(), guard.getProtectionRadius())) { cancel = true; } else if (npc.getHandle().hasTarget() && guard.isBodyguard() && Bukkit.getServer().getPlayer(npc.getOwner()) != null) { Player player = Bukkit.getServer().getPlayer(npc.getOwner()); if (npc.getHandle().getTarget() != player && !LocationUtils.withinRange( npc.getBaseLocation(), player.getLocation(), guard.getProtectionRadius())) { cancel = true; } } if (cancel) { npc.getHandle().cancelTarget(); GuardManager.returnToBase(guard, npc); guard.setAttacking(false); } } if (LocationUtils.withinRange(npc.getLocation(), npc.getBaseLocation(), 3.5)) { if (guard.isReturning()) { guard.setReturning(false); } if (!guard.isAttacking() && npc.isPaused()) { npc.setPaused(false); } } else if (guard.isReturning() && npc.getHandle().getStationaryTicks() > SettingsManager.getInt("MaxStationaryReturnTicks")) { npc.teleport(npc.getBaseLocation()); guard.setReturning(false); } if (guard.isAttacking() || guard.isReturning()) { continue; } if (guard.isBouncer()) { handleTarget(npc.getPlayer(), npc, guard); } else if (guard.isBodyguard()) { if (!npc.isPaused()) { npc.setPaused(true); } Player p = Bukkit.getServer().getPlayer(npc.getOwner()); if (p != null) { handleTarget(p, npc, guard); if (LocationUtils.withinRange( npc.getLocation(), p.getLocation(), guard.getProtectionRadius())) { PathUtils.target(npc, p, false, -1, -1, 25); } else { npc.teleport(p.getLocation()); } } else { if (CitizensManager.getNPC(npc.getUID()) != null) { toRespawn.put( npc.getOwner(), new NPCLocation(npc.getLocation(), npc.getUID(), npc.getOwner())); NPCManager.despawn(npc.getUID(), NPCRemoveReason.DEATH); } } } } } }