Mojira Archive
MC-197911

Executing function does not use command source stack OP-level

The bug

When a function is executed it uses the OP-level which was used to compile the functions (i.e. function-permission-level dedicated server property) instead of the OP-level the executor of the function (e.g. the player) has.

This can be problematic when the function-permission-level value is higher than the default value of 2.
In this case a player with OP-level 2 could end up executing a function which requires OP-level 4.

Side note: It appears this also renders the following OP-level restrictions useless (1.16.2, Mojang names):

  • net.minecraft.server.ServerFunctionManager.getGameLoopSender()
  • net.minecraft.server.commands.FunctionCommand.runFunction(CommandSourceStack, Collection<CommandFunction>)
  • net.minecraft.advancements.AdvancementRewards.grant(ServerPlayer)

Reproduction steps

  1. Start a dedicated server
  2. /op yourself
  3. Stop the server, and edit the ops.json file and change your level value to 2
  4. Set the function-permission-level value to 4 in the server.properties
  5. Place the attached datapack MC-197911.zip in the world/datapacks folder of the server
  6. Start the server
  7. Try to run the following command
    /stop
    

    It does not work because it requires OP-level 4 but you only have OP-level 2

  8. Try to run the following command
    /function mc-197911:stop-server
    

    The function executed /stop even though you (the executor) only has OP-level 2

Fix considerations

Ideally the game should use the executor permission level. However:

  • for functions run every tick (minecraft:tick) or on load (minecraft:load) function-permission-level should be used
  • for functions scheduled using /schedule function it should use the OP-level the executor of that command had for the scheduled function as well
  • for advancements function rewards function-permission-level could be used; though on the other hand tying something requiring OP-level > 2 to advancements is rather unlikely so using 2 (or the maximum of 2 and function-permission-level?) might be fine as well

Works As Intended

Marcono1234

2020-08-13, 06:38 PM

2020-10-09, 10:11 AM

2020-10-09, 10:11 AM

0

2

Confirmed

(Unassigned)

1.16.2

-