From a8aa431210b5f8e203a3beeef8ab98764634b442 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 1 Sep 2023 16:33:10 +0200 Subject: [PATCH] Update AFKStopperListener Signed-off-by: yoyosource --- .../features/world/AFKStopperListener.java | 17 ++-- .../features/world/AutoShutdownListener.java | 77 ------------------- 2 files changed, 12 insertions(+), 82 deletions(-) delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/world/AutoShutdownListener.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/AFKStopperListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/AFKStopperListener.java index ec539714..dbb04aaf 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/AFKStopperListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/AFKStopperListener.java @@ -25,6 +25,7 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerMoveEvent; @Linked @@ -41,17 +42,18 @@ public class AFKStopperListener implements Listener { if (RamUsage.getLoad() < 50.0 && RamUsage.getUsage() < 0.6) { minutesAfk = 0; return; + } else if (Bukkit.getOnlinePlayers().isEmpty()) { + Bukkit.shutdown(); + return; } switch (minutesAfk) { + case 30: + Bukkit.shutdown(); + break; case 5: - if (Bukkit.getOnlinePlayers().isEmpty()) { - Bukkit.shutdown(); - return; - } for (Player p : Bukkit.getOnlinePlayers()) { p.kickPlayer(BauSystem.MESSAGE.parse("AFK_KICK_MESSAGE", p)); } - break; case 4: BauSystem.MESSAGE.broadcast("AFK_WARNING_MESSAGE"); default: @@ -70,4 +72,9 @@ public class AFKStopperListener implements Listener { minutesAfk = 0; } } + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) { + event.getPlayer().setOp(true); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/AutoShutdownListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/AutoShutdownListener.java deleted file mode 100644 index 0fce31c9..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/AutoShutdownListener.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.world; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.tpslimit.TPSLimitUtils; -import de.steamwar.linkage.Linked; -import de.steamwar.scoreboard.SWScoreboard; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerLoginEvent; -import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.scheduler.BukkitTask; - -@Linked -public class AutoShutdownListener implements Listener { - - private BukkitTask autoShutdown; - - @EventHandler - public void onJoin(PlayerLoginEvent e) { - if (autoShutdown != null) { - autoShutdown.cancel(); - autoShutdown = null; - } - - Player p = e.getPlayer(); - p.setOp(true); - } - - @EventHandler - public void onLeave(PlayerQuitEvent e) { - Player p = e.getPlayer(); - SWScoreboard.removeScoreboard(p); - if (Bukkit.getOnlinePlayers().isEmpty() || (Bukkit.getOnlinePlayers().size() == 1 && Bukkit.getOnlinePlayers().contains(p))) { - if (autoShutdown != null) { - autoShutdown.cancel(); - } - TPSLimitUtils.setTPS(20.0); - if (false) { - Bukkit.shutdown(); - return; - } - autoShutdown = Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), new Runnable() { - int count = 0; - - @Override - public void run() { - if (count >= 300) { - Bukkit.shutdown(); - return; - } - count++; - } - }, 20, 20); - } - } -}