@Override
 public void run() {
   for (Pet cosmetic : this.module.getParent().getApi().getAllCosmetics(Pet.class)) {
     Creature entity = cosmetic.getEntity();
     Player p = cosmetic.getPlayer();
     if (!entity.getWorld().getName().equalsIgnoreCase(p.getWorld().getName())
         || entity.getLocation().distance(p.getLocation())
             >= this.module.getConfig().getTeleportDistance()) {
       entity.teleport(p);
       entity.setTarget(p);
     }
   }
 }
Esempio n. 2
0
  /**
   * Spawn guard wolves to this prisoner to kill him
   *
   * @param num Number of guards to spawn
   * @param location Spawning location
   * @param player Player, associated with this JailPrisoner
   */
  public void spawnGuards(int num, Location location, Player player) {
    List<BlockFace> checkedCorners = new ArrayList<BlockFace>();
    for (int i = 0; i < num; i++) {
      Location spawn = null;
      for (int ci = 0; ci < 4; ci++) {
        Block block = location.getBlock().getRelative(BlockFace.values()[ci]);
        if (!checkedCorners.contains(BlockFace.values()[ci])
            && (block.getType() == Material.AIR
                || block.getType() == Material.STATIONARY_WATER
                || block.getType() == Material.WATER)) {
          spawn = block.getLocation();
          checkedCorners.add(BlockFace.values()[ci]);
          break;
        }
      }
      if (spawn == null) {
        checkedCorners.clear();
        for (int ci = 0; ci < 3; ci++) {
          if (!checkedCorners.contains(BlockFace.values()[ci])
                  && location.getBlock().getRelative(BlockFace.values()[ci]).getType()
                      == Material.AIR
              || location.getBlock().getRelative(BlockFace.values()[ci]).getType()
                  == Material.STATIONARY_WATER) {
            spawn = location.getBlock().getRelative(BlockFace.NORTH).getLocation();
            checkedCorners.add(BlockFace.values()[ci]);
          }
        }
        if (spawn == null) spawn = location;
      }

      List<String> guardTypes = (List<String>) jail.getSettings().getList(Setting.GuardTypes);
      String pickedType = guardTypes.get(new Random().nextInt(guardTypes.size()));

      EntityType type = EntityType.fromName(pickedType);

      if (type == null
          || !type.isSpawnable()
          || !Creature.class.isAssignableFrom(type.getEntityClass())) {
        Jail.log.severe("[Jail] Invalid GuardTypes config! " + pickedType + " cannot be spawned.");
        type = EntityType.CHICKEN;
      }

      Creature guard = (Creature) location.getWorld().spawn(spawn, type.getEntityClass());

      if (!(guard.getWorld().getEntities().contains(guard))) {
        canSpawnGuards = false;
        return;
      }

      int health = getJail().getSettings().getInt(Setting.GuardHealth);
      if (health > guard.getMaxHealth()) {
        Jail.log.warning(
            "[Jail] Guard health cannot be more than "
                + guard.getMaxHealth()
                + "! Use Armor to increase toughness of your guards!");
        health = guard.getMaxHealth();
      }

      guardTargets.add(player);

      guard.setHealth(health);

      guard.setTarget(player);

      getGuards().add(guard);
      Jail.guards.put(guard, this);
    }
  }