From 76aa61934cb7a72a689d8b75e9b2c1188b71ebab Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 21 Aug 2024 20:27:36 +0200 Subject: [PATCH] Add CRIUSleepEvent and CRIUWakeupEvent Fix AFKStopperListener --- .../src/de/steamwar/bausystem/BauSystem.java | 2 +- .../features/world/AFKStopperListener.java | 6 ++++ .../features/world/AntiBauAddMemberFix.java | 7 +++- .../src/de/steamwar/core/CRIUSleepEvent.java | 36 +++++++++++++++++++ .../src/de/steamwar/core/CRIUWakeupEvent.java | 36 +++++++++++++++++++ .../src/de/steamwar/core/CheckpointUtils.java | 4 +-- 6 files changed, 87 insertions(+), 4 deletions(-) create mode 100644 SpigotCore/SpigotCore_Main/src/de/steamwar/core/CRIUSleepEvent.java create mode 100644 SpigotCore/SpigotCore_Main/src/de/steamwar/core/CRIUWakeupEvent.java diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 9afe6154..0b1b160c 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -72,7 +72,7 @@ import java.util.function.Consumer; import java.util.logging.Level; import java.util.stream.Collectors; -public class BauSystem extends JavaPlugin implements Listener { +public class BauSystem extends JavaPlugin { // This should be treated as final! public static Message MESSAGE; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/AFKStopperListener.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/AFKStopperListener.java index 479dd394..60a9651b 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/AFKStopperListener.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/AFKStopperListener.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.features.world; import de.steamwar.bausystem.BauSystem; +import de.steamwar.core.CRIUWakeupEvent; import de.steamwar.core.CheckpointUtils; import de.steamwar.linkage.Linked; 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()))) CheckpointUtils.freeze(); } + + @EventHandler + public void onCRIUWakeup(CRIUWakeupEvent event) { + lastMovementTime = System.currentTimeMillis(); + } } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiBauAddMemberFix.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiBauAddMemberFix.java index 97b9455c..32888912 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiBauAddMemberFix.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiBauAddMemberFix.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem.features.world; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.config.BauServer; +import de.steamwar.core.CRIUWakeupEvent; import de.steamwar.linkage.Linked; import de.steamwar.sql.BauweltMember; import de.steamwar.sql.SteamwarUser; @@ -32,7 +33,6 @@ import org.bukkit.event.player.PlayerJoinEvent; @Linked public class AntiBauAddMemberFix implements Listener { - @EventHandler(priority = EventPriority.LOW) public void onPlayerJoin(PlayerJoinEvent event) { 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!"); } } + + @EventHandler + public void onCRIUWakeup(CRIUWakeupEvent event) { + BauweltMember.clear(); + } } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CRIUSleepEvent.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CRIUSleepEvent.java new file mode 100644 index 00000000..eb8faaf0 --- /dev/null +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CRIUSleepEvent.java @@ -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 . + */ + +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; + } +} diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CRIUWakeupEvent.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CRIUWakeupEvent.java new file mode 100644 index 00000000..90a6ee32 --- /dev/null +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CRIUWakeupEvent.java @@ -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 . + */ + +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; + } +} diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtils.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtils.java index 7b3b4b76..d65d7311 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtils.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtils.java @@ -22,7 +22,6 @@ package de.steamwar.core; import com.comphenix.tinyprotocol.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import com.viaversion.viaversion.api.Via; -import de.steamwar.sql.BauweltMember; import de.steamwar.sql.internal.Statement; import io.netty.channel.ChannelFuture; import org.bukkit.Bukkit; @@ -94,6 +93,7 @@ public class CheckpointUtils { private static final Reflection.FieldAccessor 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 void freezeInternal(Path path) throws Exception { + Bukkit.getPluginManager().callEvent(new CRIUSleepEvent()); Bukkit.getWorlds().forEach(FlatteningWrapper.impl::syncSave); Statement.closeAll(); @@ -141,7 +141,7 @@ public class CheckpointUtils { } Via.getManager().getInjector().inject(); - BauweltMember.clear(); + Bukkit.getPluginManager().callEvent(new CRIUWakeupEvent()); Core.getInstance().getLogger().log(Level.INFO, "Checkpoint restored"); } }