Add Folia support minus world generation

This commit is contained in:
Telesphoreo 2023-07-21 20:01:59 -05:00
parent 91a1b1cfff
commit 77dc95ae29
No known key found for this signature in database
GPG Key ID: 9D1991811E093C02
12 changed files with 77 additions and 39 deletions

View File

@ -12,7 +12,7 @@ dependencies {
library "org.mariadb.jdbc:mariadb-java-client:3.1.4" library "org.mariadb.jdbc:mariadb-java-client:3.1.4"
library "com.zaxxer:HikariCP:5.0.1" library "com.zaxxer:HikariCP:5.0.1"
library "org.apache.maven.resolver:maven-resolver-transport-http:1.9.13" library "org.apache.maven.resolver:maven-resolver-transport-http:1.9.13"
compileOnly "io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT" compileOnly "dev.folia:folia-api:1.20.1-R0.1-SNAPSHOT"
compileOnly("com.github.MilkBowl:VaultAPI:1.7.1") { compileOnly("com.github.MilkBowl:VaultAPI:1.7.1") {
exclude group: "org.bukkit", module: "bukkit" exclude group: "org.bukkit", module: "bukkit"
} }
@ -38,9 +38,10 @@ paper {
loader = "dev.plex.PlexLibraryManager" loader = "dev.plex.PlexLibraryManager"
website = "https://plex.us.org" website = "https://plex.us.org"
authors = ["Telesphoreo", "taahanis", "supernt"] authors = ["Telesphoreo", "taahanis", "supernt"]
// Load BukkitTelnet and LibsDisguises before Plex so the modules register properly
apiVersion = "1.19" apiVersion = "1.19"
foliaSupported = true
generateLibrariesJson = true generateLibrariesJson = true
// Load BukkitTelnet and LibsDisguises before Plex so the modules register properly
serverDependencies { serverDependencies {
'BukkitTelnet' { 'BukkitTelnet' {
required = false required = false

View File

@ -21,9 +21,14 @@ import dev.plex.storage.player.MongoPlayerData;
import dev.plex.storage.player.SQLPlayerData; import dev.plex.storage.player.SQLPlayerData;
import dev.plex.storage.punishment.SQLNotes; import dev.plex.storage.punishment.SQLNotes;
import dev.plex.storage.punishment.SQLPunishment; import dev.plex.storage.punishment.SQLPunishment;
import dev.plex.util.*; import dev.plex.util.BuildInfo;
import dev.plex.util.BungeeUtil;
import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils;
import dev.plex.util.UpdateChecker;
import dev.plex.util.redis.MessageUtil; import dev.plex.util.redis.MessageUtil;
import dev.plex.world.CustomWorld; import dev.plex.world.CustomWorld;
import java.io.File;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import net.milkbowl.vault.chat.Chat; import net.milkbowl.vault.chat.Chat;
@ -33,8 +38,6 @@ import org.bukkit.Bukkit;
import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
@Getter @Getter
@Setter @Setter
public class Plex extends JavaPlugin public class Plex extends JavaPlugin
@ -189,7 +192,11 @@ public class Plex extends JavaPlugin
punishmentManager.mergeIndefiniteBans(); punishmentManager.mergeIndefiniteBans();
PlexLog.log("Punishment System initialized"); PlexLog.log("Punishment System initialized");
generateWorlds(); if (!PlexUtils.isFolia())
{
// World generation is not supported on Folia yet
generateWorlds();
}
serviceManager = new ServiceManager(); serviceManager = new ServiceManager();
PlexLog.log("Service Manager initialized"); PlexLog.log("Service Manager initialized");

View File

@ -2,7 +2,6 @@ package dev.plex.services;
import dev.plex.PlexBase; import dev.plex.PlexBase;
import lombok.Getter; import lombok.Getter;
import lombok.Setter;
@Getter @Getter
public abstract class AbstractService implements IService, PlexBase public abstract class AbstractService implements IService, PlexBase
@ -10,9 +9,6 @@ public abstract class AbstractService implements IService, PlexBase
private final boolean asynchronous; private final boolean asynchronous;
private final boolean repeating; private final boolean repeating;
@Setter
private int taskId;
public AbstractService(boolean repeating, boolean async) public AbstractService(boolean repeating, boolean async)
{ {
this.repeating = repeating; this.repeating = repeating;
@ -21,11 +17,9 @@ public abstract class AbstractService implements IService, PlexBase
public void onStart() public void onStart()
{ {
} }
public void onEnd() public void onEnd()
{ {
} }
} }

View File

@ -1,8 +1,10 @@
package dev.plex.services; package dev.plex.services;
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
public interface IService public interface IService
{ {
void run(); void run(ScheduledTask scheduledTask);
int repeatInSeconds(); int repeatInSeconds();
} }

View File

@ -2,11 +2,15 @@ package dev.plex.services;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import dev.plex.Plex; import dev.plex.Plex;
import dev.plex.services.impl.*; import dev.plex.services.impl.AutoWipeService;
import org.bukkit.Bukkit; import dev.plex.services.impl.BanService;
import org.bukkit.scheduler.BukkitTask; import dev.plex.services.impl.CommandBlockerService;
import dev.plex.services.impl.GameRuleService;
import dev.plex.services.impl.TimingService;
import dev.plex.services.impl.UpdateCheckerService;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit;
import org.bukkit.Bukkit;
public class ServiceManager public class ServiceManager
{ {
@ -24,10 +28,7 @@ public class ServiceManager
public void startServices() public void startServices()
{ {
for (AbstractService service : services) services.forEach(this::startService);
{
startService(service);
}
} }
public void endServices() public void endServices()
@ -45,26 +46,22 @@ public class ServiceManager
if (!service.isRepeating()) if (!service.isRepeating())
{ {
int time = service.repeatInSeconds(); int time = service.repeatInSeconds();
BukkitTask task;
if (time == 0) if (time == 0)
{ {
task = Bukkit.getScheduler().runTask(Plex.get(), service::run); Bukkit.getGlobalRegionScheduler().run(Plex.get(), service::run);
} }
else else
{ {
task = Bukkit.getScheduler().runTaskLater(Plex.get(), service::run, time); Bukkit.getAsyncScheduler().runDelayed(Plex.get(), service::run, time, TimeUnit.SECONDS);
} }
service.setTaskId(task.getTaskId());
} }
else if (service.isRepeating() && service.isAsynchronous()) else if (service.isRepeating() && service.isAsynchronous())
{ {
BukkitTask task = Bukkit.getScheduler().runTaskTimerAsynchronously(Plex.get(), service::run, 0, 20L * service.repeatInSeconds()); Bukkit.getAsyncScheduler().runAtFixedRate(Plex.get(), service::run, 1, service.repeatInSeconds(), TimeUnit.SECONDS);
service.setTaskId(task.getTaskId());
} }
else if (service.isRepeating() && !service.isAsynchronous()) else if (service.isRepeating() && !service.isAsynchronous())
{ {
BukkitTask task = Bukkit.getScheduler().runTaskTimer(Plex.get(), service::run, 0, 20L * service.repeatInSeconds()); Bukkit.getGlobalRegionScheduler().runAtFixedRate(Plex.get(), service::run, 1, 20L * service.repeatInSeconds());
service.setTaskId(task.getTaskId());
} }
if (!services.contains(service)) if (!services.contains(service))
{ {
@ -75,7 +72,8 @@ public class ServiceManager
public void endService(AbstractService service, boolean remove) public void endService(AbstractService service, boolean remove)
{ {
Bukkit.getScheduler().cancelTask(service.getTaskId()); Bukkit.getGlobalRegionScheduler().cancelTasks(Plex.get());
Bukkit.getAsyncScheduler().cancelTasks(Plex.get());
service.onEnd(); service.onEnd();
if (remove) if (remove)
{ {

View File

@ -2,12 +2,13 @@ package dev.plex.services.impl;
import dev.plex.Plex; import dev.plex.Plex;
import dev.plex.services.AbstractService; import dev.plex.services.AbstractService;
import dev.plex.util.PlexLog;
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
import java.util.List;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import java.util.List;
public class AutoWipeService extends AbstractService public class AutoWipeService extends AbstractService
{ {
public AutoWipeService() public AutoWipeService()
@ -16,7 +17,7 @@ public class AutoWipeService extends AbstractService
} }
@Override @Override
public void run() public void run(ScheduledTask task)
{ {
if (Plex.get().config.getBoolean("autowipe.enabled")) if (Plex.get().config.getBoolean("autowipe.enabled"))
{ {
@ -28,13 +29,32 @@ public class AutoWipeService extends AbstractService
{ {
if (entities.stream().anyMatch(entityName -> entityName.equalsIgnoreCase(entity.getType().name()))) if (entities.stream().anyMatch(entityName -> entityName.equalsIgnoreCase(entity.getType().name())))
{ {
entity.remove(); Bukkit.getRegionScheduler().run(Plex.get(), entity.getLocation(), this::entityRun);
PlexLog.debug("Started entity scheduler");
} }
} }
} }
} }
} }
private void entityRun(ScheduledTask task)
{
List<String> entities = plugin.config.getStringList("autowipe.entities");
for (World world : Bukkit.getWorlds())
{
for (Entity entity : world.getEntities())
{
if (entities.stream().anyMatch(entityName -> entityName.equalsIgnoreCase(entity.getType().name())))
{
PlexLog.debug("Removed entity " + entity.getName());
entity.remove();
task.cancel();
}
}
}
}
@Override @Override
public int repeatInSeconds() public int repeatInSeconds()
{ {

View File

@ -3,6 +3,7 @@ package dev.plex.services.impl;
import dev.plex.Plex; import dev.plex.Plex;
import dev.plex.services.AbstractService; import dev.plex.services.AbstractService;
import dev.plex.util.TimeUtils; import dev.plex.util.TimeUtils;
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -17,7 +18,7 @@ public class BanService extends AbstractService
} }
@Override @Override
public void run() public void run(ScheduledTask task)
{ {
Plex.get().getPunishmentManager().getActiveBans().whenComplete((punishments, throwable) -> Plex.get().getPunishmentManager().getActiveBans().whenComplete((punishments, throwable) ->
{ {

View File

@ -5,6 +5,7 @@ import dev.plex.command.blocking.BlockedCommand;
import dev.plex.services.AbstractService; import dev.plex.services.AbstractService;
import dev.plex.util.PlexLog; import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils; import dev.plex.util.PlexUtils;
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
import lombok.Getter; import lombok.Getter;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -22,7 +23,7 @@ public class CommandBlockerService extends AbstractService
} }
@Override @Override
public void run() public void run(ScheduledTask task)
{ {
BLOCKED_COMMANDS.clear(); BLOCKED_COMMANDS.clear();
plugin.commands.getStringList("commands").forEach(s -> plugin.commands.getStringList("commands").forEach(s ->

View File

@ -3,6 +3,7 @@ package dev.plex.services.impl;
import dev.plex.services.AbstractService; import dev.plex.services.AbstractService;
import dev.plex.util.GameRuleUtil; import dev.plex.util.GameRuleUtil;
import dev.plex.util.PlexLog; import dev.plex.util.PlexLog;
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
@ -16,7 +17,7 @@ public class GameRuleService extends AbstractService
} }
@Override @Override
public void run() public void run(ScheduledTask task)
{ {
for (World world : Bukkit.getWorlds()) for (World world : Bukkit.getWorlds())
{ {

View File

@ -7,6 +7,7 @@ import dev.plex.punishment.PunishmentType;
import dev.plex.services.AbstractService; import dev.plex.services.AbstractService;
import dev.plex.util.PlexLog; import dev.plex.util.PlexLog;
import dev.plex.util.TimeUtils; import dev.plex.util.TimeUtils;
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -26,7 +27,7 @@ public class TimingService extends AbstractService
} }
@Override @Override
public void run() public void run(ScheduledTask task)
{ {
spamCooldown.clear(); spamCooldown.clear();
nukerCooldown.clear(); nukerCooldown.clear();

View File

@ -1,6 +1,7 @@
package dev.plex.services.impl; package dev.plex.services.impl;
import dev.plex.services.AbstractService; import dev.plex.services.AbstractService;
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
public class UpdateCheckerService extends AbstractService public class UpdateCheckerService extends AbstractService
@ -13,7 +14,7 @@ public class UpdateCheckerService extends AbstractService
} }
@Override @Override
public void run() public void run(ScheduledTask task)
{ {
if (!newVersion) if (!newVersion)
{ {

View File

@ -105,6 +105,17 @@ public class PlexUtils implements PlexBase
} }
} }
public static boolean isFolia() {
try {
Class.forName("io.papermc.paper.threadedregions.ThreadedRegionizer");
}
catch (Exception e) {
return false;
}
return true;
}
public static boolean isPluginCMD(String cmd, String pluginName) public static boolean isPluginCMD(String cmd, String pluginName)
{ {
Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginName); Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginName);