Inventory Bugged?

Discussion in 'Plugin Development' started by Jalau, Dec 26, 2013.

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

    Jalau

    I often have the bug that players need to relog because the inventory just changes for the client, they cant drop items (they disapear out of inv but don't drop on ground) and moving items is just handled by the client because after a relog the items are at the same spot as before this bug happened... Dropping etc works if you do this while you have a chest / other inventory open.... I have a huge self coded RPG Plugin and i sometimes use updateInventory() and can this cause this bug? Or you have any idea or heard of it before?!
    Thanks for help
    Jalau
     
  2. Offline

    werter318

    you are probably adding the items in a bad way.. What methods do you use?
     
  3. Offline

    Jalau

    inv.addItem(is); most of the time, or when i create inventorys: inv.setItem(x, is);

    p.getInventory().setItem(x, null); Is this wrong if i want to remove a item?

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

    Likaos

    You need to resend Inventory to player with player.updateInventory(), or use the nms way cause it's deprecated in bukkit (why ?)

    On your listener drop/click event, use if event.isCancelled() updateInventory to avoid this "bug".

    After that, remind the 1.7.2 client have a bug on inventory event cancel, use 1.7.4 client.

    The setItem null remove item, but you could have to use the updateInventory depending of the event, else use a "consumme" code like that, I use material.air instead of null that seems send an update inventory information to player.

    Code:
        // Consommer un item
        public static void consumItemInHand(Player player) {
            PlayerInventory inv = player.getInventory();
            int amount = inv.getItemInHand().getAmount();
            if (amount == 1) {
                inv.setItemInHand(new ItemStack(Material.AIR));
                return;
            }
            amount--;
            inv.getItemInHand().setAmount(amount);
        }
    Finaly, keep in mind bukkit do first your stuff in a listener and if cancelled revert the initial state of the things, sometime can to odd things, could use scheduler to run things 1 tick later and solve 99% of your problems (respawnEvent teleport, foodListener or SprintListener for example)
     
    Jalau likes this.
  5. Offline

    Jalau


    I appreciate the help ;) What do you mean by Bukkit dot? Bukkit.getServer()?
     
  6. Offline

    Likaos

    Was a "Do", my english have sometimes bugs too ^^.

    What I say, dont forget when you use bukkit event system, the event fire when the event happen, for example the event PlayerRespawnEvent happen when the player click on the respawn button, not when he is alive so changing is inventory or trying to teleport him will not work.

    For the sprintEvent if you check the sprintState of the player you will have the reverse result cause the fire happen before he really sprint, just when he press the CTRL.

    When you completly understand this system, you will have to understand the second, the cancel :D.

    Example: Food event

    Player have 20 food and drop to 19, event fire
    You change the foodLevel to 20
    After the event the player will have 19 in food level, you have to cancel it to make your foodChange works.

    Its the same things for items in inventory, sometimes the event let you change them and will update correctly the client, sometime you will have to deal with the cancelSystem and your way to alter the event.

    I'm not sure to be clear, but try and experiments with this in mind ^^.
     
    Jalau likes this.
  7. Offline

    Jalau

    Thanks, really helpfull will try!
     
Thread Status:
Not open for further replies.

Share This Page