Solved If player is BLOCKING, disable all incoming damage to that player

Discussion in 'Plugin Development' started by rogerin0, Dec 29, 2012.

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

    rogerin0

    Hi everyone. I've been trying to check whether or not a player is blocking (with a sword) when the player receives damage. Here's what I've currently come up with:

    Code:
        public void onEntityDamage(EntityDamageByEntityEvent event){
            if(event.getEntity() instanceof Player){
                Player blockingplayer = (Player) event.getEntity();
                if(blockingplayer.isBlocking() == true){
                    event.setCancelled(true);
                    blockingplayer.sendMessage("You blocked all incoming damage.");
     
                }
            }
        }
    ...which doesn't appear to work at all. Any ideas?
     
  2. Offline

    Frazz86

    Try using the bukkit logger to debug where its going wrong :)
     
  3. Offline

    llamasaylol

    Did you register the event. We do get quite a lot of people forgetting to do so.
     
    chasechocolate and fireblast709 like this.
  4. Offline

    rogerin0

    I have:
    Code:
    public class MyPlugin extends JavaPlugin implements Listener{
    ...
    Is that what you mean?
     
  5. Offline

    Tirelessly

    In onEnable() put getServer().getPluginManager().registerEvents(this, this);

    Google and read a wiki every now and then, the amount of times this has been answered is ridiculous.
     
  6. Offline

    rogerin0

    Oh, right! I've already had:
    Code:
        public void onEnable(){
    ...
    Bukkit.getPluginManager().registerEvents(this, this);
        }
    Before testing. I suppose I have registered the events, then. Any ideas?
     
  7. Offline

    Sagacious_Zed Bukkit Docs

    Did you annotate the event handlers?
     
    rogerin0 likes this.
  8. Offline

    Theway2cool1

    You don't have @EventHandler.
    Code:
    @EventHandler
    public void onEntityDamage(EntityDamageByEntityEvent event){
            if(event.getEntity() instanceof Player){
                Player blockingplayer = (Player) event.getEntity();
                if(blockingplayer.isBlocking() == true){
                    event.setCancelled(true);
                    blockingplayer.sendMessage("You blocked all incoming damage.");
     
                }
            }
        }
    That should make it work.
     
    rogerin0 likes this.
  9. Offline

    rogerin0

    Oh wow. I am face-palming myself so hard right now. Thanks so much for the help! :p
     
Thread Status:
Not open for further replies.

Share This Page