Fixed player disconnections not being logged on server shutdown

This commit is contained in:
Intelli 2022-02-09 19:34:06 -07:00
parent 6a978128af
commit 40561e41c0
2 changed files with 16 additions and 3 deletions

View File

@ -4,6 +4,7 @@ import java.io.File;
import org.bstats.bukkit.MetricsLite;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
@ -17,6 +18,7 @@ import net.coreprotect.database.Database;
import net.coreprotect.language.Language;
import net.coreprotect.language.Phrase;
import net.coreprotect.listener.ListenerHandler;
import net.coreprotect.listener.player.PlayerQuitListener;
import net.coreprotect.thread.CacheHandler;
import net.coreprotect.thread.NetworkHandler;
import net.coreprotect.utility.Chat;
@ -158,6 +160,13 @@ public final class CoreProtect extends JavaPlugin {
private static void safeShutdown(CoreProtect plugin) {
try {
/* if server is stopping, log disconnections of online players */
if (plugin.getServer().isStopping()) {
for (Player player : plugin.getServer().getOnlinePlayers()) {
PlayerQuitListener.queuePlayerQuit(player);
}
}
ConfigHandler.serverRunning = false;
long shutdownTime = System.currentTimeMillis();
long alertTime = shutdownTime + (10 * 1000);

View File

@ -11,12 +11,16 @@ import net.coreprotect.consumer.Queue;
public final class PlayerQuitListener extends Queue implements Listener {
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();
public static void queuePlayerQuit(Player player) {
if (Config.getConfig(player.getWorld()).PLAYER_SESSIONS) {
int time = (int) (System.currentTimeMillis() / 1000L);
Queue.queuePlayerQuit(player, time);
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerQuit(PlayerQuitEvent event) {
queuePlayerQuit(event.getPlayer());
}
}