FlashyReese / CommandAliases

Alternate short commands for complex commands
MIT License
26 stars 6 forks source link

Cannot execute custom command in datapack function #38

Open Happyfrozenfire opened 1 year ago

Happyfrozenfire commented 1 year ago

I have three custom commands (each without arguments) that load in without issue:

[00:09:08] [Server thread/INFO]: 
commandaliases
├── removebonus.json - Successfully loaded
├── changeorigin.json - Successfully loaded
└── addbonus.json - Successfully loaded
[00:09:08] [Server thread/INFO]: Registered/Reloaded all your commands :P, you can now single command nuke!

I call one of these in a datapack mcfunction:

tag @s add tracked
addbonus

Upon loading up my server or reloading the datapacks, I get errors along the lines of this:

[00:09:08] [Server thread/ERROR]: Failed to load function scmcraft-commands:on_fortyeight_hours
java.util.concurrent.CompletionException: java.lang.IllegalArgumentException: Whilst parsing command on line 2: Unknown or incomplete command, see below for error at position 0: <--[HERE]
        at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:315) ~[?:?]
        at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:320) ~[?:?]
        at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1770) ~[?:?]
        at java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1760) ~[?:?]
        at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373) ~[?:?]
        at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182) ~[?:?]
        at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655) ~[?:?]
        at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622) ~[?:?]
        at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165) ~[?:?]
Caused by: java.lang.IllegalArgumentException: Whilst parsing command on line 2: Unknown or incomplete command, see below for error at position 0: <--[HERE]
        at net.minecraft.class_2158.method_9195(class_2158.java:63) ~[server-intermediary.jar:?]
        at net.minecraft.class_5349.method_29451(class_5349.java:85) ~[server-intermediary.jar:?]
        at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768) ~[?:?]
        ... 6 more

Running the addbonus command in-game works perfectly fine, so my hypothesis is that, when the server loads in the commands, it doesn't load them in where mcfunctions can see them. Is there any way to fix that?

FlashyReese commented 1 year ago

What version are you running? Is it possible that you can provide those command aliases files as well?

Happyfrozenfire commented 1 year ago

Version: MC 1.19.2, Fabric 0.4.10, CommandAliases 0.9.4 addbonus:

{
    "commandMode": "COMMAND_CUSTOM",
    "customCommand": 
    {
        "parent": "addbonus",
        "permission": 4,
        "actions":
        [
        {
            "command": "lp user $executor_name() parent add bonus",
            "commandType": "SERVER"
        }
        ]
    }
}

removebonus replaces the add argument with remove, and changeorigin doesn't need to run in an mcfunction. The point of this is as a workaround due to luckperms not allowing the use of selectors in commands. Running execute as @a run addbonus in a command block works fine. I just can't reference addbonus in the mcfunction.

FlashyReese commented 1 year ago

Quick question does reloading the datapack using /reload still not let you reference addbonus?

To be honest, I have no idea why it won't let you reference it as a command. I assume you can reference lp user @a parent add bonus directly.

Happyfrozenfire commented 1 year ago

Nah, it still doesn't let me reference addbonus. I can reference lp user @s parent add bonus directly, but at the time, my config was a default where lp wouldn't let me use selectors. Turns out, you can allow lp selectors in config, so I don't this solution anymore, but it's still weird

FlashyReese commented 1 year ago

The main issue is that Command Aliases are registered after default mod commands and datapacks, making it impossible for the datapack to locate them. Additionally, moving the Command Aliases registration to the default one would cause a failure to locate commands from mods loaded after Command Aliases.