Skip to content

Commit

Permalink
Add Folia Support (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
Euphillya authored May 12, 2024
1 parent 727d14a commit ad5749f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
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

0 comments on commit ad5749f

Please sign in to comment.