Ejemplo n.º 1
0
 private void heal(List<Entity> entities, int amount) {
   entities.forEach(
       e -> {
         Status status = currentStatusStore.get(e.getUniqueId());
         status.heal(amount);
         e.getWorld().playEffect(e.getLocation(), Effect.POTION_BREAK, 0);
       });
 }
Ejemplo n.º 2
0
  @Override
  protected boolean startup() {
    if (executorMonster != null) {
      switch (target) {
        case MYSELF:
          targetEntities.add(executor);
          break;
        case NEARBYMONSTER:
          Entity te =
              executor
                  .getWorld()
                  .getEntities()
                  .stream()
                  .filter(e -> monsterManager.isMonster(e))
                  .filter(e -> e.getLocation().distance(executor.getLocation()) <= 16)
                  .sorted(
                      (Entity o1, Entity o2) -> {
                        return o1.getLocation().distance(executor.getLocation())
                                < o2.getLocation().distance(executor.getLocation())
                            ? -1
                            : 1;
                      })
                  .findFirst()
                  .orElse(null);
          if (te != null) targetEntities.add(te);
          break;
        case NEARBYPLAYER:
          Player tp =
              executor
                  .getWorld()
                  .getPlayers()
                  .stream()
                  .filter(p -> p.getLocation().distance(executor.getLocation()) <= 16)
                  .sorted(
                      (Player o1, Player o2) -> {
                        return o1.getLocation().distance(executor.getLocation())
                                < o2.getLocation().distance(executor.getLocation())
                            ? -1
                            : 1;
                      })
                  .findFirst()
                  .orElse(null);
          if (tp != null) targetEntities.add(tp);
          break;
        case RANGE:
          executor
              .getWorld()
              .getEntities()
              .stream()
              .filter(e -> monsterManager.isMonster(e))
              .filter(e -> e.getLocation().distance(executor.getLocation()) <= range)
              .forEach(e -> targetEntities.add(e));
          break;
      }
    } else {
      switch (target) {
        case MYSELF:
          targetEntities.add(executor);
          break;
        case NEARBYMONSTER:
          Entity te =
              executor
                  .getWorld()
                  .getEntities()
                  .stream()
                  .filter(e -> monsterManager.isMonster(e))
                  .filter(e -> e.getLocation().distance(executor.getLocation()) <= 16)
                  .sorted(
                      (Entity o1, Entity o2) -> {
                        return o1.getLocation().distance(executor.getLocation())
                                < o2.getLocation().distance(executor.getLocation())
                            ? -1
                            : 1;
                      })
                  .findFirst()
                  .orElse(null);
          if (te != null) targetEntities.add(te);
          break;
        case NEARBYPLAYER:
          Player tp =
              executor
                  .getWorld()
                  .getPlayers()
                  .stream()
                  .filter(p -> p.getLocation().distance(executor.getLocation()) <= 16)
                  .sorted(
                      (Player o1, Player o2) -> {
                        return o1.getLocation().distance(executor.getLocation())
                                < o2.getLocation().distance(executor.getLocation())
                            ? -1
                            : 1;
                      })
                  .findFirst()
                  .orElse(null);
          if (tp != null) targetEntities.add(tp);
          break;
        case RANGE:
          Bukkit.getOnlinePlayers()
              .stream()
              .filter(p -> monsterManager.isMonster(p))
              .filter(p -> p.getLocation().distance(executor.getLocation()) <= range)
              .forEach(p -> targetEntities.add(p));
          break;
      }
    }

    if (target.equals(EnumTarget.MYSELF)) {
      Status status = currentStatusStore.get(targetEntities.get(0).getUniqueId());
      if (status.getMaxHp() == status.getHp()) return false;
    }
    return true;
  }