Ejemplo n.º 1
0
 @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}."));
   }
 }
Ejemplo n.º 2
0
 @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);
 }
Ejemplo n.º 3
0
 // Handle the right-clicking of a wizard
 public static void handleRightClick(Player player, HumanNPC npc, String op) {
   Wizard wizard = npc.getType("wizard");
   String econMsg = "";
   if (EconomyManager.useEconPlugin()) {
     if (EconomyManager.hasEnough(player, UtilityProperties.getPrice(op))) {
       double paid = EconomyManager.pay(player, UtilityProperties.getPrice(op));
       if (paid > 0) {
         econMsg = ChatColor.GREEN + "Paid " + StringUtils.wrap(EconomyManager.format(paid)) + ":";
       }
     } else {
       player.sendMessage(MessageUtils.getNoMoneyMessage(player, op));
       return;
     }
   }
   String msg = StringUtils.wrap(npc.getStrippedName());
   if (op.equals("wizard.teleport")) {
     msg += " teleported you to " + StringUtils.wrap(wizard.getCurrentLocationName()) + ".";
     if (!teleportPlayer(player, npc)) {
       return;
     }
   } else if (op.equals("wizard.spawnmob")) {
     msg +=
         " spawned a "
             + StringUtils.wrap(wizard.getMob().name().toLowerCase().replace("_", " "))
             + ".";
     if (!spawnMob(player, npc)) {
       return;
     }
   } else if (op.equals("wizard.changetime")) {
     msg += " changed the time to " + StringUtils.wrap(wizard.getTime()) + ".";
     if (!changeTime(player, npc)) {
       return;
     }
   } else if (op.equals("wizard.togglestorm")) {
     msg +=
         " toggled a thunderstorm in the world "
             + StringUtils.wrap(player.getWorld().getName())
             + ".";
     if (!toggleStorm(player, npc)) {
       return;
     }
   } else if (op.equals("wizard.executecommand")) {
     msg += " executed the command " + StringUtils.wrap("/" + wizard.getCommand()) + ".";
     if (!executeCommand(player, npc)) {
       return;
     }
     if (!player.performCommand(wizard.getCommand())) {
       return;
     }
   }
   if (EconomyManager.useEconPlugin()) {
     player.sendMessage(econMsg);
   }
   player.sendMessage(msg);
 }
Ejemplo n.º 4
0
 // 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;
 }
Ejemplo n.º 5
0
 @Command(
     aliases = "npc",
     usage = "reset",
     desc = "reset the text of an NPC",
     modifiers = "reset",
     min = 1,
     max = 1)
 @CommandPermissions("basic.modify.resettext")
 public static void reset(CommandContext args, Player player, HumanNPC npc) {
   NPCDataManager.resetText(npc.getUID());
   player.sendMessage(StringUtils.wrap(npc.getName() + "'s") + " text was reset!");
 }
Ejemplo n.º 6
0
 @Command(
     aliases = "npc",
     usage = "tp",
     desc = "teleport to an NPC",
     modifiers = {"tp", "teleport"},
     min = 1,
     max = 1)
 @CommandPermissions("basic.use.teleport")
 public static void teleport(CommandContext args, Player player, HumanNPC npc) {
   player.teleport(npc.getNPCData().getLocation());
   player.sendMessage(
       ChatColor.GREEN + "Teleported you to " + StringUtils.wrap(npc.getName()) + ". Enjoy!");
 }
Ejemplo n.º 7
0
 @Command(
     aliases = "npc",
     usage = "talk",
     desc = "toggle NPC talking on/off",
     modifiers = "talk",
     min = 1,
     max = 1)
 @CommandPermissions("basic.modify.talk")
 public static void talk(CommandContext args, Player player, HumanNPC npc) {
   npc.getNPCData().setTalk(!npc.getNPCData().isTalk());
   player.sendMessage(
       StringUtils.wrap(npc.getName())
           + ((npc.getNPCData().isTalk()) ? "is now talking." : "has stopped talking"));
 }
Ejemplo n.º 8
0
 // Decrease the mana of a wizard
 private static boolean decreaseMana(Player player, HumanNPC npc, int mana) {
   Wizard wizard = npc.getType("wizard");
   if (wizard.hasUnlimitedMana()) {
     return true;
   }
   if (wizard.getMana() - mana >= 0) {
     wizard.setMana(wizard.getMana() - mana);
     player.sendMessage(StringUtils.wrap(npc.getStrippedName()) + " has lost " + mana + " mana.");
     return true;
   }
   player.sendMessage(
       StringUtils.wrap(npc.getStrippedName()) + " does not have enough mana to do that.");
   return false;
 }
Ejemplo n.º 9
0
 @Command(
     aliases = "npc",
     usage = "set [text]",
     desc = "set the text of an NPC",
     modifiers = "set",
     min = 2)
 @CommandPermissions("basic.modify.settext")
 public static void set(CommandContext args, Player player, HumanNPC npc) {
   String text = args.getJoinedStrings(1);
   ArrayDeque<String> texts = new ArrayDeque<String>();
   texts.add(text);
   NPCDataManager.setText(npc.getUID(), texts);
   player.sendMessage(
       StringUtils.wrapFull("{" + npc.getName() + "}'s text was set to {" + text + "}."));
 }
Ejemplo n.º 10
0
  @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"));
  }
Ejemplo n.º 11
0
 @Override
 public void onRightClick(Player player, HumanNPC npc) {
   if (PermissionManager.hasPermission(player, "citizens.wizard.use.interact")) {
     if (UtilityProperties.isHoldingTool("WizardInteractItem", player)) {
       WizardManager.handleRightClick(player, npc, "wizard." + mode.toString());
     } else if (UtilityProperties.isHoldingTool("WizardManaRegenItem", player)) {
       String msg = StringUtils.wrap(npc.getName() + "'s");
       int mana = 0;
       if (mana + 10 < Settings.getInt("WizardMaxMana")) {
         mana = mana + 10;
         msg += " mana has been increased to " + StringUtils.wrap(mana) + ".";
       } else if (mana + 10 == Settings.getInt("WizardMaxMana")) {
         mana = Settings.getInt("WizardMaxMana");
         msg += " mana has been fully replenished.";
       } else {
         msg += " mana cannot be regenerated with that item any further.";
         return;
       }
       InventoryUtils.decreaseItemInHand(player);
       player.sendMessage(msg);
       this.mana = mana;
     }
   } else {
     player.sendMessage(MessageUtils.noPermissionsMessage);
   }
 }
Ejemplo n.º 12
0
 @Override
 public void onLeftClick(Player player, HumanNPC npc) {
   if (PermissionManager.hasPermission(player, "citizens.wizard.use.interact")) {
     if (UtilityProperties.isHoldingTool("WizardInteractItem", player)) {
       String msg = ChatColor.GREEN.toString();
       switch (mode) {
         case TELEPORT:
           if (locations.size() > 0) {
             cycle();
             msg += "Location set to " + StringUtils.wrap(getCurrentLocationName());
           } else {
             msg += ChatColor.RED + npc.getName() + " has no locations.";
           }
           break;
         case SPAWN:
           cycle();
           msg += "Mob to spawn set to " + StringUtils.wrap(StringUtils.format(mob));
           break;
         case TIME:
           cycle();
           msg += "Time setting set to " + StringUtils.wrap(time);
           break;
         case WEATHER:
           return;
         default:
           msg = ChatColor.RED + "No valid mode selected.";
       }
       player.sendMessage(msg);
     }
   } else {
     player.sendMessage(MessageUtils.noPermissionsMessage);
   }
 }
Ejemplo n.º 13
0
 @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()));
   }
 }
Ejemplo n.º 14
0
 @Command(
     aliases = "npc",
     usage = "talkclose",
     desc = "toggle an NPC's talk-when-close setting",
     modifiers = "talkclose",
     min = 1,
     max = 1)
 @CommandPermissions("basic.modify.talkclose")
 public static void talkClose(CommandContext args, Player player, HumanNPC npc) {
   npc.getNPCData().setTalkClose(!npc.getNPCData().isTalkClose());
   if (npc.getNPCData().isTalkClose()) {
     player.sendMessage(StringUtils.wrap(npc.getName()) + " will now talk to nearby players.");
   } else {
     player.sendMessage(StringUtils.wrap(npc.getName()) + " will stop talking to nearby players.");
   }
 }
Ejemplo n.º 15
0
 @Command(
     aliases = "npc",
     usage = "add [text]",
     desc = "add text to an NPC",
     modifiers = "add",
     min = 2)
 @CommandPermissions("basic.modify.addtext")
 public static void add(CommandContext args, Player player, HumanNPC npc) {
   String text = args.getJoinedStrings(1);
   NPCDataManager.addText(npc.getUID(), text);
   player.sendMessage(
       StringUtils.wrap(text)
           + " was added to "
           + StringUtils.wrap(npc.getName() + "'s")
           + " text.");
 }
Ejemplo n.º 16
0
 @Command(
     aliases = "npc",
     usage = "lookat",
     desc = "set an NPC's look-when-close setting",
     modifiers = "lookat",
     min = 1,
     max = 1)
 @CommandPermissions("basic.modify.lookat")
 public static void lookAt(CommandContext args, Player player, HumanNPC npc) {
   npc.getNPCData().setLookClose(!npc.getNPCData().isLookClose());
   if (npc.getNPCData().isLookClose()) {
     player.sendMessage(StringUtils.wrap(npc.getName()) + " will now look at players.");
   } else {
     player.sendMessage(StringUtils.wrap(npc.getName()) + " will stop looking at players.");
   }
 }
Ejemplo n.º 17
0
 @Command(
     aliases = {"wp", "waypoint"},
     usage = "modifier [type]",
     desc = "add a modifier",
     modifiers = {"modifier", "mod"},
     min = 2,
     max = 2)
 public static void modifier(CommandContext args, Player player, HumanNPC npc) {
   if (!NPCDataManager.pathEditors.containsKey(player.getName())) {
     player.sendMessage(ChatColor.GRAY + "You must be editing your NPC's path.");
     return;
   }
   WaypointModifierType modifier = WaypointModifierType.value(args.getString(1).toUpperCase());
   if (modifier == null) {
     player.sendMessage(ChatColor.GRAY + "Invalid modifier type.");
     return;
   }
   if (!PermissionManager.generic(
       player, "citizens.waypoints.modifier" + modifier.name().toLowerCase())) {
     player.sendMessage(MessageUtils.noPermissionsMessage);
     return;
   }
   player.sendMessage(
       ChatColor.AQUA
           + StringUtils.listify(
               StringUtils.wrap(StringUtils.capitalise(modifier.name().toLowerCase()))
                   + " chat editor"
                   + ChatColor.AQUA));
   Waypoint waypoint = npc.getWaypoints().getLast();
   ConversationUtils.addConverser(player, modifier.create(waypoint));
 }
Ejemplo n.º 18
0
 /**
  * Uses craftbukkit methods to show a player an npc's inventory screen.
  *
  * @param npc
  * @param player
  */
 public static void showInventory(HumanNPC npc, Player player) {
   NPCInventoryOpenEvent inventoryOpenEvent = new NPCInventoryOpenEvent(npc, player);
   if (inventoryOpenEvent.isCancelled()) {
     return;
   }
   ((CraftPlayer) player).getHandle().a(npc.getHandle().inventory);
 }
Ejemplo n.º 19
0
 // Spawn mob(s) at the specified location
 private static boolean spawnMob(Player player, HumanNPC npc) {
   if (decreaseMana(player, npc, SettingsManager.getInt("SpawnMobManaCost"))) {
     player
         .getWorld()
         .spawnCreature(player.getLocation(), ((Wizard) npc.getType("wizard")).getMob());
     return true;
   }
   return false;
 }
Ejemplo n.º 20
0
 @Command(
     aliases = "npc",
     usage = "move",
     desc = "move an NPC",
     modifiers = "move",
     min = 1,
     max = 1)
 @CommandPermissions("basic.modify.move")
 public static void move(CommandContext args, Player player, HumanNPC npc) {
   if (npc.getWorld() != player.getWorld()
       && !PermissionManager.hasPermission(player, "citizens.basic.modify.move.multiworld")) {
     player.sendMessage(ChatColor.GRAY + "You don't have permission to move NPCs between worlds.");
     return;
   }
   player.sendMessage(StringUtils.wrap(npc.getName()) + " is en route to your location!");
   npc.teleport(player.getLocation());
   npc.getNPCData().setLocation(player.getLocation());
 }
Ejemplo n.º 21
0
 @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);
 }
Ejemplo n.º 22
0
 @Command(aliases = "citizens", desc = "view Citizens info", modifiers = "clean", max = 1)
 @ServerCommand()
 @CommandPermissions("admin.clean")
 @CommandRequirements()
 public static void clean(CommandContext args, CommandSender sender, HumanNPC npc) {
   sender.sendMessage(ChatColor.GRAY + "Cleaning up...");
   int count = 0;
   for (World world : Bukkit.getServer().getWorlds()) {
     for (Entity entity : world.getEntities()) {
       net.minecraft.server.v1_4_6.Entity mcEntity = ((CraftEntity) entity).getHandle();
       if (!(mcEntity instanceof CraftNPC) || mcEntity instanceof CreatureNPC) continue;
       HumanNPC found = ((CraftNPC) mcEntity).npc;
       if (NPCManager.get(found.getUID()) == found) continue;
       NPCSpawner.despawnNPC(found, NPCRemoveReason.OTHER);
       ++count;
     }
   }
   sender.sendMessage(
       ChatColor.GREEN + "Done. Removed " + StringUtils.wrap(count) + " orphaned NPCs.");
 }
Ejemplo n.º 23
0
 @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);
 }
Ejemplo n.º 24
0
 @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)
           + ".");
 }
Ejemplo n.º 25
0
 @Command(
     aliases = "npc",
     usage = "wander",
     desc = "makes an NPC wander like a mob",
     modifiers = "wander",
     min = 1,
     max = 1)
 @CommandPermissions("basic.modify.wander")
 public static void wander(CommandContext args, Player player, HumanNPC npc) {
   boolean useAutoPathfinder = npc.getHandle().toggleAutoPathfinder();
   player.sendMessage(
       ChatColor.GREEN
           + (useAutoPathfinder ? "The NPC is now wandering." : "The NPC has stopped wandering."));
 }
Ejemplo n.º 26
0
 // Change the time in the player's world
 private static boolean changeTime(Player player, HumanNPC npc) {
   long time = 0;
   Wizard wizard = npc.getType("wizard");
   if (wizard.getTime().equals("day")) {
     time = 5000;
   } else if (wizard.getTime().equals("night")) {
     time = 13000;
   } else if (wizard.getTime().equals("morning")) {
     time = 0;
   } else if (wizard.getTime().equals("afternoon")) {
     time = 10000;
   }
   if (decreaseMana(player, npc, SettingsManager.getInt("ChangeTimeManaCost"))) {
     player.getWorld().setTime(time);
     return true;
   }
   return false;
 }
Ejemplo n.º 27
0
 @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)
           + ".");
 }
Ejemplo n.º 28
0
 @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.");
 }
Ejemplo n.º 29
0
 @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);
 }
Ejemplo n.º 30
0
  @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);
            }
          }
        }
      }
    }
  }