Search in sources :

Example 16 with ProtocolVersion

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

the class GeyserSpigotPlugin method isViaVersionNeeded.

/**
 * This function should not run unless ViaVersion is installed on the server.
 *
 * @return true if there is any block mappings difference between the server and client.
 */
private boolean isViaVersionNeeded() {
    ProtocolVersion serverVersion = getServerProtocolVersion();
    List<ProtocolPathEntry> protocolList = Via.getManager().getProtocolManager().getProtocolPath(MinecraftProtocol.getJavaProtocolVersion(), serverVersion.getVersion());
    if (protocolList == null) {
        // No translation needed!
        return false;
    }
    for (int i = protocolList.size() - 1; i >= 0; i--) {
        MappingData mappingData = protocolList.get(i).getProtocol().getMappingData();
        if (mappingData != null) {
            return true;
        }
    }
    // All mapping data is null, which means client and server block states are the same
    return false;
}
Also used : ProtocolPathEntry(com.viaversion.viaversion.api.protocol.ProtocolPathEntry) MappingData(com.viaversion.viaversion.api.data.MappingData) ProtocolVersion(com.viaversion.viaversion.api.protocol.version.ProtocolVersion)

Example 17 with ProtocolVersion

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

the class VelocityViaConfig method handleConfig.

@Override
protected void handleConfig(Map<String, Object> config) {
    // Parse servers
    Map<String, Object> servers;
    if (!(config.get("velocity-servers") instanceof Map)) {
        servers = new HashMap<>();
    } else {
        servers = (Map) config.get("velocity-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")) {
        // Side note: This doesn't use ProtocolRegistry as it doesn't know the protocol version at boot.
        try {
            servers.put("default", VelocityViaInjector.getLowestSupportedProtocolVersion());
        } catch (Exception e) {
            // Something went very wrong
            e.printStackTrace();
        }
    }
    // Put back
    config.put("velocity-servers", servers);
}
Also used : ProtocolVersion(com.viaversion.viaversion.api.protocol.version.ProtocolVersion) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 18 with ProtocolVersion

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

the class ProtocolInfoImpl method setProtocolVersion.

@Override
public void setProtocolVersion(int protocolVersion) {
    // Map snapshot versions to the higher/orderer release version
    ProtocolVersion protocol = ProtocolVersion.getProtocol(protocolVersion);
    this.protocolVersion = protocol.getVersion();
}
Also used : ProtocolVersion(com.viaversion.viaversion.api.protocol.version.ProtocolVersion)

Example 19 with ProtocolVersion

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

the class ProtocolInfoImpl method setServerProtocolVersion.

@Override
public void setServerProtocolVersion(int serverProtocolVersion) {
    ProtocolVersion protocol = ProtocolVersion.getProtocol(serverProtocolVersion);
    this.serverProtocolVersion = protocol.getVersion();
}
Also used : ProtocolVersion(com.viaversion.viaversion.api.protocol.version.ProtocolVersion)

Example 20 with ProtocolVersion

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

the class ViaManagerImpl method loadServerProtocol.

private void loadServerProtocol() {
    try {
        ProtocolVersion serverProtocolVersion = ProtocolVersion.getProtocol(injector.getServerProtocolVersion());
        ServerProtocolVersion versionInfo;
        if (platform.isProxy()) {
            IntSortedSet supportedVersions = injector.getServerProtocolVersions();
            versionInfo = new ServerProtocolVersionRange(supportedVersions.firstInt(), supportedVersions.lastInt(), supportedVersions);
        } else {
            versionInfo = new ServerProtocolVersionSingleton(serverProtocolVersion.getVersion());
        }
        protocolManager.setServerProtocol(versionInfo);
    } catch (Exception e) {
        platform.getLogger().severe("ViaVersion failed to get the server protocol!");
        e.printStackTrace();
    }
}
Also used : ServerProtocolVersion(com.viaversion.viaversion.api.protocol.version.ServerProtocolVersion) ServerProtocolVersionRange(com.viaversion.viaversion.protocol.ServerProtocolVersionRange) IntSortedSet(it.unimi.dsi.fastutil.ints.IntSortedSet) ServerProtocolVersion(com.viaversion.viaversion.api.protocol.version.ServerProtocolVersion) ProtocolVersion(com.viaversion.viaversion.api.protocol.version.ProtocolVersion) ServerProtocolVersionSingleton(com.viaversion.viaversion.protocol.ServerProtocolVersionSingleton)

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