@CommandRequirements() @Command( aliases = "citizens", usage = "reload", desc = "reload Citizens", modifiers = "reload", min = 1, max = 1) @CommandPermissions("admin.reload") @ServerCommand() public static void reload(CommandContext args, CommandSender sender, HumanNPC npc) { Messaging.log("Reloading configuration settings...."); if (sender instanceof Player) { sender.sendMessage(ChatColor.GREEN + "[" + StringUtils.wrap("Citizens") + "] Reloading...."); } PropertyManager.loadAll(); Settings.setupVariables(); Bukkit.getServer().getPluginManager().callEvent(new CitizensReloadEvent()); Messaging.log("Reloaded."); if (sender instanceof Player) { sender.sendMessage(ChatColor.GREEN + "[" + StringUtils.wrap("Citizens") + "] Reloaded."); } }
@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 = "citizens", usage = "debug", desc = "toggle debug mode for Citizens", modifiers = "debug", min = 1, max = 1) @ServerCommand() @CommandPermissions("admin.debug") public static void debug(CommandContext args, CommandSender sender, HumanNPC npc) { boolean debug = Settings.getBoolean("DebugMode"); UtilityProperties.getConfig().setRaw("general.debug-mode", !debug); debug = !debug; if (debug) { Messaging.log("Debug mode is now on."); if (sender instanceof Player) { Messaging.send(sender, npc, "Debug mode is now " + ChatColor.GREEN + "on"); } } else { Messaging.log("Debug mode is now off."); if (sender instanceof Player) { Messaging.send(sender, npc, "Debug mode is now " + ChatColor.RED + "off"); } } }
@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")); }
@CommandRequirements() @Command( aliases = "npc", usage = "setowner [name]", desc = "set the owner of an NPC", modifiers = "setowner", min = 2, max = 2) public static void setOwner(CommandContext args, Player player, HumanNPC npc) { if ((!NPCManager.isOwner(player, npc.getUID()) && PermissionManager.hasPermission(player, "citizens.admin.override.setowner")) || (NPCManager.isOwner(player, npc.getUID()) && PermissionManager.hasPermission(player, "citizens.basic.modify.setowner"))) { player.sendMessage( ChatColor.GREEN + "The owner of " + StringUtils.wrap(npc.getName()) + " is now " + StringUtils.wrap(args.getString(1)) + "."); npc.getNPCData().setOwner(args.getString(1)); return; } Messaging.sendError(player, MessageUtils.noPermissionsMessage); }
@Override public boolean find() { try { PathNode root = new PathNode(); root.point = start; calculateTotalCost(root, start, start, false); expand(root); int iterations = 0; while (true) { PathNode p = paths.remove(); if (p == null) { clear(); return false; } Point last = p.point; if (isGoal(last)) { calculatePath(p); // Iterate back. clear(); return true; } expand(p); ++iterations; if (iterations > 20000) { Messaging.log("took too long"); return false; } } } catch (Exception e) { e.printStackTrace(); } clear(); return false; }
@Override public void onPluginDisable(PluginDisableEvent event) { if (this.methods != null && this.methods.hasMethod()) { Boolean check = this.methods.checkDisabled(event.getPlugin()); if (check) { Messaging.log("Payment method disabled."); } EconomyManager.setServerEconomyEnabled(false); } }
public String getMessageForEventAnJobAndLevel(int job, int event, int level) { DStringValue tmpString = getStringValue(new DMessageKey(event, job, level)); if (tmpString != null) { return tmpString.getString(); } String infos = " [job:" + job + ",event:" + event + ",level:" + level + "]"; Messaging.log("Missing message:" + infos); return DMessageStore.ERROR + infos; }
// Teleport a player to one of a wizard's locations private static boolean teleportPlayer(Player player, HumanNPC npc) { Wizard wizard = npc.getType("wizard"); if (wizard.getNumberOfLocations() > 0) { if (decreaseMana(player, npc, SettingsManager.getInt("TeleportManaCost"))) { player.teleport(wizard.getCurrentLocation()); return true; } return false; } Messaging.sendError(player, npc.getStrippedName() + " has no locations."); return false; }
@Command( aliases = "blacksmith", usage = "status", desc = "view the status of your in-hand item", modifiers = "status", min = 1, max = 1) @CommandPermissions("blacksmith.use.status") public static void cost(CommandContext args, Player player, HumanNPC npc) { ItemStack item = player.getItemInHand(); String repairType = ""; if (InventoryUtils.isArmor(item)) { repairType = "armorrepair"; } else if (InventoryUtils.isTool(item)) { repairType = "toolrepair"; } if (repairType.isEmpty()) { Messaging.sendError( player, MessageUtils.getMaterialName(item.getTypeId()) + " is not a repairable item."); return; } if (EconomyManager.useEconPlugin()) { double price = BlacksmithManager.getBlacksmithPrice(player, repairType); player.sendMessage( ChatColor.GREEN + "Item: " + StringUtils.wrap(MessageUtils.getMaterialName(item.getTypeId()))); player.sendMessage( ChatColor.GREEN + "Cost: " + StringUtils.wrap(EconomyManager.format(price))); player.sendMessage( ChatColor.GREEN + "Durability Remaining: " + StringUtils.wrap( Material.getMaterial(item.getTypeId()).getMaxDurability() - item.getDurability())); } else { Messaging.sendError(player, "This server is not using an economy system."); } }
@CommandRequirements() @Command( aliases = "npc", usage = "remove (all)", desc = "remove NPCs", modifiers = "remove", min = 1, max = 2) public static void remove(CommandContext args, Player player, HumanNPC npc) { if (args.argsLength() == 2 && args.getString(1).equalsIgnoreCase("all")) { if (PermissionManager.hasPermission(player, "citizens.basic.modify.remove.all")) { if (NPCManager.GlobalUIDs.size() == 0) { Messaging.sendError(player, "There are no NPCs to remove."); return; } NPCManager.removeAll(NPCRemoveReason.COMMAND); NPCDataManager.deselectNPC(player); player.sendMessage(ChatColor.GRAY + "The NPC(s) disappeared."); } else { Messaging.sendError(player, MessageUtils.noPermissionsMessage); } return; } if (npc == null) { player.sendMessage(MessageUtils.mustHaveNPCSelectedMessage); return; } if ((!NPCManager.isOwner(player, npc.getUID()) && PermissionManager.hasPermission(player, "citizens.admin.override.remove")) || (NPCManager.isOwner(player, npc.getUID()) && PermissionManager.hasPermission(player, "citizens.basic.modify.remove"))) { NPCManager.remove(npc.getUID(), NPCRemoveReason.COMMAND); NPCDataManager.deselectNPC(player); player.sendMessage(StringUtils.wrap(npc.getName(), ChatColor.GRAY) + " disappeared."); return; } Messaging.sendError(player, MessageUtils.noPermissionsMessage); }
@CommandRequirements() @Command( aliases = "citizens", usage = "save", desc = "force a save of Citizens files", modifiers = "save", min = 1, max = 1) @ServerCommand() @CommandPermissions("admin.save") public static void save(CommandContext args, CommandSender sender, HumanNPC npc) { if (sender instanceof Player) { Messaging.log("Saving..."); } sender.sendMessage(ChatColor.GREEN + "[" + StringUtils.wrap("Citizens") + "] Saving..."); PropertyManager.saveState(); if (sender instanceof Player) { Messaging.log("Saved."); } sender.sendMessage(ChatColor.GREEN + "[" + StringUtils.wrap("Citizens") + "] Saved."); }
@Override public void onPluginEnable(PluginEnableEvent event) { if (!this.methods.hasMethod()) { if (this.methods.setMethod(event.getPlugin())) { Citizens.setMethod(this.methods.getMethod()); EconomyManager.setServerEconomyEnabled(true); Messaging.log( "Payment method found (" + methods.getMethod().getName() + " version: " + methods.getMethod().getVersion() + ")"); } } }
@Command( aliases = "npc", usage = "equip", desc = "toggle equip mode", modifiers = "equip", min = 1, max = 1) @CommandPermissions("basic.modify.equip") public static void equip(CommandContext args, Player player, HumanNPC npc) { if (NPCDataManager.pathEditors.containsKey(player)) { Messaging.sendError(player, "You can only be in one editor at a time."); return; } Integer editing = NPCDataManager.equipmentEditors.get(player); int UID = npc.getUID(); if (editing == null) { player.sendMessage( ChatColor.GREEN + StringUtils.listify(StringUtils.wrap("Now Editing " + npc.getName() + "'s Items"))); player.sendMessage(StringUtils.wrap("Right-click") + " to set an NPC's equipment."); player.sendMessage( ChatColor.GREEN + "Hold nothing in your hand to remove " + StringUtils.wrap("all") + " items."); player.sendMessage(StringUtils.wrap("Sneak") + " to set the item-in-hand to armor."); player.sendMessage(StringUtils.wrap("Repeat") + " the command to exit equipment-edit mode."); editing = UID; } else if (editing == UID) { player.sendMessage(StringUtils.wrap("Exited") + " equipment-edit mode."); NPCDataManager.equipmentEditors.remove(player); editing = null; return; } else if (editing != UID) { player.sendMessage( ChatColor.GRAY + "Now editing " + StringUtils.wrap(npc.getName(), ChatColor.GRAY) + "'s equipment."); editing = UID; } NPCDataManager.equipmentEditors.put(player, editing); }
@Command( aliases = "npc", usage = "moveto [x y z] (world pitch yaw)", desc = "move an NPC to a location", modifiers = "moveto", min = 4, max = 7) @CommandPermissions("basic.modify.moveto") public static void moveTo(CommandContext args, Player player, HumanNPC npc) { double x = 0, y = 0, z = 0; float yaw = npc.getLocation().getYaw(), pitch = npc.getLocation().getPitch(); String world = npc.getWorld().getName(); switch (args.argsLength()) { case 7: yaw = Float.parseFloat(args.getString(6)); case 6: pitch = Float.parseFloat(args.getString(5)); case 5: world = args.getString(4); if (Bukkit.getServer().getWorld(world) == null) { Messaging.sendError(player, "Invalid world."); return; } case 4: x = Double.parseDouble(args.getString(1)); y = Double.parseDouble(args.getString(2)); z = Double.parseDouble(args.getString(3)); } Location loc = new Location(Bukkit.getServer().getWorld(world), x, y, z, pitch, yaw); npc.teleport(loc); npc.getNPCData().setLocation(loc); player.sendMessage( StringUtils.wrap(npc.getName()) + " moved to the coordinates " + StringUtils.wrap(x) + ", " + StringUtils.wrap(y) + ", " + StringUtils.wrap(z) + " in the world " + StringUtils.wrap(world) + "."); }
@Command( aliases = "npc", usage = "select [id]", desc = "select an NPC by its ID", modifiers = "select", min = 2, max = 2) @CommandPermissions("basic.use.select") @CommandRequirements() public static void select(CommandContext args, Player player, HumanNPC npc) { npc = NPCManager.get(args.getInteger(1)); if (npc == null) { player.sendMessage( ChatColor.RED + "No NPC with ID " + StringUtils.wrap(args.getString(1), ChatColor.RED) + " exists."); } else { NPCDataManager.selectNPC(player, npc); Messaging.send(player, npc, 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; } }
@Command( aliases = "npc", usage = "[path|waypoints] (reset|index)", desc = "toggle waypoint editing", modifiers = {"path", "waypoints"}, min = 1, max = 2) @CommandPermissions("waypoints.edit") public static void waypoints(CommandContext args, Player player, HumanNPC npc) { if (args.argsLength() >= 2 && args.getString(1).equalsIgnoreCase("reset")) { npc.getWaypoints().resetWaypoints(); player.sendMessage(ChatColor.GREEN + "Waypoints " + StringUtils.wrap("reset") + "."); return; } if (NPCDataManager.equipmentEditors.containsKey(player)) { Messaging.sendError(player, "You can only be in one editor at a time."); return; } int index = npc.getWaypoints().size() - 1; if (args.argsLength() == 2 && StringUtils.isNumber(args.getString(1))) { index = args.getInteger(1) - 1; if (index < 0) index = 0; if (npc.getWaypoints().size() != 0 && index >= npc.getWaypoints().size()) { player.sendMessage( ChatColor.GRAY + "Index out of bounds. This NPC only has " + StringUtils.wrap(npc.getWaypoints().size()) + " waypoints."); return; } } if (index < 0) index = 0; PathEditingSession editing = NPCDataManager.pathEditors.get(player); int UID = npc.getUID(); if (editing == null) { player.sendMessage(ChatColor.AQUA + StringUtils.listify("Waypoint Editing Controls")); player.sendMessage( StringUtils.wrap("Left") + " click adds a waypoint, while " + StringUtils.wrap("right") + " click acts as an undo."); player.sendMessage( StringUtils.wrap("Right clicking") + " the NPC will cause him to restart from the current index."); player.sendMessage(StringUtils.wrap("Repeat") + " this command to finish."); editing = new PathEditingSession(UID, index); } else if (editing.getUID() == UID && args.argsLength() == 1) { player.sendMessage(StringUtils.wrap("Finished") + " editing waypoints."); NPCDataManager.pathEditors.remove(player); return; } else if (editing.getUID() != UID) { player.sendMessage( ChatColor.GRAY + "Now editing " + StringUtils.wrap(npc.getName()) + "'s waypoints."); editing = new PathEditingSession(UID, index); } if (npc.getWaypoints().size() > 0) { npc.getWaypoints().setIndex(index); npc.teleport(npc.getWaypoints().get(index).getLocation()); } NPCDataManager.pathEditors.put(player, editing); }