summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKrakenied <Krakenied1@gmail.com>2024-02-10 19:56:50 +0100
committerLeonardo Bishop <13875753+LMBishop@users.noreply.github.com>2024-02-17 13:45:29 +0000
commit832e99ce535008ffeb1bf2d63cebb21583262035 (patch)
tree2090ff1ed7f265844d9b9b4e98540832637dbdfd
parent48ee7a64be995c316cc56abb226347b778ea8e06 (diff)
Ensure that custom menu element commands are ran from Folia GlobalTickThread
Closes https://github.com/LMBishop/Quests/issues/601
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/menu/element/CustomMenuElement.java15
1 files changed, 12 insertions, 3 deletions
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/menu/element/CustomMenuElement.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/menu/element/CustomMenuElement.java
index 644ec332..048ad48d 100644
--- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/menu/element/CustomMenuElement.java
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/menu/element/CustomMenuElement.java
@@ -14,6 +14,7 @@ import java.util.UUID;
public class CustomMenuElement extends MenuElement{
+ private final BukkitQuestsPlugin plugin;
private final ItemStack itemStack;
private final List<String> commands;
private final String playerName;
@@ -23,6 +24,7 @@ public class CustomMenuElement extends MenuElement{
}
public CustomMenuElement(BukkitQuestsPlugin plugin, UUID owner, String name, ItemStack itemStack, List<String> commands) {
+ this.plugin = plugin;
this.itemStack = MenuUtils.applyPlaceholders(plugin, owner, itemStack);
this.commands = commands;
this.playerName = name;
@@ -35,10 +37,17 @@ public class CustomMenuElement extends MenuElement{
@Override
public ClickResult handleClick(ClickType clickType) {
- for (String command : commands) {
- Bukkit.dispatchCommand(Bukkit.getConsoleSender(),
- command.replace("{player}", playerName));
+ if (commands.isEmpty()) {
+ return ClickResult.DO_NOTHING;
}
+
+ this.plugin.getScheduler().runTask(() -> {
+ for (String command : commands) {
+ command = command.replace("{player}", playerName);
+ Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
+ }
+ });
+
return ClickResult.DO_NOTHING;
}