/* * Decompiled with CFR 0.152. * * Could not load the following classes: * javax.annotation.Nullable */ package de.maxhenkel.voicechat.integration.viaversion; import de.maxhenkel.voicechat.Voicechat; import de.maxhenkel.voicechat.util.Key; import java.lang.reflect.Field; import java.lang.reflect.Method; import javax.annotation.Nullable; public class ViaVersionCompatibility { public static void register() throws Exception { Class protocol113to1122 = ViaVersionCompatibility.getClass("com.viaversion.viaversion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2"); if (protocol113to1122 != null) { ViaVersionCompatibility.registerPackets(protocol113to1122); return; } Class protocol1122to113 = ViaVersionCompatibility.getClass("com.viaversion.viaversion.protocols.v1_12_2to1_13.Protocol1_12_2To1_13"); if (protocol1122to113 != null) { ViaVersionCompatibility.registerPackets(protocol1122to113); return; } } private static void registerPackets(Class protocolClass) throws Exception { Field mappingsField = protocolClass.getDeclaredField("MAPPINGS"); Object mappings = mappingsField.get(null); Method getChannelMappings = mappings.getClass().getDeclaredMethod("getChannelMappings", new Class[0]); Object mappingMap = getChannelMappings.invoke(mappings, new Object[0]); Method put = mappingMap.getClass().getDeclaredMethod("put", Object.class, Object.class); for (String id : Voicechat.netManager.getPackets()) { Key key = Key.parse(id); put.invoke(mappingMap, String.format("%s:%s", "vc", key.getValue()), String.format("%s:%s", "voicechat", key.getValue())); } } @Nullable private static Class getClass(String name) { try { return Class.forName(name); } catch (ClassNotFoundException e) { return null; } } }