From a2f6a2c6ae5dd1cf695b1f51d3c13b8fd39f2195 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 4 Aug 2022 17:01:40 +0200 Subject: [PATCH] 1.19.1 Support, API update Signed-off-by: Lixfel --- CommonCore | 2 +- src/de/steamwar/bungeecore/BungeeCore.java | 32 ++++++++----- src/de/steamwar/bungeecore/ServerStarter.java | 8 ++-- .../bungeecore/commands/TpCommand.java | 6 +-- src/de/steamwar/bungeecore/sql/Statement.java | 2 +- .../steamwar/bungeecore/tablist/Tablist.java | 1 + src/de/steamwar/bungeecore/util/Chat19.java | 45 +++++-------------- 7 files changed, 40 insertions(+), 56 deletions(-) diff --git a/CommonCore b/CommonCore index 21e77c5..47bd9af 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit 21e77c55f023261d3a63d5c6200d28b2f6f6fc4c +Subproject commit 47bd9af03eb987f94777f3b13f6ae6c30f153393 diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index 8518c97..5660af1 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -48,6 +48,7 @@ import net.md_5.bungee.config.YamlConfiguration; import java.io.File; import java.io.IOException; +import java.net.InetSocketAddress; import java.util.Collection; import java.util.HashMap; import java.util.List; @@ -57,6 +58,8 @@ import java.util.logging.Level; public class BungeeCore extends Plugin { + public static boolean MAIN_SERVER; + public static String CHAT_PREFIX; public static String WORLD_FOLDER; public static String BAUWELT_PROTOTYP; @@ -75,6 +78,15 @@ public class BungeeCore extends Plugin { @Override public void onEnable(){ + getProxy().registerChannel("sw:bridge"); + getProxy().registerChannel("fabricmodsender:mods"); + + setInstance(this); + MAIN_SERVER = ProxyServer.getInstance().getConfig().getListeners().stream().anyMatch(info -> ((InetSocketAddress) info.getSocketAddress()).getPort() == 25565); + loadConfig(); + + errorLogger = new ErrorLogger(); + SWCommandUtils.init((SWTypeMapperCreator, CommandSender, Object>) (mapper, tabCompleter) -> new TypeMapper() { @Override public Object map(CommandSender commandSender, String[] previousArguments, String s) { @@ -88,13 +100,6 @@ public class BungeeCore extends Plugin { }); BungeeCord.getInstance().getScheduler().schedule(this, TabCompletionCache::invalidateOldEntries, 1, 1, TimeUnit.SECONDS); - getProxy().registerChannel("sw:bridge"); - getProxy().registerChannel("fabricmodsender:mods"); - - setInstance(this); - loadConfig(); - - errorLogger = new ErrorLogger(); new ConnectionListener(); new Forge(); new Forge12(); @@ -305,10 +310,6 @@ public class BungeeCore extends Plugin { Persistent.setChatPrefix(CHAT_PREFIX); Persistent.setLobbyServer(LOBBY_SERVER); - if (config.contains("discord")) { - SteamwarDiscordBotConfig.loadConfig(config.getSection("discord")); - } - final Configuration servers = config.getSection("servers"); for(final String serverName : servers.getKeys()){ final Configuration server = servers.getSection(serverName); @@ -325,6 +326,15 @@ public class BungeeCore extends Plugin { ModLoaderBlocker.addServer(serverName); } } + + File discordFile = new File(System.getProperty("user.home"), "discord.yml"); + if(discordFile.exists()) { + try { + SteamwarDiscordBotConfig.loadConfig(ConfigurationProvider.getProvider(YamlConfiguration.class).load(discordFile)); + } catch (IOException e) { + get().getLogger().log(Level.SEVERE, "Could not load discord bot configuration", e); + } + } } private static void setInstance(BungeeCore core){ diff --git a/src/de/steamwar/bungeecore/ServerStarter.java b/src/de/steamwar/bungeecore/ServerStarter.java index 35a97dd..458e4d4 100644 --- a/src/de/steamwar/bungeecore/ServerStarter.java +++ b/src/de/steamwar/bungeecore/ServerStarter.java @@ -4,7 +4,6 @@ import de.steamwar.bungeecore.sql.EventFight; import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.Team; import de.steamwar.bungeecore.sql.Tutorial; -import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.io.File; @@ -17,11 +16,10 @@ import java.util.stream.Collectors; public class ServerStarter { - private static final boolean MAIN_SERVER = ProxyServer.getInstance().getConfig().getListeners().stream().anyMatch(info -> ((InetSocketAddress) info.getSocketAddress()).getPort() == 25565); - private static final Portrange BAU_PORTS = MAIN_SERVER ? new Portrange(10100, 20000) : new Portrange(2100, 2200); - private static final Portrange ARENA_PORTS = MAIN_SERVER ? new Portrange(3000, 3100) : (BungeeCore.EVENT_MODE ? new Portrange(4000, 5000) : BAU_PORTS); + private static final Portrange BAU_PORTS = BungeeCore.MAIN_SERVER ? new Portrange(10100, 20000) : new Portrange(2100, 2200); + private static final Portrange ARENA_PORTS = BungeeCore.MAIN_SERVER ? new Portrange(3000, 3100) : (BungeeCore.EVENT_MODE ? new Portrange(4000, 5000) : BAU_PORTS); - private static final String BACKBONE = "/home/minecraft/"; + private static final String BACKBONE = System.getProperty("user.home") + "/"; private static final String SERVER_PATH = BACKBONE + "server/"; private static final String EVENT_PATH = BACKBONE + "event/"; public static final String TEMP_WORLD_PATH = BACKBONE + "arenaserver/"; diff --git a/src/de/steamwar/bungeecore/commands/TpCommand.java b/src/de/steamwar/bungeecore/commands/TpCommand.java index 04cbb02..a31cd78 100644 --- a/src/de/steamwar/bungeecore/commands/TpCommand.java +++ b/src/de/steamwar/bungeecore/commands/TpCommand.java @@ -56,14 +56,10 @@ public class TpCommand extends BasicCommand { boolean onTeamServer = Storage.teamServers.containsValue(player.getServer().getInfo()); //Give control of teleport command to server - if (server == player.getServer().getInfo() || onTeamServer) { + if (server == player.getServer().getInfo() || onTeamServer || server == null) { Chat19.chat(player, "/tp " + String.join(" ", args)); return; } - if(server == null) { - sender.system("JOINME_PLAYER_OFFLINE"); - return; - } teleport(player, server); } diff --git a/src/de/steamwar/bungeecore/sql/Statement.java b/src/de/steamwar/bungeecore/sql/Statement.java index 61fcc00..06b705a 100644 --- a/src/de/steamwar/bungeecore/sql/Statement.java +++ b/src/de/steamwar/bungeecore/sql/Statement.java @@ -44,7 +44,7 @@ public class Statement implements AutoCloseable { private static final String PASSWORD; static { - File file = new File(BungeeCore.get().getDataFolder(), "MySQL.yml"); + File file = new File(System.getProperty("user.home"), "MySQL.yml"); Configuration config; try { config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file); diff --git a/src/de/steamwar/bungeecore/tablist/Tablist.java b/src/de/steamwar/bungeecore/tablist/Tablist.java index 417629d..b9acc96 100644 --- a/src/de/steamwar/bungeecore/tablist/Tablist.java +++ b/src/de/steamwar/bungeecore/tablist/Tablist.java @@ -205,6 +205,7 @@ public class Tablist extends MessageToMessageDecoder { for (PlayerListItem.Item item : list.getItems()) { item.setPing(1); item.setDisplayName(ComponentSerializer.toString(TextComponent.fromLegacyText(""))); + item.setPublicKey(null); if(!player.getUniqueId().equals(item.getUuid()) && item.getGamemode() == 3) item.setGamemode(1); diff --git a/src/de/steamwar/bungeecore/util/Chat19.java b/src/de/steamwar/bungeecore/util/Chat19.java index e0934ae..37a3f30 100644 --- a/src/de/steamwar/bungeecore/util/Chat19.java +++ b/src/de/steamwar/bungeecore/util/Chat19.java @@ -19,47 +19,26 @@ package de.steamwar.bungeecore.util; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; import net.md_5.bungee.ServerConnection; import net.md_5.bungee.api.connection.ProxiedPlayer; -import net.md_5.bungee.protocol.PacketWrapper; -import net.md_5.bungee.protocol.ProtocolConstants; -import net.md_5.bungee.protocol.packet.Chat; +import net.md_5.bungee.protocol.ChatChain; +import net.md_5.bungee.protocol.packet.ClientChat; +import net.md_5.bungee.protocol.packet.ClientCommand; -public class Chat19 extends Chat { +import java.util.Collections; + +public class Chat19 { + private Chat19(){} public static void chat(ProxiedPlayer p, String message) { if(p.getPendingConnection().getVersion() >= 759) { - boolean command = message.startsWith("/"); - Chat19 packet = new Chat19(command ? message.substring(1) : message); - - ByteBuf buf = Unpooled.buffer(); - writeVarInt(command ? 0x03 : 0x04, buf); - packet.write(buf, ProtocolConstants.Direction.TO_SERVER, p.getPendingConnection().getVersion()); - ((ServerConnection) p.getServer()).getCh().write(new PacketWrapper(packet, buf)); + if(message.startsWith("/")) { + ((ServerConnection) p.getServer()).getCh().write(new ClientCommand(message.substring(1), System.currentTimeMillis(), 0, Collections.emptyMap(), false, new ChatChain(Collections.emptyList(), null))); + } else { + ((ServerConnection) p.getServer()).getCh().write(new ClientChat(message, System.currentTimeMillis(), 0, new byte[0], false, new ChatChain(Collections.emptyList(), null))); + } } else { p.chat(message); } } - - private final long salt = 0L; - private final byte[] signature = new byte[0]; - private final boolean signedPreview = false; - - public Chat19 (String message) { - super(message); - } - - @Override - public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { - if (direction == ProtocolConstants.Direction.TO_CLIENT || protocolVersion != 759) - throw new UnsupportedOperationException(); - - writeString(getMessage(), buf); - buf.writeLong(System.currentTimeMillis()); - buf.writeLong(salt); - writeArray(signature, buf); - buf.writeBoolean(signedPreview); - } }