Rhino

Rhino

34M Downloads

[Fabric 1.19] net.minecraft.commands.CommandSourceStack has no method hasPermission()

NatSquared opened this issue ยท 5 comments

commented

When trying to require a command source has op permission in Fabric 1.19, command registry completely fails and players cannot join the server if source.hasPermission is called.
Logs attached at the bottom! :)

Builds:
architectury-5.7.28-fabric
kubejs-fabric-1900.5.5-build.19
fabric-api-0.56.3+1.19.jar
rhino-fabric-1802.1.14-build.190.jar

To replicate:

  1. Start a server running the latest (as of 6/26/2022) versions of Fabric API, Architectury, Rhino, and KubeJS for 1.19
  2. Place the following lines somewhere in a script in server_scripts on a multiplayer server
// priority: 0
onEvent('command.registry', event => {
    const { commands: Commands, arguments: Arguments } = event;
    event.register(
        Commands.literal("perms_test")
            .requires(source => source.getServer().isSingleplayer() || source.hasPermission(2))
            .executes((ctx) => {
                ctx.source.sendSuccess("You have permission!", false);
                return 1;
            })

    )
})
  1. Reload or start the server and try to join from your minecraft client
  2. The client will be unable to join, receiving the message "Invalid player data".
  3. In the server console, the following exception is thrown:
    dev.latvian.mods.rhino.EcmaError: TypeError: Cannot find function hasPermission in object net.minecraft.class_2168@4aeae43a. (server_scripts:perms_test.js#6)

Debug logs:
logs/kubejs/startup.txt
logs/latest.log

Workaround:
Replace line 6 with:

.requires(source => source.getServer().isSingleplayer() || source.getPlayerOrException().asKJS().op)

The issue is that you cannot select individual permission levels, but this should be fine for 99% of use cases

commented

Can confirm in a fresh Fabric instance.
Updated logs:
logs/latest.log

commented

Can you confirm this happens in an instance with just KubeJS and its requirements? We've had mods outright removing hasPermission before...

commented

Your script has an error elsewhere:
ctx.source.sendSuccess("You have permission!"); needs to be ctx.source.sendSuccess("You have permission!", true); to broadcast command feedback to admins or ctx.source.sendSuccess("You have permission!", false) to send the message to the player only;

commented

Good catch!
Updated the script, but the same issues arise

commented

Seeing as this is a Rhino issue, I'm going to be moving the discussion there. It seems this issue applies to all methods inherited without an override(?), or at least I've been able to verify it with both abstract and default interface methods at least, and am going to try to verify it with abstract methods in abstract classes as well