From 4a2afee27d7a61c27d7ecbd4f917610a83948386 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 16 Aug 2024 17:56:00 +0200 Subject: [PATCH 01/11] Fix Badlion restrictions (untested) Fixes #dreamjxnas-bug-325. --- .../steamwar/velocitycore/mods/Badlion.java | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/VelocityCore/src/de/steamwar/velocitycore/mods/Badlion.java b/VelocityCore/src/de/steamwar/velocitycore/mods/Badlion.java index 74c18eb0..59ac26bb 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/mods/Badlion.java +++ b/VelocityCore/src/de/steamwar/velocitycore/mods/Badlion.java @@ -28,23 +28,26 @@ public class Badlion { private final byte[] packet; - public Badlion() { //TODO check if working or (json) modsDisallowed wrapper necessary + public Badlion() { JsonObject disabled = new JsonObject(); disabled.addProperty("disabled", true); + JsonObject modsDisallowed = new JsonObject(); + modsDisallowed.add("Clear Glass", disabled); + modsDisallowed.add("ClearWater", disabled); + modsDisallowed.add("FOV Changer", disabled); + modsDisallowed.add("Hitboxes", disabled); + modsDisallowed.add("LevelHead", disabled); + modsDisallowed.add("MiniMap", disabled); + modsDisallowed.add("MLG Cobweb", disabled); + modsDisallowed.add("Replay", disabled); + modsDisallowed.add("Schematica", disabled); + modsDisallowed.add("ToggleSneak", disabled); + modsDisallowed.add("ToggleSprint", disabled); + modsDisallowed.add("TNT Time", disabled); + JsonObject json = new JsonObject(); - json.add("Clear Glass", disabled); - json.add("ClearWater", disabled); - json.add("FOV Changer", disabled); - json.add("Hitboxes", disabled); - json.add("LevelHead", disabled); - json.add("MiniMap", disabled); - json.add("MLG Cobweb", disabled); - json.add("Replay", disabled); //TODO check if ReplayMod restrictions work - json.add("Schematica", disabled); - json.add("ToggleSneak", disabled); - json.add("ToggleSprint", disabled); - json.add("TNT Time", disabled); + json.add("modsDisallowed", modsDisallowed); packet = json.toString().getBytes(); } From 09a8dc0786b3d6591add3d012d32b8763a8cd656 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 18 Aug 2024 15:36:50 +0200 Subject: [PATCH 02/11] Fix Badlion (tested), Fix Client channel registration and brand detection --- .../steamwar/messages/BungeeCore.properties | 1 - .../messages/BungeeCore_de.properties | 1 - .../velocitycore/listeners/PluginMessage.java | 60 +++++++++---------- .../steamwar/velocitycore/mods/Badlion.java | 10 +--- 4 files changed, 31 insertions(+), 41 deletions(-) diff --git a/VelocityCore/src/de/steamwar/messages/BungeeCore.properties b/VelocityCore/src/de/steamwar/messages/BungeeCore.properties index 6b92436c..5bb5238b 100644 --- a/VelocityCore/src/de/steamwar/messages/BungeeCore.properties +++ b/VelocityCore/src/de/steamwar/messages/BungeeCore.properties @@ -130,7 +130,6 @@ USAGE_ALERT=§8/§7alert §8[§emessage§8] USAGE_IGNORE=§8/§7ignore §8[§eplayer§8] #ModListener -CLIENT_DISALLOWED=Attempted use of client {0} MOD_RED_SING=Attempted use of mod {0} MOD_RED_PLUR=Attempted use of mods:\n{0} MOD_YELLOW_SING=§7Deactivate the mod §e{0}§7 to continue playing on §eSteam§8War§7. diff --git a/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties b/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties index fb4067c8..edc46c77 100644 --- a/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties +++ b/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties @@ -115,7 +115,6 @@ USAGE_ALERT=§8/§7alert §8[§eNachricht§8] USAGE_IGNORE=§8/§7ignore §8[§eSpieler§8] #ModListener -CLIENT_DISALLOWED=Versuchte Benutzung des Clients {0} MOD_RED_SING=Versuchte Benutzung des Mods {0} MOD_RED_PLUR=Versuchte Benutzung der Mods:\n{0} MOD_YELLOW_SING=§7Deaktiviere den Mod §e{0}§7, um weiter auf §eSteam§8War §7spielen zu können. diff --git a/VelocityCore/src/de/steamwar/velocitycore/listeners/PluginMessage.java b/VelocityCore/src/de/steamwar/velocitycore/listeners/PluginMessage.java index cdb36137..bd67e805 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/listeners/PluginMessage.java +++ b/VelocityCore/src/de/steamwar/velocitycore/listeners/PluginMessage.java @@ -22,9 +22,12 @@ package de.steamwar.velocitycore.listeners; import com.lunarclient.apollo.ApolloManager; import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.connection.PluginMessageEvent; +import com.velocitypowered.api.event.player.PlayerChannelRegisterEvent; +import com.velocitypowered.api.event.player.PlayerClientBrandEvent; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.ServerConnection; +import com.velocitypowered.api.proxy.messages.ChannelIdentifier; import com.velocitypowered.api.proxy.messages.ChannelMessageSource; import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier; import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; @@ -373,11 +376,11 @@ public class PluginMessage extends BasicListener { )) register(channel, false, directional(UNKNOWN, DROP)); - register("REGISTER", false, directional(this::serverRegistersChannel, this::clientRegistersChannel)); - register("minecraft:register", false, directional(this::serverRegistersChannel, this::clientRegistersChannel)); + register("REGISTER", false, directional(this::serverRegistersChannel, UNKNOWN)); + register("minecraft:register", false, directional(this::serverRegistersChannel, UNKNOWN)); - register("MC|Brand", false, directional(this::steamWarBrand, this::userBrand)); - register("minecraft:brand", false, directional(this::steamWarBrand, this::userBrand)); + register("MC|Brand", false, directional(this::steamWarBrand, UNKNOWN)); + register("minecraft:brand", false, directional(this::steamWarBrand, UNKNOWN)); //Needs to be registered cause paper refuses to send PluginMessages on unregistered channels... register("sw:bridge", true, directional(onlySWSource(async(event -> NetworkPacket.handle(new ServerMetaInfo((ServerConnection) event.getSource()), event.getData()))), UNKNOWN)); @@ -401,6 +404,15 @@ public class PluginMessage extends BasicListener { // Hackclientlike modsuppressor for labymod: https://github.com/Neocraftr/LabyMod-NeoEssentials (Potentially recognizable from NO Addons/NO Mods?) https://github.com/Neocraftr/LabyMod-NeoEssentials/blob/master/src/main/java/de/neocraftr/neoessentials/utils/BytecodeMethods.java } + @Subscribe + public void onClientChannelRegister(PlayerChannelRegisterEvent event) { + Player player = event.getPlayer(); + + for(ChannelIdentifier channel : event.getChannels()) { + channelRegisterHandlers.getOrDefault(channel.getId(), p -> VelocityCore.getLogger().log(Level.WARNING, () -> p.getUsername() + " registered unknown channel " + channel)).accept(player); + } + } + @Subscribe public void onPluginMessage(PluginMessageEvent event) { event.setResult(PluginMessageEvent.ForwardResult.handled()); @@ -412,6 +424,20 @@ public class PluginMessage extends BasicListener { } } + @Subscribe + public void onClientBrand(PlayerClientBrandEvent event) { + Player player = event.getPlayer(); + + String brand = event.getBrand(); + boolean lunarclient = brand.startsWith("lunarclient:"); + + VelocityCore.getLogger().log(knownBrands.contains(brand) || lunarclient ? Level.INFO : Level.WARNING, () -> player.getUsername() + " joins with brand: " + brand); + if(lunarclient) + lunar.sendRestrictions(player); + if(brand.equals("badlion")) + badlion.sendRestrictions(player); + } + private void registerPassthroughToClient(String... channels) { for(String channel : channels) { channelRegisterHandlers.put(channel, player -> {}); @@ -437,16 +463,6 @@ public class PluginMessage extends BasicListener { VelocityCore.getProxy().getChannelRegistrar().register(channel.indexOf(':') != -1 ? MinecraftChannelIdentifier.from(channel) : new LegacyChannelIdentifier(channel)); } - private void clientRegistersChannel(PluginMessageEvent event) { - Player player = (Player) event.getSource(); - - for(String channel : new String(event.getData()).split("\0")) { - channelRegisterHandlers.getOrDefault(channel, p -> VelocityCore.getLogger().log(Level.WARNING, () -> p.getUsername() + " registered unknown channel " + channel)).accept(player); - } - - PASS_THROUGH.handle(event); - } - private void serverRegistersChannel(PluginMessageEvent event) { Player player = (Player) event.getTarget(); @@ -455,22 +471,6 @@ public class PluginMessage extends BasicListener { send(player, "REGISTER", "minecraft:register", String.join("\0", channels).getBytes()); } - private void userBrand(PluginMessageEvent event) { - Player player = (Player) event.getSource(); - - ByteBuf buf = Unpooled.wrappedBuffer(event.getData()); - String brand = ProtocolUtils.readString(buf); - boolean lunarclient = brand.startsWith("lunarclient:"); - - VelocityCore.getLogger().log(knownBrands.contains(brand) || lunarclient ? Level.INFO : Level.WARNING, () -> player.getUsername() + " joins with brand: " + brand); - if(lunarclient) - lunar.sendRestrictions(player); - if(brand.equals("badlion")) - badlion.sendRestrictions(player); - - PASS_THROUGH.handle(event); - } - private void steamWarBrand(PluginMessageEvent event) { Player player = (Player) event.getTarget(); String brand = Chatter.of(player).parseToLegacy("STEAMWAR_BRAND", "Velocity", player.getCurrentServer().map(serverConnection -> serverConnection.getServerInfo().getName()).orElse(""), new String(event.getData(), 1, event.getData().length - 1)); diff --git a/VelocityCore/src/de/steamwar/velocitycore/mods/Badlion.java b/VelocityCore/src/de/steamwar/velocitycore/mods/Badlion.java index fa48ba7d..57cc3986 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/mods/Badlion.java +++ b/VelocityCore/src/de/steamwar/velocitycore/mods/Badlion.java @@ -22,7 +22,6 @@ package de.steamwar.velocitycore.mods; import com.google.gson.JsonObject; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; -import de.steamwar.messages.Chatter; public class Badlion { // https://github.com/BadlionClient/BadlionClientModAPI @@ -47,17 +46,10 @@ public class Badlion { modsDisallowed.add("ToggleSprint", disabled); modsDisallowed.add("TNT Time", disabled); - JsonObject json = new JsonObject(); - json.add("modsDisallowed", modsDisallowed); - - packet = json.toString().getBytes(); + packet = modsDisallowed.toString().getBytes(); } public void sendRestrictions(Player player) { - // TODO: Remove when Badlion is fixed, or we fixed the Badlion packet - Chatter sender = Chatter.of(player); - player.disconnect(sender.parse("CLIENT_DISALLOWED", "Badlion")); - player.sendPluginMessage(MinecraftChannelIdentifier.from("badlion:mods"), packet); } } From 007f0796aecf5ce8865cf63cf0dfe2a144681d87 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 21 Aug 2024 10:59:09 +0200 Subject: [PATCH 03/11] Add WorldEditSelectionSaver --- .../world/WorldEditSelectionSaver.java | 81 +++++++++++++++++++ .../bausystem/utils/WorldEditUtils.java | 32 ++++++++ 2 files changed, 113 insertions(+) create mode 100644 BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditSelectionSaver.java diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditSelectionSaver.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditSelectionSaver.java new file mode 100644 index 00000000..efd987d0 --- /dev/null +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditSelectionSaver.java @@ -0,0 +1,81 @@ +/* + * 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.bausystem.features.world; + +import com.sk89q.worldedit.regions.RegionSelector; +import de.steamwar.bausystem.shared.Pair; +import de.steamwar.bausystem.utils.WorldEditUtils; +import de.steamwar.linkage.Linked; +import de.steamwar.sql.SteamwarUser; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import java.io.*; +import java.util.List; +import java.util.stream.Collectors; + +@Linked +public class WorldEditSelectionSaver implements Listener { + + private File WORLD_EDIT_SELECTIONS = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "world_edit_selections"); + + { + WORLD_EDIT_SELECTIONS.mkdir(); + } + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) { + SteamwarUser steamwarUser = SteamwarUser.get(event.getPlayer().getUniqueId()); + File file = new File(WORLD_EDIT_SELECTIONS, steamwarUser.getId() + ""); + if (!file.exists()) return; + try { + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file))); + Class clazz = (Class) Class.forName(bufferedReader.readLine()); + List locations = bufferedReader.lines() + .map(s -> s.split(" ")) + .map(strings -> new Location(event.getPlayer().getWorld(), Integer.parseInt(strings[0]), Integer.parseInt(strings[1]), Integer.parseInt(strings[2]))) + .collect(Collectors.toList()); + WorldEditUtils.setVertices(event.getPlayer(), clazz, locations); + } catch (IOException | ClassNotFoundException e) { + file.delete(); + } + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + SteamwarUser steamwarUser = SteamwarUser.get(event.getPlayer().getUniqueId()); + Pair, List> data = WorldEditUtils.getVertices(event.getPlayer()); + File file = new File(WORLD_EDIT_SELECTIONS, steamwarUser.getId() + ""); + try { + BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file))); + bufferedWriter.write(data.getKey().getTypeName() + "\n"); + for (Location location : data.getValue()) { + bufferedWriter.write(location.getBlockX() + " " + location.getBlockY() + " " + location.getBlockZ() + "\n"); + } + bufferedWriter.close(); + } catch (IOException e) { + file.delete(); + } + } +} diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/WorldEditUtils.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/WorldEditUtils.java index ec464ef4..2d104e9e 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/WorldEditUtils.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/WorldEditUtils.java @@ -19,17 +19,21 @@ package de.steamwar.bausystem.utils; +import com.comphenix.tinyprotocol.Reflection; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.IncompleteRegionException; +import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.extension.factory.PatternFactory; +import com.sk89q.worldedit.extension.platform.permission.ActorSelectorLimits; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.internal.registry.InputParser; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.RegionSelector; +import com.sk89q.worldedit.regions.selector.limit.SelectorLimits; import de.steamwar.bausystem.shared.Pair; import lombok.SneakyThrows; import lombok.experimental.UtilityClass; @@ -37,6 +41,9 @@ import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Player; +import java.util.List; +import java.util.stream.Collectors; + @UtilityClass public class WorldEditUtils { @@ -77,6 +84,31 @@ public class WorldEditUtils { return WorldEdit.getInstance().getPatternFactory(); } + public Pair, List> getVertices(Player player) { + RegionSelector regionSelector = WorldEdit.getInstance() + .getSessionManager() + .get(BukkitAdapter.adapt(player)) + .getRegionSelector(BukkitAdapter.adapt(player.getWorld())); + return new Pair<>(regionSelector.getClass(), regionSelector.getVertices().stream().map(blockVector3 -> adapt(player.getWorld(), blockVector3)).collect(Collectors.toList())); + } + + public void setVertices(Player player, Class clazz, List vertices) { + LocalSession localSession = WorldEdit.getInstance() + .getSessionManager() + .get(BukkitAdapter.adapt(player)); + + RegionSelector regionSelector = (RegionSelector) Reflection.newInstance(clazz); + localSession.setRegionSelector(BukkitAdapter.adapt(player.getWorld()), regionSelector); + + if (vertices.isEmpty()) return; + + SelectorLimits selectorLimits = ActorSelectorLimits.forActor(BukkitAdapter.adapt(player)); + regionSelector.selectPrimary(BukkitAdapter.adapt(vertices.get(0)).toBlockPoint(), selectorLimits); + for (int i = 1; i < vertices.size(); i++) { + regionSelector.selectSecondary(BukkitAdapter.adapt(vertices.get(0)).toBlockPoint(), selectorLimits); + } + } + public Pair getSelection(Player player) { RegionSelector regionSelector = WorldEdit.getInstance() .getSessionManager() From 6a2a3314c65cb7023304639c6e3274131371d9e5 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 21 Aug 2024 11:04:28 +0200 Subject: [PATCH 04/11] Fix SpecialItem.getRandomItem --- .../src/de/steamwar/misslewars/items/SpecialItem.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MissileWars/src/de/steamwar/misslewars/items/SpecialItem.java b/MissileWars/src/de/steamwar/misslewars/items/SpecialItem.java index de8b6847..a287958b 100644 --- a/MissileWars/src/de/steamwar/misslewars/items/SpecialItem.java +++ b/MissileWars/src/de/steamwar/misslewars/items/SpecialItem.java @@ -111,11 +111,11 @@ public abstract class SpecialItem { } public static ItemStack getRandomItem() { - if (Config.MissileChance == 0 || consecutiveSupportItems > 1) { - consecutiveSupportItems = 0; + if (Config.MissileChance == 0) { return supportItems.get(random.nextInt(supportItems.size())).getItem(); } - if (Config.MissileChance == 1) { + if (Config.MissileChance == 1 || consecutiveSupportItems > 1) { + consecutiveSupportItems = 0; return missileItems.get(random.nextInt(missileItems.size())).getItem(); } From f375aa68b508dfd66550761e5ab3876338623f4f Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 21 Aug 2024 18:26:33 +0200 Subject: [PATCH 05/11] Fix things --- .../features/world/WorldEditSelectionSaver.java | 10 +++++++--- .../de/steamwar/bausystem/utils/WorldEditUtils.java | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditSelectionSaver.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditSelectionSaver.java index efd987d0..7a1e2f4e 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditSelectionSaver.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditSelectionSaver.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.features.world; import com.sk89q.worldedit.regions.RegionSelector; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.shared.Pair; import de.steamwar.bausystem.utils.WorldEditUtils; import de.steamwar.linkage.Linked; @@ -33,6 +34,7 @@ import org.bukkit.event.player.PlayerQuitEvent; import java.io.*; import java.util.List; +import java.util.logging.Level; import java.util.stream.Collectors; @Linked @@ -47,7 +49,7 @@ public class WorldEditSelectionSaver implements Listener { @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { SteamwarUser steamwarUser = SteamwarUser.get(event.getPlayer().getUniqueId()); - File file = new File(WORLD_EDIT_SELECTIONS, steamwarUser.getId() + ""); + File file = new File(WORLD_EDIT_SELECTIONS, Integer.toString(steamwarUser.getId())); if (!file.exists()) return; try { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file))); @@ -58,6 +60,7 @@ public class WorldEditSelectionSaver implements Listener { .collect(Collectors.toList()); WorldEditUtils.setVertices(event.getPlayer(), clazz, locations); } catch (IOException | ClassNotFoundException e) { + BauSystem.getInstance().getLogger().log(Level.SEVERE, e.getMessage(), e); file.delete(); } } @@ -69,12 +72,13 @@ public class WorldEditSelectionSaver implements Listener { File file = new File(WORLD_EDIT_SELECTIONS, steamwarUser.getId() + ""); try { BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file))); - bufferedWriter.write(data.getKey().getTypeName() + "\n"); + bufferedWriter.write(data.getKey().getTypeName()); for (Location location : data.getValue()) { - bufferedWriter.write(location.getBlockX() + " " + location.getBlockY() + " " + location.getBlockZ() + "\n"); + bufferedWriter.write("\n" + location.getBlockX() + " " + location.getBlockY() + " " + location.getBlockZ()); } bufferedWriter.close(); } catch (IOException e) { + BauSystem.getInstance().getLogger().log(Level.SEVERE, e.getMessage(), e); file.delete(); } } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/WorldEditUtils.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/WorldEditUtils.java index 2d104e9e..ba47c1ed 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/WorldEditUtils.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/WorldEditUtils.java @@ -105,7 +105,7 @@ public class WorldEditUtils { SelectorLimits selectorLimits = ActorSelectorLimits.forActor(BukkitAdapter.adapt(player)); regionSelector.selectPrimary(BukkitAdapter.adapt(vertices.get(0)).toBlockPoint(), selectorLimits); for (int i = 1; i < vertices.size(); i++) { - regionSelector.selectSecondary(BukkitAdapter.adapt(vertices.get(0)).toBlockPoint(), selectorLimits); + regionSelector.selectSecondary(BukkitAdapter.adapt(vertices.get(i)).toBlockPoint(), selectorLimits); } } From 76aa61934cb7a72a689d8b75e9b2c1188b71ebab Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 21 Aug 2024 20:27:36 +0200 Subject: [PATCH 06/11] 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"); } } From 42fd35077b79cf20750423bec003312b889328a1 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 21 Aug 2024 20:31:21 +0200 Subject: [PATCH 07/11] Fix PR stuff --- .../bausystem/features/world/WorldEditSelectionSaver.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditSelectionSaver.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditSelectionSaver.java index 7a1e2f4e..397f7d5f 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditSelectionSaver.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditSelectionSaver.java @@ -69,7 +69,7 @@ public class WorldEditSelectionSaver implements Listener { public void onPlayerQuit(PlayerQuitEvent event) { SteamwarUser steamwarUser = SteamwarUser.get(event.getPlayer().getUniqueId()); Pair, List> data = WorldEditUtils.getVertices(event.getPlayer()); - File file = new File(WORLD_EDIT_SELECTIONS, steamwarUser.getId() + ""); + File file = new File(WORLD_EDIT_SELECTIONS, Integer.toString(steamwarUser.getId())); try { BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file))); bufferedWriter.write(data.getKey().getTypeName()); From fde70029c5cea2386525f767c4574d21aa5e7c92 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 21 Aug 2024 20:55:03 +0200 Subject: [PATCH 08/11] Fix WorldEditUtils.setVertices --- .../src/de/steamwar/bausystem/utils/WorldEditUtils.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/WorldEditUtils.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/WorldEditUtils.java index ba47c1ed..81fe6723 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/WorldEditUtils.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/WorldEditUtils.java @@ -97,7 +97,8 @@ public class WorldEditUtils { .getSessionManager() .get(BukkitAdapter.adapt(player)); - RegionSelector regionSelector = (RegionSelector) Reflection.newInstance(clazz); + Reflection.ConstructorInvoker constructorInvoker = Reflection.getConstructor(clazz, com.sk89q.worldedit.world.World.class); + RegionSelector regionSelector = (RegionSelector) constructorInvoker.invoke(BukkitAdapter.adapt(player.getWorld())); localSession.setRegionSelector(BukkitAdapter.adapt(player.getWorld()), regionSelector); if (vertices.isEmpty()) return; From 49fa6c364f15b43d52efe7df4ec8b34efe69c67b Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 21 Aug 2024 21:07:25 +0200 Subject: [PATCH 09/11] Hotfix WorldEditUtils.getVertices --- .../src/de/steamwar/bausystem/utils/WorldEditUtils.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/WorldEditUtils.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/WorldEditUtils.java index 81fe6723..25029fae 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/WorldEditUtils.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/WorldEditUtils.java @@ -42,6 +42,7 @@ import org.bukkit.World; import org.bukkit.entity.Player; import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; @UtilityClass @@ -89,7 +90,11 @@ public class WorldEditUtils { .getSessionManager() .get(BukkitAdapter.adapt(player)) .getRegionSelector(BukkitAdapter.adapt(player.getWorld())); - return new Pair<>(regionSelector.getClass(), regionSelector.getVertices().stream().map(blockVector3 -> adapt(player.getWorld(), blockVector3)).collect(Collectors.toList())); + return new Pair<>(regionSelector.getClass(), regionSelector.getVertices() + .stream() + .filter(Objects::nonNull) + .map(blockVector3 -> adapt(player.getWorld(), blockVector3)) + .collect(Collectors.toList())); } public void setVertices(Player player, Class clazz, List vertices) { From 20acd7abbed480931c5023cfe81889557686e0b7 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 21 Aug 2024 21:15:00 +0200 Subject: [PATCH 10/11] Fix WorldEditSelectionSaver finally --- .../features/world/WorldEditSelectionSaver.java | 8 ++++++-- .../steamwar/bausystem/utils/WorldEditUtils.java | 15 +++++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditSelectionSaver.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditSelectionSaver.java index 397f7d5f..3b80bf53 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditSelectionSaver.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditSelectionSaver.java @@ -56,7 +56,7 @@ public class WorldEditSelectionSaver implements Listener { Class clazz = (Class) Class.forName(bufferedReader.readLine()); List locations = bufferedReader.lines() .map(s -> s.split(" ")) - .map(strings -> new Location(event.getPlayer().getWorld(), Integer.parseInt(strings[0]), Integer.parseInt(strings[1]), Integer.parseInt(strings[2]))) + .map(strings -> strings.length != 3 ? null : new Location(event.getPlayer().getWorld(), Integer.parseInt(strings[0]), Integer.parseInt(strings[1]), Integer.parseInt(strings[2]))) .collect(Collectors.toList()); WorldEditUtils.setVertices(event.getPlayer(), clazz, locations); } catch (IOException | ClassNotFoundException e) { @@ -74,7 +74,11 @@ public class WorldEditSelectionSaver implements Listener { BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file))); bufferedWriter.write(data.getKey().getTypeName()); for (Location location : data.getValue()) { - bufferedWriter.write("\n" + location.getBlockX() + " " + location.getBlockY() + " " + location.getBlockZ()); + if (location == null) { + bufferedWriter.write("\n"); + } else { + bufferedWriter.write("\n" + location.getBlockX() + " " + location.getBlockY() + " " + location.getBlockZ()); + } } bufferedWriter.close(); } catch (IOException e) { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/WorldEditUtils.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/WorldEditUtils.java index 25029fae..4d20f346 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/WorldEditUtils.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/WorldEditUtils.java @@ -42,7 +42,6 @@ import org.bukkit.World; import org.bukkit.entity.Player; import java.util.List; -import java.util.Objects; import java.util.stream.Collectors; @UtilityClass @@ -92,8 +91,7 @@ public class WorldEditUtils { .getRegionSelector(BukkitAdapter.adapt(player.getWorld())); return new Pair<>(regionSelector.getClass(), regionSelector.getVertices() .stream() - .filter(Objects::nonNull) - .map(blockVector3 -> adapt(player.getWorld(), blockVector3)) + .map(blockVector3 -> blockVector3 == null ? null : adapt(player.getWorld(), blockVector3)) .collect(Collectors.toList())); } @@ -109,9 +107,14 @@ public class WorldEditUtils { if (vertices.isEmpty()) return; SelectorLimits selectorLimits = ActorSelectorLimits.forActor(BukkitAdapter.adapt(player)); - regionSelector.selectPrimary(BukkitAdapter.adapt(vertices.get(0)).toBlockPoint(), selectorLimits); - for (int i = 1; i < vertices.size(); i++) { - regionSelector.selectSecondary(BukkitAdapter.adapt(vertices.get(i)).toBlockPoint(), selectorLimits); + for (int i = 0; i < vertices.size(); i++) { + Location location = vertices.get(i); + if (location == null) continue; + if (i == 0) { + regionSelector.selectPrimary(BukkitAdapter.adapt(location).toBlockPoint(), selectorLimits); + } else { + regionSelector.selectSecondary(BukkitAdapter.adapt(location).toBlockPoint(), selectorLimits); + } } } From a75a1e8e1081cfe4c385a277f3966ff28af8fbae Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 22 Aug 2024 17:01:53 +0200 Subject: [PATCH 11/11] Hotfix WorldEditSelectionSaver --- .../bausystem/features/world/WorldEditSelectionSaver.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditSelectionSaver.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditSelectionSaver.java index 3b80bf53..1d989226 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditSelectionSaver.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditSelectionSaver.java @@ -24,6 +24,7 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.shared.Pair; import de.steamwar.bausystem.utils.WorldEditUtils; import de.steamwar.linkage.Linked; +import de.steamwar.linkage.MinVersion; import de.steamwar.sql.SteamwarUser; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -31,6 +32,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; +import org.checkerframework.checker.units.qual.min; import java.io.*; import java.util.List; @@ -38,6 +40,7 @@ import java.util.logging.Level; import java.util.stream.Collectors; @Linked +@MinVersion(18) public class WorldEditSelectionSaver implements Listener { private File WORLD_EDIT_SELECTIONS = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "world_edit_selections");