Check if a player can hurt another player?

Discussion in 'Plugin Development' started by Phinary, Aug 19, 2012.

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

    Phinary

    Anyone have any idea if there is a way you can check if a Player can hurt another one? I was thinking of something like sending a fake player damage event and seeing if it gets cancelled or something, not sure exactly though. I am open to suggestions!
     
  2. Triggering the event maually might also trigger unwated effects from other plugins, like giving exp, potion effects, instantly killing the victim, stuff like that... there are alot of plugins that do stuff when entites damage eachother, so fakefully triggering it wouldn't be best.

    There is no sure way to know how other plugins will react or do unless you already know beforehand and hardcode it in the plugin to expect it.
     
  3. Offline

    kyle1320

    Code:
    @EventHandler
        public void entityDamage(EntityDamageByEntityEvent event) {
            if(event.getEntity() instanceof Player && event.getDamager() instanceof Player) {
                Player player = (Player)event.getEntity();
                boolean cancelled = event.isCancelled();
                if (cancelled) {
                    player.sendMessage("You were attacked, but it got cancelled..");
                }
             
            }
        }
    Seems to work alright for me, unless I misunderstood what you wanted.

    EDIT: Oh you want to check any time, yeah no idea lol
     
Thread Status:
Not open for further replies.

Share This Page