From f7eea35cb9b043aae0a3866a9578724aa7560585 Mon Sep 17 00:00:00 2001 From: sciwhiz12 Date: Thu, 1 Dec 2022 06:07:18 +0800 Subject: [PATCH] Check source permission level before selector permission (#9147) In some situations, such as execution of a function by an advancement as part of its reward, a command source stack may have a backing source of a ServerPlayer which may lack the entity selector permission and have an explicit permission level that should allow the use of entity selectors, through CommandSourceStack#withPermission. We now check if the permission level of the command source stack is sufficient for entity selectors _before_ checking if the source is a player and if they have the requisite permission. This means that an operator permission level of 2 will always override the Forge entity selector permission. Fixes #9137 --- src/main/java/net/minecraftforge/common/ForgeHooks.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/minecraftforge/common/ForgeHooks.java b/src/main/java/net/minecraftforge/common/ForgeHooks.java index c301c72a49..bafd67a49d 100644 --- a/src/main/java/net/minecraftforge/common/ForgeHooks.java +++ b/src/main/java/net/minecraftforge/common/ForgeHooks.java @@ -1650,10 +1650,14 @@ public class ForgeHooks public static boolean canUseEntitySelectors(SharedSuggestionProvider provider) { - if (provider instanceof CommandSourceStack source && source.source instanceof ServerPlayer player) + if (provider.hasPermission(Commands.LEVEL_GAMEMASTERS)) + { + return true; + } + else if (provider instanceof CommandSourceStack source && source.source instanceof ServerPlayer player) { return PermissionAPI.getPermission(player, ForgeMod.USE_SELECTORS_PERMISSION); } - return provider.hasPermission(Commands.LEVEL_GAMEMASTERS); + return false; } }