From 4e7205d401a2e3c065b972524fe80b23e72ed846 Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Mon, 6 Mar 2023 12:57:29 -0800 Subject: [PATCH] Change entity scheduler API to use Runnables The generics pose a problem, and the parameter passed to the Consumer is not needed in API. Additionally, stop trying to cancel Bukkit scheduler tasks on plugin disable as the Bukkit scheduler does not work. --- patches/api/0002-Region-scheduler-API.patch | 23 +++++++++++++++------ patches/server/0004-Threaded-Regions.patch | 13 ++++++------ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/patches/api/0002-Region-scheduler-API.patch b/patches/api/0002-Region-scheduler-API.patch index 6999314..a0485d4 100644 --- a/patches/api/0002-Region-scheduler-API.patch +++ b/patches/api/0002-Region-scheduler-API.patch @@ -7,17 +7,15 @@ Add both a location based scheduler and an entity based scheduler diff --git a/src/main/java/io/papermc/paper/threadedregions/scheduler/EntityScheduler.java b/src/main/java/io/papermc/paper/threadedregions/scheduler/EntityScheduler.java new file mode 100644 -index 0000000000000000000000000000000000000000..edf4fe717c72aa147e5c0dee758bc7a133a19aa3 +index 0000000000000000000000000000000000000000..4193b13f1f51c2fb8da76f3e03187d859eaa8e10 --- /dev/null +++ b/src/main/java/io/papermc/paper/threadedregions/scheduler/EntityScheduler.java -@@ -0,0 +1,49 @@ +@@ -0,0 +1,47 @@ +package io.papermc.paper.threadedregions.scheduler; + -+import org.bukkit.entity.Entity; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -+import java.util.function.Consumer; + +/** + * An entity can move between worlds with an arbitrary tick delay, be temporarily removed @@ -56,8 +54,8 @@ index 0000000000000000000000000000000000000000..edf4fe717c72aa147e5c0dee758bc7a1 + * will be invoked (but never both), or {@code false} indicating neither the run nor retired function will be invoked + * since the scheduler has been retired. + */ -+ public boolean execute(@NotNull final Plugin plugin, @NotNull final Consumer run, -+ @Nullable final Consumer retired, final long delay); ++ public boolean execute(@NotNull final Plugin plugin, @NotNull final Runnable run, @Nullable final Runnable retired, ++ final long delay); + +} diff --git a/src/main/java/io/papermc/paper/threadedregions/scheduler/RegionisedScheduler.java b/src/main/java/io/papermc/paper/threadedregions/scheduler/RegionisedScheduler.java @@ -160,3 +158,16 @@ index cdbc7329cf5f67d66e31eb31e83b9e7997040f72..90451ed12b2c95bb372ac2e3cbb57b8b + @NotNull io.papermc.paper.threadedregions.scheduler.EntityScheduler getScheduler(); + // Folia end - region threading API } +diff --git a/src/main/java/org/bukkit/plugin/SimplePluginManager.java b/src/main/java/org/bukkit/plugin/SimplePluginManager.java +index b012ce40d82389c29d1b841ff685425ac10a7f9e..499dc8309a16b33d16b57b433c3c5b4330323717 100644 +--- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java ++++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java +@@ -585,7 +585,7 @@ public final class SimplePluginManager implements PluginManager { + } + + try { +- server.getScheduler().cancelTasks(plugin); ++ //server.getScheduler().cancelTasks(plugin); // Folia - Bukkit scheduler not supported + } catch (Throwable ex) { + handlePluginException("Error occurred (in the plugin loader) while cancelling tasks for " + + plugin.getDescription().getFullName() + " (Is it up to date?)", ex, plugin); // Paper diff --git a/patches/server/0004-Threaded-Regions.patch b/patches/server/0004-Threaded-Regions.patch index ab6f28c..b9b014e 100644 --- a/patches/server/0004-Threaded-Regions.patch +++ b/patches/server/0004-Threaded-Regions.patch @@ -9427,15 +9427,14 @@ index 0000000000000000000000000000000000000000..5bf205d8c0a03ba932be85cc1a63d6ce +} diff --git a/src/main/java/io/papermc/paper/threadedregions/scheduler/FoliaEntityScheduler.java b/src/main/java/io/papermc/paper/threadedregions/scheduler/FoliaEntityScheduler.java new file mode 100644 -index 0000000000000000000000000000000000000000..b924146112006e85dfc12c2b303a2eecf23741ca +index 0000000000000000000000000000000000000000..c0b9f43fc53a5c9b3d9788f080e4fd3f4f94ebfe --- /dev/null +++ b/src/main/java/io/papermc/paper/threadedregions/scheduler/FoliaEntityScheduler.java -@@ -0,0 +1,39 @@ +@@ -0,0 +1,38 @@ +package io.papermc.paper.threadedregions.scheduler; + +import ca.spottedleaf.concurrentutil.util.Validate; +import org.bukkit.craftbukkit.entity.CraftEntity; -+import org.bukkit.entity.Entity; +import org.bukkit.plugin.Plugin; +import java.util.function.Consumer; +import java.util.logging.Level; @@ -9448,13 +9447,13 @@ index 0000000000000000000000000000000000000000..b924146112006e85dfc12c2b303a2eec + this.entity = entity; + } + -+ private static Consumer wrap(final Plugin plugin, final Consumer consumer) { ++ private static Consumer wrap(final Plugin plugin, final Runnable runnable) { + Validate.notNull(plugin, "Plugin may not be null"); -+ Validate.notNull(consumer, "Consumer may not be null"); ++ Validate.notNull(runnable, "Runnable may not be null"); + + return (final net.minecraft.world.entity.Entity nmsEntity) -> { + try { -+ ((Consumer)consumer).accept(nmsEntity.getBukkitEntity()); ++ runnable.run(); + } catch (final Throwable throwable) { + plugin.getLogger().log(Level.WARNING, "Entity task for " + plugin.getDescription().getFullName() + " generated an exception", throwable); + } @@ -9462,7 +9461,7 @@ index 0000000000000000000000000000000000000000..b924146112006e85dfc12c2b303a2eec + } + + @Override -+ public boolean execute(final Plugin plugin, final Consumer run, final Consumer retired, ++ public boolean execute(final Plugin plugin, final Runnable run, final Runnable retired, + final long delay) { + final Consumer runNMS = wrap(plugin, run); + final Consumer runRetired = retired == null ? null : wrap(plugin, retired);