.setHelmet not working

Discussion in 'Plugin Development' started by myluki2000, Feb 15, 2014.

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

    myluki2000

    So I have an event handler that is checking if the player interacts with an iron barding in his hands:

    Code:java
    1. @EventHandler(priority=EventPriority.HIGH)
    2. public void onPlayerUse(PlayerInteractEvent event){
    3. Player p = event.getPlayer();
    4.  
    5. if(event.getAction().equals(Action.RIGHT_CLICK_AIR)){
    6. if(p.getItemInHand().getType() == Material.IRON_BARDING){
    7. p.getInventory().setHelmet(new ItemStack(Material.PUMPKIN));
    8. }
    9. }
    10.  
    11. }


    If I replace the setHelmet thing with a simple message it works, so it's not the eventhandler. But it doesn't place a pumpkin on my head. Why?

    Thanks
     
  2. Offline

    Retherz_

    new ItemStack(Material.PUMPKIN, 1));
     
  3. Offline

    myluki2000

    Still not working :(
     
  4. Offline

    TryB4

  5. Offline

    myluki2000

    Now i get this error:

    Show Spoiler

     
  6. Offline

    Retherz_

    try
    ItemStack item = new ItemStack(Material.PUMPKIN, 1);
    ItemStack air = new ItemStack(Material.AIR, 1);
    p.getInventory().setHelmet(item);
    p.getInventory().addItem(air);
     
  7. Offline

    myluki2000

    Why the air?

    EDIT:
    Still not working
     
  8. Offline

    Retherz_

    Updates the inventory
    updateInventory() doesn't usually work, and you shouldn't use EventPriority.HIGH
     
  9. Offline

    myluki2000

    Ok

    But sadly it still isn't working
     
  10. Offline

    Retherz_

    Code:java
    1.  
    Code:java
    1.  
    Code:java
    1.  
    Code:java
    1.  
    2. [FONT=trebuchet ms][COLOR=#000000][SIZE=3]@EventHandler(priority=EventPriority.LOW)[/SIZE][/COLOR][/FONT]
    3. [FONT=trebuchet ms][COLOR=#000000][SIZE=3]publicvoid onPlayerUse(PlayerInteractEvent event){[/SIZE][/COLOR][/FONT]
    4. [FONT=trebuchet ms][COLOR=#000000][SIZE=3]if(event.getAction() == ([URL='http://www.google.com/search?hl=en&q=allinurl%3Aaction+java.sun.com&btnI=I%27m%20Feeling%20Lucky'][COLOR=#000000]Action[/COLOR][/URL].RIGHT_CLICK_AIR)){[/SIZE][/COLOR][/FONT]
    5. [FONT=trebuchet ms][COLOR=#000000][SIZE=3] Player p = event.getPlayer();[/SIZE][/COLOR][/FONT]
    6. [FONT=trebuchet ms][COLOR=#000000][SIZE=3]if(p.getItemInHand().getType()== Material.IRON_BARDING){[/SIZE][/COLOR][/FONT]
    7. [FONT=trebuchet ms][COLOR=#000000][SIZE=3] p.getInventory().setHelmet(new ItemStack(Material.PUMPKIN), 1);[/SIZE][/COLOR][/FONT]
    8. [FONT=trebuchet ms][COLOR=#000000][SIZE=3]p.getInventory().addItem(new ItemStack(Material.AIR, 1));[/SIZE][/COLOR][/FONT]
    9. [FONT=trebuchet ms][COLOR=#000000][SIZE=3]}[/SIZE][/COLOR][/FONT]
    10. [FONT=trebuchet ms][COLOR=#000000][SIZE=3]}[/SIZE][/COLOR][/FONT]
    11. [FONT=trebuchet ms][COLOR=#000000][SIZE=3]}[/SIZE][/COLOR][/FONT]
     
  11. Offline

    myluki2000

    After removing these BBCodes... Still doesn't work. I can't understand why. If I use the pumpkin thing in a command or anything else it works. But not here.
     
  12. Offline

    Skatedog27

    Code:
    if (e.getAction() == Action.RIGHT_CLICK_AIR && e.getItem().getType() == Material.IRON_BARDING {
        ItemStack pumpkin = new ItemStack(Material.PUMPKIN);
        Player p = e.getPlayer();
        p.getInventory().setHelmet(pumpkin);
    }
     
  13. Offline

    myluki2000

    I don't know why but it isn't working with your code either...
     
  14. Offline

    Retherz_

    Send a message after giving the item and see if that works
     
  15. Offline

    myluki2000

    It works I already tested it.
    Tested it again. Still works
     
  16. Offline

    Retherz_

    try
    p.getEquipment().setHelmet(new ItemStack(Material.PUMPKIN, 1));
     
  17. Offline

    myluki2000

    I'll try tomorrow and say if it worked.

    Still not working BUT when I join it puts a pumpkin on my head. But not when I right click the horse armor

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

    __Sour

    myluki2000

    This might and might not work i do have a server to test it on but might work

    Code:java
    1. @EventHandler
    2. public void onPumpkinHead(PlayerInteractEvent e) {
    3. Player p = e.getPlayer();
    4. PlayerInventory pInv = p.getInventory();
    5. //This should work i dont have a server to test it on right now hope i helped!
    6. if(e.getAction().equals(Action.RIGHT_CLICK_AIR) && p.getItemInHand().getType() == Material.IRON_BARDING) {
    7. pInv.setHelmet(null);
    8.  
    9. ItemStack helm = new ItemStack(Material.PUMPKIN);
    10. ItemMeta helmMeta = helm.getItemMeta();
    11. helm.setItemMeta(helmMeta);
    12.  
    13. pInv.setHelmet(helm);
    14. }
    15. }


    myluki2000
    Also make sure to refresh it be4 you export it and delete the plugin your your plugins folder then put it in there, because sometimes for me overriding the plugin doesn't work for me.

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

    Aqua

    Did you register the eventlistener?
     
  20. Offline

    myluki2000

    think so Yes and everything else is working fine.
     
Thread Status:
Not open for further replies.

Share This Page