diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java index 0af02e0..d93b9f3 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java @@ -28,7 +28,6 @@ import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.MenuManager; import me.filoghost.chestcommands.api.Icon; import me.filoghost.chestcommands.api.IconMenu; -import me.filoghost.chestcommands.task.ExecuteActionsTask; import java.util.HashMap; import java.util.Map; @@ -95,8 +94,14 @@ public class InventoryListener implements Listener { } } - // Closes the inventory and executes actions AFTER the event - Bukkit.getScheduler().runTask(ChestCommands.getInstance(), new ExecuteActionsTask(clicker, icon)); + // Only handle the click AFTER the event has finished + Bukkit.getScheduler().runTask(ChestCommands.getInstance(), () -> { + boolean close = icon.onClick(clicker); + + if (close) { + clicker.closeInventory(); + } + }); } @EventHandler diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/task/ExecuteActionsTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/task/ExecuteActionsTask.java deleted file mode 100644 index ac6e403..0000000 --- a/Plugin/src/main/java/me/filoghost/chestcommands/task/ExecuteActionsTask.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.task; - -import org.bukkit.entity.Player; - -import me.filoghost.chestcommands.api.Icon; - -public class ExecuteActionsTask implements Runnable { - - private Player player; - private Icon icon; - - - public ExecuteActionsTask(Player player, Icon icon) { - this.player = player; - this.icon = icon; - } - - - @Override - public void run() { - boolean close = icon.onClick(player); - - if (close) { - player.closeInventory(); - } - } - - -}