ChatDeserializer
MattiaFioretti opened this issue ยท 1 comments
java.lang.IllegalStateException: Unable to invoke method public static java.lang.Object net.minecraft.util.ChatDeserializer.b(com.google.gson.Gson,java.lang.String,java.lang.Class,boolean)
at com.comphenix.protocol.reflect.accessors.DefaultMethodAccessor.invoke(DefaultMethodAccessor.java:25) ~[ProtocolLib.jar:?]
at com.comphenix.protocol.wrappers.WrappedChatComponent.deserialize(WrappedChatComponent.java:63) ~[ProtocolLib.jar:?]
at com.comphenix.protocol.wrappers.WrappedChatComponent.fromJson(WrappedChatComponent.java:94) ~[ProtocolLib.jar:?]
at it.coralrp.laroc.tooltips.api.utils.builder.TitleBuilder.setSubtitle(TitleBuilder.java:38) ~[#-tooltips-module.jar:?]
at it.coralrp.laroc.tooltips.server.commands.TestCommand.lambda$get$0(TestCommand.java:31) ~[#-tooltips-module.jar:?]
at dev.jorel.commandapi.executors.PlayerCommandExecutor.run(PlayerCommandExecutor.java:48) ~[CommandAPI-9.3.0.jar:?]
at dev.jorel.commandapi.executors.NormalExecutor.executeWith(NormalExecutor.java:44) ~[CommandAPI-9.3.0.jar:?]
at dev.jorel.commandapi.CommandAPIExecutor.execute(CommandAPIExecutor.java:137) ~[CommandAPI-9.3.0.jar:?]
at dev.jorel.commandapi.CommandAPIExecutor.execute(CommandAPIExecutor.java:110) ~[CommandAPI-9.3.0.jar:?]
at dev.jorel.commandapi.CommandAPIExecutor.execute(CommandAPIExecutor.java:91) ~[CommandAPI-9.3.0.jar:?]
at dev.jorel.commandapi.CommandAPIHandler.lambda$generateCommand$0(CommandAPIHandler.java:258) ~[CommandAPI-9.3.0.jar:?]
at com.mojang.brigadier.context.ContextChain.runExecutable(ContextChain.java:73) ~[brigadier-1.2.9.jar:?]
at net.minecraft.commands.execution.tasks.ExecuteCommand.execute(ExecuteCommand.java:32) ~[?:git-UniverseSpigot-"ab6ddf5"]
at net.minecraft.commands.execution.tasks.ExecuteCommand.execute(ExecuteCommand.java:19) ~[?:git-UniverseSpigot-"ab6ddf5"]
at net.minecraft.commands.execution.UnboundEntryAction.lambda$bind$0(UnboundEntryAction.java:8) ~[?:git-UniverseSpigot-"ab6ddf5"]
at net.minecraft.commands.execution.CommandQueueEntry.a(CommandQueueEntry.java:5) ~[?:git-UniverseSpigot-"ab6ddf5"]
at net.minecraft.commands.execution.ExecutionContext.runCommandQueue(ExecutionContext.java:101) ~[?:git-UniverseSpigot-"ab6ddf5"]
at net.minecraft.commands.Commands.executeCommandInContext(Commands.java:443) ~[?:?]
at net.minecraft.commands.Commands.performCommand(Commands.java:345) ~[?:?]
at net.minecraft.commands.Commands.performCommand(Commands.java:332) ~[?:?]
at net.minecraft.server.network.ServerGamePacketListenerImpl.performChatCommand(ServerGamePacketListenerImpl.java:2249) ~[?:?]
at net.minecraft.server.network.ServerGamePacketListenerImpl.lambda$handleChatCommand$14(ServerGamePacketListenerImpl.java:2209) ~[?:?]
at net.minecraft.util.thread.BlockableEventLoop.lambda$submitAsync$0(BlockableEventLoop.java:58) ~[?:?]
at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768) ~[?:?]
at net.minecraft.server.TickTask.run(TickTask.java:18) ~[?:git-UniverseSpigot-"ab6ddf5"]
at net.minecraft.util.thread.BlockableEventLoop.doRunTask(BlockableEventLoop.java:152) ~[?:?]
at net.minecraft.util.thread.ReentrantBlockableEventLoop.doRunTask(ReentrantBlockableEventLoop.java:24) ~[?:?]
at net.minecraft.server.MinecraftServer.doRunTask(MinecraftServer.java:1475) ~[?:git-UniverseSpigot-"ab6ddf5"]
at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:197) ~[?:git-UniverseSpigot-"ab6ddf5"]
at net.minecraft.util.thread.BlockableEventLoop.pollTask(BlockableEventLoop.java:125) ~[?:?]
at net.minecraft.server.MinecraftServer.pollTaskInternal(MinecraftServer.java:1452) ~[?:git-UniverseSpigot-"ab6ddf5"]
at net.minecraft.server.MinecraftServer.pollTask(MinecraftServer.java:1380) ~[?:git-UniverseSpigot-"ab6ddf5"]
at net.minecraft.util.thread.BlockableEventLoop.managedBlock(BlockableEventLoop.java:135) ~[?:?]
at net.minecraft.server.MinecraftServer.waitUntilNextTick(MinecraftServer.java:1358) ~[?:git-UniverseSpigot-"ab6ddf5"]
at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1247) ~[?:git-UniverseSpigot-"ab6ddf5"]
at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:324) ~[?:git-UniverseSpigot-"ab6ddf5"]
at java.lang.Thread.run(Thread.java:840) ~[?:?]
Caused by: com.google.gson.JsonIOException: Interfaces can't be instantiated! Register an InstanceCreator or a TypeAdapter for this type. Interface name: net.minecraft.network.chat.IChatBaseComponent
at com.google.gson.internal.ConstructorConstructor$3.construct(ConstructorConstructor.java:136) ~[gson-2.10.1.jar:?]
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$FieldReflectionAdapter.createAccumulator(ReflectiveTypeAdapterFactory.java:427) ~[gson-2.10.1.jar:?]
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:383) ~[gson-2.10.1.jar:?]
at net.minecraft.util.GsonHelper.fromNullableJson(GsonHelper.java:437) ~[?:?]
at net.minecraft.util.GsonHelper.fromNullableJson(GsonHelper.java:483) ~[?:?]
at com.comphenix.protocol.reflect.accessors.DefaultMethodAccessor.invoke(DefaultMethodAccessor.java:23) ~[ProtocolLib.jar:?]
... 36 more
public class TitleBuilder {
private WrappedChatComponent title = WrappedChatComponent.fromLegacyText("");
private WrappedChatComponent subtitle = WrappedChatComponent.fromLegacyText("");
private int fadeIn = 0;
private int stay = 0;
private int fadeOut = 0;
public TitleBuilder setTitleText(String text) {
this.title = WrappedChatComponent.fromText(text);
return this;
}
public TitleBuilder setSubtitleText(String text) {
this.subtitle = WrappedChatComponent.fromText(text);
return this;
}
public TitleBuilder setTitle(BaseComponent[] title) {
String json = ComponentSerializer.toString(title);
this.title = WrappedChatComponent.fromJson(json);
return this;
}
public TitleBuilder setSubtitle(BaseComponent[] subtitle) {
String json = ComponentSerializer.toString(subtitle);
this.subtitle = WrappedChatComponent.fromJson(json);
return this;
}
public TitleBuilder setTitle(String titleJson) {
this.title = WrappedChatComponent.fromJson(titleJson);
return this;
}
public TitleBuilder setSubtitle(String subtitleJson) {
this.subtitle = WrappedChatComponent.fromJson(subtitleJson);
return this;
}
public TitleBuilder setTitle(WrappedChatComponent title) {
this.title = title;
return this;
}
public TitleBuilder setSubtitle(WrappedChatComponent subtitle) {
this.subtitle = subtitle;
return this;
}
public TitleBuilder setFadeIn(int fadeIn) {
this.fadeIn = fadeIn;
return this;
}
public TitleBuilder setStay(int stay) {
this.stay = stay;
return this;
}
public TitleBuilder setFadeOut(int fadeOut) {
this.fadeOut = fadeOut;
return this;
}
public void send(TooltipsModule module, Player entity) {
PacketContainer titlePacket = new PacketContainer(PacketType.Play.Server.SET_TITLE_TEXT);
titlePacket.getChatComponents().write(0, title);
PacketContainer subtitlePacket = new PacketContainer(PacketType.Play.Server.SET_SUBTITLE_TEXT);
subtitlePacket.getChatComponents().write(0, subtitle);
PacketContainer time = new PacketContainer(PacketType.Play.Server.SET_TITLES_ANIMATION);
time.getIntegers().write(0, fadeIn).write(1, stay).write(2, fadeOut);
ProtocolManager protocolManager = module.getProtocolManager();
protocolManager.sendServerPacket(entity, titlePacket);
protocolManager.sendServerPacket(entity, subtitlePacket);
protocolManager.sendServerPacket(entity, time);
}
}