From 2ef06f61e44c43ac4257c51b81409277626f2e50 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 20 Jun 2024 23:10:58 +0200 Subject: [PATCH] Bugfixes Signed-off-by: Lixfel --- Persistent/build.gradle | 8 ++-- .../src/de/steamwar/bungeecore/Subserver.java | 2 +- build.gradle | 16 ++++--- src/de/steamwar/bungeecore/Config.java | 42 ++++++++++++++++--- src/de/steamwar/bungeecore/ErrorLogger.java | 23 ++++------ .../steamwar/bungeecore/GameModeConfig.java | 10 ++--- src/de/steamwar/bungeecore/VelocityCore.java | 8 ++++ .../commands/PunishmentCommand.java | 2 +- .../commands/ServerSwitchCommand.java | 7 ++-- .../bungeecore/commands/VerifyCommand.java | 2 +- .../bungeecore/discord/DiscordConfig.java | 17 ++++---- .../discord/listeners/DiscordSchemUpload.java | 2 +- .../bungeecore/discord/util/AuthManager.java | 2 +- .../bungeecore/listeners/ChatListener.java | 2 +- .../bungeecore/listeners/IPSanitizer.java | 2 +- .../bungeecore/listeners/PluginMessage.java | 5 ++- src/de/steamwar/bungeecore/mods/FML.java | 6 ++- src/de/steamwar/bungeecore/mods/ModUtils.java | 4 +- .../bungeecore/mods/ServerListPing.java | 25 +++-------- .../steamwar/bungeecore/tablist/Tablist.java | 3 +- .../bungeecore/tablist/TablistManager.java | 4 +- src/de/steamwar/bungeecore/util/Chat19.java | 10 +++++ src/de/steamwar/command/SWCommand.java | 6 ++- 23 files changed, 120 insertions(+), 88 deletions(-) diff --git a/Persistent/build.gradle b/Persistent/build.gradle index c52ad18..87f4fe9 100644 --- a/Persistent/build.gradle +++ b/Persistent/build.gradle @@ -54,10 +54,10 @@ repositories { } dependencies { - compileOnly 'org.projectlombok:lombok:1.18.22' - testCompileOnly 'org.projectlombok:lombok:1.18.22' - annotationProcessor 'org.projectlombok:lombok:1.18.22' - testAnnotationProcessor 'org.projectlombok:lombok:1.18.22' + compileOnly 'org.projectlombok:lombok:1.18.32' + testCompileOnly 'org.projectlombok:lombok:1.18.32' + annotationProcessor 'org.projectlombok:lombok:1.18.32' + testAnnotationProcessor 'org.projectlombok:lombok:1.18.32' compileOnly 'de.steamwar:velocity:RELEASE' annotationProcessor 'com.velocitypowered:velocity-api:3.3.0-SNAPSHOT' diff --git a/Persistent/src/de/steamwar/bungeecore/Subserver.java b/Persistent/src/de/steamwar/bungeecore/Subserver.java index 50f2127..869a28d 100644 --- a/Persistent/src/de/steamwar/bungeecore/Subserver.java +++ b/Persistent/src/de/steamwar/bungeecore/Subserver.java @@ -251,7 +251,7 @@ public class Subserver { } private Component generateBar(int progress) { - return Component.text("⬛".repeat(Math.max(0, progress))).color(NamedTextColor.GOLD) + return Component.text("⬛".repeat(Math.max(0, progress))).color(NamedTextColor.YELLOW) .append(Component.text("⬛".repeat(Math.max(0, 10 - progress))).color(NamedTextColor.DARK_GRAY)); } diff --git a/build.gradle b/build.gradle index b5cd280..f779cf6 100644 --- a/build.gradle +++ b/build.gradle @@ -77,22 +77,26 @@ allprojects { shadowJar { exclude 'META-INF/*' //https://imperceptiblethoughts.com/shadow/configuration/minimizing/ - minimize { + /*minimize { exclude project(':') - } + exclude 'mysql:mysql-connector-java:8.0.33' + }*/ duplicatesStrategy DuplicatesStrategy.INCLUDE } dependencies { - compileOnly 'org.projectlombok:lombok:1.18.22' - testCompileOnly 'org.projectlombok:lombok:1.18.22' - annotationProcessor 'org.projectlombok:lombok:1.18.22' - testAnnotationProcessor 'org.projectlombok:lombok:1.18.22' + compileOnly 'org.projectlombok:lombok:1.18.32' + testCompileOnly 'org.projectlombok:lombok:1.18.32' + annotationProcessor 'org.projectlombok:lombok:1.18.32' + testAnnotationProcessor 'org.projectlombok:lombok:1.18.32' annotationProcessor 'com.velocitypowered:velocity-api:3.3.0-SNAPSHOT' compileOnly 'de.steamwar:velocity:RELEASE' compileOnly project(":Persistent") + runtimeOnly 'org.xerial:sqlite-jdbc:3.36.0' //TODO native only linux + implementation 'mysql:mysql-connector-java:8.0.33' + implementation("net.dv8tion:JDA:4.4.0_352") { exclude module: 'opus-java' } diff --git a/src/de/steamwar/bungeecore/Config.java b/src/de/steamwar/bungeecore/Config.java index 613434b..107532d 100644 --- a/src/de/steamwar/bungeecore/Config.java +++ b/src/de/steamwar/bungeecore/Config.java @@ -25,28 +25,59 @@ import org.yaml.snakeyaml.LoaderOptions; import org.yaml.snakeyaml.TypeDescription; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.Constructor; +import org.yaml.snakeyaml.introspector.BeanAccess; +import org.yaml.snakeyaml.representer.Representer; import java.io.File; import java.io.FileInputStream; import java.io.IOException; -import java.util.*; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.function.Consumer; @Getter public class Config { - public static Config load() { + public static T load(Class clazz, File file, Consumer description) { TypeDescription typeDescription = new TypeDescription(Config.class); - typeDescription.addPropertyParameters("servers", String.class, Config.Server.class); + description.accept(typeDescription); + Constructor constructor = new Constructor(clazz, new LoaderOptions()); + constructor.addTypeDescription(typeDescription); + + Representer representer = new Representer(); + representer.getPropertyUtils().setSkipMissingProperties(true); + + Yaml yaml = new Yaml(constructor, representer); + yaml.setBeanAccess(BeanAccess.FIELD); + + try{ + return yaml.load(new FileInputStream(file)); + }catch(IOException e){ + VelocityCore.getProxy().shutdown(); + throw new SecurityException("Could not load config", e); + } + } + + public static Config load() { + return load(Config.class, new File(VelocityCore.get().getDataDirectory().toFile(), "config.yml"), description -> description.addPropertyParameters("servers", String.class, Config.Server.class)); + + /* + + typeDescription.addPropertyParameters("servers", String.class, Config.Server.class); Constructor constructor = new Constructor(Config.class, new LoaderOptions()); constructor.addTypeDescription(typeDescription); + Yaml yaml = new Yaml(constructor); + yaml.setBeanAccess(BeanAccess.FIELD); + try{ - return new Yaml(constructor).load(new FileInputStream(new File(VelocityCore.get().getDataDirectory().toFile(), "config.yml"))); + return yaml.load(new FileInputStream(new File(VelocityCore.get().getDataDirectory().toFile(), "config.yml"))); }catch(IOException e){ VelocityCore.getProxy().shutdown(); throw new SecurityException("Could not load config.yml", e); - } + }*/ } private String lobbyserver; @@ -67,7 +98,6 @@ public class Config { @Getter public static class Server { - private String permission = "user"; private int spectatePort = 0; private List commands; } diff --git a/src/de/steamwar/bungeecore/ErrorLogger.java b/src/de/steamwar/bungeecore/ErrorLogger.java index 1dd6f9b..4470a6c 100644 --- a/src/de/steamwar/bungeecore/ErrorLogger.java +++ b/src/de/steamwar/bungeecore/ErrorLogger.java @@ -27,19 +27,20 @@ import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.logging.Handler; -import java.util.logging.Level; -import java.util.logging.LogRecord; -import java.util.logging.Logger; +import java.util.logging.*; public class ErrorLogger extends Handler { ErrorLogger(){ - Logger.getLogger("").addHandler(this); + Logger logger = VelocityCore.getLogger(); + while(logger.getParent() != null) + logger = logger.getParent(); + + logger.addHandler(this); } void unregister(){ - Logger.getLogger("").removeHandler(this); + Logger.getGlobal().removeHandler(this); } @Override @@ -78,16 +79,6 @@ public class ErrorLogger extends Handler { static { List contains = new ArrayList<>(); - contains.add("Error authenticating "); - contains.add("read timed out"); - contains.add("could not decode packet"); - contains.add("Connection reset by peer"); - contains.add("No client connected for pending server"); - contains.add("Error occurred processing connection for"); - contains.add("Server is online mode!"); - contains.add(" took "); - contains.add("Could not translate packet "); - contains.add("455420"); ignoreContains = Collections.unmodifiableList(contains); } } diff --git a/src/de/steamwar/bungeecore/GameModeConfig.java b/src/de/steamwar/bungeecore/GameModeConfig.java index 6c0d17a..7f2045f 100644 --- a/src/de/steamwar/bungeecore/GameModeConfig.java +++ b/src/de/steamwar/bungeecore/GameModeConfig.java @@ -21,12 +21,8 @@ package de.steamwar.bungeecore; import lombok.Getter; import lombok.Setter; -import org.yaml.snakeyaml.Yaml; -import org.yaml.snakeyaml.constructor.Constructor; import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -40,13 +36,13 @@ public class GameModeConfig { if(!folder.exists()) return; - Yaml yaml = new Yaml(new Constructor(config)); for(File file : Arrays.stream(folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))).sorted().toList()) { - try { + consumer.accept(file, Config.load(config, file, description -> {})); + /*try { consumer.accept(file, yaml.load(new FileInputStream(file))); } catch (IOException e) { throw new SecurityException("Could not load GameModeConfig", e); - } + }*/ } } diff --git a/src/de/steamwar/bungeecore/VelocityCore.java b/src/de/steamwar/bungeecore/VelocityCore.java index 0349dce..e664ffb 100644 --- a/src/de/steamwar/bungeecore/VelocityCore.java +++ b/src/de/steamwar/bungeecore/VelocityCore.java @@ -46,6 +46,8 @@ import de.steamwar.sql.internal.Statement; import lombok.Getter; import java.nio.file.Path; +import java.sql.DriverManager; +import java.sql.SQLException; import java.util.Collection; import java.util.List; import java.util.Map; @@ -101,6 +103,12 @@ public class VelocityCore { this.dataDirectory = dataDirectory; instance = this; + + try { + DriverManager.registerDriver(new com.mysql.cj.jdbc.Driver()); + } catch (SQLException e) { + throw new RuntimeException(e); + } } @Subscribe diff --git a/src/de/steamwar/bungeecore/commands/PunishmentCommand.java b/src/de/steamwar/bungeecore/commands/PunishmentCommand.java index 48e7b93..00f04b5 100644 --- a/src/de/steamwar/bungeecore/commands/PunishmentCommand.java +++ b/src/de/steamwar/bungeecore/commands/PunishmentCommand.java @@ -72,7 +72,7 @@ public class PunishmentCommand { } catch (NoSuchElementException e) { // ignore, player does not exist } catch (IOException e) { - VelocityCore.getLogger().log(Level.SEVERE, "Could not get offline player UUID {0}".formatted(playerName), e); + VelocityCore.getLogger().log(Level.SEVERE, "Could not get offline player UUID %s".formatted(playerName), e); } return null; } diff --git a/src/de/steamwar/bungeecore/commands/ServerSwitchCommand.java b/src/de/steamwar/bungeecore/commands/ServerSwitchCommand.java index 00ec29b..dd174b5 100644 --- a/src/de/steamwar/bungeecore/commands/ServerSwitchCommand.java +++ b/src/de/steamwar/bungeecore/commands/ServerSwitchCommand.java @@ -19,21 +19,22 @@ package de.steamwar.bungeecore.commands; +import com.velocitypowered.api.proxy.server.RegisteredServer; import de.steamwar.bungeecore.VelocityCore; import de.steamwar.command.SWCommand; import de.steamwar.messages.PlayerChatter; public class ServerSwitchCommand extends SWCommand { - private final String serverName; + private final RegisteredServer server; public ServerSwitchCommand(String cmd, String name, String... aliases) { super(cmd, null, aliases); - serverName = name; + server = VelocityCore.getProxy().getServer(name).orElseThrow(); } @Register public void genericCommand(PlayerChatter sender) { - sender.getPlayer().createConnectionRequest(VelocityCore.getProxy().getServer(serverName).orElseThrow()).fireAndForget(); + sender.getPlayer().createConnectionRequest(server).fireAndForget(); } } diff --git a/src/de/steamwar/bungeecore/commands/VerifyCommand.java b/src/de/steamwar/bungeecore/commands/VerifyCommand.java index 283a32f..efb061d 100644 --- a/src/de/steamwar/bungeecore/commands/VerifyCommand.java +++ b/src/de/steamwar/bungeecore/commands/VerifyCommand.java @@ -51,7 +51,7 @@ public class VerifyCommand extends SWCommand { User user = AuthManager.connectAuth(sender.user(), code); if(user != null) { - VelocityCore.getLogger().log(Level.INFO, "{0} Verified with Discorduser: {1}".formatted(sender.user().getUserName(), user.getIdLong())); + VelocityCore.getLogger().log(Level.INFO,"%s Verified with Discorduser: %s".formatted(sender.user().getUserName(), user.getIdLong())); sender.system("VERIFY_SUCCESS", user.getAsTag()); } else { sender.system("VERIFY_INVALID"); diff --git a/src/de/steamwar/bungeecore/discord/DiscordConfig.java b/src/de/steamwar/bungeecore/discord/DiscordConfig.java index c07326e..112ac2d 100644 --- a/src/de/steamwar/bungeecore/discord/DiscordConfig.java +++ b/src/de/steamwar/bungeecore/discord/DiscordConfig.java @@ -19,6 +19,7 @@ package de.steamwar.bungeecore.discord; +import de.steamwar.bungeecore.Config; import de.steamwar.bungeecore.VelocityCore; import lombok.AllArgsConstructor; import lombok.Data; @@ -26,14 +27,8 @@ import lombok.Getter; import net.dv8tion.jda.api.entities.Emoji; import net.dv8tion.jda.api.interactions.components.Button; import net.dv8tion.jda.api.interactions.components.ButtonStyle; -import org.yaml.snakeyaml.LoaderOptions; -import org.yaml.snakeyaml.TypeDescription; -import org.yaml.snakeyaml.Yaml; -import org.yaml.snakeyaml.constructor.Constructor; import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; import java.util.List; import java.util.Map; @@ -45,17 +40,21 @@ public class DiscordConfig { if(!file.exists() || VelocityCore.get().getConfig().isEventmode()) return null; - TypeDescription typeDescription = new TypeDescription(DiscordConfig.class); + return Config.load(DiscordConfig.class, file, description -> description.addPropertyParameters("roles", String.class, DiscordRole.class)); + /*TypeDescription typeDescription = new TypeDescription(DiscordConfig.class); typeDescription.addPropertyParameters("roles", String.class, DiscordRole.class); Constructor constructor = new Constructor(DiscordConfig.class, new LoaderOptions()); constructor.addTypeDescription(typeDescription); + Yaml yaml = new Yaml(constructor); + yaml.setBeanAccess(BeanAccess.FIELD); + try{ - return new Yaml(constructor).load(new FileInputStream(file)); + return yaml.load(new FileInputStream(file)); }catch(IOException e){ throw new SecurityException("Could not load discord bot configuration", e); - } + }*/ } public String channel(String type) { diff --git a/src/de/steamwar/bungeecore/discord/listeners/DiscordSchemUpload.java b/src/de/steamwar/bungeecore/discord/listeners/DiscordSchemUpload.java index 1d54a48..7d3a4a2 100644 --- a/src/de/steamwar/bungeecore/discord/listeners/DiscordSchemUpload.java +++ b/src/de/steamwar/bungeecore/discord/listeners/DiscordSchemUpload.java @@ -82,7 +82,7 @@ public class DiscordSchemUpload extends ListenerAdapter { } catch (InterruptedException e) { Thread.currentThread().interrupt(); } catch (ExecutionException | IOException e) { - VelocityCore.getLogger().log(Level.SEVERE, "Could not upload schem \"{0}\" for user \"{1}\"".formatted(name, user.getUserName()), e); + VelocityCore.getLogger().log(Level.SEVERE, "Could not upload schem \"%s\" for user \"%s\"".formatted(name, user.getUserName()), e); sender.system("DC_SCHEMUPLOAD_ERROR", name); } } diff --git a/src/de/steamwar/bungeecore/discord/util/AuthManager.java b/src/de/steamwar/bungeecore/discord/util/AuthManager.java index e97dd3e..b05412a 100644 --- a/src/de/steamwar/bungeecore/discord/util/AuthManager.java +++ b/src/de/steamwar/bungeecore/discord/util/AuthManager.java @@ -50,7 +50,7 @@ public class AuthManager { String code = Base64.getEncoder().encodeToString(randBytes); TOKENS.put(code, user); - VelocityCore.getLogger().log(Level.INFO, "Created Discord Auth-Token: {0} for: {1}".formatted(code, user.getAsTag())); + VelocityCore.getLogger().log(Level.INFO, "Created Discord Auth-Token: %s for: %s".formatted(code, user.getAsTag())); VelocityCore.schedule(() -> TOKENS.remove(code)).delay(10, TimeUnit.MINUTES).schedule(); return code; } diff --git a/src/de/steamwar/bungeecore/listeners/ChatListener.java b/src/de/steamwar/bungeecore/listeners/ChatListener.java index c6b5183..8d30c9d 100644 --- a/src/de/steamwar/bungeecore/listeners/ChatListener.java +++ b/src/de/steamwar/bungeecore/listeners/ChatListener.java @@ -58,7 +58,7 @@ public class ChatListener extends BasicListener { if (message.contains("jndi:ldap")) { SteamwarUser user = SteamwarUser.get(player.getUniqueId()); PunishmentCommand.ban(user, Punishment.PERMA_TIME, "Versuchte Exploit-Ausnutzung", SteamwarUser.get(-1), true); - VelocityCore.getLogger().log(Level.SEVERE, "{0} {1} wurde automatisch wegen jndi:ldap gebannt.".formatted(user.getUserName(), user.getId())); + VelocityCore.getLogger().log(Level.SEVERE, "%s %s wurde automatisch wegen jndi:ldap gebannt.".formatted(user.getUserName(), user.getId())); return; } diff --git a/src/de/steamwar/bungeecore/listeners/IPSanitizer.java b/src/de/steamwar/bungeecore/listeners/IPSanitizer.java index 872c8dc..359497f 100644 --- a/src/de/steamwar/bungeecore/listeners/IPSanitizer.java +++ b/src/de/steamwar/bungeecore/listeners/IPSanitizer.java @@ -46,7 +46,7 @@ public class IPSanitizer extends BasicListener { @Subscribe public void loginEvent(PreLoginEvent e) { - VelocityCore.getLogger().log(Level.INFO, "{0} has logged in with user name {1}".formatted(e.getConnection().getRemoteAddress(), e.getUsername())); + VelocityCore.getLogger().log(Level.INFO, "%s has logged in with user name %s".formatted(e.getConnection().getRemoteAddress(), e.getUsername())); remoteAddress.set(Hostname.getInitialInboundConnection((LoginInboundConnection) e.getConnection()).getConnection(), sanitized); } } diff --git a/src/de/steamwar/bungeecore/listeners/PluginMessage.java b/src/de/steamwar/bungeecore/listeners/PluginMessage.java index 1f66f3a..63224f5 100644 --- a/src/de/steamwar/bungeecore/listeners/PluginMessage.java +++ b/src/de/steamwar/bungeecore/listeners/PluginMessage.java @@ -26,6 +26,7 @@ import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.ServerConnection; import com.velocitypowered.api.proxy.messages.ChannelMessageSource; +import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier; import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; import com.velocitypowered.proxy.protocol.ProtocolUtils; import de.steamwar.bungeecore.VelocityCore; @@ -54,7 +55,7 @@ public class PluginMessage extends BasicListener { public static void send(Player player, String channel, byte[] data) { //TODO only if player has registered channel - player.sendPluginMessage(MinecraftChannelIdentifier.from(channel), data); + player.sendPluginMessage(channel.indexOf(':') != -1 ? MinecraftChannelIdentifier.from(channel) : new LegacyChannelIdentifier(channel), data); } public static byte[] genBufPacket(Consumer generator) { @@ -242,7 +243,7 @@ public class PluginMessage extends BasicListener { private void register(String channel, boolean clientSideRegister, Parser handler) { handlers.put(channel, handler); if(clientSideRegister) - VelocityCore.getProxy().getChannelRegistrar().register(MinecraftChannelIdentifier.from(channel)); + VelocityCore.getProxy().getChannelRegistrar().register(channel.indexOf(':') != -1 ? MinecraftChannelIdentifier.from(channel) : new LegacyChannelIdentifier(channel)); } private void clientRegistersChannel(PluginMessageEvent event) { diff --git a/src/de/steamwar/bungeecore/mods/FML.java b/src/de/steamwar/bungeecore/mods/FML.java index b64f3f9..684cab7 100644 --- a/src/de/steamwar/bungeecore/mods/FML.java +++ b/src/de/steamwar/bungeecore/mods/FML.java @@ -22,8 +22,9 @@ package de.steamwar.bungeecore.mods; import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.connection.PluginMessageEvent; import com.velocitypowered.api.event.connection.PostLoginEvent; +import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.proxy.Player; -import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; +import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier; import com.velocitypowered.proxy.protocol.ProtocolUtils; import de.steamwar.bungeecore.VelocityCore; import de.steamwar.bungeecore.listeners.BasicListener; @@ -59,7 +60,8 @@ public class FML extends BasicListener { } //if(isFML(player, "\0FML\0")) - player.sendPluginMessage(MinecraftChannelIdentifier.from(CHANNEL), helloPacket); + if(player.getProtocolVersion().lessThan(ProtocolVersion.MINECRAFT_1_13)) + player.sendPluginMessage(new LegacyChannelIdentifier(CHANNEL), helloPacket); } public void handlePluginMessage(PluginMessageEvent event) { diff --git a/src/de/steamwar/bungeecore/mods/ModUtils.java b/src/de/steamwar/bungeecore/mods/ModUtils.java index f031cd8..d08471a 100644 --- a/src/de/steamwar/bungeecore/mods/ModUtils.java +++ b/src/de/steamwar/bungeecore/mods/ModUtils.java @@ -54,7 +54,7 @@ public class ModUtils { Chatter sender = Chatter.of(uuid); SteamwarUser user = sender.user(); playerModMap.put(uuid,new ArrayList<>(mods)); - VelocityCore.getLogger().log(Level.INFO, "{0} declares mods: {1}".formatted(user.getUserName(), mods.stream().map(mod -> mod.getPlatform() + ":" + mod.getModName()).collect(Collectors.joining(" ")))); + VelocityCore.getLogger().log(Level.INFO, "%s declares mods: %s".formatted(user.getUserName(), mods.stream().map(mod -> mod.getPlatform() + ":" + mod.getModName()).collect(Collectors.joining(" ")))); ModType max = ModType.YELLOW; Iterator it = mods.iterator(); @@ -83,7 +83,7 @@ public class ModUtils { if(max == ModType.RED) { PunishmentCommand.ban(user, Timestamp.from(Instant.now().plus(7, ChronoUnit.DAYS)), message, SteamwarUser.get(-1), false); - VelocityCore.getLogger().log(Level.SEVERE, "{0} {1} wurde automatisch wegen der Mods {2} gebannt.".formatted(user.getUserName(), user.getId(), modList)); + VelocityCore.getLogger().log(Level.SEVERE, "%s %s wurde automatisch wegen der Mods %s gebannt.".formatted(user.getUserName(), user.getId(), modList)); } disconnect.accept(LegacyComponentSerializer.legacySection().deserialize(message)); diff --git a/src/de/steamwar/bungeecore/mods/ServerListPing.java b/src/de/steamwar/bungeecore/mods/ServerListPing.java index 6ba105e..5edc9dc 100644 --- a/src/de/steamwar/bungeecore/mods/ServerListPing.java +++ b/src/de/steamwar/bungeecore/mods/ServerListPing.java @@ -21,10 +21,8 @@ package de.steamwar.bungeecore.mods; import com.google.gson.*; import com.velocitypowered.api.proxy.server.ServerPing; -import de.steamwar.bungeecore.VelocityCore; import lombok.AllArgsConstructor; -import java.lang.reflect.Field; import java.lang.reflect.Type; @AllArgsConstructor @@ -39,23 +37,12 @@ public class ServerListPing implements JsonSerializer, JsonDeserial }; public static void init() { - try { - for (String fieldName : FIELDS_TO_OVERRIDE) { - Field field = VelocityCore.getProxy().getClass().getDeclaredField(fieldName); - field.setAccessible(true); - Object obj = field.get(null); - if (obj instanceof Gson gsonOld) { - Gson gsonNew = new GsonBuilder() - .registerTypeAdapter(ServerPing.class, new ServerListPing(gsonOld)) - .create(); - field.set(null, gsonNew); - } else { - throw new SecurityException("Failed to inject ServerListPing in " + fieldName); - } - } - } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { - throw new SecurityException("Failed to inject ServerListPing", e); - } + /*for (String fieldName : FIELDS_TO_OVERRIDE) { + Reflection.Field field = Reflection.getField(VelocityServer.class, fieldName); + field.set(null, new GsonBuilder() + .registerTypeAdapter(ServerPing.class, new ServerListPing(field.get(null))) + .create()); + }*/ } private final Gson gson; diff --git a/src/de/steamwar/bungeecore/tablist/Tablist.java b/src/de/steamwar/bungeecore/tablist/Tablist.java index 4f9e638..76e48d9 100644 --- a/src/de/steamwar/bungeecore/tablist/Tablist.java +++ b/src/de/steamwar/bungeecore/tablist/Tablist.java @@ -72,7 +72,6 @@ public class Tablist extends ChannelInboundHandlerAdapter { return; player.sendPlayerListHeaderAndFooter(header(viewer, seconds), viewer.parse(false, "TABLIST_FOOTER", connection.getServerInfo().getName(), ping(), VelocityCore.getProxy().getPlayerCount())); - player.getTabList(); List tablist = new ArrayList<>(); List direct = new ArrayList<>(); @@ -98,7 +97,7 @@ public class Tablist extends ChannelInboundHandlerAdapter { update.add(tabItem); } } - boolean playerNotOnTeamserver = !Storage.teamServers.containsValue(player.getCurrentServer().orElseThrow().getServerInfo()); + boolean playerNotOnTeamserver = !Storage.teamServers.containsValue(connection.getServerInfo()); for(UpsertPlayerInfoPacket.Entry item : directTabItems.values()) { if(playerNotOnTeamserver && !nonNPCs.contains(item.getProfileId()) && !npcs.contains(item.getProfileId()) && !player.getUniqueId().equals(item.getProfileId())) { npcs.add(item.getProfileId()); diff --git a/src/de/steamwar/bungeecore/tablist/TablistManager.java b/src/de/steamwar/bungeecore/tablist/TablistManager.java index 265dc58..dc477c3 100644 --- a/src/de/steamwar/bungeecore/tablist/TablistManager.java +++ b/src/de/steamwar/bungeecore/tablist/TablistManager.java @@ -22,7 +22,7 @@ package de.steamwar.bungeecore.tablist; import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.connection.DisconnectEvent; import com.velocitypowered.api.event.connection.PostLoginEvent; -import com.velocitypowered.api.event.player.ServerConnectedEvent; +import com.velocitypowered.api.event.player.ServerPostConnectEvent; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.server.RegisteredServer; import de.steamwar.bungeecore.Servertype; @@ -66,7 +66,7 @@ public class TablistManager extends BasicListener { } @Subscribe - public void onServerConnection(ServerConnectedEvent event) { + public void onServerConnection(ServerPostConnectEvent event) { synchronized (tablists) { tablists.get(event.getPlayer()).onServerSwitch(); } diff --git a/src/de/steamwar/bungeecore/util/Chat19.java b/src/de/steamwar/bungeecore/util/Chat19.java index 9641631..da66c7e 100644 --- a/src/de/steamwar/bungeecore/util/Chat19.java +++ b/src/de/steamwar/bungeecore/util/Chat19.java @@ -27,5 +27,15 @@ public class Chat19 { public static void chat(Player p, String message) { p.spoofChatInput(message); + + /*if(p.getProtocolVersion().greaterThan(ProtocolVersion.MINECRAFT_1_18_2)) { + if(message.startsWith("/")) { + ((ServerConnection) p.getServer()).getCh().write(new ClientCommand(message.substring(1), System.currentTimeMillis(), 0, Collections.emptyMap(), false, new ChatChain(Collections.emptyList(), null), new SeenMessages(0, new BitSet(0)))); + } else { + ((ServerConnection) p.getServer()).getCh().write(new ClientChat(message, System.currentTimeMillis(), 0, version < ProtocolConstants.MINECRAFT_1_19_3 ? new byte[0] : null, false, new ChatChain(Collections.emptyList(), null), new SeenMessages(0, new BitSet(0)))); + } + } else { + p.spoofChatInput(message); + }*/ } } \ No newline at end of file diff --git a/src/de/steamwar/command/SWCommand.java b/src/de/steamwar/command/SWCommand.java index 968e124..c9448ec 100644 --- a/src/de/steamwar/command/SWCommand.java +++ b/src/de/steamwar/command/SWCommand.java @@ -30,6 +30,7 @@ import net.kyori.adventure.text.event.ClickEvent; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Supplier; @@ -83,6 +84,9 @@ public class SWCommand extends AbstractSWCommand { @Override public List suggest(Invocation invocation) { + if(invocation.arguments().length == 0) + return Collections.emptyList(); + return SWCommand.this.tabComplete(Chatter.of(invocation.source()), invocation.alias(), invocation.arguments()); } @@ -177,7 +181,7 @@ public class SWCommand extends AbstractSWCommand { chatter.prefixless(s, new Message("PLAIN_STRING", hover), ClickEvent.suggestCommand("/" + name + " " + String.join(" ", subCommand.subCommand))); } } catch (Exception e) { - VelocityCore.getLogger().log(Level.WARNING, "Failed to send description of registered method '{0}' with description '{1}'".formatted(subCommand.method, Arrays.toString(subCommand.description)), e); + VelocityCore.getLogger().log(Level.WARNING, "Failed to send description of registered method '%s' with description '%s'".formatted(subCommand.method, Arrays.toString(subCommand.description)), e); } } }