Solved Forcing keeping an inventory open.

Discussion in 'Plugin Help/Development/Requests' started by ElCreeperHD, Jul 28, 2016.

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

    ElCreeperHD

    Hello. I am making a class plugin and I need to force new players to keep an inventory open when joining the first time to select a class. I am trying to use the InventoryCloseEvent and opening it again, but it doesn't work well. How can I make that with packets or other events?
     
  2. Offline

    I Al Istannen

    @ElCreeperHD
    Wait one (or more) tick after the InventoryCloseEvent and then reopen it again. This worked for me in the past.
     
    ElCreeperHD likes this.
  3. Offline

    ElCreeperHD

    @I Al Istannen Hello. Is there an alternative as I need to access non-final variables?
    Code:
        @EventHandler
        public void CloseInv(InventoryCloseEvent ev){
            Inventory i = ev.getInventory();
            if(i.getName().equalsIgnoreCase(menu.getName()) ){
                new BukkitRunnable() {
                    public void run() {
                        ev.getPlayer().openInventory(ev.getInventory());
                    }
                }.runTaskLater(plugin, 1);
        }
    
            }
     
  4. Offline

    I Al Istannen

    @ElCreeperHD
    Just make the event final (final InventoryCloseEvent ev). You will never assign a new value to it anyways ;)
     
    ElCreeperHD likes this.
  5. Offline

    ElCreeperHD

    @I Al Istannen Thanks! :) I thought that setting that to final could cause problems!
     
  6. Offline

    I Al Istannen

    @ElCreeperHD
    Final just means that this vatiable is a constant and will never be reassigned. You can call methods on it though. As you normally don't assign a new value to the event, you can safely declare it final :)

    Have a nice day ;)
     
Thread Status:
Not open for further replies.

Share This Page