Blocking armor equiping with right click

Discussion in 'Plugin Development' started by RamonSGomes, Apr 2, 2013.

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


    I want to block diamond set usage for player's that does not have the appropiate permission, but I got a problem with the new feature of Minecraft that allows the player to equip an armor by right clicking with the item selected in the quick toolbar.

    My question is: How to block it?

    Sorry for my awful english.
  2. Offline


    1. @EventHandler
    2. public void onPlayerInteract(PlayerInteractEvent event){
    3. Player player = event.getPlayer();
    4. Action action = event.getAction();
    5. if(action == Action.RIGHT_CLICK_BLOCK || action == Action.RIGHT_CLICK_AIR){
    6. if(<player.getItemInHand() is armor>){ //I am not sure if there is some easy way to check if it is armor
    7. event.setCancelled(true);
    8. }
    9. }
    10. }
  3. Offline


    It does not works
  4. Offline


    RamonSGomes Of course it does. You must not be adding the armor into the if statement. Try to not copy and paste the code and add each type of armor.
  5. Here is a noob friendly version:

    1. // Add your items to check here, I've just added 2 armor parts
    2. private List<Material> armorMaterials = Arrays.asList(Material.LEATHER_BOOTS, Material.LEATHER_LEGGINGS);
    4. @EventHandler
    5. public void onPlayerInteract(PlayerInteractEvent event)
    6. {
    7. Player player = event.getPlayer();
    8. if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK) || event.getAction().equals(Action.RIGHT_CLICK_AIR))
    9. {
    10. // Check if the item in hand is contained in the armor list
    11. if (armorMaterials.contains(player.getItemInHand().getType()))
    12. {
    13. event.setCancelled(true);
    14. }
    15. }
    16. }
  6. Not working, I mean the cancellation is working (I have test it with some equipment, but the armors are equipped.). It seems the cancellation works for tools, but armor parts still equipped. Any other idea?

    Not working against armor equipping. Tools are not working (I have test the cancellation with a hoe), but armor parts are still equipped. Any idea?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 31, 2016
  7. Offline


    You have to reload the player inventory.
Thread Status:
Not open for further replies.

Share This Page