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 "com.zaxxer:HikariCP:5.0.1"
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") {
exclude group: "org.bukkit", module: "bukkit"
}
@ -38,9 +38,10 @@ paper {
loader = "dev.plex.PlexLibraryManager"
website = "https://plex.us.org"
authors = ["Telesphoreo", "taahanis", "supernt"]
// Load BukkitTelnet and LibsDisguises before Plex so the modules register properly
apiVersion = "1.19"
foliaSupported = true
generateLibrariesJson = true
// Load BukkitTelnet and LibsDisguises before Plex so the modules register properly
serverDependencies {
'BukkitTelnet' {
required = false

View file

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

View file

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

View file

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

View file

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

View file

@ -2,12 +2,13 @@ package dev.plex.services.impl;
import dev.plex.Plex;
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.World;
import org.bukkit.entity.Entity;
import java.util.List;
public class AutoWipeService extends AbstractService
{
public AutoWipeService()
@ -16,7 +17,7 @@ public class AutoWipeService extends AbstractService
}
@Override
public void run()
public void run(ScheduledTask task)
{
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())))
{
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
public int repeatInSeconds()
{

View file

@ -3,6 +3,7 @@ package dev.plex.services.impl;
import dev.plex.Plex;
import dev.plex.services.AbstractService;
import dev.plex.util.TimeUtils;
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
@ -17,7 +18,7 @@ public class BanService extends AbstractService
}
@Override
public void run()
public void run(ScheduledTask task)
{
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.util.PlexLog;
import dev.plex.util.PlexUtils;
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
import lombok.Getter;
import org.bukkit.command.Command;
@ -22,7 +23,7 @@ public class CommandBlockerService extends AbstractService
}
@Override
public void run()
public void run(ScheduledTask task)
{
BLOCKED_COMMANDS.clear();
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.util.GameRuleUtil;
import dev.plex.util.PlexLog;
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
import org.bukkit.Bukkit;
import org.bukkit.World;
@ -16,7 +17,7 @@ public class GameRuleService extends AbstractService
}
@Override
public void run()
public void run(ScheduledTask task)
{
for (World world : Bukkit.getWorlds())
{

View file

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

View file

@ -1,6 +1,7 @@
package dev.plex.services.impl;
import dev.plex.services.AbstractService;
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
import org.bukkit.Bukkit;
public class UpdateCheckerService extends AbstractService
@ -13,7 +14,7 @@ public class UpdateCheckerService extends AbstractService
}
@Override
public void run()
public void run(ScheduledTask task)
{
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)
{
Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginName);