Solved Silent Opening a shulker box causes errors

Discussion in 'Spigot Plugin Development' started by Jonnyo101, Feb 19, 2019.

  1. hello i am trying to allow players to be able to open a shulker box even if there is a block above the box.
    How ever i am getting really weird behaviour and glitches.

    Here is the code used to open the box.
    Code (Java):
       @EventHandler
        public void E_PlayerInteractEvent(final PlayerInteractEvent e) {

            if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {

                final Block clicked = e.getClickedBlock();

                if (clicked.getType().toString().toUpperCase().contains("SHULKER_BOX")) {

                    final ShulkerBox shulkerBox = (ShulkerBox) clicked.getState();
                    final Inventory inventory = shulkerBox.getInventory();

                    if (inventory != null ){
                        e.getPlayer().openInventory(inventory);
                    }

                }

            }
    }
    My inventory BEFORE clicking the shulker box (With a block above)
    [​IMG]

    My inventory after clicking the box ONCE
    [​IMG]
    After clicking the shulker box once you can see my inventory has been messed up even a item been put in my off hand. Also the shulker box its self has also changed to the "Open Animation"
    You can see the shulker box has not opened after clicking it once.

    Clicking the shulker box a second time
    [​IMG]

    Now it opens the box but even after closing my inventory the item are still vanished and messed up.
    Does anyone know why this is happening.

    Version Info:
    [​IMG]
     
  2. Client desync like that occurs when the server is telling the client the wrong slot numbers, usually because the inventory opened is the wrong size. Because you're in creative, the server just accepts whatever the client thinks it should have.

    Looks like you're using the API correctly and it's likely a Spigot issue. Unfortunately, 1.12 is old, so you're not likely to see it fixed.
     
  3. This bug still happens when in survival.

    So is there no other way to open the inventory in a forced way where having blocks above the shulker box does not block it from opening or a work around for the bug
     
  4. What do you mean with clicking the Shulker Box once and a second time?
    Can you elaborate on this?


    A possible workaround:
    If this behaviour isn't fixable by normal means and you can't / don't want to upgrade to 1.13, then you could probably use a fake chest inventory and "copy" the Shulker Box items into that inventory, so that your bug doesn't appear and after making a change to that inventory, also make that change to the real Shulker Box inventory (without opening the inventory for the player).
    But be careful when you do this, since it can bring a lot of other problems with it, if you don't implement it correctly (item duping on concurrent access of that inventory for example).
     
  5. Yer i was thinking of opening a fake chest. But i am going upgrade the plugin to 1.13 and see if it fixes the problem.
     
  6. By java conventions, functions should be named MyFunction and variables myVariable without under score or another special character
     
  7. Yes i know that.. I do not see how this is helping with my problem ?
    I have dyslexia and rely more on colours of things in my editor rather then the naming conventions.
     
    • Agree Agree x 1
  8. Okay this is solved. Updating to 1.13 seems to have fixed the problem.
     
  9. Shouldn’t a function name start with a lower case if you are using The convention proposed by SunMicrosystems?
     
  10. Auto correction xd It's my phone. Functions should be named lowerCamelCase, you're right