From 47711b746ea4c15e2c0e5c62b0fd7afcc319d9d0 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 10 Jul 2021 22:04:56 +0200 Subject: [PATCH] Add DevCommand --- src/de/steamwar/bungeecore/BungeeCore.java | 1 + .../bungeecore/commands/DevCommand.java | 86 +++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 src/de/steamwar/bungeecore/commands/DevCommand.java diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index 2344d56..fe19b80 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -108,6 +108,7 @@ public class BungeeCore extends Plugin { new DenyCommand("watchcat", "wc"); new TeamCommand(); new ServerTeamchatCommand(); + new DevCommand(); new EventCommand(); new EventreloadCommand(); new EventRescheduleCommand(); diff --git a/src/de/steamwar/bungeecore/commands/DevCommand.java b/src/de/steamwar/bungeecore/commands/DevCommand.java new file mode 100644 index 0000000..c266520 --- /dev/null +++ b/src/de/steamwar/bungeecore/commands/DevCommand.java @@ -0,0 +1,86 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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.bungeecore.commands; + +import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.config.ServerInfo; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +import java.io.File; +import java.net.InetSocketAddress; +import java.util.Arrays; +import java.util.Collections; +import java.util.stream.Collectors; + +public class DevCommand extends BasicCommand { + + private final File DevServerDir = new File("/configs/DevServer"); + + public DevCommand() { + super("dev", ""); + } + + @Override + public void execute(CommandSender sender, String[] args) { + if (!(sender instanceof ProxiedPlayer)) { + return; + } + String[] devSever = DevServerDir.list(); + if (devSever == null || devSever.length == 0) { + sender.sendMessage("§eSteam§8War§8» §cDer Server ist derzeit nicht erreichbar."); + } else if (devSever.length == 1) { + String[] server = devSever[0].split("\\."); + sendToServer((ProxiedPlayer) sender, server[0], Integer.parseInt(server[1])); + } else { + if (args.length != 0) { + for (String s : devSever) { + String[] server = s.split("\\."); + if (args[0].equals(server[0])) { + sendToServer((ProxiedPlayer) sender, server[0], Integer.parseInt(server[1])); + return; + } + } + } + sender.sendMessage("§eSteam§8War§8» §cUnbekannter DevServer."); + } + } + + private void sendToServer(ProxiedPlayer proxiedPlayer, String name, int port) { + InetSocketAddress address = new InetSocketAddress("127.0.0.1", port); + ServerInfo serverInfo = ProxyServer.getInstance().constructServerInfo("Dev-" + name, address, "SteamWar.de - Subserver", false); + proxiedPlayer.connect(serverInfo); + } + + @Override + public Iterable onTabComplete(CommandSender sender, String[] args) { + if (!(sender instanceof ProxiedPlayer)) { + return Collections.emptyList(); + } + String[] devSever = DevServerDir.list(); + if (devSever == null) { + return Collections.emptyList(); + } + if (args.length > 1) { + return Collections.emptyList(); + } + return Arrays.stream(devSever).map(s -> s.split("\\.")).map(s -> s[0]).collect(Collectors.toList()); + } +}