From 24075306fd7526923e91b15548bdbe2a6844d655 Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Fri, 11 Mar 2022 19:21:29 +0100 Subject: [PATCH] Fabric Mod Sender Integration. Mod itself is not final --- src/de/steamwar/bungeecore/BungeeCore.java | 2 + .../bungeecore/listeners/mods/Fabric.java | 45 +++++++++++++++++++ src/de/steamwar/bungeecore/sql/Mod.java | 3 +- 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 src/de/steamwar/bungeecore/listeners/mods/Fabric.java diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index b7338af..8e9e8fd 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -70,6 +70,7 @@ public class BungeeCore extends Plugin { @Override public void onEnable(){ getProxy().registerChannel("sw:bridge"); + getProxy().registerChannel("fabricmodsender:mods"); setInstance(this); loadConfig(); @@ -86,6 +87,7 @@ public class BungeeCore extends Plugin { new ModLoaderBlocker(); new WorldDownloader(); new BrandListener(); + new Fabric(); new Node.LocalNode(); //new Node.RemoteNode("lx"); diff --git a/src/de/steamwar/bungeecore/listeners/mods/Fabric.java b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java new file mode 100644 index 0000000..61ae91a --- /dev/null +++ b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java @@ -0,0 +1,45 @@ +package de.steamwar.bungeecore.listeners.mods; + +import de.steamwar.bungeecore.listeners.BasicListener; +import de.steamwar.bungeecore.sql.Mod; +import io.netty.util.internal.StringUtil; +import net.md_5.bungee.api.connection.PendingConnection; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.event.PluginMessageEvent; +import net.md_5.bungee.event.EventHandler; +import org.apache.commons.lang3.StringUtils; + +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; + +public class Fabric extends BasicListener { + + @EventHandler + public void onPluginMessageEvent(PluginMessageEvent e){ + if(!e.getTag().equals("fabricmodsender:mods")) + return; + + String dataString = new String(e.getData()).substring(2); + dataString = StringUtils.chop(dataString); + char x = 34; + dataString = dataString.replace(x, ' '); + dataString = dataString.replaceAll("\\s+",""); + + String[] parts = dataString.split(","); + + List mods = new ArrayList<>(); + + for(String mod : parts) { + mods.add(Mod.get(mod, Mod.Platform.FABRIC)); + } + + if (e.getSender() instanceof ProxiedPlayer) { + ProxiedPlayer player = (ProxiedPlayer) e.getSender(); + + if(!Utils.handleMods(player, mods)) + player.disconnect(""); + } + } + +} diff --git a/src/de/steamwar/bungeecore/sql/Mod.java b/src/de/steamwar/bungeecore/sql/Mod.java index 9aad08b..dcd69ae 100644 --- a/src/de/steamwar/bungeecore/sql/Mod.java +++ b/src/de/steamwar/bungeecore/sql/Mod.java @@ -61,7 +61,8 @@ public class Mod { public enum Platform{ FORGE(0), - LABYMOD(1); + LABYMOD(1), + FABRIC(2); Platform(int value){ this.value = value;