Split paper feature patches into file patches

This commit is contained in:
Spottedleaf 2025-01-11 06:42:06 -08:00
parent b1da93e90b
commit 504f90840b
201 changed files with 4685 additions and 5135 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,74 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Wed, 22 Mar 2023 14:40:24 -0700
Subject: [PATCH] Throw UnsupportedOperationException() for broken APIs
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 82e4b25fbfb27d4a2a96a0785daf2168c60584aa..62a9bb77078522c3a98806083a4995251e036138 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -1320,6 +1320,7 @@ public final class CraftServer implements Server {
@Override
public World createWorld(WorldCreator creator) {
+ if (true) throw new UnsupportedOperationException(); // Folia - not implemented properly yet
Preconditions.checkState(this.console.getAllLevels().iterator().hasNext(), "Cannot create additional worlds on STARTUP");
//Preconditions.checkState(!this.console.isIteratingOverLevels, "Cannot create a world while worlds are being ticked"); // Paper - Cat - Temp disable. We'll see how this goes.
Preconditions.checkArgument(creator != null, "WorldCreator cannot be null");
@@ -1517,6 +1518,7 @@ public final class CraftServer implements Server {
@Override
public boolean unloadWorld(World world, boolean save) {
+ if (true) throw new UnsupportedOperationException(); // Folia - not implemented properly yet
//Preconditions.checkState(!this.console.isIteratingOverLevels, "Cannot unload a world while worlds are being ticked"); // Paper - Cat - Temp disable. We'll see how this goes.
if (world == null) {
return false;
diff --git a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java
index 253574890a9ed23d38a84680ba1eb221dc72b310..ce8b91f00f925960ad17f381162a11294e8b511d 100644
--- a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java
+++ b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java
@@ -45,6 +45,7 @@ public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard {
}
@Override
public CraftObjective registerNewObjective(String name, Criteria criteria, net.kyori.adventure.text.Component displayName, RenderType renderType) throws IllegalArgumentException {
+ if (true) throw new UnsupportedOperationException(); // Folia - not supported yet
if (displayName == null) {
displayName = net.kyori.adventure.text.Component.empty();
}
@@ -204,6 +205,7 @@ public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard {
@Override
public Team registerNewTeam(String name) {
+ if (true) throw new UnsupportedOperationException(); // Folia - not supported yet
Preconditions.checkArgument(name != null, "Team name cannot be null");
Preconditions.checkArgument(name.length() <= Short.MAX_VALUE, "Team name '%s' is longer than the limit of 32767 characters (%s)", name, name.length());
Preconditions.checkArgument(this.board.getPlayerTeam(name) == null, "Team name '%s' is already in use", name);
@@ -231,6 +233,7 @@ public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard {
@Override
public void clearSlot(DisplaySlot slot) {
+ if (true) throw new UnsupportedOperationException(); // Folia - not supported yet
Preconditions.checkArgument(slot != null, "Slot cannot be null");
this.board.setDisplayObjective(CraftScoreboardTranslations.fromBukkitSlot(slot), null);
}
diff --git a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboardManager.java b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboardManager.java
index f3184be3853dfc4df4ae4b8af764dfef07628ef4..99ba4d19b72a66ea1fc83fda16d37aaa0f154abb 100644
--- a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboardManager.java
+++ b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboardManager.java
@@ -42,6 +42,7 @@ public final class CraftScoreboardManager implements ScoreboardManager {
@Override
public CraftScoreboard getNewScoreboard() {
+ if (true) throw new UnsupportedOperationException(); // Folia - not supported yet
org.spigotmc.AsyncCatcher.catchOp("scoreboard creation"); // Spigot
CraftScoreboard scoreboard = new CraftScoreboard(new ServerScoreboard(this.server));
// Paper start
@@ -68,6 +69,7 @@ public final class CraftScoreboardManager implements ScoreboardManager {
// CraftBukkit method
public void setPlayerBoard(CraftPlayer player, org.bukkit.scoreboard.Scoreboard bukkitScoreboard) {
+ if (true) throw new UnsupportedOperationException(); // Folia - not supported yet
Preconditions.checkArgument(bukkitScoreboard instanceof CraftScoreboard, "Cannot set player scoreboard to an unregistered Scoreboard");
CraftScoreboard scoreboard = (CraftScoreboard) bukkitScoreboard;

View File

@ -1,82 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com>
Date: Wed, 29 Mar 2023 16:50:14 -0400
Subject: [PATCH] Require plugins to be explicitly marked as Folia supported
diff --git a/src/main/java/io/papermc/paper/plugin/provider/configuration/PaperPluginMeta.java b/src/main/java/io/papermc/paper/plugin/provider/configuration/PaperPluginMeta.java
index d3b3a8baca013909fa9c6204d964d7d7efeb2719..fb7c6621e2805f4339c255f6c2e02c55ff4c502e 100644
--- a/src/main/java/io/papermc/paper/plugin/provider/configuration/PaperPluginMeta.java
+++ b/src/main/java/io/papermc/paper/plugin/provider/configuration/PaperPluginMeta.java
@@ -64,6 +64,7 @@ public class PaperPluginMeta implements PluginMeta {
private PermissionConfiguration permissionConfiguration = new PermissionConfiguration(PermissionDefault.OP, List.of());
@Required
private ApiVersion apiVersion;
+ private boolean foliaSupported = false; // Folia
private Map<PluginDependencyLifeCycle, Map<String, DependencyConfiguration>> dependencies = new EnumMap<>(PluginDependencyLifeCycle.class);
@@ -251,6 +252,13 @@ public class PaperPluginMeta implements PluginMeta {
return this.apiVersion.getVersionString();
}
+ // Folia start
+ @Override
+ public boolean isFoliaSupported() {
+ return this.foliaSupported;
+ }
+ // Folia end
+
@Override
public @NotNull List<String> getProvidedPlugins() {
return this.provides;
diff --git a/src/main/java/io/papermc/paper/plugin/provider/type/paper/PaperPluginProviderFactory.java b/src/main/java/io/papermc/paper/plugin/provider/type/paper/PaperPluginProviderFactory.java
index 0a27b468560ccf4b9588cd12d50c02e442f3024f..6369b13e1fcdbdb25dd9d6e4d3bffdedbee4f739 100644
--- a/src/main/java/io/papermc/paper/plugin/provider/type/paper/PaperPluginProviderFactory.java
+++ b/src/main/java/io/papermc/paper/plugin/provider/type/paper/PaperPluginProviderFactory.java
@@ -24,6 +24,11 @@ class PaperPluginProviderFactory implements PluginTypeFactory<PaperPluginParent,
@Override
public PaperPluginParent build(JarFile file, PaperPluginMeta configuration, Path source) {
+ // Folia start - block plugins not marked as supported
+ if (!configuration.isFoliaSupported()) {
+ throw new RuntimeException("Could not load plugin '" + configuration.getDisplayName() + "' as it is not marked as supporting Folia!");
+ }
+ // Folia end - block plugins not marked as supported
Logger jul = PaperPluginLogger.getLogger(configuration);
ComponentLogger logger = ComponentLogger.logger(jul.getName());
PluginProviderContext context = PluginProviderContextImpl.create(configuration, logger, source);
diff --git a/src/main/java/io/papermc/paper/plugin/provider/type/spigot/SpigotPluginProviderFactory.java b/src/main/java/io/papermc/paper/plugin/provider/type/spigot/SpigotPluginProviderFactory.java
index 9edf79dffd2836b40d41da4437c18d6145853f89..276461c70d383709d5420f050e5d409dda3dfd6e 100644
--- a/src/main/java/io/papermc/paper/plugin/provider/type/spigot/SpigotPluginProviderFactory.java
+++ b/src/main/java/io/papermc/paper/plugin/provider/type/spigot/SpigotPluginProviderFactory.java
@@ -35,6 +35,11 @@ class SpigotPluginProviderFactory implements PluginTypeFactory<SpigotPluginProvi
@Override
public SpigotPluginProvider build(JarFile file, PluginDescriptionFile configuration, Path source) throws InvalidDescriptionException {
+ // Folia start - block plugins not marked as supported
+ if (!configuration.isFoliaSupported()) {
+ throw new RuntimeException("Could not load plugin '" + configuration.getDisplayName() + "' as it is not marked as supporting Folia!");
+ }
+ // Folia end - block plugins not marked as supported
// Copied from SimplePluginManager#loadPlugins
// Spigot doesn't validate the name when the config is created, and instead when the plugin is loaded.
// Paper plugin configuration will do these checks in config serializer instead of when this is created.
diff --git a/src/test/java/io/papermc/paper/plugin/TestPluginMeta.java b/src/test/java/io/papermc/paper/plugin/TestPluginMeta.java
index ba271c35eb2804f94cfc893bf94affb9ae13d3ba..db9285c2ff0c805f5d9564b6e8520c33ea5bb65a 100644
--- a/src/test/java/io/papermc/paper/plugin/TestPluginMeta.java
+++ b/src/test/java/io/papermc/paper/plugin/TestPluginMeta.java
@@ -20,6 +20,13 @@ public class TestPluginMeta implements PluginMeta {
this.identifier = identifier;
}
+ // Folia start - region threading
+ @Override
+ public boolean isFoliaSupported() {
+ return true;
+ }
+ // Folia end - region threading
+
@Override
public @NotNull String getName() {
return this.identifier;

View File

@ -1,29 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Wed, 31 Jul 2024 11:27:24 -0700
Subject: [PATCH] Disable spark profiler
It's not thread-safe. The plugin instead needs to be used.
diff --git a/src/main/java/io/papermc/paper/SparksFly.java b/src/main/java/io/papermc/paper/SparksFly.java
index 2ad5b9b0b7e18780ee73310451d9fa73f44c4bdb..b332645ed65928100f580221d8a9948bc77e362e 100644
--- a/src/main/java/io/papermc/paper/SparksFly.java
+++ b/src/main/java/io/papermc/paper/SparksFly.java
@@ -116,7 +116,7 @@ public final class SparksFly {
private void enable() {
if (!this.enabled) {
- if (GlobalConfiguration.get().spark.enabled) {
+ if (false) { // Folia - disable in-built spark profiler
this.enabled = true;
this.spark.enable();
} else {
@@ -168,7 +168,7 @@ public final class SparksFly {
}
public static boolean isPluginPreferred() {
- return Boolean.getBoolean(PREFER_SPARK_PLUGIN_PROPERTY);
+ return true; // Folia - disable in-built spark profiler
}
private static boolean isPluginEnabled(final Server server) {

View File

@ -0,0 +1,184 @@
--- a/src/main/java/ca/spottedleaf/moonrise/common/util/TickThread.java
+++ b/src/main/java/ca/spottedleaf/moonrise/common/util/TickThread.java
@@ -1,5 +_,11 @@
package ca.spottedleaf.moonrise.common.util;
+import io.papermc.paper.threadedregions.RegionShutdownThread;
+import io.papermc.paper.threadedregions.RegionizedServer;
+import io.papermc.paper.threadedregions.RegionizedWorldData;
+import io.papermc.paper.threadedregions.ThreadedRegionizer;
+import io.papermc.paper.threadedregions.TickRegionScheduler;
+import io.papermc.paper.threadedregions.TickRegions;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.ChunkPos;
@@ -119,50 +_,157 @@
}
public static boolean isShutdownThread() {
- return false;
+ return Thread.currentThread().getClass() == RegionShutdownThread.class;
}
public static boolean isTickThreadFor(final Level world, final BlockPos pos) {
- return isTickThread();
+ return isTickThreadFor(world, pos.getX() >> 4, pos.getZ() >> 4);
}
public static boolean isTickThreadFor(final Level world, final BlockPos pos, final int blockRadius) {
- return isTickThread();
+ return isTickThreadFor(
+ world,
+ (pos.getX() - blockRadius) >> 4, (pos.getZ() - blockRadius) >> 4,
+ (pos.getX() + blockRadius) >> 4, (pos.getZ() + blockRadius) >> 4
+ );
}
public static boolean isTickThreadFor(final Level world, final ChunkPos pos) {
- return isTickThread();
+ return isTickThreadFor(world, pos.x, pos.z);
}
public static boolean isTickThreadFor(final Level world, final Vec3 pos) {
- return isTickThread();
+ return isTickThreadFor(world, net.minecraft.util.Mth.floor(pos.x) >> 4, net.minecraft.util.Mth.floor(pos.z) >> 4);
}
public static boolean isTickThreadFor(final Level world, final int chunkX, final int chunkZ) {
- return isTickThread();
+ final ThreadedRegionizer.ThreadedRegion<TickRegions.TickRegionData, TickRegions.TickRegionSectionData> region =
+ TickRegionScheduler.getCurrentRegion();
+ if (region == null) {
+ return isShutdownThread();
+ }
+ return ((net.minecraft.server.level.ServerLevel)world).regioniser.getRegionAtUnsynchronised(chunkX, chunkZ) == region;
}
public static boolean isTickThreadFor(final Level world, final AABB aabb) {
- return isTickThread();
+ return isTickThreadFor(
+ world,
+ CoordinateUtils.getChunkCoordinate(aabb.minX), CoordinateUtils.getChunkCoordinate(aabb.minZ),
+ CoordinateUtils.getChunkCoordinate(aabb.maxX), CoordinateUtils.getChunkCoordinate(aabb.maxZ)
+ );
}
public static boolean isTickThreadFor(final Level world, final double blockX, final double blockZ) {
- return isTickThread();
+ return isTickThreadFor(world, CoordinateUtils.getChunkCoordinate(blockX), CoordinateUtils.getChunkCoordinate(blockZ));
}
public static boolean isTickThreadFor(final Level world, final Vec3 position, final Vec3 deltaMovement, final int buffer) {
- return isTickThread();
+ final int fromChunkX = CoordinateUtils.getChunkX(position);
+ final int fromChunkZ = CoordinateUtils.getChunkZ(position);
+
+ final int toChunkX = CoordinateUtils.getChunkCoordinate(position.x + deltaMovement.x);
+ final int toChunkZ = CoordinateUtils.getChunkCoordinate(position.z + deltaMovement.z);
+
+ // expect from < to, but that may not be the case
+ return isTickThreadFor(
+ world,
+ Math.min(fromChunkX, toChunkX) - buffer,
+ Math.min(fromChunkZ, toChunkZ) - buffer,
+ Math.max(fromChunkX, toChunkX) + buffer,
+ Math.max(fromChunkZ, toChunkZ) + buffer
+ );
}
public static boolean isTickThreadFor(final Level world, final int fromChunkX, final int fromChunkZ, final int toChunkX, final int toChunkZ) {
- return isTickThread();
+ final ThreadedRegionizer.ThreadedRegion<TickRegions.TickRegionData, TickRegions.TickRegionSectionData> region =
+ TickRegionScheduler.getCurrentRegion();
+ if (region == null) {
+ return isShutdownThread();
+ }
+
+ final int shift = ((net.minecraft.server.level.ServerLevel)world).regioniser.sectionChunkShift;
+
+ final int minSectionX = fromChunkX >> shift;
+ final int maxSectionX = toChunkX >> shift;
+ final int minSectionZ = fromChunkZ >> shift;
+ final int maxSectionZ = toChunkZ >> shift;
+
+ for (int secZ = minSectionZ; secZ <= maxSectionZ; ++secZ) {
+ for (int secX = minSectionX; secX <= maxSectionX; ++secX) {
+ final int lowerLeftCX = secX << shift;
+ final int lowerLeftCZ = secZ << shift;
+ if (((net.minecraft.server.level.ServerLevel)world).regioniser.getRegionAtUnsynchronised(lowerLeftCX, lowerLeftCZ) != region) {
+ return false;
+ }
+ }
+ }
+
+ return true;
}
public static boolean isTickThreadFor(final Level world, final int chunkX, final int chunkZ, final int radius) {
- return isTickThread();
+ return isTickThreadFor(world, chunkX - radius, chunkZ - radius, chunkX + radius, chunkZ + radius);
}
public static boolean isTickThreadFor(final Entity entity) {
- return isTickThread();
+ if (entity == null) {
+ return true;
+ }
+ final ThreadedRegionizer.ThreadedRegion<TickRegions.TickRegionData, TickRegions.TickRegionSectionData> region =
+ TickRegionScheduler.getCurrentRegion();
+ if (region == null) {
+ if (RegionizedServer.isGlobalTickThread()) {
+ if (entity instanceof net.minecraft.server.level.ServerPlayer serverPlayer) {
+ final net.minecraft.server.network.ServerGamePacketListenerImpl possibleBad = serverPlayer.connection;
+ if (possibleBad == null) {
+ return true;
+ }
+
+ final net.minecraft.network.PacketListener packetListener = possibleBad.connection.getPacketListener();
+ if (packetListener instanceof net.minecraft.server.network.ServerGamePacketListenerImpl gamePacketListener) {
+ return gamePacketListener.waitingForSwitchToConfig;
+ }
+ if (packetListener instanceof net.minecraft.server.network.ServerConfigurationPacketListenerImpl configurationPacketListener) {
+ return !configurationPacketListener.switchToMain;
+ }
+ return true;
+ } else {
+ return false;
+ }
+ }
+ if (isShutdownThread()) {
+ return true;
+ }
+ if (entity instanceof net.minecraft.server.level.ServerPlayer serverPlayer) {
+ // off-main access to server player is never ok, server player is owned by one of global context or region context always
+ return false;
+ }
+ // only own entities that have not yet been added to the world
+
+ // if the entity is removed, then it was in the world previously - which means that a region containing its location
+ // owns it
+ // if the entity has a callback, then it is contained in a world
+ return entity.hasNullCallback() && !entity.isRemoved();
+ }
+
+ final Level world = entity.level();
+ if (world != region.regioniser.world) {
+ // world mismatch
+ return false;
+ }
+
+ final RegionizedWorldData worldData = io.papermc.paper.threadedregions.TickRegionScheduler.getCurrentRegionizedWorldData();
+
+ // pass through the check if the entity is removed and we own its chunk
+ if (worldData.hasEntity(entity)) {
+ return true;
+ }
+
+ if (entity instanceof net.minecraft.server.level.ServerPlayer serverPlayer) {
+ net.minecraft.server.network.ServerGamePacketListenerImpl conn = serverPlayer.connection;
+ return conn != null && worldData.connections.contains(conn.connection);
+ } else {
+ return ((entity.hasNullCallback() || entity.isRemoved())) && isTickThreadFor((net.minecraft.server.level.ServerLevel)world, entity.chunkPosition());
+ }
}
}

View File

@ -0,0 +1,57 @@
--- a/src/main/java/io/papermc/paper/SparksFly.java
+++ b/src/main/java/io/papermc/paper/SparksFly.java
@@ -33,13 +_,13 @@
private final Logger logger;
private final PaperSparkModule spark;
- private final ConcurrentLinkedQueue<Runnable> mainThreadTaskQueue;
+ // Folia - region threading
private boolean enabled;
private boolean disabledInConfigurationWarningLogged;
public SparksFly(final Server server) {
- this.mainThreadTaskQueue = new ConcurrentLinkedQueue<>();
+ // Folia - region threading
this.logger = Logger.getLogger(ID);
this.logger.log(Level.INFO, "This server bundles the spark profiler. For more information please visit https://docs.papermc.io/paper/profiling");
this.spark = PaperSparkModule.create(Compatibility.VERSION_1_0, server, this.logger, new PaperScheduler() {
@@ -50,7 +_,7 @@
@Override
public void executeSync(final Runnable runnable) {
- SparksFly.this.mainThreadTaskQueue.offer(this.catching(runnable, "synchronous"));
+ io.papermc.paper.threadedregions.RegionizedServer.getInstance().addTask(this.catching(runnable, "synchronous")); // Folia - region threading
}
private Runnable catching(final Runnable runnable, final String type) {
@@ -88,10 +_,7 @@
}
public void executeMainThreadTasks() {
- Runnable task;
- while ((task = this.mainThreadTaskQueue.poll()) != null) {
- task.run();
- }
+ throw new UnsupportedOperationException(); // Folia - region threading
}
public void enableEarlyIfRequested() {
@@ -119,7 +_,7 @@
private void enable() {
if (!this.enabled) {
- if (GlobalConfiguration.get().spark.enabled) {
+ if (false) { // Folia - disable in-built spark profiler
this.enabled = true;
this.spark.enable();
} else {
@@ -171,7 +_,7 @@
}
public static boolean isPluginPreferred() {
- return Boolean.getBoolean(PREFER_SPARK_PLUGIN_PROPERTY);
+ return true; // Folia - disable in-built spark profiler
}
private static boolean isPluginEnabled(final Server server) {

View File

@ -0,0 +1,20 @@
--- a/src/main/java/io/papermc/paper/adventure/ChatProcessor.java
+++ b/src/main/java/io/papermc/paper/adventure/ChatProcessor.java
@@ -83,7 +_,7 @@
final CraftPlayer player = this.player.getBukkitEntity();
final AsyncPlayerChatEvent ae = new AsyncPlayerChatEvent(this.async, player, this.craftbukkit$originalMessage, new LazyPlayerSet(this.server));
this.post(ae);
- if (listenersOnSyncEvent) {
+ if (false && listenersOnSyncEvent) { // Folia - region threading
final PlayerChatEvent se = new PlayerChatEvent(player, ae.getMessage(), ae.getFormat(), ae.getRecipients());
se.setCancelled(ae.isCancelled()); // propagate cancelled state
this.queueIfAsyncOrRunImmediately(new Waitable<Void>() {
@@ -150,7 +_,7 @@
ae.setCancelled(cancelled); // propagate cancelled state
this.post(ae);
final boolean listenersOnSyncEvent = canYouHearMe(ChatEvent.getHandlerList());
- if (listenersOnSyncEvent) {
+ if (false && listenersOnSyncEvent) { // Folia - region threading
this.queueIfAsyncOrRunImmediately(new Waitable<Void>() {
@Override
protected Void evaluate() {

View File

@ -0,0 +1,57 @@
--- a/src/main/java/io/papermc/paper/adventure/providers/ClickCallbackProviderImpl.java
+++ b/src/main/java/io/papermc/paper/adventure/providers/ClickCallbackProviderImpl.java
@@ -23,35 +_,42 @@
public static final class CallbackManager {
- private final Map<UUID, StoredCallback> callbacks = new HashMap<>();
- private final Queue<StoredCallback> queue = new ConcurrentLinkedQueue<>();
+ private final java.util.concurrent.ConcurrentHashMap<UUID, StoredCallback> callbacks = new java.util.concurrent.ConcurrentHashMap<>(); // Folia - region threading
+ // Folia - region threading
private CallbackManager() {
}
public UUID addCallback(final @NotNull ClickCallback<Audience> callback, final ClickCallback.@NotNull Options options) {
final UUID id = UUID.randomUUID();
- this.queue.add(new StoredCallback(callback, options, id));
+ final StoredCallback scb = new StoredCallback(callback, options, id); // Folia - region threading
+ this.callbacks.put(scb.id(), scb); // Folia - region threading
return id;
}
public void handleQueue(final int currentTick) {
// Evict expired entries
if (currentTick % 100 == 0) {
- this.callbacks.values().removeIf(callback -> !callback.valid());
+ this.callbacks.values().removeIf(StoredCallback::expired); // Folia - region threading - don't read uses field
}
- // Add entries from queue
- StoredCallback callback;
- while ((callback = this.queue.poll()) != null) {
- this.callbacks.put(callback.id(), callback);
- }
+ // Folia - region threading
}
public void runCallback(final @NotNull Audience audience, final UUID id) {
- final StoredCallback callback = this.callbacks.get(id);
- if (callback != null && callback.valid()) { //TODO Message if expired/invalid?
- callback.takeUse();
+ // Folia start - region threading
+ final StoredCallback[] use = new StoredCallback[1];
+ this.callbacks.computeIfPresent(id, (final UUID keyInMap, final StoredCallback value) -> {
+ if (!value.valid()) {
+ return null;
+ }
+ use[0] = value;
+ value.takeUse();
+ return value.valid() ? value : null;
+ });
+ final StoredCallback callback = use[0];
+ if (callback != null) { //TODO Message if expired/invalid?
+ // Folia end - region threading
callback.callback.accept(audience);
}
}

View File

@ -0,0 +1,10 @@
--- a/src/main/java/io/papermc/paper/command/PaperCommands.java
+++ b/src/main/java/io/papermc/paper/command/PaperCommands.java
@@ -19,6 +_,7 @@
COMMANDS.put("paper", new PaperCommand("paper"));
COMMANDS.put("callback", new CallbackCommand("callback"));
COMMANDS.put("mspt", new MSPTCommand("mspt"));
+ COMMANDS.put("tps", new io.papermc.paper.threadedregions.commands.CommandServerHealth()); // Folia - region threading
}
public static void registerCommands(final MinecraftServer server) {

View File

@ -0,0 +1,11 @@
--- a/src/main/java/io/papermc/paper/command/subcommands/EntityCommand.java
+++ b/src/main/java/io/papermc/paper/command/subcommands/EntityCommand.java
@@ -129,7 +_,7 @@
final int z = (e.getKey().z << 4) + 8;
final Component message = text(" " + e.getValue() + ": " + e.getKey().x + ", " + e.getKey().z + (chunkProviderServer.isPositionTicking(e.getKey().toLong()) ? " (Ticking)" : " (Non-Ticking)"))
.hoverEvent(HoverEvent.showText(text("Click to teleport to chunk", GREEN)))
- .clickEvent(ClickEvent.clickEvent(ClickEvent.Action.RUN_COMMAND, "/minecraft:execute as @s in " + world.getWorld().getKey() + " run tp " + x + " " + (world.getWorld().getHighestBlockYAt(x, z, HeightMap.MOTION_BLOCKING) + 1) + " " + z));
+ .clickEvent(ClickEvent.clickEvent(ClickEvent.Action.RUN_COMMAND, "/minecraft:execute as @s in " + world.getWorld().getKey() + " run tp " + x + " " + (128) + " " + z)); // Folia - region threading - avoid sync load here
sender.sendMessage(message);
});
} else {

View File

@ -0,0 +1,12 @@
--- a/src/main/java/io/papermc/paper/command/subcommands/HeapDumpCommand.java
+++ b/src/main/java/io/papermc/paper/command/subcommands/HeapDumpCommand.java
@@ -18,7 +_,9 @@
public final class HeapDumpCommand implements PaperSubcommand {
@Override
public boolean execute(final CommandSender sender, final String subCommand, final String[] args) {
+ io.papermc.paper.threadedregions.RegionizedServer.getInstance().addTask(() -> { // Folia - region threading
this.dumpHeap(sender);
+ }); // Folia - region threading
return true;
}

View File

@ -0,0 +1,12 @@
--- a/src/main/java/io/papermc/paper/command/subcommands/ReloadCommand.java
+++ b/src/main/java/io/papermc/paper/command/subcommands/ReloadCommand.java
@@ -16,7 +_,9 @@
public final class ReloadCommand implements PaperSubcommand {
@Override
public boolean execute(final CommandSender sender, final String subCommand, final String[] args) {
+ io.papermc.paper.threadedregions.RegionizedServer.getInstance().addTask(() -> { // Folia - region threading
this.doReload(sender);
+ }); // Folia - region threading
return true;
}

View File

@ -0,0 +1,20 @@
--- a/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java
+++ b/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java
@@ -396,4 +_,17 @@
}
}
}
+ // Folia start - threaded regions
+ public ThreadedRegions threadedRegions;
+ public class ThreadedRegions extends ConfigurationPart {
+
+ public int threads = -1;
+ public int gridExponent = 4;
+
+ @PostProcess
+ public void postProcess() {
+ io.papermc.paper.threadedregions.TickRegions.init(this);
+ }
+ }
+ // Folia end - threaded regions
}

View File

@ -0,0 +1,17 @@
--- a/src/main/java/io/papermc/paper/configuration/WorldConfiguration.java
+++ b/src/main/java/io/papermc/paper/configuration/WorldConfiguration.java
@@ -493,6 +_,14 @@
public Chunks chunks;
public class Chunks extends ConfigurationPart {
+
+ // Folia start - region threading - force prevent moving into unloaded chunks
+ @PostProcess
+ public void postProcess() {
+ this.preventMovingIntoUnloadedChunks = true;
+ }
+ // Folia end - region threading - force prevent moving into unloaded chunks
+
public AutosavePeriod autoSaveInterval = AutosavePeriod.def();
public int maxAutoSaveChunksPerTick = 24;
public int fixedChunkInhabitedTime = -1;

View File

@ -0,0 +1,19 @@
--- a/src/main/java/io/papermc/paper/entity/PaperSchoolableFish.java
+++ b/src/main/java/io/papermc/paper/entity/PaperSchoolableFish.java
@@ -11,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public AbstractSchoolingFish getHandleRaw() {
+ return (AbstractSchoolingFish)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public AbstractSchoolingFish getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (AbstractSchoolingFish) super.getHandle();
}

View File

@ -0,0 +1,11 @@
--- a/src/main/java/io/papermc/paper/entity/activation/ActivationType.java
+++ b/src/main/java/io/papermc/paper/entity/activation/ActivationType.java
@@ -19,7 +_,7 @@
RAIDER,
MISC;
- AABB boundingBox = new AABB(0, 0, 0, 0, 0, 0);
+ //AABB boundingBox = new AABB(0, 0, 0, 0, 0, 0); // Folia - threaded regions - replaced by local variable
/**
* Returns the activation type for the given entity.

View File

@ -1,20 +1,6 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Mon, 15 May 2023 10:58:06 -0700
Subject: [PATCH] Synchronize PaperPermissionManager
Since multiple regions can exist, there are concurrent accesses
in this class. To prevent deadlock, the monitor is not held
when recalculating permissions, as Permissable holds its own
lock.
This fixes CMEs originating from this class.
diff --git a/src/main/java/io/papermc/paper/plugin/manager/PaperPermissionManager.java b/src/main/java/io/papermc/paper/plugin/manager/PaperPermissionManager.java
index afe793c35f05a80058e80bcaee76ac45a40b04a2..9ddbb2d72e11c6abbbdb866f3010f276efceda41 100644
--- a/src/main/java/io/papermc/paper/plugin/manager/PaperPermissionManager.java
+++ b/src/main/java/io/papermc/paper/plugin/manager/PaperPermissionManager.java
@@ -32,7 +32,9 @@ abstract class PaperPermissionManager implements PermissionManager {
@@ -32,7 +_,9 @@
@Override
@Nullable
public Permission getPermission(@NotNull String name) {
@ -24,7 +10,7 @@ index afe793c35f05a80058e80bcaee76ac45a40b04a2..9ddbb2d72e11c6abbbdb866f3010f276
}
@Override
@@ -52,12 +54,24 @@ abstract class PaperPermissionManager implements PermissionManager {
@@ -52,12 +_,24 @@
private void addPermission(@NotNull Permission perm, boolean dirty) {
String name = perm.getName().toLowerCase(java.util.Locale.ENGLISH);
@ -50,7 +36,7 @@ index afe793c35f05a80058e80bcaee76ac45a40b04a2..9ddbb2d72e11c6abbbdb866f3010f276
}
@Override
@@ -80,42 +94,58 @@ abstract class PaperPermissionManager implements PermissionManager {
@@ -80,42 +_,58 @@
@Override
public void recalculatePermissionDefaults(@NotNull Permission perm) {
@ -62,6 +48,7 @@ index afe793c35f05a80058e80bcaee76ac45a40b04a2..9ddbb2d72e11c6abbbdb866f3010f276
this.defaultPerms().get(false).remove(perm);
- this.calculatePermissionDefault(perm, true);
- }
+ recalc = this.calculatePermissionDefault(perm, true); // Folia - synchronized
+ }
+ } // Folia - synchronized
@ -72,7 +59,7 @@ index afe793c35f05a80058e80bcaee76ac45a40b04a2..9ddbb2d72e11c6abbbdb866f3010f276
+ } else {
+ this.dirtyPermissibles(false);
+ }
}
+ }
+ // Folia end - synchronize this class - we hold a lock now, prevent deadlock by moving this out
}
@ -113,7 +100,7 @@ index afe793c35f05a80058e80bcaee76ac45a40b04a2..9ddbb2d72e11c6abbbdb866f3010f276
Map<Permissible, Boolean> map = this.permSubs().get(name);
if (map != null) {
@@ -125,11 +155,13 @@ abstract class PaperPermissionManager implements PermissionManager {
@@ -125,11 +_,13 @@
this.permSubs().remove(name);
}
}
@ -127,7 +114,7 @@ index afe793c35f05a80058e80bcaee76ac45a40b04a2..9ddbb2d72e11c6abbbdb866f3010f276
String name = permission.toLowerCase(java.util.Locale.ENGLISH);
Map<Permissible, Boolean> map = this.permSubs().get(name);
@@ -138,17 +170,21 @@ abstract class PaperPermissionManager implements PermissionManager {
@@ -138,17 +_,21 @@
} else {
return ImmutableSet.copyOf(map.keySet());
}
@ -149,7 +136,7 @@ index afe793c35f05a80058e80bcaee76ac45a40b04a2..9ddbb2d72e11c6abbbdb866f3010f276
Map<Permissible, Boolean> map = this.defSubs().get(op);
if (map != null) {
@@ -158,11 +194,13 @@ abstract class PaperPermissionManager implements PermissionManager {
@@ -158,11 +_,13 @@
this.defSubs().remove(op);
}
}
@ -163,7 +150,7 @@ index afe793c35f05a80058e80bcaee76ac45a40b04a2..9ddbb2d72e11c6abbbdb866f3010f276
Map<Permissible, Boolean> map = this.defSubs().get(op);
if (map == null) {
@@ -170,19 +208,24 @@ abstract class PaperPermissionManager implements PermissionManager {
@@ -170,19 +_,24 @@
} else {
return ImmutableSet.copyOf(map.keySet());
}

View File

@ -0,0 +1,16 @@
--- a/src/main/java/io/papermc/paper/plugin/manager/PaperPluginInstanceManager.java
+++ b/src/main/java/io/papermc/paper/plugin/manager/PaperPluginInstanceManager.java
@@ -256,12 +_,7 @@
+ pluginName + " (Is it up to date?)", ex, plugin); // Paper
}
- try {
- this.server.getScheduler().cancelTasks(plugin);
- } catch (Throwable ex) {
- this.handlePluginException("Error occurred (in the plugin loader) while cancelling tasks for "
- + pluginName + " (Is it up to date?)", ex, plugin); // Paper
- }
+ // Folia - region threading
// Paper start - Folia schedulers
try {

View File

@ -0,0 +1,24 @@
--- a/src/main/java/io/papermc/paper/plugin/provider/configuration/PaperPluginMeta.java
+++ b/src/main/java/io/papermc/paper/plugin/provider/configuration/PaperPluginMeta.java
@@ -64,6 +_,7 @@
private PermissionConfiguration permissionConfiguration = new PermissionConfiguration(PermissionDefault.OP, List.of());
@Required
private ApiVersion apiVersion;
+ private boolean foliaSupported = false; // Folia
private Map<PluginDependencyLifeCycle, Map<String, DependencyConfiguration>> dependencies = new EnumMap<>(PluginDependencyLifeCycle.class);
@@ -250,6 +_,13 @@
public @NotNull String getAPIVersion() {
return this.apiVersion.getVersionString();
}
+
+ // Folia start
+ @Override
+ public boolean isFoliaSupported() {
+ return this.foliaSupported;
+ }
+ // Folia end
@Override
public @NotNull List<String> getProvidedPlugins() {

View File

@ -0,0 +1,14 @@
--- a/src/main/java/io/papermc/paper/plugin/provider/type/paper/PaperPluginProviderFactory.java
+++ b/src/main/java/io/papermc/paper/plugin/provider/type/paper/PaperPluginProviderFactory.java
@@ -24,6 +_,11 @@
@Override
public PaperPluginParent build(JarFile file, PaperPluginMeta configuration, Path source) {
+ // Folia start - block plugins not marked as supported
+ if (!configuration.isFoliaSupported()) {
+ throw new RuntimeException("Could not load plugin '" + configuration.getDisplayName() + "' as it is not marked as supporting Folia!");
+ }
+ // Folia end - block plugins not marked as supported
Logger jul = PaperPluginLogger.getLogger(configuration);
ComponentLogger logger = ComponentLogger.logger(jul.getName());
PluginProviderContext context = PluginProviderContextImpl.create(configuration, logger, source);

View File

@ -0,0 +1,14 @@
--- a/src/main/java/io/papermc/paper/plugin/provider/type/spigot/SpigotPluginProviderFactory.java
+++ b/src/main/java/io/papermc/paper/plugin/provider/type/spigot/SpigotPluginProviderFactory.java
@@ -35,6 +_,11 @@
@Override
public SpigotPluginProvider build(JarFile file, PluginDescriptionFile configuration, Path source) throws InvalidDescriptionException {
+ // Folia start - block plugins not marked as supported
+ if (!configuration.isFoliaSupported()) {
+ throw new RuntimeException("Could not load plugin '" + configuration.getDisplayName() + "' as it is not marked as supporting Folia!");
+ }
+ // Folia end - block plugins not marked as supported
// Copied from SimplePluginManager#loadPlugins
// Spigot doesn't validate the name when the config is created, and instead when the plugin is loaded.
// Paper plugin configuration will do these checks in config serializer instead of when this is created.

View File

@ -0,0 +1,17 @@
--- a/src/main/java/io/papermc/paper/threadedregions/EntityScheduler.java
+++ b/src/main/java/io/papermc/paper/threadedregions/EntityScheduler.java
@@ -50,6 +_,14 @@
this.entity = Validate.notNull(entity);
}
+ // Folia start - region threading
+ public boolean isRetired() {
+ synchronized (this.stateLock) {
+ return this.tickCount == RETIRED_TICK_COUNT;
+ }
+ }
+ // Folia end - region threading
+
/**
* Retires the scheduler, preventing new tasks from being scheduled and invoking the retired callback
* on all currently scheduled tasks.

View File

@ -0,0 +1,41 @@
--- a/src/main/java/io/papermc/paper/util/MCUtil.java
+++ b/src/main/java/io/papermc/paper/util/MCUtil.java
@@ -94,6 +_,7 @@
*/
public static void ensureMain(String reason, Runnable run) {
if (!isMainThread()) {
+ if (true) throw new UnsupportedOperationException(); // Folia - region threading
if (reason != null) {
MinecraftServer.LOGGER.warn("Asynchronous " + reason + "!", new IllegalStateException());
}
@@ -147,6 +_,30 @@
public static Location toLocation(Level world, BlockPos pos) {
return new Location(world.getWorld(), pos.getX(), pos.getY(), pos.getZ());
}
+
+ // Folia start - TODO MERGE INTO MCUTIL
+ /**
+ * Converts a NMS World/Vector to Bukkit Location
+ * @param world
+ * @param pos
+ * @return
+ */
+ public static Location toLocation(Level world, Vec3 pos) {
+ return new Location(world.getWorld(), pos.x(), pos.y(), pos.z());
+ }
+
+ /**
+ * Converts a NMS World/Vector to Bukkit Location
+ * @param world
+ * @param pos
+ * @param yaw
+ * @param pitch
+ * @return
+ */
+ public static Location toLocation(Level world, Vec3 pos, float yaw, float pitch) {
+ return new Location(world.getWorld(), pos.x(), pos.y(), pos.z(), yaw, pitch);
+ }
+ // Folia end - TODO MERGE INTO MCUTIL
public static BlockPos toBlockPosition(Location loc) {
return new BlockPos(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());

View File

@ -0,0 +1,102 @@
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -315,7 +_,7 @@
public final io.papermc.paper.SparksFly spark; // Paper - spark
// Paper start - Folia region threading API
- private final io.papermc.paper.threadedregions.scheduler.FallbackRegionScheduler regionizedScheduler = new io.papermc.paper.threadedregions.scheduler.FallbackRegionScheduler();
+ private final io.papermc.paper.threadedregions.scheduler.FoliaRegionScheduler regionizedScheduler = new io.papermc.paper.threadedregions.scheduler.FoliaRegionScheduler(); // Folia - region threading
private final io.papermc.paper.threadedregions.scheduler.FoliaAsyncScheduler asyncScheduler = new io.papermc.paper.threadedregions.scheduler.FoliaAsyncScheduler();
private final io.papermc.paper.threadedregions.scheduler.FoliaGlobalRegionScheduler globalRegionScheduler = new io.papermc.paper.threadedregions.scheduler.FoliaGlobalRegionScheduler();
@@ -392,7 +_,7 @@
@Override
public final boolean isGlobalTickThread() {
- return ca.spottedleaf.moonrise.common.util.TickThread.isTickThread();
+ return io.papermc.paper.threadedregions.RegionizedServer.isGlobalTickThread(); // Folia - region threading API
}
// Paper end - Folia reagion threading API
@@ -987,6 +_,9 @@
// NOTE: Should only be called from DedicatedServer.ah()
public boolean dispatchServerCommand(CommandSender sender, ConsoleInput serverCommand) {
+ // Folia start - region threading
+ io.papermc.paper.threadedregions.RegionizedServer.ensureGlobalTickThread("May not dispatch server commands async");
+ // Folia end - region threading
if (sender instanceof Conversable) {
Conversable conversable = (Conversable) sender;
@@ -1006,12 +_,46 @@
}
}
+ // Folia start - region threading
+ public void dispatchCmdAsync(CommandSender sender, String commandLine) {
+ if ((sender instanceof Entity entity)) {
+ ((org.bukkit.craftbukkit.entity.CraftEntity)entity).taskScheduler.schedule(
+ (nmsEntity) -> {
+ CraftServer.this.dispatchCommand(nmsEntity.getBukkitEntity(), commandLine);
+ },
+ null,
+ 1L
+ );
+ } else if (sender instanceof ConsoleCommandSender || sender instanceof io.papermc.paper.commands.FeedbackForwardingSender) {
+ io.papermc.paper.threadedregions.RegionizedServer.getInstance().addTask(() -> {
+ CraftServer.this.dispatchCommand(sender, commandLine);
+ });
+ } else {
+ // huh?
+ throw new UnsupportedOperationException("Dispatching command for " + sender);
+ }
+ }
+ // Folia end - region threading
+
@Override
public boolean dispatchCommand(CommandSender sender, String commandLine) {
Preconditions.checkArgument(sender != null, "sender cannot be null");
Preconditions.checkArgument(commandLine != null, "commandLine cannot be null");
org.spigotmc.AsyncCatcher.catchOp("Command Dispatched Async: " + commandLine); // Spigot // Paper - Include command in error message
+ // Folia start - region threading
+ if ((sender instanceof Entity entity)) {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(((org.bukkit.craftbukkit.entity.CraftEntity)entity).getHandle(), "Dispatching command async");
+ } else if (sender instanceof ConsoleCommandSender || sender instanceof net.minecraft.server.rcon.RconConsoleSource
+ || sender instanceof org.bukkit.craftbukkit.command.CraftRemoteConsoleCommandSender
+ || sender instanceof io.papermc.paper.commands.FeedbackForwardingSender) {
+ io.papermc.paper.threadedregions.RegionizedServer.ensureGlobalTickThread("Dispatching command async");
+ } else {
+ // huh?
+ throw new UnsupportedOperationException("Dispatching command for " + sender);
+ }
+ // Folia end - region threading
+
if (this.commandMap.dispatch(sender, commandLine)) {
return true;
}
@@ -1283,6 +_,7 @@
@Override
public World createWorld(WorldCreator creator) {
+ if (true) throw new UnsupportedOperationException(); // Folia - not implemented properly yet
Preconditions.checkState(this.console.getAllLevels().iterator().hasNext(), "Cannot create additional worlds on STARTUP");
//Preconditions.checkState(!this.console.isIteratingOverLevels, "Cannot create a world while worlds are being ticked"); // Paper - Cat - Temp disable. We'll see how this goes.
Preconditions.checkArgument(creator != null, "WorldCreator cannot be null");
@@ -1480,6 +_,7 @@
@Override
public boolean unloadWorld(World world, boolean save) {
+ if (true) throw new UnsupportedOperationException(); // Folia - not implemented properly yet
//Preconditions.checkState(!this.console.isIteratingOverLevels, "Cannot unload a world while worlds are being ticked"); // Paper - Cat - Temp disable. We'll see how this goes.
if (world == null) {
return false;
@@ -3252,7 +_,7 @@
@Override
public int getCurrentTick() {
- return net.minecraft.server.MinecraftServer.currentTick;
+ return (int)io.papermc.paper.threadedregions.RegionizedServer.getCurrentTick(); // Folia - region threading
}
@Override

View File

@ -0,0 +1,415 @@
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -228,7 +_,7 @@
@Override
public int getTickableTileEntityCount() {
- return world.blockEntityTickers.size();
+ throw new UnsupportedOperationException(); // Folia - region threading - TODO fix this?
}
@Override
@@ -295,7 +_,7 @@
// Paper start - per world spawn limits
for (SpawnCategory spawnCategory : SpawnCategory.values()) {
if (CraftSpawnCategory.isValidForLimits(spawnCategory)) {
- setSpawnLimit(spawnCategory, this.world.paperConfig().entities.spawning.spawnLimits.getInt(CraftSpawnCategory.toNMS(spawnCategory)));
+ this.spawnCategoryLimit.put(spawnCategory, this.world.paperConfig().entities.spawning.spawnLimits.getInt(CraftSpawnCategory.toNMS(spawnCategory))); // Folia - region threading
}
}
// Paper end - per world spawn limits
@@ -365,6 +_,7 @@
@Override
public Chunk getChunkAt(int x, int z) {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.getHandle(), x, z, "Async chunk retrieval"); // Folia - region threading
warnUnsafeChunk("getting a faraway chunk", x, z); // Paper
net.minecraft.world.level.chunk.LevelChunk chunk = (net.minecraft.world.level.chunk.LevelChunk) this.world.getChunk(x, z, ChunkStatus.FULL, true);
return new CraftChunk(chunk);
@@ -395,10 +_,10 @@
@Override
public boolean isChunkGenerated(int x, int z) {
// Paper start - Fix this method
- if (!Bukkit.isPrimaryThread()) {
+ if (!ca.spottedleaf.moonrise.common.util.TickThread.isTickThreadFor(this.getHandle(), x, z)) { // Folia - region threading
return java.util.concurrent.CompletableFuture.supplyAsync(() -> {
return CraftWorld.this.isChunkGenerated(x, z);
- }, world.getChunkSource().mainThreadProcessor).join();
+ }, (run) -> { io.papermc.paper.threadedregions.RegionizedServer.getInstance().taskQueue.queueChunkTask(this.getHandle(), x, z, run);}).join(); // Folia - region threading
}
ChunkAccess chunk = world.getChunkSource().getChunkAtImmediately(x, z);
if (chunk != null) {
@@ -455,7 +_,7 @@
}
private boolean unloadChunk0(int x, int z, boolean save) {
- org.spigotmc.AsyncCatcher.catchOp("chunk unload"); // Spigot
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.world, x, z, "Cannot unload chunk asynchronously"); // Folia - region threading
if (!this.isChunkLoaded(x, z)) {
return true;
}
@@ -472,7 +_,7 @@
@Override
public boolean regenerateChunk(int x, int z) {
- org.spigotmc.AsyncCatcher.catchOp("chunk regenerate"); // Spigot
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.world, x, z, "Cannot regenerate chunk asynchronously"); // Folia - region threading
throw new UnsupportedOperationException("Not supported in this Minecraft version! Unless you can fix it, this is not a bug :)");
/*
if (!unloadChunk0(x, z, false)) {
@@ -499,6 +_,7 @@
@Override
public boolean refreshChunk(int x, int z) {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.world, x, z, "Cannot refresh chunk asynchronously"); // Folia - region threading
ChunkHolder playerChunk = this.world.getChunkSource().chunkMap.getVisibleChunkIfPresent(ChunkPos.asLong(x, z));
if (playerChunk == null) return false;
@@ -549,7 +_,7 @@
@Override
public boolean loadChunk(int x, int z, boolean generate) {
- org.spigotmc.AsyncCatcher.catchOp("chunk load"); // Spigot
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.getHandle(), x, z, "May not sync load chunks asynchronously"); // Folia - region threading
warnUnsafeChunk("loading a faraway chunk", x, z); // Paper
ChunkAccess chunk = this.world.getChunkSource().getChunk(x, z, generate || isChunkGenerated(x, z) ? ChunkStatus.FULL : ChunkStatus.EMPTY, true); // Paper
@@ -589,7 +_,7 @@
final DistanceManager distanceManager = this.world.getChunkSource().chunkMap.distanceManager;
if (distanceManager.addPluginRegionTicket(new ChunkPos(x, z), plugin)) {
- this.getChunkAt(x, z); // ensure it's loaded
+ //this.getChunkAt(x, z); // ensure it's loaded // Folia - region threading - do not load chunks for tickets anymore to make this mt-safe
return true;
}
@@ -777,13 +_,15 @@
@Override
public boolean generateTree(Location loc, TreeType type, BlockChangeDelegate delegate) {
- this.world.captureTreeGeneration = true;
- this.world.captureBlockStates = true;
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.world, loc.getX(), loc.getZ(), "Cannot generate tree asynchronously"); // Folia - region threading
+ io.papermc.paper.threadedregions.RegionizedWorldData worldData = world.getCurrentWorldData(); // Folia - region threading
+ worldData.captureTreeGeneration = true; // Folia - region threading
+ worldData.captureBlockStates = true; // Folia - region threading
boolean grownTree = this.generateTree(loc, type);
- this.world.captureBlockStates = false;
- this.world.captureTreeGeneration = false;
+ worldData.captureBlockStates = false; // Folia - region threading
+ worldData.captureTreeGeneration = false; // Folia - region threading
if (grownTree) { // Copy block data to delegate
- for (BlockState blockstate : this.world.capturedBlockStates.values()) {
+ for (BlockState blockstate : worldData.capturedBlockStates.values()) { // Folia - region threading
BlockPos position = ((CraftBlockState) blockstate).getPosition();
net.minecraft.world.level.block.state.BlockState oldBlock = this.world.getBlockState(position);
int flag = ((CraftBlockState) blockstate).getFlag();
@@ -791,10 +_,10 @@
net.minecraft.world.level.block.state.BlockState newBlock = this.world.getBlockState(position);
this.world.notifyAndUpdatePhysics(position, null, oldBlock, newBlock, newBlock, flag, 512);
}
- this.world.capturedBlockStates.clear();
+ worldData.capturedBlockStates.clear(); // Folia - region threading
return true;
} else {
- this.world.capturedBlockStates.clear();
+ worldData.capturedBlockStates.clear(); // Folia - region threading
return false;
}
}
@@ -828,6 +_,7 @@
@Override
public void setTime(long time) {
+ io.papermc.paper.threadedregions.RegionizedServer.ensureGlobalTickThread("Cannot modify time off of the global region"); // Folia - region threading
long margin = (time - this.getFullTime()) % 24000;
if (margin < 0) margin += 24000;
this.setFullTime(this.getFullTime() + margin);
@@ -840,6 +_,7 @@
@Override
public void setFullTime(long time) {
+ io.papermc.paper.threadedregions.RegionizedServer.ensureGlobalTickThread("Cannot modify time off of the global region"); // Folia - region threading
// Notify anyone who's listening
TimeSkipEvent event = new TimeSkipEvent(this, TimeSkipEvent.SkipReason.CUSTOM, time - this.world.getDayTime());
this.server.getPluginManager().callEvent(event);
@@ -867,7 +_,7 @@
@Override
public long getGameTime() {
- return this.world.levelData.getGameTime();
+ return this.getHandle().getGameTime(); // Folia - region threading
}
@Override
@@ -892,6 +_,7 @@
}
public boolean createExplosion(double x, double y, double z, float power, boolean setFire, boolean breakBlocks, Entity source, Consumer<net.minecraft.world.level.ServerExplosion> configurator) {
// Paper end - expand explosion API
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.world, x, z, "Cannot create explosion asynchronously"); // Folia - region threading
net.minecraft.world.level.Level.ExplosionInteraction explosionType;
if (!breakBlocks) {
explosionType = net.minecraft.world.level.Level.ExplosionInteraction.NONE; // Don't break blocks
@@ -901,6 +_,7 @@
explosionType = net.minecraft.world.level.Level.ExplosionInteraction.MOB; // Respect mobGriefing gamerule
}
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.world, x, z, "Cannot create explosion asynchronously"); // Folia - region threading
net.minecraft.world.entity.Entity entity = (source == null) ? null : ((CraftEntity) source).getHandle();
return !this.world.explode0(entity, Explosion.getDefaultDamageSource(this.world, entity), null, x, y, z, power, setFire, explosionType, ParticleTypes.EXPLOSION, ParticleTypes.EXPLOSION_EMITTER, SoundEvents.GENERIC_EXPLODE, configurator).wasCanceled; // Paper - expand explosion API
}
@@ -983,6 +_,7 @@
@Override
public int getHighestBlockYAt(int x, int z, org.bukkit.HeightMap heightMap) {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.world, x >> 4, z >> 4, "Cannot retrieve chunk asynchronously"); // Folia - region threading
warnUnsafeChunk("getting a faraway chunk", x >> 4, z >> 4); // Paper
// Transient load for this tick
return this.world.getChunk(x >> 4, z >> 4).getHeight(CraftHeightMap.toNMS(heightMap), x, z);
@@ -1013,6 +_,7 @@
@Override
public void setBiome(int x, int y, int z, Holder<net.minecraft.world.level.biome.Biome> bb) {
BlockPos pos = new BlockPos(x, 0, z);
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.world, pos, "Cannot retrieve chunk asynchronously"); // Folia - region threading
if (this.world.hasChunkAt(pos)) {
net.minecraft.world.level.chunk.LevelChunk chunk = this.world.getChunkAt(pos);
@@ -1323,6 +_,7 @@
@Override
public void setStorm(boolean hasStorm) {
+ io.papermc.paper.threadedregions.RegionizedServer.ensureGlobalTickThread("Cannot modify weather off of the global region"); // Folia - region threading
this.world.serverLevelData.setRaining(hasStorm, org.bukkit.event.weather.WeatherChangeEvent.Cause.PLUGIN); // Paper - Add cause to Weather/ThunderChangeEvents
this.setWeatherDuration(0); // Reset weather duration (legacy behaviour)
this.setClearWeatherDuration(0); // Reset clear weather duration (reset "/weather clear" commands)
@@ -1335,6 +_,7 @@
@Override
public void setWeatherDuration(int duration) {
+ io.papermc.paper.threadedregions.RegionizedServer.ensureGlobalTickThread("Cannot modify weather off of the global region"); // Folia - region threading
this.world.serverLevelData.setRainTime(duration);
}
@@ -1345,6 +_,7 @@
@Override
public void setThundering(boolean thundering) {
+ io.papermc.paper.threadedregions.RegionizedServer.ensureGlobalTickThread("Cannot modify weather off of the global region"); // Folia - region threading
this.world.serverLevelData.setThundering(thundering, org.bukkit.event.weather.ThunderChangeEvent.Cause.PLUGIN); // Paper - Add cause to Weather/ThunderChangeEvents
this.setThunderDuration(0); // Reset weather duration (legacy behaviour)
this.setClearWeatherDuration(0); // Reset clear weather duration (reset "/weather clear" commands)
@@ -1357,6 +_,7 @@
@Override
public void setThunderDuration(int duration) {
+ io.papermc.paper.threadedregions.RegionizedServer.ensureGlobalTickThread("Cannot modify weather off of the global region"); // Folia - region threading
this.world.serverLevelData.setThunderTime(duration);
}
@@ -1367,6 +_,7 @@
@Override
public void setClearWeatherDuration(int duration) {
+ io.papermc.paper.threadedregions.RegionizedServer.ensureGlobalTickThread("Cannot modify weather off of the global region"); // Folia - region threading
this.world.serverLevelData.setClearWeatherTime(duration);
}
@@ -1565,6 +_,7 @@
@Override
public void setKeepSpawnInMemory(boolean keepLoaded) {
+ io.papermc.paper.threadedregions.RegionizedServer.ensureGlobalTickThread("Cannot modify keep spawn in memory off of the global region"); // Folia - region threading
if (keepLoaded) {
this.setGameRule(GameRule.SPAWN_CHUNK_RADIUS, this.getGameRuleDefault(GameRule.SPAWN_CHUNK_RADIUS));
} else {
@@ -1633,6 +_,7 @@
@Override
public void setHardcore(boolean hardcore) {
+ io.papermc.paper.threadedregions.RegionizedServer.ensureGlobalTickThread("Cannot modify server settings off of the global region"); // Folia - region threading
this.world.serverLevelData.settings.hardcore = hardcore;
}
@@ -1645,6 +_,7 @@
@Override
@Deprecated
public void setTicksPerAnimalSpawns(int ticksPerAnimalSpawns) {
+ io.papermc.paper.threadedregions.RegionizedServer.ensureGlobalTickThread("Cannot modify server settings off of the global region"); // Folia - region threading
this.setTicksPerSpawns(SpawnCategory.ANIMAL, ticksPerAnimalSpawns);
}
@@ -1657,6 +_,7 @@
@Override
@Deprecated
public void setTicksPerMonsterSpawns(int ticksPerMonsterSpawns) {
+ io.papermc.paper.threadedregions.RegionizedServer.ensureGlobalTickThread("Cannot modify server settings off of the global region"); // Folia - region threading
this.setTicksPerSpawns(SpawnCategory.MONSTER, ticksPerMonsterSpawns);
}
@@ -1669,6 +_,7 @@
@Override
@Deprecated
public void setTicksPerWaterSpawns(int ticksPerWaterSpawns) {
+ io.papermc.paper.threadedregions.RegionizedServer.ensureGlobalTickThread("Cannot modify server settings off of the global region"); // Folia - region threading
this.setTicksPerSpawns(SpawnCategory.WATER_ANIMAL, ticksPerWaterSpawns);
}
@@ -1681,6 +_,7 @@
@Override
@Deprecated
public void setTicksPerWaterAmbientSpawns(int ticksPerWaterAmbientSpawns) {
+ io.papermc.paper.threadedregions.RegionizedServer.ensureGlobalTickThread("Cannot modify server settings off of the global region"); // Folia - region threading
this.setTicksPerSpawns(SpawnCategory.WATER_AMBIENT, ticksPerWaterAmbientSpawns);
}
@@ -1693,6 +_,7 @@
@Override
@Deprecated
public void setTicksPerWaterUndergroundCreatureSpawns(int ticksPerWaterUndergroundCreatureSpawns) {
+ io.papermc.paper.threadedregions.RegionizedServer.ensureGlobalTickThread("Cannot modify server settings off of the global region"); // Folia - region threading
this.setTicksPerSpawns(SpawnCategory.WATER_UNDERGROUND_CREATURE, ticksPerWaterUndergroundCreatureSpawns);
}
@@ -1705,11 +_,13 @@
@Override
@Deprecated
public void setTicksPerAmbientSpawns(int ticksPerAmbientSpawns) {
+ io.papermc.paper.threadedregions.RegionizedServer.ensureGlobalTickThread("Cannot modify server settings off of the global region"); // Folia - region threading
this.setTicksPerSpawns(SpawnCategory.AMBIENT, ticksPerAmbientSpawns);
}
@Override
public void setTicksPerSpawns(SpawnCategory spawnCategory, int ticksPerCategorySpawn) {
+ io.papermc.paper.threadedregions.RegionizedServer.ensureGlobalTickThread("Cannot modify server settings off of the global region"); // Folia - region threading
Preconditions.checkArgument(spawnCategory != null, "SpawnCategory cannot be null");
Preconditions.checkArgument(CraftSpawnCategory.isValidForLimits(spawnCategory), "SpawnCategory.%s are not supported", spawnCategory);
@@ -1726,21 +_,25 @@
@Override
public void setMetadata(String metadataKey, MetadataValue newMetadataValue) {
+ io.papermc.paper.threadedregions.RegionizedServer.ensureGlobalTickThread("Cannot modify metadata off of the global region"); // Folia - region threading
this.server.getWorldMetadata().setMetadata(this, metadataKey, newMetadataValue);
}
@Override
public List<MetadataValue> getMetadata(String metadataKey) {
+ io.papermc.paper.threadedregions.RegionizedServer.ensureGlobalTickThread("Cannot retrieve metadata off of the global region"); // Folia - region threading
return this.server.getWorldMetadata().getMetadata(this, metadataKey);
}
@Override
public boolean hasMetadata(String metadataKey) {
+ io.papermc.paper.threadedregions.RegionizedServer.ensureGlobalTickThread("Cannot retrieve metadata off of the global region"); // Folia - region threading
return this.server.getWorldMetadata().hasMetadata(this, metadataKey);
}
@Override
public void removeMetadata(String metadataKey, Plugin owningPlugin) {
+ io.papermc.paper.threadedregions.RegionizedServer.ensureGlobalTickThread("Cannot modify metadata off of the global region"); // Folia - region threading
this.server.getWorldMetadata().removeMetadata(this, metadataKey, owningPlugin);
}
@@ -1753,6 +_,7 @@
@Override
@Deprecated
public void setMonsterSpawnLimit(int limit) {
+ io.papermc.paper.threadedregions.RegionizedServer.ensureGlobalTickThread("Cannot modify server settings off of the global region"); // Folia - region threading
this.setSpawnLimit(SpawnCategory.MONSTER, limit);
}
@@ -1765,6 +_,7 @@
@Override
@Deprecated
public void setAnimalSpawnLimit(int limit) {
+ io.papermc.paper.threadedregions.RegionizedServer.ensureGlobalTickThread("Cannot modify server settings off of the global region"); // Folia - region threading
this.setSpawnLimit(SpawnCategory.ANIMAL, limit);
}
@@ -1777,6 +_,7 @@
@Override
@Deprecated
public void setWaterAnimalSpawnLimit(int limit) {
+ io.papermc.paper.threadedregions.RegionizedServer.ensureGlobalTickThread("Cannot modify server settings off of the global region"); // Folia - region threading
this.setSpawnLimit(SpawnCategory.WATER_ANIMAL, limit);
}
@@ -1789,6 +_,7 @@
@Override
@Deprecated
public void setWaterAmbientSpawnLimit(int limit) {
+ io.papermc.paper.threadedregions.RegionizedServer.ensureGlobalTickThread("Cannot modify server settings off of the global region"); // Folia - region threading
this.setSpawnLimit(SpawnCategory.WATER_AMBIENT, limit);
}
@@ -1801,6 +_,7 @@
@Override
@Deprecated
public void setWaterUndergroundCreatureSpawnLimit(int limit) {
+ io.papermc.paper.threadedregions.RegionizedServer.ensureGlobalTickThread("Cannot modify server settings off of the global region"); // Folia - region threading
this.setSpawnLimit(SpawnCategory.WATER_UNDERGROUND_CREATURE, limit);
}
@@ -1813,6 +_,7 @@
@Override
@Deprecated
public void setAmbientSpawnLimit(int limit) {
+ io.papermc.paper.threadedregions.RegionizedServer.ensureGlobalTickThread("Cannot modify server settings off of the global region"); // Folia - region threading
this.setSpawnLimit(SpawnCategory.AMBIENT, limit);
}
@@ -1835,6 +_,7 @@
@Override
public void setSpawnLimit(SpawnCategory spawnCategory, int limit) {
+ io.papermc.paper.threadedregions.RegionizedServer.ensureGlobalTickThread("Cannot modify server settings off of the global region"); // Folia - region threading
Preconditions.checkArgument(spawnCategory != null, "SpawnCategory cannot be null");
Preconditions.checkArgument(CraftSpawnCategory.isValidForLimits(spawnCategory), "SpawnCategory.%s are not supported", spawnCategory);
@@ -1917,7 +_,7 @@
if (!(entity instanceof CraftEntity craftEntity) || entity.getWorld() != this || sound == null || category == null) return;
ClientboundSoundEntityPacket packet = new ClientboundSoundEntityPacket(CraftSound.bukkitToMinecraftHolder(sound), net.minecraft.sounds.SoundSource.valueOf(category.name()), craftEntity.getHandle(), volume, pitch, seed);
- ChunkMap.TrackedEntity entityTracker = this.getHandle().getChunkSource().chunkMap.entityMap.get(entity.getEntityId());
+ ChunkMap.TrackedEntity entityTracker = ((CraftEntity) entity).getHandle().moonrise$getTrackedEntity(); // Folia - region threading
if (entityTracker != null) {
entityTracker.broadcastAndSend(packet);
}
@@ -1938,7 +_,7 @@
if (!(entity instanceof CraftEntity craftEntity) || entity.getWorld() != this || sound == null || category == null) return;
ClientboundSoundEntityPacket packet = new ClientboundSoundEntityPacket(Holder.direct(SoundEvent.createVariableRangeEvent(ResourceLocation.parse(sound))), net.minecraft.sounds.SoundSource.valueOf(category.name()), craftEntity.getHandle(), volume, pitch, seed);
- ChunkMap.TrackedEntity entityTracker = this.getHandle().getChunkSource().chunkMap.entityMap.get(entity.getEntityId());
+ ChunkMap.TrackedEntity entityTracker = ((CraftEntity)entity).getHandle().moonrise$getTrackedEntity(); // Folia - region threading
if (entityTracker != null) {
entityTracker.broadcastAndSend(packet);
}
@@ -2021,6 +_,7 @@
@Override
public boolean setGameRuleValue(String rule, String value) {
+ io.papermc.paper.threadedregions.RegionizedServer.ensureGlobalTickThread("Cannot modify server settings off of the global region"); // Folia - region threading
// No null values allowed
if (rule == null || value == null) return false;
@@ -2063,6 +_,7 @@
@Override
public <T> boolean setGameRule(GameRule<T> rule, T newValue) {
+ io.papermc.paper.threadedregions.RegionizedServer.ensureGlobalTickThread("Cannot modify server settings off of the global region"); // Folia - region threading
Preconditions.checkArgument(rule != null, "GameRule cannot be null");
Preconditions.checkArgument(newValue != null, "GameRule value cannot be null");
@@ -2290,6 +_,12 @@
@Override
public void sendGameEvent(Entity sourceEntity, org.bukkit.GameEvent gameEvent, Vector position) {
+ // Folia start - region threading
+ if (sourceEntity != null && !Bukkit.isOwnedByCurrentRegion(sourceEntity)) {
+ throw new IllegalStateException("Cannot send game event asynchronously");
+ }
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.world, position.getX(), position.getZ(), "Cannot send game event asynchronously");
+ // Folia end - region threading
getHandle().gameEvent(sourceEntity != null ? ((CraftEntity) sourceEntity).getHandle(): null, net.minecraft.core.registries.BuiltInRegistries.GAME_EVENT.get(org.bukkit.craftbukkit.util.CraftNamespacedKey.toMinecraft(gameEvent.getKey())).orElseThrow(), org.bukkit.craftbukkit.util.CraftVector.toBlockPos(position));
}
// Paper end

View File

@ -0,0 +1,201 @@
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
@@ -75,6 +_,11 @@
}
public net.minecraft.world.level.block.state.BlockState getNMS() {
+ // Folia start - region threading
+ if (this.world instanceof ServerLevel serverWorld) {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(serverWorld, this.position, "Cannot read world asynchronously");
+ }
+ // Folia end - region threading
return this.world.getBlockState(this.position);
}
@@ -157,6 +_,11 @@
}
private void setData(final byte data, int flag) {
+ // Folia start - region threading
+ if (this.world instanceof ServerLevel serverWorld) {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(serverWorld, this.position, "Cannot read world asynchronously");
+ }
+ // Folia end - region threading
this.world.setBlock(this.position, CraftMagicNumbers.getBlock(this.getType(), data), flag);
}
@@ -198,6 +_,11 @@
}
public static boolean setTypeAndData(LevelAccessor world, BlockPos position, net.minecraft.world.level.block.state.BlockState old, net.minecraft.world.level.block.state.BlockState blockData, boolean applyPhysics) {
+ // Folia start - region threading
+ if (world instanceof ServerLevel serverWorld) {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(serverWorld, position, "Cannot modify world asynchronously");
+ }
+ // Folia end - region threading
// SPIGOT-611: need to do this to prevent glitchiness. Easier to handle this here (like /setblock) than to fix weirdness in tile entity cleanup
if (old.hasBlockEntity() && blockData.getBlock() != old.getBlock()) { // SPIGOT-3725 remove old tile entity if block changes
// SPIGOT-4612: faster - just clear tile
@@ -343,18 +_,33 @@
@Override
public Biome getBiome() {
+ // Folia start - region threading
+ if (this.world instanceof ServerLevel serverWorld) {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(serverWorld, this.position, "Cannot read world asynchronously");
+ }
+ // Folia end - region threading
return this.getWorld().getBiome(this.getX(), this.getY(), this.getZ());
}
// Paper start
@Override
public Biome getComputedBiome() {
+ // Folia start - region threading
+ if (this.world instanceof ServerLevel serverWorld) {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(serverWorld, this.position, "Cannot read world asynchronously");
+ }
+ // Folia end - region threading
return this.getWorld().getComputedBiome(this.getX(), this.getY(), this.getZ());
}
// Paper end
@Override
public void setBiome(Biome bio) {
+ // Folia start - region threading
+ if (this.world instanceof ServerLevel serverWorld) {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(serverWorld, this.position, "Cannot read world asynchronously");
+ }
+ // Folia end - region threading
this.getWorld().setBiome(this.getX(), this.getY(), this.getZ(), bio);
}
@@ -402,6 +_,11 @@
@Override
public boolean isBlockFaceIndirectlyPowered(BlockFace face) {
+ // Folia start - region threading
+ if (this.world instanceof ServerLevel serverWorld) {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(serverWorld, this.position, "Cannot read world asynchronously");
+ }
+ // Folia end - region threading
int power = this.world.getMinecraftWorld().getSignal(this.position, CraftBlock.blockFaceToNotch(face));
Block relative = this.getRelative(face);
@@ -414,6 +_,11 @@
@Override
public int getBlockPower(BlockFace face) {
+ // Folia start - region threading
+ if (this.world instanceof ServerLevel serverWorld) {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(serverWorld, this.position, "Cannot read world asynchronously");
+ }
+ // Folia end - region threading
int power = 0;
net.minecraft.world.level.Level world = this.world.getMinecraftWorld();
int x = this.getX();
@@ -500,6 +_,11 @@
@Override
public boolean breakNaturally(ItemStack item, boolean triggerEffect, boolean dropExperience) {
+ // Folia start - region threading
+ if (this.world instanceof ServerLevel serverWorld) {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(serverWorld, this.position, "Cannot read world asynchronously");
+ }
+ // Folia end - region threading
// Paper end
// Order matters here, need to drop before setting to air so skulls can get their data
net.minecraft.world.level.block.state.BlockState iblockdata = this.getNMS();
@@ -543,21 +_,27 @@
@Override
public boolean applyBoneMeal(BlockFace face) {
+ // Folia start - region threading
+ if (this.world instanceof ServerLevel serverWorld) {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(serverWorld, this.position, "Cannot read world asynchronously");
+ }
+ // Folia end - region threading
Direction direction = CraftBlock.blockFaceToNotch(face);
BlockFertilizeEvent event = null;
ServerLevel world = this.getCraftWorld().getHandle();
UseOnContext context = new UseOnContext(world, null, InteractionHand.MAIN_HAND, Items.BONE_MEAL.getDefaultInstance(), new BlockHitResult(Vec3.ZERO, direction, this.getPosition(), false));
+ io.papermc.paper.threadedregions.RegionizedWorldData worldData = world.getCurrentWorldData(); // Folia - region threading
// SPIGOT-6895: Call StructureGrowEvent and BlockFertilizeEvent
- world.captureTreeGeneration = true;
+ worldData.captureTreeGeneration = true; // Folia - region threading
InteractionResult result = BoneMealItem.applyBonemeal(context);
- world.captureTreeGeneration = false;
+ worldData.captureTreeGeneration = false; // Folia - region threading
- if (world.capturedBlockStates.size() > 0) {
- TreeType treeType = SaplingBlock.treeType;
- SaplingBlock.treeType = null;
- List<BlockState> blocks = new ArrayList<>(world.capturedBlockStates.values());
- world.capturedBlockStates.clear();
+ if (worldData.capturedBlockStates.size() > 0) { // Folia - region threading
+ TreeType treeType = SaplingBlock.treeTypeRT.get(); // Folia - region threading
+ SaplingBlock.treeTypeRT.set(null); // Folia - region threading
+ List<BlockState> blocks = new ArrayList<>(worldData.capturedBlockStates.values()); // Folia - region threading
+ worldData.capturedBlockStates.clear(); // Folia - region threading
StructureGrowEvent structureEvent = null;
if (treeType != null) {
@@ -644,6 +_,11 @@
@Override
public RayTraceResult rayTrace(Location start, Vector direction, double maxDistance, FluidCollisionMode fluidCollisionMode) {
+ // Folia start - region threading
+ if (this.world instanceof ServerLevel serverWorld) {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(serverWorld, this.position, "Cannot read world asynchronously");
+ }
+ // Folia end - region threading
Preconditions.checkArgument(start != null, "Location start cannot be null");
Preconditions.checkArgument(this.getWorld().equals(start.getWorld()), "Location start cannot be a different world");
start.checkFinite();
@@ -685,6 +_,11 @@
@Override
public boolean canPlace(BlockData data) {
+ // Folia start - region threading
+ if (this.world instanceof ServerLevel serverWorld) {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(serverWorld, this.position, "Cannot read world asynchronously");
+ }
+ // Folia end - region threading
Preconditions.checkArgument(data != null, "BlockData cannot be null");
net.minecraft.world.level.block.state.BlockState iblockdata = ((CraftBlockData) data).getState();
net.minecraft.world.level.Level world = this.world.getMinecraftWorld();
@@ -719,18 +_,32 @@
@Override
public void tick() {
+ // Folia start - region threading
+ if (this.world instanceof ServerLevel serverWorld) {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(serverWorld, this.position, "Cannot read world asynchronously");
+ }
+ // Folia end - region threading
final ServerLevel level = this.world.getMinecraftWorld();
this.getNMS().tick(level, this.position, level.random);
}
-
@Override
public void fluidTick() {
+ // Folia start - region threading
+ if (this.world instanceof ServerLevel serverWorld) {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(serverWorld, this.position, "Cannot read world asynchronously");
+ }
+ // Folia end - region threading
this.getNMSFluid().tick(this.world.getMinecraftWorld(), this.position, this.getNMS());
}
@Override
public void randomTick() {
+ // Folia start - region threading
+ if (this.world instanceof ServerLevel serverWorld) {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(serverWorld, this.position, "Cannot read world asynchronously");
+ }
+ // Folia end - region threading
final ServerLevel level = this.world.getMinecraftWorld();
this.getNMS().randomTick(level, this.position, level.random);
}

View File

@ -0,0 +1,22 @@
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java
@@ -25,7 +_,7 @@
private final T tileEntity;
private final T snapshot;
public boolean snapshotDisabled; // Paper
- public static boolean DISABLE_SNAPSHOT = false; // Paper
+ public static final ThreadLocal<Boolean> DISABLE_SNAPSHOT = ThreadLocal.withInitial(() -> Boolean.FALSE); // Paper // Folia - region threading
public CraftBlockEntityState(World world, T tileEntity) {
super(world, tileEntity.getBlockPos(), tileEntity.getBlockState());
@@ -34,8 +_,8 @@
try { // Paper - Show blockstate location if we failed to read it
// Paper start
- this.snapshotDisabled = DISABLE_SNAPSHOT;
- if (DISABLE_SNAPSHOT) {
+ this.snapshotDisabled = DISABLE_SNAPSHOT.get().booleanValue(); // Folia - region threading
+ if (this.snapshotDisabled) { // Folia - region threading
this.snapshot = this.tileEntity;
} else {
this.snapshot = this.createSnapshot(tileEntity);

View File

@ -0,0 +1,25 @@
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java
@@ -215,6 +_,12 @@
LevelAccessor access = this.getWorldHandle();
CraftBlock block = this.getBlock();
+ // Folia start - region threading
+ if (access instanceof net.minecraft.server.level.ServerLevel serverWorld) {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(serverWorld, position, "Cannot modify world asynchronously");
+ }
+ // Folia end - region threading
+
if (block.getType() != this.getType()) {
if (!force) {
return false;
@@ -350,6 +_,9 @@
@Override
public java.util.Collection<org.bukkit.inventory.ItemStack> getDrops(org.bukkit.inventory.ItemStack item, org.bukkit.entity.Entity entity) {
+ // Folia start - region threading
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(world.getHandle(), position, "Cannot modify world asynchronously");
+ // Folia end - region threading
this.requirePlaced();
net.minecraft.world.item.ItemStack nms = org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(item);

View File

@ -0,0 +1,22 @@
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockStates.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockStates.java
@@ -249,8 +_,8 @@
net.minecraft.world.level.block.state.BlockState blockData = craftBlock.getNMS();
BlockEntity tileEntity = craftBlock.getHandle().getBlockEntity(blockPosition);
// Paper start - block state snapshots
- boolean prev = CraftBlockEntityState.DISABLE_SNAPSHOT;
- CraftBlockEntityState.DISABLE_SNAPSHOT = !useSnapshot;
+ boolean prev = CraftBlockEntityState.DISABLE_SNAPSHOT.get().booleanValue(); // Folia - region threading
+ CraftBlockEntityState.DISABLE_SNAPSHOT.set(Boolean.valueOf(!useSnapshot)); // Folia - region threading
try {
// Paper end
CraftBlockState blockState = CraftBlockStates.getBlockState(world, blockPosition, blockData, tileEntity);
@@ -258,7 +_,7 @@
return blockState;
// Paper start
} finally {
- CraftBlockEntityState.DISABLE_SNAPSHOT = prev;
+ CraftBlockEntityState.DISABLE_SNAPSHOT.set(Boolean.valueOf(prev)); // Folia - region threading
}
// Paper end
}

View File

@ -0,0 +1,20 @@
--- a/src/main/java/org/bukkit/craftbukkit/command/ConsoleCommandCompleter.java
+++ b/src/main/java/org/bukkit/craftbukkit/command/ConsoleCommandCompleter.java
@@ -50,7 +_,7 @@
return syncEvent.callEvent() ? syncEvent.getCompletions() : com.google.common.collect.ImmutableList.of();
}
};
- server.getServer().processQueue.add(syncCompletions);
+ io.papermc.paper.threadedregions.RegionizedServer.getInstance().addTask(syncCompletions); // Folia - region threading
try {
final List<String> legacyCompletions = syncCompletions.get();
completions.removeIf(it -> !legacyCompletions.contains(it.suggestion())); // remove any suggestions that were removed
@@ -98,7 +_,7 @@
return tabEvent.isCancelled() ? Collections.EMPTY_LIST : tabEvent.getCompletions();
}
};
- server.getServer().processQueue.add(waitable); // Paper - Remove "this."
+ io.papermc.paper.threadedregions.RegionizedServer.getInstance().addTask(waitable); // Folia - region threading
try {
List<String> offers = waitable.get();
if (offers == null) {

View File

@ -0,0 +1,31 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/AbstractProjectile.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/AbstractProjectile.java
@@ -1,5 +_,6 @@
package org.bukkit.craftbukkit.entity;
+import net.minecraft.world.entity.Entity;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.Projectile;
@@ -38,6 +_,13 @@
this.getHandle().hasBeenShot = beenShot;
}
+ // Folia start - region threading
+ @Override
+ public net.minecraft.world.entity.projectile.Projectile getHandleRaw() {
+ return (net.minecraft.world.entity.projectile.Projectile)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public boolean canHitEntity(org.bukkit.entity.Entity entity) {
return this.getHandle().canHitEntityPublic(((CraftEntity) entity).getHandle());
@@ -55,6 +_,7 @@
@Override
public net.minecraft.world.entity.projectile.Projectile getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (net.minecraft.world.entity.projectile.Projectile) entity;
}

View File

@ -0,0 +1,10 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftAbstractArrow.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftAbstractArrow.java
@@ -133,6 +_,7 @@
@Override
public net.minecraft.world.entity.projectile.AbstractArrow getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (net.minecraft.world.entity.projectile.AbstractArrow) this.entity;
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftAbstractHorse.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftAbstractHorse.java
@@ -17,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public net.minecraft.world.entity.animal.horse.AbstractHorse getHandleRaw() {
+ return (net.minecraft.world.entity.animal.horse.AbstractHorse)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public net.minecraft.world.entity.animal.horse.AbstractHorse getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (net.minecraft.world.entity.animal.horse.AbstractHorse) this.entity;
}

View File

@ -0,0 +1,20 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftAbstractSkeleton.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftAbstractSkeleton.java
@@ -15,8 +_,17 @@
throw new UnsupportedOperationException("Not supported.");
}
// Paper start
+
+ // Folia start - region threading
+ @Override
+ public net.minecraft.world.entity.monster.AbstractSkeleton getHandleRaw() {
+ return (net.minecraft.world.entity.monster.AbstractSkeleton)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public net.minecraft.world.entity.monster.AbstractSkeleton getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (net.minecraft.world.entity.monster.AbstractSkeleton) super.getHandle();
}
// Paper end

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftAbstractVillager.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftAbstractVillager.java
@@ -15,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public net.minecraft.world.entity.npc.AbstractVillager getHandleRaw() {
+ return (net.minecraft.world.entity.npc.AbstractVillager)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public net.minecraft.world.entity.npc.AbstractVillager getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (Villager) this.entity;
}

View File

@ -0,0 +1,10 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftAbstractWindCharge.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftAbstractWindCharge.java
@@ -17,6 +_,7 @@
@Override
public net.minecraft.world.entity.projectile.windcharge.AbstractWindCharge getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (net.minecraft.world.entity.projectile.windcharge.AbstractWindCharge) this.entity;
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftAgeable.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftAgeable.java
@@ -63,8 +_,16 @@
}
}
+ // Folia start - region threading
+ @Override
+ public AgeableMob getHandleRaw() {
+ return (AgeableMob)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public AgeableMob getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (AgeableMob) this.entity;
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftAllay.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftAllay.java
@@ -16,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public Allay getHandleRaw() {
+ return (Allay)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public Allay getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (Allay) this.entity;
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftAmbient.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftAmbient.java
@@ -9,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public AmbientCreature getHandleRaw() {
+ return (AmbientCreature)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public AmbientCreature getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (AmbientCreature) this.entity;
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftAnimals.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftAnimals.java
@@ -15,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public Animal getHandleRaw() {
+ return (Animal)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public Animal getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (Animal) this.entity;
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftAreaEffectCloud.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftAreaEffectCloud.java
@@ -28,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public net.minecraft.world.entity.AreaEffectCloud getHandleRaw() {
+ return (net.minecraft.world.entity.AreaEffectCloud)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public net.minecraft.world.entity.AreaEffectCloud getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (net.minecraft.world.entity.AreaEffectCloud) super.getHandle();
}

View File

@ -0,0 +1,10 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftArmadillo.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftArmadillo.java
@@ -11,6 +_,7 @@
@Override
public net.minecraft.world.entity.animal.armadillo.Armadillo getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (net.minecraft.world.entity.animal.armadillo.Armadillo) super.getHandle();
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftArmorStand.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftArmorStand.java
@@ -20,8 +_,16 @@
return "CraftArmorStand";
}
+ // Folia start - region threading
+ @Override
+ public net.minecraft.world.entity.decoration.ArmorStand getHandleRaw() {
+ return (net.minecraft.world.entity.decoration.ArmorStand)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public net.minecraft.world.entity.decoration.ArmorStand getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (net.minecraft.world.entity.decoration.ArmorStand) super.getHandle();
}

View File

@ -0,0 +1,24 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftArrow.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftArrow.java
@@ -26,6 +_,7 @@
@Override
public net.minecraft.world.entity.projectile.Arrow getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (net.minecraft.world.entity.projectile.Arrow) this.entity;
}
@@ -89,6 +_,13 @@
this.getHandle().setPotionContents(new PotionContents(old.potion(), old.customColor(), old.customEffects().stream().filter((mobEffect) -> !mobEffect.getEffect().equals(minecraft)).toList(), old.customName()));
return true;
}
+
+ // Folia start - region threading
+ @Override
+ public net.minecraft.world.entity.projectile.AbstractArrow getHandleRaw() {
+ return (net.minecraft.world.entity.projectile.AbstractArrow)this.entity;
+ }
+ // Folia end - region threading
@Override
public void setBasePotionData(PotionData data) {

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftAxolotl.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftAxolotl.java
@@ -10,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public net.minecraft.world.entity.animal.axolotl.Axolotl getHandleRaw() {
+ return (net.minecraft.world.entity.animal.axolotl.Axolotl)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public net.minecraft.world.entity.animal.axolotl.Axolotl getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (net.minecraft.world.entity.animal.axolotl.Axolotl) super.getHandle();
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftBat.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftBat.java
@@ -8,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public net.minecraft.world.entity.ambient.Bat getHandleRaw() {
+ return (net.minecraft.world.entity.ambient.Bat)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public net.minecraft.world.entity.ambient.Bat getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (net.minecraft.world.entity.ambient.Bat) this.entity;
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftBee.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftBee.java
@@ -13,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public net.minecraft.world.entity.animal.Bee getHandleRaw() {
+ return (net.minecraft.world.entity.animal.Bee)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public net.minecraft.world.entity.animal.Bee getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (net.minecraft.world.entity.animal.Bee) this.entity;
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftBlaze.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftBlaze.java
@@ -8,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public net.minecraft.world.entity.monster.Blaze getHandleRaw() {
+ return (net.minecraft.world.entity.monster.Blaze)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public net.minecraft.world.entity.monster.Blaze getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (net.minecraft.world.entity.monster.Blaze) this.entity;
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftBlockAttachedEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftBlockAttachedEntity.java
@@ -8,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public BlockAttachedEntity getHandleRaw() {
+ return (BlockAttachedEntity)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public BlockAttachedEntity getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (BlockAttachedEntity) this.entity;
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftBlockDisplay.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftBlockDisplay.java
@@ -12,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public net.minecraft.world.entity.Display.BlockDisplay getHandleRaw() {
+ return (net.minecraft.world.entity.Display.BlockDisplay)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public net.minecraft.world.entity.Display.BlockDisplay getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (net.minecraft.world.entity.Display.BlockDisplay) super.getHandle();
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftBoat.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftBoat.java
@@ -101,8 +_,16 @@
return CraftBoat.boatStatusFromNms(this.getHandle().status);
}
+ // Folia start - region threading
+ @Override
+ public AbstractBoat getHandleRaw() {
+ return (AbstractBoat)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public AbstractBoat getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (AbstractBoat) this.entity;
}

View File

@ -0,0 +1,10 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftBogged.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftBogged.java
@@ -12,6 +_,7 @@
@Override
public net.minecraft.world.entity.monster.Bogged getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (net.minecraft.world.entity.monster.Bogged) this.entity;
}

View File

@ -0,0 +1,10 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftBreeze.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftBreeze.java
@@ -13,6 +_,7 @@
@Override
public net.minecraft.world.entity.monster.breeze.Breeze getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (net.minecraft.world.entity.monster.breeze.Breeze) this.entity;
}

View File

@ -0,0 +1,10 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftBreezeWindCharge.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftBreezeWindCharge.java
@@ -10,6 +_,7 @@
@Override
public net.minecraft.world.entity.projectile.windcharge.BreezeWindCharge getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (net.minecraft.world.entity.projectile.windcharge.BreezeWindCharge) this.entity;
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftCamel.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftCamel.java
@@ -11,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public net.minecraft.world.entity.animal.camel.Camel getHandleRaw() {
+ return (net.minecraft.world.entity.animal.camel.Camel)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public net.minecraft.world.entity.animal.camel.Camel getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (net.minecraft.world.entity.animal.camel.Camel) super.getHandle();
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftCat.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftCat.java
@@ -19,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public net.minecraft.world.entity.animal.Cat getHandleRaw() {
+ return (net.minecraft.world.entity.animal.Cat)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public net.minecraft.world.entity.animal.Cat getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (net.minecraft.world.entity.animal.Cat) super.getHandle();
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftCaveSpider.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftCaveSpider.java
@@ -8,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public net.minecraft.world.entity.monster.CaveSpider getHandleRaw() {
+ return (net.minecraft.world.entity.monster.CaveSpider)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public net.minecraft.world.entity.monster.CaveSpider getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (net.minecraft.world.entity.monster.CaveSpider) this.entity;
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftChestBoat.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftChestBoat.java
@@ -15,8 +_,16 @@
this.inventory = new CraftInventory(entity);
}
+ // Folia start - region threading
+ @Override
+ public AbstractChestBoat getHandleRaw() {
+ return (AbstractChestBoat)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public AbstractChestBoat getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (AbstractChestBoat) this.entity;
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftChestedHorse.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftChestedHorse.java
@@ -10,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public AbstractChestedHorse getHandleRaw() {
+ return (AbstractChestedHorse)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public AbstractChestedHorse getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (AbstractChestedHorse) super.getHandle();
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftChicken.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftChicken.java
@@ -9,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public net.minecraft.world.entity.animal.Chicken getHandleRaw() {
+ return (net.minecraft.world.entity.animal.Chicken)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public net.minecraft.world.entity.animal.Chicken getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (net.minecraft.world.entity.animal.Chicken) this.entity;
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftCod.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftCod.java
@@ -9,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public net.minecraft.world.entity.animal.Cod getHandleRaw() {
+ return (net.minecraft.world.entity.animal.Cod)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public net.minecraft.world.entity.animal.Cod getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (net.minecraft.world.entity.animal.Cod) super.getHandle();
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftComplexPart.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftComplexPart.java
@@ -32,8 +_,16 @@
return this.getParent().isValid();
}
+ // Folia start - region threading
+ @Override
+ public EnderDragonPart getHandleRaw() {
+ return (EnderDragonPart)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public EnderDragonPart getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (EnderDragonPart) this.entity;
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftCow.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftCow.java
@@ -9,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public net.minecraft.world.entity.animal.Cow getHandleRaw() {
+ return (net.minecraft.world.entity.animal.Cow)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public net.minecraft.world.entity.animal.Cow getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (net.minecraft.world.entity.animal.Cow) this.entity;
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftCreaking.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftCreaking.java
@@ -9,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public Creaking getHandleRaw() {
+ return (Creaking)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public Creaking getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (Creaking) this.entity;
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftCreature.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftCreature.java
@@ -9,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public PathfinderMob getHandleRaw() {
+ return (PathfinderMob)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public PathfinderMob getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (PathfinderMob) this.entity;
}

View File

@ -0,0 +1,24 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftCreeper.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftCreeper.java
@@ -87,6 +_,13 @@
this.getHandle().ignite();
}
+ // Folia start - region threading
+ @Override
+ public net.minecraft.world.entity.monster.Creeper getHandleRaw() {
+ return (net.minecraft.world.entity.monster.Creeper)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public Entity getIgniter() {
return (this.getHandle().entityIgniter != null) ? this.getHandle().entityIgniter.getBukkitEntity() : null;
@@ -94,6 +_,7 @@
@Override
public net.minecraft.world.entity.monster.Creeper getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (net.minecraft.world.entity.monster.Creeper) this.entity;
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftDisplay.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftDisplay.java
@@ -12,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public net.minecraft.world.entity.Display getHandleRaw() {
+ return (net.minecraft.world.entity.Display)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public net.minecraft.world.entity.Display getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (net.minecraft.world.entity.Display) super.getHandle();
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftDolphin.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftDolphin.java
@@ -9,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public net.minecraft.world.entity.animal.Dolphin getHandleRaw() {
+ return (net.minecraft.world.entity.animal.Dolphin)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public net.minecraft.world.entity.animal.Dolphin getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (net.minecraft.world.entity.animal.Dolphin) super.getHandle();
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftDrowned.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftDrowned.java
@@ -9,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public net.minecraft.world.entity.monster.Drowned getHandleRaw() {
+ return (net.minecraft.world.entity.monster.Drowned)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public net.minecraft.world.entity.monster.Drowned getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (net.minecraft.world.entity.monster.Drowned) this.entity;
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEgg.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEgg.java
@@ -9,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public ThrownEgg getHandleRaw() {
+ return (ThrownEgg)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public ThrownEgg getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (ThrownEgg) this.entity;
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEnderCrystal.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEnderCrystal.java
@@ -39,8 +_,16 @@
}
}
+ // Folia start - region threading
+ @Override
+ public EndCrystal getHandleRaw() {
+ return (EndCrystal)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public EndCrystal getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (EndCrystal) this.entity;
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEnderDragon.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEnderDragon.java
@@ -30,8 +_,16 @@
return builder.build();
}
+ // Folia start - region threading
+ @Override
+ public net.minecraft.world.entity.boss.enderdragon.EnderDragon getHandleRaw() {
+ return (net.minecraft.world.entity.boss.enderdragon.EnderDragon)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public net.minecraft.world.entity.boss.enderdragon.EnderDragon getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (net.minecraft.world.entity.boss.enderdragon.EnderDragon) this.entity;
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEnderDragonPart.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEnderDragonPart.java
@@ -16,8 +_,16 @@
return (EnderDragon) super.getParent();
}
+ // Folia start - region threading
+ @Override
+ public net.minecraft.world.entity.boss.EnderDragonPart getHandleRaw() {
+ return (net.minecraft.world.entity.boss.EnderDragonPart)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public net.minecraft.world.entity.boss.EnderDragonPart getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (net.minecraft.world.entity.boss.EnderDragonPart) this.entity;
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEnderPearl.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEnderPearl.java
@@ -9,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public ThrownEnderpearl getHandleRaw() {
+ return (ThrownEnderpearl)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public ThrownEnderpearl getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (ThrownEnderpearl) this.entity;
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEnderSignal.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEnderSignal.java
@@ -15,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public EyeOfEnder getHandleRaw() {
+ return (EyeOfEnder)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public EyeOfEnder getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (EyeOfEnder) this.entity;
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEnderman.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEnderman.java
@@ -62,8 +_,16 @@
}
// Paper end
+ // Folia start - region threading
+ @Override
+ public EnderMan getHandleRaw() {
+ return (EnderMan)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public EnderMan getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (EnderMan) this.entity;
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEndermite.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEndermite.java
@@ -9,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public net.minecraft.world.entity.monster.Endermite getHandleRaw() {
+ return (net.minecraft.world.entity.monster.Endermite)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public net.minecraft.world.entity.monster.Endermite getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (net.minecraft.world.entity.monster.Endermite) super.getHandle();
}

View File

@ -0,0 +1,134 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
@@ -82,6 +_,11 @@
return this.apiScheduler;
};
// Paper end - Folia schedulers
+ // Folia start - region threading
+ public boolean isPurged() {
+ return this.taskScheduler.isRetired();
+ }
+ // Folia end - region threading
public CraftEntity(final CraftServer server, final Entity entity) {
this.server = server;
@@ -239,6 +_,11 @@
@Override
public boolean teleport(Location location, TeleportCause cause, io.papermc.paper.entity.TeleportFlag... flags) {
+ // Folia start - region threading
+ if (true) {
+ throw new UnsupportedOperationException("Must use teleportAsync while in region threading");
+ }
+ // Folia end - region threading
// Paper end
Preconditions.checkArgument(location != null, "location cannot be null");
location.checkFinite();
@@ -528,6 +_,7 @@
}
public Entity getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return this.entity;
}
@@ -722,7 +_,7 @@
ImmutableSet.Builder<Player> players = ImmutableSet.builder();
ServerLevel world = ((CraftWorld) this.getWorld()).getHandle();
- ChunkMap.TrackedEntity entityTracker = world.getChunkSource().chunkMap.entityMap.get(this.getEntityId());
+ ChunkMap.TrackedEntity entityTracker = this.getHandle().moonrise$getTrackedEntity(); // Folia - region threading
if (entityTracker != null) {
for (ServerPlayerConnection connection : entityTracker.seenBy) {
@@ -1026,7 +_,7 @@
}
ServerLevel world = ((CraftWorld) this.getWorld()).getHandle();
- ChunkMap.TrackedEntity entityTracker = world.getChunkSource().chunkMap.entityMap.get(this.getEntityId());
+ ChunkMap.TrackedEntity entityTracker = this.getHandle().moonrise$getTrackedEntity(); // Folia - region threading
if (entityTracker == null) {
return;
@@ -1045,7 +_,7 @@
}
ServerLevel world = ((CraftWorld) this.getWorld()).getHandle();
- ChunkMap.TrackedEntity entityTracker = world.getChunkSource().chunkMap.entityMap.get(this.getEntityId());
+ ChunkMap.TrackedEntity entityTracker = this.entity.moonrise$getTrackedEntity(); // Folia - region threading
if (entityTracker == null) {
return;
@@ -1079,29 +_,43 @@
location.checkFinite();
Location locationClone = location.clone(); // clone so we don't need to worry about mutations after this call.
- net.minecraft.server.level.ServerLevel world = ((CraftWorld)locationClone.getWorld()).getHandle();
+ // Folia start - region threading
java.util.concurrent.CompletableFuture<Boolean> ret = new java.util.concurrent.CompletableFuture<>();
+ java.util.function.Consumer<Entity> run = (Entity nmsEntity) -> {
+ boolean success = nmsEntity.teleportAsync(
+ ((CraftWorld)locationClone.getWorld()).getHandle(),
+ new net.minecraft.world.phys.Vec3(locationClone.getX(), locationClone.getY(), locationClone.getZ()),
+ locationClone.getYaw(), locationClone.getPitch(), net.minecraft.world.phys.Vec3.ZERO,
+ cause == null ? TeleportCause.UNKNOWN : cause,
+ Entity.TELEPORT_FLAG_LOAD_CHUNK | Entity.TELEPORT_FLAG_TELEPORT_PASSENGERS, // preserve behavior with old API: dismount the entity so it can teleport
+ (Entity entityTp) -> {
+ ret.complete(Boolean.TRUE);
+ }
+ );
+ if (!success) {
+ ret.complete(Boolean.FALSE);
+ }
+ };
+ if (org.bukkit.Bukkit.isOwnedByCurrentRegion(this)) {
+ run.accept(this.getHandle());
+ return ret;
+ }
+ boolean scheduled = this.taskScheduler.schedule(
+ // success
+ run,
+ // retired
+ (Entity nmsEntity) -> {
+ ret.complete(Boolean.FALSE);
+ },
+ 1L
+ );
- world.loadChunksForMoveAsync(getHandle().getBoundingBoxAt(locationClone.getX(), locationClone.getY(), locationClone.getZ()),
- this instanceof CraftPlayer ? ca.spottedleaf.concurrentutil.util.Priority.HIGHER : ca.spottedleaf.concurrentutil.util.Priority.NORMAL, (list) -> {
- net.minecraft.server.MinecraftServer.getServer().scheduleOnMain(() -> {
- final net.minecraft.server.level.ServerChunkCache chunkCache = world.getChunkSource();
- for (final net.minecraft.world.level.chunk.ChunkAccess chunk : list) {
- chunkCache.addTicketAtLevel(net.minecraft.server.level.TicketType.POST_TELEPORT, chunk.getPos(), 33, CraftEntity.this.getEntityId());
- }
- try {
- ret.complete(CraftEntity.this.teleport(locationClone, cause, teleportFlags) ? Boolean.TRUE : Boolean.FALSE);
- } catch (Throwable throwable) {
- if (throwable instanceof ThreadDeath) {
- throw (ThreadDeath)throwable;
- }
- net.minecraft.server.MinecraftServer.LOGGER.error("Failed to teleport entity " + CraftEntity.this, throwable);
- ret.completeExceptionally(throwable);
- }
- });
- });
+ if (!scheduled) {
+ ret.complete(Boolean.FALSE);
+ }
return ret;
+ // Folia end - region threading
}
// Paper end - more teleport API / async chunk API
@@ -1214,8 +_,7 @@
// Paper start - tracked players API
@Override
public Set<org.bukkit.entity.Player> getTrackedPlayers() {
- ServerLevel world = (net.minecraft.server.level.ServerLevel)this.entity.level();
- ChunkMap.TrackedEntity tracker = world == null ? null : world.getChunkSource().chunkMap.entityMap.get(this.entity.getId());
+ ChunkMap.TrackedEntity tracker = this.entity.moonrise$getTrackedEntity(); // Folia - region threading
if (tracker == null) {
return java.util.Collections.emptySet();
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEvoker.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEvoker.java
@@ -11,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public net.minecraft.world.entity.monster.Evoker getHandleRaw() {
+ return (net.minecraft.world.entity.monster.Evoker)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public net.minecraft.world.entity.monster.Evoker getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (net.minecraft.world.entity.monster.Evoker) super.getHandle();
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEvokerFangs.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEvokerFangs.java
@@ -11,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public net.minecraft.world.entity.projectile.EvokerFangs getHandleRaw() {
+ return (net.minecraft.world.entity.projectile.EvokerFangs)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public net.minecraft.world.entity.projectile.EvokerFangs getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (net.minecraft.world.entity.projectile.EvokerFangs) super.getHandle();
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftExperienceOrb.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftExperienceOrb.java
@@ -42,8 +_,16 @@
}
// Paper end
+ // Folia start - region threading
+ @Override
+ public net.minecraft.world.entity.ExperienceOrb getHandleRaw() {
+ return (net.minecraft.world.entity.ExperienceOrb)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public net.minecraft.world.entity.ExperienceOrb getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (net.minecraft.world.entity.ExperienceOrb) this.entity;
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftFallingBlock.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftFallingBlock.java
@@ -14,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public FallingBlockEntity getHandleRaw() {
+ return (FallingBlockEntity)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public FallingBlockEntity getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (FallingBlockEntity) this.entity;
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftFireball.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftFireball.java
@@ -83,8 +_,16 @@
}
// Paper end - Expose power on fireball projectiles
+ // Folia start - region threading
+ @Override
+ public AbstractHurtingProjectile getHandleRaw() {
+ return (AbstractHurtingProjectile)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public AbstractHurtingProjectile getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (AbstractHurtingProjectile) this.entity;
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftFirework.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftFirework.java
@@ -37,8 +_,16 @@
// Paper end - Expose firework item directly
}
+ // Folia start - region threading
+ @Override
+ public FireworkRocketEntity getHandleRaw() {
+ return (FireworkRocketEntity)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public FireworkRocketEntity getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (FireworkRocketEntity) this.entity;
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftFish.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftFish.java
@@ -10,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public AbstractFish getHandleRaw() {
+ return (AbstractFish)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public AbstractFish getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (AbstractFish) this.entity;
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftFishHook.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftFishHook.java
@@ -14,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public FishingHook getHandleRaw() {
+ return (FishingHook)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public FishingHook getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (FishingHook) this.entity;
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftFlying.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftFlying.java
@@ -10,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public FlyingMob getHandleRaw() {
+ return (FlyingMob)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public FlyingMob getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (FlyingMob) this.entity;
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftFox.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftFox.java
@@ -14,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public net.minecraft.world.entity.animal.Fox getHandleRaw() {
+ return (net.minecraft.world.entity.animal.Fox)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public net.minecraft.world.entity.animal.Fox getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (net.minecraft.world.entity.animal.Fox) super.getHandle();
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftFrog.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftFrog.java
@@ -19,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public Frog getHandleRaw() {
+ return (Frog)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public Frog getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (Frog) this.entity;
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftGhast.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftGhast.java
@@ -9,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public net.minecraft.world.entity.monster.Ghast getHandleRaw() {
+ return (net.minecraft.world.entity.monster.Ghast)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public net.minecraft.world.entity.monster.Ghast getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (net.minecraft.world.entity.monster.Ghast) this.entity;
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftGiant.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftGiant.java
@@ -9,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public net.minecraft.world.entity.monster.Giant getHandleRaw() {
+ return (net.minecraft.world.entity.monster.Giant)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public net.minecraft.world.entity.monster.Giant getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (net.minecraft.world.entity.monster.Giant) this.entity;
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftGlowItemFrame.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftGlowItemFrame.java
@@ -9,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public net.minecraft.world.entity.decoration.GlowItemFrame getHandleRaw() {
+ return (net.minecraft.world.entity.decoration.GlowItemFrame)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public net.minecraft.world.entity.decoration.GlowItemFrame getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (net.minecraft.world.entity.decoration.GlowItemFrame) super.getHandle();
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftGlowSquid.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftGlowSquid.java
@@ -10,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public net.minecraft.world.entity.GlowSquid getHandleRaw() {
+ return (net.minecraft.world.entity.GlowSquid)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public net.minecraft.world.entity.GlowSquid getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (net.minecraft.world.entity.GlowSquid) super.getHandle();
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftGoat.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftGoat.java
@@ -9,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public net.minecraft.world.entity.animal.goat.Goat getHandleRaw() {
+ return (net.minecraft.world.entity.animal.goat.Goat)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public net.minecraft.world.entity.animal.goat.Goat getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (net.minecraft.world.entity.animal.goat.Goat) super.getHandle();
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftGolem.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftGolem.java
@@ -9,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public AbstractGolem getHandleRaw() {
+ return (AbstractGolem)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public AbstractGolem getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (AbstractGolem) this.entity;
}

View File

@ -0,0 +1,19 @@
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftGuardian.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftGuardian.java
@@ -13,8 +_,16 @@
super(server, entity);
}
+ // Folia start - region threading
+ @Override
+ public net.minecraft.world.entity.monster.Guardian getHandleRaw() {
+ return (net.minecraft.world.entity.monster.Guardian)this.entity;
+ }
+ // Folia end - region threading
+
@Override
public net.minecraft.world.entity.monster.Guardian getHandle() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading
return (net.minecraft.world.entity.monster.Guardian) super.getHandle();
}

Some files were not shown because too many files have changed in this diff Show More