Exemple #1
0
  private static boolean addDamage(Player attacker, Player victim, Double damage) {
    // mysql shit
    if (attacker == null) {
      attacker = DataUtils.getPlayer(victim).getLastAttacker();
    }
    if (damage > victim.getHealth()) {
      damage = victim.getHealth();
    }

    SmashPlayer Victim = DataUtils.getPlayer(victim);
    Victim.setLastDamage(System.currentTimeMillis());
    Victim.setLastAttacker(attacker);

    StatisticUtils.addDamageTaken(victim, damage);

    if (attacker != null) {

      StatisticUtils.addDamageDelt(attacker, damage);

      if (Victim.getDamagers().containsKey(attacker)) {
        Victim.getDamagers().put(attacker, Victim.getDamagers().get(attacker) + damage);
      } else {
        Victim.getDamagers().put(attacker, damage);
      }
    }

    return HealthUtils.addHealth(victim, damage * -1);
  }
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);
    }
  }