示例#1
0
  public static boolean Damage(Player attacker, Player victim, Double damage) {

    if (victim.isDead()) {
      return false;
    }
    if (attacker != null && !attacker.isOnline()) {
      return false;
    }
    if (DataUtils.getPlayer(victim).isVanished()) {
      return false;
    }
    if (attacker != null && DataUtils.getPlayer(attacker).isVanished()) {
      return false;
    }

    // Multiply and reduce by team stats.

    SmashPredamageEvent event = new SmashPredamageEvent(attacker, victim, damage);
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled()) {
      return false;
    }
    damage = event.getDamage();

    victim.playEffect(EntityEffect.HURT);
    Location loc = victim.getLocation().add(0, 1, 0);
    ParticleUtils.SendPacket(
        ParticleUtils.createBlockPacket(
            EnumParticle.BLOCK_CRACK, 152, 0, loc, new Vector(0.1, 0.1, 0.1), 0F, 50),
        loc);
    ParticleUtils.SendPacket(
        ParticleUtils.createNormalPacket(
            EnumParticle.VILLAGER_ANGRY, victim.getEyeLocation(), new Vector(0, 0, 0), 0F, 1),
        loc);

    Double totalDamage = damage;

    damage = BarrierUtils.takeDamage(victim, damage);

    HologramUtils.displayAlertHolo(victim, "&c-" + Integer.toString(totalDamage.intValue()) + " ❤");

    boolean result = addDamage(attacker, victim, damage);

    Bukkit.getPluginManager().callEvent(new SmashDamageEvent(attacker, victim, totalDamage));

    return result;
  }
示例#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);
    }
  }