Player.closeInventory() and openInventory() ignored after relog

Discussion in 'Plugin Development' started by xorinzor, Jan 9, 2016.

Thread Status:
Not open for further replies.
  1. I am running into a very weird issue where player.closeInventory() is completely ignored by the client when the player relogs.

    My code is a bit too complex to share here unfortunatly (as well as the source must be kept secret); however I have googled for similar issues and made sure to use .equals where nessecary for value comparisons.
    the Player instance used is not null either, it just seems to be broken after relogging.

    The eventlisteners such as inventoryclickevent, playerjoinevent and playerquitevent still trigger as they should.

    What could be a cause for this and has this happened to anyone before? if so, how did you manage to solve it?
  2. Offline


    @xorinzor Could we see a litle piece of code arround the area where you use Player#closeInventory();?
    We are not going to steal any code but it is required to pinpoint the issue.
  3. I can do that, that code isn't the secret bit (the API and class such as OxidePlayer is, however)

    public void onSlotClickEvent(InventoryClickEvent event) {
            OxidePlayer oxidePlayer = instance.Api.getPlayer(event.getWhoClicked().getUniqueId());
            this.instance.Logger.logDebug("onSlotClickEvent player uuid: "+event.getWhoClicked().getUniqueId());
            Player player = oxidePlayer.getPlayer();
            CustomGUIBase gui;
            this.instance.Logger.logDebug("clicked item of type: "+event.getCurrentItem().getType().toString());
            // Perform an action depending on the Material
            switch (event.getCurrentItem().getType()) {
                case BONE:
                    gui = instance.customGUIStore.getGUI(ParticlesLineMenu.GUI_NAME);
                case NETHER_STAR:
                    gui = instance.customGUIStore.getGUI(ParticlesHaloMenu.GUI_NAME);
                case REDSTONE_BLOCK:
                    player.sendMessage(ChatColor.AQUA + "Particle effects disabled");
                    player.playSound(player.getLocation(), Sound.ZOMBIE_REMEDY, 1, 1);
                // The chosen slot has no actions bound, do nothing
            this.instance.Logger.logDebug("reached end of switch statement with gui name:"+gui.getGuiName());
            this.instance.Logger.logDebug("Closing inventory and showing new GUI");
            Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(instance, new Runnable() {
                public void run() {
            }, 3L);
    I should note that the log in the console shows that all the values are what they are expected to be. isn't working either (which is basically a wrapper for another Inventory object called with player.openInventory())
    Last edited: Jan 9, 2016
  4. Offline


    @xorinzor So you are reaching the "Closing inventory and showing new GUI" right?
    So that part works untill the player disconnects and comes back in.
    When the player relogs and clicks the inventory, what point does the code reach?
    Also do you sture the player in ANY Collection / Map ?

    P.S Dont forget to tahg me, otherwise i wont be notified :S do @mine-care :)
    Last edited: Jan 9, 2016
  5. @mine-care

    All code is reached, including the player.openInventory() method within the (as seen in the bottom of the code snippet).

    The closeInventory() and openInventory() methods work until a player relogs, from there they are completely ignored and the code will continue executing without throwing any errors.

    InventoryClickEvents also show they are working as intended (I am pretty much logging everything right now just to figure this out).

    the OxidePlayer object is kept in an hashmap<uuid, OxidePlayer>, whenever a player quit's it's instance gets removed from the list and re-added when he logs in.

    the OxidePlayer class has a remove method that's called before the instance is removed, which will nullify all variables inside the class and unset the Player instance reference.

    When a player logs back in the a new OxidePlayer instance will be created and the Player instance reference is created using Bukkit.getPlayer(uuid);
  6. Offline


    @xorinzor Hmm Wow... that sounds peculiar!
    Never faced anything alike :eek:
    I think its up to more experienced members (**cough cough** @teej107 **cough cough**) to take a look :eek:
    Sorry mate :(
  7. no problem, thanks for trying
    mine-care likes this.
  8. Offline


    xorinzor likes this.
  9. Interesting, I never knew this, guess you learn something new every day :)
    I'll update my code, test it and report back!

    @teej107 unfortunatly wrapping closeInventory() in a runTask did not help

    The issue doesn't occur the 1st time a player joins either, it's strictly when a player relogs

    I have located the issue, I was storing a reference to the player instance in my OxidePlayer class instance, I changed this to not do that and instead just return Bukkit.getPlayer(uuid); and now it seems to work.
    I'm qurious as to why this matters since I was removing the reference (ie: this.player = null;) when the PlayerQuitEvent was called to make sure it wouldn't be kept loaded while the player wasn't online.
    Last edited: Jan 9, 2016
Thread Status:
Not open for further replies.

Share This Page