Archiviert
1
0

FmlPing now multi versions

Dieser Commit ist enthalten in:
zOnlyKroks 2022-01-31 16:58:48 +01:00
Ursprung 2026893d95
Commit 0033de233b
2 geänderte Dateien mit 45 neuen und 5 gelöschten Zeilen

Datei anzeigen

@ -21,14 +21,17 @@ package de.steamwar.bungeecore.listeners.mods;
import net.md_5.bungee.api.ServerPing; import net.md_5.bungee.api.ServerPing;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map;
public class FMLPing extends ServerPing { 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()); super(existing.getVersion(), existing.getPlayers(), existing.getDescriptionComponent(), existing.getFaviconObject());
forgeData = new ForgeData(version);
} }
private static class ForgeData { private static class ForgeData {
@ -36,14 +39,51 @@ public class FMLPing extends ServerPing {
private final List<ForgeMod> mods = new ArrayList<>(); private final List<ForgeMod> mods = new ArrayList<>();
private final int fmlNetworkVersion = 2; private final int fmlNetworkVersion = 2;
public ForgeData() { public ForgeData(int versionNumber) {
channels.add(new ForgeChannel("minecraft:unregister")); channels.add(new ForgeChannel("minecraft:unregister"));
channels.add(new ForgeChannel("minecraft:register")); channels.add(new ForgeChannel("minecraft:register"));
channels.add(new ForgeChannel("fml:handshake")); 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")); 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<Integer, ProtocolVersion> 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 static class ForgeChannel {
private final String res; private final String res;
private final String version = "FML2"; private final String version = "FML2";

Datei anzeigen

@ -55,7 +55,7 @@ public class Forge extends BasicListener {
@EventHandler @EventHandler
public void onServerPing(ProxyPingEvent event) { public void onServerPing(ProxyPingEvent event) {
event.setResponse(new FMLPing(event.getResponse())); event.setResponse(new FMLPing(event.getResponse(), event.getConnection().getVersion()));
} }
@EventHandler @EventHandler