/**
  * 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);
 }
 @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."));
 }
Exemple #3
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);
            }
          }
        }
      }
    }
  }