Direct Damage

Discussion in 'Plugin Development' started by Coopah, May 30, 2015.

Thread Status:
Not open for further replies.
  1. Offline


    How would I inflict direct damage to a player ignoring their armor and enchantments on it.

    I've tried the player.damage(damageD) feature but seem to have issues. I've also tried event.setDamage(0D) then tried to set the damage getting their health and subtracting damage only to find errors.

    Any help will be much appreciated :)
  2. Offline


    What is wrong with something like this:

         event.getPlayer.setHealth(event.getPlayer.getHealth() - 8); 
    Works for me
  3. Offline


    @Coopah What seanliam2000 said, just take in account that setting health lower than 0 throws and exception, so you need to check that, also use Player#playerEffect to play the hurt effect
  4. Offline


    @Konato_K @seanliam2000
    I'm using this code but it doesn't work. It just keeps setting their health to the same amount. It puts them on 2 hearts instead of subtracting 2 hearts from their health and then every shot following that will keep them on 2 hearts.

    Isn't #getHealth just getting their total health and not current?

        public void onArrowLand(EntityDamageByEntityEvent e) {
            Entity damagerE = e.getDamager();
            Entity damagedE = e.getEntity();
            if (damagerE instanceof Arrow && damagedE instanceof Player) {
                Player damaged = (Player) damagedE;
                final Arrow arw = (Arrow) damagerE;
                if (arw.getShooter() instanceof Player) {
                    final Player damager = (Player) arw.getShooter();
                    if (ArrowToggles.CripplingArrows.contains(damager.getName())) {
                        damaged.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 60, 1));
                    } else if (ArrowToggles.PiercingArrows.contains(damager.getName())) {
                        damaged.damage(damaged.getHealth() - 8);
                    } else {
  5. Offline


    Yes. I don't see you setting the player's health in your code as
    @seanliam2000 suggested
    seanliam2000 likes this.
Thread Status:
Not open for further replies.

Share This Page