diff --git a/src/de/steamwar/bungeecore/listeners/mods/FMLPing.java b/src/de/steamwar/bungeecore/listeners/mods/FMLPing.java index 4ed9a01c..c7f68c84 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/FMLPing.java +++ b/src/de/steamwar/bungeecore/listeners/mods/FMLPing.java @@ -21,14 +21,17 @@ package de.steamwar.bungeecore.listeners.mods; import net.md_5.bungee.api.ServerPing; import java.util.ArrayList; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; public class FMLPing extends ServerPing { - private final ForgeData forgeData = new ForgeData(); + private final ForgeData forgeData; - public FMLPing(ServerPing existing) { + public FMLPing(ServerPing existing, int version) { super(existing.getVersion(), existing.getPlayers(), existing.getDescriptionComponent(), existing.getFaviconObject()); + forgeData = new ForgeData(version); } private static class ForgeData { @@ -36,14 +39,51 @@ public class FMLPing extends ServerPing { private final List mods = new ArrayList<>(); private final int fmlNetworkVersion = 2; - public ForgeData() { + public ForgeData(int versionNumber) { channels.add(new ForgeChannel("minecraft:unregister")); channels.add(new ForgeChannel("minecraft:register")); channels.add(new ForgeChannel("fml:handshake")); - mods.add(new ForgeMod("minecraft", "1.15.2")); + mods.add(new ForgeMod("minecraft", ProtocolVersion.getVersion(versionNumber).toString())); mods.add(new ForgeMod("forge", "ANY")); } + public enum ProtocolVersion { + MINECRAFT_1_18(757), + MINECRAFT_1_17_1(756), + MINECRAFT_1_16_5(754), + MINECRAFT_1_15_2(578), + MINECRAFT_1_14_4(498), + MINECRAFT_1_13(393), + UNKNOWN(0); + + private int number; + + ProtocolVersion(int versionNumber) { + this.number = versionNumber; + } + + private static Map numbers; + + static { + numbers = new LinkedHashMap<>(); + for(ProtocolVersion version : values()) { + numbers.put(version.number, version); + } + } + + public static ProtocolVersion getVersion(int versionNumber) { + ProtocolVersion protocolVersion = numbers.get(versionNumber); + if (protocolVersion != null) { + return protocolVersion; + } + return UNKNOWN; + } + + public String toString() { + return name().replace("MINECRAFT_", "").replace("_", "."); + } + } + private static class ForgeChannel { private final String res; private final String version = "FML2"; diff --git a/src/de/steamwar/bungeecore/listeners/mods/Forge.java b/src/de/steamwar/bungeecore/listeners/mods/Forge.java index 99d46143..95219659 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/Forge.java +++ b/src/de/steamwar/bungeecore/listeners/mods/Forge.java @@ -55,7 +55,7 @@ public class Forge extends BasicListener { @EventHandler public void onServerPing(ProxyPingEvent event) { - event.setResponse(new FMLPing(event.getResponse())); + event.setResponse(new FMLPing(event.getResponse(), event.getConnection().getVersion())); } @EventHandler