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
This commit is contained in:
sciwhiz12 authored and GitHub committed 2022-11-30 14:07:18 -08:00
1 parent a2434e1607
commit f7eea35cb9
1 file changed
+6 -2
@@ -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;
}
}