From 22a8ca4aea23e9f51334e76c8c8bdb1d65090e19 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 24 Dec 2024 14:55:27 +0100 Subject: [PATCH 1/2] Move ViaVersion to Proxy --- BauSystem/BauSystem_Main/build.gradle.kts | 1 - .../BauSystem_Main/src/BauSystem.properties | 4 +- .../src/BauSystem_de.properties | 4 +- .../bausystem/utils/VersionAnnouncer.java | 49 ----------- BauSystem/BauSystem_Main/src/plugin.yml | 2 - SpigotCore/SpigotCore_9/build.gradle.kts | 2 - .../de/steamwar/core/BountifulWrapper9.java | 4 +- SpigotCore/SpigotCore_Main/build.gradle.kts | 1 - .../de/steamwar/core/CheckpointUtilsJ9.java | 3 - .../src/de/steamwar/core/Core.java | 3 - .../core/events/PartialChunkFixer.java | 84 ------------------- SpigotCore/SpigotCore_Main/src/plugin.yml | 1 - .../src/de/steamwar/persistent/Subserver.java | 10 +-- VelocityCore/build.gradle.kts | 3 +- .../steamwar/messages/BungeeCore.properties | 3 + .../messages/BungeeCore_de.properties | 3 + .../steamwar/velocitycore/GameModeConfig.java | 9 +- .../src/de/steamwar/velocitycore/Node.java | 14 ++-- .../steamwar/velocitycore/ServerStarter.java | 14 ++-- .../steamwar/velocitycore/ServerVersion.java | 29 ++++--- .../steamwar/velocitycore/VelocityCore.java | 1 + .../listeners/VersionAnnouncer.java | 47 +++++++++++ settings.gradle.kts | 3 +- 23 files changed, 104 insertions(+), 190 deletions(-) delete mode 100644 BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/VersionAnnouncer.java delete mode 100644 SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/PartialChunkFixer.java create mode 100644 VelocityCore/src/de/steamwar/velocitycore/listeners/VersionAnnouncer.java diff --git a/BauSystem/BauSystem_Main/build.gradle.kts b/BauSystem/BauSystem_Main/build.gradle.kts index 8f46699d..5b8f0a89 100644 --- a/BauSystem/BauSystem_Main/build.gradle.kts +++ b/BauSystem/BauSystem_Main/build.gradle.kts @@ -38,7 +38,6 @@ dependencies { compileOnly(libs.spigotapi) compileOnly(libs.axiom) compileOnly(libs.authlib) - compileOnly(libs.viaapi) compileOnly(libs.fawe18) diff --git a/BauSystem/BauSystem_Main/src/BauSystem.properties b/BauSystem/BauSystem_Main/src/BauSystem.properties index c9116dce..929d0c67 100644 --- a/BauSystem/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem/BauSystem_Main/src/BauSystem.properties @@ -1013,6 +1013,4 @@ XRAY_OFF=§cXray deactivated COLORREPLACE_HELP=§8//§ecolorreplace §8[§7color§8] §8[§7color§8] §8- §7Replace all blocks of one color with another TYPEREPLACE_HELP=§8//§etypereplace §8[§7type§8] §8[§7type§8] §8- §7Replace all blocks of one type with another # Schematic -SCHEMATIC_GUI_ITEM=§eSchematics -#VersionAnnouncer -SERVER_VERSION=§7This server runs on Minecraft version §e{0} \ No newline at end of file +SCHEMATIC_GUI_ITEM=§eSchematics \ No newline at end of file diff --git a/BauSystem/BauSystem_Main/src/BauSystem_de.properties b/BauSystem/BauSystem_Main/src/BauSystem_de.properties index 45e60f84..4cb20d95 100644 --- a/BauSystem/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem/BauSystem_Main/src/BauSystem_de.properties @@ -954,6 +954,4 @@ XRAY_OFF=§cXray deaktiviert COLORREPLACE_HELP=§8//§ecolorreplace §8[§7color§8] §8[§7color§8] §8- §7Ersetzt eine Farbe mit einer anderen TYPEREPLACE_HELP=§8//§etyreplace §8[§7type§8] §8[§7type§8] §8- §7Ersetzt einen Blockgruppe mit einer anderen # Schematics -SCHEMATIC_GUI_ITEM=§eSchematics -#VersionAnnouncer -SERVER_VERSION=§7Dieser Server läuft auf Minecraft-Version §e{0} \ No newline at end of file +SCHEMATIC_GUI_ITEM=§eSchematics \ No newline at end of file diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/VersionAnnouncer.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/VersionAnnouncer.java deleted file mode 100644 index ee9e91be..00000000 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/VersionAnnouncer.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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.utils; - -import com.viaversion.viaversion.api.Via; -import com.viaversion.viaversion.api.ViaAPI; -import de.steamwar.bausystem.BauSystem; -import de.steamwar.linkage.Linked; -import net.md_5.bungee.api.ChatMessageType; -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; - -@Linked -public class VersionAnnouncer implements Listener { - - private final String versionString = Bukkit.getBukkitVersion().split("-", 2)[0]; - - @SuppressWarnings("unchecked") - private final ViaAPI via = Via.getAPI(); - - @EventHandler - public void onJoin(PlayerJoinEvent event) { - Player player = event.getPlayer(); - if(via.getServerVersion().supportedVersions().contains(via.getPlayerVersion(player))) - return; - - BauSystem.MESSAGE.sendPrefixless("SERVER_VERSION", player, ChatMessageType.ACTION_BAR, versionString); - } -} diff --git a/BauSystem/BauSystem_Main/src/plugin.yml b/BauSystem/BauSystem_Main/src/plugin.yml index 53585eaa..71b08d95 100644 --- a/BauSystem/BauSystem_Main/src/plugin.yml +++ b/BauSystem/BauSystem_Main/src/plugin.yml @@ -2,8 +2,6 @@ name: BauSystem authors: [ Lixfel, YoyoNow, Chaoscaot, Zeanon, D4rkr34lm ] version: "2.0" depend: [ WorldEdit, SpigotCore ] -softdepend: - - ViaVersion load: POSTWORLD main: de.steamwar.bausystem.BauSystem api-version: "1.13" diff --git a/SpigotCore/SpigotCore_9/build.gradle.kts b/SpigotCore/SpigotCore_9/build.gradle.kts index 3463498a..a888faf1 100644 --- a/SpigotCore/SpigotCore_9/build.gradle.kts +++ b/SpigotCore/SpigotCore_9/build.gradle.kts @@ -26,6 +26,4 @@ dependencies { compileOnly(project(":SpigotCore:SpigotCore_8", "default")) compileOnly(libs.nms9) - - compileOnly(libs.viaapi) } diff --git a/SpigotCore/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java b/SpigotCore/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java index fa126698..d35e4239 100644 --- a/SpigotCore/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java +++ b/SpigotCore/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java @@ -20,10 +20,8 @@ package de.steamwar.core; import com.comphenix.tinyprotocol.Reflection; -import com.viaversion.viaversion.api.Via; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.BaseComponent; -import net.minecraft.server.v1_9_R2.PacketPlayOutEntity; import org.bukkit.Sound; import org.bukkit.entity.Player; @@ -38,7 +36,7 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper { @Override public void sendMessage(Player player, ChatMessageType type, BaseComponent... msg) { - if(type == ChatMessageType.CHAT && Via.getAPI().getPlayerVersion(player.getUniqueId()) >= 759) + if(type == ChatMessageType.CHAT) type = ChatMessageType.SYSTEM; player.spigot().sendMessage(type, msg); diff --git a/SpigotCore/SpigotCore_Main/build.gradle.kts b/SpigotCore/SpigotCore_Main/build.gradle.kts index 88825bc9..cc941d8c 100644 --- a/SpigotCore/SpigotCore_Main/build.gradle.kts +++ b/SpigotCore/SpigotCore_Main/build.gradle.kts @@ -35,7 +35,6 @@ dependencies { compileOnly(libs.spigotapi) compileOnly(libs.netty) compileOnly(libs.authlib) - compileOnly(libs.viaapi) compileOnly(libs.fastutil) implementation(libs.anvilgui) diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java index cde82084..50658aea 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java @@ -21,7 +21,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.internal.Statement; import io.netty.channel.ChannelFuture; import org.bukkit.Bukkit; @@ -99,7 +98,6 @@ class CheckpointUtilsJ9 { Statement.closeAll(); // Close socket - Via.getManager().getInjector().uninject(); Object serverConnection = TinyProtocol.getServerConnection(Core.getInstance()); List channels = channelFutures.get(serverConnection); for(Object future : channels) { @@ -140,7 +138,6 @@ class CheckpointUtilsJ9 { ((ChannelFuture) future).channel().config().setAutoRead(true); } } - Via.getManager().getInjector().inject(); Bukkit.getPluginManager().callEvent(new CRIUWakeupEvent()); Core.getInstance().getLogger().log(Level.INFO, "Checkpoint restored"); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Core.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Core.java index 9c1e51ef..f4a2b419 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Core.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Core.java @@ -100,9 +100,6 @@ public class Core extends JavaPlugin{ CheckpointUtils.signalHandler(); new AntiNocom(); - if(Core.getVersion() < 17 && Bukkit.getPluginManager().getPlugin("ViaVersion") != null) - new PartialChunkFixer(); - if(Core.getVersion() >= 19) new ServerDataHandler(); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/PartialChunkFixer.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/PartialChunkFixer.java deleted file mode 100644 index 6efab3c5..00000000 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/PartialChunkFixer.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 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.events; - -import com.comphenix.tinyprotocol.Reflection; -import com.comphenix.tinyprotocol.TinyProtocol; -import com.viaversion.viaversion.api.Via; -import com.viaversion.viaversion.api.ViaAPI; -import de.steamwar.core.Core; -import de.steamwar.core.CraftbukkitWrapper; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -import java.util.ArrayList; -import java.util.List; - -/** - * TinyProtocol can't translate BlockEntities during 1.16 to 1.17 conversions du to removed partial chunk update support. This class cancels PartialChunkUpdates for this players and sends them a complete chunk instead. - * This class can only be loaded on 1.9 to 1.15 with active ViaVersion. - **/ -public class PartialChunkFixer { - - private static final int PROTOCOL1_17 = 755; - private static final Class mapChunk = Reflection.getClass("{nms}.PacketPlayOutMapChunk"); - private static final Reflection.FieldAccessor fullChunkFlag = Reflection.getField(mapChunk, boolean.class, 0); - private static final Reflection.FieldAccessor chunkX = Reflection.getField(mapChunk, int.class, 0); - private static final Reflection.FieldAccessor chunkZ = Reflection.getField(mapChunk, int.class, 1); - - private final ViaAPI via = Via.getAPI(); - - private final List chunksToResend = new ArrayList<>(); - - public PartialChunkFixer() { - TinyProtocol.instance.addFilter(mapChunk, this::chunkFilter); - Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> { - synchronized (chunksToResend) { - for(ResendChunk chunk : chunksToResend) { - CraftbukkitWrapper.impl.sendChunk(chunk.player, chunk.x, chunk.z); - } - chunksToResend.clear(); - } - }, 1, 1); - } - - private Object chunkFilter(Player player, Object packet) { - if(via.getPlayerVersion(player) >= PROTOCOL1_17 && !fullChunkFlag.get(packet)) { - // partial chunk update - synchronized (chunksToResend) { - chunksToResend.add(new ResendChunk(player, chunkX.get(packet), chunkZ.get(packet))); - } - return null; - } - return packet; - } - - private static class ResendChunk { - private final Player player; - private final int x; - private final int z; - - private ResendChunk(Player player, int x, int z) { - this.player = player; - this.x = x; - this.z = z; - } - } -} diff --git a/SpigotCore/SpigotCore_Main/src/plugin.yml b/SpigotCore/SpigotCore_Main/src/plugin.yml index 75652668..a29249d2 100644 --- a/SpigotCore/SpigotCore_Main/src/plugin.yml +++ b/SpigotCore/SpigotCore_Main/src/plugin.yml @@ -4,7 +4,6 @@ author: Lixfel api-version: "1.13" load: STARTUP softdepend: - - ViaVersion - WorldEdit main: de.steamwar.core.Core diff --git a/VelocityCore/Persistent/src/de/steamwar/persistent/Subserver.java b/VelocityCore/Persistent/src/de/steamwar/persistent/Subserver.java index 072f1467..d4290814 100644 --- a/VelocityCore/Persistent/src/de/steamwar/persistent/Subserver.java +++ b/VelocityCore/Persistent/src/de/steamwar/persistent/Subserver.java @@ -225,20 +225,16 @@ public class Subserver { if (line.contains("Loading libraries, please wait")) sendProgress(2); else if (line.contains("Starting Minecraft server on")) - sendProgress(4); + sendProgress(5); else if (line.contains("Preparing start region")) - sendProgress(6); - return line.contains("Finished mapping loading"); + sendProgress(8); + return line.contains("Done ("); }); } if (!started) return; - sendProgress(8); - - Thread.sleep(300); - sendProgress(10); for (Player cachedPlayer : cachedPlayers) { sendPlayer(cachedPlayer); diff --git a/VelocityCore/build.gradle.kts b/VelocityCore/build.gradle.kts index 78603f8c..2029b3f4 100644 --- a/VelocityCore/build.gradle.kts +++ b/VelocityCore/build.gradle.kts @@ -47,6 +47,8 @@ java { dependencies { annotationProcessor(libs.velocityapi) compileOnly(libs.velocity) + compileOnly(libs.viaapi) + compileOnly(libs.viavelocity) compileOnly(project(":VelocityCore:Persistent", "default")) @@ -61,6 +63,5 @@ dependencies { } implementation(libs.msgpack) - implementation(libs.apolloprotos) } \ No newline at end of file diff --git a/VelocityCore/src/de/steamwar/messages/BungeeCore.properties b/VelocityCore/src/de/steamwar/messages/BungeeCore.properties index b133d99b..c018323c 100644 --- a/VelocityCore/src/de/steamwar/messages/BungeeCore.properties +++ b/VelocityCore/src/de/steamwar/messages/BungeeCore.properties @@ -728,6 +728,9 @@ MOD_ITEM_BACK=§7Back INV_PAGE_BACK=§{0}Seite zurück INV_PAGE_NEXT=§{0}Seite vor +#VersionAnnouncer +SERVER_VERSION=§7This server runs on Minecraft version §e{0} + #Discord DC_UNLINKED=For this action your Discord account has to be linked to your Minecraft account. To link your accounts go onto the SteamWar Discord to the `regeln-infos` Channel and click on `Minecraft Verknüpfen`. DC_TITLE_SCHEMINFO=Schematic Info diff --git a/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties b/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties index 9299064f..26d52987 100644 --- a/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties +++ b/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties @@ -681,6 +681,9 @@ ADVENT_CALENDAR_OPEN=§7Du hast §e{0}§7 aus dem Adventskalender erhalten! INV_PAGE_BACK=§{0}Page back INV_PAGE_NEXT=§{0}Next page +#VersionAnnouncer +SERVER_VERSION=§7Dieser Server läuft auf Minecraft-Version §e{0} + #Discord DC_UNLINKED=Für diese Aktion muss dein Minecraftaccount mit deinem Discordaccount verknüpft sein, gehe dazu auf dem SteamWar-Discord in den `regeln-infos` Channel und Klicke auf `Minecraft Verknüpfen`. DC_TITLE_SCHEMINFO=Schematicinfo diff --git a/VelocityCore/src/de/steamwar/velocitycore/GameModeConfig.java b/VelocityCore/src/de/steamwar/velocitycore/GameModeConfig.java index 8dab4d8d..74fb19bf 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/GameModeConfig.java +++ b/VelocityCore/src/de/steamwar/velocitycore/GameModeConfig.java @@ -27,10 +27,13 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.function.BiConsumer; +import java.util.regex.Pattern; @Getter public class GameModeConfig { + private static final Pattern terminatingNumber = Pattern.compile("\\D+(\\d+)$"); + public static void loadAll(Class config, BiConsumer consumer) { File folder = new File(VelocityCore.get().getDataDirectory().getParent().toFile(), "FightSystem"); if(!folder.exists()) @@ -51,9 +54,9 @@ public class GameModeConfig { @Getter public static class Server { private String Folder; - private String ServerJar; private List ChatNames = Collections.emptyList(); private List Maps; + private boolean Spigot = false; private boolean Ranked = false; private boolean Historic = false; } @@ -66,8 +69,8 @@ public class GameModeConfig { private boolean ManualCheck = true; } - public String getServerJar() { - return getServer().getServerJar(); + public ServerVersion getVersion() { + return ServerVersion.valueOf((getServer().isSpigot() ? "SPIGOT_" : "PAPER_") + terminatingNumber.matcher(getServer().getFolder()).group(1)); } public String getFolder() { diff --git a/VelocityCore/src/de/steamwar/velocitycore/Node.java b/VelocityCore/src/de/steamwar/velocitycore/Node.java index b97ef0ba..23cf808a 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/Node.java +++ b/VelocityCore/src/de/steamwar/velocitycore/Node.java @@ -63,7 +63,7 @@ public abstract class Node { nodes.forEach(consumer); } - public abstract ProcessBuilder startServer(String serverJar, File directory, String worldDir, String levelName, int port, String xmx, String... dParams); + public abstract ProcessBuilder startServer(String serverJar, File directory, String worldDir, String levelName, int port, String... dParams); protected abstract ProcessBuilder prepareExecution(String... command); protected abstract void calcLoadLimit(); @@ -95,7 +95,7 @@ public abstract class Node { return hostname; } - protected void constructServerstart(File directory, List cmd, String serverJar, String worldDir, String levelName, int port, String xmx, String... dParams) { + protected void constructServerstart(File directory, List cmd, String serverJar, String worldDir, String levelName, int port, String... dParams) { if (JAVA_8.contains(serverJar)) cmd.add("/usr/lib/jvm/java-8-openj9-amd64/bin/java"); else @@ -105,7 +105,7 @@ public abstract class Node { cmd.add("-D" + param); } cmd.add("-Xshareclasses:nonfatal,name=" + directory.getName()); - cmd.add("-Xmx" + xmx); + cmd.add("-Xmx768M"); cmd.addAll(OPENJ9_ARGS); if (!JAVA_8.contains(serverJar)) { cmd.add("--add-opens"); @@ -142,9 +142,9 @@ public abstract class Node { } @Override - public ProcessBuilder startServer(String serverJar, File directory, String worldDir, String levelName, int port, String xmx, String... dParams) { + public ProcessBuilder startServer(String serverJar, File directory, String worldDir, String levelName, int port, String... dParams) { List cmd = new ArrayList<>(); - constructServerstart(directory, cmd, serverJar, worldDir, levelName, port, xmx, dParams); + constructServerstart(directory, cmd, serverJar, worldDir, levelName, port, dParams); ProcessBuilder builder = new ProcessBuilder(cmd); builder.directory(directory); return builder; @@ -174,7 +174,7 @@ public abstract class Node { } @Override - public ProcessBuilder startServer(String serverJar, File directory, String worldDir, String levelName, int port, String xmx, String... dParams) { + public ProcessBuilder startServer(String serverJar, File directory, String worldDir, String levelName, int port, String... dParams) { List cmd = new ArrayList<>(); cmd.add("ssh"); cmd.add("-L"); @@ -183,7 +183,7 @@ public abstract class Node { cmd.add("cd"); cmd.add(directory.getPath()); cmd.add(";"); - constructServerstart(directory, cmd, serverJar, worldDir, levelName, port, xmx, dParams); + constructServerstart(directory, cmd, serverJar, worldDir, levelName, port, dParams); return new ProcessBuilder(cmd); } diff --git a/VelocityCore/src/de/steamwar/velocitycore/ServerStarter.java b/VelocityCore/src/de/steamwar/velocitycore/ServerStarter.java index 1b834390..0fbdf696 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/ServerStarter.java +++ b/VelocityCore/src/de/steamwar/velocitycore/ServerStarter.java @@ -20,6 +20,8 @@ package de.steamwar.velocitycore; import com.velocitypowered.api.proxy.Player; +import com.viaversion.viaversion.api.Via; +import com.viaversion.viaversion.velocity.platform.VelocityViaConfig; import de.steamwar.messages.Chatter; import de.steamwar.persistent.Arenaserver; import de.steamwar.persistent.Bauserver; @@ -56,8 +58,7 @@ public class ServerStarter { private String worldDir = null; private Node node = null; - private String serverJar = "spigot-1.15.2.jar"; - private String xmx = "768M"; + private ServerVersion version = ServerVersion.PAPER_20; private Portrange portrange = BAU_PORTS; private Function serverNameProvider = port -> node.getName() + port; private BooleanSupplier startCondition = () -> true; @@ -78,7 +79,7 @@ public class ServerStarter { public ServerStarter arena(ArenaMode mode, String map) { portrange = ARENA_PORTS; serverNameProvider = port -> mode.getGameName() + (port - portrange.start); - serverJar = mode.getServerJar(); + version = mode.getVersion(); allowMerge = true; fightMap = map; gameMode = mode.getInternalName(); @@ -145,8 +146,8 @@ public class ServerStarter { } public ServerStarter build(ServerVersion version, UUID owner) { + this.version = version; directory = version.getServerDirectory("Bau"); - serverJar = version.getServerJar(); worldDir = version.getWorldFolder(WORLDS_BASE_PATH); worldName = version != ServerVersion.SPIGOT_12 ? String.valueOf(SteamwarUser.get(owner).getId()) : owner.toString(); checkpoint = true; @@ -219,7 +220,7 @@ public class ServerStarter { } public ServerStarter builder(ServerVersion version, String map, File generator) { - serverJar = version.getServerJar(); + this.version = version; directory = version.getServerDirectory("Builder"); worldDir = version.getWorldFolder(BUILDER_BASE_PATH); worldName = map; @@ -294,6 +295,7 @@ public class ServerStarter { if(checkpoint) arguments.put("checkpoint", checkpointDir.getPath()); + ((VelocityViaConfig) Via.getConfig()).getVelocityServerProtocols().put(serverName, version.getProtocolVersion().getProtocol()); if(checkpoint && checkpointDir.exists()) { try(DataOutputStream out = new DataOutputStream(Files.newOutputStream(new File(checkpointDir, "port").toPath()))) { out.writeInt(port); @@ -313,7 +315,7 @@ public class ServerStarter { private void regularStart(String serverName, int port) { postStart(constructor.construct(serverName, port, node.startServer( - serverJar, directory, worldDir, worldName, port, xmx, arguments.entrySet().stream().map(entry -> entry.getKey() + "=" + entry.getValue()).toArray(String[]::new) + version.getServerJar(), directory, worldDir, worldName, port, arguments.entrySet().stream().map(entry -> entry.getKey() + "=" + entry.getValue()).toArray(String[]::new) ), worldCleanup, null)); } diff --git a/VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java b/VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java index 31b8e39e..fd505e77 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java +++ b/VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java @@ -19,6 +19,8 @@ package de.steamwar.velocitycore; +import com.velocitypowered.api.network.ProtocolVersion; +import lombok.AllArgsConstructor; import lombok.Getter; import java.io.File; @@ -27,12 +29,23 @@ import java.util.Map; import java.util.Set; @Getter +@AllArgsConstructor public enum ServerVersion { - SPIGOT_12("spigot-1.12.2.jar", 12), - SPIGOT_15("spigot-1.15.2.jar", 15), - PAPER_19("paper-1.19.3.jar", 19), - PAPER_20("paper-1.20.1.jar", 20), - PAPER_21("paper-1.21.jar", 21); + SPIGOT_8("spigot-1.8.8.jar", 8, ProtocolVersion.MINECRAFT_1_8), + SPIGOT_9("spigot-1.9.4.jar", 9, ProtocolVersion.MINECRAFT_1_9), + SPIGOT_10("spigot-1.10.2.jar", 10, ProtocolVersion.MINECRAFT_1_10), + SPIGOT_12("spigot-1.12.2.jar", 12, ProtocolVersion.MINECRAFT_1_12_2), + SPIGOT_14("spigot-1.14.4.jar", 14, ProtocolVersion.MINECRAFT_1_14_4), + SPIGOT_15("spigot-1.15.2.jar", 15, ProtocolVersion.MINECRAFT_1_15_2), + + PAPER_8("paper-1.8.8.jar", 8, ProtocolVersion.MINECRAFT_1_8), + PAPER_10("paper-1.10.2.jar", 10, ProtocolVersion.MINECRAFT_1_10), + PAPER_12("paper-1.12.2.jar", 12, ProtocolVersion.MINECRAFT_1_12_2), + PAPER_15("paper-1.15.2.jar", 15, ProtocolVersion.MINECRAFT_1_15_2), + PAPER_18("paper-1.18.2.jar", 15, ProtocolVersion.MINECRAFT_1_18_2), + PAPER_19("paper-1.19.3.jar", 19, ProtocolVersion.MINECRAFT_1_19_3), + PAPER_20("paper-1.20.1.jar", 20, ProtocolVersion.MINECRAFT_1_20), + PAPER_21("paper-1.21.jar", 21, ProtocolVersion.MINECRAFT_1_21_2); private static final Map chatMap = new HashMap<>(); @@ -76,11 +89,7 @@ public enum ServerVersion { private final String serverJar; private final int versionSuffix; - - ServerVersion(String serverJar, int versionSuffix) { - this.serverJar = serverJar; - this.versionSuffix = versionSuffix; - } + private final ProtocolVersion protocolVersion; public String getWorldFolder(String base) { return base + versionSuffix + "/"; diff --git a/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java b/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java index 6a5b3ade..5e6dca1d 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java +++ b/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java @@ -152,6 +152,7 @@ public class VelocityCore implements ReloadablePlugin { new BanListener(); new CheckListener(); new IPSanitizer(); + new VersionAnnouncer(); local = new Node.LocalNode(); if(MAIN_SERVER) { diff --git a/VelocityCore/src/de/steamwar/velocitycore/listeners/VersionAnnouncer.java b/VelocityCore/src/de/steamwar/velocitycore/listeners/VersionAnnouncer.java new file mode 100644 index 00000000..c28a8fee --- /dev/null +++ b/VelocityCore/src/de/steamwar/velocitycore/listeners/VersionAnnouncer.java @@ -0,0 +1,47 @@ +/* + * 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.velocitycore.listeners; + +import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.event.player.ServerConnectedEvent; +import com.velocitypowered.api.network.ProtocolVersion; +import com.velocitypowered.api.proxy.Player; +import com.velocitypowered.api.proxy.server.ServerInfo; +import com.viaversion.viaversion.api.Via; +import com.viaversion.viaversion.velocity.platform.VelocityViaConfig; +import de.steamwar.messages.Chatter; +import de.steamwar.persistent.Subserver; + +public class VersionAnnouncer extends BasicListener { + + @Subscribe + public void postConnect(ServerConnectedEvent e) { + ServerInfo server = e.getServer().getServerInfo(); + if(!Subserver.isBuild(Subserver.getSubserver(server))) + return; + + Player player = e.getPlayer(); + int serverVersion = ((VelocityViaConfig) Via.getConfig()).getVelocityServerProtocols().get(server.getName()); + if(Via.getAPI().getPlayerVersion(player) == serverVersion) + return; + + player.sendActionBar(Chatter.of(player).parse("SERVER_VERSION", ProtocolVersion.getProtocolVersion(serverVersion).getMostRecentSupportedVersion())); + } +} diff --git a/settings.gradle.kts b/settings.gradle.kts index a29c0412..9389f289 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -116,7 +116,6 @@ dependencyResolutionManagement { library("authlib", "com.mojang:authlib:1.5.25") library("datafixer", "com.mojang:datafixerupper:4.0.26") library("brigadier", "com.mojang:brigadier:1.0.18") - library("viaapi", "com.viaversion:viaversion-api:4.3.1") library("anvilgui", "net.wesjd:anvilgui:1.10.3-SNAPSHOT") library("nms8", "de.steamwar:spigot:1.8") @@ -138,6 +137,8 @@ dependencyResolutionManagement { library("velocity", "de.steamwar:velocity:RELEASE") library("velocityapi", "com.velocitypowered:velocity-api:3.3.0-SNAPSHOT") + library("viaapi", "com.viaversion:viaversion-api:4.3.1") + library("viavelocity", "com.viaversion:viaversion-velocity:4.3.1") library("jda", "net.dv8tion:JDA:5.2.0") library("msgpack", "org.msgpack:msgpack-core:0.9.8") library("apolloprotos", "com.lunarclient:apollo-protos:1.0-SNAPSHOT") From 6b7825ead9965c2424b5bb02102a96dd82fc95fc Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 2 Jan 2025 11:05:07 +0100 Subject: [PATCH 2/2] Fix version matching --- .../src/de/steamwar/velocitycore/GameModeConfig.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/VelocityCore/src/de/steamwar/velocitycore/GameModeConfig.java b/VelocityCore/src/de/steamwar/velocitycore/GameModeConfig.java index 74fb19bf..208f6df3 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/GameModeConfig.java +++ b/VelocityCore/src/de/steamwar/velocitycore/GameModeConfig.java @@ -27,12 +27,13 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.function.BiConsumer; +import java.util.regex.Matcher; import java.util.regex.Pattern; @Getter public class GameModeConfig { - private static final Pattern terminatingNumber = Pattern.compile("\\D+(\\d+)$"); + private static final Pattern terminatingNumber = Pattern.compile("(\\d+)$"); public static void loadAll(Class config, BiConsumer consumer) { File folder = new File(VelocityCore.get().getDataDirectory().getParent().toFile(), "FightSystem"); @@ -70,7 +71,9 @@ public class GameModeConfig { } public ServerVersion getVersion() { - return ServerVersion.valueOf((getServer().isSpigot() ? "SPIGOT_" : "PAPER_") + terminatingNumber.matcher(getServer().getFolder()).group(1)); + Matcher matcher = terminatingNumber.matcher(getServer().getFolder()); + matcher.find(); + return ServerVersion.valueOf((getServer().isSpigot() ? "SPIGOT_" : "PAPER_") + matcher.group(1)); } public String getFolder() {