setContents() creates ghost items?

Discussion in 'Plugin Development' started by Zach_1919, Mar 23, 2014.

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

    Zach_1919

    I am using the setContents method in a player's inventory so I can set their inventory contents. When I do this, the ItemStacks show up in the player's inventory, however, when the player clicks with the item, it disappears. What's weird though is that the item still works, then disappears. For example, if I hit a mob with a diamond sword, it does the damage of the diamond sword, but disappears. Help?
     
  2. Offline

    ShadowLAX

    Zach_1919 That's a bit strange... did you call the p.updateInventory() method after setting the contents?
     
  3. Offline

    AoH_Ruthless

    Zach_1919
    p.updateInventory(); - While it's deprecated, that's the only quick and viable way to prevent ghost items.
     
  4. Offline

    Zach_1919

  5. Offline

    ShadowLAX

    Zach_1919 Mind pasting the code you are using?
     
  6. Offline

    Zach_1919

    ShadowLAX Well it's a little spread out amongst several classes but here's where I actually execute the setContents method:
    Code:
        @SuppressWarnings("deprecation")
        public void putOnDuty(Player player)
        {
            GuardInventory inv = new GuardInventory(player.getInventory().getContents(),player.getInventory().getArmorContents());
            Main.guardInvs.put(player.getName(),inv);
            player.getInventory().setContents(guardContents);
            player.getInventory().setArmorContents(guardArmorContents);
            player.updateInventory();
            getServer().broadcastMessage(Main.prefix + ChatColor.GREEN + player.getName() + " is now on duty");
        }
    Now what's weird is that I use the setContents method to return the player's original items, and that works just fine:
    Code:
        @SuppressWarnings("deprecation")
        public void putOffDuty(Player player)
        {
            player.getInventory().setContents(guardInvs.get(player.getName()).contents);
            player.getInventory().setArmorContents(guardInvs.get(player.getName()).armorContents);
            guardInvs.remove(player.getName());
            player.updateInventory();
            getServer().broadcastMessage(Main.prefix + ChatColor.RED + player.getName() + " is now off duty");
        }
     
  7. Offline

    Gater12

    Zach_1919
    Try clearing their inventory after you saved it to the HashMap, but before you set contents? It's what I did [for my guard plugin I was making...]
     
  8. Offline

    Zach_1919

    Gater12 Alrighty, I'll try it. Why did you bold "was"? It makes me feel like I did something wrong :(

    Gater12 SORRY FOR DOUBLE POSTING but it didn't do anything

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

    rfsantos1996

    HAHAHA, YOUR SIGNATURE, THIS IS SO TRUE... I can't code while I'm assleep, if I do, I need to recode everything on the next day lol
     
    Mattkx4, Zach_1919 and Gater12 like this.
  10. Offline

    PatoTheBest

    How did you record it as a GIF image? What program did you use?
     
  11. Offline

    Zach_1919

    PatoTheBest I recorded it with Camtasia Studio then I used a custom export setting I made that exports it as a gif. If you have Camtasia I would be happy to PM you about how to export gifs.
     
Thread Status:
Not open for further replies.

Share This Page