DiSkyOrg / DiSky

The best Skript add-on for Discord management! Slash commands, interaction, components, modal and much more available!
https://disky.me/
Apache License 2.0
42 stars 12 forks source link

Disky Structure Attempts Function Validation Before Functions Are Registered #173

Closed bessel28 closed 4 months ago

bessel28 commented 4 months ago

The following script:

function testFunc():
    broadcast "test"

command /test:
    trigger:
        testFunc()

discord command ,test:
    trigger:
        testFunc()

Displays this error when reloading (with verbosity on debug):

[Skript] Reloading test.sk...
Commands synced to clients
loading 'test.sk'
Line 10: (test.sk)
    The function 'testFunc' does not exist.
    (from Skript.jar//ch.njol.skript.lang.function.FunctionReference.validateFunction(FunctionReference.java:131))
    Line: testFunc()

loaded 3 structures from 'test.sk'
Registered function signature: testFunc
function testFunc():
    broadcast "test"
command /test:
Validating function testFunc
    testFunc()
discord command ,test (discord command test):
Commands synced to clients
[Skript] Encountered 1 error while reloading test.sk! (5ms)

Where it attempts to validate the function signature in the discord command BEFORE the function signature itself has been registered. If testFunc() is moved to a different script and that script is loaded before reloading the discord command it reloads with no errors.

Server Version: git-Paper-461 (MC: 1.20.4) Skript Version: 2.8.3 (skriptlang-github) Disky Version: DiSky v4.13.0 (built from dev branch)

bessel28 commented 4 months ago

I've fixed this on my fork by using the load function instead of init inside the CommandRegistry.

Seems that calling CommandFactory.getInstance().add() inside the init function calls SkriptUtils.loadCode(trigger, CommandEvent.class) when creating the CommandObject, causing the trigger the be loaded before any ScriptFunctions have been registered

TrasonCo commented 4 months ago

would be good to make a PR with this fix

EquipableMC commented 4 months ago

I agree, it would greatly benefit Sky and everyone else who uses DiSky.