Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.19 break changes #18

Open
corentingosselin opened this issue Jul 6, 2022 · 4 comments
Open

1.19 break changes #18

corentingosselin opened this issue Jul 6, 2022 · 4 comments

Comments

@corentingosselin
Copy link

Hello,

There is an error when using JSONMessage:

[22:26:54] [Server thread/WARN]: java.lang.ClassNotFoundException: net.minecraft.network.chat.ChatComponentText
[22:26:54] [Server thread/WARN]: 	at org.bukkit.plugin.java.PluginClassLoader.loadClass0(PluginClassLoader.java:147)
[22:26:54] [Server thread/WARN]: 	at org.bukkit.plugin.java.PluginClassLoader.loadClass(PluginClassLoader.java:99)
[22:26:54] [Server thread/WARN]: 	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
[22:26:54] [Server thread/WARN]: 	at java.base/java.lang.Class.forName0(Native Method)
[22:26:54] [Server thread/WARN]: 	at java.base/java.lang.Class.forName(Class.java:375)
[22:26:54] [Server thread/WARN]: 	at me.rayzr522.jsonmessage.ReflectionHelper.getClass(ReflectionHelper.java:23)
[22:26:54] [Server thread/WARN]: 	at me.rayzr522.jsonmessage.compat.impl.ChatComponentImpl17ToFuture.<init>(ChatComponentImpl17ToFuture.java:16)
[22:26:54] [Server thread/WARN]: 	at me.rayzr522.jsonmessage.compat.ImplementationPicker.lambda$getImplementation$1(ImplementationPicker.java:29)
[22:26:54] [Server thread/WARN]: 	at java.base/java.util.Optional.map(Optional.java:260)
[22:26:54] [Server thread/WARN]: 	at me.rayzr522.jsonmessage.compat.ImplementationPicker.getImplementation(ImplementationPicker.java:27)
[22:26:54] [Server thread/WARN]: 	at me.rayzr522.jsonmessage.compat.CompatManager.<init>(CompatManager.java:20)
[22:26:54] [Server thread/WARN]: 	at me.rayzr522.jsonmessage.compat.CompatManager.get(CompatManager.java:54)
[22:26:54] [Server thread/WARN]: 	at me.rayzr522.jsonmessage.compat.CompatManager.chatComponent(CompatManager.java:60)
[22:26:54] [Server thread/WARN]: 	at me.rayzr522.jsonmessage.JSONMessage.send(JSONMessage.java:159)
[22:26:54] [Server thread/WARN]: 	at fr.cocoraid.prodigynightclub.commands.admin.NightclubCMD.lambda$onNightclubList$0(NightclubCMD.java:74)
[22:26:54] [Server thread/WARN]: 	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
[22:26:54] [Server thread/WARN]: 	at fr.cocoraid.prodigynightclub.commands.admin.NightclubCMD.onNightclubList(NightclubCMD.java:61)
[22:26:54] [Server thread/WARN]: 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[22:26:54] [Server thread/WARN]: 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
[22:26:54] [Server thread/WARN]: 	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[22:26:54] [Server thread/WARN]: 	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
[22:26:54] [Server thread/WARN]: 	at fr.cocoraid.acf.RegisteredCommand.invoke(RegisteredCommand.java:152)
[22:26:54] [Server thread/WARN]: 	at fr.cocoraid.acf.BaseCommand.executeCommand(BaseCommand.java:577)
[22:26:54] [Server thread/WARN]: 	at fr.cocoraid.acf.BaseCommand.execute(BaseCommand.java:513)
[22:26:54] [Server thread/WARN]: 	at fr.cocoraid.acf.RootCommand.execute(RootCommand.java:99)
[22:26:54] [Server thread/WARN]: 	at fr.cocoraid.acf.BukkitRootCommand.execute(BukkitRootCommand.java:84)
[22:26:54] [Server thread/WARN]: 	at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:149)
[22:26:54] [Server thread/WARN]: 	at org.bukkit.craftbukkit.v1_19_R1.CraftServer.dispatchCommand(CraftServer.java:828)
[22:26:54] [Server thread/WARN]: 	at net.minecraft.server.network.PlayerConnection.handleCommand(PlayerConnection.java:2031)
[22:26:54] [Server thread/WARN]: 	at net.minecraft.server.network.PlayerConnection.a(PlayerConnection.java:1834)
[22:26:54] [Server thread/WARN]: 	at net.minecraft.network.protocol.game.ServerboundChatCommandPacket.a(SourceFile:37)
[22:26:54] [Server thread/WARN]: 	at net.minecraft.network.protocol.game.ServerboundChatCommandPacket.a(SourceFile:13)
[22:26:54] [Server thread/WARN]: 	at net.minecraft.network.protocol.PlayerConnectionUtils.lambda$0(PlayerConnectionUtils.java:31)
[22:26:54] [Server thread/WARN]: 	at net.minecraft.server.TickTask.run(SourceFile:18)
[22:26:54] [Server thread/WARN]: 	at net.minecraft.util.thread.IAsyncTaskHandler.d(SourceFile:157)
[22:26:54] [Server thread/WARN]: 	at net.minecraft.util.thread.IAsyncTaskHandlerReentrant.d(SourceFile:23)
[22:26:54] [Server thread/WARN]: 	at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:1150)
[22:26:54] [Server thread/WARN]: 	at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:1)
[22:26:54] [Server thread/WARN]: 	at net.minecraft.util.thread.IAsyncTaskHandler.x(SourceFile:131)
[22:26:54] [Server thread/WARN]: 	at net.minecraft.server.MinecraftServer.bh(MinecraftServer.java:1129)
[22:26:54] [Server thread/WARN]: 	at net.minecraft.server.MinecraftServer.x(MinecraftServer.java:1122)
[22:26:54] [Server thread/WARN]: 	at net.minecraft.util.thread.IAsyncTaskHandler.c(SourceFile:140)
[22:26:54] [Server thread/WARN]: 	at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:1106)
[22:26:54] [Server thread/WARN]: 	at net.minecraft.server.MinecraftServer.v(MinecraftServer.java:1014)
[22:26:54] [Server thread/WARN]: 	at net.minecraft.server.MinecraftServer.lambda$0(MinecraftServer.java:291)
[22:26:54] [Server thread/WARN]: 	at java.base/java.lang.Thread.run(Thread.java:833)

Code:

JSONMessage.create("CLICK HERE")
                        .color(ChatColor.DARK_PURPLE)
                        .style(ChatColor.BOLD)
                        .runCommand("/test tp " + nc.getName())
                        .then(" to teleport")
                        .color(ChatColor.LIGHT_PURPLE)
                        .send((Player) sender);

Potential solution:

I had the same issue for one of my plugin,

new ChatComponentText(customName) must be changed into Component.literal(customName)

@uhFinn
Copy link

uhFinn commented Aug 9, 2022

Yep I'm having the exact same issue aswell

@corentingosselin
Copy link
Author

corentingosselin commented Aug 10, 2022

Yep I'm having the exact same issue aswell

I made my own class with the same builder system if you need :)

import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;

import java.util.LinkedList;

public class JSONMessage {

    LinkedList<TextComponent> textComponents = new LinkedList<>();

    public JSONMessage(String text) {
        then(text);
    }

    public JSONMessage then(String text) {
        TextComponent message = new TextComponent(text);
        textComponents.add(message);
        return this;
    }

    public JSONMessage color(ChatColor color) {
        textComponents.getLast().setColor(net.md_5.bungee.api.ChatColor.of(color.name()));
        return this;
    }

    public JSONMessage bold() {
        textComponents.getLast().setBold(true);
        return this;
    }

    public JSONMessage runCommand(String command) {
        textComponents.getLast().setClickEvent( new ClickEvent( ClickEvent.Action.RUN_COMMAND, "/" + command));
        return this;
    }

    public void send(Player player) {
        TextComponent[] array = textComponents.toArray(new TextComponent[textComponents.size()]);
        player.spigot().sendMessage(array);
    }
}

Example:

 new JSONMessage("Great !")
                        .color(ChatColor.DARK_PURPLE)
                        .then(" CLICK HERE TO SAVE ")
                        .color(ChatColor.LIGHT_PURPLE)
                        .bold()
                        .runCommand("pnc setup finish")
                        .then(" your nightclub")
                        .color(ChatColor.DARK_PURPLE)
                        .send(admin);

@uhFinn
Copy link

uhFinn commented Aug 10, 2022

Your incredible, thank you! :)

@rayzr522
Copy link
Owner

I've started adding 1.19 support but it's getting progressively more difficult to support newer versions as Mojang makes pretty significant changes to their code. I may put this on hold for now and work on a compatibility module that instead utilizes TextComponent since it has a more stable API and at this point is pretty universally available...

anyway, here's the source as it stands: https://github.com/rayzr522/JSONMessage/tree/1.19-compat

only thing done so far is getting the ChatComponent implementation to not fail on load, haven't even tested if it works yet since everything else is still broken

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants