Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Allow to use plotsquared with Paper-Folia #4009

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6305db8
Use folia api against paper api
TheMeinerLP Apr 5, 2023
1ddeec6
Implement run paper for folia
TheMeinerLP Apr 5, 2023
f5c606f
Add folia support class
TheMeinerLP Apr 5, 2023
6727d85
Add specialized folia task manager
TheMeinerLP Apr 5, 2023
c6bab2a
Enable folia support
TheMeinerLP Apr 5, 2023
accce89
Add snapshot support for run paper
TheMeinerLP Apr 5, 2023
dcb11e1
Implement folia support
TheMeinerLP Apr 5, 2023
19cde40
Extend git ignore
TheMeinerLP Apr 5, 2023
0e0b4e2
Exclude 1.20 biome for 1.19
TheMeinerLP Apr 5, 2023
c31aea7
Check if world creation folia api
TheMeinerLP Apr 5, 2023
129859e
Fix command processing for folia servers
TheMeinerLP Jun 5, 2023
fe47580
Fix chunk coordinator for folia
TheMeinerLP Jun 5, 2023
654c48e
Remove unused code
TheMeinerLP Jun 5, 2023
3138d67
Use folia api against paper api
TheMeinerLP Apr 5, 2023
c09d842
Implement run paper for folia
TheMeinerLP Apr 5, 2023
402805d
Add folia support class
TheMeinerLP Apr 5, 2023
e104e0f
Add specialized folia task manager
TheMeinerLP Apr 5, 2023
1fa9d0c
Enable folia support
TheMeinerLP Apr 5, 2023
43d71fe
Add snapshot support for run paper
TheMeinerLP Apr 5, 2023
086138b
Implement folia support
TheMeinerLP Apr 5, 2023
b72001c
Extend git ignore
TheMeinerLP Apr 5, 2023
963a921
Exclude 1.20 biome for 1.19
TheMeinerLP Apr 5, 2023
aba3a92
Check if world creation folia api
TheMeinerLP Apr 5, 2023
75361b9
Fix command processing for folia servers
TheMeinerLP Jun 5, 2023
15d8027
Fix chunk coordinator for folia
TheMeinerLP Jun 5, 2023
1e691f5
Remove unused code
TheMeinerLP Jun 5, 2023
a5371aa
Merge remote-tracking branch 'origin/feature/folia' into feature/folia
TheMeinerLP Jun 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ docs/
build/

.DS_Store
### Run Paper
run-folia/
run/
# Ignore run folders
run-[0-0].[0-9]/
run-[0-0].[0-9].[0-9]/
Expand Down
2 changes: 1 addition & 1 deletion Bukkit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ dependencies {
implementation("org.bstats:bstats-bukkit")

// Paper
compileOnly("io.papermc.paper:paper-api")
compileOnly("dev.folia:folia-api:1.19.4-R0.1-SNAPSHOT")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
compileOnly("dev.folia:folia-api:1.19.4-R0.1-SNAPSHOT")
compileOnly("dev.folia:folia-api:1.19.4-R0.1-SNAPSHOT")

This doesn't look right to me. The bukkit module has to stick to Paper for compatibility and compiling reasons.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When i allow both. The the API support for folia will break in IJ

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this breaks compatibility with Spigot and Paper.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. Let me check that how we can handle it

implementation("io.papermc:paperlib")

// Plugins
Expand Down
108 changes: 33 additions & 75 deletions Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,57 +18,28 @@
*/
package com.plotsquared.bukkit;

import com.google.inject.Guice;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Singleton;
import com.google.inject.Stage;
import com.google.inject.TypeLiteral;
import com.google.inject.*;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use asterisk imports. Please configure your IDE to respect the .editorconfig file placed in the root directory.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My ide dont respect the settings 😂 Idk why but all the default settings

import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
import com.plotsquared.bukkit.inject.BackupModule;
import com.plotsquared.bukkit.inject.BukkitModule;
import com.plotsquared.bukkit.inject.PermissionModule;
import com.plotsquared.bukkit.inject.WorldManagerModule;
import com.plotsquared.bukkit.listener.BlockEventListener;
import com.plotsquared.bukkit.listener.BlockEventListener117;
import com.plotsquared.bukkit.listener.ChunkListener;
import com.plotsquared.bukkit.listener.EntityEventListener;
import com.plotsquared.bukkit.listener.EntitySpawnListener;
import com.plotsquared.bukkit.listener.PaperListener;
import com.plotsquared.bukkit.listener.PlayerEventListener;
import com.plotsquared.bukkit.listener.ProjectileEventListener;
import com.plotsquared.bukkit.listener.ServerListener;
import com.plotsquared.bukkit.listener.SingleWorldListener;
import com.plotsquared.bukkit.listener.SpigotListener;
import com.plotsquared.bukkit.listener.WorldEvents;
import com.plotsquared.bukkit.listener.*;
import com.plotsquared.bukkit.placeholder.PAPIPlaceholders;
import com.plotsquared.bukkit.placeholder.PlaceholderFormatter;
import com.plotsquared.bukkit.player.BukkitPlayer;
import com.plotsquared.bukkit.player.BukkitPlayerManager;
import com.plotsquared.bukkit.util.BukkitUtil;
import com.plotsquared.bukkit.util.BukkitWorld;
import com.plotsquared.bukkit.util.SetGenCB;
import com.plotsquared.bukkit.util.TranslationUpdateManager;
import com.plotsquared.bukkit.util.UpdateUtility;
import com.plotsquared.bukkit.util.*;
import com.plotsquared.bukkit.util.task.BukkitTaskManager;
import com.plotsquared.bukkit.util.task.FoliaTaskManager;
import com.plotsquared.bukkit.util.task.PaperTimeConverter;
import com.plotsquared.bukkit.util.task.SpigotTimeConverter;
import com.plotsquared.bukkit.uuid.EssentialsUUIDService;
import com.plotsquared.bukkit.uuid.LuckPermsUUIDService;
import com.plotsquared.bukkit.uuid.OfflinePlayerUUIDService;
import com.plotsquared.bukkit.uuid.PaperUUIDService;
import com.plotsquared.bukkit.uuid.SQLiteUUIDService;
import com.plotsquared.bukkit.uuid.SquirrelIdUUIDService;
import com.plotsquared.bukkit.uuid.*;
import com.plotsquared.core.PlotPlatform;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.backup.BackupManager;
import com.plotsquared.core.components.ComponentPresetManager;
import com.plotsquared.core.configuration.ConfigurationNode;
import com.plotsquared.core.configuration.ConfigurationSection;
import com.plotsquared.core.configuration.ConfigurationUtil;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.configuration.Storage;
import com.plotsquared.core.configuration.*;
import com.plotsquared.core.configuration.caption.ChatFormatter;
import com.plotsquared.core.configuration.file.YamlConfiguration;
import com.plotsquared.core.database.DBFunc;
Expand All @@ -77,35 +48,20 @@
import com.plotsquared.core.generator.GeneratorWrapper;
import com.plotsquared.core.generator.IndependentPlotGenerator;
import com.plotsquared.core.generator.SingleWorldGenerator;
import com.plotsquared.core.inject.annotations.BackgroundPipeline;
import com.plotsquared.core.inject.annotations.DefaultGenerator;
import com.plotsquared.core.inject.annotations.ImpromptuPipeline;
import com.plotsquared.core.inject.annotations.WorldConfig;
import com.plotsquared.core.inject.annotations.WorldFile;
import com.plotsquared.core.inject.annotations.*;
import com.plotsquared.core.inject.modules.PlotSquaredModule;
import com.plotsquared.core.listener.PlotListener;
import com.plotsquared.core.listener.WESubscriber;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotAreaTerrainType;
import com.plotsquared.core.plot.PlotAreaType;
import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.plot.*;
import com.plotsquared.core.plot.comment.CommentManager;
import com.plotsquared.core.plot.flag.implementations.ServerPlotFlag;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.plot.world.SinglePlotArea;
import com.plotsquared.core.plot.world.SinglePlotAreaManager;
import com.plotsquared.core.setup.PlotAreaBuilder;
import com.plotsquared.core.setup.SettingsNodesWrapper;
import com.plotsquared.core.util.EventDispatcher;
import com.plotsquared.core.util.FileUtils;
import com.plotsquared.core.util.PlatformWorldManager;
import com.plotsquared.core.util.PlayerManager;
import com.plotsquared.core.util.PremiumVerification;
import com.plotsquared.core.util.ReflectionUtils;
import com.plotsquared.core.util.SetupUtils;
import com.plotsquared.core.util.WorldUtil;
import com.plotsquared.core.util.*;
import com.plotsquared.core.util.task.TaskManager;
import com.plotsquared.core.util.task.TaskTime;
import com.plotsquared.core.uuid.CacheUUIDService;
Expand Down Expand Up @@ -143,27 +99,13 @@
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import java.util.UUID;
import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

import static com.plotsquared.core.util.PremiumVerification.getDownloadID;
import static com.plotsquared.core.util.PremiumVerification.getResourceID;
import static com.plotsquared.core.util.PremiumVerification.getUserID;
import static com.plotsquared.core.util.PremiumVerification.*;
import static com.plotsquared.core.util.ReflectionUtils.getRefClass;

@SuppressWarnings("unused")
Expand Down Expand Up @@ -264,7 +206,12 @@ public void onEnable() {

// Stuff that needs to be created before the PlotSquared instance
PlotPlayer.registerConverter(Player.class, BukkitUtil::adapt);
TaskManager.setPlatformImplementation(new BukkitTaskManager(this, timeConverter));
if (FoliaSupport.isFolia()) {
TaskManager.setPlatformImplementation(new FoliaTaskManager(this, timeConverter));
} else {
TaskManager.setPlatformImplementation(new BukkitTaskManager(this, timeConverter));
}


final PlotSquared plotSquared = new PlotSquared(this, "Bukkit");

Expand Down Expand Up @@ -558,9 +505,7 @@ public void onEnable() {
e.printStackTrace();
}
}

// Clean up potential memory leak
Bukkit.getScheduler().runTaskTimer(this, () -> {
Runnable cleanUp = () -> {
try {
for (final PlotPlayer<? extends Player> player : this.playerManager().getPlayers()) {
if (player.getPlatformPlayer() == null || !player.getPlatformPlayer().isOnline()) {
Expand All @@ -570,7 +515,15 @@ public void onEnable() {
} catch (final Exception e) {
getLogger().warning("Failed to clean up players: " + e.getMessage());
}
}, 100L, 100L);
};
if (FoliaSupport.isFolia()) {
Bukkit.getGlobalRegionScheduler().runAtFixedRate(this, scheduledTask -> {
cleanUp.run();
}, 100, 100);
} else {
// Clean up potential memory leak
Bukkit.getScheduler().runTaskTimer(this, cleanUp, 100L, 100L);
}

// Check if we are in a safe environment
ServerLib.checkUnsafeForks();
Expand Down Expand Up @@ -728,7 +681,12 @@ private void startUuidCaching(
@Override
public void onDisable() {
PlotSquared.get().disable();
Bukkit.getScheduler().cancelTasks(this);
if (FoliaSupport.isFolia()) {
Bukkit.getAsyncScheduler().cancelTasks(this);
Bukkit.getGlobalRegionScheduler().cancelTasks(this);
} else {
Bukkit.getScheduler().cancelTasks(this);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,9 @@ private final class BukkitPlotBiomeProvider extends BiomeProvider {
static {
ArrayList<Biome> biomes = new ArrayList<>(List.of(Biome.values()));
biomes.remove(Biome.CUSTOM);
if (PlotSquared.platform().serverVersion()[1] <= 19) {
biomes.remove(Biome.CHERRY_GROVE);
}
Comment on lines +439 to +441
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is that supposed to do? Does folia not support cherry groves?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some 1.19.4 servers tries to generate plots without 1.20 datapacks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the issue. CHERRY_GROVE exist in 1.19.4, what does Folia or 1.20 have to do with it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[13:21:06] [pool-13-thread-1/WARN]: [PlotSquared/BukkitPlatform] This message may also be a false positive and could be ignored.
[13:21:06] [Server thread/INFO]: [PlotSquared/BukkitPlatform] (UUID) 0 UUIDs will be cached
[13:21:06] [Server thread/INFO]: Preparing level "world"
[13:21:06] [Server thread/ERROR]: Encountered an unexpected exception
java.lang.IllegalStateException: Missing key in ResourceKey[minecraft:root / minecraft:worldgen/biome]: ResourceKey[minecraft:worldgen/biome / minecraft:cherry_grove]
	at net.minecraft.core.Registry.getHolderOrThrow(Registry.java:162) ~[folia-1.19.4.jar:git-Folia-22]
	at java.util.Optional.orElseThrow(Optional.java:403) ~[?:?]
	at net.minecraft.core.Registry.getHolderOrThrow(Registry.java:162) ~[folia-1.19.4.jar:git-Folia-22]
	at org.bukkit.craftbukkit.v1_19_R3.block.CraftBlock.biomeToBiomeBase(CraftBlock.java:407) ~[folia-1.19.4.jar:git-Folia-22]
	at org.bukkit.craftbukkit.v1_19_R3.generator.CustomWorldChunkManager.biomeListToBiomeBaseList(CustomWorldChunkManager.java:28) ~[folia-1.19.4.jar:git-Folia-22]
	at org.bukkit.craftbukkit.v1_19_R3.generator.CustomWorldChunkManager.b(CustomWorldChunkManager.java:55) ~[folia-1.19.4.jar:git-Folia-22]
	at net.minecraft.world.level.biome.BiomeSource.d(BiomeSource.java:29) ~[?:?]
	at com.google.common.base.Suppliers$NonSerializableMemoizingSupplier.get(Suppliers.java:183) ~[guava-31.1-jre.jar:?]
	at net.minecraft.world.level.biome.BiomeSource.possibleBiomes(BiomeSource.java:40) ~[?:?]
	at net.minecraft.world.level.chunk.ChunkGeneratorStructureState.hasBiomesForStructureSet(ChunkGeneratorStructureState.java:157) ~[folia-1.19.4.jar:git-Folia-22]
	at net.minecraft.world.level.chunk.ChunkGeneratorStructureState.lambda$createForNormal$1(ChunkGeneratorStructureState.java:65) ~[folia-1.19.4.jar:git-Folia-22]
	at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:178) ~[?:?]
	at java.util.AbstractList$RandomAccessSpliterator.forEachRemaining(AbstractList.java:720) ~[?:?]
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) ~[?:?]
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) ~[?:?]
	at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) ~[?:?]
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[?:?]
	at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682) ~[?:?]
	at net.minecraft.world.level.chunk.ChunkGeneratorStructureState.createForNormal(ChunkGeneratorStructureState.java:66) ~[folia-1.19.4.jar:git-Folia-22]
	at net.minecraft.world.level.chunk.ChunkGenerator.createState(ChunkGenerator.java:106) ~[folia-1.19.4.jar:git-Folia-22]
	at net.minecraft.server.level.ChunkMap.<init>(ChunkMap.java:305) ~[folia-1.19.4.jar:git-Folia-22]
	at net.minecraft.server.level.ServerChunkCache.<init>(ServerChunkCache.java:276) ~[?:?]
	at net.minecraft.server.level.ServerLevel.<init>(ServerLevel.java:645) ~[?:?]
	at net.minecraft.server.MinecraftServer.loadWorld0(MinecraftServer.java:616) ~[folia-1.19.4.jar:git-Folia-22]
	at net.minecraft.server.MinecraftServer.loadLevel(MinecraftServer.java:465) ~[folia-1.19.4.jar:git-Folia-22]
	at net.minecraft.server.dedicated.DedicatedServer.initServer(DedicatedServer.java:308) ~[folia-1.19.4.jar:git-Folia-22]
	at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1191) ~[folia-1.19.4.jar:git-Folia-22]
	at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:348) ~[folia-1.19.4.jar:git-Folia-22]
	at java.lang.Thread.run(Thread.java:833) ~[?:?]
[13:21:07] [Server thread/ERROR]: This crash report has been saved to: /Users/pglanz/development/workspace/gitlab_themeinerlp_dev/onelitefeather/PlotSquared/run-folia/./crash-reports/crash-2023-04-05_13.21.07-server.txt
[13:21:07] [Region shutdown thread/INFO]: [RegionShutdownThread] Awaiting scheduler termination for 60s
[13:21:07] [Region shutdown thread/INFO]: [RegionShutdownThread] Scheduler halted
[13:21:07] [Region shutdown thread/INFO]: Stopping server

Thats the generic issue on the main branch of PS.
I prepared also already a non folia fix of it.

BIOMES = List.copyOf(biomes);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package com.plotsquared.bukkit.managers;

import com.google.inject.Singleton;
import com.plotsquared.bukkit.util.FoliaSupport;
import com.plotsquared.core.configuration.file.YamlConfiguration;
import com.plotsquared.core.util.PlatformWorldManager;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -48,13 +49,16 @@ public void initialize() {
@Override
public @Nullable World handleWorldCreation(@NonNull String worldName, @Nullable String generator) {
this.setGenerator(worldName, generator);
final WorldCreator wc = new WorldCreator(worldName);
wc.environment(World.Environment.NORMAL);
if (generator != null) {
wc.generator(generator);
wc.type(WorldType.FLAT);
if (!FoliaSupport.isFolia()) {
final WorldCreator wc = new WorldCreator(worldName);
wc.environment(World.Environment.NORMAL);
if (generator != null) {
wc.generator(generator);
wc.type(WorldType.FLAT);
}
Comment on lines +52 to +58
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an issue within the default branch preventing world generation atm, so this can't be tested and verified safely.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Folia have not yet a API for create worlds. Before we run in issues, I removed that option for folia

return Bukkit.createWorld(wc);
}
return Bukkit.createWorld(wc);
return null;
}

protected void setGenerator(final @Nullable String worldName, final @Nullable String generator) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import com.plotsquared.bukkit.BukkitPlatform;
import com.plotsquared.bukkit.util.FoliaSupport;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.queue.ChunkCoordinator;
import com.plotsquared.core.queue.subscriber.ProgressSubscriber;
Expand Down Expand Up @@ -160,6 +161,7 @@ public void run() {
}

Chunk chunk = this.availableChunks.poll();

if (chunk == null) {
if (this.availableChunks.isEmpty()) {
if (this.requestedChunks.isEmpty() && loadingChunks.get() == 0) {
Expand All @@ -175,7 +177,20 @@ public void run() {
do {
final long start = System.currentTimeMillis();
try {
this.chunkConsumer.accept(BlockVector2.at(chunk.getX(), chunk.getZ()));
if (FoliaSupport.isFolia()) {
var tempChunk = chunk;
Bukkit.getRegionScheduler().run(
this.plugin,
this.bukkitWorld,
chunk.getX(),
chunk.getZ(),
scheduledTask -> {
this.chunkConsumer.accept(BlockVector2.at(tempChunk.getX(), tempChunk.getZ()));
}
);
} else {
this.chunkConsumer.accept(BlockVector2.at(chunk.getX(), chunk.getZ()));
}
} catch (final Throwable throwable) {
this.throwableConsumer.accept(throwable);
}
Expand All @@ -188,6 +203,8 @@ public void run() {
iterationTime[0] = iterationTime[1];
iterationTime[1] = end - start;
} while (iterationTime[0] + iterationTime[1] < this.maxIterationTime * 2 && (chunk = availableChunks.poll()) != null);


if (processedChunks < this.batchSize) {
// Adjust batch size based on the amount of processed chunks per tick
this.batchSize = processedChunks;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.plotsquared.bukkit.util;

public final class FoliaSupport {
private FoliaSupport() {

}

private static final boolean IS_FOLIA;

private static final Class<?> TICK_THREAD_CLASS;
static {
boolean isFolia = false;
try {
// Assume API is present
Class.forName("io.papermc.paper.threadedregions.scheduler.EntityScheduler");
isFolia = true;
} catch (Exception ignored) {

}
IS_FOLIA = isFolia;
Class<?> tickThreadClass = String.class; // thread will never be instance of String
if (IS_FOLIA) {
try {
tickThreadClass = Class.forName("io.papermc.paper.util.TickThread");
} catch (ClassNotFoundException e) {
throw new AssertionError(e);
}
}
TICK_THREAD_CLASS = tickThreadClass;
}

public static boolean isFolia() {
return IS_FOLIA;
}

public static boolean isTickThread() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. Currently

return TICK_THREAD_CLASS.isInstance(Thread.currentThread());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.plotsquared.bukkit.util.task;

import com.plotsquared.core.util.task.PlotSquaredTask;
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.jetbrains.annotations.NotNull;

import java.util.concurrent.TimeUnit;

public final class FoliaPlotSquaredTask implements PlotSquaredTask {

@NonNull
private final Runnable runnable;
@NotNull
private final JavaPlugin javaPlugin;

private ScheduledTask task;

public FoliaPlotSquaredTask(final @NonNull Runnable runnable, final JavaPlugin javaPlugin) {
this.runnable = runnable;
this.javaPlugin = javaPlugin;
}

@Override
public void runTask() {
this.task = Bukkit.getGlobalRegionScheduler().run(javaPlugin, scheduledTask -> this.runnable.run());
}

public void runTaskLater(long delay) {
this.task = Bukkit.getGlobalRegionScheduler().runDelayed(javaPlugin, scheduledTask -> this.runnable.run(), delay);
}

public void runTaskLaterAsynchronously(long delay) {
this.task = Bukkit.getAsyncScheduler().runDelayed(javaPlugin, scheduledTask -> this.runnable.run(), delay, TimeUnit.MILLISECONDS);
}

public void runTaskAsynchronously() {
this.task = Bukkit.getAsyncScheduler().runNow(javaPlugin, scheduledTask -> this.runnable.run());
}

public void runTaskTimerAsynchronously(long delay, long period) {
this.task = Bukkit.getAsyncScheduler().runAtFixedRate(javaPlugin, scheduledTask -> this.runnable.run(), delay, period, TimeUnit.MILLISECONDS);
}

public void runTaskTimer(long delay, long period) {
this.task = Bukkit.getGlobalRegionScheduler().runAtFixedRate(javaPlugin, scheduledTask -> this.runnable.run(), delay, period);
}

@Override
public boolean isCancelled() {
return this.task.isCancelled();
}

@Override
public void cancel() {
this.task.cancel();
}

}
Loading