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

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

Open
NatSquared opened this issue Jun 26, 2022 · 5 comments
Labels
1.18 This issue applies to Minecraft 1.18. 1.19 This issue applies to Minecraft 1.19. bug Something isn't working

Comments

@NatSquared
Copy link

NatSquared commented Jun 26, 2022

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

@MaxNeedsSnacks
Copy link
Member

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

@NatSquared
Copy link
Author

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

@MaxNeedsSnacks
Copy link
Member

MaxNeedsSnacks commented Jun 27, 2022

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;

@NatSquared
Copy link
Author

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

@MaxNeedsSnacks
Copy link
Member

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

@MaxNeedsSnacks MaxNeedsSnacks transferred this issue from KubeJS-Mods/KubeJS Jul 18, 2022
@MaxNeedsSnacks MaxNeedsSnacks added bug Something isn't working 1.19 This issue applies to Minecraft 1.19. 1.18 This issue applies to Minecraft 1.18. labels Jul 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.18 This issue applies to Minecraft 1.18. 1.19 This issue applies to Minecraft 1.19. bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants