Exemple #1
0
  public static boolean MeleeDamage(Player attacker, Player victim) {
    EntityHuman e = ((EntityHuman) ((CraftPlayer) attacker).getHandle());
    boolean flag =
        (e.fallDistance > 0.0F)
            && (!e.onGround)
            && (!e.k_())
            && (!e.V())
            && (!e.hasEffect(MobEffectList.BLINDNESS))
            && (e.vehicle == null);

    double damage = Variables.getDouble("basedamage") * (flag ? 1.5 : 1);

    if (victim.isBlocking()) {
      damage = damage / 2;
    }

    return Damage(attacker, victim, damage);
  }
Exemple #2
0
  /**
   * Heals a player with the following parameters
   *
   * @param player Targeted player to heal
   * @param amount Health to heal per loop
   * @param times Total times to heal, set to 0 for instant heal
   * @param timePerTick Delay between heals
   * @param cancelOnDamage If true, healing will stop if a player is damaged
   * @param spell Spell name. Will automatically get config name.
   */
  public static void regenHealth(
      final Player player,
      final Double amount,
      final int times,
      final Long timePerTick,
      final boolean cancelOnDamage,
      final String spell) {
    if (times == 0) {
      Double heal = amount;
      if (heal + player.getHealth() > player.getMaxHealth()) {
        heal = player.getMaxHealth() - player.getHealth();
      }

      String msg = "";
      if (heal == 0) {
        msg = Variables.getString("heal_healfail");
        msg = msg.replaceAll("%s", spell);
      } else {
        msg = Variables.getString("heal_healmessage");
        msg = msg.replaceAll("%s", spell);
        msg = msg.replaceAll("%h", Integer.toString((heal.intValue())));
        HealthUtils.addHealth(player, heal);

        HologramUtils.displayAlertHolo(player, "&a+" + Integer.toString(heal.intValue()) + " ❤");
      }

      ChatUtils.sendMessage(player, msg);

      StatisticUtils.addHeal(player, heal.intValue());

    } else {

      final UUID tsid = UUID.randomUUID();
      int id =
          Bukkit.getScheduler()
              .scheduleSyncRepeatingTask(
                  Main.instance,
                  new Runnable() {

                    int i = 0;
                    Long lastDamage = DataUtils.getPlayer(player).getLastDamage();

                    @Override
                    public void run() {
                      if (!player.isOnline()) {
                        TaskUtils.killTask(tsid);
                        return;
                      }

                      player.addPotionEffect(
                          new PotionEffect(PotionEffectType.REGENERATION, 100000, 5, true, true));

                      if (cancelOnDamage
                          && lastDamage != DataUtils.getPlayer(player).getLastDamage()) {
                        player.removePotionEffect(PotionEffectType.REGENERATION);
                        String m = Variables.getString("heal_healcancelonhitmessage");
                        m = m.replaceAll("%s", spell);
                        ChatUtils.sendMessage(player, m);

                        TaskUtils.killTask(tsid);
                        return;
                      }
                      Double heal = amount;
                      if (heal + player.getHealth() > player.getMaxHealth()) {
                        heal = player.getMaxHealth() - player.getHealth();
                      }
                      if (heal == 0) {
                        ChatUtils.sendMessage(
                            player, Variables.getString("heal_healfail").replace("%s", spell));
                        if (cancelOnDamage) {
                          player.removePotionEffect(PotionEffectType.REGENERATION);
                          TaskUtils.killTask(tsid);
                          return;
                        }
                      } else {
                        regenHealth(player, heal, spell);
                      }

                      // add to total heal

                      i++;
                      if (i >= times) {
                        player.removePotionEffect(PotionEffectType.REGENERATION);

                        String m = Variables.getString("heal_healexpire");
                        m = m.replaceAll("%s", spell);
                        ChatUtils.sendMessage(player, m);

                        TaskUtils.killTask(tsid);
                        return;
                      }
                    }
                  },
                  timePerTick,
                  timePerTick);
      TaskUtils.startTask(tsid, id, player, spell);
    }
  }