Solved Re-opening the menu when closing it leads to overload and crash of the server.

Discussion in 'Plugin Development' started by Flioris, Dec 20, 2023.

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

    Flioris

    When InventoryCloseEvent was triggered, I tried to re-open the class selection menu if the player had not selected it, but this caused overload and crashed the server. Then I came up with a temporary solution: set a delay for re-opening the menu. I don't know how else to solve this problem, so I wrote here. My decision doesn't seem entirely rational to me.

    Code:
        @EventHandler
        private void onInventoryClose(InventoryCloseEvent event) {
            Player player = (Player) event.getPlayer();
            Inventory inv = event.getInventory();
            if (inv == GUI.getSelectMenu() && WizardHandler.getWizard(player) == null) new BukkitRunnable(){
                @Override
                public void run() {
                    player.openInventory(GUI.getSelectMenu());
                }
            }.runTaskLater(Koritohi.getPlugin(), 10);
        }
     
  2. Offline

    timtower Administrator Administrator Moderator

    @Flioris I don't see code in there that stops opening the inventory after they picked something .
    And every time they close an inventory a new runnable is started.

    Make 1 runnable that is always running and is checking every online player
     
  3. Offline

    Flioris

    If WizardHandler.getWizard(player) == null, then this means that the player has not selected anything.
     
  4. Offline

    timtower Administrator Administrator Moderator

    Wait, thought I saw runTaskTimer.
    Considered increasing the time? To see what is happening?
     
  5. Offline

    Flioris

    A server crash occurs if there is no delay before re-opening the menu. If there is any delay, then everything works fine.
     
  6. Offline

    timtower Administrator Administrator Moderator

    Can you post the server log then?
     
  7. Offline

    Flioris

     

    Attached Files:

  8. Offline

    timtower Administrator Administrator Moderator

    @Flioris And what is wrong with having the delay? Because in this case you need it: you are still in the process of closing an inventory, opening a new one with one open will require closing first.
    And you have an infinite loop.
     
  9. Offline

    Flioris

    Okay, if there is no other solution, I'll close the thread.
     
  10. Offline

    timtower Administrator Administrator Moderator

    Could try to keep the timer but set it to 0, could be that it runs on the next tick instead of right away.
     
Thread Status:
Not open for further replies.

Share This Page