Solved An event not being cancelled ?

Discussion in 'Plugin Development' started by Kozomo, May 19, 2020.

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

    Kozomo

    Hey so this should be pretty self explanatory... A player inSZ should not be able to hurt a player not inSZ and yet he is able to deal damage. And i'm also receiving both messages "test1" and "test2" under the specified circumstances. Any help would be appreciated. Thank you :D
    Code:
    @EventHandler
        public void dam(EntityDamageByEntityEvent e)
        {
            if(e.getEntity() instanceof Player && e.getDamager() instanceof Player)
            {
                Player gdmg = (Player) e.getEntity();
                Player dmgr = (Player) e.getDamager();
               
                if(!(CoreKP.inSZ.contains(gdmg.getUniqueId())) && CoreKP.inSZ.contains(dmgr.getUniqueId()))
                {
                    e.setCancelled(true);
                    dmgr.sendMessage("test1");
                    gdmg.sendMessage("test2");
                }
            }
        }
     
  2. Offline

    bowlerguy66

    @Kozomo Try using EventPriority
     
  3. Offline

    Kozomo

    Okay that solved it thank you :D. But one question though will this affect other events in any way ?
     
  4. Offline

    bowlerguy66

    @Kozomo Not in their basic functionality. I'm pretty sure changing the EventPriority changes the order in which the event are called, so if another EntityDamageByEntity event is called that should have a higher priority but isn't given it by your code that is the only way you can run into issues.
     
  5. Offline

    Kozomo

    bowlerguy66 likes this.
Thread Status:
Not open for further replies.

Share This Page