Plugin Help Preventing sword blocking

Discussion in 'Plugin Help/Development/Requests' started by HCMatt, Apr 24, 2015.

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

    HCMatt

    I was wondering if there is a way to stop people from blocking with a sword. So if they right click and the item in their hand is a sword, the sword wont move.. Here is what i tried...

    Code:
    @EventHandler
        public void onBlock(PlayerInteractEvent e) {
            Action a = e.getAction();
            Player p = e.getPlayer();
            if (a == Action.RIGHT_CLICK_AIR || a == Action.RIGHT_CLICK_BLOCK) {
                if (p.getItemInHand().getType().equals(Material.IRON_SWORD)) {
                    e.setCancelled(true);
                    return;
    
                }
            }
    
        }
    Please help!
     
  2. @HCMatt Sword blocking is a client side animation, so cannot be disabled. If you wanted to prevent the damage being reduced, you can use the EntityDamageEntityEvent and check if player.isBlocking();
     
Thread Status:
Not open for further replies.

Share This Page