setHelmet not working properly?

Discussion in 'Plugin Development' started by BasBloem, May 4, 2014.

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

    BasBloem

    Hello, I used to make plugins a long time ago, and now I'm back to making them.
    But I'm getting a lot of trouble with some simple stuff.

    I'm trying to make a zoom item for a gamemode I'm working on but whenever I try to set the helmet it won't work. (I use a pumpkin, so I can use the pumpkin blur texture as a binocular texture)


    Code:java
    1. @EventHandler
    2. public void onPlayerUse(PlayerInteractEvent e){
    3. if(e.getPlayer().getItemInHand().getType() == Material.QUARTZ){
    4. RPPlayer rp = RPGame.getRPPlayer(e.getPlayer());
    5. Player p = e.getPlayer();
    6. rp.zoom++;
    7. if(rp.zoom==2){rp.zoom=0;}
    8. if(rp.zoom==0){
    9. //Reset all zoom
    10. p.removePotionEffect(PotionEffectType.SLOW);
    11. p.setWalkSpeed(0.2f);
    12. if(rp.preZoomHelmet!=null){
    13. p.getEquipment().setHelmet(rp.preZoomHelmet);
    14. }
    15. }
    16. else if(rp.zoom==1){
    17. //Zoom small
    18. p.removePotionEffect(PotionEffectType.SLOW);
    19. PotionEffect zoom = new PotionEffect(PotionEffectType.SLOW,99999,255);
    20. p.addPotionEffect(zoom);
    21. p.setWalkSpeed(-0.25f);
    22. rp.preZoomHelmet = p.getEquipment().getHelmet();
    23. p.getEquipment().setHelmet(new ItemStack(Material.PUMPKIN));
    24. }
    25. }
    26. }


    The event is registered correctly, because the zoom itself works.
    I think the only important part for this problem is the last 2 functions.
    There are also no errors, and I also tried
    p.getInventory().setHelmet, but no succes with that either.

    I'm running the 1.7.9 development build (R0.1 build 3075)

    I found out that it does set it, but doesn't update the players inventory for some reason.
    What's up with that?

    EDIT:

    Fixed using the updateInventory method, but that is deprecated...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
Thread Status:
Not open for further replies.

Share This Page