JorelAli / CommandAPI

A Bukkit/Spigot API for the command UI introduced in Minecraft 1.13

Home Page:https://commandapi.jorel.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CustomArgumentException fromString doesn't support rgb

Zoltus opened this issue · comments

CommandAPI version

9.0.3

Minecraft version

1.20.1

Are you shading the CommandAPI?

Yes

What I did

public class GamemodeArgument extends CustomArgument<GameMode, String> implements IArgument {

    public GamemodeArgument() {
        super(new StringArgument(Lang.NODES_GAMEMODE.getString()), info -> {
            GameMode gm = getGamemode(info.input());
            if (gm == null) {
                throw CustomArgumentException.fromString("§x§F§F§5§1§5§1R§x§F§F§5§E§5§Eo§x§F§F§6§C§6§Cm§x§F§F§7§9§7§9u§x§F§F§8§7§8§7n§x§F§F§9§4§9§4a");
            } else {
                return gm;
            }
        });
    }
}

What actually happened

It does handle the colors the wrong way.

What should have happened

it should output rgb colors

Server logs and CommandAPI config

no logs/errors.

Other

No response

I could not reproduce this error, using CommandAPI 9.2.0 with Minecraft 1.20.1 using this code:

Argument<String> gamemodeArgument = new CustomArgument<>(new StringArgument("gamemode"), info -> {
            String gm = getGamemode(info.input());
            if (gm == null) {
                throw CustomArgument.CustomArgumentException.fromString("§x§F§F§5§1§5§1R§x§F§F§5§E§5§Eo§x§F§F§6§C§6§Cm§x§F§F§7§9§7§9u§x§F§F§8§7§8§7n§x§F§F§9§4§9§4a");
            } else {
                return gm;
            }
        });
        new CommandAPICommand("test")
            .withArguments(gamemodeArgument)
            .executes(info -> {
                info.sender().sendMessage(Component.text().content("This works!").build());
            })
            .register();

private String getGamemode(String input) {
        return (input.equals("s")) ? "survival" : null;
    }

Executing this command in-game and not giving the option s, makes the command output this error:
image

I'd close this for now. If this issue somehow still happens for you, please reply to this!

I could not reproduce this error, using CommandAPI 9.2.0 with Minecraft 1.20.1 using this code:

Argument<String> gamemodeArgument = new CustomArgument<>(new StringArgument("gamemode"), info -> {
            String gm = getGamemode(info.input());
            if (gm == null) {
                throw CustomArgument.CustomArgumentException.fromString("§x§F§F§5§1§5§1R§x§F§F§5§E§5§Eo§x§F§F§6§C§6§Cm§x§F§F§7§9§7§9u§x§F§F§8§7§8§7n§x§F§F§9§4§9§4a");
            } else {
                return gm;
            }
        });
        new CommandAPICommand("test")
            .withArguments(gamemodeArgument)
            .executes(info -> {
                info.sender().sendMessage(Component.text().content("This works!").build());
            })
            .register();

private String getGamemode(String input) {
        return (input.equals("s")) ? "survival" : null;
    }

Executing this command in-game and not giving the option s, makes the command output this error: image

I'd close this for now. If this issue somehow still happens for you, please reply to this!

The output you get means you are reproducing the issue, if you check he romuna text colors it's different than in fromString.
It should look like this:

javaw_2023-10-06_23-59-43

So I generally fixed this problem on Paper at least.
On Spigot, and I don't know if it's a me-problem, I get an exception.

For now, my progress is on dev/rgb-errors if anyone (or you) wants to try to fix this.
No matter what I do, I get this exception:

[13:12:14] [Server thread/INFO]: [BugTestingCommandAPI] Loading BugTestingCommandAPI v0.0.1
[13:12:14] [Server thread/INFO]: Loaded platform NMS_1_20_R1 > NMS_Common > CommandAPIBukkit
[13:12:14] [Server thread/WARN]: Could not hook into the NBT API for NBT support. Download it from https://www.spigotmc.org/resources/nbt-api.7939/
[13:12:14] [Server thread/INFO]: Hooked into Spigot successfully for Chat/ChatComponents
[13:12:14] [Server thread/WARN]: Could not hook into Adventure for AdventureChat/AdventureChatComponents
[13:12:14] [Server thread/WARN]: Could not hook into Paper for /minecraft:reload. Consider upgrading to Paper: https://papermc.io/
[13:12:14] [Server thread/ERROR]: net/kyori/adventure/text/Component initializing BugTestingCommandAPI v0.0.1 (Is it up to date?)
java.lang.NoClassDefFoundError: net/kyori/adventure/text/Component
        at io.github.derechtepilz.commandapi.CommandAPIBukkit.checkDependencies(CommandAPIBukkit.java:195) ~[?:?]
        at io.github.derechtepilz.commandapi.CommandAPIBukkit.onLoad(CommandAPIBukkit.java:134) ~[?:?]
        at io.github.derechtepilz.commandapi.CommandAPIHandler.onLoad(CommandAPIHandler.java:139) ~[?:?]
        at io.github.derechtepilz.commandapi.CommandAPI.onLoad(CommandAPI.java:122) ~[?:?]
        at io.github.derechtepilz.bugtestingcommandapi.Main.onLoad(Main.java:22) ~[?:?]
        at org.bukkit.craftbukkit.v1_20_R1.CraftServer.loadPlugins(CraftServer.java:440) ~[spigot-1.20.1-R0.1-SNAPSHOT.jar:3871-Spigot-d2eba2c-3f9263b]
        at net.minecraft.server.dedicated.DedicatedServer.e(DedicatedServer.java:219) ~[spigot-1.20.1-R0.1-SNAPSHOT.jar:3871-Spigot-d2eba2c-3f9263b]
        at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:972) ~[spigot-1.20.1-R0.1-SNAPSHOT.jar:3871-Spigot-d2eba2c-3f9263b]
        at net.minecraft.server.MinecraftServer.lambda$0(MinecraftServer.java:303) ~[spigot-1.20.1-R0.1-SNAPSHOT.jar:3871-Spigot-d2eba2c-3f9263b]
        at java.lang.Thread.run(Thread.java:833) ~[?:?]
Caused by: java.lang.ClassNotFoundException: net.kyori.adventure.text.Component
        at org.bukkit.plugin.java.PluginClassLoader.loadClass0(PluginClassLoader.java:147) ~[spigot-api-1.20.1-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.plugin.java.PluginClassLoader.loadClass(PluginClassLoader.java:99) ~[spigot-api-1.20.1-R0.1-SNAPSHOT.jar:?]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[?:?]
        ... 10 more

From the looks of it, the exception is thrown when the PaperImplementations.java constructor is called.
According to this discord message a NoClassDefFoundError only is thrown when a class that does not exist is used. Imports apparently don't matter.

So, at least for me, this issue is staying active a bit longer as I can't seem to find a solution that doesn't throw an exception (well, I could, but it uses reflection and is not a feasable solution for this problem).
Again, if anyone can figure out what's going on with this, please provide a bit more information, commit to this branch or open a pull request - I have no idea what's going on.

Implemented in CommandAPI 9.3.0.