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

Support Folia #40

Merged
merged 2 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ modrinth {
// rootProject.layout.buildDirectory.file("libs/${rootProject.name}-${project.version}-sources.jar").get()
//])
gameVersions.addAll(["${minecraftVersion}"])
loaders.addAll(['bukkit', 'fabric', /*'forge',*/ 'paper', 'purpur', 'quilt', 'spigot'])
loaders.addAll(['bukkit', 'fabric', /*'forge',*/ 'paper', 'purpur', 'quilt', 'spigot', 'folia'])
changelog = System.getenv('COMMIT_MESSAGE')
dependencies {
required.project 'fabric-api'
Expand Down
27 changes: 18 additions & 9 deletions bukkit/src/main/java/net/pl3x/map/bukkit/Pl3xMapBukkit.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@
package net.pl3x.map.bukkit;

import java.util.UUID;
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
import net.pl3x.map.bukkit.command.BukkitCommandManager;
import net.pl3x.map.core.Pl3xMap;
import net.pl3x.map.core.event.server.ServerLoadedEvent;
import net.pl3x.map.core.network.Network;
import net.pl3x.map.core.player.Player;
import net.pl3x.map.core.player.PlayerListener;
import net.pl3x.map.core.player.PlayerRegistry;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.event.EventHandler;
Expand All @@ -47,6 +49,8 @@
public class Pl3xMapBukkit extends JavaPlugin implements Listener {
private final Pl3xMapImpl pl3xmap;
private final PlayerListener playerListener = new PlayerListener();
private boolean isFolia = false;
private ScheduledTask tickTimerTask = null;

private Network network;

Expand All @@ -58,13 +62,9 @@ public Pl3xMapBukkit() {
@Override
public void onEnable() {
try {
io.papermc.paper.chunk.system.scheduling.ChunkFullTask.class.getDeclaredField("chunkLoads");
io.papermc.paper.chunk.system.scheduling.ChunkFullTask.class.getDeclaredField("chunkGenerates");
getLogger().severe("Pl3xMap does not support Folia");
getLogger().severe("Pl3xMap will now disable itself");
getServer().getPluginManager().disablePlugin(this);
return;
} catch (Throwable ignore) {
Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
isFolia = true;
} catch (ClassNotFoundException ignored) {
}

this.pl3xmap.enable();
Expand All @@ -80,8 +80,13 @@ public void onEnable() {
throw new RuntimeException(e);
}

getServer().getScheduler().runTaskTimer(this, () ->
this.pl3xmap.getScheduler().tick(), 20, 1);
if (isFolia) {
tickTimerTask = Bukkit.getGlobalRegionScheduler().runAtFixedRate(this, timerTask ->
this.pl3xmap.getScheduler().tick(), 20, 1);
} else {
getServer().getScheduler().runTaskTimer(this, () ->
this.pl3xmap.getScheduler().tick(), 20, 1);
}
}

@Override
Expand All @@ -91,6 +96,10 @@ public void onDisable() {
this.network = null;
}

if (tickTimerTask != null) {
tickTimerTask.cancel();
}

this.pl3xmap.disable();
}

Expand Down
1 change: 1 addition & 0 deletions bukkit/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ load: "POSTWORLD"
authors: ${authors}
description: "${description}"
website: "${website}"
folia-supported: true

permissions:
pl3xmap.command.map:
Expand Down
Loading