From 3dc65c746a163728e8014be99655cd393f1545d6 Mon Sep 17 00:00:00 2001 From: Stabrinai Date: Thu, 7 Mar 2024 16:05:00 +0800 Subject: [PATCH 1/9] Support folia using Energie --- build.gradle | 3 ++- .../commandprompter/CommandPrompter.java | 17 +++++++++++++---- .../commandprompter/api/Dispatcher.java | 19 +++++-------------- .../hook/hooks/CarbonChatHook.java | 3 ++- .../commandprompter/prompt/PromptManager.java | 14 ++++++++------ .../commandprompter/prompt/PromptQueue.java | 7 ++++--- .../prompt/prompts/ChatPrompt.java | 3 ++- .../prompt/prompts/PlayerUIPrompt.java | 3 ++- .../commandprompter/prompt/ui/HeadCache.java | 3 ++- src/main/resources/plugin.yml | 1 + 10 files changed, 41 insertions(+), 32 deletions(-) diff --git a/build.gradle b/build.gradle index a7c6fb0..3745ed3 100644 --- a/build.gradle +++ b/build.gradle @@ -33,7 +33,7 @@ compileTestJava.options.encoding = "UTF-8" java { toolchain { - languageVersion = JavaLanguageVersion.of(16) + languageVersion = JavaLanguageVersion.of(17) } } @@ -69,6 +69,7 @@ dependencies { implementation 'org.bstats:bstats-bukkit:3.0.0' implementation "dev.jorel:commandapi-bukkit-shade:9.3.0" implementation group: 'org.fusesource.jansi', name: 'jansi', version: '2.4.0' + implementation("com.github.Euphillya:Energie:5659f25e22") // Exclude these implementation 'me.lucko:jar-relocator:1.7' diff --git a/src/main/java/com/cyr1en/commandprompter/CommandPrompter.java b/src/main/java/com/cyr1en/commandprompter/CommandPrompter.java index 547969a..acacc8e 100644 --- a/src/main/java/com/cyr1en/commandprompter/CommandPrompter.java +++ b/src/main/java/com/cyr1en/commandprompter/CommandPrompter.java @@ -45,6 +45,9 @@ import com.cyr1en.kiso.mc.I18N; import com.cyr1en.kiso.mc.UpdateChecker; import com.cyr1en.kiso.utils.SRegex; +import fr.euphyllia.energie.Energie; +import fr.euphyllia.energie.model.Scheduler; +import fr.euphyllia.energie.model.SchedulerType; import org.bstats.bukkit.Metrics; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -70,9 +73,12 @@ public class CommandPrompter extends JavaPlugin { private PluginMessenger messenger; private HeadCache headCache; private CommandAPIWrapper commandAPIWrapper; + private Energie energie; @Override public void onEnable() { + instance = this; + energie = new Energie(this); new Metrics(this, 5359); setupConfig(); @@ -96,10 +102,9 @@ public void onEnable() { initPromptSystem(); setupCommands(); - instance = this; Bukkit.getPluginManager().registerEvents(new CommandSendListener(this), this); - Bukkit.getScheduler().runTaskLater(this, () -> { + getScheduler().runDelayed(SchedulerType.SYNC, task -> { hookContainer = new HookContainer(this); hookContainer.initHooks(); headCache.registerFilters(); @@ -172,7 +177,7 @@ private void initCommandListener() { return; } var delay = (long) config.modificationDelay(); - Bukkit.getScheduler().runTaskLater(this, this::hackMap, delay); + getScheduler().runDelayed(SchedulerType.SYNC, task -> this.hackMap(), delay); } private void hackMap() { @@ -209,7 +214,7 @@ private void setupUpdater() { updateChecker = new UpdateChecker(this, 47772); if (updateChecker.isDisabled()) return; - Bukkit.getServer().getScheduler().runTaskAsynchronously(this, () -> { + getScheduler().runTask(SchedulerType.ASYNC, task -> { if (updateChecker.newVersionAvailable()) logger.info(SRegex.ANSI_GREEN + "A new update is available! (" + updateChecker.getCurrVersion().asString() + ")" + SRegex.ANSI_RESET); @@ -223,6 +228,10 @@ public I18N getI18N() { return i18n; } + public Scheduler getScheduler() { + return energie.getScheduler(Energie.SchedulerSoft.MINECRAFT); + } + public HookContainer getHookContainer() { return this.hookContainer; } diff --git a/src/main/java/com/cyr1en/commandprompter/api/Dispatcher.java b/src/main/java/com/cyr1en/commandprompter/api/Dispatcher.java index 8419fbe..6fa67bd 100644 --- a/src/main/java/com/cyr1en/commandprompter/api/Dispatcher.java +++ b/src/main/java/com/cyr1en/commandprompter/api/Dispatcher.java @@ -25,11 +25,11 @@ package com.cyr1en.commandprompter.api; import com.cyr1en.commandprompter.CommandPrompter; +import fr.euphyllia.energie.model.SchedulerType; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; -import org.bukkit.scheduler.BukkitRunnable; import org.jetbrains.annotations.NotNull; /** @@ -47,17 +47,12 @@ public class Dispatcher { * Dispatches command by forcing a player to chat the command. * This will allow plugins to support CommandPrompter. * - * @param plugin Instance of plugin. * @param sender command sender (in menu's, then the item clicker) * @param command command that would be dispatched. */ - public static void dispatchCommand(Plugin plugin, Player sender, String command) { + public static void dispatchCommand(Player sender, String command) { final String checked = command.codePointAt(0) == 0x2F ? command : "/" + command; - new BukkitRunnable() { - public void run() { - sender.chat(checked); - } - }.runTask(plugin); + CommandPrompter.getInstance().getScheduler().runTask(SchedulerType.SYNC, task -> sender.chat(checked)); } /** @@ -67,11 +62,7 @@ public void run() { */ public static void dispatchConsole(final String command) { final String checked = command.codePointAt(0) == 0x2F ? command.substring(1) : command; - new BukkitRunnable() { - public void run() { - Bukkit.dispatchCommand(Bukkit.getConsoleSender(), checked); - } - }.runTask(CommandPrompter.getInstance()); + CommandPrompter.getInstance().getScheduler().runTask(SchedulerType.SYNC, task -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), checked)); } /** @@ -103,7 +94,7 @@ public static void dispatchWithAttachment(Plugin plugin, Player sender, String c } attachment.getPermissible().recalculatePermissions(); final String checked = command.codePointAt(0) == 0x2F ? command.substring(1) : command; - Bukkit.dispatchCommand(sender, checked); + CommandPrompter.getInstance().getScheduler().runTask(SchedulerType.SYNC, task -> Bukkit.dispatchCommand(sender, checked)); //dispatchCommand(plugin, sender, command); sender.removeAttachment(attachment); } diff --git a/src/main/java/com/cyr1en/commandprompter/hook/hooks/CarbonChatHook.java b/src/main/java/com/cyr1en/commandprompter/hook/hooks/CarbonChatHook.java index eaa154f..9a1a46f 100644 --- a/src/main/java/com/cyr1en/commandprompter/hook/hooks/CarbonChatHook.java +++ b/src/main/java/com/cyr1en/commandprompter/hook/hooks/CarbonChatHook.java @@ -4,6 +4,7 @@ import com.cyr1en.commandprompter.hook.annotations.TargetPlugin; import com.cyr1en.commandprompter.prompt.PromptContext; import com.cyr1en.commandprompter.prompt.PromptManager; +import fr.euphyllia.energie.model.SchedulerType; import net.draycia.carbon.api.CarbonChatProvider; import net.draycia.carbon.api.events.CarbonChatEvent; import net.kyori.adventure.text.Component; @@ -58,6 +59,6 @@ public void handle(CarbonChatEvent event) { msg = prompt.sanitizeInput() ? ds : msg; } var ctx = new PromptContext.Builder().setSender(player).setContent(msg).build(); - Bukkit.getScheduler().runTask(getPlugin(), () -> promptManager.processPrompt(ctx)); + CommandPrompter.getInstance().getScheduler().runTask(SchedulerType.SYNC, task -> promptManager.processPrompt(ctx)); } } diff --git a/src/main/java/com/cyr1en/commandprompter/prompt/PromptManager.java b/src/main/java/com/cyr1en/commandprompter/prompt/PromptManager.java index 6b883b8..92b31e6 100644 --- a/src/main/java/com/cyr1en/commandprompter/prompt/PromptManager.java +++ b/src/main/java/com/cyr1en/commandprompter/prompt/PromptManager.java @@ -31,6 +31,8 @@ import com.cyr1en.commandprompter.prompt.prompts.PlayerUIPrompt; import com.cyr1en.commandprompter.prompt.prompts.SignPrompt; import com.cyr1en.commandprompter.util.Util; +import fr.euphyllia.energie.model.Scheduler; +import fr.euphyllia.energie.model.SchedulerType; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; @@ -61,13 +63,13 @@ public class PromptManager extends HashMap> { private final CommandPrompter plugin; private final PromptRegistry promptRegistry; private final PromptParser promptParser; - private final BukkitScheduler scheduler; + private final Scheduler scheduler; public PromptManager(CommandPrompter commandPrompter) { this.plugin = commandPrompter; this.promptRegistry = new PromptRegistry(plugin); this.promptParser = new PromptParser(this); - this.scheduler = Bukkit.getScheduler(); + this.scheduler = CommandPrompter.getInstance().getScheduler(); } public void registerPrompts() { @@ -88,7 +90,7 @@ public Class put(String key, Class value) { public void parse(PromptContext context) { var queueHash = promptParser.parsePrompts(context); var timeout = plugin.getConfiguration().promptTimeout(); - scheduler.runTaskLater(plugin, () -> cancel(context.getSender(), queueHash), 20L * timeout); + scheduler.runDelayed(SchedulerType.SYNC, task -> cancel(context.getSender(), queueHash), 20L * timeout); } public void sendPrompt(CommandSender sender) { @@ -102,7 +104,7 @@ public void sendPrompt(CommandSender sender) { if (!queue.isEmpty()) { var prompt = Objects.requireNonNull(queue.peek()); - Bukkit.getScheduler().runTaskLater(plugin, prompt::sendPrompt, 2L); + scheduler.runDelayed(SchedulerType.SYNC, task -> prompt.sendPrompt(), 2L); plugin.getPluginLogger().debug("Sent %s to %s", prompt.getClass().getSimpleName(), sender.getName()); } else if (queue.containsPCM()) { // This means queue is empty but contains PCM. If it does, we just dispatch it. @@ -177,7 +179,7 @@ private void dispatchQueue(CommandSender sender, PromptQueue queue) { sender.setOp(false); plugin.getPluginLogger().debug("Remove OP status"); // Redundancy for de-op - Bukkit.getScheduler().runTaskLater(plugin, () -> { + scheduler.runDelayed(SchedulerType.SYNC, task -> { plugin.getPluginLogger().debug("Remove OP status (redundancy)"); sender.setOp(false); }, 2L); @@ -231,7 +233,7 @@ public void cancel(CommandSender sender, int queueHash) { return; if (pcm.delayTicks() > 0) - plugin.getServer().getScheduler().runTaskLater(plugin, () -> queue.execPCM(pcm, (Player) sender), + plugin.getScheduler().runDelayed(SchedulerType.SYNC, task -> queue.execPCM(pcm, (Player) sender), pcm.delayTicks()); else queue.execPCM(pcm, (Player) sender); diff --git a/src/main/java/com/cyr1en/commandprompter/prompt/PromptQueue.java b/src/main/java/com/cyr1en/commandprompter/prompt/PromptQueue.java index 03f26d0..cefeb5f 100644 --- a/src/main/java/com/cyr1en/commandprompter/prompt/PromptQueue.java +++ b/src/main/java/com/cyr1en/commandprompter/prompt/PromptQueue.java @@ -6,6 +6,7 @@ import com.cyr1en.commandprompter.api.prompt.Prompt; import com.cyr1en.commandprompter.util.MMUtil; import com.cyr1en.kiso.utils.SRegex; +import fr.euphyllia.energie.model.SchedulerType; import org.bukkit.entity.Player; import java.util.Arrays; @@ -107,7 +108,7 @@ public void dispatch(CommandPrompter plugin, Player sender) { plugin.getConfiguration().permissionAttachmentTicks(), plugin.getConfiguration().getPermissionAttachment(permissionAttachmentKey)); } else - Dispatcher.dispatchCommand(plugin, sender, getCompleteCommand()); + Dispatcher.dispatchCommand(sender, getCompleteCommand()); if (!postCommandMetas.isEmpty()) postCommandMetas.forEach(pcm -> { @@ -115,7 +116,7 @@ public void dispatch(CommandPrompter plugin, Player sender) { return; if (pcm.delayTicks() > 0) - plugin.getServer().getScheduler().runTaskLater(plugin, () -> execPCM(pcm, sender), + plugin.getScheduler().runDelayed(SchedulerType.SYNC, task -> execPCM(pcm, sender), pcm.delayTicks()); else execPCM(pcm, sender); @@ -138,7 +139,7 @@ void execPCM(PostCommandMeta postCommandMeta, Player sender) { Dispatcher.dispatchConsole(command); } else { logger.debug("Dispatching PostCommand as player"); - Dispatcher.dispatchCommand(CommandPrompter.getInstance(), sender, command); + Dispatcher.dispatchCommand(sender, command); } } diff --git a/src/main/java/com/cyr1en/commandprompter/prompt/prompts/ChatPrompt.java b/src/main/java/com/cyr1en/commandprompter/prompt/prompts/ChatPrompt.java index cf7d15b..660f328 100644 --- a/src/main/java/com/cyr1en/commandprompter/prompt/prompts/ChatPrompt.java +++ b/src/main/java/com/cyr1en/commandprompter/prompt/prompts/ChatPrompt.java @@ -32,6 +32,7 @@ import com.cyr1en.commandprompter.prompt.PromptParser; import com.cyr1en.commandprompter.unsafe.PvtFieldMutator; import es.capitanpuerka.puerkaschat.manager.PuerkasFormat; +import fr.euphyllia.energie.model.SchedulerType; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.HoverEvent; @@ -138,7 +139,7 @@ public void onResponse(Player player, String msg, Cancellable event) { .setSender(player) .setContent(msg).build(); - Bukkit.getScheduler().runTask(plugin, () -> manager.processPrompt(ctx)); + CommandPrompter.getInstance().getScheduler().runTask(SchedulerType.SYNC, task -> manager.processPrompt(ctx)); } } diff --git a/src/main/java/com/cyr1en/commandprompter/prompt/prompts/PlayerUIPrompt.java b/src/main/java/com/cyr1en/commandprompter/prompt/prompts/PlayerUIPrompt.java index 91ee412..446eef2 100644 --- a/src/main/java/com/cyr1en/commandprompter/prompt/prompts/PlayerUIPrompt.java +++ b/src/main/java/com/cyr1en/commandprompter/prompt/prompts/PlayerUIPrompt.java @@ -34,6 +34,7 @@ import com.cyr1en.commandprompter.util.Util; import com.github.stefvanschie.inventoryframework.gui.type.ChestGui; import com.github.stefvanschie.inventoryframework.pane.PaginatedPane; +import fr.euphyllia.energie.model.SchedulerType; import org.bukkit.Bukkit; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; @@ -211,7 +212,7 @@ public void sendPrompt() { getPlugin().getPluginLogger().debug("Missing heads in cache, rebuilding before sending..."); headCache.reBuildCache().thenAccept(cache -> { getPlugin().getPluginLogger().debug("Rebuilt cache!"); - Bukkit.getScheduler().runTask(getPlugin(), () -> send(p)); + CommandPrompter.getInstance().getScheduler().runTask(SchedulerType.SYNC, task -> send(p)); }); } else { send(p); diff --git a/src/main/java/com/cyr1en/commandprompter/prompt/ui/HeadCache.java b/src/main/java/com/cyr1en/commandprompter/prompt/ui/HeadCache.java index 204ac9d..cafa905 100644 --- a/src/main/java/com/cyr1en/commandprompter/prompt/ui/HeadCache.java +++ b/src/main/java/com/cyr1en/commandprompter/prompt/ui/HeadCache.java @@ -11,6 +11,7 @@ import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableMap; +import fr.euphyllia.energie.model.SchedulerType; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -227,7 +228,7 @@ public void onPlayerLogin(PlayerLoginEvent e) { var cacheDelay = plugin.getPromptConfig().cacheDelay(); logger.debug("Caching Delay: %s", cacheDelay); - Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, () -> { + CommandPrompter.getInstance().getScheduler().runDelayed(SchedulerType.ASYNC, task -> { if (isVanished(e.getPlayer())) { logger.debug("Player is vanished"); return; diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 72eda8a..7449af1 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -6,6 +6,7 @@ softdepend: [VentureChat, SuperVanish, PuerkasChat, PlaceholderAPI, CarbonChat, main: ${projectEntry} api-version: 1.13 +folia-supported: true permissions: commandprompter.reload: From ab53768ebfd4271c8769e04a6e5b7fd38d6e0bac Mon Sep 17 00:00:00 2001 From: Stabrinai Date: Thu, 7 Mar 2024 17:12:37 +0800 Subject: [PATCH 2/9] Disable setupUpdater() if server is folia --- src/main/java/com/cyr1en/commandprompter/CommandPrompter.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/cyr1en/commandprompter/CommandPrompter.java b/src/main/java/com/cyr1en/commandprompter/CommandPrompter.java index acacc8e..f0a8b0c 100644 --- a/src/main/java/com/cyr1en/commandprompter/CommandPrompter.java +++ b/src/main/java/com/cyr1en/commandprompter/CommandPrompter.java @@ -211,6 +211,7 @@ private void setupCommands() { } private void setupUpdater() { + if (Energie.isFolia()) return; updateChecker = new UpdateChecker(this, 47772); if (updateChecker.isDisabled()) return; From 6d52339bc316b275533c64ea4ea575b7c09a391e Mon Sep 17 00:00:00 2001 From: Stabrinai Date: Thu, 7 Mar 2024 18:33:33 +0800 Subject: [PATCH 3/9] replace CommandPrompter.getInstance().getScheduler() to plugin.getScheduler() --- .../cyr1en/commandprompter/CommandPrompter.java | 14 +++++--------- .../com/cyr1en/commandprompter/api/Dispatcher.java | 6 +++--- .../commandprompter/hook/hooks/CarbonChatHook.java | 2 +- .../commandprompter/prompt/PromptManager.java | 4 ++-- .../cyr1en/commandprompter/prompt/PromptQueue.java | 2 +- .../commandprompter/prompt/prompts/ChatPrompt.java | 2 +- .../prompt/prompts/PlayerUIPrompt.java | 2 +- .../commandprompter/prompt/ui/HeadCache.java | 2 +- 8 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/cyr1en/commandprompter/CommandPrompter.java b/src/main/java/com/cyr1en/commandprompter/CommandPrompter.java index f0a8b0c..879abfd 100644 --- a/src/main/java/com/cyr1en/commandprompter/CommandPrompter.java +++ b/src/main/java/com/cyr1en/commandprompter/CommandPrompter.java @@ -59,6 +59,7 @@ public class CommandPrompter extends JavaPlugin { private static CommandPrompter instance; + public static Scheduler scheduler; private ConfigurationManager configManager; private CommandPrompterConfig config; @@ -73,12 +74,11 @@ public class CommandPrompter extends JavaPlugin { private PluginMessenger messenger; private HeadCache headCache; private CommandAPIWrapper commandAPIWrapper; - private Energie energie; @Override public void onEnable() { instance = this; - energie = new Energie(this); + scheduler = new Energie(this).getScheduler(Energie.SchedulerSoft.MINECRAFT); new Metrics(this, 5359); setupConfig(); @@ -104,7 +104,7 @@ public void onEnable() { Bukkit.getPluginManager().registerEvents(new CommandSendListener(this), this); - getScheduler().runDelayed(SchedulerType.SYNC, task -> { + scheduler.runDelayed(SchedulerType.SYNC, task -> { hookContainer = new HookContainer(this); hookContainer.initHooks(); headCache.registerFilters(); @@ -177,7 +177,7 @@ private void initCommandListener() { return; } var delay = (long) config.modificationDelay(); - getScheduler().runDelayed(SchedulerType.SYNC, task -> this.hackMap(), delay); + scheduler.runDelayed(SchedulerType.SYNC, task -> this.hackMap(), delay); } private void hackMap() { @@ -215,7 +215,7 @@ private void setupUpdater() { updateChecker = new UpdateChecker(this, 47772); if (updateChecker.isDisabled()) return; - getScheduler().runTask(SchedulerType.ASYNC, task -> { + scheduler.runTask(SchedulerType.ASYNC, task -> { if (updateChecker.newVersionAvailable()) logger.info(SRegex.ANSI_GREEN + "A new update is available! (" + updateChecker.getCurrVersion().asString() + ")" + SRegex.ANSI_RESET); @@ -229,10 +229,6 @@ public I18N getI18N() { return i18n; } - public Scheduler getScheduler() { - return energie.getScheduler(Energie.SchedulerSoft.MINECRAFT); - } - public HookContainer getHookContainer() { return this.hookContainer; } diff --git a/src/main/java/com/cyr1en/commandprompter/api/Dispatcher.java b/src/main/java/com/cyr1en/commandprompter/api/Dispatcher.java index 6fa67bd..5cb5a86 100644 --- a/src/main/java/com/cyr1en/commandprompter/api/Dispatcher.java +++ b/src/main/java/com/cyr1en/commandprompter/api/Dispatcher.java @@ -52,7 +52,7 @@ public class Dispatcher { */ public static void dispatchCommand(Player sender, String command) { final String checked = command.codePointAt(0) == 0x2F ? command : "/" + command; - CommandPrompter.getInstance().getScheduler().runTask(SchedulerType.SYNC, task -> sender.chat(checked)); + CommandPrompter.scheduler.runTask(SchedulerType.SYNC, task -> sender.chat(checked)); } /** @@ -62,7 +62,7 @@ public static void dispatchCommand(Player sender, String command) { */ public static void dispatchConsole(final String command) { final String checked = command.codePointAt(0) == 0x2F ? command.substring(1) : command; - CommandPrompter.getInstance().getScheduler().runTask(SchedulerType.SYNC, task -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), checked)); + CommandPrompter.scheduler.runTask(SchedulerType.SYNC, task -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), checked)); } /** @@ -94,7 +94,7 @@ public static void dispatchWithAttachment(Plugin plugin, Player sender, String c } attachment.getPermissible().recalculatePermissions(); final String checked = command.codePointAt(0) == 0x2F ? command.substring(1) : command; - CommandPrompter.getInstance().getScheduler().runTask(SchedulerType.SYNC, task -> Bukkit.dispatchCommand(sender, checked)); + CommandPrompter.scheduler.runTask(SchedulerType.SYNC, task -> Bukkit.dispatchCommand(sender, checked)); //dispatchCommand(plugin, sender, command); sender.removeAttachment(attachment); } diff --git a/src/main/java/com/cyr1en/commandprompter/hook/hooks/CarbonChatHook.java b/src/main/java/com/cyr1en/commandprompter/hook/hooks/CarbonChatHook.java index 9a1a46f..d9ad454 100644 --- a/src/main/java/com/cyr1en/commandprompter/hook/hooks/CarbonChatHook.java +++ b/src/main/java/com/cyr1en/commandprompter/hook/hooks/CarbonChatHook.java @@ -59,6 +59,6 @@ public void handle(CarbonChatEvent event) { msg = prompt.sanitizeInput() ? ds : msg; } var ctx = new PromptContext.Builder().setSender(player).setContent(msg).build(); - CommandPrompter.getInstance().getScheduler().runTask(SchedulerType.SYNC, task -> promptManager.processPrompt(ctx)); + CommandPrompter.scheduler.runTask(SchedulerType.SYNC, task -> promptManager.processPrompt(ctx)); } } diff --git a/src/main/java/com/cyr1en/commandprompter/prompt/PromptManager.java b/src/main/java/com/cyr1en/commandprompter/prompt/PromptManager.java index 92b31e6..a42b102 100644 --- a/src/main/java/com/cyr1en/commandprompter/prompt/PromptManager.java +++ b/src/main/java/com/cyr1en/commandprompter/prompt/PromptManager.java @@ -69,7 +69,7 @@ public PromptManager(CommandPrompter commandPrompter) { this.plugin = commandPrompter; this.promptRegistry = new PromptRegistry(plugin); this.promptParser = new PromptParser(this); - this.scheduler = CommandPrompter.getInstance().getScheduler(); + this.scheduler = CommandPrompter.scheduler; } public void registerPrompts() { @@ -233,7 +233,7 @@ public void cancel(CommandSender sender, int queueHash) { return; if (pcm.delayTicks() > 0) - plugin.getScheduler().runDelayed(SchedulerType.SYNC, task -> queue.execPCM(pcm, (Player) sender), + scheduler.runDelayed(SchedulerType.SYNC, task -> queue.execPCM(pcm, (Player) sender), pcm.delayTicks()); else queue.execPCM(pcm, (Player) sender); diff --git a/src/main/java/com/cyr1en/commandprompter/prompt/PromptQueue.java b/src/main/java/com/cyr1en/commandprompter/prompt/PromptQueue.java index cefeb5f..e16571c 100644 --- a/src/main/java/com/cyr1en/commandprompter/prompt/PromptQueue.java +++ b/src/main/java/com/cyr1en/commandprompter/prompt/PromptQueue.java @@ -116,7 +116,7 @@ public void dispatch(CommandPrompter plugin, Player sender) { return; if (pcm.delayTicks() > 0) - plugin.getScheduler().runDelayed(SchedulerType.SYNC, task -> execPCM(pcm, sender), + CommandPrompter.scheduler.runDelayed(SchedulerType.SYNC, task -> execPCM(pcm, sender), pcm.delayTicks()); else execPCM(pcm, sender); diff --git a/src/main/java/com/cyr1en/commandprompter/prompt/prompts/ChatPrompt.java b/src/main/java/com/cyr1en/commandprompter/prompt/prompts/ChatPrompt.java index 660f328..f9e9f8a 100644 --- a/src/main/java/com/cyr1en/commandprompter/prompt/prompts/ChatPrompt.java +++ b/src/main/java/com/cyr1en/commandprompter/prompt/prompts/ChatPrompt.java @@ -139,7 +139,7 @@ public void onResponse(Player player, String msg, Cancellable event) { .setSender(player) .setContent(msg).build(); - CommandPrompter.getInstance().getScheduler().runTask(SchedulerType.SYNC, task -> manager.processPrompt(ctx)); + CommandPrompter.scheduler.runTask(SchedulerType.SYNC, task -> manager.processPrompt(ctx)); } } diff --git a/src/main/java/com/cyr1en/commandprompter/prompt/prompts/PlayerUIPrompt.java b/src/main/java/com/cyr1en/commandprompter/prompt/prompts/PlayerUIPrompt.java index 446eef2..30eafa6 100644 --- a/src/main/java/com/cyr1en/commandprompter/prompt/prompts/PlayerUIPrompt.java +++ b/src/main/java/com/cyr1en/commandprompter/prompt/prompts/PlayerUIPrompt.java @@ -212,7 +212,7 @@ public void sendPrompt() { getPlugin().getPluginLogger().debug("Missing heads in cache, rebuilding before sending..."); headCache.reBuildCache().thenAccept(cache -> { getPlugin().getPluginLogger().debug("Rebuilt cache!"); - CommandPrompter.getInstance().getScheduler().runTask(SchedulerType.SYNC, task -> send(p)); + CommandPrompter.scheduler.runTask(SchedulerType.SYNC, task -> send(p)); }); } else { send(p); diff --git a/src/main/java/com/cyr1en/commandprompter/prompt/ui/HeadCache.java b/src/main/java/com/cyr1en/commandprompter/prompt/ui/HeadCache.java index cafa905..4a2d1f9 100644 --- a/src/main/java/com/cyr1en/commandprompter/prompt/ui/HeadCache.java +++ b/src/main/java/com/cyr1en/commandprompter/prompt/ui/HeadCache.java @@ -228,7 +228,7 @@ public void onPlayerLogin(PlayerLoginEvent e) { var cacheDelay = plugin.getPromptConfig().cacheDelay(); logger.debug("Caching Delay: %s", cacheDelay); - CommandPrompter.getInstance().getScheduler().runDelayed(SchedulerType.ASYNC, task -> { + CommandPrompter.scheduler.runDelayed(SchedulerType.ASYNC, task -> { if (isVanished(e.getPlayer())) { logger.debug("Player is vanished"); return; From 9748498b5cc8f4d419b35b083d71eba186825a44 Mon Sep 17 00:00:00 2001 From: Stabrinai Date: Sat, 9 Mar 2024 19:39:03 +0800 Subject: [PATCH 4/9] Fix folia support for dependencies --- .../commandprompter/prompt/prompts/SignPrompt.java | 1 + src/main/resources/runtime-deps.json | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/cyr1en/commandprompter/prompt/prompts/SignPrompt.java b/src/main/java/com/cyr1en/commandprompter/prompt/prompts/SignPrompt.java index 4c41185..f06283c 100644 --- a/src/main/java/com/cyr1en/commandprompter/prompt/prompts/SignPrompt.java +++ b/src/main/java/com/cyr1en/commandprompter/prompt/prompts/SignPrompt.java @@ -47,6 +47,7 @@ else if (parts.size() > 4) .setLines(finalParts.toArray(String[]::new)) .setType(mat) .setHandler((p, r) -> process(finalParts, p, r.getLines())) + .callHandlerSynchronously(CommandPrompter.getInstance()) .build(); gui.open((Player) getContext().getSender()); diff --git a/src/main/resources/runtime-deps.json b/src/main/resources/runtime-deps.json index 99fa9d1..a28dbdd 100644 --- a/src/main/resources/runtime-deps.json +++ b/src/main/resources/runtime-deps.json @@ -1,21 +1,21 @@ { "IF": { - "filename": "IF-0.10.11.jar", - "url": "https://github.com/stefvanschie/IF/releases/download/v0.10.11/IF-0.10.11.jar", + "filename": "IF-0.10.14-SNAPSHOT.jar", + "url": "https://github.com/Stabrinai/IF-Folia/releases/download/Folia/IF-0.10.14-SNAPSHOT.jar", "relocation": [ "com.github.stefvanschie.inventoryframework", "com.cyr1en.inventoryframework" ], - "sha1": "26aaf95a5552972d6612febabbe31776b902ee75" + "sha1": "3edd02bba6df1c4728e34ab6469c0b4a22551405" }, "SignGUI": { - "filename": "signgui-2.2.2.jar", - "url": "https://repo1.maven.org/maven2/io/github/rapha149/signgui/signgui/2.2.2/signgui-2.2.2.jar", + "filename": "signgui-2.3.2.jar", + "url": "https://github.com/Stabrinai/SignGUI-folia/releases/download/Folia/signgui-2.3.2.jar", "relocation": [ - "io.github.rapha149.signgui", + "de.rapha149.signgui", "com.cyr1en.signgui" ], - "sha1": "982894bc7e9da56830b278a64c4cdbfc4df96054" + "sha1": "3ed90c9de0464575fff3c055434660b37d3d4766" }, "CommandAPI": { "filename": "commandapi-bukkit-shade-9.3.0.jar", From 69edd3a8186a5f103c921e860017ed6a6a6f9f20 Mon Sep 17 00:00:00 2001 From: Stabrinai Date: Mon, 11 Mar 2024 17:33:40 +0800 Subject: [PATCH 5/9] add dispatchWithAttachmentFolia() and getScheduler() --- .../commandprompter/CommandPrompter.java | 10 +++-- .../commandprompter/api/Dispatcher.java | 39 +++++++++++++++++-- .../hook/hooks/CarbonChatHook.java | 2 +- .../commandprompter/prompt/PromptManager.java | 2 +- .../commandprompter/prompt/PromptQueue.java | 2 +- .../prompt/prompts/ChatPrompt.java | 2 +- .../prompt/prompts/PlayerUIPrompt.java | 2 +- .../commandprompter/prompt/ui/HeadCache.java | 2 +- .../util/FoliaUpdateChecker.java | 20 ++++++++++ 9 files changed, 69 insertions(+), 12 deletions(-) create mode 100644 src/main/java/com/cyr1en/commandprompter/util/FoliaUpdateChecker.java diff --git a/src/main/java/com/cyr1en/commandprompter/CommandPrompter.java b/src/main/java/com/cyr1en/commandprompter/CommandPrompter.java index 879abfd..1e05cc6 100644 --- a/src/main/java/com/cyr1en/commandprompter/CommandPrompter.java +++ b/src/main/java/com/cyr1en/commandprompter/CommandPrompter.java @@ -40,6 +40,7 @@ import com.cyr1en.commandprompter.unsafe.CommandMapHacker; import com.cyr1en.commandprompter.unsafe.ModifiedCommandMap; import com.cyr1en.commandprompter.unsafe.PvtFieldMutator; +import com.cyr1en.commandprompter.util.FoliaUpdateChecker; import com.cyr1en.commandprompter.util.Util; import com.cyr1en.commandprompter.util.Util.ServerType; import com.cyr1en.kiso.mc.I18N; @@ -59,7 +60,7 @@ public class CommandPrompter extends JavaPlugin { private static CommandPrompter instance; - public static Scheduler scheduler; + private static Scheduler scheduler; private ConfigurationManager configManager; private CommandPrompterConfig config; @@ -211,8 +212,7 @@ private void setupCommands() { } private void setupUpdater() { - if (Energie.isFolia()) return; - updateChecker = new UpdateChecker(this, 47772); + updateChecker = Energie.isFolia()? new FoliaUpdateChecker(this, 47772) : new UpdateChecker(this, 47772); if (updateChecker.isDisabled()) return; scheduler.runTask(SchedulerType.ASYNC, task -> { @@ -270,6 +270,10 @@ public static CommandPrompter getInstance() { return instance; } + public static Scheduler getScheduler() { + return scheduler; + } + public CommandPrompterConfig getConfiguration() { return config; } diff --git a/src/main/java/com/cyr1en/commandprompter/api/Dispatcher.java b/src/main/java/com/cyr1en/commandprompter/api/Dispatcher.java index 5cb5a86..eb185a5 100644 --- a/src/main/java/com/cyr1en/commandprompter/api/Dispatcher.java +++ b/src/main/java/com/cyr1en/commandprompter/api/Dispatcher.java @@ -25,6 +25,7 @@ package com.cyr1en.commandprompter.api; import com.cyr1en.commandprompter.CommandPrompter; +import fr.euphyllia.energie.Energie; import fr.euphyllia.energie.model.SchedulerType; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; @@ -32,6 +33,9 @@ import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; +import java.util.Objects; +import java.util.concurrent.CompletableFuture; + /** * Player command dispatcher for Support with CommandPrompter. * @@ -52,7 +56,7 @@ public class Dispatcher { */ public static void dispatchCommand(Player sender, String command) { final String checked = command.codePointAt(0) == 0x2F ? command : "/" + command; - CommandPrompter.scheduler.runTask(SchedulerType.SYNC, task -> sender.chat(checked)); + CommandPrompter.getScheduler().runTask(SchedulerType.SYNC, sender, task -> sender.chat(checked), null); } /** @@ -62,7 +66,7 @@ public static void dispatchCommand(Player sender, String command) { */ public static void dispatchConsole(final String command) { final String checked = command.codePointAt(0) == 0x2F ? command.substring(1) : command; - CommandPrompter.scheduler.runTask(SchedulerType.SYNC, task -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), checked)); + CommandPrompter.getScheduler().runTask(SchedulerType.SYNC, task -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), checked)); } /** @@ -77,6 +81,10 @@ public static void dispatchConsole(final String command) { */ public static void dispatchWithAttachment(Plugin plugin, Player sender, String command, int ticks, @NotNull String[] perms) { + if (Energie.isFolia()) { + dispatchWithAttachmentFolia(plugin, sender, command, ticks, perms); + return; + } var commandPrompter = (CommandPrompter) plugin; var logger = commandPrompter.getPluginLogger(); @@ -94,9 +102,34 @@ public static void dispatchWithAttachment(Plugin plugin, Player sender, String c } attachment.getPermissible().recalculatePermissions(); final String checked = command.codePointAt(0) == 0x2F ? command.substring(1) : command; - CommandPrompter.scheduler.runTask(SchedulerType.SYNC, task -> Bukkit.dispatchCommand(sender, checked)); + CommandPrompter.getScheduler().runTask(SchedulerType.SYNC, sender, task -> Bukkit.dispatchCommand(sender, checked), null); //dispatchCommand(plugin, sender, command); sender.removeAttachment(attachment); } + public static void dispatchWithAttachmentFolia(Plugin plugin, Player sender, String command, int ticks, + @NotNull String[] perms) { + var commandPrompter = (CommandPrompter) plugin; + var logger = commandPrompter.getPluginLogger(); + logger.debug("Dispatching command with permission attachment"); + + var attachment = sender.addAttachment(plugin); + CommandPrompter.getScheduler().runDelayed(SchedulerType.SYNC, task -> attachment.remove(), ticks); + + if (attachment == null) { + logger.err("Unable to create PermissionAttachment for " + sender.getName()); + return; + } + + for (String perm : perms) { + logger.debug("Attached Perm: " + perm); + attachment.setPermission(perm, true); + } + attachment.getPermissible().recalculatePermissions(); + final String checked = command.codePointAt(0) == 0x2F ? command.substring(1) : command; + + new CompletableFuture().completeAsync(() -> Bukkit.dispatchCommand(sender, checked),executor -> CommandPrompter. + getScheduler().runTask(SchedulerType.SYNC,sender, task -> executor.run(), null)).thenRun(() -> + sender.removeAttachment(attachment)).join(); + } } diff --git a/src/main/java/com/cyr1en/commandprompter/hook/hooks/CarbonChatHook.java b/src/main/java/com/cyr1en/commandprompter/hook/hooks/CarbonChatHook.java index d9ad454..3f1b879 100644 --- a/src/main/java/com/cyr1en/commandprompter/hook/hooks/CarbonChatHook.java +++ b/src/main/java/com/cyr1en/commandprompter/hook/hooks/CarbonChatHook.java @@ -59,6 +59,6 @@ public void handle(CarbonChatEvent event) { msg = prompt.sanitizeInput() ? ds : msg; } var ctx = new PromptContext.Builder().setSender(player).setContent(msg).build(); - CommandPrompter.scheduler.runTask(SchedulerType.SYNC, task -> promptManager.processPrompt(ctx)); + CommandPrompter.getScheduler().runTask(SchedulerType.SYNC, task -> promptManager.processPrompt(ctx)); } } diff --git a/src/main/java/com/cyr1en/commandprompter/prompt/PromptManager.java b/src/main/java/com/cyr1en/commandprompter/prompt/PromptManager.java index a42b102..ab2ac79 100644 --- a/src/main/java/com/cyr1en/commandprompter/prompt/PromptManager.java +++ b/src/main/java/com/cyr1en/commandprompter/prompt/PromptManager.java @@ -69,7 +69,7 @@ public PromptManager(CommandPrompter commandPrompter) { this.plugin = commandPrompter; this.promptRegistry = new PromptRegistry(plugin); this.promptParser = new PromptParser(this); - this.scheduler = CommandPrompter.scheduler; + this.scheduler = CommandPrompter.getScheduler(); } public void registerPrompts() { diff --git a/src/main/java/com/cyr1en/commandprompter/prompt/PromptQueue.java b/src/main/java/com/cyr1en/commandprompter/prompt/PromptQueue.java index e16571c..585aadb 100644 --- a/src/main/java/com/cyr1en/commandprompter/prompt/PromptQueue.java +++ b/src/main/java/com/cyr1en/commandprompter/prompt/PromptQueue.java @@ -116,7 +116,7 @@ public void dispatch(CommandPrompter plugin, Player sender) { return; if (pcm.delayTicks() > 0) - CommandPrompter.scheduler.runDelayed(SchedulerType.SYNC, task -> execPCM(pcm, sender), + CommandPrompter.getScheduler().runDelayed(SchedulerType.SYNC, task -> execPCM(pcm, sender), pcm.delayTicks()); else execPCM(pcm, sender); diff --git a/src/main/java/com/cyr1en/commandprompter/prompt/prompts/ChatPrompt.java b/src/main/java/com/cyr1en/commandprompter/prompt/prompts/ChatPrompt.java index f9e9f8a..d637392 100644 --- a/src/main/java/com/cyr1en/commandprompter/prompt/prompts/ChatPrompt.java +++ b/src/main/java/com/cyr1en/commandprompter/prompt/prompts/ChatPrompt.java @@ -139,7 +139,7 @@ public void onResponse(Player player, String msg, Cancellable event) { .setSender(player) .setContent(msg).build(); - CommandPrompter.scheduler.runTask(SchedulerType.SYNC, task -> manager.processPrompt(ctx)); + CommandPrompter.getScheduler().runTask(SchedulerType.SYNC, task -> manager.processPrompt(ctx)); } } diff --git a/src/main/java/com/cyr1en/commandprompter/prompt/prompts/PlayerUIPrompt.java b/src/main/java/com/cyr1en/commandprompter/prompt/prompts/PlayerUIPrompt.java index 30eafa6..3f5083b 100644 --- a/src/main/java/com/cyr1en/commandprompter/prompt/prompts/PlayerUIPrompt.java +++ b/src/main/java/com/cyr1en/commandprompter/prompt/prompts/PlayerUIPrompt.java @@ -212,7 +212,7 @@ public void sendPrompt() { getPlugin().getPluginLogger().debug("Missing heads in cache, rebuilding before sending..."); headCache.reBuildCache().thenAccept(cache -> { getPlugin().getPluginLogger().debug("Rebuilt cache!"); - CommandPrompter.scheduler.runTask(SchedulerType.SYNC, task -> send(p)); + CommandPrompter.getScheduler().runTask(SchedulerType.SYNC, task -> send(p)); }); } else { send(p); diff --git a/src/main/java/com/cyr1en/commandprompter/prompt/ui/HeadCache.java b/src/main/java/com/cyr1en/commandprompter/prompt/ui/HeadCache.java index 4a2d1f9..7214958 100644 --- a/src/main/java/com/cyr1en/commandprompter/prompt/ui/HeadCache.java +++ b/src/main/java/com/cyr1en/commandprompter/prompt/ui/HeadCache.java @@ -228,7 +228,7 @@ public void onPlayerLogin(PlayerLoginEvent e) { var cacheDelay = plugin.getPromptConfig().cacheDelay(); logger.debug("Caching Delay: %s", cacheDelay); - CommandPrompter.scheduler.runDelayed(SchedulerType.ASYNC, task -> { + CommandPrompter.getScheduler().runDelayed(SchedulerType.ASYNC, task -> { if (isVanished(e.getPlayer())) { logger.debug("Player is vanished"); return; diff --git a/src/main/java/com/cyr1en/commandprompter/util/FoliaUpdateChecker.java b/src/main/java/com/cyr1en/commandprompter/util/FoliaUpdateChecker.java new file mode 100644 index 0000000..e8d3c4e --- /dev/null +++ b/src/main/java/com/cyr1en/commandprompter/util/FoliaUpdateChecker.java @@ -0,0 +1,20 @@ +package com.cyr1en.commandprompter.util; + +import com.cyr1en.commandprompter.CommandPrompter; +import com.cyr1en.kiso.mc.UpdateChecker; +import fr.euphyllia.energie.model.SchedulerType; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.plugin.java.JavaPlugin; + +public class FoliaUpdateChecker extends UpdateChecker { + public FoliaUpdateChecker(JavaPlugin plugin, int resourceID) { + super(plugin, resourceID); + } + + @Override + public void onJoin(PlayerJoinEvent event) { + CommandPrompter.getScheduler().runTask(SchedulerType.SYNC, task -> { + this.sendUpdateAvailableMessage(event.getPlayer()); + }); + } +} From 1f64db9ea047822d801d04f79af611f85b3b81c5 Mon Sep 17 00:00:00 2001 From: Stabrinai Date: Mon, 11 Mar 2024 17:55:42 +0800 Subject: [PATCH 6/9] Change FoliaUpdateChecker.onJoin() to EntityScheduler --- .../java/com/cyr1en/commandprompter/CommandPrompter.java | 2 +- .../java/com/cyr1en/commandprompter/api/Dispatcher.java | 3 +-- .../cyr1en/commandprompter/util/FoliaUpdateChecker.java | 7 +++++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/cyr1en/commandprompter/CommandPrompter.java b/src/main/java/com/cyr1en/commandprompter/CommandPrompter.java index 1e05cc6..a370cac 100644 --- a/src/main/java/com/cyr1en/commandprompter/CommandPrompter.java +++ b/src/main/java/com/cyr1en/commandprompter/CommandPrompter.java @@ -212,7 +212,7 @@ private void setupCommands() { } private void setupUpdater() { - updateChecker = Energie.isFolia()? new FoliaUpdateChecker(this, 47772) : new UpdateChecker(this, 47772); + updateChecker = Energie.isFolia() ? new FoliaUpdateChecker(this, 47772) : new UpdateChecker(this, 47772); if (updateChecker.isDisabled()) return; scheduler.runTask(SchedulerType.ASYNC, task -> { diff --git a/src/main/java/com/cyr1en/commandprompter/api/Dispatcher.java b/src/main/java/com/cyr1en/commandprompter/api/Dispatcher.java index eb185a5..3bb41e2 100644 --- a/src/main/java/com/cyr1en/commandprompter/api/Dispatcher.java +++ b/src/main/java/com/cyr1en/commandprompter/api/Dispatcher.java @@ -33,7 +33,6 @@ import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; -import java.util.Objects; import java.util.concurrent.CompletableFuture; /** @@ -129,7 +128,7 @@ public static void dispatchWithAttachmentFolia(Plugin plugin, Player sender, Str final String checked = command.codePointAt(0) == 0x2F ? command.substring(1) : command; new CompletableFuture().completeAsync(() -> Bukkit.dispatchCommand(sender, checked),executor -> CommandPrompter. - getScheduler().runTask(SchedulerType.SYNC,sender, task -> executor.run(), null)).thenRun(() -> + getScheduler().runTask(SchedulerType.SYNC, sender, task -> executor.run(), null)).thenRun(() -> sender.removeAttachment(attachment)).join(); } } diff --git a/src/main/java/com/cyr1en/commandprompter/util/FoliaUpdateChecker.java b/src/main/java/com/cyr1en/commandprompter/util/FoliaUpdateChecker.java index e8d3c4e..562b4c0 100644 --- a/src/main/java/com/cyr1en/commandprompter/util/FoliaUpdateChecker.java +++ b/src/main/java/com/cyr1en/commandprompter/util/FoliaUpdateChecker.java @@ -3,6 +3,8 @@ import com.cyr1en.commandprompter.CommandPrompter; import com.cyr1en.kiso.mc.UpdateChecker; import fr.euphyllia.energie.model.SchedulerType; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.plugin.java.JavaPlugin; @@ -12,9 +14,10 @@ public FoliaUpdateChecker(JavaPlugin plugin, int resourceID) { } @Override + @EventHandler(priority = EventPriority.LOW) public void onJoin(PlayerJoinEvent event) { - CommandPrompter.getScheduler().runTask(SchedulerType.SYNC, task -> { + CommandPrompter.getScheduler().runTask(SchedulerType.SYNC, event.getPlayer() , task -> { this.sendUpdateAvailableMessage(event.getPlayer()); - }); + }, null); } } From 814d06a44f072493ccaf52b9d58b4e4e912081d2 Mon Sep 17 00:00:00 2001 From: Stabrinai Date: Mon, 11 Mar 2024 20:27:28 +0800 Subject: [PATCH 7/9] dump signgui version to 2.3.2 fix dispatchWithAttachment() --- build.gradle | 6 +++--- .../com/cyr1en/commandprompter/api/Dispatcher.java | 13 ++++++++++++- .../commandprompter/prompt/prompts/SignPrompt.java | 4 ++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 3745ed3..6c247cb 100644 --- a/build.gradle +++ b/build.gradle @@ -65,7 +65,7 @@ dependencies { implementation 'com.cyr1en:kiso-utils:1.8-SNAPSHOT' implementation 'com.cyr1en:kiso-mc:1.8-SNAPSHOT' implementation 'net.wesjd:anvilgui:1.9.2-SNAPSHOT' - implementation 'io.github.rapha149.signgui:signgui:2.2.2' + implementation 'de.rapha149.signgui:signgui:2.3.2' implementation 'org.bstats:bstats-bukkit:3.0.0' implementation "dev.jorel:commandapi-bukkit-shade:9.3.0" implementation group: 'org.fusesource.jansi', name: 'jansi', version: '2.4.0' @@ -107,7 +107,7 @@ shadowJar { relocate 'com.github.stefvanschie.inventoryframework', 'com.cyr1en.inventoryframework' relocate 'net.wesjd.anvilgui', 'com.cyr1en.anvilgui' - relocate 'io.github.rapha149.signgui', 'com.cyr1en.signgui' + relocate 'de.rapha149.signgui', 'com.cyr1en.signgui' relocate 'net.kyori.adventure.text.minimessage', 'com.cyr1en.minimessage' relocate 'dev.jorel.commandapi', 'com.cyr1en.commandapi' relocate 'org.fusesource.jansi', 'com.cyr1en.jansi' @@ -142,7 +142,7 @@ tasks.register("lightJar", ShadowJar) { } relocate 'com.github.stefvanschie.inventoryframework', 'com.cyr1en.inventoryframework' relocate 'net.wesjd.anvilgui', 'com.cyr1en.anvilgui' - relocate 'io.github.rapha149.signgui', 'com.cyr1en.signgui' + relocate 'de.rapha149.signgui', 'com.cyr1en.signgui' relocate 'net.kyori.adventure.text.minimessage', 'com.cyr1en.minimessage' relocate 'org.fusesource.jansi', 'com.cyr1en.jansi' relocate 'dev.jorel.commandapi', 'com.cyr1en.commandapi' diff --git a/src/main/java/com/cyr1en/commandprompter/api/Dispatcher.java b/src/main/java/com/cyr1en/commandprompter/api/Dispatcher.java index 3bb41e2..d53c289 100644 --- a/src/main/java/com/cyr1en/commandprompter/api/Dispatcher.java +++ b/src/main/java/com/cyr1en/commandprompter/api/Dispatcher.java @@ -101,10 +101,21 @@ public static void dispatchWithAttachment(Plugin plugin, Player sender, String c } attachment.getPermissible().recalculatePermissions(); final String checked = command.codePointAt(0) == 0x2F ? command.substring(1) : command; - CommandPrompter.getScheduler().runTask(SchedulerType.SYNC, sender, task -> Bukkit.dispatchCommand(sender, checked), null); + Bukkit.dispatchCommand(sender, checked); //dispatchCommand(plugin, sender, command); sender.removeAttachment(attachment); } + + /** + * Dispatch a command for a player with a PermissionAttachment that contains + * all the whitelisted commands. - folia + * + * @param plugin Instance of plugin. + * @param sender command sender (in menu's, then the item clicker) + * @param command command that would be dispatched. + * @param ticks Number of ticks before the attachment expires + * @param perms Permissions to set to the PermissionAttachment + */ public static void dispatchWithAttachmentFolia(Plugin plugin, Player sender, String command, int ticks, @NotNull String[] perms) { var commandPrompter = (CommandPrompter) plugin; diff --git a/src/main/java/com/cyr1en/commandprompter/prompt/prompts/SignPrompt.java b/src/main/java/com/cyr1en/commandprompter/prompt/prompts/SignPrompt.java index f06283c..22745fc 100644 --- a/src/main/java/com/cyr1en/commandprompter/prompt/prompts/SignPrompt.java +++ b/src/main/java/com/cyr1en/commandprompter/prompt/prompts/SignPrompt.java @@ -5,8 +5,8 @@ import com.cyr1en.commandprompter.prompt.PromptParser; import com.cyr1en.commandprompter.util.Util; import com.cyr1en.kiso.utils.FastStrings; -import io.github.rapha149.signgui.SignGUI; -import io.github.rapha149.signgui.SignGUIAction; +import de.rapha149.signgui.SignGUI; +import de.rapha149.signgui.SignGUIAction; import org.bukkit.Material; import org.bukkit.entity.Player; From 14b75b7ea55636705d86dd1ea9240e2755c201dd Mon Sep 17 00:00:00 2001 From: Stabrinai Date: Wed, 13 Mar 2024 12:14:26 +0800 Subject: [PATCH 8/9] dump energie version --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 6c247cb..b254696 100644 --- a/build.gradle +++ b/build.gradle @@ -69,7 +69,7 @@ dependencies { implementation 'org.bstats:bstats-bukkit:3.0.0' implementation "dev.jorel:commandapi-bukkit-shade:9.3.0" implementation group: 'org.fusesource.jansi', name: 'jansi', version: '2.4.0' - implementation("com.github.Euphillya:Energie:5659f25e22") + implementation("com.github.Euphillya:Energie:1.1.4") // Exclude these implementation 'me.lucko:jar-relocator:1.7' From 048662d7e87ad27fb5c394b7978c2bacd64f862e Mon Sep 17 00:00:00 2001 From: Stabrinai Date: Wed, 13 Mar 2024 14:21:12 +0800 Subject: [PATCH 9/9] fix execution order --- .../commandprompter/api/Dispatcher.java | 57 ++++--------------- 1 file changed, 12 insertions(+), 45 deletions(-) diff --git a/src/main/java/com/cyr1en/commandprompter/api/Dispatcher.java b/src/main/java/com/cyr1en/commandprompter/api/Dispatcher.java index d53c289..e22fe76 100644 --- a/src/main/java/com/cyr1en/commandprompter/api/Dispatcher.java +++ b/src/main/java/com/cyr1en/commandprompter/api/Dispatcher.java @@ -30,11 +30,10 @@ import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.bukkit.permissions.PermissionAttachment; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; -import java.util.concurrent.CompletableFuture; - /** * Player command dispatcher for Support with CommandPrompter. * @@ -80,52 +79,19 @@ public static void dispatchConsole(final String command) { */ public static void dispatchWithAttachment(Plugin plugin, Player sender, String command, int ticks, @NotNull String[] perms) { - if (Energie.isFolia()) { - dispatchWithAttachmentFolia(plugin, sender, command, ticks, perms); - return; - } var commandPrompter = (CommandPrompter) plugin; var logger = commandPrompter.getPluginLogger(); logger.debug("Dispatching command with permission attachment"); - var attachment = sender.addAttachment(plugin, ticks); - if (attachment == null) { - logger.err("Unable to create PermissionAttachment for " + sender.getName()); - return; + PermissionAttachment attachment; + if (!Energie.isFolia()) { + attachment = sender.addAttachment(plugin, ticks); + } else { + attachment = sender.addAttachment(plugin); + CommandPrompter.getScheduler().runDelayed(SchedulerType.SYNC, task -> attachment.remove(), ticks); } - for (String perm : perms) { - logger.debug("Attached Perm: " + perm); - attachment.setPermission(perm, true); - } - attachment.getPermissible().recalculatePermissions(); - final String checked = command.codePointAt(0) == 0x2F ? command.substring(1) : command; - Bukkit.dispatchCommand(sender, checked); - //dispatchCommand(plugin, sender, command); - sender.removeAttachment(attachment); - } - - /** - * Dispatch a command for a player with a PermissionAttachment that contains - * all the whitelisted commands. - folia - * - * @param plugin Instance of plugin. - * @param sender command sender (in menu's, then the item clicker) - * @param command command that would be dispatched. - * @param ticks Number of ticks before the attachment expires - * @param perms Permissions to set to the PermissionAttachment - */ - public static void dispatchWithAttachmentFolia(Plugin plugin, Player sender, String command, int ticks, - @NotNull String[] perms) { - var commandPrompter = (CommandPrompter) plugin; - var logger = commandPrompter.getPluginLogger(); - - logger.debug("Dispatching command with permission attachment"); - - var attachment = sender.addAttachment(plugin); - CommandPrompter.getScheduler().runDelayed(SchedulerType.SYNC, task -> attachment.remove(), ticks); - if (attachment == null) { logger.err("Unable to create PermissionAttachment for " + sender.getName()); return; @@ -137,9 +103,10 @@ public static void dispatchWithAttachmentFolia(Plugin plugin, Player sender, Str } attachment.getPermissible().recalculatePermissions(); final String checked = command.codePointAt(0) == 0x2F ? command.substring(1) : command; - - new CompletableFuture().completeAsync(() -> Bukkit.dispatchCommand(sender, checked),executor -> CommandPrompter. - getScheduler().runTask(SchedulerType.SYNC, sender, task -> executor.run(), null)).thenRun(() -> - sender.removeAttachment(attachment)).join(); + CommandPrompter.getScheduler().runTask(SchedulerType.SYNC, sender, task -> { + Bukkit.dispatchCommand(sender, checked); + //dispatchCommand(plugin, sender, command); + sender.removeAttachment(attachment); + }, null); } }