Solved Help With Player Inventory's

Discussion in 'Plugin Development' started by DragonSlayer1920, Jun 19, 2014.

Thread Status:
Not open for further replies.
  1. Hello,
    I am coding a plugin which will add and remove some items to a players inventory. Everything works great until the player is given the item. You can't see the item in your inventory until you relog. This is a big problem because most players think it's lag and they buy an item twice and so on until they relog. I need this fixed soon. Please Help!
    Thanks,
    Dragon
     
  2. Offline

    Dinosaurs

    Possibly provide the code you are trying?
     
  3. Dinosaurs just a test method but this is what I was using

    Code:
    public void give(Player p) {
            p.getInventory().addItem(new ItemStack(Material.DIRT));
           
        }
     
  4. Offline

    Dinosaurs

    There shouldn't be any problems with that code, Perhaps something else is conflicting with it?

    Possibly try to update the inventory.
    Code:
     p.updateInventory(); 
     
  5. Dinosaurs tried that, works if the player is not holding an item, if they are it is the same
     
  6. Offline

    Dinosaurs

    Try updating the inventory with an delay
    Code:
    new BukkitRunnable() {
        @Override
        public void run() {
            p.updateInventory();
        }
    }.runTaskLater(plugin, 20);
    
    or possibly setting the contents ...
    Code:
    player.getInventory().setContents(player.getInventory().getContents());
    
    I'm currently unable to reproduce the problem, so i'm kind of at an standstill.
     
Thread Status:
Not open for further replies.

Share This Page