Solved Infinite loop?

Discussion in 'Plugin Development' started by Orange Tabby, Jan 2, 2017.

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

    Orange Tabby

    Solved: I am an idiot, that should be ".runTaskLater" not ".runTaskTimer" sorry about that. lol

    Hi, I am trying to make a kit plugin, and I want the player to be forced to select a kit. But as I was making the inventory reopen after they close it, I ran into an infinite loop problem. When I run the code below I get spammed with "Closed". Why is the InventoryCloseEvent repeating?

    Code:
    @EventHandler
        public void onPlayerCloseInventory(final InventoryCloseEvent e) {
            if (e.getInventory().getName().equals("Custom Menu")) {
                final Player p = (Player) e.getPlayer();
                Bukkit.broadcastMessage("Closed!");
                new BukkitRunnable() {
                    @Override
                    public void run() {
                        p.openInventory(e.getInventory());
                    }
                }.runTaskTimer(kitPvp, 0, 20);
            }
        }
     
    Last edited: Jan 2, 2017
  2. Offline

    davidovski

    you might be better off making one global loop that iterates through online players and checks if they have selected a kit. You could keep a boolean Hashmap to save if they have selected a kit or not.
     
Thread Status:
Not open for further replies.

Share This Page