예제 #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);
  }
예제 #2
0
  public static void Death(Player victim) {
    DeathEffectUtils.playDeathEffect(victim);
    SoundUtils.playSound(Sound.HURT_FLESH, victim.getEyeLocation(), 2F, 0F);

    Player attacker = DataUtils.getPlayer(victim).getLastAttacker();

    StatisticUtils.addDeath(victim);

    if (attacker == null) {
      TitleUtils.sendTitle(victim, "&c&lYou have died!", "&7&lMistakes were made", 10, 80, 10);
      ChatUtils.sendMessage(victim, "&7&m-----------------------------------------------------");
      ChatUtils.sendMessage(victim, "&8[&c&lDeath&8] &7Mistakes were made.");
      ChatUtils.sendMessage(victim, "&7&m-----------------------------------------------------");
    } else {

      String prefixAttacker = DataUtils.getPlayer(attacker).getPrefix();
      String colorAttacker = prefixAttacker.substring(0, 2);
      ChatUtils.sendMessage(victim, "&7&m-----------------------------------------------------");
      ChatUtils.sendMessage(
          victim,
          "&8[&c&lDeath&8] &7You have been slain by " + prefixAttacker + attacker.getDisplayName());
      ChatUtils.sendMessage(victim, "&7&m-----------------------------------------------------");
      TitleUtils.sendTitle(
          victim,
          "&c&lYou have been slain!",
          "&7&lKiller: " + colorAttacker + attacker.getDisplayName(),
          10,
          80,
          10);

      MoneyUtils.deathCoinsPayout(victim);

      StatisticUtils.addDeath(attacker);
    }
    victim.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 60, 0, true, true));

    //		victim.teleport(Main.SpawnLoc);
    // Location teleport to team spawn.
    victim.setVelocity(new Vector(0, 0, 0));
  }
예제 #3
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);
    }
  }