viaversion update

This commit is contained in:
creeper123123321 2021-04-01 17:53:46 -03:00
parent 98edd5ac90
commit e03a3d3aa6
6 changed files with 19 additions and 73 deletions

View File

@ -52,8 +52,8 @@ tasks.named<ProcessResources>("processResources") {
dependencies { dependencies {
// transitive = false because Guava is conflicting on runClient // transitive = false because Guava is conflicting on runClient
implementation("us.myles:viaversion:3.3.0-21w08b") { isTransitive = false } implementation("us.myles:viaversion:3.3.0-21w13a") { isTransitive = false }
include("us.myles:viaversion:3.2.1") include("us.myles:viaversion:3.3.0-21w13a")
implementation("org.yaml:snakeyaml:1.26") implementation("org.yaml:snakeyaml:1.26")
include("org.yaml:snakeyaml:1.26") include("org.yaml:snakeyaml:1.26")

View File

@ -45,10 +45,9 @@ import net.fabricmc.fabric.api.registry.CommandRegistry;
import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.command.CommandSource; import net.minecraft.command.CommandSource;
import org.apache.logging.log4j.LogManager; 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.Via;
import us.myles.ViaVersion.api.data.MappingDataLoader; import us.myles.ViaVersion.api.data.MappingDataLoader;
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
import us.myles.ViaVersion.api.protocol.ProtocolVersion; import us.myles.ViaVersion.api.protocol.ProtocolVersion;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -89,7 +88,7 @@ public class ViaFabric implements ModInitializer {
@Override @Override
public void onInitialize() { public void onInitialize() {
Via.init(ViaManager.builder() Via.init(ViaManagerImpl.builder()
.injector(new VRInjector()) .injector(new VRInjector())
.loader(new VRLoader()) .loader(new VRLoader())
.commandHandler(new VRCommandHandler()) .commandHandler(new VRCommandHandler())
@ -97,9 +96,9 @@ public class ViaFabric implements ModInitializer {
FabricLoader.getInstance().getModContainer("viabackwards").ifPresent(mod -> MappingDataLoader.enableMappingsCache()); 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"); ProtocolVersion.register(-2, "AUTO");
FabricLoader.getInstance().getEntrypoints("viafabric:via_api_initialized", Runnable.class).forEach(Runnable::run); 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()); .resolve("viafabric.yml").toFile());
INIT_FUTURE.complete(null); INIT_FUTURE.complete(null);

View File

@ -44,8 +44,8 @@ import java.util.List;
public class MixinDebugHud { public class MixinDebugHud {
@Inject(at = @At("RETURN"), method = "getLeftText") @Inject(at = @At("RETURN"), method = "getLeftText")
protected void getLeftText(CallbackInfoReturnable<List<String>> info) { protected void getLeftText(CallbackInfoReturnable<List<String>> info) {
String line = "[ViaFabric] I: " + Via.getManager().getConnections().size() + " (F: " String line = "[ViaFabric] I: " + Via.getManager().getConnectionManager().getConnections().size() + " (F: "
+ Via.getManager().getConnectedClients().size() + ")"; + Via.getManager().getConnectionManager().getConnectedClients().size() + ")";
@SuppressWarnings("ConstantConditions") ChannelHandler viaDecoder = ((MixinClientConnectionAccessor) MinecraftClient.getInstance().getNetworkHandler() @SuppressWarnings("ConstantConditions") ChannelHandler viaDecoder = ((MixinClientConnectionAccessor) MinecraftClient.getInstance().getNetworkHandler()
.getConnection()).getChannel().pipeline().get(CommonTransformer.HANDLER_DECODER_NAME); .getConnection()).getChannel().pipeline().get(CommonTransformer.HANDLER_DECODER_NAME);
if (viaDecoder instanceof FabricDecodeHandler) { if (viaDecoder instanceof FabricDecodeHandler) {

View File

@ -50,13 +50,13 @@ import us.myles.ViaVersion.api.ViaVersionConfig;
import us.myles.ViaVersion.api.command.ViaCommandSender; import us.myles.ViaVersion.api.command.ViaCommandSender;
import us.myles.ViaVersion.api.configuration.ConfigurationProvider; import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
import us.myles.ViaVersion.api.platform.TaskId; 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.api.platform.ViaPlatform;
import us.myles.ViaVersion.dump.PluginInfo; import us.myles.ViaVersion.dump.PluginInfo;
import us.myles.ViaVersion.util.GsonUtil; import us.myles.ViaVersion.util.GsonUtil;
import us.myles.viaversion.libs.gson.JsonObject; 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.gson.GsonComponentSerializer;
import us.myles.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import us.myles.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import java.io.File; import java.io.File;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
@ -74,14 +74,12 @@ public class VRPlatform implements ViaPlatform<UUID> {
private final Logger logger = new JLoggerToLog4j(LogManager.getLogger("ViaVersion")); private final Logger logger = new JLoggerToLog4j(LogManager.getLogger("ViaVersion"));
private final VRViaConfig config; private final VRViaConfig config;
private final File dataFolder; private final File dataFolder;
private final ViaConnectionManager connectionManager;
private final ViaAPI<UUID> api; private final ViaAPI<UUID> api;
public VRPlatform() { public VRPlatform() {
Path configDir = FabricLoader.getInstance().getConfigDirectory().toPath().resolve("ViaFabric"); Path configDir = FabricLoader.getInstance().getConfigDirectory().toPath().resolve("ViaFabric");
config = new VRViaConfig(configDir.resolve("viaversion.yml").toFile()); config = new VRViaConfig(configDir.resolve("viaversion.yml").toFile());
dataFolder = configDir.toFile(); dataFolder = configDir.toFile();
connectionManager = new ViaConnectionManager();
api = new VRViaAPI(); api = new VRViaAPI();
} }
@ -97,6 +95,10 @@ public class VRPlatform implements ViaPlatform<UUID> {
return MinecraftClient.getInstance().getServer(); return MinecraftClient.getInstance().getServer();
} }
public static String legacyToJson(String legacy) {
return GsonComponentSerializer.gson().serialize(LegacyComponentSerializer.legacySection().deserialize(legacy));
}
@Override @Override
public Logger getLogger() { public Logger getLogger() {
return logger; return logger;
@ -194,7 +196,7 @@ public class VRPlatform implements ViaPlatform<UUID> {
if (server != null && server.isOnThread()) { if (server != null && server.isOnThread()) {
return getServerPlayers(); return getServerPlayers();
} }
return Via.getManager().getConnectedClients().values().stream() return Via.getManager().getConnectionManager().getConnectedClients().values().stream()
.map(UserCommandSender::new) .map(UserCommandSender::new)
.toArray(ViaCommandSender[]::new); .toArray(ViaCommandSender[]::new);
} }
@ -300,13 +302,4 @@ public class VRPlatform implements ViaPlatform<UUID> {
public boolean isOldClientsAllowed() { public boolean isOldClientsAllowed() {
return true; return true;
} }
@Override
public ViaConnectionManager getConnectionManager() {
return connectionManager;
}
public static String legacyToJson(String legacy) {
return GsonComponentSerializer.gson().serialize(LegacyComponentSerializer.legacySection().deserialize(legacy));
}
} }

View File

@ -25,49 +25,14 @@
package com.github.creeper123123321.viafabric.platform; package com.github.creeper123123321.viafabric.platform;
import io.netty.buffer.ByteBuf; import us.myles.ViaVersion.api.ViaAPIBase;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.ViaAPI;
import us.myles.ViaVersion.api.boss.BossBar; import us.myles.ViaVersion.api.boss.BossBar;
import us.myles.ViaVersion.api.boss.BossColor; import us.myles.ViaVersion.api.boss.BossColor;
import us.myles.ViaVersion.api.boss.BossStyle; 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; import java.util.UUID;
public class VRViaAPI implements ViaAPI<UUID> { public class VRViaAPI extends ViaAPIBase<UUID> {
@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);
}
@Override @Override
public BossBar<Void> createBossBar(String s, BossColor bossColor, BossStyle bossStyle) { public BossBar<Void> createBossBar(String s, BossColor bossColor, BossStyle bossStyle) {
return new VRBossBar(s, 1f, bossColor, bossStyle); return new VRBossBar(s, 1f, bossColor, bossStyle);
@ -77,12 +42,4 @@ public class VRViaAPI implements ViaAPI<UUID> {
public BossBar<Void> createBossBar(String s, float v, BossColor bossColor, BossStyle bossStyle) { public BossBar<Void> createBossBar(String s, float v, BossColor bossColor, BossStyle bossStyle) {
return new VRBossBar(s, v, bossColor, bossStyle); return new VRBossBar(s, v, bossColor, bossStyle);
} }
@Override
public SortedSet<Integer> getSupportedVersions() {
SortedSet<Integer> outputSet = new TreeSet<>(ProtocolRegistry.getSupportedVersions());
outputSet.removeAll(Via.getPlatform().getConf().getBlockedProtocols());
return outputSet;
}
} }

View File

@ -38,10 +38,7 @@ import us.myles.ViaVersion.api.protocol.ProtocolVersion;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.exception.CancelException; import us.myles.ViaVersion.exception.CancelException;
import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.base.BaseProtocol1_16; import us.myles.ViaVersion.protocols.base.*;
import us.myles.ViaVersion.protocols.base.BaseProtocol1_7;
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.protocols.base.VersionProvider;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -50,7 +47,7 @@ import java.net.SocketAddress;
import java.util.*; import java.util.*;
import java.util.stream.IntStream; import java.util.stream.IntStream;
public class VRVersionProvider extends VersionProvider { public class VRVersionProvider extends BaseVersionProvider {
private int[] multiconnectSupportedVersions = null; private int[] multiconnectSupportedVersions = null;
{ {