/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.mojang.brigadier.arguments.ArgumentType * org.bukkit.entity.Player */ package de.maxhenkel.voicechat.compatibility; import com.mojang.brigadier.arguments.ArgumentType; import de.maxhenkel.voicechat.BukkitVersion; import de.maxhenkel.voicechat.compatibility.Compatibility1_8; import de.maxhenkel.voicechat.compatibility.JsonMessageBaseCompatibility; import de.maxhenkel.voicechat.compatibility.ReflectionUtils; import org.bukkit.entity.Player; public class Compatibility1_20 extends JsonMessageBaseCompatibility { public static final BukkitVersion VERSION_1_20 = BukkitVersion.parseBukkitVersion("1.20-R0.1"); public static final BukkitVersion VERSION_1_20_1 = BukkitVersion.parseBukkitVersion("1.20.1-R0.1"); public static final Compatibility1_20 INSTANCE = new Compatibility1_20(); @Override public void sendJsonMessage(Player player, String json) { this.send(player, json, false); } @Override public void sendJsonStatusMessage(Player player, String json) { this.send(player, json, true); } @Override public String createTranslationMessage(String key, String ... args) { return Compatibility1_8.constructTranslationMessage(key, args); } @Override public void sendInviteMessage(Player player, Player commandSender, String groupName, String joinCommand) { this.sendJsonMessage(player, Compatibility1_8.constructInviteMessage(commandSender, groupName, joinCommand)); } @Override public void sendIncompatibleMessage(Player player, String pluginVersion, String pluginName) { this.sendJsonMessage(player, Compatibility1_8.constructIncompatibleMessage(pluginVersion, pluginName)); } @Override public ArgumentType playerArgument() { Class argumentEntity = ReflectionUtils.getClazz("net.minecraft.commands.arguments.ArgumentEntity"); return (ArgumentType)ReflectionUtils.callMethod(argumentEntity, "c"); } @Override public ArgumentType uuidArgument() { Class argumentEntity = ReflectionUtils.getClazz("net.minecraft.commands.arguments.ArgumentUUID"); return (ArgumentType)ReflectionUtils.callMethod(argumentEntity, "a"); } private void send(Player player, String json, boolean status) { Object entityPlayer = ReflectionUtils.callMethod((Object)player, "getHandle"); Object playerConnection = ReflectionUtils.getField(entityPlayer, "c"); Class packet = ReflectionUtils.getClazz("net.minecraft.network.protocol.Packet"); Class craftChatMessage = this.getBukkitClass("util.CraftChatMessage"); Class iChatBaseComponentClass = ReflectionUtils.getClazz("net.minecraft.network.chat.IChatBaseComponent"); Object iChatBaseComponent = ReflectionUtils.callMethod(craftChatMessage, "fromJSON", new Class[]{String.class}, json); Class clientboundSystemChatPacketClass = ReflectionUtils.getClazz("net.minecraft.network.protocol.game.ClientboundSystemChatPacket"); Object clientboundSystemChatPacket = ReflectionUtils.callConstructor(clientboundSystemChatPacketClass, new Class[]{iChatBaseComponentClass, Boolean.TYPE}, iChatBaseComponent, status); ReflectionUtils.callMethod(playerConnection, "a", new Class[]{packet}, clientboundSystemChatPacket); } }