Search in sources :

Example 21 with ProtocolVersion

use of com.viaversion.viaversion.api.protocol.version.ProtocolVersion in project ViaVersion by ViaVersion.

the class BungeeViaConfig method handleConfig.

@Override
protected void handleConfig(Map<String, Object> config) {
    // Parse servers
    Map<String, Object> servers;
    if (!(config.get("bungee-servers") instanceof Map)) {
        servers = new HashMap<>();
    } else {
        servers = (Map) config.get("bungee-servers");
    }
    // Convert any bad Protocol Ids
    for (Map.Entry<String, Object> entry : new HashSet<>(servers.entrySet())) {
        if (!(entry.getValue() instanceof Integer)) {
            if (entry.getValue() instanceof String) {
                ProtocolVersion found = ProtocolVersion.getClosest((String) entry.getValue());
                if (found != null) {
                    servers.put(entry.getKey(), found.getVersion());
                } else {
                    // Remove!
                    servers.remove(entry.getKey());
                }
            } else {
                // Remove!
                servers.remove(entry.getKey());
            }
        }
    }
    // Ensure default exists
    if (!servers.containsKey("default")) {
        servers.put("default", BungeeVersionProvider.getLowestSupportedVersion());
    }
    // Put back
    config.put("bungee-servers", servers);
}
Also used : ProtocolVersion(com.viaversion.viaversion.api.protocol.version.ProtocolVersion) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Aggregations

ProtocolVersion (com.viaversion.viaversion.api.protocol.version.ProtocolVersion)21 ProtocolInfo (com.viaversion.viaversion.api.connection.ProtocolInfo)9 FabricDecodeHandler (com.viaversion.fabric.common.handler.FabricDecodeHandler)7 ChannelHandler (io.netty.channel.ChannelHandler)7 Inject (org.spongepowered.asm.mixin.injection.Inject)7 Map (java.util.Map)4 ProtocolPathEntry (com.viaversion.viaversion.api.protocol.ProtocolPathEntry)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Text (net.minecraft.text.Text)3 TranslatableText (net.minecraft.text.TranslatableText)3 Redirect (org.spongepowered.asm.mixin.injection.Redirect)3 JsonElement (com.google.gson.JsonElement)2 Via (com.viaversion.viaversion.api.Via)2 ServerProtocolVersion (com.viaversion.viaversion.api.protocol.version.ServerProtocolVersion)2 ServerProtocolVersionSingleton (com.viaversion.viaversion.protocol.ServerProtocolVersionSingleton)2 JsonObject (com.google.gson.JsonObject)1 JsonParseException (com.google.gson.JsonParseException)1 AddressParser (com.viaversion.fabric.common.AddressParser)1