add noPlayerToggle option

this adds an option to automatically pause/unpause the worldBorder fill based on players connecting or disconnecting from the server
This commit is contained in:
vince 2020-11-25 09:28:34 +08:00
parent 0ee59f99f4
commit 176bebac8f
2 changed files with 28 additions and 0 deletions

View File

@ -49,6 +49,7 @@ public class Config {
private static int fillMemoryTolerance = 500;
private static boolean preventBlockPlace = false;
private static boolean preventMobSpawn = false;
private static boolean noPlayersToggle = false;
// for monitoring plugin efficiency
// public static long timeUsed = 0;
@ -290,6 +291,8 @@ public class Config {
return knockBack;
}
public static boolean NoPlayersToggle() { return noPlayersToggle; }
public static void setTimerTicks(int ticks) {
timerTicks = ticks;
log("Timer delay set to " + timerTicks + " tick(s). That is roughly " + (timerTicks * 50) + "ms / " + (((double) timerTicks * 50.0) / 1000.0) + " seconds.");
@ -531,6 +534,7 @@ public class Config {
fillMemoryTolerance = cfg.getInt("fill-memory-tolerance", 500);
preventBlockPlace = cfg.getBoolean("prevent-block-place");
preventMobSpawn = cfg.getBoolean("prevent-mob-spawn");
noPlayersToggle = cfg.getBoolean("no-players-toggle");
StartBorderTimer();
@ -634,6 +638,7 @@ public class Config {
cfg.set("fill-memory-tolerance", fillMemoryTolerance);
cfg.set("prevent-block-place", preventBlockPlace);
cfg.set("prevent-mob-spawn", preventMobSpawn);
cfg.set("no-players-toggle", noPlayersToggle);
cfg.set("worlds", null);
for (Entry<String, BorderData> stringBorderDataEntry : borders.entrySet()) {

View File

@ -1,11 +1,15 @@
package com.wimbli.WorldBorder;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerPortalEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.ChunkUnloadEvent;
@ -83,4 +87,23 @@ public class WBListener implements Listener {
chunk.setForceLoaded(false);
}
// If player joins and noPlayersToggle is on automatically pause any existing fill task
@EventHandler
public void onPlayerJoin(PlayerJoinEvent e) {
if (!Config.NoPlayersToggle() || Config.fillTask == null || Config.fillTask.isPaused())
return;
Config.fillTask.pause(true);
Config.log("Detected player online. World map generation task automatically paused.");
}
// If no players online and noPlayersToggle is on automatically unpause any existing fill task
@EventHandler
public void onPlayerQuit(PlayerQuitEvent e) {
if (!Config.NoPlayersToggle() || Config.fillTask == null || Bukkit.getOnlinePlayers().size() > 1 || !Config.fillTask.isPaused())
return;
Config.fillTask.pause(false);
Config.log("No players online. World map generation task automatically unpaused.");
}
}