[Please Help] Disable event of dress the helmet!

Discussion in 'Plugin Development' started by zDubsCrazy, Apr 21, 2014.

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

    zDubsCrazy

    I want that when the player clicks with the right mouse button with a leather helmet in hand, he is not automatically dress! And the helmet keep the slot he was. Please help!

    Thanks.
     
  2. Offline

    thisguy128512

    You are looking for a PlayerInteractEvent with Action type Action.RIGHT_CLICK_BLOCK or Action.RIGHT_CLICK_AIR. You will need to check for the item in hand, and if it is a leather helmet, cancel the interact event or something.

    http://jd.bukkit.org/dev/apidocs
     
  3. Offline

    zDubsCrazy

  4. Offline

    Gater12

  5. Offline

    zDubsCrazy

    Gater12
    That's not what I want to know, my event is created, understand the question please!

    but no one?

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

    lukewizzy

    Check if they're holding a leather helmet and then cancel the event:
    Code:java
    1. if (event.getPlayer().getItemInHand().getType() == Material.LEATHER_HELMET) {
    2. event.setCancelled(true);
    3. }




    You may only wish to cancel it when they right click it though, so you can check for that like this:
    Code:java
    1. if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK)
     
  7. I tested my code and it puts the helmet on and i get back my helmet.
     
  8. Offline

    lukewizzy

    Check that it isn't a visual bug (click on it), because sometimes that happens.
    You could do this instead:
    Code:java
    1. player.getInventory().setHelmet(null);
    2. player.getInventory().addItem(new ItemStack(Material.LEATHER_HELMET, 1));
     
  9. lukewizzy
    I wrote this code(that was what i tested)
    Code:java
    1. @EventHandler
    2. public void helmet(PlayerInteractEvent e){
    3. if(!(e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK))) return;
    4. Player p = e.getPlayer();
    5. if(p.getItemInHand().equals(Material.LEATHER_HELMET)){
    6. e.setCancelled(true);
    7. p.getEquipment().setHelmet(null);
    8. }
    9. }
     
  10. Offline

    zDubsCrazy

    sohardhun15
    it work?

    Please help-me!

    but no one?

    I'm not getting! :'(

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

    MrInspector


    You just triple posted in 1 hour!

    Please bump every 24 hours or so, or is it 12 hours, not sure. :p

    I'd just test it your self instead of waiting for a reply. :)
     
  12. Offline

    zDubsCrazy

    But I'm not able to help in that aspect! :'(

    Bump.

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

    zDubsCrazy

    Please help people! :'(
     
  14. Offline

    Adriani6

    I dont get the question.

    You mean this;
    Right click with leather helmet in hand and player will get dressed up ? And helmet slot will remain untouched?
     
  15. Offline

    zDubsCrazy

    Adriani6 Yes, the helmet does not stand in the player's head when they click the right button. And the helmet return to hand of player.
     
  16. Offline

    Gater12

    zDubsCrazy
    2 codes were posted and seems like it would work (May have visual bugs, but that's Minecraft at its finest). Did you try them?
     
  17. Offline

    zDubsCrazy

    Gater12
    Yes, the helmet goes to the head of the player anyway.
     
  18. Offline

    Garris0n

    Update their inventory, it's just client prediction.
     
  19. Offline

    zDubsCrazy

    Garris0n
    It does not work. player.updateInventory(); is deprecated! It cause errors.
     
  20. Offline

    Garris0n

    It doesn't cause errors, it causes warnings, which, in this case, are safe to ignore.
     
  21. Offline

    zDubsCrazy

    Garris0n
    No, cause error yes, i am test.
     
  22. Offline

    Garris0n

    Erm...screenshot?
     
  23. Offline

    zDubsCrazy

    Garris0n
    I think this may already be forgotten, gave a lot of work, and I ended up switching to a different material ... Thank you all for your help! Had a bad error by player.updateInventory (); be deprecated.
     
  24. zDubsCrazy There's no such thing as a deprecation error.
     
    Garris0n likes this.
  25. Offline

    zDubsCrazy

    AdamQpzm
    When not using player.updateInventory(); the error did not occur, was just adding that and a huge mistake filled my console.
     
  26. zDubsCrazy Can I see the huge mistake (stack trace) - because if deprecations are now causing errors, someone at Oracle should be informed
     
Thread Status:
Not open for further replies.

Share This Page