diff --git a/build.gradle b/build.gradle index a7c6fb0..b254696 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) } } @@ -65,10 +65,11 @@ 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' + implementation("com.github.Euphillya:Energie:1.1.4") // Exclude these implementation 'me.lucko:jar-relocator:1.7' @@ -106,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' @@ -141,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/CommandPrompter.java b/src/main/java/com/cyr1en/commandprompter/CommandPrompter.java index 547969a..a370cac 100644 --- a/src/main/java/com/cyr1en/commandprompter/CommandPrompter.java +++ b/src/main/java/com/cyr1en/commandprompter/CommandPrompter.java @@ -40,11 +40,15 @@ 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; 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; @@ -56,6 +60,7 @@ public class CommandPrompter extends JavaPlugin { private static CommandPrompter instance; + private static Scheduler scheduler; private ConfigurationManager configManager; private CommandPrompterConfig config; @@ -73,6 +78,8 @@ public class CommandPrompter extends JavaPlugin { @Override public void onEnable() { + instance = this; + scheduler = new Energie(this).getScheduler(Energie.SchedulerSoft.MINECRAFT); new Metrics(this, 5359); setupConfig(); @@ -96,10 +103,9 @@ public void onEnable() { initPromptSystem(); setupCommands(); - instance = this; Bukkit.getPluginManager().registerEvents(new CommandSendListener(this), this); - Bukkit.getScheduler().runTaskLater(this, () -> { + scheduler.runDelayed(SchedulerType.SYNC, task -> { hookContainer = new HookContainer(this); hookContainer.initHooks(); headCache.registerFilters(); @@ -172,7 +178,7 @@ private void initCommandListener() { return; } var delay = (long) config.modificationDelay(); - Bukkit.getScheduler().runTaskLater(this, this::hackMap, delay); + scheduler.runDelayed(SchedulerType.SYNC, task -> this.hackMap(), delay); } private void hackMap() { @@ -206,10 +212,10 @@ private void setupCommands() { } private void setupUpdater() { - updateChecker = new UpdateChecker(this, 47772); + updateChecker = Energie.isFolia() ? new FoliaUpdateChecker(this, 47772) : new UpdateChecker(this, 47772); if (updateChecker.isDisabled()) return; - Bukkit.getServer().getScheduler().runTaskAsynchronously(this, () -> { + scheduler.runTask(SchedulerType.ASYNC, task -> { if (updateChecker.newVersionAvailable()) logger.info(SRegex.ANSI_GREEN + "A new update is available! (" + updateChecker.getCurrVersion().asString() + ")" + SRegex.ANSI_RESET); @@ -264,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 8419fbe..e22fe76 100644 --- a/src/main/java/com/cyr1en/commandprompter/api/Dispatcher.java +++ b/src/main/java/com/cyr1en/commandprompter/api/Dispatcher.java @@ -25,11 +25,13 @@ 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; import org.bukkit.entity.Player; +import org.bukkit.permissions.PermissionAttachment; import org.bukkit.plugin.Plugin; -import org.bukkit.scheduler.BukkitRunnable; import org.jetbrains.annotations.NotNull; /** @@ -47,17 +49,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.getScheduler().runTask(SchedulerType.SYNC, sender, task -> sender.chat(checked), null); } /** @@ -67,11 +64,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.getScheduler().runTask(SchedulerType.SYNC, task -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), checked)); } /** @@ -91,7 +84,14 @@ public static void dispatchWithAttachment(Plugin plugin, Player sender, String c logger.debug("Dispatching command with permission attachment"); - var attachment = sender.addAttachment(plugin, ticks); + PermissionAttachment attachment; + if (!Energie.isFolia()) { + attachment = sender.addAttachment(plugin, ticks); + } else { + 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; @@ -103,9 +103,10 @@ 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); - //dispatchCommand(plugin, sender, command); - sender.removeAttachment(attachment); + CommandPrompter.getScheduler().runTask(SchedulerType.SYNC, sender, task -> { + Bukkit.dispatchCommand(sender, checked); + //dispatchCommand(plugin, sender, command); + sender.removeAttachment(attachment); + }, null); } - } 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..3f1b879 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.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..ab2ac79 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.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), + 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 03f26d0..585aadb 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), + CommandPrompter.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..d637392 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.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..3f5083b 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.getScheduler().runTask(SchedulerType.SYNC, task -> send(p)); }); } else { send(p); 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..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; @@ -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/java/com/cyr1en/commandprompter/prompt/ui/HeadCache.java b/src/main/java/com/cyr1en/commandprompter/prompt/ui/HeadCache.java index 204ac9d..7214958 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.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..562b4c0 --- /dev/null +++ b/src/main/java/com/cyr1en/commandprompter/util/FoliaUpdateChecker.java @@ -0,0 +1,23 @@ +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.EventHandler; +import org.bukkit.event.EventPriority; +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 + @EventHandler(priority = EventPriority.LOW) + public void onJoin(PlayerJoinEvent event) { + CommandPrompter.getScheduler().runTask(SchedulerType.SYNC, event.getPlayer() , task -> { + this.sendUpdateAvailableMessage(event.getPlayer()); + }, null); + } +} 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: 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",