-
-
Notifications
You must be signed in to change notification settings - Fork 750
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
base: main
Are you sure you want to change the base?
Changes from all commits
6305db8
1ddeec6
f5c606f
6727d85
c6bab2a
accce89
dcb11e1
19cde40
0e0b4e2
c31aea7
129859e
fe47580
654c48e
3138d67
c09d842
402805d
e104e0f
1fa9d0c
43d71fe
086138b
b72001c
963a921
aba3a92
75361b9
15d8027
1e691f5
a5371aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.*; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't use asterisk imports. Please configure your IDE to respect the There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
@@ -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; | ||
|
@@ -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") | ||
|
@@ -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"); | ||
|
||
|
@@ -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()) { | ||
|
@@ -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(); | ||
|
@@ -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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is that supposed to do? Does folia not support cherry groves? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Thats the generic issue on the main branch of PS. |
||
BIOMES = List.copyOf(biomes); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
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() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look right to me. The bukkit module has to stick to Paper for compatibility and compiling reasons.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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