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
|
* @return true if the sender can use the command
|
||||||
*/
|
*/
|
||||||
public boolean isAuthorized(Sender sender) {
|
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 GroupSetTempInherit())
|
||||||
.add(new GroupUnsetTempInherit())
|
.add(new GroupUnsetTempInherit())
|
||||||
.add(new GroupShowTracks())
|
.add(new GroupShowTracks())
|
||||||
.add(new MetaCommands<>())
|
.add(new MetaCommands<>(false))
|
||||||
.add(new GroupBulkChange())
|
.add(new GroupBulkChange())
|
||||||
.add(new GroupClear())
|
.add(new GroupClear())
|
||||||
.add(new GroupRename())
|
.add(new GroupRename())
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
package me.lucko.luckperms.commands.meta;
|
package me.lucko.luckperms.commands.meta;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
import me.lucko.luckperms.LuckPermsPlugin;
|
import me.lucko.luckperms.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.commands.*;
|
import me.lucko.luckperms.commands.*;
|
||||||
import me.lucko.luckperms.commands.meta.subcommands.*;
|
import me.lucko.luckperms.commands.meta.subcommands.*;
|
||||||
@ -36,6 +37,8 @@ import java.util.Optional;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class MetaCommands<T extends PermissionHolder> extends SubCommand<T> {
|
public class MetaCommands<T extends PermissionHolder> extends SubCommand<T> {
|
||||||
|
private boolean user;
|
||||||
|
|
||||||
private final List<MetaSubCommand> subCommands = ImmutableList.<MetaSubCommand>builder()
|
private final List<MetaSubCommand> subCommands = ImmutableList.<MetaSubCommand>builder()
|
||||||
.add(new MetaInfo())
|
.add(new MetaInfo())
|
||||||
.add(new MetaAddPrefix())
|
.add(new MetaAddPrefix())
|
||||||
@ -49,14 +52,13 @@ public class MetaCommands<T extends PermissionHolder> extends SubCommand<T> {
|
|||||||
.add(new MetaClear())
|
.add(new MetaClear())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
public MetaCommands() {
|
public MetaCommands(boolean user) {
|
||||||
super("meta", "Edit metadata values", null, Predicate.alwaysFalse(), null);
|
super("meta", "Edit metadata values", null, Predicate.alwaysFalse(), null);
|
||||||
|
this.user = user;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, T t, List<String> args, String label) {
|
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, T t, List<String> args, String label) {
|
||||||
boolean user = t instanceof User;
|
|
||||||
|
|
||||||
if (args.size() == 0) {
|
if (args.size() == 0) {
|
||||||
sendUsageMeta(sender, user, label);
|
sendUsageMeta(sender, user, label);
|
||||||
return CommandResult.INVALID_ARGS;
|
return CommandResult.INVALID_ARGS;
|
||||||
@ -91,6 +93,16 @@ public class MetaCommands<T extends PermissionHolder> extends SubCommand<T> {
|
|||||||
return sub.execute(plugin, sender, t, strippedArgs);
|
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) {
|
private void sendUsageMeta(Sender sender, boolean user, String label) {
|
||||||
List<MetaSubCommand> subs = subCommands.stream()
|
List<MetaSubCommand> subs = subCommands.stream()
|
||||||
.filter(s -> s.isAuthorized(sender, user))
|
.filter(s -> s.isAuthorized(sender, user))
|
||||||
|
@ -59,7 +59,7 @@ public class UserMainCommand extends MainCommand<User> {
|
|||||||
.add(new UserPromote())
|
.add(new UserPromote())
|
||||||
.add(new UserDemote())
|
.add(new UserDemote())
|
||||||
.add(new UserShowPos())
|
.add(new UserShowPos())
|
||||||
.add(new MetaCommands<>())
|
.add(new MetaCommands<>(true))
|
||||||
.add(new UserBulkChange())
|
.add(new UserBulkChange())
|
||||||
.add(new UserClear())
|
.add(new UserClear())
|
||||||
.build()
|
.build()
|
||||||
|
Loading…
Reference in New Issue
Block a user