forked from SteamWar/SteamWar
Move ViaVersion to Proxy
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 <T extends GameModeConfig> void loadAll(Class<T> config, BiConsumer<File, T> 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<String> ChatNames = Collections.emptyList();
|
||||
private List<String> 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() {
|
||||
|
||||
@@ -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<String> cmd, String serverJar, String worldDir, String levelName, int port, String xmx, String... dParams) {
|
||||
protected void constructServerstart(File directory, List<String> 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<String> 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<String> 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Integer, String> 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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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<String, ServerVersion> 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 + "/";
|
||||
|
||||
@@ -152,6 +152,7 @@ public class VelocityCore implements ReloadablePlugin {
|
||||
new BanListener();
|
||||
new CheckListener();
|
||||
new IPSanitizer();
|
||||
new VersionAnnouncer();
|
||||
|
||||
local = new Node.LocalNode();
|
||||
if(MAIN_SERVER) {
|
||||
|
||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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()));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user