Esempio n. 1
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);
 }
Esempio n. 2
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"));
  }
Esempio n. 3
0
 public static void checkRespawn(Player player) {
   String owner = player.getName();
   if (toRespawn.containsKey(owner)) {
     NPCManager.register(toRespawn.get(owner).getUID(), owner, NPCCreateReason.RESPAWN);
     CitizensManager.getNPC(toRespawn.get(owner).getUID()).teleport(player.getLocation());
   }
 }
Esempio n. 4
0
 @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")));
   }
 }
Esempio n. 5
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}."));
   }
 }
Esempio n. 6
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);
 }
Esempio n. 7
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.");
 }
Esempio n. 8
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.");
 }
Esempio n. 9
0
 @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"));
   }
 }
Esempio n. 10
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)
           + ".");
 }
Esempio n. 11
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);
            }
          }
        }
      }
    }
  }