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

    mine-care

    @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.
    Thanks.
     
  3. I can do that, that code isn't the secret bit (the API and class such as OxidePlayer is, however)

    Code:
    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);
                    break;
                 
                case NETHER_STAR:
                    gui = instance.customGUIStore.getGUI(ParticlesHaloMenu.GUI_NAME);
                    break;
                
                case REDSTONE_BLOCK:
                    player.sendMessage(ChatColor.AQUA + "Particle effects disabled");
                    instance.maths.stopEffect(player);
                    player.playSound(player.getLocation(), Sound.ZOMBIE_REMEDY, 1, 1);
                    player.closeInventory();
                    return;
    
                // The chosen slot has no actions bound, do nothing
                default:
                    return;
            }
         
            this.instance.Logger.logDebug("reached end of switch statement with gui name:"+gui.getGuiName());
         
            player.closeInventory();
         
            this.instance.Logger.logDebug("Closing inventory and showing new GUI");
         
            Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(instance, new Runnable() {
                @Override
                public void run() {
                    gui.show(player);
                }
            }, 3L);
        }
    I should note that the log in the console shows that all the values are what they are expected to be. gui.show() isn't working either (which is basically a wrapper for another Inventory object called with player.openInventory())
     
    Last edited: Jan 9, 2016
  4. Offline

    mine-care

    @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 gui.show() (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

    mine-care

    @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

    teej107

    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

    EDIT:
    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