SteamWar/BauSystem2.0
Archiviert
12
0

Add AutoShutdownListener

Dieser Commit ist enthalten in:
yoyosource 2021-04-17 16:17:21 +02:00
Ursprung 9b781666a9
Commit 307759f257
4 geänderte Dateien mit 93 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -29,13 +29,13 @@ import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
@Linked(LinkageType.LISTENER) @Linked(LinkageType.LISTENER)
public class AFKStopper implements Listener { public class AFKStopperListener implements Listener {
private static final String afkWarning = BauSystem.PREFIX + "§cDieser Server wird bei weiterer Inaktivität in einer Minute gestoppt"; private static final String afkWarning = BauSystem.PREFIX + "§cDieser Server wird bei weiterer Inaktivität in einer Minute gestoppt";
private int minutesAfk; private int minutesAfk;
public AFKStopper() { public AFKStopperListener() {
minutesAfk = 0; minutesAfk = 0;
Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance()); Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance());
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> { Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {

Datei anzeigen

@ -0,0 +1,90 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.world;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.tpslimit.TPSLimitUtils;
import de.steamwar.bausystem.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked;
import de.steamwar.core.Core;
import de.steamwar.scoreboard.SWScoreboard;
import org.bukkit.Bukkit;
import org.bukkit.GameRule;
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;
import java.util.logging.Level;
@Linked(LinkageType.LISTENER)
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);
if (Core.getVersion() == 15) {
Bukkit.getWorlds().get(0).setGameRule(GameRule.REDUCED_DEBUG_INFO, false);
}
}
@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);
autoShutdown = Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), new Runnable() {
int count = 0;
@Override
public void run() {
if (count >= 300) {
Bukkit.shutdown();
return;
}
count++;
try {
if (RamUsage.getUsage() > 0.8) {
Bukkit.shutdown();
}
} catch (Throwable throwable) {
Bukkit.getLogger().log(Level.WARNING, throwable.getMessage(), throwable);
Bukkit.shutdown();
}
}
}, 20, 20);
}
}
}

Datei anzeigen

@ -17,7 +17,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.steamwar.bausystem.utils; package de.steamwar.bausystem.features.world;
import lombok.experimental.UtilityClass; import lombok.experimental.UtilityClass;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;