mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-09-03 09:50:24 +02:00
Fix meta command showing when a user doesn't have permission to use it
This commit is contained in:
parent
d433a5461d
commit
e079b0f3ed
|
@ -123,7 +123,7 @@ public abstract class SubCommand<T> {
|
|||
* @return true if the sender can use the command
|
||||
*/
|
||||
public boolean isAuthorized(Sender sender) {
|
||||
return permission == null || permission.isAuthorized(sender);
|
||||
return permission.isAuthorized(sender);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ public class GroupMainCommand extends MainCommand<Group> {
|
|||
.add(new GroupSetTempInherit())
|
||||
.add(new GroupUnsetTempInherit())
|
||||
.add(new GroupShowTracks())
|
||||
.add(new MetaCommands<>())
|
||||
.add(new MetaCommands<>(false))
|
||||
.add(new GroupBulkChange())
|
||||
.add(new GroupClear())
|
||||
.add(new GroupRename())
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
package me.lucko.luckperms.commands.meta;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.*;
|
||||
import me.lucko.luckperms.commands.meta.subcommands.*;
|
||||
|
@ -36,6 +37,8 @@ import java.util.Optional;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
public class MetaCommands<T extends PermissionHolder> extends SubCommand<T> {
|
||||
private boolean user;
|
||||
|
||||
private final List<MetaSubCommand> subCommands = ImmutableList.<MetaSubCommand>builder()
|
||||
.add(new MetaInfo())
|
||||
.add(new MetaAddPrefix())
|
||||
|
@ -49,14 +52,13 @@ public class MetaCommands<T extends PermissionHolder> extends SubCommand<T> {
|
|||
.add(new MetaClear())
|
||||
.build();
|
||||
|
||||
public MetaCommands() {
|
||||
public MetaCommands(boolean user) {
|
||||
super("meta", "Edit metadata values", null, Predicate.alwaysFalse(), null);
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, T t, List<String> args, String label) {
|
||||
boolean user = t instanceof User;
|
||||
|
||||
if (args.size() == 0) {
|
||||
sendUsageMeta(sender, user, label);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
|
@ -91,6 +93,16 @@ public class MetaCommands<T extends PermissionHolder> extends SubCommand<T> {
|
|||
return sub.execute(plugin, sender, t, strippedArgs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAuthorized(Sender sender) {
|
||||
for (MetaSubCommand subCommand : subCommands) {
|
||||
if (subCommand.isAuthorized(sender, user)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void sendUsageMeta(Sender sender, boolean user, String label) {
|
||||
List<MetaSubCommand> subs = subCommands.stream()
|
||||
.filter(s -> s.isAuthorized(sender, user))
|
||||
|
|
|
@ -59,7 +59,7 @@ public class UserMainCommand extends MainCommand<User> {
|
|||
.add(new UserPromote())
|
||||
.add(new UserDemote())
|
||||
.add(new UserShowPos())
|
||||
.add(new MetaCommands<>())
|
||||
.add(new MetaCommands<>(true))
|
||||
.add(new UserBulkChange())
|
||||
.add(new UserClear())
|
||||
.build()
|
||||
|
|
Loading…
Reference in New Issue
Block a user