Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Folia support for a wide range of plugins #5

Merged
merged 12 commits into from
Jun 14, 2024
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ In summary, a plugin must be careful of:
- One thread reading data while it is being updated by another thread.
- Code is to be executed on the chunk's thread, not simply the main thread.

If your plugin already has support for Folia there is a 99% chance it will work with ShreddedPaper without any changes
If you have a sanity check similar to the following
```java
try {
Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
return true;
} catch (ClassNotFoundException e) {
return false;
}
```
You should either remove it (because its really not needed) OR add a check for the class `io.multipaper.shreddedpaper.ShreddedPaper`

[See here for a more detailed tutorial](DEVELOPING_A_MULTITHREAD_PLUGIN.md)

### Using the ShreddedPaper API as a dependency
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: ProdPreva1l <prod.preva1l@gmail.com>
Date: Wed, 5 Jun 2024 20:44:50 +1000
Subject: [PATCH] Add RegionizedServerInitEvent for Folia support


diff --git a/src/main/java/io/papermc/paper/threadedregions/RegionizedServerInitEvent.java b/src/main/java/io/papermc/paper/threadedregions/RegionizedServerInitEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..d991df9523676ab7ba90f45ecae3ea9dac5b55d6
--- /dev/null
+++ b/src/main/java/io/papermc/paper/threadedregions/RegionizedServerInitEvent.java
@@ -0,0 +1,24 @@
+package io.papermc.paper.threadedregions;
+
+import org.bukkit.event.Event;
+import org.bukkit.event.HandlerList;
+import org.jetbrains.annotations.ApiStatus;
+import org.jetbrains.annotations.NotNull;
+
+public class RegionizedServerInitEvent extends Event {
+ private static final HandlerList HANDLER_LIST = new HandlerList();
+
+ @ApiStatus.Internal
+ public RegionizedServerInitEvent() {
+ super();
+ }
+
+ @Override
+ public @NotNull HandlerList getHandlers() {
+ return HANDLER_LIST;
+ }
+
+ public static @NotNull HandlerList getHandlerList() {
+ return HANDLER_LIST;
+ }
+}
\ No newline at end of file
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: ProdPreva1l <prod.preva1l@gmail.com>
Date: Wed, 5 Jun 2024 20:27:53 +1000
Subject: [PATCH] Fix compat for Folia plugins that check for Folia


diff --git a/src/main/java/io/papermc/paper/threadedregions/RegionizedServer.java b/src/main/java/io/papermc/paper/threadedregions/RegionizedServer.java
new file mode 100644
index 0000000000000000000000000000000000000000..69db3090c24ab058549cdd8e78ca1beb7be5e7a8
--- /dev/null
+++ b/src/main/java/io/papermc/paper/threadedregions/RegionizedServer.java
@@ -0,0 +1,7 @@
+package io.papermc.paper.threadedregions;
+
+@SuppressWarnings("unused")
+public class RegionizedServer {
+ /* We have nothing here because this is just to fix compat
+ for Folia plugins that have hard coded checks for Folia */
+}
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index b6d5954ae9fbbcc52d9bd0bfb7b46d78f907b436..ee5eb2967ffd0b5aac88cffc7921b5a8fbade64f 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -16,6 +16,7 @@ import com.mojang.datafixers.DataFixer;
import com.mojang.logging.LogUtils;
import io.multipaper.shreddedpaper.ShreddedPaper;
import io.multipaper.shreddedpaper.threading.ShreddedPaperPlayerTicker;
+import io.papermc.paper.threadedregions.RegionizedServerInitEvent;
import io.papermc.paper.util.TickThread;
import it.unimi.dsi.fastutil.longs.LongIterator;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
@@ -1160,6 +1161,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.statusIcon = (ServerStatus.Favicon) this.loadStatusIcon().orElse(null); // CraftBukkit - decompile error
this.status = this.buildServerStatus();

+ new RegionizedServerInitEvent().callEvent(); // ShreddedPaper - Folia plugin support
+
// Spigot start
// Paper start - move done tracking
LOGGER.info("Running delayed init tasks");