diff --git a/build.gradle.kts b/build.gradle.kts index d83818f..98efd3c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -52,8 +52,8 @@ tasks.named("processResources") { dependencies { // transitive = false because Guava is conflicting on runClient - implementation("us.myles:viaversion:3.3.0-21w08b") { isTransitive = false } - include("us.myles:viaversion:3.2.1") + implementation("us.myles:viaversion:3.3.0-21w13a") { isTransitive = false } + include("us.myles:viaversion:3.3.0-21w13a") implementation("org.yaml:snakeyaml:1.26") include("org.yaml:snakeyaml:1.26") diff --git a/src/main/java/com/github/creeper123123321/viafabric/ViaFabric.java b/src/main/java/com/github/creeper123123321/viafabric/ViaFabric.java index cdb44cf..14e3719 100644 --- a/src/main/java/com/github/creeper123123321/viafabric/ViaFabric.java +++ b/src/main/java/com/github/creeper123123321/viafabric/ViaFabric.java @@ -45,10 +45,9 @@ import net.fabricmc.fabric.api.registry.CommandRegistry; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.command.CommandSource; import org.apache.logging.log4j.LogManager; -import us.myles.ViaVersion.ViaManager; +import us.myles.ViaVersion.ViaManagerImpl; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.MappingDataLoader; -import us.myles.ViaVersion.api.protocol.ProtocolRegistry; import us.myles.ViaVersion.api.protocol.ProtocolVersion; import java.util.concurrent.CompletableFuture; @@ -89,7 +88,7 @@ public class ViaFabric implements ModInitializer { @Override public void onInitialize() { - Via.init(ViaManager.builder() + Via.init(ViaManagerImpl.builder() .injector(new VRInjector()) .loader(new VRLoader()) .commandHandler(new VRCommandHandler()) @@ -97,9 +96,9 @@ public class ViaFabric implements ModInitializer { FabricLoader.getInstance().getModContainer("viabackwards").ifPresent(mod -> MappingDataLoader.enableMappingsCache()); - Via.getManager().init(); + ((ViaManagerImpl) Via.getManager()).init(); - ProtocolRegistry.registerBaseProtocol(ViaFabricHostnameProtocol.INSTANCE, Range.lessThan(Integer.MIN_VALUE)); + Via.getManager().getProtocolManager().registerBaseProtocol(ViaFabricHostnameProtocol.INSTANCE, Range.lessThan(Integer.MIN_VALUE)); ProtocolVersion.register(-2, "AUTO"); FabricLoader.getInstance().getEntrypoints("viafabric:via_api_initialized", Runnable.class).forEach(Runnable::run); @@ -115,7 +114,7 @@ public class ViaFabric implements ModInitializer { } } - config = new VRConfig(FabricLoader.getInstance().getConfigDirectory().toPath().resolve("ViaFabric") + config = new VRConfig(FabricLoader.getInstance().getConfigDir().resolve("ViaFabric") .resolve("viafabric.yml").toFile()); INIT_FUTURE.complete(null); diff --git a/src/main/java/com/github/creeper123123321/viafabric/mixin/debug/client/MixinDebugHud.java b/src/main/java/com/github/creeper123123321/viafabric/mixin/debug/client/MixinDebugHud.java index 41e1881..6aa4cdf 100644 --- a/src/main/java/com/github/creeper123123321/viafabric/mixin/debug/client/MixinDebugHud.java +++ b/src/main/java/com/github/creeper123123321/viafabric/mixin/debug/client/MixinDebugHud.java @@ -44,8 +44,8 @@ import java.util.List; public class MixinDebugHud { @Inject(at = @At("RETURN"), method = "getLeftText") protected void getLeftText(CallbackInfoReturnable> info) { - String line = "[ViaFabric] I: " + Via.getManager().getConnections().size() + " (F: " - + Via.getManager().getConnectedClients().size() + ")"; + String line = "[ViaFabric] I: " + Via.getManager().getConnectionManager().getConnections().size() + " (F: " + + Via.getManager().getConnectionManager().getConnectedClients().size() + ")"; @SuppressWarnings("ConstantConditions") ChannelHandler viaDecoder = ((MixinClientConnectionAccessor) MinecraftClient.getInstance().getNetworkHandler() .getConnection()).getChannel().pipeline().get(CommonTransformer.HANDLER_DECODER_NAME); if (viaDecoder instanceof FabricDecodeHandler) { diff --git a/src/main/java/com/github/creeper123123321/viafabric/platform/VRPlatform.java b/src/main/java/com/github/creeper123123321/viafabric/platform/VRPlatform.java index aae0081..9e15b1d 100644 --- a/src/main/java/com/github/creeper123123321/viafabric/platform/VRPlatform.java +++ b/src/main/java/com/github/creeper123123321/viafabric/platform/VRPlatform.java @@ -50,13 +50,13 @@ import us.myles.ViaVersion.api.ViaVersionConfig; import us.myles.ViaVersion.api.command.ViaCommandSender; import us.myles.ViaVersion.api.configuration.ConfigurationProvider; import us.myles.ViaVersion.api.platform.TaskId; -import us.myles.ViaVersion.api.platform.ViaConnectionManager; import us.myles.ViaVersion.api.platform.ViaPlatform; import us.myles.ViaVersion.dump.PluginInfo; import us.myles.ViaVersion.util.GsonUtil; import us.myles.viaversion.libs.gson.JsonObject; import us.myles.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import us.myles.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; + import java.io.File; import java.nio.file.Path; import java.util.ArrayList; @@ -74,14 +74,12 @@ public class VRPlatform implements ViaPlatform { private final Logger logger = new JLoggerToLog4j(LogManager.getLogger("ViaVersion")); private final VRViaConfig config; private final File dataFolder; - private final ViaConnectionManager connectionManager; private final ViaAPI api; public VRPlatform() { Path configDir = FabricLoader.getInstance().getConfigDirectory().toPath().resolve("ViaFabric"); config = new VRViaConfig(configDir.resolve("viaversion.yml").toFile()); dataFolder = configDir.toFile(); - connectionManager = new ViaConnectionManager(); api = new VRViaAPI(); } @@ -97,6 +95,10 @@ public class VRPlatform implements ViaPlatform { return MinecraftClient.getInstance().getServer(); } + public static String legacyToJson(String legacy) { + return GsonComponentSerializer.gson().serialize(LegacyComponentSerializer.legacySection().deserialize(legacy)); + } + @Override public Logger getLogger() { return logger; @@ -194,7 +196,7 @@ public class VRPlatform implements ViaPlatform { if (server != null && server.isOnThread()) { return getServerPlayers(); } - return Via.getManager().getConnectedClients().values().stream() + return Via.getManager().getConnectionManager().getConnectedClients().values().stream() .map(UserCommandSender::new) .toArray(ViaCommandSender[]::new); } @@ -300,13 +302,4 @@ public class VRPlatform implements ViaPlatform { public boolean isOldClientsAllowed() { return true; } - - @Override - public ViaConnectionManager getConnectionManager() { - return connectionManager; - } - - public static String legacyToJson(String legacy) { - return GsonComponentSerializer.gson().serialize(LegacyComponentSerializer.legacySection().deserialize(legacy)); - } } diff --git a/src/main/java/com/github/creeper123123321/viafabric/platform/VRViaAPI.java b/src/main/java/com/github/creeper123123321/viafabric/platform/VRViaAPI.java index 9387247..9626629 100644 --- a/src/main/java/com/github/creeper123123321/viafabric/platform/VRViaAPI.java +++ b/src/main/java/com/github/creeper123123321/viafabric/platform/VRViaAPI.java @@ -25,49 +25,14 @@ package com.github.creeper123123321.viafabric.platform; -import io.netty.buffer.ByteBuf; -import us.myles.ViaVersion.api.Via; -import us.myles.ViaVersion.api.ViaAPI; +import us.myles.ViaVersion.api.ViaAPIBase; import us.myles.ViaVersion.api.boss.BossBar; import us.myles.ViaVersion.api.boss.BossColor; import us.myles.ViaVersion.api.boss.BossStyle; -import us.myles.ViaVersion.api.data.UserConnection; -import us.myles.ViaVersion.api.protocol.ProtocolRegistry; -import java.util.SortedSet; -import java.util.TreeSet; import java.util.UUID; -public class VRViaAPI implements ViaAPI { - @Override - public int getPlayerVersion(UUID uuid) { - UserConnection con = Via.getManager().getConnection(uuid); - if (con != null) { - return con.getProtocolInfo().getProtocolVersion(); - } - try { - return Via.getManager().getInjector().getServerProtocolVersion(); - } catch (Exception e) { - throw new AssertionError(e); - } - } - - @Override - public boolean isInjected(UUID uuid) { - return Via.getManager().isClientConnected(uuid); - } - - @Override - public String getVersion() { - return Via.getPlatform().getPluginVersion(); - } - - @Override - public void sendRawPacket(UUID uuid, ByteBuf byteBuf) throws IllegalArgumentException { - UserConnection ci = Via.getManager().getConnection(uuid); - ci.sendRawPacket(byteBuf); - } - +public class VRViaAPI extends ViaAPIBase { @Override public BossBar createBossBar(String s, BossColor bossColor, BossStyle bossStyle) { return new VRBossBar(s, 1f, bossColor, bossStyle); @@ -77,12 +42,4 @@ public class VRViaAPI implements ViaAPI { public BossBar createBossBar(String s, float v, BossColor bossColor, BossStyle bossStyle) { return new VRBossBar(s, v, bossColor, bossStyle); } - - @Override - public SortedSet getSupportedVersions() { - SortedSet outputSet = new TreeSet<>(ProtocolRegistry.getSupportedVersions()); - outputSet.removeAll(Via.getPlatform().getConf().getBlockedProtocols()); - - return outputSet; - } } diff --git a/src/main/java/com/github/creeper123123321/viafabric/providers/VRVersionProvider.java b/src/main/java/com/github/creeper123123321/viafabric/providers/VRVersionProvider.java index 7b9422d..a52d839 100644 --- a/src/main/java/com/github/creeper123123321/viafabric/providers/VRVersionProvider.java +++ b/src/main/java/com/github/creeper123123321/viafabric/providers/VRVersionProvider.java @@ -38,10 +38,7 @@ import us.myles.ViaVersion.api.protocol.ProtocolVersion; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.exception.CancelException; import us.myles.ViaVersion.packets.State; -import us.myles.ViaVersion.protocols.base.BaseProtocol1_16; -import us.myles.ViaVersion.protocols.base.BaseProtocol1_7; -import us.myles.ViaVersion.protocols.base.ProtocolInfo; -import us.myles.ViaVersion.protocols.base.VersionProvider; +import us.myles.ViaVersion.protocols.base.*; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -50,7 +47,7 @@ import java.net.SocketAddress; import java.util.*; import java.util.stream.IntStream; -public class VRVersionProvider extends VersionProvider { +public class VRVersionProvider extends BaseVersionProvider { private int[] multiconnectSupportedVersions = null; {