Solved Event for Players Dealing Damage?

Discussion in 'Plugin Development' started by LeeTheENTP, Jun 18, 2013.

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

    LeeTheENTP

    Hi!

    I'm working on improving my graylisting plugin by adding the prevention of damage dealt by and to players not on the graylist. I've managed to block incoming damage, but I'm not sure how to prevent outgoing damage.

    I'm sure it's some type of event I can't think of, but I can't seem to find it.

    Thanks for any help!
     
  2. Offline

    Garris0n

    EntityDamageByEntityEvent
     
  3. Offline

    LeeTheENTP

    Ah, thanks! I'll export and test this now.
     
  4. Offline

    Minnymin3

    BTW, Google is your friend.
     
  5. Offline

    TheRealNovus

    Code:java
    1. @EventHandler
    2. public void onPlayerDamage(EntityDamageByEntityEvent event)
    3. {
    4. if (event.getDamager() instanceof Player)
    5. {
    6. Player attacker = (Player) event.getDamager();
    7. // attacker is a player
    8. }
    9.  
    10. if (event.getEntity() instanceof Player)
    11. {
    12. Player victim = (Player) event.getEntity();
    13. // victim is a player
    14. }
    15. }
     
  6. Offline

    LeeTheENTP


    This doesn't seem to be working. I went with what you put here, but the damage is not being prevented either way.

    To clarify, this is not just for PvP combat prevention; I'm trying to block PvE and fall damage as well.

    This is what I have for the damage event so far:

    Code:
    public void onDamage(EntityDamageByEntityEvent d){
            if(d.getDamager() instanceof Player){
                Player p = (Player) d.getDamager();
                if(p.hasPermission("tsbgl.graylisted")){
                 
                } else {
                    d.setCancelled(true);
                    p.sendMessage(ChatColor.DARK_PURPLE + "[TSBGL]" + ChatColor.GREEN + " You cannot deal damage until you have been graylisted!");
                }
            } else if(d.getEntity() instanceof Player){
                    Player p = (Player) d.getEntity();
                    if(p.hasPermission("tsbgl.graylisted")){
                     
                    } else {
                        d.setCancelled(true);
                        p.sendMessage(ChatColor.DARK_PURPLE + "[TSBGL]" + ChatColor.GREEN + " Damage has been prevented because you are not graylisted.");
                }
            }
        }
    Oohdang. I seem to have forgotten the @EventHandler. I'll fix that and try again.

    I got the PvP and PvE damage prevention working. Thanks for the help!

    Also got fall damage prevention working!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 2, 2016
Thread Status:
Not open for further replies.

Share This Page