fixed injector, don't pretend to be a proxy on server-side

This commit is contained in:
creeper123123321 2021-12-18 08:07:47 -03:00
parent db57ced2bb
commit 43379d2369
14 changed files with 47 additions and 8 deletions

View File

@ -15,6 +15,7 @@ import com.viaversion.viaversion.libs.gson.JsonObject;
import io.netty.channel.EventLoop;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
import net.fabricmc.loader.api.Version;
@ -41,11 +42,15 @@ public abstract class AbstractFabricPlatform implements ViaPlatform<UUID> {
}
public void init() {
// We'll use it early for ViaInjector
installNativeVersionProvider();
Path configDir = FabricLoader.getInstance().getConfigDir().resolve("ViaFabric");
dataFolder = configDir.toFile();
config = new FabricViaConfig(configDir.resolve("viaversion.yml").toFile());
}
protected abstract void installNativeVersionProvider();
protected abstract ExecutorService asyncService();
protected abstract EventLoop eventLoop();
@ -94,7 +99,7 @@ public abstract class AbstractFabricPlatform implements ViaPlatform<UUID> {
@Override
public boolean isProxy() {
// We kinda of have all server versions
return true;
return FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT;
}
@Override

View File

@ -1,6 +1,7 @@
package com.viaversion.fabric.mc114.platform;
import com.viaversion.fabric.common.commands.UserCommandSender;
import com.viaversion.fabric.common.platform.NativeVersionProvider;
import com.viaversion.fabric.common.provider.AbstractFabricPlatform;
import com.viaversion.fabric.common.util.FutureTaskId;
import com.viaversion.fabric.common.util.RemappingUtil;
@ -108,6 +109,11 @@ public class FabricPlatform extends AbstractFabricPlatform {
return false; // Can't know if it worked
}
@Override
protected void installNativeVersionProvider() {
Via.getManager().getProviders().use(NativeVersionProvider.class, new FabricNativeVersionProvider());
}
@Override
protected ExecutorService asyncService() {
return ViaFabric.ASYNC_EXECUTOR;

View File

@ -15,7 +15,6 @@ import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MovementTr
public class VFLoader implements ViaPlatformLoader {
@Override
public void load() {
Via.getManager().getProviders().use(NativeVersionProvider.class, new FabricNativeVersionProvider());
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BungeeMovementTransmitter());
Via.getManager().getProviders().use(VersionProvider.class, new FabricVersionProvider());

View File

@ -1,6 +1,7 @@
package com.viaversion.fabric.mc115.platform;
import com.viaversion.fabric.common.commands.UserCommandSender;
import com.viaversion.fabric.common.platform.NativeVersionProvider;
import com.viaversion.fabric.common.provider.AbstractFabricPlatform;
import com.viaversion.fabric.common.util.FutureTaskId;
import com.viaversion.fabric.common.util.RemappingUtil;
@ -38,6 +39,11 @@ public class FabricPlatform extends AbstractFabricPlatform {
return MinecraftClient.getInstance().getServer();
}
@Override
protected void installNativeVersionProvider() {
Via.getManager().getProviders().use(NativeVersionProvider.class, new FabricNativeVersionProvider());
}
@Override
protected ExecutorService asyncService() {
return ViaFabric.ASYNC_EXECUTOR;

View File

@ -15,7 +15,6 @@ import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MovementTr
public class VFLoader implements ViaPlatformLoader {
@Override
public void load() {
Via.getManager().getProviders().use(NativeVersionProvider.class, new FabricNativeVersionProvider());
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BungeeMovementTransmitter());
Via.getManager().getProviders().use(VersionProvider.class, new FabricVersionProvider());

View File

@ -1,6 +1,7 @@
package com.viaversion.fabric.mc116.platform;
import com.viaversion.fabric.common.commands.UserCommandSender;
import com.viaversion.fabric.common.platform.NativeVersionProvider;
import com.viaversion.fabric.common.provider.AbstractFabricPlatform;
import com.viaversion.fabric.common.util.FutureTaskId;
import com.viaversion.fabric.common.util.RemappingUtil;
@ -37,6 +38,11 @@ public class FabricPlatform extends AbstractFabricPlatform {
return MinecraftClient.getInstance().getServer();
}
@Override
protected void installNativeVersionProvider() {
Via.getManager().getProviders().use(NativeVersionProvider.class, new FabricNativeVersionProvider());
}
@Override
protected ExecutorService asyncService() {
return ViaFabric.ASYNC_EXECUTOR;

View File

@ -15,7 +15,6 @@ import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MovementTr
public class VFLoader implements ViaPlatformLoader {
@Override
public void load() {
Via.getManager().getProviders().use(NativeVersionProvider.class, new FabricNativeVersionProvider());
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BungeeMovementTransmitter());
Via.getManager().getProviders().use(VersionProvider.class, new FabricVersionProvider());

View File

@ -1,6 +1,7 @@
package com.viaversion.fabric.mc117.platform;
import com.viaversion.fabric.common.commands.UserCommandSender;
import com.viaversion.fabric.common.platform.NativeVersionProvider;
import com.viaversion.fabric.common.provider.AbstractFabricPlatform;
import com.viaversion.fabric.common.util.FutureTaskId;
import com.viaversion.fabric.common.util.RemappingUtil;
@ -109,6 +110,11 @@ public class FabricPlatform extends AbstractFabricPlatform {
return false; // Can't know if it worked
}
@Override
protected void installNativeVersionProvider() {
Via.getManager().getProviders().use(NativeVersionProvider.class, new FabricNativeVersionProvider());
}
@Override
protected ExecutorService asyncService() {
return ViaFabric.ASYNC_EXECUTOR;

View File

@ -15,7 +15,6 @@ import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MovementTr
public class VFLoader implements ViaPlatformLoader {
@Override
public void load() {
Via.getManager().getProviders().use(NativeVersionProvider.class, new FabricNativeVersionProvider());
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BungeeMovementTransmitter());
Via.getManager().getProviders().use(VersionProvider.class, new FabricVersionProvider());

View File

@ -1,6 +1,7 @@
package com.viaversion.fabric.mc118.platform;
import com.viaversion.fabric.common.commands.UserCommandSender;
import com.viaversion.fabric.common.platform.NativeVersionProvider;
import com.viaversion.fabric.common.provider.AbstractFabricPlatform;
import com.viaversion.fabric.common.util.FutureTaskId;
import com.viaversion.fabric.common.util.RemappingUtil;
@ -109,6 +110,11 @@ public class FabricPlatform extends AbstractFabricPlatform {
return false; // Can't know if it worked
}
@Override
protected void installNativeVersionProvider() {
Via.getManager().getProviders().use(NativeVersionProvider.class, new FabricNativeVersionProvider());
}
@Override
protected ExecutorService asyncService() {
return ViaFabric.ASYNC_EXECUTOR;

View File

@ -15,7 +15,6 @@ import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MovementTr
public class VFLoader implements ViaPlatformLoader {
@Override
public void load() {
Via.getManager().getProviders().use(NativeVersionProvider.class, new FabricNativeVersionProvider());
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BungeeMovementTransmitter());
Via.getManager().getProviders().use(VersionProvider.class, new FabricVersionProvider());

View File

@ -7,6 +7,7 @@ import net.fabricmc.api.Environment;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.realms.RealmsSharedConstants;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.ServerMetadata;
public class FabricNativeVersionProvider implements NativeVersionProvider {
@Override
@ -14,7 +15,10 @@ public class FabricNativeVersionProvider implements NativeVersionProvider {
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
return getClientProtocol();
}
return MinecraftServer.getServer().getServerMetadata().getVersion().getProtocolVersion();
ServerMetadata.Version version = MinecraftServer.getServer().getServerMetadata().getVersion();
if (version == null) return ProtocolVersion.v1_8.getVersion();
return version.getProtocolVersion();
}
@Environment(EnvType.CLIENT)

View File

@ -1,6 +1,7 @@
package com.viaversion.fabric.mc18.platform;
import com.viaversion.fabric.common.commands.UserCommandSender;
import com.viaversion.fabric.common.platform.NativeVersionProvider;
import com.viaversion.fabric.common.provider.AbstractFabricPlatform;
import com.viaversion.fabric.common.util.FutureTaskId;
import com.viaversion.fabric.common.util.RemappingUtil;
@ -32,6 +33,11 @@ public class FabricPlatform extends AbstractFabricPlatform {
return MinecraftServer.getServer();
}
@Override
protected void installNativeVersionProvider() {
Via.getManager().getProviders().use(NativeVersionProvider.class, new FabricNativeVersionProvider());
}
@Override
protected ExecutorService asyncService() {
return ViaFabric.ASYNC_EXECUTOR;

View File

@ -15,7 +15,6 @@ import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MovementTr
public class VFLoader implements ViaPlatformLoader {
@Override
public void load() {
Via.getManager().getProviders().use(NativeVersionProvider.class, new FabricNativeVersionProvider());
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BungeeMovementTransmitter());
Via.getManager().getProviders().use(VersionProvider.class, new FabricVersionProvider());