DamageCause

Discussion in 'Plugin Development' started by kangkyuchang, Feb 16, 2020.

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

    kangkyuchang

    I wanna cancel the damage when the player swings it with a weapon or hand.
    Code:
    @EventHandler
        public void Attack2(EntityDamageEvent e)
        {
            if(e.getEntityType() != EntityType.PLAYER) return;
            if(DamageCause.ENTITY_SWEEP_ATTACK != null)
            {
                if(e.getCause() == DamageCause.ENTITY_SWEEP_ATTACK)
                {
                    e.setCancelled(true);
                }
            }
        }
    Is ENTITY_SWEEP_ATTACK a swing attack?(Left click)
     
  2. Offline

    KarimAKL

    @kangkyuchang
    1. DamageCause.ENTITY_SWEEP_ATTACK will never be null, so there's no need to check for that.
    2. ENTITY_SWEEP_ATTACK is when attacked by a sweep attack (a charged sword attack), you're probably looking for ENITTY_ATTACK.
     
  3. Offline

    kangkyuchang

    Thank you. But even with Entity_Attack it doesn't do what I want.
     
  4. Offline

    timtower Administrator Administrator Moderator

  5. Offline

    kangkyuchang

    What value is?
     
  6. Offline

    timtower Administrator Administrator Moderator

    The value of e.getCause()
    Print it to the terminal.
     
  7. Offline

    kangkyuchang

    Code:
    @EventHandler
        public void Attack2(EntityDamageEvent e, EntityDamageEvent.DamageCause de)
        {
            de = e.getCause();
            if(e.getEntityType() != EntityType.PLAYER) return;
            if(de == DamageCause.ENTITY_ATTACK)
            {
                e.setCancelled(true);
                return;
            }
        }
    Right?
     
  8. Offline

    timtower Administrator Administrator Moderator

    @kangkyuchang You are not printing it to the terminal. And that method will never get called as it has 2 parameters.
     
  9. Offline

    kangkyuchang

    What is the terminal?
     
  10. Offline

    Wick

    @kangkyuchang

    You said "Entity_Attack it doesn't do what I want", therefore add a print message that sends out the DamageCause, and do some testing in-game to see what DamageCause you need

    Code:
    System.out.print(e.getCause().toString) or Bukkit.broadcastMessage(e.getCause().toString
    The terminal is the console, the black box that appears when you start your server, or if its hosted, the host will normally have a console page within the control panel
     
  11. Offline

    Strahan

    Console. The window the server outputs all of the stuff to.
     
  12. Offline

    kangkyuchang

    Thank you.
     
Thread Status:
Not open for further replies.

Share This Page