Add CRIUSleepEvent and CRIUWakeupEvent

Fix AFKStopperListener
This commit is contained in:
2024-08-21 20:27:36 +02:00
parent b2ff042e4a
commit 76aa61934c
6 changed files with 87 additions and 4 deletions
@@ -72,7 +72,7 @@ import java.util.function.Consumer;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class BauSystem extends JavaPlugin implements Listener { public class BauSystem extends JavaPlugin {
// This should be treated as final! // This should be treated as final!
public static Message MESSAGE; public static Message MESSAGE;
@@ -20,6 +20,7 @@
package de.steamwar.bausystem.features.world; package de.steamwar.bausystem.features.world;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.core.CRIUWakeupEvent;
import de.steamwar.core.CheckpointUtils; import de.steamwar.core.CheckpointUtils;
import de.steamwar.linkage.Linked; import de.steamwar.linkage.Linked;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@@ -69,4 +70,9 @@ public class AFKStopperListener implements Listener {
if(Bukkit.getOnlinePlayers().isEmpty() || (Bukkit.getOnlinePlayers().size() == 1 && Bukkit.getOnlinePlayers().contains(event.getPlayer()))) if(Bukkit.getOnlinePlayers().isEmpty() || (Bukkit.getOnlinePlayers().size() == 1 && Bukkit.getOnlinePlayers().contains(event.getPlayer())))
CheckpointUtils.freeze(); CheckpointUtils.freeze();
} }
@EventHandler
public void onCRIUWakeup(CRIUWakeupEvent event) {
lastMovementTime = System.currentTimeMillis();
}
} }
@@ -21,6 +21,7 @@ package de.steamwar.bausystem.features.world;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.config.BauServer; import de.steamwar.bausystem.config.BauServer;
import de.steamwar.core.CRIUWakeupEvent;
import de.steamwar.linkage.Linked; import de.steamwar.linkage.Linked;
import de.steamwar.sql.BauweltMember; import de.steamwar.sql.BauweltMember;
import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.SteamwarUser;
@@ -32,7 +33,6 @@ import org.bukkit.event.player.PlayerJoinEvent;
@Linked @Linked
public class AntiBauAddMemberFix implements Listener { public class AntiBauAddMemberFix implements Listener {
@EventHandler(priority = EventPriority.LOW) @EventHandler(priority = EventPriority.LOW)
public void onPlayerJoin(PlayerJoinEvent event) { public void onPlayerJoin(PlayerJoinEvent event) {
if (BauSystem.DEV_SERVER) return; if (BauSystem.DEV_SERVER) return;
@@ -44,4 +44,9 @@ public class AntiBauAddMemberFix implements Listener {
throw new SecurityException("The player " + event.getPlayer().getName() + " joined on the server of " + SteamwarUser.get(BauServer.getInstance().getOwnerID()).getUserName() + " without being added!"); throw new SecurityException("The player " + event.getPlayer().getName() + " joined on the server of " + SteamwarUser.get(BauServer.getInstance().getOwnerID()).getUserName() + " without being added!");
} }
} }
@EventHandler
public void onCRIUWakeup(CRIUWakeupEvent event) {
BauweltMember.clear();
}
} }
@@ -0,0 +1,36 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 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.core;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class CRIUSleepEvent extends Event {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}
@@ -0,0 +1,36 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 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.core;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class CRIUWakeupEvent extends Event {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}
@@ -22,7 +22,6 @@ package de.steamwar.core;
import com.comphenix.tinyprotocol.Reflection; import com.comphenix.tinyprotocol.Reflection;
import com.comphenix.tinyprotocol.TinyProtocol; import com.comphenix.tinyprotocol.TinyProtocol;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import de.steamwar.sql.BauweltMember;
import de.steamwar.sql.internal.Statement; import de.steamwar.sql.internal.Statement;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@@ -94,6 +93,7 @@ public class CheckpointUtils {
private static final Reflection.FieldAccessor<List> channelFutures = Reflection.getField(TinyProtocol.serverConnection, List.class, 0, ChannelFuture.class); private static final Reflection.FieldAccessor<List> channelFutures = Reflection.getField(TinyProtocol.serverConnection, List.class, 0, ChannelFuture.class);
private static final Reflection.MethodInvoker bind = Reflection.getMethod(TinyProtocol.serverConnection, null, InetAddress.class, int.class); private static final Reflection.MethodInvoker bind = Reflection.getMethod(TinyProtocol.serverConnection, null, InetAddress.class, int.class);
private static void freezeInternal(Path path) throws Exception { private static void freezeInternal(Path path) throws Exception {
Bukkit.getPluginManager().callEvent(new CRIUSleepEvent());
Bukkit.getWorlds().forEach(FlatteningWrapper.impl::syncSave); Bukkit.getWorlds().forEach(FlatteningWrapper.impl::syncSave);
Statement.closeAll(); Statement.closeAll();
@@ -141,7 +141,7 @@ public class CheckpointUtils {
} }
Via.getManager().getInjector().inject(); Via.getManager().getInjector().inject();
BauweltMember.clear(); Bukkit.getPluginManager().callEvent(new CRIUWakeupEvent());
Core.getInstance().getLogger().log(Level.INFO, "Checkpoint restored"); Core.getInstance().getLogger().log(Level.INFO, "Checkpoint restored");
} }
} }