mirror of
https://github.com/plexusorg/Plex.git
synced 2026-06-04 13:36:55 +00:00
More modernization for the database
This commit is contained in:
@@ -1,16 +1,18 @@
|
||||
package dev.plex.services;
|
||||
|
||||
import dev.plex.PlexBase;
|
||||
import dev.plex.Plex;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public abstract class AbstractService implements IService, PlexBase
|
||||
public abstract class AbstractService implements IService
|
||||
{
|
||||
protected final Plex plugin;
|
||||
private final boolean asynchronous;
|
||||
private final boolean repeating;
|
||||
|
||||
public AbstractService(boolean repeating, boolean async)
|
||||
public AbstractService(Plex plugin, boolean repeating, boolean async)
|
||||
{
|
||||
this.plugin = plugin;
|
||||
this.repeating = repeating;
|
||||
this.asynchronous = async;
|
||||
}
|
||||
|
||||
@@ -15,15 +15,17 @@ import org.bukkit.Bukkit;
|
||||
|
||||
public class ServiceManager
|
||||
{
|
||||
private final Plex plugin;
|
||||
private final List<AbstractService> services = Lists.newArrayList();
|
||||
|
||||
public ServiceManager()
|
||||
public ServiceManager(Plex plugin)
|
||||
{
|
||||
registerService(new AutoWipeService());
|
||||
registerService(new BanService());
|
||||
registerService(new GameRuleService());
|
||||
registerService(new TimingService());
|
||||
registerService(new UpdateCheckerService());
|
||||
this.plugin = plugin;
|
||||
registerService(new AutoWipeService(plugin));
|
||||
registerService(new BanService(plugin));
|
||||
registerService(new GameRuleService(plugin));
|
||||
registerService(new TimingService(plugin));
|
||||
registerService(new UpdateCheckerService(plugin));
|
||||
}
|
||||
|
||||
public void startServices()
|
||||
@@ -48,20 +50,20 @@ public class ServiceManager
|
||||
int time = service.repeatInSeconds();
|
||||
if (time == 0)
|
||||
{
|
||||
Bukkit.getGlobalRegionScheduler().run(Plex.get(), service::run);
|
||||
Bukkit.getGlobalRegionScheduler().run(plugin, service::run);
|
||||
}
|
||||
else
|
||||
{
|
||||
Bukkit.getAsyncScheduler().runDelayed(Plex.get(), service::run, time, TimeUnit.SECONDS);
|
||||
Bukkit.getAsyncScheduler().runDelayed(plugin, service::run, time, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
else if (service.isRepeating() && service.isAsynchronous())
|
||||
{
|
||||
Bukkit.getAsyncScheduler().runAtFixedRate(Plex.get(), service::run, 1, service.repeatInSeconds(), TimeUnit.SECONDS);
|
||||
Bukkit.getAsyncScheduler().runAtFixedRate(plugin, service::run, 1, service.repeatInSeconds(), TimeUnit.SECONDS);
|
||||
}
|
||||
else if (service.isRepeating() && !service.isAsynchronous())
|
||||
{
|
||||
Bukkit.getGlobalRegionScheduler().runAtFixedRate(Plex.get(), service::run, 1, 20L * service.repeatInSeconds());
|
||||
Bukkit.getGlobalRegionScheduler().runAtFixedRate(plugin, service::run, 1, 20L * service.repeatInSeconds());
|
||||
}
|
||||
if (!services.contains(service))
|
||||
{
|
||||
@@ -72,8 +74,8 @@ public class ServiceManager
|
||||
|
||||
public void endService(AbstractService service, boolean remove)
|
||||
{
|
||||
Bukkit.getGlobalRegionScheduler().cancelTasks(Plex.get());
|
||||
Bukkit.getAsyncScheduler().cancelTasks(Plex.get());
|
||||
Bukkit.getGlobalRegionScheduler().cancelTasks(plugin);
|
||||
Bukkit.getAsyncScheduler().cancelTasks(plugin);
|
||||
service.onEnd();
|
||||
if (remove)
|
||||
{
|
||||
|
||||
@@ -12,15 +12,15 @@ import org.bukkit.entity.Entity;
|
||||
|
||||
public class AutoWipeService extends AbstractService
|
||||
{
|
||||
public AutoWipeService()
|
||||
public AutoWipeService(Plex plugin)
|
||||
{
|
||||
super(true, false);
|
||||
super(plugin, true, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(ScheduledTask task)
|
||||
{
|
||||
if (Plex.get().config.getBoolean("autowipe.enabled"))
|
||||
if (plugin.config.getBoolean("autowipe.enabled"))
|
||||
{
|
||||
List<String> entities = plugin.config.getStringList("autowipe.entities");
|
||||
|
||||
@@ -30,7 +30,7 @@ public class AutoWipeService extends AbstractService
|
||||
{
|
||||
if (entities.stream().anyMatch(entityName -> entityName.equalsIgnoreCase(entity.getType().name())))
|
||||
{
|
||||
Bukkit.getRegionScheduler().run(Plex.get(), entity.getLocation(), this::entityRun);
|
||||
Bukkit.getRegionScheduler().run(plugin, entity.getLocation(), this::entityRun);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,21 +13,21 @@ import org.bukkit.Bukkit;
|
||||
|
||||
public class BanService extends AbstractService
|
||||
{
|
||||
public BanService()
|
||||
public BanService(Plex plugin)
|
||||
{
|
||||
super(true, true);
|
||||
super(plugin, true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(ScheduledTask task)
|
||||
{
|
||||
Plex.get().getPunishmentManager().getActiveBans().whenComplete((punishments, throwable) ->
|
||||
plugin.getPunishmentManager().getActiveBans().whenComplete((punishments, throwable) ->
|
||||
{
|
||||
punishments.forEach(punishment ->
|
||||
{
|
||||
if (ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE)).isAfter(punishment.getEndDate()))
|
||||
{
|
||||
Plex.get().getPunishmentManager().unban(punishment);
|
||||
plugin.getPunishmentManager().unban(punishment);
|
||||
Bukkit.broadcast(PlexUtils.messageComponent("banExpiredBroadcast", Bukkit.getOfflinePlayer(punishment.getPunished()).getName()));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package dev.plex.services.impl;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.services.AbstractService;
|
||||
import dev.plex.util.GameRuleUtil;
|
||||
import dev.plex.util.PlexLog;
|
||||
@@ -12,9 +13,9 @@ import org.bukkit.World;
|
||||
|
||||
public class GameRuleService extends AbstractService
|
||||
{
|
||||
public GameRuleService()
|
||||
public GameRuleService(Plex plugin)
|
||||
{
|
||||
super(false, true);
|
||||
super(plugin, false, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -22,7 +23,7 @@ public class GameRuleService extends AbstractService
|
||||
{
|
||||
for (World world : Bukkit.getWorlds())
|
||||
{
|
||||
GameRuleUtil.commitGlobalGameRules(world);
|
||||
GameRuleUtil.commitGlobalGameRules(plugin, world);
|
||||
PlexLog.log("Set global gamerules for world: " + world.getName());
|
||||
}
|
||||
for (String world : plugin.config.getConfigurationSection("worlds").getKeys(false))
|
||||
@@ -30,7 +31,7 @@ public class GameRuleService extends AbstractService
|
||||
World bukkitWorld = Bukkit.getWorld(world);
|
||||
if (bukkitWorld != null)
|
||||
{
|
||||
GameRuleUtil.commitSpecificGameRules(bukkitWorld);
|
||||
GameRuleUtil.commitSpecificGameRules(plugin, bukkitWorld);
|
||||
PlexLog.log("Set specific gamerules for world: " + world.toLowerCase(Locale.ROOT));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.plex.services.impl;
|
||||
|
||||
import dev.plex.cache.DataUtils;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.punishment.Punishment;
|
||||
import dev.plex.punishment.PunishmentType;
|
||||
@@ -22,9 +23,9 @@ public class TimingService extends AbstractService
|
||||
public static final Map<UUID, Long> nukerCooldown = new HashMap<>();
|
||||
public static final Map<UUID, Long> strikes = new HashMap<>();
|
||||
|
||||
public TimingService()
|
||||
public TimingService(Plex plugin)
|
||||
{
|
||||
super(true, true);
|
||||
super(plugin, true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -48,7 +49,7 @@ public class TimingService extends AbstractService
|
||||
{
|
||||
Punishment punishment = new Punishment(map.getKey(), null);
|
||||
Player player = Bukkit.getPlayer(map.getKey());
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(map.getKey());
|
||||
PlexPlayer plexPlayer = plugin.getPlayerService().getPlayer(map.getKey());
|
||||
punishment.setType(PunishmentType.TEMPBAN);
|
||||
punishment.setReason("You are temporarily banned for five minutes for using a Nuker.");
|
||||
if (player != null)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package dev.plex.services.impl;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.services.AbstractService;
|
||||
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -8,9 +9,9 @@ public class UpdateCheckerService extends AbstractService
|
||||
{
|
||||
private boolean newVersion = false;
|
||||
|
||||
public UpdateCheckerService()
|
||||
public UpdateCheckerService(Plex plugin)
|
||||
{
|
||||
super(true, true);
|
||||
super(plugin, true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user