From 076a7d9bf2a32a4b09970234853838270bbb42a0 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 2 Jan 2021 17:23:37 +0100 Subject: [PATCH] Work around new forge mod loader Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/Message.java | 4 +-- .../listeners/mods/ModLoaderBlocker.java | 35 ++++++++++++++----- .../steamwar/messages/BungeeCore.properties | 4 +++ 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/de/steamwar/bungeecore/Message.java b/src/de/steamwar/bungeecore/Message.java index 1e5e0c0..65f1dec 100644 --- a/src/de/steamwar/bungeecore/Message.java +++ b/src/de/steamwar/bungeecore/Message.java @@ -48,10 +48,10 @@ public class Message { } private static String parse(String message, boolean prefixed, CommandSender sender,Object... params){ - Locale locale; + Locale locale = null; if(sender instanceof ProxiedPlayer) locale = ((ProxiedPlayer)sender).getLocale(); - else + if(locale == null) locale = Locale.getDefault(); ResourceBundle resourceBundle = ResourceBundle.getBundle("de.steamwar.messages.BungeeCore", locale); diff --git a/src/de/steamwar/bungeecore/listeners/mods/ModLoaderBlocker.java b/src/de/steamwar/bungeecore/listeners/mods/ModLoaderBlocker.java index af123d8..11e8d87 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/ModLoaderBlocker.java +++ b/src/de/steamwar/bungeecore/listeners/mods/ModLoaderBlocker.java @@ -19,10 +19,7 @@ package de.steamwar.bungeecore.listeners.mods; -import de.steamwar.bungeecore.BungeeCore; -import de.steamwar.bungeecore.Servertype; -import de.steamwar.bungeecore.Storage; -import de.steamwar.bungeecore.Subserver; +import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.listeners.BasicListener; import net.md_5.bungee.api.connection.Connection; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -31,6 +28,8 @@ import net.md_5.bungee.api.event.PluginMessageEvent; import net.md_5.bungee.api.event.ServerSwitchEvent; import net.md_5.bungee.event.EventHandler; +import java.nio.charset.StandardCharsets; + public class ModLoaderBlocker extends BasicListener { @EventHandler @@ -45,17 +44,37 @@ public class ModLoaderBlocker extends BasicListener { if(new String(e.getData()).contains("fabric")){ ProxiedPlayer p = (ProxiedPlayer) sender; Storage.fabricPlayers.add(p); - BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§7Du hast Fabric installiert. Mit Fabric kannst du nicht auf die Arenen"); + Message.send("MODLOADER_INSTALLED", p, "Fabric"); }else if(new String(e.getData()).contains("LiteLoader")) { ProxiedPlayer p = (ProxiedPlayer) sender; Storage.fabricPlayers.add(p); - BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§7Du hast LiteLoader installiert. Mit LiteLoader kannst du nicht auf die Arenen"); + Message.send("MODLOADER_INSTALLED", p, "LiteLoader"); + } + } + + @EventHandler + public void onPluginMessage(PluginMessageEvent e){ + if(!e.getTag().equals("minecraft:register")) + return; + + Connection sender = e.getSender(); + if(!(sender instanceof ProxiedPlayer)) + return; + ProxiedPlayer p = (ProxiedPlayer) sender; + + if(p.getPendingConnection().getVersion() <= 340) + return; + + String registered = new String(e.getData(), StandardCharsets.UTF_8); + if(registered.contains("fml:loginwrapper") || registered.contains("fml:handshake") || registered.contains("fml:play")){ + Storage.fabricPlayers.add(p); + Message.send("MODLOADER_INSTALLED", p, "Forge"); } } @EventHandler public void onDisconnect(PlayerDisconnectEvent e){ - Storage.fabricPlayers.removeIf(player -> player == e.getPlayer()); + Storage.fabricPlayers.remove(e.getPlayer()); } @EventHandler @@ -64,7 +83,7 @@ public class ModLoaderBlocker extends BasicListener { && Subserver.getSubserver(event.getPlayer()).getType() == Servertype.ARENA && isFabric(event.getPlayer())) { event.getPlayer().connect(BungeeCore.get().getProxy().getServerInfo(BungeeCore.LOBBY_SERVER)); - BungeeCore.send(event.getPlayer(), BungeeCore.CHAT_PREFIX + "§cMit Fabric und LiteLoader kannst du nicht auf die Arenen"); + Message.send("MODLOADER_DENIED", event.getPlayer()); } } diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 73f532d..0b11312 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -5,6 +5,10 @@ UNKNOWN_COMMAND=§cUnbekannter Befehl. UNKNOWN_PLAYER=§cDiesen Spieler gibt es nicht. INVALID_TIME=§cUngültige Zeitangabe. +#ModLoader blocker +MODLOADER_INSTALLED=§7Du hast §e{0} §7installiert. Daher kannst du keinen Arenen beitreten. +MODLOADER_DENIED=§cMit Fabric, Forge und LiteLoader kannst du keinen Arenen beitreten. + #Help command HELP_LOBBY=§7Kehre von überall mit §8/§el §7zur Lobby zurück! HELP_LOBBY_HOVER=§eZurück zur Lobby -- 2.39.2