mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-24 03:25:19 +01:00
Refactor command argument parsing
This commit is contained in:
parent
bfaa543ecd
commit
2ac7d3dfe6
@ -34,6 +34,7 @@ import de.bananaco.bpermissions.api.WorldManager;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.commands.migration.MigrationUtils;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
@ -61,7 +62,6 @@ import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
@ -83,7 +83,7 @@ public class MigrationBPermissions extends ChildCommand<Object> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object ignored, ArgumentList args, String label) {
|
||||
ProgressLogger log = new ProgressLogger(Message.MIGRATION_LOG, Message.MIGRATION_LOG_PROGRESS, "bPermissions");
|
||||
log.addListener(plugin.getConsoleSender());
|
||||
log.addListener(sender);
|
||||
|
@ -28,6 +28,7 @@ package me.lucko.luckperms.bukkit.migration;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.commands.migration.MigrationUtils;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
@ -74,7 +75,7 @@ public class MigrationGroupManager extends ChildCommand<Object> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object ignored, ArgumentList args, String label) {
|
||||
ProgressLogger log = new ProgressLogger(Message.MIGRATION_LOG, Message.MIGRATION_LOG_PROGRESS, "GroupManager");
|
||||
log.addListener(plugin.getConsoleSender());
|
||||
log.addListener(sender);
|
||||
|
@ -30,6 +30,7 @@ import com.platymuus.bukkit.permissions.PermissionsPlugin;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.commands.migration.MigrationUtils;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
@ -62,7 +63,7 @@ public class MigrationPermissionsBukkit extends ChildCommand<Object> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object ignored, ArgumentList args, String label) {
|
||||
ProgressLogger log = new ProgressLogger(Message.MIGRATION_LOG, Message.MIGRATION_LOG_PROGRESS, "PermissionsBukkit");
|
||||
log.addListener(plugin.getConsoleSender());
|
||||
log.addListener(sender);
|
||||
|
@ -30,6 +30,7 @@ import com.google.common.base.Strings;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.commands.migration.MigrationUtils;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
@ -107,7 +108,7 @@ public class MigrationPermissionsEx extends ChildCommand<Object> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object ignored, ArgumentList args, String label) {
|
||||
ProgressLogger log = new ProgressLogger(Message.MIGRATION_LOG, Message.MIGRATION_LOG_PROGRESS, "PermissionsEx");
|
||||
log.addListener(plugin.getConsoleSender());
|
||||
log.addListener(sender);
|
||||
|
@ -36,6 +36,7 @@ import com.zaxxer.hikari.HikariDataSource;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.commands.migration.MigrationUtils;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -84,7 +85,7 @@ public class MigrationPowerfulPerms extends ChildCommand<Object> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object ignored, ArgumentList args, String label) {
|
||||
ProgressLogger log = new ProgressLogger(Message.MIGRATION_LOG, Message.MIGRATION_LOG_PROGRESS, "PowerfulPerms");
|
||||
log.addListener(plugin.getConsoleSender());
|
||||
log.addListener(sender);
|
||||
|
@ -28,6 +28,7 @@ package me.lucko.luckperms.bukkit.migration;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.commands.migration.MigrationUtils;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
@ -63,7 +64,6 @@ import org.tyrannyofheaven.bukkit.zPermissions.model.PermissionEntity;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
@ -75,7 +75,7 @@ public class MigrationZPermissions extends ChildCommand<Object> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object ignored, ArgumentList args, String label) {
|
||||
ProgressLogger log = new ProgressLogger(Message.MIGRATION_LOG, Message.MIGRATION_LOG_PROGRESS, "zPermissions");
|
||||
log.addListener(plugin.getConsoleSender());
|
||||
log.addListener(sender);
|
||||
|
@ -28,6 +28,7 @@ package me.lucko.luckperms.bungee.migration;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.commands.migration.MigrationUtils;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
@ -61,7 +62,7 @@ public class MigrationBungeePerms extends ChildCommand<Object> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object ignored, ArgumentList args, String label) {
|
||||
ProgressLogger log = new ProgressLogger(Message.MIGRATION_LOG, Message.MIGRATION_LOG_PROGRESS, "BungeePerms");
|
||||
log.addListener(plugin.getConsoleSender());
|
||||
log.addListener(sender);
|
||||
|
@ -33,6 +33,7 @@ import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.CompletionSupplier;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.commands.group.CreateGroup;
|
||||
import me.lucko.luckperms.common.commands.group.DeleteGroup;
|
||||
import me.lucko.luckperms.common.commands.group.GroupParentCommand;
|
||||
@ -200,7 +201,7 @@ public class CommandManager {
|
||||
// Try to execute the command.
|
||||
CommandResult result;
|
||||
try {
|
||||
result = main.execute(this.plugin, sender, null, arguments, label);
|
||||
result = main.execute(this.plugin, sender, null, new ArgumentList(arguments), label);
|
||||
} catch (CommandException e) {
|
||||
result = e.handle(sender, label, main);
|
||||
} catch (Throwable e) {
|
||||
@ -224,7 +225,7 @@ public class CommandManager {
|
||||
.from(1, partial -> mains.stream()
|
||||
.filter(m -> m.getName().equalsIgnoreCase(arguments.get(0)))
|
||||
.findFirst()
|
||||
.map(cmd -> cmd.tabComplete(this.plugin, sender, arguments.subList(1, arguments.size())))
|
||||
.map(cmd -> cmd.tabComplete(this.plugin, sender, new ArgumentList(arguments.subList(1, arguments.size()))))
|
||||
.orElse(Collections.emptyList())
|
||||
)
|
||||
.complete(arguments);
|
||||
|
@ -27,6 +27,7 @@ package me.lucko.luckperms.common.command.abstraction;
|
||||
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.locale.command.Argument;
|
||||
import me.lucko.luckperms.common.locale.command.LocalizedCommandSpec;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
@ -145,10 +146,10 @@ public abstract class Command<T> {
|
||||
}
|
||||
|
||||
// Main execution method for the command.
|
||||
public abstract CommandResult execute(LuckPermsPlugin plugin, Sender sender, T t, List<String> args, String label) throws CommandException;
|
||||
public abstract CommandResult execute(LuckPermsPlugin plugin, Sender sender, T target, ArgumentList args, String label) throws CommandException;
|
||||
|
||||
// Tab completion method - default implementation is provided as some commands do not provide tab completions.
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,7 @@ package me.lucko.luckperms.common.command.abstraction;
|
||||
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.locale.command.Argument;
|
||||
import me.lucko.luckperms.common.locale.command.LocalizedCommandSpec;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
@ -71,9 +72,9 @@ public abstract class GenericChildCommand {
|
||||
this.argumentCheck = argumentCheck;
|
||||
}
|
||||
|
||||
public abstract CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException;
|
||||
public abstract CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException;
|
||||
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,7 @@ package me.lucko.luckperms.common.command.abstraction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.CompletionSupplier;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.locale.command.LocalizedCommandSpec;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
import me.lucko.luckperms.common.model.HolderType;
|
||||
@ -58,7 +59,7 @@ public class GenericParentCommand<T extends PermissionHolder> extends ChildComma
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, T holder, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, T holder, ArgumentList args, String label) {
|
||||
if (args.isEmpty()) {
|
||||
sendUsageDetailed(sender, label);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
@ -94,7 +95,7 @@ public class GenericParentCommand<T extends PermissionHolder> extends ChildComma
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, CompletionSupplier.startsWith(() -> this.children.stream()
|
||||
.filter(s -> s.isAuthorized(sender, this.type))
|
||||
|
@ -28,6 +28,7 @@ package me.lucko.luckperms.common.command.abstraction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.CompletionSupplier;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.locale.command.LocalizedCommandSpec;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
@ -59,7 +60,7 @@ public abstract class ParentCommand<T, I> extends Command<Void> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Void ignored, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Void ignored, ArgumentList args, String label) {
|
||||
// check if required argument and/or subcommand is missing
|
||||
if (args.size() < this.type.minArgs) {
|
||||
sendUsage(sender, label);
|
||||
@ -118,7 +119,7 @@ public abstract class ParentCommand<T, I> extends Command<Void> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
switch (this.type) {
|
||||
case TAKES_ARGUMENT_FOR_TARGET:
|
||||
return TabCompleter.create()
|
||||
|
@ -27,13 +27,13 @@ package me.lucko.luckperms.common.command.abstraction;
|
||||
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.locale.command.Argument;
|
||||
import me.lucko.luckperms.common.locale.command.LocalizedCommandSpec;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
@ -46,11 +46,11 @@ public abstract class SingleCommand extends Command<Void> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Void v, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Void ignored, ArgumentList args, String label) throws CommandException {
|
||||
return execute(plugin, sender, args, label);
|
||||
}
|
||||
|
||||
public abstract CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) throws CommandException;
|
||||
public abstract CommandResult execute(LuckPermsPlugin plugin, Sender sender, ArgumentList args, String label) throws CommandException;
|
||||
|
||||
@Override
|
||||
public void sendUsage(Sender sender, String label) {
|
||||
|
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.common.command.utils;
|
||||
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.Command;
|
||||
import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
|
||||
public abstract class ArgumentException extends CommandException {
|
||||
|
||||
public static class DetailedUsage extends ArgumentException {
|
||||
@Override
|
||||
protected CommandResult handle(Sender sender) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult handle(Sender sender, String label, Command<?> command) {
|
||||
command.sendDetailedUsage(sender, label);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult handle(Sender sender, GenericChildCommand command) {
|
||||
command.sendDetailedUsage(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
}
|
||||
|
||||
public static class PastDate extends ArgumentException {
|
||||
@Override
|
||||
protected CommandResult handle(Sender sender) {
|
||||
Message.PAST_DATE_ERROR.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
}
|
||||
|
||||
public static class InvalidDate extends ArgumentException {
|
||||
private final String invalidDate;
|
||||
|
||||
public InvalidDate(String invalidDate) {
|
||||
this.invalidDate = invalidDate;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CommandResult handle(Sender sender) {
|
||||
Message.ILLEGAL_DATE_ERROR.send(sender, this.invalidDate);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
}
|
||||
|
||||
public static class InvalidPriority extends ArgumentException {
|
||||
private final String invalidPriority;
|
||||
|
||||
public InvalidPriority(String invalidPriority) {
|
||||
this.invalidPriority = invalidPriority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult handle(Sender sender) {
|
||||
Message.META_INVALID_PRIORITY.send(sender, this.invalidPriority);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,246 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.common.command.utils;
|
||||
|
||||
import com.google.common.collect.ForwardingList;
|
||||
|
||||
import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.commands.user.UserParentCommand;
|
||||
import me.lucko.luckperms.common.context.contextset.ImmutableContextSetImpl;
|
||||
import me.lucko.luckperms.common.context.contextset.MutableContextSetImpl;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.util.DurationParser;
|
||||
|
||||
import net.luckperms.api.context.Context;
|
||||
import net.luckperms.api.context.DefaultContextKeys;
|
||||
import net.luckperms.api.context.ImmutableContextSet;
|
||||
import net.luckperms.api.context.MutableContextSet;
|
||||
import net.luckperms.api.model.data.TemporaryNodeMergeStrategy;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* A list of {@link String} arguments, with extra methods to help
|
||||
* with parsing.
|
||||
*/
|
||||
public class ArgumentList extends ForwardingList<String> {
|
||||
private final List<String> backingList;
|
||||
|
||||
public ArgumentList(List<String> backingList) {
|
||||
this.backingList = backingList;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> delegate() {
|
||||
return this.backingList;
|
||||
}
|
||||
|
||||
public boolean indexOutOfBounds(int index) {
|
||||
return index < 0 || index >= size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get(int index) throws IndexOutOfBoundsException {
|
||||
return super.get(index).replace("{SPACE}", " ");
|
||||
}
|
||||
|
||||
public String getOrDefault(int index, String defaultValue) {
|
||||
if (indexOutOfBounds(index)) {
|
||||
return defaultValue;
|
||||
}
|
||||
return get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull ArgumentList subList(int fromIndex, int toIndex) {
|
||||
return new ArgumentList(super.subList(fromIndex, toIndex));
|
||||
}
|
||||
|
||||
public int getIntOrDefault(int index, int defaultValue) {
|
||||
if (indexOutOfBounds(index)) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
try {
|
||||
return Integer.parseInt(get(index));
|
||||
} catch (NumberFormatException e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public String getLowercase(int index, Predicate<? super String> test) throws ArgumentException.DetailedUsage {
|
||||
String arg = get(index).toLowerCase();
|
||||
if (!test.test(arg)) {
|
||||
throw new ArgumentException.DetailedUsage();
|
||||
}
|
||||
return arg;
|
||||
}
|
||||
|
||||
public boolean getBooleanOrInsert(int index, boolean defaultValue) {
|
||||
if (!indexOutOfBounds(index)) {
|
||||
String arg = get(index);
|
||||
if (arg.equalsIgnoreCase("true") || arg.equalsIgnoreCase("false")) {
|
||||
return Boolean.parseBoolean(arg);
|
||||
}
|
||||
}
|
||||
|
||||
add(index, Boolean.toString(defaultValue));
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public int getPriority(int index) throws ArgumentException {
|
||||
try {
|
||||
return Integer.parseInt(get(index));
|
||||
} catch (NumberFormatException e) {
|
||||
throw new ArgumentException.InvalidPriority(get(index));
|
||||
}
|
||||
}
|
||||
|
||||
public UUID getUserTarget(int index, LuckPermsPlugin plugin, Sender sender) {
|
||||
String arg = get(index);
|
||||
return UserParentCommand.parseTargetUniqueId(arg, plugin, sender);
|
||||
}
|
||||
|
||||
public Duration getDuration(int index) throws ArgumentException {
|
||||
String arg = get(index);
|
||||
return parseDuration(arg).orElseThrow(() -> new ArgumentException.InvalidDate(arg));
|
||||
}
|
||||
|
||||
public Duration getDurationOrDefault(int index, Duration defaultValue) throws ArgumentException {
|
||||
if (indexOutOfBounds(index)) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
return parseDuration(get(index)).orElse(defaultValue);
|
||||
}
|
||||
|
||||
private static Optional<Duration> parseDuration(String input) throws ArgumentException.PastDate {
|
||||
try {
|
||||
long number = Long.parseLong(input);
|
||||
Instant now = Instant.now().truncatedTo(ChronoUnit.SECONDS);
|
||||
Duration duration = checkPastDate(Duration.between(now, Instant.ofEpochSecond(number)));
|
||||
return Optional.of(duration);
|
||||
} catch (NumberFormatException e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
try {
|
||||
Duration duration = checkPastDate(DurationParser.parseDuration(input));
|
||||
return Optional.of(duration);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
private static Duration checkPastDate(Duration duration) throws ArgumentException.PastDate {
|
||||
if (duration.isNegative()) {
|
||||
throw new ArgumentException.PastDate();
|
||||
}
|
||||
return duration;
|
||||
}
|
||||
|
||||
public Optional<TemporaryNodeMergeStrategy> getTemporaryModifierAndRemove(int index) {
|
||||
if (indexOutOfBounds(index)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
TemporaryNodeMergeStrategy strategy = parseTemporaryModifier(get(index));
|
||||
if (strategy == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
remove(index);
|
||||
return Optional.of(strategy);
|
||||
}
|
||||
|
||||
private static TemporaryNodeMergeStrategy parseTemporaryModifier(String s) {
|
||||
switch (s.toLowerCase()) {
|
||||
case "accumulate":
|
||||
return TemporaryNodeMergeStrategy.ADD_NEW_DURATION_TO_EXISTING;
|
||||
case "replace":
|
||||
return TemporaryNodeMergeStrategy.REPLACE_EXISTING_IF_DURATION_LONGER;
|
||||
case "deny":
|
||||
case "none":
|
||||
return TemporaryNodeMergeStrategy.NONE;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public MutableContextSet getContextOrDefault(int fromIndex, LuckPermsPlugin plugin) throws CommandException {
|
||||
if (size() <= fromIndex) {
|
||||
return plugin.getConfiguration().getContextsFile().getDefaultContexts().mutableCopy();
|
||||
}
|
||||
return parseContext(fromIndex);
|
||||
}
|
||||
|
||||
public ImmutableContextSet getContextOrEmpty(int fromIndex) {
|
||||
if (size() <= fromIndex) {
|
||||
return ImmutableContextSetImpl.EMPTY;
|
||||
}
|
||||
return parseContext(fromIndex).immutableCopy();
|
||||
}
|
||||
|
||||
private MutableContextSet parseContext(int fromIndex) {
|
||||
MutableContextSet contextSet = new MutableContextSetImpl();
|
||||
List<String> entries = subList(fromIndex, size());
|
||||
for (int i = 0; i < entries.size(); i++) {
|
||||
String entry = entries.get(i);
|
||||
int sep = entry.indexOf('=');
|
||||
|
||||
String key;
|
||||
String value;
|
||||
|
||||
if (sep != -1) {
|
||||
key = entry.substring(0, sep);
|
||||
value = entry.substring(sep + 1);
|
||||
} else {
|
||||
key = i == 1 ? DefaultContextKeys.WORLD_KEY : DefaultContextKeys.SERVER_KEY;
|
||||
value = entry;
|
||||
}
|
||||
|
||||
if (!Context.isValidKey(key) || !Context.isValidValue(value)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
contextSet.add(key, value);
|
||||
}
|
||||
|
||||
return contextSet;
|
||||
}
|
||||
|
||||
}
|
@ -1,304 +0,0 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.common.command.utils;
|
||||
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.Command;
|
||||
import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
||||
import me.lucko.luckperms.common.commands.user.UserParentCommand;
|
||||
import me.lucko.luckperms.common.context.contextset.ImmutableContextSetImpl;
|
||||
import me.lucko.luckperms.common.context.contextset.MutableContextSetImpl;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.storage.misc.DataConstraints;
|
||||
import me.lucko.luckperms.common.util.DurationParser;
|
||||
|
||||
import net.luckperms.api.context.Context;
|
||||
import net.luckperms.api.context.DefaultContextKeys;
|
||||
import net.luckperms.api.context.ImmutableContextSet;
|
||||
import net.luckperms.api.context.MutableContextSet;
|
||||
import net.luckperms.api.model.data.TemporaryNodeMergeStrategy;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Utility class to help process arguments, and throw checked exceptions if the arguments are invalid.
|
||||
*/
|
||||
public class ArgumentParser {
|
||||
|
||||
public static String parseString(int index, List<String> args) {
|
||||
return args.get(index).replace("{SPACE}", " ");
|
||||
}
|
||||
|
||||
public static String parseStringOrElse(int index, List<String> args, String other) {
|
||||
if (index < 0 || index >= args.size()) {
|
||||
return other;
|
||||
}
|
||||
|
||||
return args.get(index).replace("{SPACE}", " ");
|
||||
}
|
||||
|
||||
public static int parseIntOrElse(int index, List<String> args, int other) {
|
||||
if (index < 0 || index >= args.size()) {
|
||||
return other;
|
||||
}
|
||||
|
||||
try {
|
||||
return Integer.parseInt(args.get(index));
|
||||
} catch (NumberFormatException e) {
|
||||
return other;
|
||||
}
|
||||
}
|
||||
|
||||
public static String parseName(int index, List<String> args) throws ArgumentException {
|
||||
String groupName = args.get(index).toLowerCase();
|
||||
if (!DataConstraints.GROUP_NAME_TEST.test(groupName)) {
|
||||
throw new DetailedUsageException();
|
||||
}
|
||||
return groupName;
|
||||
}
|
||||
|
||||
public static String parseNameWithSpace(int index, List<String> args) throws ArgumentException {
|
||||
String groupName = args.get(index).toLowerCase();
|
||||
if (!DataConstraints.GROUP_NAME_TEST_ALLOW_SPACE.test(groupName)) {
|
||||
throw new DetailedUsageException();
|
||||
}
|
||||
return groupName;
|
||||
}
|
||||
|
||||
public static boolean parseBoolean(int index, List<String> args) {
|
||||
if (index < args.size()) {
|
||||
String bool = args.get(index);
|
||||
if (bool.equalsIgnoreCase("true") || bool.equalsIgnoreCase("false")) {
|
||||
return Boolean.parseBoolean(bool);
|
||||
}
|
||||
}
|
||||
|
||||
args.add(index, "true");
|
||||
return true;
|
||||
}
|
||||
|
||||
public static Duration parseDurationOrElse(int index, List<String> args, Duration other) throws ArgumentException {
|
||||
if (index < 0 || index >= args.size()) {
|
||||
return other;
|
||||
}
|
||||
|
||||
String input = args.get(index);
|
||||
Duration duration;
|
||||
|
||||
try {
|
||||
long number = Long.parseLong(input);
|
||||
Instant now = Instant.now().truncatedTo(ChronoUnit.SECONDS);
|
||||
duration = Duration.between(now, Instant.ofEpochSecond(number));
|
||||
} catch (NumberFormatException e) {
|
||||
try {
|
||||
duration = DurationParser.parseDuration(input);
|
||||
} catch (IllegalArgumentException e1) {
|
||||
return other;
|
||||
}
|
||||
}
|
||||
|
||||
if (duration.isNegative()) {
|
||||
throw new PastDateException();
|
||||
}
|
||||
|
||||
return duration;
|
||||
}
|
||||
|
||||
public static Duration parseDuration(int index, List<String> args) throws ArgumentException {
|
||||
String input = args.get(index);
|
||||
Duration duration;
|
||||
|
||||
try {
|
||||
long number = Long.parseLong(input);
|
||||
Instant now = Instant.now().truncatedTo(ChronoUnit.SECONDS);
|
||||
duration = Duration.between(now, Instant.ofEpochSecond(number));
|
||||
} catch (NumberFormatException e) {
|
||||
try {
|
||||
duration = DurationParser.parseDuration(input);
|
||||
} catch (IllegalArgumentException e1) {
|
||||
throw new InvalidDateException(input);
|
||||
}
|
||||
}
|
||||
|
||||
if (duration.isNegative()) {
|
||||
throw new PastDateException();
|
||||
}
|
||||
|
||||
return duration;
|
||||
}
|
||||
|
||||
public static TemporaryNodeMergeStrategy parseTemporaryModifier(String s) {
|
||||
switch (s.toLowerCase()) {
|
||||
case "accumulate":
|
||||
return TemporaryNodeMergeStrategy.ADD_NEW_DURATION_TO_EXISTING;
|
||||
case "replace":
|
||||
return TemporaryNodeMergeStrategy.REPLACE_EXISTING_IF_DURATION_LONGER;
|
||||
case "deny":
|
||||
case "none":
|
||||
return TemporaryNodeMergeStrategy.NONE;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown value: " + s);
|
||||
}
|
||||
}
|
||||
|
||||
public static Optional<TemporaryNodeMergeStrategy> parseTemporaryModifier(int index, List<String> args) {
|
||||
if (index < 0 || index >= args.size()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
String s = args.get(index);
|
||||
try {
|
||||
Optional<TemporaryNodeMergeStrategy> strategy = Optional.of(parseTemporaryModifier(s));
|
||||
args.remove(index);
|
||||
return strategy;
|
||||
} catch (IllegalArgumentException e) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
public static MutableContextSet parseContext(int fromIndex, List<String> args, LuckPermsPlugin plugin) throws CommandException {
|
||||
if (args.size() <= fromIndex) {
|
||||
return plugin.getConfiguration().getContextsFile().getDefaultContexts().mutableCopy();
|
||||
}
|
||||
return parseContext(fromIndex, args);
|
||||
}
|
||||
|
||||
public static ImmutableContextSet parseContextSponge(int fromIndex, List<String> args) {
|
||||
if (args.size() <= fromIndex) {
|
||||
return ImmutableContextSetImpl.EMPTY;
|
||||
}
|
||||
return parseContext(fromIndex, args).immutableCopy();
|
||||
}
|
||||
|
||||
private static MutableContextSet parseContext(int fromIndex, List<String> args) {
|
||||
MutableContextSet contextSet = new MutableContextSetImpl();
|
||||
List<String> entries = args.subList(fromIndex, args.size());
|
||||
for (int i = 0; i < entries.size(); i++) {
|
||||
String entry = entries.get(i);
|
||||
int sep = entry.indexOf('=');
|
||||
|
||||
String key;
|
||||
String value;
|
||||
|
||||
if (sep != -1) {
|
||||
key = entry.substring(0, sep);
|
||||
value = entry.substring(sep + 1);
|
||||
} else {
|
||||
key = i == 1 ? DefaultContextKeys.WORLD_KEY : DefaultContextKeys.SERVER_KEY;
|
||||
value = entry;
|
||||
}
|
||||
|
||||
if (!Context.isValidKey(key) || !Context.isValidValue(value)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
contextSet.add(key, value);
|
||||
}
|
||||
|
||||
return contextSet;
|
||||
}
|
||||
|
||||
public static int parsePriority(int index, List<String> args) throws ArgumentException {
|
||||
try {
|
||||
return Integer.parseInt(args.get(index));
|
||||
} catch (NumberFormatException e) {
|
||||
throw new InvalidPriorityException(args.get(index));
|
||||
}
|
||||
}
|
||||
|
||||
public static UUID parseUserTarget(int index, List<String> args, LuckPermsPlugin plugin, Sender sender) {
|
||||
final String target = args.get(index);
|
||||
return UserParentCommand.parseTargetUniqueId(target, plugin, sender);
|
||||
}
|
||||
|
||||
public abstract static class ArgumentException extends CommandException {
|
||||
|
||||
}
|
||||
|
||||
public static class DetailedUsageException extends ArgumentException {
|
||||
@Override
|
||||
protected CommandResult handle(Sender sender) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult handle(Sender sender, String label, Command<?> command) {
|
||||
command.sendDetailedUsage(sender, label);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult handle(Sender sender, GenericChildCommand command) {
|
||||
command.sendDetailedUsage(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
}
|
||||
|
||||
public static class PastDateException extends ArgumentException {
|
||||
@Override
|
||||
protected CommandResult handle(Sender sender) {
|
||||
Message.PAST_DATE_ERROR.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
}
|
||||
|
||||
public static class InvalidDateException extends ArgumentException {
|
||||
private final String invalidDate;
|
||||
|
||||
public InvalidDateException(String invalidDate) {
|
||||
this.invalidDate = invalidDate;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CommandResult handle(Sender sender) {
|
||||
Message.ILLEGAL_DATE_ERROR.send(sender, this.invalidDate);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
}
|
||||
|
||||
public static class InvalidPriorityException extends ArgumentException {
|
||||
private final String invalidPriority;
|
||||
|
||||
public InvalidPriorityException(String invalidPriority) {
|
||||
this.invalidPriority = invalidPriority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult handle(Sender sender) {
|
||||
Message.META_INVALID_PRIORITY.send(sender, this.invalidPriority);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -25,11 +25,9 @@
|
||||
|
||||
package me.lucko.luckperms.common.command.utils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SortMode {
|
||||
|
||||
public static SortMode determine(List<String> args) {
|
||||
public static SortMode determine(ArgumentList args) {
|
||||
SortType type = SortType.PRIORITY;
|
||||
boolean ascending = true;
|
||||
for (String arg : args) {
|
||||
|
@ -33,7 +33,7 @@ import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -85,25 +85,25 @@ public class MetaAddChatMeta extends GenericChildCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, holder)) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
int priority = ArgumentParser.parsePriority(0, args);
|
||||
String meta = ArgumentParser.parseString(1, args);
|
||||
MutableContextSet context = ArgumentParser.parseContext(2, args, plugin);
|
||||
int priority = args.getPriority(0);
|
||||
String meta = args.get(1);
|
||||
MutableContextSet context = args.getContextOrDefault(2, plugin);
|
||||
|
||||
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, holder, context)) {
|
||||
ArgumentPermissions.checkGroup(plugin, sender, target, context)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
DataMutateResult result = holder.setNode(DataType.NORMAL, this.type.builder(meta, priority).withContext(context).build(), true);
|
||||
DataMutateResult result = target.setNode(DataType.NORMAL, this.type.builder(meta, priority).withContext(context).build(), true);
|
||||
if (result.wasSuccessful()) {
|
||||
TextComponent.Builder builder = Message.ADD_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), holder.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
|
||||
TextComponent.Builder builder = Message.ADD_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), target.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
|
||||
HoverEvent event = HoverEvent.showText(TextUtils.fromLegacy(
|
||||
"§3Raw " + this.type.name().toLowerCase() + ": §r" + meta,
|
||||
'§'
|
||||
@ -111,20 +111,20 @@ public class MetaAddChatMeta extends GenericChildCommand {
|
||||
builder.applyDeep(c -> c.hoverEvent(event));
|
||||
sender.sendMessage(builder.build());
|
||||
|
||||
LoggedAction.build().source(sender).target(holder)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("meta" , "add" + this.type.name().toLowerCase(), priority, meta, context)
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
StorageAssistant.save(holder, sender, plugin);
|
||||
StorageAssistant.save(target, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} else {
|
||||
Message.ALREADY_HAS_CHAT_META.send(sender, holder.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
Message.ALREADY_HAS_CHAT_META.send(sender, target.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.from(2, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
|
@ -33,7 +33,7 @@ import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
@ -89,30 +89,30 @@ public class MetaAddTempChatMeta extends GenericChildCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, holder)) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
int priority = ArgumentParser.parsePriority(0, args);
|
||||
String meta = ArgumentParser.parseString(1, args);
|
||||
Duration duration = ArgumentParser.parseDuration(2, args);
|
||||
TemporaryNodeMergeStrategy modifier = ArgumentParser.parseTemporaryModifier(3, args).orElseGet(() -> plugin.getConfiguration().get(ConfigKeys.TEMPORARY_ADD_BEHAVIOUR));
|
||||
MutableContextSet context = ArgumentParser.parseContext(3, args, plugin);
|
||||
int priority = args.getPriority(0);
|
||||
String meta = args.get(1);
|
||||
Duration duration = args.getDuration(2);
|
||||
TemporaryNodeMergeStrategy modifier = args.getTemporaryModifierAndRemove(3).orElseGet(() -> plugin.getConfiguration().get(ConfigKeys.TEMPORARY_ADD_BEHAVIOUR));
|
||||
MutableContextSet context = args.getContextOrDefault(3, plugin);
|
||||
|
||||
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, holder, context)) {
|
||||
ArgumentPermissions.checkGroup(plugin, sender, target, context)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
DataMutateResult.WithMergedNode result = holder.setNode(DataType.NORMAL, this.type.builder(meta, priority).expiry(duration).withContext(context).build(), modifier);
|
||||
DataMutateResult.WithMergedNode result = target.setNode(DataType.NORMAL, this.type.builder(meta, priority).expiry(duration).withContext(context).build(), modifier);
|
||||
|
||||
if (result.getResult().wasSuccessful()) {
|
||||
duration = result.getMergedNode().getExpiryDuration();
|
||||
|
||||
TextComponent.Builder builder = Message.ADD_TEMP_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), holder.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, DurationFormatter.LONG.format(duration), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
|
||||
TextComponent.Builder builder = Message.ADD_TEMP_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), target.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, DurationFormatter.LONG.format(duration), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
|
||||
HoverEvent event = HoverEvent.showText(TextUtils.fromLegacy(
|
||||
"§3Raw " + this.type.name().toLowerCase() + ": §r" + meta,
|
||||
'§'
|
||||
@ -120,20 +120,20 @@ public class MetaAddTempChatMeta extends GenericChildCommand {
|
||||
builder.applyDeep(c -> c.hoverEvent(event));
|
||||
sender.sendMessage(builder.build());
|
||||
|
||||
LoggedAction.build().source(sender).target(holder)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("meta" , "addtemp" + this.type.name().toLowerCase(), priority, meta, duration, context)
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
StorageAssistant.save(holder, sender, plugin);
|
||||
StorageAssistant.save(target, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} else {
|
||||
Message.ALREADY_HAS_TEMP_CHAT_META.send(sender, holder.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
Message.ALREADY_HAS_TEMP_CHAT_META.send(sender, target.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.from(3, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
|
@ -33,7 +33,7 @@ import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -56,8 +56,8 @@ public class MetaClear extends GenericChildCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, holder)) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
@ -90,39 +90,39 @@ public class MetaClear extends GenericChildCommand {
|
||||
type = NodeType.META_OR_CHAT_META;
|
||||
}
|
||||
|
||||
int before = holder.normalData().immutable().size();
|
||||
int before = target.normalData().immutable().size();
|
||||
|
||||
MutableContextSet context = ArgumentParser.parseContext(0, args, plugin);
|
||||
MutableContextSet context = args.getContextOrDefault(0, plugin);
|
||||
|
||||
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, holder, context)) {
|
||||
ArgumentPermissions.checkGroup(plugin, sender, target, context)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
if (context.isEmpty()) {
|
||||
holder.removeIf(DataType.NORMAL, null, type::matches, false);
|
||||
target.removeIf(DataType.NORMAL, null, type::matches, false);
|
||||
} else {
|
||||
holder.removeIf(DataType.NORMAL, context, type::matches, false);
|
||||
target.removeIf(DataType.NORMAL, context, type::matches, false);
|
||||
}
|
||||
|
||||
int changed = before - holder.normalData().immutable().size();
|
||||
int changed = before - target.normalData().immutable().size();
|
||||
if (changed == 1) {
|
||||
Message.META_CLEAR_SUCCESS_SINGULAR.send(sender, holder.getFormattedDisplayName(), type.name().toLowerCase(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
|
||||
Message.META_CLEAR_SUCCESS_SINGULAR.send(sender, target.getFormattedDisplayName(), type.name().toLowerCase(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
|
||||
} else {
|
||||
Message.META_CLEAR_SUCCESS.send(sender, holder.getFormattedDisplayName(), type.name().toLowerCase(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
|
||||
Message.META_CLEAR_SUCCESS.send(sender, target.getFormattedDisplayName(), type.name().toLowerCase(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
|
||||
}
|
||||
|
||||
LoggedAction.build().source(sender).target(holder)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("meta", "clear", context)
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
StorageAssistant.save(holder, sender, plugin);
|
||||
StorageAssistant.save(target, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.from(0, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
|
@ -31,6 +31,7 @@ import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
@ -60,7 +61,6 @@ import net.luckperms.api.node.types.SuffixNode;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
@ -73,8 +73,8 @@ public class MetaInfo extends GenericChildCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) {
|
||||
if (ArgumentPermissions.checkViewPerms(plugin, sender, permission, holder)) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) {
|
||||
if (ArgumentPermissions.checkViewPerms(plugin, sender, permission, target)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
@ -84,7 +84,7 @@ public class MetaInfo extends GenericChildCommand {
|
||||
Set<MetaNode> meta = new LinkedHashSet<>();
|
||||
|
||||
// Collect data
|
||||
for (Node node : holder.resolveInheritedNodes(QueryOptionsImpl.DEFAULT_NON_CONTEXTUAL)) {
|
||||
for (Node node : target.resolveInheritedNodes(QueryOptionsImpl.DEFAULT_NON_CONTEXTUAL)) {
|
||||
if (!NodeType.META_OR_CHAT_META.matches(node)) {
|
||||
continue;
|
||||
}
|
||||
@ -101,24 +101,24 @@ public class MetaInfo extends GenericChildCommand {
|
||||
}
|
||||
|
||||
if (prefixes.isEmpty()) {
|
||||
Message.CHAT_META_PREFIX_NONE.send(sender, holder.getFormattedDisplayName());
|
||||
Message.CHAT_META_PREFIX_NONE.send(sender, target.getFormattedDisplayName());
|
||||
} else {
|
||||
Message.CHAT_META_PREFIX_HEADER.send(sender, holder.getFormattedDisplayName());
|
||||
sendChatMetaMessage(prefixes, sender, holder, label);
|
||||
Message.CHAT_META_PREFIX_HEADER.send(sender, target.getFormattedDisplayName());
|
||||
sendChatMetaMessage(prefixes, sender, target, label);
|
||||
}
|
||||
|
||||
if (suffixes.isEmpty()) {
|
||||
Message.CHAT_META_SUFFIX_NONE.send(sender, holder.getFormattedDisplayName());
|
||||
Message.CHAT_META_SUFFIX_NONE.send(sender, target.getFormattedDisplayName());
|
||||
} else {
|
||||
Message.CHAT_META_SUFFIX_HEADER.send(sender, holder.getFormattedDisplayName());
|
||||
sendChatMetaMessage(suffixes, sender, holder, label);
|
||||
Message.CHAT_META_SUFFIX_HEADER.send(sender, target.getFormattedDisplayName());
|
||||
sendChatMetaMessage(suffixes, sender, target, label);
|
||||
}
|
||||
|
||||
if (meta.isEmpty()) {
|
||||
Message.META_NONE.send(sender, holder.getFormattedDisplayName());
|
||||
Message.META_NONE.send(sender, target.getFormattedDisplayName());
|
||||
} else {
|
||||
Message.META_HEADER.send(sender, holder.getFormattedDisplayName());
|
||||
sendMetaMessage(meta, sender, holder, label);
|
||||
Message.META_HEADER.send(sender, target.getFormattedDisplayName());
|
||||
sendMetaMessage(meta, sender, target, label);
|
||||
}
|
||||
|
||||
return CommandResult.SUCCESS;
|
||||
|
@ -33,7 +33,7 @@ import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -85,39 +85,39 @@ public class MetaRemoveChatMeta extends GenericChildCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, holder)) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
int priority = ArgumentParser.parsePriority(0, args);
|
||||
String meta = ArgumentParser.parseStringOrElse(1, args, "null");
|
||||
ImmutableContextSet context = ArgumentParser.parseContext(2, args, plugin).immutableCopy();
|
||||
int priority = args.getPriority(0);
|
||||
String meta = args.getOrDefault(1, "null");
|
||||
ImmutableContextSet context = args.getContextOrDefault(2, plugin).immutableCopy();
|
||||
|
||||
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, holder, context)) {
|
||||
ArgumentPermissions.checkGroup(plugin, sender, target, context)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
// Handle bulk removal
|
||||
if (meta.equalsIgnoreCase("null") || meta.equals("*")) {
|
||||
holder.removeIf(DataType.NORMAL, context, this.type.nodeType().predicate(n -> n.getPriority() == priority && !n.hasExpiry()), false);
|
||||
Message.BULK_REMOVE_CHATMETA_SUCCESS.send(sender, holder.getFormattedDisplayName(), this.type.name().toLowerCase(), priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
target.removeIf(DataType.NORMAL, context, this.type.nodeType().predicate(n -> n.getPriority() == priority && !n.hasExpiry()), false);
|
||||
Message.BULK_REMOVE_CHATMETA_SUCCESS.send(sender, target.getFormattedDisplayName(), this.type.name().toLowerCase(), priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
|
||||
LoggedAction.build().source(sender).target(holder)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("meta" , "remove" + this.type.name().toLowerCase(), priority, "*", context)
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
StorageAssistant.save(holder, sender, plugin);
|
||||
StorageAssistant.save(target, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
DataMutateResult result = holder.unsetNode(DataType.NORMAL, this.type.builder(meta, priority).withContext(context).build());
|
||||
DataMutateResult result = target.unsetNode(DataType.NORMAL, this.type.builder(meta, priority).withContext(context).build());
|
||||
|
||||
if (result.wasSuccessful()) {
|
||||
TextComponent.Builder builder = Message.REMOVE_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), holder.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
|
||||
TextComponent.Builder builder = Message.REMOVE_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), target.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
|
||||
HoverEvent event = HoverEvent.showText(TextUtils.fromLegacy(
|
||||
"§3Raw " + this.type.name().toLowerCase() + ": §r" + meta,
|
||||
'§'
|
||||
@ -125,20 +125,20 @@ public class MetaRemoveChatMeta extends GenericChildCommand {
|
||||
builder.applyDeep(c -> c.hoverEvent(event));
|
||||
sender.sendMessage(builder.build());
|
||||
|
||||
LoggedAction.build().source(sender).target(holder)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("meta" , "remove" + this.type.name().toLowerCase(), priority, meta, context)
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
StorageAssistant.save(holder, sender, plugin);
|
||||
StorageAssistant.save(target, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} else {
|
||||
Message.DOES_NOT_HAVE_CHAT_META.send(sender, holder.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
Message.DOES_NOT_HAVE_CHAT_META.send(sender, target.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.from(2, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
|
@ -33,7 +33,7 @@ import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -85,39 +85,39 @@ public class MetaRemoveTempChatMeta extends GenericChildCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, holder)) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
int priority = ArgumentParser.parsePriority(0, args);
|
||||
String meta = ArgumentParser.parseStringOrElse(1, args, "null");
|
||||
ImmutableContextSet context = ArgumentParser.parseContext(2, args, plugin).immutableCopy();
|
||||
int priority = args.getPriority(0);
|
||||
String meta = args.getOrDefault(1, "null");
|
||||
ImmutableContextSet context = args.getContextOrDefault(2, plugin).immutableCopy();
|
||||
|
||||
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, holder, context)) {
|
||||
ArgumentPermissions.checkGroup(plugin, sender, target, context)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
// Handle bulk removal
|
||||
if (meta.equalsIgnoreCase("null") || meta.equals("*")) {
|
||||
holder.removeIf(DataType.NORMAL, context, this.type.nodeType().predicate(n -> n.getPriority() == priority && n.hasExpiry()), false);
|
||||
Message.BULK_REMOVE_TEMP_CHATMETA_SUCCESS.send(sender, holder.getFormattedDisplayName(), this.type.name().toLowerCase(), priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
target.removeIf(DataType.NORMAL, context, this.type.nodeType().predicate(n -> n.getPriority() == priority && n.hasExpiry()), false);
|
||||
Message.BULK_REMOVE_TEMP_CHATMETA_SUCCESS.send(sender, target.getFormattedDisplayName(), this.type.name().toLowerCase(), priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
|
||||
LoggedAction.build().source(sender).target(holder)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("meta" , "removetemp" + this.type.name().toLowerCase(), priority, "*", context)
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
StorageAssistant.save(holder, sender, plugin);
|
||||
StorageAssistant.save(target, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
DataMutateResult result = holder.unsetNode(DataType.NORMAL, this.type.builder(meta, priority).expiry(10L).withContext(context).build());
|
||||
DataMutateResult result = target.unsetNode(DataType.NORMAL, this.type.builder(meta, priority).expiry(10L).withContext(context).build());
|
||||
|
||||
if (result.wasSuccessful()) {
|
||||
TextComponent.Builder builder = Message.REMOVE_TEMP_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), holder.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
|
||||
TextComponent.Builder builder = Message.REMOVE_TEMP_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), target.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
|
||||
HoverEvent event = HoverEvent.showText(TextUtils.fromLegacy(
|
||||
"§3Raw " + this.type.name().toLowerCase() + ": §r" + meta,
|
||||
'§'
|
||||
@ -125,20 +125,20 @@ public class MetaRemoveTempChatMeta extends GenericChildCommand {
|
||||
builder.applyDeep(c -> c.hoverEvent(event));
|
||||
sender.sendMessage(builder.build());
|
||||
|
||||
LoggedAction.build().source(sender).target(holder)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("meta" , "removetemp" + this.type.name().toLowerCase(), priority, meta, context)
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
StorageAssistant.save(holder, sender, plugin);
|
||||
StorageAssistant.save(target, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} else {
|
||||
Message.DOES_NOT_HAVE_TEMP_CHAT_META.send(sender, holder.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
Message.DOES_NOT_HAVE_TEMP_CHAT_META.send(sender, target.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.from(2, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
|
@ -33,7 +33,7 @@ import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -62,18 +62,18 @@ public class MetaSet extends GenericChildCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, holder)) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
String key = args.get(0);
|
||||
String value = args.get(1);
|
||||
MutableContextSet context = ArgumentParser.parseContext(2, args, plugin);
|
||||
MutableContextSet context = args.getContextOrDefault(2, plugin);
|
||||
|
||||
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, holder, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, target, context) ||
|
||||
ArgumentPermissions.checkArguments(plugin, sender, permission, key)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
@ -81,15 +81,15 @@ public class MetaSet extends GenericChildCommand {
|
||||
|
||||
Node node = Meta.builder(key, value).withContext(context).build();
|
||||
|
||||
if (holder.hasNode(DataType.NORMAL, node, NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE).asBoolean()) {
|
||||
Message.ALREADY_HAS_META.send(sender, holder.getFormattedDisplayName(), key, value, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
if (target.hasNode(DataType.NORMAL, node, NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE).asBoolean()) {
|
||||
Message.ALREADY_HAS_META.send(sender, target.getFormattedDisplayName(), key, value, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
holder.removeIf(DataType.NORMAL, context, NodeType.META.predicate(n -> !n.hasExpiry() && n.getMetaKey().equalsIgnoreCase(key)), false);
|
||||
holder.setNode(DataType.NORMAL, node, true);
|
||||
target.removeIf(DataType.NORMAL, context, NodeType.META.predicate(n -> !n.hasExpiry() && n.getMetaKey().equalsIgnoreCase(key)), false);
|
||||
target.setNode(DataType.NORMAL, node, true);
|
||||
|
||||
TextComponent.Builder builder = Message.SET_META_SUCCESS.asComponent(plugin.getLocaleManager(), key, value, holder.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
|
||||
TextComponent.Builder builder = Message.SET_META_SUCCESS.asComponent(plugin.getLocaleManager(), key, value, target.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
|
||||
HoverEvent event = HoverEvent.showText(TextUtils.fromLegacy(
|
||||
TextUtils.joinNewline("§3Raw key: §r" + key, "§3Raw value: §r" + value),
|
||||
'§'
|
||||
@ -97,16 +97,16 @@ public class MetaSet extends GenericChildCommand {
|
||||
builder.applyDeep(c -> c.hoverEvent(event));
|
||||
sender.sendMessage(builder.build());
|
||||
|
||||
LoggedAction.build().source(sender).target(holder)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("meta", "set", key, value, context)
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
StorageAssistant.save(holder, sender, plugin);
|
||||
StorageAssistant.save(target, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.from(2, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
|
@ -34,7 +34,7 @@ import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -89,20 +89,20 @@ public class MetaSetChatMeta extends GenericChildCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, holder)) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
int priority = ArgumentParser.parseIntOrElse(0, args, Integer.MIN_VALUE);
|
||||
int priority = args.getIntOrDefault(0, Integer.MIN_VALUE);
|
||||
String meta;
|
||||
MutableContextSet context;
|
||||
|
||||
if (priority == Integer.MIN_VALUE) {
|
||||
// priority wasn't defined, meta is at index 0, contexts at index 1
|
||||
meta = ArgumentParser.parseString(0, args);
|
||||
context = ArgumentParser.parseContext(1, args, plugin);
|
||||
meta = args.get(0);
|
||||
context = args.getContextOrDefault(1, plugin);
|
||||
} else {
|
||||
// priority was defined, meta should be at index 1, contexts at index 2
|
||||
if (args.size() <= 1) {
|
||||
@ -110,35 +110,35 @@ public class MetaSetChatMeta extends GenericChildCommand {
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
meta = ArgumentParser.parseString(1, args);
|
||||
context = ArgumentParser.parseContext(2, args, plugin);
|
||||
meta = args.get(1);
|
||||
context = args.getContextOrDefault(2, plugin);
|
||||
}
|
||||
|
||||
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, holder, context)) {
|
||||
ArgumentPermissions.checkGroup(plugin, sender, target, context)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
// remove all other prefixes/suffixes set in these contexts
|
||||
holder.removeIf(DataType.NORMAL, context, this.type.nodeType()::matches, false);
|
||||
target.removeIf(DataType.NORMAL, context, this.type.nodeType()::matches, false);
|
||||
|
||||
// determine the priority to set at
|
||||
if (priority == Integer.MIN_VALUE) {
|
||||
MetaAccumulator metaAccumulator = holder.accumulateMeta(QueryOptionsImpl.DEFAULT_CONTEXTUAL.toBuilder().context(context).build());
|
||||
MetaAccumulator metaAccumulator = target.accumulateMeta(QueryOptionsImpl.DEFAULT_CONTEXTUAL.toBuilder().context(context).build());
|
||||
priority = metaAccumulator.getChatMeta(this.type).keySet().stream().mapToInt(e -> e).max().orElse(0) + 1;
|
||||
|
||||
if (holder instanceof Group) {
|
||||
OptionalInt weight = holder.getWeight();
|
||||
if (target instanceof Group) {
|
||||
OptionalInt weight = target.getWeight();
|
||||
if (weight.isPresent() && weight.getAsInt() > priority) {
|
||||
priority = weight.getAsInt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DataMutateResult result = holder.setNode(DataType.NORMAL, this.type.builder(meta, priority).withContext(context).build(), true);
|
||||
DataMutateResult result = target.setNode(DataType.NORMAL, this.type.builder(meta, priority).withContext(context).build(), true);
|
||||
if (result.wasSuccessful()) {
|
||||
TextComponent.Builder builder = Message.ADD_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), holder.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
|
||||
TextComponent.Builder builder = Message.ADD_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), target.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
|
||||
HoverEvent event = HoverEvent.showText(TextUtils.fromLegacy(
|
||||
"§3Raw " + this.type.name().toLowerCase() + ": §r" + meta,
|
||||
'§'
|
||||
@ -146,20 +146,20 @@ public class MetaSetChatMeta extends GenericChildCommand {
|
||||
builder.applyDeep(c -> c.hoverEvent(event));
|
||||
sender.sendMessage(builder.build());
|
||||
|
||||
LoggedAction.build().source(sender).target(holder)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("meta" , "set" + this.type.name().toLowerCase(), priority, meta, context)
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
StorageAssistant.save(holder, sender, plugin);
|
||||
StorageAssistant.save(target, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} else {
|
||||
Message.ALREADY_HAS_CHAT_META.send(sender, holder.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
Message.ALREADY_HAS_CHAT_META.send(sender, target.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.from(1, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
|
@ -33,7 +33,7 @@ import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
@ -66,20 +66,20 @@ public class MetaSetTemp extends GenericChildCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, holder)) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
String key = args.get(0);
|
||||
String value = args.get(1);
|
||||
Duration duration = ArgumentParser.parseDuration(2, args);
|
||||
TemporaryNodeMergeStrategy modifier = ArgumentParser.parseTemporaryModifier(3, args).orElseGet(() -> plugin.getConfiguration().get(ConfigKeys.TEMPORARY_ADD_BEHAVIOUR));
|
||||
MutableContextSet context = ArgumentParser.parseContext(3, args, plugin);
|
||||
Duration duration = args.getDuration(2);
|
||||
TemporaryNodeMergeStrategy modifier = args.getTemporaryModifierAndRemove(3).orElseGet(() -> plugin.getConfiguration().get(ConfigKeys.TEMPORARY_ADD_BEHAVIOUR));
|
||||
MutableContextSet context = args.getContextOrDefault(3, plugin);
|
||||
|
||||
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, holder, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, target, context) ||
|
||||
ArgumentPermissions.checkArguments(plugin, sender, permission, key)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
@ -87,15 +87,15 @@ public class MetaSetTemp extends GenericChildCommand {
|
||||
|
||||
Node node = Meta.builder(key, value).withContext(context).expiry(duration).build();
|
||||
|
||||
if (holder.hasNode(DataType.NORMAL, node, NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE).asBoolean()) {
|
||||
Message.ALREADY_HAS_TEMP_META.send(sender, holder.getFormattedDisplayName(), key, value, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
if (target.hasNode(DataType.NORMAL, node, NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE).asBoolean()) {
|
||||
Message.ALREADY_HAS_TEMP_META.send(sender, target.getFormattedDisplayName(), key, value, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
holder.removeIf(DataType.NORMAL, context, NodeType.META.predicate(n -> n.hasExpiry() && n.getMetaKey().equalsIgnoreCase(key)), false);
|
||||
duration = holder.setNode(DataType.NORMAL, node, modifier).getMergedNode().getExpiryDuration();
|
||||
target.removeIf(DataType.NORMAL, context, NodeType.META.predicate(n -> n.hasExpiry() && n.getMetaKey().equalsIgnoreCase(key)), false);
|
||||
duration = target.setNode(DataType.NORMAL, node, modifier).getMergedNode().getExpiryDuration();
|
||||
|
||||
TextComponent.Builder builder = Message.SET_META_TEMP_SUCCESS.asComponent(plugin.getLocaleManager(), key, value, holder.getFormattedDisplayName(), DurationFormatter.LONG.format(duration), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
|
||||
TextComponent.Builder builder = Message.SET_META_TEMP_SUCCESS.asComponent(plugin.getLocaleManager(), key, value, target.getFormattedDisplayName(), DurationFormatter.LONG.format(duration), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
|
||||
HoverEvent event = HoverEvent.showText(TextUtils.fromLegacy(
|
||||
TextUtils.joinNewline("§3Raw key: §r" + key, "§3Raw value: §r" + value),
|
||||
'§'
|
||||
@ -103,16 +103,16 @@ public class MetaSetTemp extends GenericChildCommand {
|
||||
builder.applyDeep(c -> c.hoverEvent(event));
|
||||
sender.sendMessage(builder.build());
|
||||
|
||||
LoggedAction.build().source(sender).target(holder)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("meta", "settemp", key, value, duration, context)
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
StorageAssistant.save(holder, sender, plugin);
|
||||
StorageAssistant.save(target, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.from(3, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
|
@ -34,7 +34,7 @@ import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
@ -93,13 +93,13 @@ public class MetaSetTempChatMeta extends GenericChildCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, holder)) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
int priority = ArgumentParser.parseIntOrElse(0, args, Integer.MIN_VALUE);
|
||||
int priority = args.getIntOrDefault(0, Integer.MIN_VALUE);
|
||||
String meta;
|
||||
Duration duration;
|
||||
TemporaryNodeMergeStrategy modifier;
|
||||
@ -107,10 +107,10 @@ public class MetaSetTempChatMeta extends GenericChildCommand {
|
||||
|
||||
if (priority == Integer.MIN_VALUE) {
|
||||
// priority wasn't defined, meta is at index 0, duration at index 1
|
||||
meta = ArgumentParser.parseString(0, args);
|
||||
duration = ArgumentParser.parseDuration(1, args);
|
||||
modifier = ArgumentParser.parseTemporaryModifier(2, args).orElseGet(() -> plugin.getConfiguration().get(ConfigKeys.TEMPORARY_ADD_BEHAVIOUR));
|
||||
context = ArgumentParser.parseContext(2, args, plugin);
|
||||
meta = args.get(0);
|
||||
duration = args.getDuration(1);
|
||||
modifier = args.getTemporaryModifierAndRemove(2).orElseGet(() -> plugin.getConfiguration().get(ConfigKeys.TEMPORARY_ADD_BEHAVIOUR));
|
||||
context = args.getContextOrDefault(2, plugin);
|
||||
} else {
|
||||
// priority was defined, meta should be at index 1, duration at index 2
|
||||
if (args.size() <= 2) {
|
||||
@ -118,40 +118,40 @@ public class MetaSetTempChatMeta extends GenericChildCommand {
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
meta = ArgumentParser.parseString(1, args);
|
||||
duration = ArgumentParser.parseDuration(2, args);
|
||||
modifier = ArgumentParser.parseTemporaryModifier(3, args).orElseGet(() -> plugin.getConfiguration().get(ConfigKeys.TEMPORARY_ADD_BEHAVIOUR));
|
||||
context = ArgumentParser.parseContext(3, args, plugin);
|
||||
meta = args.get(1);
|
||||
duration = args.getDuration(2);
|
||||
modifier = args.getTemporaryModifierAndRemove(3).orElseGet(() -> plugin.getConfiguration().get(ConfigKeys.TEMPORARY_ADD_BEHAVIOUR));
|
||||
context = args.getContextOrDefault(3, plugin);
|
||||
}
|
||||
|
||||
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, holder, context)) {
|
||||
ArgumentPermissions.checkGroup(plugin, sender, target, context)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
// remove all other prefixes/suffixes set in these contexts
|
||||
holder.removeIf(DataType.NORMAL, context, this.type.nodeType()::matches, false);
|
||||
target.removeIf(DataType.NORMAL, context, this.type.nodeType()::matches, false);
|
||||
|
||||
// determine the priority to set at
|
||||
if (priority == Integer.MIN_VALUE) {
|
||||
MetaAccumulator metaAccumulator = holder.accumulateMeta(QueryOptionsImpl.DEFAULT_CONTEXTUAL.toBuilder().context(context).build());
|
||||
MetaAccumulator metaAccumulator = target.accumulateMeta(QueryOptionsImpl.DEFAULT_CONTEXTUAL.toBuilder().context(context).build());
|
||||
priority = metaAccumulator.getChatMeta(this.type).keySet().stream().mapToInt(e -> e).max().orElse(0) + 1;
|
||||
|
||||
if (holder instanceof Group) {
|
||||
OptionalInt weight = holder.getWeight();
|
||||
if (target instanceof Group) {
|
||||
OptionalInt weight = target.getWeight();
|
||||
if (weight.isPresent() && weight.getAsInt() > priority) {
|
||||
priority = weight.getAsInt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DataMutateResult.WithMergedNode result = holder.setNode(DataType.NORMAL, this.type.builder(meta, priority).expiry(duration).withContext(context).build(), modifier);
|
||||
DataMutateResult.WithMergedNode result = target.setNode(DataType.NORMAL, this.type.builder(meta, priority).expiry(duration).withContext(context).build(), modifier);
|
||||
|
||||
if (result.getResult().wasSuccessful()) {
|
||||
duration = result.getMergedNode().getExpiryDuration();
|
||||
|
||||
TextComponent.Builder builder = Message.ADD_TEMP_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), holder.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, DurationFormatter.LONG.format(duration), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
|
||||
TextComponent.Builder builder = Message.ADD_TEMP_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), target.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, DurationFormatter.LONG.format(duration), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
|
||||
HoverEvent event = HoverEvent.showText(TextUtils.fromLegacy(
|
||||
"§3Raw " + this.type.name().toLowerCase() + ": §r" + meta,
|
||||
'§'
|
||||
@ -159,20 +159,20 @@ public class MetaSetTempChatMeta extends GenericChildCommand {
|
||||
builder.applyDeep(c -> c.hoverEvent(event));
|
||||
sender.sendMessage(builder.build());
|
||||
|
||||
LoggedAction.build().source(sender).target(holder)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("meta" , "settemp" + this.type.name().toLowerCase(), priority, meta, duration, context)
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
StorageAssistant.save(holder, sender, plugin);
|
||||
StorageAssistant.save(target, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} else {
|
||||
Message.ALREADY_HAS_TEMP_CHAT_META.send(sender, holder.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
Message.ALREADY_HAS_TEMP_CHAT_META.send(sender, target.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.from(2, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
|
@ -33,7 +33,7 @@ import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -56,39 +56,39 @@ public class MetaUnset extends GenericChildCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, holder)) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
String key = args.get(0);
|
||||
MutableContextSet context = ArgumentParser.parseContext(1, args, plugin);
|
||||
MutableContextSet context = args.getContextOrDefault(1, plugin);
|
||||
|
||||
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, holder, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, target, context) ||
|
||||
ArgumentPermissions.checkArguments(plugin, sender, permission, key)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
if (holder.removeIf(DataType.NORMAL, context, NodeType.META.predicate(n -> !n.hasExpiry() && n.getMetaKey().equalsIgnoreCase(key)), false)) {
|
||||
Message.UNSET_META_SUCCESS.send(sender, key, holder.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
if (target.removeIf(DataType.NORMAL, context, NodeType.META.predicate(n -> !n.hasExpiry() && n.getMetaKey().equalsIgnoreCase(key)), false)) {
|
||||
Message.UNSET_META_SUCCESS.send(sender, key, target.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
|
||||
LoggedAction.build().source(sender).target(holder)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("meta", "unset", key, context)
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
StorageAssistant.save(holder, sender, plugin);
|
||||
StorageAssistant.save(target, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} else {
|
||||
Message.DOESNT_HAVE_META.send(sender, holder.getFormattedDisplayName(), key, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
Message.DOESNT_HAVE_META.send(sender, target.getFormattedDisplayName(), key, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.from(1, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
|
@ -33,7 +33,7 @@ import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -56,39 +56,39 @@ public class MetaUnsetTemp extends GenericChildCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, holder)) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
String key = args.get(0);
|
||||
MutableContextSet context = ArgumentParser.parseContext(1, args, plugin);
|
||||
MutableContextSet context = args.getContextOrDefault(1, plugin);
|
||||
|
||||
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, holder, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, target, context) ||
|
||||
ArgumentPermissions.checkArguments(plugin, sender, permission, key)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
if (holder.removeIf(DataType.NORMAL, context, NodeType.META.predicate(n -> n.hasExpiry() && n.getMetaKey().equalsIgnoreCase(key)), false)) {
|
||||
Message.UNSET_META_TEMP_SUCCESS.send(sender, key, holder.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
if (target.removeIf(DataType.NORMAL, context, NodeType.META.predicate(n -> n.hasExpiry() && n.getMetaKey().equalsIgnoreCase(key)), false)) {
|
||||
Message.UNSET_META_TEMP_SUCCESS.send(sender, key, target.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
|
||||
LoggedAction.build().source(sender).target(holder)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("meta", "unsettemp", key, context)
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
StorageAssistant.save(holder, sender, plugin);
|
||||
StorageAssistant.save(target, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} else {
|
||||
Message.DOESNT_HAVE_TEMP_META.send(sender, holder.getFormattedDisplayName(), key, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
Message.DOESNT_HAVE_TEMP_META.send(sender, target.getFormattedDisplayName(), key, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.from(1, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
|
@ -33,7 +33,7 @@ import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -56,45 +56,45 @@ public class HolderClear<T extends PermissionHolder> extends ChildCommand<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, T holder, List<String> args, String label) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, getPermission().get(), holder)) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, T target, ArgumentList args, String label) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, getPermission().get(), target)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
int before = holder.normalData().immutable().size();
|
||||
int before = target.normalData().immutable().size();
|
||||
|
||||
MutableContextSet context = ArgumentParser.parseContext(0, args, plugin);
|
||||
MutableContextSet context = args.getContextOrDefault(0, plugin);
|
||||
|
||||
if (ArgumentPermissions.checkContext(plugin, sender, getPermission().get(), context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, holder, context)) {
|
||||
ArgumentPermissions.checkGroup(plugin, sender, target, context)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
if (context.isEmpty()) {
|
||||
holder.clearNodes(DataType.NORMAL, null, true);
|
||||
target.clearNodes(DataType.NORMAL, null, true);
|
||||
} else {
|
||||
holder.clearNodes(DataType.NORMAL, context, true);
|
||||
target.clearNodes(DataType.NORMAL, context, true);
|
||||
}
|
||||
|
||||
int changed = before - holder.normalData().immutable().size();
|
||||
int changed = before - target.normalData().immutable().size();
|
||||
if (changed == 1) {
|
||||
Message.CLEAR_SUCCESS_SINGULAR.send(sender, holder.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
|
||||
Message.CLEAR_SUCCESS_SINGULAR.send(sender, target.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
|
||||
} else {
|
||||
Message.CLEAR_SUCCESS.send(sender, holder.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
|
||||
Message.CLEAR_SUCCESS.send(sender, target.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
|
||||
}
|
||||
|
||||
LoggedAction.build().source(sender).target(holder)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("clear", context)
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
StorageAssistant.save(holder, sender, plugin);
|
||||
StorageAssistant.save(target, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.from(0, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
|
@ -31,6 +31,7 @@ import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.commands.misc.EditorCommand;
|
||||
import me.lucko.luckperms.common.context.contextset.ImmutableContextSetImpl;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -67,8 +68,8 @@ public class HolderEditor<T extends PermissionHolder> extends ChildCommand<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, T holder, List<String> args, String label) {
|
||||
if (ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), holder) || ArgumentPermissions.checkGroup(plugin, sender, holder, ImmutableContextSetImpl.EMPTY)) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, T target, ArgumentList args, String label) {
|
||||
if (ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), target) || ArgumentPermissions.checkGroup(plugin, sender, target, ImmutableContextSetImpl.EMPTY)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
@ -76,8 +77,8 @@ public class HolderEditor<T extends PermissionHolder> extends ChildCommand<T> {
|
||||
List<PermissionHolder> holders = new ArrayList<>();
|
||||
|
||||
// also include users who are a member of the group
|
||||
if (holder instanceof Group) {
|
||||
Group group = (Group) holder;
|
||||
if (target instanceof Group) {
|
||||
Group group = (Group) target;
|
||||
ConstraintNodeMatcher<Node> matcher = StandardNodeMatchers.key(Inheritance.key(group.getName()));
|
||||
|
||||
Map<UUID, User> users = new LinkedHashMap<>(plugin.getUserManager().getAll());
|
||||
@ -114,7 +115,7 @@ public class HolderEditor<T extends PermissionHolder> extends ChildCommand<T> {
|
||||
}
|
||||
|
||||
// include the original holder too
|
||||
holders.add(holder);
|
||||
holders.add(target);
|
||||
|
||||
Message.EDITOR_START.send(sender);
|
||||
|
||||
|
@ -31,6 +31,7 @@ import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
@ -58,8 +59,8 @@ public class HolderShowTracks<T extends PermissionHolder> extends ChildCommand<T
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, T holder, List<String> args, String label) {
|
||||
if (ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), holder)) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, T target, ArgumentList args, String label) {
|
||||
if (ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), target)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
@ -74,9 +75,9 @@ public class HolderShowTracks<T extends PermissionHolder> extends ChildCommand<T
|
||||
|
||||
List<Map.Entry<Track, String>> lines = new ArrayList<>();
|
||||
|
||||
if (holder.getType() == HolderType.USER) {
|
||||
if (target.getType() == HolderType.USER) {
|
||||
// if the holder is a user, we want to query parent groups for tracks
|
||||
Set<InheritanceNode> nodes = holder.normalData().immutableInheritance().values().stream()
|
||||
Set<InheritanceNode> nodes = target.normalData().immutableInheritance().values().stream()
|
||||
.filter(Node::getValue)
|
||||
.filter(n -> !n.hasExpiry())
|
||||
.collect(Collectors.toSet());
|
||||
@ -93,7 +94,7 @@ public class HolderShowTracks<T extends PermissionHolder> extends ChildCommand<T
|
||||
}
|
||||
} else {
|
||||
// otherwise, just lookup for the actual group
|
||||
String groupName = ((Group) holder).getName();
|
||||
String groupName = ((Group) target).getName();
|
||||
List<Track> tracks = plugin.getTrackManager().getAll().values().stream()
|
||||
.filter(t -> t.containsGroup(groupName))
|
||||
.collect(Collectors.toList());
|
||||
@ -104,11 +105,11 @@ public class HolderShowTracks<T extends PermissionHolder> extends ChildCommand<T
|
||||
}
|
||||
|
||||
if (lines.isEmpty()) {
|
||||
Message.LIST_TRACKS_EMPTY.send(sender, holder.getFormattedDisplayName());
|
||||
Message.LIST_TRACKS_EMPTY.send(sender, target.getFormattedDisplayName());
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
Message.LIST_TRACKS.send(sender, holder.getFormattedDisplayName());
|
||||
Message.LIST_TRACKS.send(sender, target.getFormattedDisplayName());
|
||||
for (Map.Entry<Track, String> line : lines) {
|
||||
Message.LIST_TRACKS_ENTRY.send(sender, line.getKey().getName(), line.getValue());
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -44,6 +44,7 @@ import me.lucko.luckperms.common.model.PermissionHolder;
|
||||
import me.lucko.luckperms.common.node.types.Inheritance;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.storage.misc.DataConstraints;
|
||||
import me.lucko.luckperms.common.util.Predicates;
|
||||
|
||||
import net.luckperms.api.context.MutableContextSet;
|
||||
@ -58,14 +59,14 @@ public class ParentAdd extends GenericChildCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, holder)) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
String groupName = ArgumentParser.parseName(0, args);
|
||||
MutableContextSet context = ArgumentParser.parseContext(1, args, plugin);
|
||||
String groupName = args.getLowercase(0, DataConstraints.GROUP_NAME_TEST);
|
||||
MutableContextSet context = args.getContextOrDefault(1, plugin);
|
||||
|
||||
Group group = StorageAssistant.loadGroup(groupName, sender, plugin, false);
|
||||
if (group == null) {
|
||||
@ -73,32 +74,32 @@ public class ParentAdd extends GenericChildCommand {
|
||||
}
|
||||
|
||||
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, holder, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, target, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, group, context) ||
|
||||
ArgumentPermissions.checkArguments(plugin, sender, permission, group.getName())) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
DataMutateResult result = holder.setNode(DataType.NORMAL, Inheritance.builder(group.getName()).withContext(context).build(), true);
|
||||
DataMutateResult result = target.setNode(DataType.NORMAL, Inheritance.builder(group.getName()).withContext(context).build(), true);
|
||||
|
||||
if (result.wasSuccessful()) {
|
||||
Message.SET_INHERIT_SUCCESS.send(sender, holder.getFormattedDisplayName(), group.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
Message.SET_INHERIT_SUCCESS.send(sender, target.getFormattedDisplayName(), group.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
|
||||
LoggedAction.build().source(sender).target(holder)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("parent", "add", group.getName(), context)
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
StorageAssistant.save(holder, sender, plugin);
|
||||
StorageAssistant.save(target, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} else {
|
||||
Message.ALREADY_INHERITS.send(sender, holder.getFormattedDisplayName(), group.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
Message.ALREADY_INHERITS.send(sender, target.getFormattedDisplayName(), group.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, TabCompletions.groups(plugin))
|
||||
.from(1, TabCompletions.contexts(plugin))
|
||||
|
@ -33,7 +33,7 @@ import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
@ -45,6 +45,7 @@ import me.lucko.luckperms.common.model.PermissionHolder;
|
||||
import me.lucko.luckperms.common.node.types.Inheritance;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.storage.misc.DataConstraints;
|
||||
import me.lucko.luckperms.common.util.DurationFormatter;
|
||||
import me.lucko.luckperms.common.util.Predicates;
|
||||
|
||||
@ -62,16 +63,16 @@ public class ParentAddTemp extends GenericChildCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, holder)) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
String groupName = ArgumentParser.parseName(0, args);
|
||||
Duration duration = ArgumentParser.parseDuration(1, args);
|
||||
TemporaryNodeMergeStrategy modifier = ArgumentParser.parseTemporaryModifier(2, args).orElseGet(() -> plugin.getConfiguration().get(ConfigKeys.TEMPORARY_ADD_BEHAVIOUR));
|
||||
MutableContextSet context = ArgumentParser.parseContext(2, args, plugin);
|
||||
String groupName = args.getLowercase(0, DataConstraints.GROUP_NAME_TEST);
|
||||
Duration duration = args.getDuration(1);
|
||||
TemporaryNodeMergeStrategy modifier = args.getTemporaryModifierAndRemove(2).orElseGet(() -> plugin.getConfiguration().get(ConfigKeys.TEMPORARY_ADD_BEHAVIOUR));
|
||||
MutableContextSet context = args.getContextOrDefault(2, plugin);
|
||||
|
||||
Group group = StorageAssistant.loadGroup(groupName, sender, plugin, false);
|
||||
if (group == null) {
|
||||
@ -79,38 +80,38 @@ public class ParentAddTemp extends GenericChildCommand {
|
||||
}
|
||||
|
||||
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, holder, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, target, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, group, context) ||
|
||||
ArgumentPermissions.checkArguments(plugin, sender, permission, group.getName())) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
if (group.getName().equalsIgnoreCase(holder.getObjectName())) {
|
||||
Message.ALREADY_TEMP_INHERITS.send(sender, holder.getFormattedDisplayName(), group.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
if (group.getName().equalsIgnoreCase(target.getObjectName())) {
|
||||
Message.ALREADY_TEMP_INHERITS.send(sender, target.getFormattedDisplayName(), group.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
DataMutateResult.WithMergedNode result = holder.setNode(DataType.NORMAL, Inheritance.builder(group.getName()).expiry(duration).withContext(context).build(), modifier);
|
||||
DataMutateResult.WithMergedNode result = target.setNode(DataType.NORMAL, Inheritance.builder(group.getName()).expiry(duration).withContext(context).build(), modifier);
|
||||
|
||||
if (result.getResult().wasSuccessful()) {
|
||||
duration = result.getMergedNode().getExpiryDuration();
|
||||
Message.SET_TEMP_INHERIT_SUCCESS.send(sender, holder.getFormattedDisplayName(), group.getFormattedDisplayName(), DurationFormatter.LONG.format(duration), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
Message.SET_TEMP_INHERIT_SUCCESS.send(sender, target.getFormattedDisplayName(), group.getFormattedDisplayName(), DurationFormatter.LONG.format(duration), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
|
||||
LoggedAction.build().source(sender).target(holder)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("parent", "addtemp", group.getName(), duration, context)
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
StorageAssistant.save(holder, sender, plugin);
|
||||
StorageAssistant.save(target, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} else {
|
||||
Message.ALREADY_TEMP_INHERITS.send(sender, holder.getFormattedDisplayName(), group.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
Message.ALREADY_TEMP_INHERITS.send(sender, target.getFormattedDisplayName(), group.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, TabCompletions.groups(plugin))
|
||||
.from(2, TabCompletions.contexts(plugin))
|
||||
|
@ -33,7 +33,7 @@ import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -56,44 +56,44 @@ public class ParentClear extends GenericChildCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, holder)) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
int before = holder.normalData().immutable().size();
|
||||
int before = target.normalData().immutable().size();
|
||||
|
||||
MutableContextSet context = ArgumentParser.parseContext(0, args, plugin);
|
||||
MutableContextSet context = args.getContextOrDefault(0, plugin);
|
||||
|
||||
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || ArgumentPermissions.checkGroup(plugin, sender, holder, context)) {
|
||||
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || ArgumentPermissions.checkGroup(plugin, sender, target, context)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
if (context.isEmpty()) {
|
||||
holder.removeIf(DataType.NORMAL, null, NodeType.INHERITANCE::matches, true);
|
||||
target.removeIf(DataType.NORMAL, null, NodeType.INHERITANCE::matches, true);
|
||||
} else {
|
||||
holder.removeIf(DataType.NORMAL, context, NodeType.INHERITANCE::matches, true);
|
||||
target.removeIf(DataType.NORMAL, context, NodeType.INHERITANCE::matches, true);
|
||||
}
|
||||
|
||||
int changed = before - holder.normalData().immutable().size();
|
||||
int changed = before - target.normalData().immutable().size();
|
||||
if (changed == 1) {
|
||||
Message.PARENT_CLEAR_SUCCESS_SINGULAR.send(sender, holder.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
|
||||
Message.PARENT_CLEAR_SUCCESS_SINGULAR.send(sender, target.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
|
||||
} else {
|
||||
Message.PARENT_CLEAR_SUCCESS.send(sender, holder.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
|
||||
Message.PARENT_CLEAR_SUCCESS.send(sender, target.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
|
||||
}
|
||||
|
||||
LoggedAction.build().source(sender).target(holder)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("parent", "clear", context)
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
StorageAssistant.save(holder, sender, plugin);
|
||||
StorageAssistant.save(target, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.from(0, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
|
@ -33,7 +33,7 @@ import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -60,8 +60,8 @@ public class ParentClearTrack extends GenericChildCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, holder)) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
@ -82,41 +82,41 @@ public class ParentClearTrack extends GenericChildCommand {
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
int before = holder.normalData().immutable().size();
|
||||
int before = target.normalData().immutable().size();
|
||||
|
||||
ImmutableContextSet context = ArgumentParser.parseContext(1, args, plugin).immutableCopy();
|
||||
ImmutableContextSet context = args.getContextOrDefault(1, plugin).immutableCopy();
|
||||
|
||||
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, holder, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, target, context) ||
|
||||
ArgumentPermissions.checkArguments(plugin, sender, permission, track.getName())) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
holder.removeIf(DataType.NORMAL, context.isEmpty() ? null : context, NodeType.INHERITANCE.predicate(n -> track.containsGroup(n.getGroupName())), false);
|
||||
target.removeIf(DataType.NORMAL, context.isEmpty() ? null : context, NodeType.INHERITANCE.predicate(n -> track.containsGroup(n.getGroupName())), false);
|
||||
|
||||
if (holder.getType() == HolderType.USER) {
|
||||
plugin.getUserManager().giveDefaultIfNeeded(((User) holder), false);
|
||||
if (target.getType() == HolderType.USER) {
|
||||
plugin.getUserManager().giveDefaultIfNeeded(((User) target), false);
|
||||
}
|
||||
|
||||
int changed = before - holder.normalData().immutable().size();
|
||||
int changed = before - target.normalData().immutable().size();
|
||||
|
||||
if (changed == 1) {
|
||||
Message.PARENT_CLEAR_TRACK_SUCCESS_SINGULAR.send(sender, holder.getFormattedDisplayName(), track.getName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
|
||||
Message.PARENT_CLEAR_TRACK_SUCCESS_SINGULAR.send(sender, target.getFormattedDisplayName(), track.getName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
|
||||
} else {
|
||||
Message.PARENT_CLEAR_TRACK_SUCCESS.send(sender, holder.getFormattedDisplayName(), track.getName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
|
||||
Message.PARENT_CLEAR_TRACK_SUCCESS.send(sender, target.getFormattedDisplayName(), track.getName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
|
||||
}
|
||||
|
||||
LoggedAction.build().source(sender).target(holder)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("parent", "cleartrack", track.getName(), context)
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
StorageAssistant.save(holder, sender, plugin);
|
||||
StorageAssistant.save(target, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, TabCompletions.tracks(plugin))
|
||||
.from(1, TabCompletions.contexts(plugin))
|
||||
|
@ -29,7 +29,7 @@ import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.SortMode;
|
||||
import me.lucko.luckperms.common.command.utils.SortType;
|
||||
@ -66,25 +66,25 @@ public class ParentInfo extends GenericChildCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) {
|
||||
if (ArgumentPermissions.checkViewPerms(plugin, sender, permission, holder)) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) {
|
||||
if (ArgumentPermissions.checkViewPerms(plugin, sender, permission, target)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
int page = ArgumentParser.parseIntOrElse(0, args, 1);
|
||||
int page = args.getIntOrDefault(0, 1);
|
||||
SortMode sortMode = SortMode.determine(args);
|
||||
|
||||
// get the holders nodes
|
||||
List<InheritanceNode> nodes = new LinkedList<>();
|
||||
holder.normalData().copyInheritanceNodesTo(nodes, QueryOptionsImpl.DEFAULT_NON_CONTEXTUAL);
|
||||
target.normalData().copyInheritanceNodesTo(nodes, QueryOptionsImpl.DEFAULT_NON_CONTEXTUAL);
|
||||
|
||||
// remove irrelevant types (these are displayed in the other info commands)
|
||||
nodes.removeIf(node -> !node.getValue());
|
||||
|
||||
// handle empty
|
||||
if (nodes.isEmpty()) {
|
||||
Message.PARENT_INFO_NO_DATA.send(sender, holder.getFormattedDisplayName());
|
||||
Message.PARENT_INFO_NO_DATA.send(sender, target.getFormattedDisplayName());
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
@ -109,7 +109,7 @@ public class ParentInfo extends GenericChildCommand {
|
||||
List<InheritanceNode> content = pages.get(pageIndex);
|
||||
|
||||
// send header
|
||||
Message.PARENT_INFO.send(sender, holder.getFormattedDisplayName(), page, pages.size(), nodes.size());
|
||||
Message.PARENT_INFO.send(sender, target.getFormattedDisplayName(), page, pages.size(), nodes.size());
|
||||
|
||||
// send content
|
||||
for (InheritanceNode node : content) {
|
||||
@ -118,7 +118,7 @@ public class ParentInfo extends GenericChildCommand {
|
||||
s += "\n&2 expires in " + DurationFormatter.LONG.format(node.getExpiryDuration());
|
||||
}
|
||||
|
||||
TextComponent message = TextUtils.fromLegacy(s, TextUtils.AMPERSAND_CHAR).toBuilder().applyDeep(makeFancy(holder, label, node)).build();
|
||||
TextComponent message = TextUtils.fromLegacy(s, TextUtils.AMPERSAND_CHAR).toBuilder().applyDeep(makeFancy(target, label, node)).build();
|
||||
sender.sendMessage(message);
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
@ -47,6 +47,7 @@ import me.lucko.luckperms.common.model.manager.group.GroupManager;
|
||||
import me.lucko.luckperms.common.node.types.Inheritance;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.storage.misc.DataConstraints;
|
||||
import me.lucko.luckperms.common.util.Predicates;
|
||||
|
||||
import net.luckperms.api.context.MutableContextSet;
|
||||
@ -61,25 +62,25 @@ public class ParentRemove extends GenericChildCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, holder)) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
String groupName = ArgumentParser.parseNameWithSpace(0, args);
|
||||
MutableContextSet context = ArgumentParser.parseContext(1, args, plugin);
|
||||
String groupName = args.getLowercase(0, DataConstraints.GROUP_NAME_TEST_ALLOW_SPACE);
|
||||
MutableContextSet context = args.getContextOrDefault(1, plugin);
|
||||
|
||||
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, holder, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, target, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, groupName, context) ||
|
||||
ArgumentPermissions.checkArguments(plugin, sender, permission, groupName)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
if (holder.getType() == HolderType.USER) {
|
||||
User user = (User) holder;
|
||||
if (target.getType() == HolderType.USER) {
|
||||
User user = (User) target;
|
||||
|
||||
boolean shouldPrevent = plugin.getConfiguration().get(ConfigKeys.PREVENT_PRIMARY_GROUP_REMOVAL) &&
|
||||
context.isEmpty() &&
|
||||
@ -92,28 +93,28 @@ public class ParentRemove extends GenericChildCommand {
|
||||
}
|
||||
}
|
||||
|
||||
DataMutateResult result = holder.unsetNode(DataType.NORMAL, Inheritance.builder(groupName).withContext(context).build());
|
||||
DataMutateResult result = target.unsetNode(DataType.NORMAL, Inheritance.builder(groupName).withContext(context).build());
|
||||
if (result.wasSuccessful()) {
|
||||
Message.UNSET_INHERIT_SUCCESS.send(sender, holder.getFormattedDisplayName(), groupName, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
Message.UNSET_INHERIT_SUCCESS.send(sender, target.getFormattedDisplayName(), groupName, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
|
||||
LoggedAction.build().source(sender).target(holder)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("parent", "remove", groupName, context)
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
if (holder.getType() == HolderType.USER) {
|
||||
plugin.getUserManager().giveDefaultIfNeeded(((User) holder), false);
|
||||
if (target.getType() == HolderType.USER) {
|
||||
plugin.getUserManager().giveDefaultIfNeeded(((User) target), false);
|
||||
}
|
||||
|
||||
StorageAssistant.save(holder, sender, plugin);
|
||||
StorageAssistant.save(target, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} else {
|
||||
Message.DOES_NOT_INHERIT.send(sender, holder.getFormattedDisplayName(), groupName, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
Message.DOES_NOT_INHERIT.send(sender, target.getFormattedDisplayName(), groupName, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, TabCompletions.groups(plugin))
|
||||
.from(1, TabCompletions.contexts(plugin))
|
||||
|
@ -33,7 +33,7 @@ import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -43,6 +43,7 @@ import me.lucko.luckperms.common.model.PermissionHolder;
|
||||
import me.lucko.luckperms.common.node.types.Inheritance;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.storage.misc.DataConstraints;
|
||||
import me.lucko.luckperms.common.util.DurationFormatter;
|
||||
import me.lucko.luckperms.common.util.Predicates;
|
||||
|
||||
@ -60,58 +61,59 @@ public class ParentRemoveTemp extends GenericChildCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, holder)) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
String groupName = ArgumentParser.parseNameWithSpace(0, args);
|
||||
Duration duration = ArgumentParser.parseDurationOrElse(1, args, null);
|
||||
MutableContextSet context = ArgumentParser.parseContext(duration == null ? 1 : 2, args, plugin);
|
||||
String groupName = args.getLowercase(0, DataConstraints.GROUP_NAME_TEST_ALLOW_SPACE);
|
||||
Duration duration = args.getDurationOrDefault(1, null);
|
||||
int fromIndex = duration == null ? 1 : 2;
|
||||
MutableContextSet context = args.getContextOrDefault(fromIndex, plugin);
|
||||
|
||||
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, holder, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, target, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, groupName, context) ||
|
||||
ArgumentPermissions.checkArguments(plugin, sender, permission, groupName)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
DataMutateResult.WithMergedNode result = holder.unsetNode(DataType.NORMAL, Inheritance.builder(groupName).expiry(10L).withContext(context).build(), duration);
|
||||
DataMutateResult.WithMergedNode result = target.unsetNode(DataType.NORMAL, Inheritance.builder(groupName).expiry(10L).withContext(context).build(), duration);
|
||||
if (result.getResult().wasSuccessful()) {
|
||||
Node mergedNode = result.getMergedNode();
|
||||
//noinspection ConstantConditions
|
||||
if (mergedNode != null) {
|
||||
Message.UNSET_TEMP_INHERIT_SUBTRACT_SUCCESS.send(sender,
|
||||
holder.getFormattedDisplayName(),
|
||||
target.getFormattedDisplayName(),
|
||||
groupName,
|
||||
DurationFormatter.LONG.format(mergedNode.getExpiryDuration()),
|
||||
MessageUtils.contextSetToString(plugin.getLocaleManager(), context),
|
||||
DurationFormatter.LONG.format(duration)
|
||||
);
|
||||
|
||||
LoggedAction.build().source(sender).target(holder)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("parent", "removetemp", groupName, duration, context)
|
||||
.build().submit(plugin, sender);
|
||||
} else {
|
||||
Message.UNSET_TEMP_INHERIT_SUCCESS.send(sender, holder.getFormattedDisplayName(), groupName, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
Message.UNSET_TEMP_INHERIT_SUCCESS.send(sender, target.getFormattedDisplayName(), groupName, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
|
||||
LoggedAction.build().source(sender).target(holder)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("parent", "removetemp", groupName, context)
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
StorageAssistant.save(holder, sender, plugin);
|
||||
StorageAssistant.save(target, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} else {
|
||||
Message.DOES_NOT_TEMP_INHERIT.send(sender, holder.getFormattedDisplayName(), groupName, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
Message.DOES_NOT_TEMP_INHERIT.send(sender, target.getFormattedDisplayName(), groupName, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, TabCompletions.groups(plugin))
|
||||
.from(1, TabCompletions.contexts(plugin))
|
||||
|
@ -33,7 +33,7 @@ import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -46,6 +46,7 @@ import me.lucko.luckperms.common.model.User;
|
||||
import me.lucko.luckperms.common.node.types.Inheritance;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.storage.misc.DataConstraints;
|
||||
import me.lucko.luckperms.common.util.Predicates;
|
||||
|
||||
import net.luckperms.api.context.MutableContextSet;
|
||||
@ -60,14 +61,14 @@ public class ParentSet extends GenericChildCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, holder)) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
String groupName = ArgumentParser.parseName(0, args);
|
||||
MutableContextSet context = ArgumentParser.parseContext(1, args, plugin);
|
||||
String groupName = args.getLowercase(0, DataConstraints.GROUP_NAME_TEST);
|
||||
MutableContextSet context = args.getContextOrDefault(1, plugin);
|
||||
|
||||
Group group = StorageAssistant.loadGroup(groupName, sender, plugin, false);
|
||||
if (group == null) {
|
||||
@ -75,31 +76,31 @@ public class ParentSet extends GenericChildCommand {
|
||||
}
|
||||
|
||||
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, holder, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, target, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, group, context) ||
|
||||
ArgumentPermissions.checkArguments(plugin, sender, permission, group.getName())) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
holder.removeIf(DataType.NORMAL, context, NodeType.INHERITANCE::matches, false);
|
||||
holder.setNode(DataType.NORMAL, Inheritance.builder(group.getName()).withContext(context).build(), true);
|
||||
if (holder.getType() == HolderType.USER) {
|
||||
((User) holder).getPrimaryGroup().setStoredValue(group.getName());
|
||||
target.removeIf(DataType.NORMAL, context, NodeType.INHERITANCE::matches, false);
|
||||
target.setNode(DataType.NORMAL, Inheritance.builder(group.getName()).withContext(context).build(), true);
|
||||
if (target.getType() == HolderType.USER) {
|
||||
((User) target).getPrimaryGroup().setStoredValue(group.getName());
|
||||
}
|
||||
|
||||
Message.SET_PARENT_SUCCESS.send(sender, holder.getFormattedDisplayName(), group.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
Message.SET_PARENT_SUCCESS.send(sender, target.getFormattedDisplayName(), group.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
|
||||
LoggedAction.build().source(sender).target(holder)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("parent", "set", group.getName(), context)
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
StorageAssistant.save(holder, sender, plugin);
|
||||
StorageAssistant.save(target, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, TabCompletions.groups(plugin))
|
||||
.from(1, TabCompletions.contexts(plugin))
|
||||
|
@ -33,7 +33,7 @@ import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -60,8 +60,8 @@ public class ParentSetTrack extends GenericChildCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, holder)) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
@ -82,7 +82,7 @@ public class ParentSetTrack extends GenericChildCommand {
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
int index = ArgumentParser.parseIntOrElse(1, args, -1);
|
||||
int index = args.getIntOrDefault(1, -1);
|
||||
String groupName;
|
||||
if (index > 0) {
|
||||
List<String> trackGroups = track.getGroups();
|
||||
@ -92,14 +92,14 @@ public class ParentSetTrack extends GenericChildCommand {
|
||||
}
|
||||
groupName = track.getGroups().get(index - 1);
|
||||
} else {
|
||||
groupName = ArgumentParser.parseName(1, args);
|
||||
groupName = args.getLowercase(1, DataConstraints.GROUP_NAME_TEST);
|
||||
if (!track.containsGroup(groupName)) {
|
||||
Message.TRACK_DOES_NOT_CONTAIN.send(sender, track.getName(), groupName);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
}
|
||||
|
||||
ImmutableContextSet context = ArgumentParser.parseContext(2, args, plugin).immutableCopy();
|
||||
ImmutableContextSet context = args.getContextOrDefault(2, plugin).immutableCopy();
|
||||
|
||||
Group group = StorageAssistant.loadGroup(groupName, sender, plugin, false);
|
||||
if (group == null) {
|
||||
@ -107,28 +107,28 @@ public class ParentSetTrack extends GenericChildCommand {
|
||||
}
|
||||
|
||||
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, holder, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, target, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, group, context) ||
|
||||
ArgumentPermissions.checkArguments(plugin, sender, permission, track.getName(), group.getName())) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
holder.removeIf(DataType.NORMAL, context, NodeType.INHERITANCE.predicate(n -> track.containsGroup(n.getGroupName())), false);
|
||||
holder.setNode(DataType.NORMAL, Inheritance.builder(group.getName()).withContext(context).build(), true);
|
||||
target.removeIf(DataType.NORMAL, context, NodeType.INHERITANCE.predicate(n -> track.containsGroup(n.getGroupName())), false);
|
||||
target.setNode(DataType.NORMAL, Inheritance.builder(group.getName()).withContext(context).build(), true);
|
||||
|
||||
Message.SET_TRACK_PARENT_SUCCESS.send(sender, holder.getFormattedDisplayName(), track.getName(), group.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
Message.SET_TRACK_PARENT_SUCCESS.send(sender, target.getFormattedDisplayName(), track.getName(), group.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
|
||||
LoggedAction.build().source(sender).target(holder)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("parent", "settrack", track.getName(), groupName, context)
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
StorageAssistant.save(holder, sender, plugin);
|
||||
StorageAssistant.save(target, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, TabCompletions.tracks(plugin))
|
||||
.at(1, TabCompletions.groups(plugin))
|
||||
|
@ -32,6 +32,7 @@ import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.context.contextset.ImmutableContextSetImpl;
|
||||
@ -59,11 +60,11 @@ public class UserSwitchPrimaryGroup extends GenericChildCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) {
|
||||
// cast to user
|
||||
// although this command is build as a sharedsubcommand,
|
||||
// it is only added to the listings for users.
|
||||
User user = ((User) holder);
|
||||
User user = ((User) target);
|
||||
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, user)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
@ -82,7 +83,7 @@ public class UserSwitchPrimaryGroup extends GenericChildCommand {
|
||||
}
|
||||
|
||||
if (ArgumentPermissions.checkContext(plugin, sender, permission, ImmutableContextSetImpl.EMPTY) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, holder, ImmutableContextSetImpl.EMPTY) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, target, ImmutableContextSetImpl.EMPTY) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, group, ImmutableContextSetImpl.EMPTY) ||
|
||||
ArgumentPermissions.checkArguments(plugin, sender, permission, group.getName())) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
@ -97,7 +98,7 @@ public class UserSwitchPrimaryGroup extends GenericChildCommand {
|
||||
Node node = Inheritance.builder(group.getName()).build();
|
||||
if (!user.hasNode(DataType.NORMAL, node, NodeEqualityPredicate.IGNORE_VALUE).asBoolean()) {
|
||||
Message.USER_PRIMARYGROUP_ERROR_NOTMEMBER.send(sender, user.getFormattedDisplayName(), group.getName());
|
||||
holder.setNode(DataType.NORMAL, node, true);
|
||||
target.setNode(DataType.NORMAL, node, true);
|
||||
}
|
||||
|
||||
user.getPrimaryGroup().setStoredValue(group.getName());
|
||||
@ -112,7 +113,7 @@ public class UserSwitchPrimaryGroup extends GenericChildCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, TabCompletions.groups(plugin))
|
||||
.complete(args);
|
||||
|
@ -32,7 +32,7 @@ import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
@ -56,24 +56,24 @@ public class PermissionCheck extends GenericChildCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkViewPerms(plugin, sender, permission, holder)) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkViewPerms(plugin, sender, permission, target)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
String node = ArgumentParser.parseString(0, args);
|
||||
MutableContextSet context = ArgumentParser.parseContext(1, args, plugin);
|
||||
String node = args.get(0);
|
||||
MutableContextSet context = args.getContextOrDefault(1, plugin);
|
||||
|
||||
Tristate result = holder.hasNode(DataType.NORMAL, NodeBuilders.determineMostApplicable(node).withContext(context).build(), NodeEqualityPredicate.IGNORE_VALUE_OR_IF_TEMPORARY);
|
||||
Tristate result = target.hasNode(DataType.NORMAL, NodeBuilders.determineMostApplicable(node).withContext(context).build(), NodeEqualityPredicate.IGNORE_VALUE_OR_IF_TEMPORARY);
|
||||
String s = MessageUtils.formatTristate(result);
|
||||
|
||||
Message.CHECK_PERMISSION.send(sender, holder.getFormattedDisplayName(), node, s, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
Message.CHECK_PERMISSION.send(sender, target.getFormattedDisplayName(), node, s, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, TabCompletions.permissions(plugin))
|
||||
.from(1, TabCompletions.contexts(plugin))
|
||||
|
@ -32,7 +32,7 @@ import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
@ -57,32 +57,32 @@ public class PermissionCheckInherits extends GenericChildCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkViewPerms(plugin, sender, permission, holder)) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkViewPerms(plugin, sender, permission, target)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
String node = ArgumentParser.parseString(0, args);
|
||||
MutableContextSet context = ArgumentParser.parseContext(1, args, plugin);
|
||||
String node = args.get(0);
|
||||
MutableContextSet context = args.getContextOrDefault(1, plugin);
|
||||
|
||||
Optional<Node> match = holder.resolveInheritedNodes(QueryOptionsImpl.DEFAULT_NON_CONTEXTUAL).stream()
|
||||
Optional<Node> match = target.resolveInheritedNodes(QueryOptionsImpl.DEFAULT_NON_CONTEXTUAL).stream()
|
||||
.filter(n -> n.getKey().equalsIgnoreCase(node) && n.getContexts().equals(context))
|
||||
.findFirst();
|
||||
|
||||
String location = match.map(n -> n.metadata(InheritanceOriginMetadata.KEY).getOrigin().getName()).orElse(null);
|
||||
|
||||
if (location == null || location.equalsIgnoreCase(holder.getObjectName())) {
|
||||
if (location == null || location.equalsIgnoreCase(target.getObjectName())) {
|
||||
location = "self";
|
||||
}
|
||||
|
||||
String s = MessageUtils.formatTristate(match.map(n -> Tristate.of(n.getValue())).orElse(Tristate.UNDEFINED));
|
||||
Message.CHECK_INHERITS_PERMISSION.send(sender, holder.getFormattedDisplayName(), node, s, MessageUtils.contextSetToString(plugin.getLocaleManager(), context), location);
|
||||
Message.CHECK_INHERITS_PERMISSION.send(sender, target.getFormattedDisplayName(), node, s, MessageUtils.contextSetToString(plugin.getLocaleManager(), context), location);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, TabCompletions.permissions(plugin))
|
||||
.from(1, TabCompletions.contexts(plugin))
|
||||
|
@ -33,7 +33,7 @@ import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -56,41 +56,41 @@ public class PermissionClear extends GenericChildCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, holder)) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
int before = holder.normalData().immutable().size();
|
||||
int before = target.normalData().immutable().size();
|
||||
|
||||
MutableContextSet context = ArgumentParser.parseContext(0, args, plugin);
|
||||
MutableContextSet context = args.getContextOrDefault(0, plugin);
|
||||
|
||||
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, holder, context)) {
|
||||
ArgumentPermissions.checkGroup(plugin, sender, target, context)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
holder.removeIf(DataType.NORMAL, context.isEmpty() ? null : context, NodeType.PERMISSION::matches, false);
|
||||
target.removeIf(DataType.NORMAL, context.isEmpty() ? null : context, NodeType.PERMISSION::matches, false);
|
||||
|
||||
int changed = before - holder.normalData().immutable().size();
|
||||
int changed = before - target.normalData().immutable().size();
|
||||
if (changed == 1) {
|
||||
Message.PERMISSION_CLEAR_SUCCESS_SINGULAR.send(sender, holder.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
|
||||
Message.PERMISSION_CLEAR_SUCCESS_SINGULAR.send(sender, target.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
|
||||
} else {
|
||||
Message.PERMISSION_CLEAR_SUCCESS.send(sender, holder.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
|
||||
Message.PERMISSION_CLEAR_SUCCESS.send(sender, target.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
|
||||
}
|
||||
|
||||
LoggedAction.build().source(sender).target(holder)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("permission", "clear", context)
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
StorageAssistant.save(holder, sender, plugin);
|
||||
StorageAssistant.save(target, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.from(0, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
|
@ -29,7 +29,7 @@ import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.SortMode;
|
||||
import me.lucko.luckperms.common.command.utils.SortType;
|
||||
@ -66,17 +66,17 @@ public class PermissionInfo extends GenericChildCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) {
|
||||
if (ArgumentPermissions.checkViewPerms(plugin, sender, permission, holder)) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) {
|
||||
if (ArgumentPermissions.checkViewPerms(plugin, sender, permission, target)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
int page = ArgumentParser.parseIntOrElse(0, args, 1);
|
||||
int page = args.getIntOrDefault(0, 1);
|
||||
SortMode sortMode = SortMode.determine(args);
|
||||
|
||||
// get the holders nodes
|
||||
List<Node> nodes = new ArrayList<>(holder.normalData().asSortedSet());
|
||||
List<Node> nodes = new ArrayList<>(target.normalData().asSortedSet());
|
||||
|
||||
// remove irrelevant types (these are displayed in the other info commands)
|
||||
nodes.removeIf(NodeType.INHERITANCE.predicate(n -> n.getValue() && plugin.getGroupManager().isLoaded(n.getGroupName()))
|
||||
@ -84,7 +84,7 @@ public class PermissionInfo extends GenericChildCommand {
|
||||
|
||||
// handle empty
|
||||
if (nodes.isEmpty()) {
|
||||
Message.PERMISSION_INFO_NO_DATA.send(sender, holder.getFormattedDisplayName());
|
||||
Message.PERMISSION_INFO_NO_DATA.send(sender, target.getFormattedDisplayName());
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
@ -109,7 +109,7 @@ public class PermissionInfo extends GenericChildCommand {
|
||||
List<Node> content = pages.get(pageIndex);
|
||||
|
||||
// send header
|
||||
Message.PERMISSION_INFO.send(sender, holder.getFormattedDisplayName(), page, pages.size(), nodes.size());
|
||||
Message.PERMISSION_INFO.send(sender, target.getFormattedDisplayName(), page, pages.size(), nodes.size());
|
||||
|
||||
// send content
|
||||
for (Node node : content) {
|
||||
@ -118,7 +118,7 @@ public class PermissionInfo extends GenericChildCommand {
|
||||
s += "\n&2- expires in " + DurationFormatter.LONG.format(node.getExpiryDuration());
|
||||
}
|
||||
|
||||
TextComponent message = TextUtils.fromLegacy(s, TextUtils.AMPERSAND_CHAR).toBuilder().applyDeep(makeFancy(holder, label, node)).build();
|
||||
TextComponent message = TextUtils.fromLegacy(s, TextUtils.AMPERSAND_CHAR).toBuilder().applyDeep(makeFancy(target, label, node)).build();
|
||||
sender.sendMessage(message);
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -59,18 +59,18 @@ public class PermissionSet extends GenericChildCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, holder)) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
String node = ArgumentParser.parseString(0, args);
|
||||
boolean value = ArgumentParser.parseBoolean(1, args);
|
||||
MutableContextSet context = ArgumentParser.parseContext(2, args, plugin);
|
||||
String node = args.get(0);
|
||||
boolean value = args.getBooleanOrInsert(1, true);
|
||||
MutableContextSet context = args.getContextOrDefault(2, plugin);
|
||||
|
||||
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, holder, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, target, context) ||
|
||||
ArgumentPermissions.checkArguments(plugin, sender, permission, node)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
@ -85,25 +85,25 @@ public class PermissionSet extends GenericChildCommand {
|
||||
}
|
||||
}
|
||||
|
||||
DataMutateResult result = holder.setNode(DataType.NORMAL, builtNode, true);
|
||||
DataMutateResult result = target.setNode(DataType.NORMAL, builtNode, true);
|
||||
|
||||
if (result.wasSuccessful()) {
|
||||
Message.SETPERMISSION_SUCCESS.send(sender, node, value, holder.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
Message.SETPERMISSION_SUCCESS.send(sender, node, value, target.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
|
||||
LoggedAction.build().source(sender).target(holder)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("permission", "set", node, value, context)
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
StorageAssistant.save(holder, sender, plugin);
|
||||
StorageAssistant.save(target, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} else {
|
||||
Message.ALREADY_HASPERMISSION.send(sender, holder.getFormattedDisplayName(), node, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
Message.ALREADY_HASPERMISSION.send(sender, target.getFormattedDisplayName(), node, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, TabCompletions.permissions(plugin))
|
||||
.at(1, TabCompletions.booleans())
|
||||
|
@ -33,7 +33,7 @@ import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
@ -63,20 +63,20 @@ public class PermissionSetTemp extends GenericChildCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, holder)) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
String node = ArgumentParser.parseString(0, args);
|
||||
boolean value = ArgumentParser.parseBoolean(1, args);
|
||||
Duration duration = ArgumentParser.parseDuration(2, args);
|
||||
TemporaryNodeMergeStrategy modifier = ArgumentParser.parseTemporaryModifier(3, args).orElseGet(() -> plugin.getConfiguration().get(ConfigKeys.TEMPORARY_ADD_BEHAVIOUR));
|
||||
MutableContextSet context = ArgumentParser.parseContext(3, args, plugin);
|
||||
String node = args.get(0);
|
||||
boolean value = args.getBooleanOrInsert(1, true);
|
||||
Duration duration = args.getDuration(2);
|
||||
TemporaryNodeMergeStrategy modifier = args.getTemporaryModifierAndRemove(3).orElseGet(() -> plugin.getConfiguration().get(ConfigKeys.TEMPORARY_ADD_BEHAVIOUR));
|
||||
MutableContextSet context = args.getContextOrDefault(3, plugin);
|
||||
|
||||
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, holder, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, target, context) ||
|
||||
ArgumentPermissions.checkArguments(plugin, sender, permission, node)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
@ -91,26 +91,26 @@ public class PermissionSetTemp extends GenericChildCommand {
|
||||
}
|
||||
}
|
||||
|
||||
DataMutateResult.WithMergedNode result = holder.setNode(DataType.NORMAL, builtNode, modifier);
|
||||
DataMutateResult.WithMergedNode result = target.setNode(DataType.NORMAL, builtNode, modifier);
|
||||
|
||||
if (result.getResult().wasSuccessful()) {
|
||||
duration = result.getMergedNode().getExpiryDuration();
|
||||
Message.SETPERMISSION_TEMP_SUCCESS.send(sender, node, value, holder.getFormattedDisplayName(), DurationFormatter.LONG.format(duration), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
Message.SETPERMISSION_TEMP_SUCCESS.send(sender, node, value, target.getFormattedDisplayName(), DurationFormatter.LONG.format(duration), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
|
||||
LoggedAction.build().source(sender).target(holder)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("permission", "settemp", node, value, duration, context)
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
StorageAssistant.save(holder, sender, plugin);
|
||||
StorageAssistant.save(target, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} else {
|
||||
Message.ALREADY_HAS_TEMP_PERMISSION.send(sender, holder.getFormattedDisplayName(), node, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
Message.ALREADY_HAS_TEMP_PERMISSION.send(sender, target.getFormattedDisplayName(), node, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, TabCompletions.permissions(plugin))
|
||||
.at(1, TabCompletions.booleans())
|
||||
|
@ -33,7 +33,7 @@ import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -59,17 +59,17 @@ public class PermissionUnset extends GenericChildCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, holder)) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
String node = ArgumentParser.parseString(0, args);
|
||||
MutableContextSet context = ArgumentParser.parseContext(1, args, plugin);
|
||||
String node = args.get(0);
|
||||
MutableContextSet context = args.getContextOrDefault(1, plugin);
|
||||
|
||||
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, holder, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, target, context) ||
|
||||
ArgumentPermissions.checkArguments(plugin, sender, permission, node)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
@ -84,25 +84,25 @@ public class PermissionUnset extends GenericChildCommand {
|
||||
}
|
||||
}
|
||||
|
||||
DataMutateResult result = holder.unsetNode(DataType.NORMAL, builtNode);
|
||||
DataMutateResult result = target.unsetNode(DataType.NORMAL, builtNode);
|
||||
|
||||
if (result.wasSuccessful()) {
|
||||
Message.UNSETPERMISSION_SUCCESS.send(sender, node, holder.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
Message.UNSETPERMISSION_SUCCESS.send(sender, node, target.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
|
||||
LoggedAction.build().source(sender).target(holder)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("permission", "unset", node, context)
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
StorageAssistant.save(holder, sender, plugin);
|
||||
StorageAssistant.save(target, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} else {
|
||||
Message.DOES_NOT_HAVE_PERMISSION.send(sender, holder.getFormattedDisplayName(), node, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
Message.DOES_NOT_HAVE_PERMISSION.send(sender, target.getFormattedDisplayName(), node, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, TabCompletions.permissions(plugin))
|
||||
.from(1, TabCompletions.contexts(plugin))
|
||||
|
@ -33,7 +33,7 @@ import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -61,18 +61,19 @@ public class PermissionUnsetTemp extends GenericChildCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, holder)) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
String node = ArgumentParser.parseString(0, args);
|
||||
Duration duration = ArgumentParser.parseDurationOrElse(1, args, null);
|
||||
MutableContextSet context = ArgumentParser.parseContext(duration == null ? 1 : 2, args, plugin);
|
||||
String node = args.get(0);
|
||||
Duration duration = args.getDurationOrDefault(1, null);
|
||||
int fromIndex = duration == null ? 1 : 2;
|
||||
MutableContextSet context = args.getContextOrDefault(fromIndex, plugin);
|
||||
|
||||
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, holder, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, target, context) ||
|
||||
ArgumentPermissions.checkArguments(plugin, sender, permission, node)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
@ -87,7 +88,7 @@ public class PermissionUnsetTemp extends GenericChildCommand {
|
||||
}
|
||||
}
|
||||
|
||||
DataMutateResult.WithMergedNode result = holder.unsetNode(DataType.NORMAL, builtNode, duration);
|
||||
DataMutateResult.WithMergedNode result = target.unsetNode(DataType.NORMAL, builtNode, duration);
|
||||
if (result.getResult().wasSuccessful()) {
|
||||
Node mergedNode = result.getMergedNode();
|
||||
//noinspection ConstantConditions
|
||||
@ -95,33 +96,33 @@ public class PermissionUnsetTemp extends GenericChildCommand {
|
||||
Message.UNSET_TEMP_PERMISSION_SUBTRACT_SUCCESS.send(sender,
|
||||
mergedNode.getKey(),
|
||||
mergedNode.getValue(),
|
||||
holder.getFormattedDisplayName(),
|
||||
target.getFormattedDisplayName(),
|
||||
DurationFormatter.LONG.format(mergedNode.getExpiryDuration()),
|
||||
MessageUtils.contextSetToString(plugin.getLocaleManager(), context),
|
||||
DurationFormatter.LONG.format(duration)
|
||||
);
|
||||
|
||||
LoggedAction.build().source(sender).target(holder)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("permission", "unsettemp", node, duration, context)
|
||||
.build().submit(plugin, sender);
|
||||
} else {
|
||||
Message.UNSET_TEMP_PERMISSION_SUCCESS.send(sender, node, holder.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
Message.UNSET_TEMP_PERMISSION_SUCCESS.send(sender, node, target.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
|
||||
LoggedAction.build().source(sender).target(holder)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("permission", "unsettemp", node, context)
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
StorageAssistant.save(holder, sender, plugin);
|
||||
StorageAssistant.save(target, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} else {
|
||||
Message.DOES_NOT_HAVE_TEMP_PERMISSION.send(sender, holder.getFormattedDisplayName(), node, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
Message.DOES_NOT_HAVE_TEMP_PERMISSION.send(sender, target.getFormattedDisplayName(), node, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, TabCompletions.permissions(plugin))
|
||||
.from(1, TabCompletions.contexts(plugin))
|
||||
|
@ -29,6 +29,7 @@ import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SingleCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
@ -40,15 +41,13 @@ import me.lucko.luckperms.common.util.Predicates;
|
||||
import net.luckperms.api.actionlog.Action;
|
||||
import net.luckperms.api.event.cause.CreationCause;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CreateGroup extends SingleCommand {
|
||||
public CreateGroup(LocaleManager locale) {
|
||||
super(CommandSpec.CREATE_GROUP.localize(locale), "CreateGroup", CommandPermission.CREATE_GROUP, Predicates.not(1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, ArgumentList args, String label) {
|
||||
if (args.isEmpty()) {
|
||||
sendUsage(sender, label);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
|
@ -31,6 +31,7 @@ import me.lucko.luckperms.common.command.abstraction.SingleCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
@ -51,7 +52,7 @@ public class DeleteGroup extends SingleCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, ArgumentList args, String label) {
|
||||
if (args.isEmpty()) {
|
||||
sendUsage(sender, label);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
@ -89,7 +90,7 @@ public class DeleteGroup extends SingleCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, TabCompletions.groups(plugin))
|
||||
.complete(args);
|
||||
|
@ -30,6 +30,7 @@ import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
@ -43,16 +44,14 @@ import me.lucko.luckperms.common.util.Predicates;
|
||||
import net.luckperms.api.event.cause.CreationCause;
|
||||
import net.luckperms.api.model.data.DataType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroupClone extends ChildCommand<Group> {
|
||||
public GroupClone(LocaleManager locale) {
|
||||
super(CommandSpec.GROUP_CLONE.localize(locale), "clone", CommandPermission.GROUP_CLONE, Predicates.not(1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
if (ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), group)) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group target, ArgumentList args, String label) {
|
||||
if (ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), target)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
@ -74,12 +73,12 @@ public class GroupClone extends ChildCommand<Group> {
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
newGroup.setNodes(DataType.NORMAL, group.normalData().immutable());
|
||||
newGroup.setNodes(DataType.NORMAL, target.normalData().immutable());
|
||||
|
||||
Message.CLONE_SUCCESS.send(sender, group.getName(), newGroup.getName());
|
||||
Message.CLONE_SUCCESS.send(sender, target.getName(), newGroup.getName());
|
||||
|
||||
LoggedAction.build().source(sender).target(newGroup)
|
||||
.description("clone", group.getName())
|
||||
.description("clone", target.getName())
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
StorageAssistant.save(newGroup, sender, plugin);
|
||||
|
@ -32,6 +32,7 @@ import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
@ -57,24 +58,24 @@ public class GroupInfo extends ChildCommand<Group> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
if (ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), group)) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group target, ArgumentList args, String label) {
|
||||
if (ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), target)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
Message.GROUP_INFO_GENERAL.send(sender,
|
||||
group.getName(),
|
||||
group.getPlainDisplayName(),
|
||||
group.getWeight().isPresent() ? group.getWeight().getAsInt() : "None"
|
||||
target.getName(),
|
||||
target.getPlainDisplayName(),
|
||||
target.getWeight().isPresent() ? target.getWeight().getAsInt() : "None"
|
||||
);
|
||||
|
||||
List<InheritanceNode> parents = group.normalData().inheritanceAsSortedSet().stream()
|
||||
List<InheritanceNode> parents = target.normalData().inheritanceAsSortedSet().stream()
|
||||
.filter(Node::getValue)
|
||||
.filter(n -> !n.hasExpiry())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<InheritanceNode> tempParents = group.normalData().inheritanceAsSortedSet().stream()
|
||||
List<InheritanceNode> tempParents = target.normalData().inheritanceAsSortedSet().stream()
|
||||
.filter(Node::getValue)
|
||||
.filter(Node::hasExpiry)
|
||||
.collect(Collectors.toList());
|
||||
@ -100,7 +101,7 @@ public class GroupInfo extends ChildCommand<Group> {
|
||||
String suffix = "&bNone";
|
||||
String meta = "&bNone";
|
||||
|
||||
MetaCache data = group.getCachedData().getMetaData(queryOptions);
|
||||
MetaCache data = target.getCachedData().getMetaData(queryOptions);
|
||||
String prefixValue = data.getPrefix(MetaCheckEvent.Origin.INTERNAL);
|
||||
if (prefixValue != null) {
|
||||
prefix = "&f\"" + prefixValue + "&f\"";
|
||||
|
@ -32,7 +32,7 @@ import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -76,24 +76,24 @@ public class GroupListMembers extends ChildCommand<Group> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
if (ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), group)) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group target, ArgumentList args, String label) {
|
||||
if (ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), target)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
InheritanceNode node = Inheritance.builder(group.getName()).build();
|
||||
InheritanceNode node = Inheritance.builder(target.getName()).build();
|
||||
ConstraintNodeMatcher<InheritanceNode> matcher = StandardNodeMatchers.key(node);
|
||||
int page = ArgumentParser.parseIntOrElse(0, args, 1);
|
||||
int page = args.getIntOrDefault(0, 1);
|
||||
|
||||
Message.SEARCH_SEARCHING_MEMBERS.send(sender, group.getName());
|
||||
Message.SEARCH_SEARCHING_MEMBERS.send(sender, target.getName());
|
||||
|
||||
List<NodeEntry<UUID, InheritanceNode>> matchedUsers = plugin.getStorage().searchUserNodes(matcher).join().stream()
|
||||
.filter(n -> n.getNode().getValue())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// special handling for default group
|
||||
if (group.getName().equals(GroupManager.DEFAULT_GROUP_NAME)) {
|
||||
if (target.getName().equals(GroupManager.DEFAULT_GROUP_NAME)) {
|
||||
// include all non-saved online players in the results
|
||||
for (User user : plugin.getUserManager().getAll().values()) {
|
||||
if (!plugin.getUserManager().shouldSave(user)) {
|
||||
|
@ -29,6 +29,7 @@ import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
@ -43,15 +44,13 @@ import net.luckperms.api.event.cause.CreationCause;
|
||||
import net.luckperms.api.event.cause.DeletionCause;
|
||||
import net.luckperms.api.model.data.DataType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroupRename extends ChildCommand<Group> {
|
||||
public GroupRename(LocaleManager locale) {
|
||||
super(CommandSpec.GROUP_RENAME.localize(locale), "rename", CommandPermission.GROUP_RENAME, Predicates.not(1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group target, ArgumentList args, String label) {
|
||||
String newGroupName = args.get(0).toLowerCase();
|
||||
if (!DataConstraints.GROUP_NAME_TEST.test(newGroupName)) {
|
||||
Message.GROUP_INVALID_ENTRY.send(sender, newGroupName);
|
||||
@ -73,18 +72,18 @@ public class GroupRename extends ChildCommand<Group> {
|
||||
}
|
||||
|
||||
try {
|
||||
plugin.getStorage().deleteGroup(group, DeletionCause.COMMAND).get();
|
||||
plugin.getStorage().deleteGroup(target, DeletionCause.COMMAND).get();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Message.DELETE_ERROR.send(sender, group.getFormattedDisplayName());
|
||||
Message.DELETE_ERROR.send(sender, target.getFormattedDisplayName());
|
||||
return CommandResult.FAILURE;
|
||||
}
|
||||
|
||||
newGroup.setNodes(DataType.NORMAL, group.normalData().immutable());
|
||||
newGroup.setNodes(DataType.NORMAL, target.normalData().immutable());
|
||||
|
||||
Message.RENAME_SUCCESS.send(sender, group.getName(), newGroup.getName());
|
||||
Message.RENAME_SUCCESS.send(sender, target.getName(), newGroup.getName());
|
||||
|
||||
LoggedAction.build().source(sender).target(group)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("rename", newGroup.getName())
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
|
@ -33,7 +33,7 @@ import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -58,65 +58,65 @@ public class GroupSetDisplayName extends ChildCommand<Group> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, getPermission().get(), group)) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group target, ArgumentList args, String label) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, getPermission().get(), target)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
String name = ArgumentParser.parseString(0, args);
|
||||
ImmutableContextSet context = ArgumentParser.parseContext(1, args, plugin).immutableCopy();
|
||||
String name = args.get(0);
|
||||
ImmutableContextSet context = args.getContextOrDefault(1, plugin).immutableCopy();
|
||||
|
||||
String previousName = group.normalData().immutable().get(context).stream()
|
||||
String previousName = target.normalData().immutable().get(context).stream()
|
||||
.filter(NodeType.DISPLAY_NAME::matches)
|
||||
.map(NodeType.DISPLAY_NAME::cast)
|
||||
.findFirst()
|
||||
.map(DisplayNameNode::getDisplayName)
|
||||
.orElse(null);
|
||||
|
||||
if (previousName == null && name.equals(group.getName())) {
|
||||
Message.GROUP_SET_DISPLAY_NAME_DOESNT_HAVE.send(sender, group.getName());
|
||||
if (previousName == null && name.equals(target.getName())) {
|
||||
Message.GROUP_SET_DISPLAY_NAME_DOESNT_HAVE.send(sender, target.getName());
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
if (name.equals(previousName)) {
|
||||
Message.GROUP_SET_DISPLAY_NAME_ALREADY_HAS.send(sender, group.getName(), name);
|
||||
Message.GROUP_SET_DISPLAY_NAME_ALREADY_HAS.send(sender, target.getName(), name);
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
Group existing = plugin.getGroupManager().getByDisplayName(name);
|
||||
if (existing != null && !group.equals(existing)) {
|
||||
if (existing != null && !target.equals(existing)) {
|
||||
Message.GROUP_SET_DISPLAY_NAME_ALREADY_IN_USE.send(sender, name, existing.getName());
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
group.removeIf(DataType.NORMAL, context, NodeType.DISPLAY_NAME::matches, false);
|
||||
target.removeIf(DataType.NORMAL, context, NodeType.DISPLAY_NAME::matches, false);
|
||||
|
||||
if (name.equals(group.getName())) {
|
||||
Message.GROUP_SET_DISPLAY_NAME_REMOVED.send(sender, group.getName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
if (name.equals(target.getName())) {
|
||||
Message.GROUP_SET_DISPLAY_NAME_REMOVED.send(sender, target.getName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
|
||||
LoggedAction.build().source(sender).target(group)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("setdisplayname", name, context)
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
StorageAssistant.save(group, sender, plugin);
|
||||
StorageAssistant.save(target, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
group.setNode(DataType.NORMAL, DisplayName.builder(name).withContext(context).build(), true);
|
||||
target.setNode(DataType.NORMAL, DisplayName.builder(name).withContext(context).build(), true);
|
||||
|
||||
Message.GROUP_SET_DISPLAY_NAME.send(sender, name, group.getName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
Message.GROUP_SET_DISPLAY_NAME.send(sender, name, target.getName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
|
||||
LoggedAction.build().source(sender).target(group)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("setdisplayname", name, context)
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
StorageAssistant.save(group, sender, plugin);
|
||||
StorageAssistant.save(target, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.from(1, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
|
@ -31,7 +31,7 @@ import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
@ -45,32 +45,30 @@ import me.lucko.luckperms.common.util.Predicates;
|
||||
import net.luckperms.api.model.data.DataType;
|
||||
import net.luckperms.api.node.NodeType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroupSetWeight extends ChildCommand<Group> {
|
||||
public GroupSetWeight(LocaleManager locale) {
|
||||
super(CommandSpec.GROUP_SETWEIGHT.localize(locale), "setweight", CommandPermission.GROUP_SET_WEIGHT, Predicates.not(1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, getPermission().get(), group)) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group target, ArgumentList args, String label) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, getPermission().get(), target)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
int weight = ArgumentParser.parsePriority(0, args);
|
||||
int weight = args.getPriority(0);
|
||||
|
||||
group.removeIf(DataType.NORMAL, null, NodeType.WEIGHT::matches, false);
|
||||
group.setNode(DataType.NORMAL, Weight.builder(weight).build(), true);
|
||||
target.removeIf(DataType.NORMAL, null, NodeType.WEIGHT::matches, false);
|
||||
target.setNode(DataType.NORMAL, Weight.builder(weight).build(), true);
|
||||
|
||||
Message.GROUP_SET_WEIGHT.send(sender, weight, group.getFormattedDisplayName());
|
||||
Message.GROUP_SET_WEIGHT.send(sender, weight, target.getFormattedDisplayName());
|
||||
|
||||
LoggedAction.build().source(sender).target(group)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("setweight", weight)
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
StorageAssistant.save(group, sender, plugin);
|
||||
StorageAssistant.save(target, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ package me.lucko.luckperms.common.commands.group;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SingleCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
@ -51,7 +52,7 @@ public class ListGroups extends SingleCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, ArgumentList args, String label) {
|
||||
|
||||
try {
|
||||
plugin.getStorage().loadAllGroups().get();
|
||||
|
@ -32,7 +32,7 @@ import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
@ -53,7 +53,7 @@ public class LogGroupHistory extends ChildCommand<Log> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Log log, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Log log, ArgumentList args, String label) {
|
||||
String group = args.get(0).toLowerCase();
|
||||
if (!DataConstraints.GROUP_NAME_TEST.test(group)) {
|
||||
Message.GROUP_INVALID_ENTRY.send(sender, group);
|
||||
@ -62,7 +62,7 @@ public class LogGroupHistory extends ChildCommand<Log> {
|
||||
|
||||
Paginated<LoggedAction> content = new Paginated<>(log.getGroupHistory(group));
|
||||
|
||||
int page = ArgumentParser.parseIntOrElse(1, args, Integer.MIN_VALUE);
|
||||
int page = args.getIntOrDefault(1, Integer.MIN_VALUE);
|
||||
if (page != Integer.MIN_VALUE) {
|
||||
return showLog(page, sender, content);
|
||||
} else {
|
||||
@ -105,7 +105,7 @@ public class LogGroupHistory extends ChildCommand<Log> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, TabCompletions.groups(plugin))
|
||||
.complete(args);
|
||||
|
@ -29,6 +29,7 @@ import me.lucko.luckperms.common.actionlog.Log;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.context.contextset.ImmutableContextSetImpl;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
@ -42,7 +43,6 @@ import me.lucko.luckperms.common.util.Predicates;
|
||||
import net.luckperms.api.model.data.DataType;
|
||||
import net.luckperms.api.node.Node;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -86,7 +86,7 @@ public class LogNotify extends ChildCommand<Log> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Log log, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Log log, ArgumentList args, String label) {
|
||||
if (sender.isConsole()) {
|
||||
Message.LOG_NOTIFY_CONSOLE.send(sender);
|
||||
return CommandResult.SUCCESS;
|
||||
|
@ -30,7 +30,7 @@ import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
@ -51,27 +51,27 @@ public class LogRecent extends ChildCommand<Log> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Log log, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Log log, ArgumentList args, String label) {
|
||||
if (args.isEmpty()) {
|
||||
// No page or user
|
||||
Paginated<LoggedAction> content = new Paginated<>(log.getContent());
|
||||
return showLog(content.getMaxPages(ENTRIES_PER_PAGE), false, sender, content);
|
||||
}
|
||||
|
||||
int page = ArgumentParser.parseIntOrElse(0, args, Integer.MIN_VALUE);
|
||||
int page = args.getIntOrDefault(0, Integer.MIN_VALUE);
|
||||
if (page != Integer.MIN_VALUE) {
|
||||
Paginated<LoggedAction> content = new Paginated<>(log.getContent());
|
||||
return showLog(page, false, sender, content);
|
||||
}
|
||||
|
||||
// User and possibly page
|
||||
UUID uuid = ArgumentParser.parseUserTarget(0, args, plugin, sender);
|
||||
UUID uuid = args.getUserTarget(0, plugin, sender);
|
||||
if (uuid == null) {
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
Paginated<LoggedAction> content = new Paginated<>(log.getContent(uuid));
|
||||
page = ArgumentParser.parseIntOrElse(1, args, Integer.MIN_VALUE);
|
||||
page = args.getIntOrDefault(1, Integer.MIN_VALUE);
|
||||
if (page != Integer.MIN_VALUE) {
|
||||
return showLog(page, true, sender, content);
|
||||
} else {
|
||||
|
@ -30,6 +30,7 @@ import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
@ -49,7 +50,7 @@ public class LogSearch extends ChildCommand<Log> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Log log, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Log log, ArgumentList args, String label) {
|
||||
int page = Integer.MIN_VALUE;
|
||||
if (args.size() > 1) {
|
||||
try {
|
||||
|
@ -32,7 +32,7 @@ import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
@ -53,7 +53,7 @@ public class LogTrackHistory extends ChildCommand<Log> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Log log, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Log log, ArgumentList args, String label) {
|
||||
String track = args.get(0).toLowerCase();
|
||||
if (!DataConstraints.TRACK_NAME_TEST.test(track)) {
|
||||
Message.TRACK_INVALID_ENTRY.send(sender, track);
|
||||
@ -62,7 +62,7 @@ public class LogTrackHistory extends ChildCommand<Log> {
|
||||
|
||||
Paginated<LoggedAction> content = new Paginated<>(log.getTrackHistory(track));
|
||||
|
||||
int page = ArgumentParser.parseIntOrElse(1, args, Integer.MIN_VALUE);
|
||||
int page = args.getIntOrDefault(1, Integer.MIN_VALUE);
|
||||
if (page != Integer.MIN_VALUE) {
|
||||
return showLog(page, sender, content);
|
||||
} else {
|
||||
@ -105,7 +105,7 @@ public class LogTrackHistory extends ChildCommand<Log> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, TabCompletions.tracks(plugin))
|
||||
.complete(args);
|
||||
|
@ -30,7 +30,7 @@ import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
@ -51,15 +51,15 @@ public class LogUserHistory extends ChildCommand<Log> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Log log, List<String> args, String label) {
|
||||
UUID uuid = ArgumentParser.parseUserTarget(0, args, plugin, sender);
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Log log, ArgumentList args, String label) {
|
||||
UUID uuid = args.getUserTarget(0, plugin, sender);
|
||||
if (uuid == null) {
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
Paginated<LoggedAction> content = new Paginated<>(log.getUserHistory(uuid));
|
||||
|
||||
int page = ArgumentParser.parseIntOrElse(1, args, Integer.MIN_VALUE);
|
||||
int page = args.getIntOrDefault(1, Integer.MIN_VALUE);
|
||||
if (page != Integer.MIN_VALUE) {
|
||||
return showLog(page, sender, content);
|
||||
} else {
|
||||
|
@ -32,6 +32,7 @@ import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.Command;
|
||||
import me.lucko.luckperms.common.command.abstraction.ParentCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
@ -76,7 +77,7 @@ public class MigrationParentCommand extends ParentCommand<Object, Void> {
|
||||
this.display = false;
|
||||
this.commands.add(new ChildCommand<Object>(CommandSpec.MIGRATION_COMMAND.localize(getSpec().getLocaleManager()), "No available plugins to migrate from", CommandPermission.MIGRATION, Predicates.alwaysFalse()) {
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, ArgumentList args, String label) {
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
});
|
||||
|
@ -34,6 +34,7 @@ import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SingleCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.context.contextset.ImmutableContextSetImpl;
|
||||
@ -74,7 +75,7 @@ public class ApplyEditsCommand extends SingleCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, ArgumentList args, String label) {
|
||||
String code = args.get(0);
|
||||
|
||||
if (code.isEmpty()) {
|
||||
|
@ -41,7 +41,8 @@ import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SingleCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentException;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
@ -50,7 +51,6 @@ import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.util.CaffeineFactory;
|
||||
import me.lucko.luckperms.common.util.Predicates;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@ -62,7 +62,7 @@ public class BulkUpdateCommand extends SingleCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, ArgumentList args, String label) throws CommandException {
|
||||
if (!sender.isConsole()) {
|
||||
Message.BULK_UPDATE_MUST_USE_CONSOLE.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
@ -91,7 +91,7 @@ public class BulkUpdateCommand extends SingleCommand {
|
||||
}
|
||||
|
||||
if (args.size() < 2) {
|
||||
throw new ArgumentParser.DetailedUsageException();
|
||||
throw new ArgumentException.DetailedUsage();
|
||||
}
|
||||
|
||||
BulkUpdateBuilder bulkUpdateBuilder = BulkUpdateBuilder.create();
|
||||
@ -110,20 +110,20 @@ public class BulkUpdateCommand extends SingleCommand {
|
||||
break;
|
||||
case "update":
|
||||
if (args.size() < 2) {
|
||||
throw new ArgumentParser.DetailedUsageException();
|
||||
throw new ArgumentException.DetailedUsage();
|
||||
}
|
||||
|
||||
String field = args.remove(0);
|
||||
QueryField queryField = QueryField.of(field);
|
||||
if (queryField == null) {
|
||||
throw new ArgumentParser.DetailedUsageException();
|
||||
throw new ArgumentException.DetailedUsage();
|
||||
}
|
||||
String value = args.remove(0);
|
||||
|
||||
bulkUpdateBuilder.action(UpdateAction.of(queryField, value));
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentParser.DetailedUsageException();
|
||||
throw new ArgumentException.DetailedUsage();
|
||||
}
|
||||
|
||||
for (String constraint : args) {
|
||||
|
@ -31,6 +31,7 @@ import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.CompletionSupplier;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
@ -53,7 +54,7 @@ public class CheckCommand extends SingleCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, ArgumentList args, String label) {
|
||||
String target = args.get(0);
|
||||
String permission = args.get(1);
|
||||
|
||||
@ -76,7 +77,7 @@ public class CheckCommand extends SingleCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, CompletionSupplier.startsWith(() -> plugin.getBootstrap().getPlayerList().stream()))
|
||||
.at(1, TabCompletions.permissions(plugin))
|
||||
|
@ -31,7 +31,7 @@ import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SingleCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.context.contextset.ImmutableContextSetImpl;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
@ -67,12 +67,12 @@ public class EditorCommand extends SingleCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, ArgumentList args, String label) {
|
||||
Type type = Type.ALL;
|
||||
String filter = null;
|
||||
|
||||
// attempt to parse type
|
||||
String arg0 = ArgumentParser.parseStringOrElse(0, args, null);
|
||||
String arg0 = args.getOrDefault(0, null);
|
||||
if (arg0 != null) {
|
||||
try {
|
||||
type = Type.valueOf(arg0.toUpperCase());
|
||||
@ -82,7 +82,7 @@ public class EditorCommand extends SingleCommand {
|
||||
}
|
||||
|
||||
if (filter == null) {
|
||||
filter = ArgumentParser.parseStringOrElse(1, args, null);
|
||||
filter = args.getOrDefault(1, null);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,7 @@ import me.lucko.luckperms.common.backup.Exporter;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SingleCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
@ -39,7 +40,6 @@ import me.lucko.luckperms.common.util.Predicates;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class ExportCommand extends SingleCommand {
|
||||
@ -50,7 +50,7 @@ public class ExportCommand extends SingleCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, ArgumentList args, String label) {
|
||||
if (this.running.get()) {
|
||||
Message.EXPORT_ALREADY_RUNNING.send(sender);
|
||||
return CommandResult.STATE_ERROR;
|
||||
|
@ -31,6 +31,7 @@ import me.lucko.luckperms.common.backup.Importer;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SingleCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
@ -45,7 +46,6 @@ import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
@ -57,7 +57,7 @@ public class ImportCommand extends SingleCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, ArgumentList args, String label) {
|
||||
if (this.running.get()) {
|
||||
Message.IMPORT_ALREADY_RUNNING.send(sender);
|
||||
return CommandResult.STATE_ERROR;
|
||||
|
@ -28,6 +28,7 @@ package me.lucko.luckperms.common.commands.misc;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SingleCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
@ -45,7 +46,6 @@ import net.luckperms.api.extension.Extension;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class InfoCommand extends SingleCommand {
|
||||
@ -54,7 +54,7 @@ public class InfoCommand extends SingleCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, ArgumentList args, String label) {
|
||||
Map<String, String> storageMeta = plugin.getStorage().getMeta();
|
||||
|
||||
Message.INFO_HEADER.send(sender,
|
||||
|
@ -28,6 +28,7 @@ package me.lucko.luckperms.common.commands.misc;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SingleCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
@ -36,7 +37,6 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.util.Predicates;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class NetworkSyncCommand extends SingleCommand {
|
||||
@ -45,7 +45,7 @@ public class NetworkSyncCommand extends SingleCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, ArgumentList args, String label) {
|
||||
Message.UPDATE_TASK_REQUEST.send(sender);
|
||||
plugin.getSyncTaskBuffer().request().join();
|
||||
Message.UPDATE_TASK_COMPLETE_NETWORK.send(sender);
|
||||
|
@ -28,6 +28,7 @@ package me.lucko.luckperms.common.commands.misc;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SingleCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
@ -35,15 +36,13 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.util.Predicates;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ReloadConfigCommand extends SingleCommand {
|
||||
public ReloadConfigCommand(LocaleManager locale) {
|
||||
super(CommandSpec.RELOAD_CONFIG.localize(locale), "ReloadConfig", CommandPermission.RELOAD_CONFIG, Predicates.alwaysFalse());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, ArgumentList args, String label) {
|
||||
plugin.getConfiguration().reload();
|
||||
Message.RELOAD_CONFIG_SUCCESS.send(sender);
|
||||
return CommandResult.SUCCESS;
|
||||
|
@ -36,7 +36,7 @@ import me.lucko.luckperms.common.command.abstraction.SingleCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -75,7 +75,7 @@ public class SearchCommand extends SingleCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, ArgumentList args, String label) {
|
||||
Comparison comparison = StandardComparison.parseComparison(args.get(0));
|
||||
if (comparison == null) {
|
||||
comparison = StandardComparison.EQUAL;
|
||||
@ -83,7 +83,7 @@ public class SearchCommand extends SingleCommand {
|
||||
}
|
||||
|
||||
ConstraintNodeMatcher<Node> matcher = StandardNodeMatchers.of(Constraint.of(comparison, args.get(1)));
|
||||
int page = ArgumentParser.parseIntOrElse(2, args, 1);
|
||||
int page = args.getIntOrDefault(2, 1);
|
||||
|
||||
Message.SEARCH_SEARCHING.send(sender, matcher);
|
||||
|
||||
@ -122,7 +122,7 @@ public class SearchCommand extends SingleCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, TabCompletions.permissions(plugin))
|
||||
.complete(args);
|
||||
|
@ -28,6 +28,7 @@ package me.lucko.luckperms.common.commands.misc;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SingleCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
@ -35,15 +36,13 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.util.Predicates;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SyncCommand extends SingleCommand {
|
||||
public SyncCommand(LocaleManager locale) {
|
||||
super(CommandSpec.SYNC.localize(locale), "Sync", CommandPermission.SYNC, Predicates.alwaysFalse());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, ArgumentList args, String label) {
|
||||
Message.UPDATE_TASK_REQUEST.send(sender);
|
||||
plugin.getSyncTaskBuffer().request().join();
|
||||
Message.UPDATE_TASK_COMPLETE.send(sender);
|
||||
|
@ -29,6 +29,7 @@ import me.lucko.luckperms.common.cacheddata.type.PermissionCache;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SingleCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
@ -48,7 +49,6 @@ import net.kyori.text.event.HoverEvent;
|
||||
import net.kyori.text.format.TextColor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class TreeCommand extends SingleCommand {
|
||||
@ -57,7 +57,7 @@ public class TreeCommand extends SingleCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, ArgumentList args, String label) {
|
||||
String selection = ".";
|
||||
String player = null;
|
||||
|
||||
|
@ -30,6 +30,7 @@ import me.lucko.luckperms.common.command.abstraction.SingleCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.CompletionSupplier;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
@ -59,7 +60,7 @@ public class VerboseCommand extends SingleCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, ArgumentList args, String label) {
|
||||
if (args.isEmpty()) {
|
||||
sendUsage(sender, label);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
@ -195,7 +196,7 @@ public class VerboseCommand extends SingleCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, CompletionSupplier.startsWith("on", "record", "off", "upload", "command"))
|
||||
.complete(args);
|
||||
|
@ -29,6 +29,7 @@ import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SingleCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
@ -40,15 +41,13 @@ import me.lucko.luckperms.common.util.Predicates;
|
||||
import net.luckperms.api.actionlog.Action;
|
||||
import net.luckperms.api.event.cause.CreationCause;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CreateTrack extends SingleCommand {
|
||||
public CreateTrack(LocaleManager locale) {
|
||||
super(CommandSpec.CREATE_TRACK.localize(locale), "CreateTrack", CommandPermission.CREATE_TRACK, Predicates.not(1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, ArgumentList args, String label) {
|
||||
if (args.isEmpty()) {
|
||||
sendUsage(sender, label);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
|
@ -31,6 +31,7 @@ import me.lucko.luckperms.common.command.abstraction.SingleCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
@ -50,7 +51,7 @@ public class DeleteTrack extends SingleCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, ArgumentList args, String label) {
|
||||
if (args.isEmpty()) {
|
||||
sendUsage(sender, label);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
@ -81,7 +82,7 @@ public class DeleteTrack extends SingleCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, TabCompletions.tracks(plugin))
|
||||
.complete(args);
|
||||
|
@ -28,6 +28,7 @@ package me.lucko.luckperms.common.commands.track;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SingleCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
@ -36,7 +37,6 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.util.Predicates;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ListTracks extends SingleCommand {
|
||||
@ -45,7 +45,7 @@ public class ListTracks extends SingleCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, ArgumentList args, String label) {
|
||||
try {
|
||||
plugin.getStorage().loadAllTracks().get();
|
||||
} catch (Exception e) {
|
||||
|
@ -31,6 +31,7 @@ import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -53,7 +54,7 @@ public class TrackAppend extends ChildCommand<Track> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track target, ArgumentList args, String label) {
|
||||
String groupName = args.get(0).toLowerCase();
|
||||
if (!DataConstraints.GROUP_NAME_TEST.test(groupName)) {
|
||||
sendDetailedUsage(sender, label);
|
||||
@ -65,28 +66,28 @@ public class TrackAppend extends ChildCommand<Track> {
|
||||
return CommandResult.LOADING_ERROR;
|
||||
}
|
||||
|
||||
DataMutateResult result = track.appendGroup(group);
|
||||
DataMutateResult result = target.appendGroup(group);
|
||||
|
||||
if (result.wasSuccessful()) {
|
||||
Message.TRACK_APPEND_SUCCESS.send(sender, group.getName(), track.getName());
|
||||
if (track.getGroups().size() > 1) {
|
||||
Message.BLANK.send(sender, MessageUtils.listToArrowSep(track.getGroups(), group.getName()));
|
||||
Message.TRACK_APPEND_SUCCESS.send(sender, group.getName(), target.getName());
|
||||
if (target.getGroups().size() > 1) {
|
||||
Message.BLANK.send(sender, MessageUtils.listToArrowSep(target.getGroups(), group.getName()));
|
||||
}
|
||||
|
||||
LoggedAction.build().source(sender).target(track)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("append", group.getName())
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
StorageAssistant.save(track, sender, plugin);
|
||||
StorageAssistant.save(target, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} else {
|
||||
Message.TRACK_ALREADY_CONTAINS.send(sender, track.getName(), group.getName());
|
||||
Message.TRACK_ALREADY_CONTAINS.send(sender, target.getName(), group.getName());
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, TabCompletions.groups(plugin))
|
||||
.complete(args);
|
||||
|
@ -29,6 +29,7 @@ import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
@ -38,23 +39,21 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.util.Predicates;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TrackClear extends ChildCommand<Track> {
|
||||
public TrackClear(LocaleManager locale) {
|
||||
super(CommandSpec.TRACK_CLEAR.localize(locale), "clear", CommandPermission.TRACK_CLEAR, Predicates.alwaysFalse());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) {
|
||||
track.clearGroups();
|
||||
Message.TRACK_CLEAR.send(sender, track.getName());
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track target, ArgumentList args, String label) {
|
||||
target.clearGroups();
|
||||
Message.TRACK_CLEAR.send(sender, target.getName());
|
||||
|
||||
LoggedAction.build().source(sender).target(track)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("clear")
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
StorageAssistant.save(track, sender, plugin);
|
||||
StorageAssistant.save(target, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
@ -41,15 +42,13 @@ import me.lucko.luckperms.common.util.Predicates;
|
||||
|
||||
import net.luckperms.api.event.cause.CreationCause;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TrackClone extends ChildCommand<Track> {
|
||||
public TrackClone(LocaleManager locale) {
|
||||
super(CommandSpec.TRACK_CLONE.localize(locale), "clone", CommandPermission.TRACK_CLONE, Predicates.not(1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track target, ArgumentList args, String label) {
|
||||
String newTrackName = args.get(0).toLowerCase();
|
||||
if (!DataConstraints.TRACK_NAME_TEST.test(newTrackName)) {
|
||||
Message.TRACK_INVALID_ENTRY.send(sender, newTrackName);
|
||||
@ -62,11 +61,11 @@ public class TrackClone extends ChildCommand<Track> {
|
||||
return CommandResult.LOADING_ERROR;
|
||||
}
|
||||
|
||||
newTrack.setGroups(track.getGroups());
|
||||
newTrack.setGroups(target.getGroups());
|
||||
|
||||
Message.CLONE_SUCCESS.send(sender, track.getName(), newTrack.getName());
|
||||
Message.CLONE_SUCCESS.send(sender, target.getName(), newTrack.getName());
|
||||
|
||||
LoggedAction.build().source(sender).target(track)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("clone", newTrack.getName())
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
|
@ -28,6 +28,7 @@ package me.lucko.luckperms.common.commands.track;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
@ -37,16 +38,14 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.util.Predicates;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TrackInfo extends ChildCommand<Track> {
|
||||
public TrackInfo(LocaleManager locale) {
|
||||
super(CommandSpec.TRACK_INFO.localize(locale), "info", CommandPermission.TRACK_INFO, Predicates.alwaysFalse());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) {
|
||||
Message.TRACK_INFO.send(sender, track.getName(), MessageUtils.listToArrowSep(track.getGroups()));
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track target, ArgumentList args, String label) {
|
||||
Message.TRACK_INFO.send(sender, target.getName(), MessageUtils.listToArrowSep(target.getGroups()));
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -53,7 +54,7 @@ public class TrackInsert extends ChildCommand<Track> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track target, ArgumentList args, String label) {
|
||||
String groupName = args.get(0).toLowerCase();
|
||||
if (!DataConstraints.GROUP_NAME_TEST.test(groupName)) {
|
||||
sendDetailedUsage(sender, label);
|
||||
@ -74,22 +75,22 @@ public class TrackInsert extends ChildCommand<Track> {
|
||||
}
|
||||
|
||||
try {
|
||||
DataMutateResult result = track.insertGroup(group, pos - 1);
|
||||
DataMutateResult result = target.insertGroup(group, pos - 1);
|
||||
|
||||
if (result.wasSuccessful()) {
|
||||
Message.TRACK_INSERT_SUCCESS.send(sender, group.getName(), track.getName(), pos);
|
||||
if (track.getGroups().size() > 1) {
|
||||
Message.BLANK.send(sender, MessageUtils.listToArrowSep(track.getGroups(), group.getName()));
|
||||
Message.TRACK_INSERT_SUCCESS.send(sender, group.getName(), target.getName(), pos);
|
||||
if (target.getGroups().size() > 1) {
|
||||
Message.BLANK.send(sender, MessageUtils.listToArrowSep(target.getGroups(), group.getName()));
|
||||
}
|
||||
|
||||
LoggedAction.build().source(sender).target(track)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("insert", group.getName(), pos)
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
StorageAssistant.save(track, sender, plugin);
|
||||
StorageAssistant.save(target, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} else {
|
||||
Message.TRACK_ALREADY_CONTAINS.send(sender, track.getName(), group.getName());
|
||||
Message.TRACK_ALREADY_CONTAINS.send(sender, target.getName(), group.getName());
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
@ -100,7 +101,7 @@ public class TrackInsert extends ChildCommand<Track> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, TabCompletions.groups(plugin))
|
||||
.complete(args);
|
||||
|
@ -31,6 +31,7 @@ import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -52,35 +53,35 @@ public class TrackRemove extends ChildCommand<Track> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track target, ArgumentList args, String label) {
|
||||
String groupName = args.get(0).toLowerCase();
|
||||
if (!DataConstraints.GROUP_NAME_TEST.test(groupName)) {
|
||||
sendDetailedUsage(sender, label);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
DataMutateResult result = track.removeGroup(groupName);
|
||||
DataMutateResult result = target.removeGroup(groupName);
|
||||
|
||||
if (result.wasSuccessful()) {
|
||||
Message.TRACK_REMOVE_SUCCESS.send(sender, groupName, track.getName());
|
||||
if (track.getGroups().size() > 1) {
|
||||
Message.BLANK.send(sender, MessageUtils.listToArrowSep(track.getGroups()));
|
||||
Message.TRACK_REMOVE_SUCCESS.send(sender, groupName, target.getName());
|
||||
if (target.getGroups().size() > 1) {
|
||||
Message.BLANK.send(sender, MessageUtils.listToArrowSep(target.getGroups()));
|
||||
}
|
||||
|
||||
LoggedAction.build().source(sender).target(track)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("remove", groupName)
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
StorageAssistant.save(track, sender, plugin);
|
||||
StorageAssistant.save(target, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} else {
|
||||
Message.TRACK_DOES_NOT_CONTAIN.send(sender, track.getName(), groupName);
|
||||
Message.TRACK_DOES_NOT_CONTAIN.send(sender, target.getName(), groupName);
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, TabCompletions.groups(plugin))
|
||||
.complete(args);
|
||||
|
@ -29,6 +29,7 @@ import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
@ -42,15 +43,13 @@ import me.lucko.luckperms.common.util.Predicates;
|
||||
import net.luckperms.api.event.cause.CreationCause;
|
||||
import net.luckperms.api.event.cause.DeletionCause;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TrackRename extends ChildCommand<Track> {
|
||||
public TrackRename(LocaleManager locale) {
|
||||
super(CommandSpec.TRACK_RENAME.localize(locale), "rename", CommandPermission.TRACK_RENAME, Predicates.not(1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track target, ArgumentList args, String label) {
|
||||
String newTrackName = args.get(0).toLowerCase();
|
||||
if (!DataConstraints.TRACK_NAME_TEST.test(newTrackName)) {
|
||||
Message.TRACK_INVALID_ENTRY.send(sender, newTrackName);
|
||||
@ -72,18 +71,18 @@ public class TrackRename extends ChildCommand<Track> {
|
||||
}
|
||||
|
||||
try {
|
||||
plugin.getStorage().deleteTrack(track, DeletionCause.COMMAND).get();
|
||||
plugin.getStorage().deleteTrack(target, DeletionCause.COMMAND).get();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Message.DELETE_ERROR.send(sender, track.getName());
|
||||
Message.DELETE_ERROR.send(sender, target.getName());
|
||||
return CommandResult.FAILURE;
|
||||
}
|
||||
|
||||
newTrack.setGroups(track.getGroups());
|
||||
newTrack.setGroups(target.getGroups());
|
||||
|
||||
Message.RENAME_SUCCESS.send(sender, track.getName(), newTrack.getName());
|
||||
Message.RENAME_SUCCESS.send(sender, target.getName(), newTrack.getName());
|
||||
|
||||
LoggedAction.build().source(sender).target(track)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("rename", newTrack.getName())
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
|
@ -30,7 +30,7 @@ import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
@ -42,7 +42,6 @@ import me.lucko.luckperms.common.util.Predicates;
|
||||
|
||||
import net.luckperms.api.model.data.DataType;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class UserClone extends ChildCommand<User> {
|
||||
@ -51,13 +50,13 @@ public class UserClone extends ChildCommand<User> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
if (ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), user)) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User target, ArgumentList args, String label) {
|
||||
if (ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), target)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
UUID uuid = ArgumentParser.parseUserTarget(0, args, plugin, sender);
|
||||
UUID uuid = args.getUserTarget(0, plugin, sender);
|
||||
if (uuid == null) {
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
@ -73,12 +72,12 @@ public class UserClone extends ChildCommand<User> {
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
otherUser.setNodes(DataType.NORMAL, user.normalData().immutable());
|
||||
otherUser.setNodes(DataType.NORMAL, target.normalData().immutable());
|
||||
|
||||
Message.CLONE_SUCCESS.send(sender, user.getFormattedDisplayName(), otherUser.getFormattedDisplayName());
|
||||
Message.CLONE_SUCCESS.send(sender, target.getFormattedDisplayName(), otherUser.getFormattedDisplayName());
|
||||
|
||||
LoggedAction.build().source(sender).target(otherUser)
|
||||
.description("clone", user.getUsername())
|
||||
.description("clone", target.getUsername())
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
StorageAssistant.save(otherUser, sender, plugin);
|
||||
|
@ -33,7 +33,7 @@ import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -59,8 +59,8 @@ public class UserDemote extends ChildCommand<User> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, getPermission().get(), user)) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User target, ArgumentList args, String label) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, getPermission().get(), target)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
@ -97,7 +97,7 @@ public class UserDemote extends ChildCommand<User> {
|
||||
}
|
||||
|
||||
boolean dontShowTrackProgress = args.remove("-s");
|
||||
MutableContextSet context = ArgumentParser.parseContext(1, args, plugin);
|
||||
MutableContextSet context = args.getContextOrDefault(1, plugin);
|
||||
|
||||
if (ArgumentPermissions.checkContext(plugin, sender, getPermission().get(), context)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
@ -108,13 +108,13 @@ public class UserDemote extends ChildCommand<User> {
|
||||
!ArgumentPermissions.checkArguments(plugin, sender, getPermission().get(), track.getName(), s) &&
|
||||
!ArgumentPermissions.checkGroup(plugin, sender, s, context);
|
||||
|
||||
DemotionResult result = track.demote(user, context, previousGroupPermissionChecker, sender, removeFromFirst);
|
||||
DemotionResult result = track.demote(target, context, previousGroupPermissionChecker, sender, removeFromFirst);
|
||||
switch (result.getStatus()) {
|
||||
case NOT_ON_TRACK:
|
||||
Message.USER_TRACK_ERROR_NOT_CONTAIN_GROUP.send(sender, user.getFormattedDisplayName(), track.getName());
|
||||
Message.USER_TRACK_ERROR_NOT_CONTAIN_GROUP.send(sender, target.getFormattedDisplayName(), track.getName());
|
||||
return CommandResult.FAILURE;
|
||||
case AMBIGUOUS_CALL:
|
||||
Message.TRACK_AMBIGUOUS_CALL.send(sender, user.getFormattedDisplayName());
|
||||
Message.TRACK_AMBIGUOUS_CALL.send(sender, target.getFormattedDisplayName());
|
||||
return CommandResult.FAILURE;
|
||||
case UNDEFINED_FAILURE:
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
@ -125,17 +125,17 @@ public class UserDemote extends ChildCommand<User> {
|
||||
|
||||
case REMOVED_FROM_FIRST_GROUP: {
|
||||
if (!removeFromFirst && !result.getGroupFrom().isPresent()) {
|
||||
Message.USER_DEMOTE_ENDOFTRACK_NOT_REMOVED.send(sender, track.getName(), user.getFormattedDisplayName());
|
||||
Message.USER_DEMOTE_ENDOFTRACK_NOT_REMOVED.send(sender, track.getName(), target.getFormattedDisplayName());
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
Message.USER_DEMOTE_ENDOFTRACK.send(sender, track.getName(), user.getFormattedDisplayName(), result.getGroupFrom().get());
|
||||
Message.USER_DEMOTE_ENDOFTRACK.send(sender, track.getName(), target.getFormattedDisplayName(), result.getGroupFrom().get());
|
||||
|
||||
LoggedAction.build().source(sender).target(user)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("demote", track.getName(), context)
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
StorageAssistant.save(user, sender, plugin);
|
||||
StorageAssistant.save(target, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
@ -143,16 +143,16 @@ public class UserDemote extends ChildCommand<User> {
|
||||
String groupFrom = result.getGroupFrom().get();
|
||||
String groupTo = result.getGroupTo().get();
|
||||
|
||||
Message.USER_DEMOTE_SUCCESS.send(sender, user.getFormattedDisplayName(), track.getName(), groupFrom, groupTo, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
Message.USER_DEMOTE_SUCCESS.send(sender, target.getFormattedDisplayName(), track.getName(), groupFrom, groupTo, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
if (!dontShowTrackProgress) {
|
||||
Message.BLANK.send(sender, MessageUtils.listToArrowSep(track.getGroups(), groupTo, groupFrom, true));
|
||||
}
|
||||
|
||||
LoggedAction.build().source(sender).target(user)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("demote", track.getName(), context)
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
StorageAssistant.save(user, sender, plugin);
|
||||
StorageAssistant.save(target, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
@ -162,7 +162,7 @@ public class UserDemote extends ChildCommand<User> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, TabCompletions.tracks(plugin))
|
||||
.from(1, TabCompletions.contexts(plugin))
|
||||
|
@ -32,6 +32,7 @@ import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
@ -58,26 +59,26 @@ public class UserInfo extends ChildCommand<User> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
if (ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), user)) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User target, ArgumentList args, String label) {
|
||||
if (ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), target)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
Message status = plugin.getBootstrap().isPlayerOnline(user.getUniqueId()) ? Message.PLAYER_ONLINE : Message.PLAYER_OFFLINE;
|
||||
Message status = plugin.getBootstrap().isPlayerOnline(target.getUniqueId()) ? Message.PLAYER_ONLINE : Message.PLAYER_OFFLINE;
|
||||
Message.USER_INFO_GENERAL.send(sender,
|
||||
user.getUsername().orElse("Unknown"),
|
||||
user.getUniqueId(),
|
||||
user.getUniqueId().version() == 4 ? "&2mojang" : "&8offline",
|
||||
target.getUsername().orElse("Unknown"),
|
||||
target.getUniqueId(),
|
||||
target.getUniqueId().version() == 4 ? "&2mojang" : "&8offline",
|
||||
status.asString(plugin.getLocaleManager())
|
||||
);
|
||||
|
||||
List<InheritanceNode> parents = user.normalData().inheritanceAsSortedSet().stream()
|
||||
List<InheritanceNode> parents = target.normalData().inheritanceAsSortedSet().stream()
|
||||
.filter(Node::getValue)
|
||||
.filter(n -> !n.hasExpiry())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<InheritanceNode> tempParents = user.normalData().inheritanceAsSortedSet().stream()
|
||||
List<InheritanceNode> tempParents = target.normalData().inheritanceAsSortedSet().stream()
|
||||
.filter(Node::getValue)
|
||||
.filter(Node::hasExpiry)
|
||||
.collect(Collectors.toList());
|
||||
@ -97,7 +98,7 @@ public class UserInfo extends ChildCommand<User> {
|
||||
}
|
||||
}
|
||||
|
||||
QueryOptions queryOptions = plugin.getQueryOptionsForUser(user).orElse(null);
|
||||
QueryOptions queryOptions = plugin.getQueryOptionsForUser(target).orElse(null);
|
||||
boolean active = true;
|
||||
|
||||
if (queryOptions == null) {
|
||||
@ -117,7 +118,7 @@ public class UserInfo extends ChildCommand<User> {
|
||||
.collect(Collectors.joining(" "));
|
||||
}
|
||||
|
||||
MetaCache data = user.getCachedData().getMetaData(queryOptions);
|
||||
MetaCache data = target.getCachedData().getMetaData(queryOptions);
|
||||
String prefixValue = data.getPrefix(MetaCheckEvent.Origin.INTERNAL);
|
||||
if (prefixValue != null) {
|
||||
prefix = "&f\"" + prefixValue + "&f\"";
|
||||
@ -126,7 +127,7 @@ public class UserInfo extends ChildCommand<User> {
|
||||
if (sussexValue != null) {
|
||||
suffix = "&f\"" + sussexValue + "&f\"";
|
||||
}
|
||||
String primaryGroup = user.getCachedData().getMetaData(queryOptions).getPrimaryGroup(MetaCheckEvent.Origin.INTERNAL);
|
||||
String primaryGroup = target.getCachedData().getMetaData(queryOptions).getPrimaryGroup(MetaCheckEvent.Origin.INTERNAL);
|
||||
|
||||
Map<String, List<String>> metaMap = data.getMeta(MetaCheckEvent.Origin.INTERNAL);
|
||||
if (!metaMap.isEmpty()) {
|
||||
|
@ -33,7 +33,7 @@ import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -59,8 +59,8 @@ public class UserPromote extends ChildCommand<User> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, getPermission().get(), user)) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User target, ArgumentList args, String label) throws CommandException {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, getPermission().get(), target)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
@ -97,7 +97,7 @@ public class UserPromote extends ChildCommand<User> {
|
||||
}
|
||||
|
||||
boolean dontShowTrackProgress = args.remove("-s");
|
||||
MutableContextSet context = ArgumentParser.parseContext(1, args, plugin);
|
||||
MutableContextSet context = args.getContextOrDefault(1, plugin);
|
||||
|
||||
if (ArgumentPermissions.checkContext(plugin, sender, getPermission().get(), context)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
@ -108,7 +108,7 @@ public class UserPromote extends ChildCommand<User> {
|
||||
!ArgumentPermissions.checkArguments(plugin, sender, getPermission().get(), track.getName(), s) &&
|
||||
!ArgumentPermissions.checkGroup(plugin, sender, s, context);
|
||||
|
||||
PromotionResult result = track.promote(user, context, nextGroupPermissionChecker, sender, addToFirst);
|
||||
PromotionResult result = track.promote(target, context, nextGroupPermissionChecker, sender, addToFirst);
|
||||
switch (result.getStatus()) {
|
||||
case MALFORMED_TRACK:
|
||||
Message.USER_PROMOTE_ERROR_MALFORMED.send(sender, result.getGroupTo().get());
|
||||
@ -117,25 +117,25 @@ public class UserPromote extends ChildCommand<User> {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
case AMBIGUOUS_CALL:
|
||||
Message.TRACK_AMBIGUOUS_CALL.send(sender, user.getFormattedDisplayName());
|
||||
Message.TRACK_AMBIGUOUS_CALL.send(sender, target.getFormattedDisplayName());
|
||||
return CommandResult.FAILURE;
|
||||
case END_OF_TRACK:
|
||||
Message.USER_PROMOTE_ERROR_ENDOFTRACK.send(sender, track.getName(), user.getFormattedDisplayName());
|
||||
Message.USER_PROMOTE_ERROR_ENDOFTRACK.send(sender, track.getName(), target.getFormattedDisplayName());
|
||||
return CommandResult.STATE_ERROR;
|
||||
|
||||
case ADDED_TO_FIRST_GROUP: {
|
||||
if (!addToFirst && !result.getGroupTo().isPresent()) {
|
||||
Message.USER_PROMOTE_NOT_ON_TRACK.send(sender, track.getName(), user.getFormattedDisplayName());
|
||||
Message.USER_PROMOTE_NOT_ON_TRACK.send(sender, track.getName(), target.getFormattedDisplayName());
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
Message.USER_TRACK_ADDED_TO_FIRST.send(sender, user.getFormattedDisplayName(), result.getGroupTo().get(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
Message.USER_TRACK_ADDED_TO_FIRST.send(sender, target.getFormattedDisplayName(), result.getGroupTo().get(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
|
||||
LoggedAction.build().source(sender).target(user)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("promote", track.getName(), context)
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
StorageAssistant.save(user, sender, plugin);
|
||||
StorageAssistant.save(target, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
@ -143,16 +143,16 @@ public class UserPromote extends ChildCommand<User> {
|
||||
String groupFrom = result.getGroupFrom().get();
|
||||
String groupTo = result.getGroupTo().get();
|
||||
|
||||
Message.USER_PROMOTE_SUCCESS.send(sender, user.getFormattedDisplayName(), track.getName(), groupFrom, groupTo, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
Message.USER_PROMOTE_SUCCESS.send(sender, target.getFormattedDisplayName(), track.getName(), groupFrom, groupTo, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
if (!dontShowTrackProgress) {
|
||||
Message.BLANK.send(sender, MessageUtils.listToArrowSep(track.getGroups(), groupFrom, groupTo, false));
|
||||
}
|
||||
|
||||
LoggedAction.build().source(sender).target(user)
|
||||
LoggedAction.build().source(sender).target(target)
|
||||
.description("promote", track.getName(), context)
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
StorageAssistant.save(user, sender, plugin);
|
||||
StorageAssistant.save(target, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
@ -162,7 +162,7 @@ public class UserPromote extends ChildCommand<User> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, ArgumentList args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, TabCompletions.tracks(plugin))
|
||||
.from(1, TabCompletions.contexts(plugin))
|
||||
|
@ -30,7 +30,6 @@ import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import me.lucko.luckperms.common.cacheddata.type.SimpleMetaValueSelector;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.config.generic.KeyedConfiguration;
|
||||
import me.lucko.luckperms.common.config.generic.key.ConfigKey;
|
||||
import me.lucko.luckperms.common.config.generic.key.SimpleConfigKey;
|
||||
@ -164,12 +163,15 @@ public final class ConfigKeys {
|
||||
* Controls how temporary add commands should behave
|
||||
*/
|
||||
public static final ConfigKey<TemporaryNodeMergeStrategy> TEMPORARY_ADD_BEHAVIOUR = key(c -> {
|
||||
String option = c.getString("temporary-add-behaviour", "deny").toLowerCase();
|
||||
if (!option.equals("deny") && !option.equals("replace") && !option.equals("accumulate")) {
|
||||
option = "deny";
|
||||
String value = c.getString("temporary-add-behaviour", "deny");
|
||||
switch (value.toLowerCase()) {
|
||||
case "accumulate":
|
||||
return TemporaryNodeMergeStrategy.ADD_NEW_DURATION_TO_EXISTING;
|
||||
case "replace":
|
||||
return TemporaryNodeMergeStrategy.REPLACE_EXISTING_IF_DURATION_LONGER;
|
||||
default:
|
||||
return TemporaryNodeMergeStrategy.NONE;
|
||||
}
|
||||
|
||||
return ArgumentParser.parseTemporaryModifier(option);
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -28,7 +28,7 @@ package me.lucko.luckperms.sponge.commands;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
@ -39,16 +39,14 @@ import me.lucko.luckperms.sponge.service.model.LPSubjectData;
|
||||
|
||||
import net.luckperms.api.context.ImmutableContextSet;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class OptionClear extends ChildCommand<LPSubjectData> {
|
||||
public OptionClear(LocaleManager locale) {
|
||||
super(CommandSpec.SPONGE_OPTION_CLEAR.localize(locale), "clear", CommandPermission.SPONGE_OPTION_CLEAR, Predicates.alwaysFalse());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) {
|
||||
ImmutableContextSet contextSet = ArgumentParser.parseContextSponge(0, args);
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, ArgumentList args, String label) {
|
||||
ImmutableContextSet contextSet = args.getContextOrEmpty(0);
|
||||
if (contextSet.isEmpty()) {
|
||||
subjectData.clearOptions();
|
||||
Message.BLANK.send(sender, "&aCleared options matching contexts &bANY&a.");
|
||||
|
@ -30,7 +30,7 @@ import com.google.common.collect.ImmutableMap;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
@ -41,7 +41,6 @@ import me.lucko.luckperms.sponge.service.model.LPSubjectData;
|
||||
|
||||
import net.luckperms.api.context.ImmutableContextSet;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class OptionInfo extends ChildCommand<LPSubjectData> {
|
||||
@ -50,8 +49,8 @@ public class OptionInfo extends ChildCommand<LPSubjectData> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) {
|
||||
ImmutableContextSet contextSet = ArgumentParser.parseContextSponge(0, args);
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, ArgumentList args, String label) {
|
||||
ImmutableContextSet contextSet = args.getContextOrEmpty(0);
|
||||
if (contextSet.isEmpty()) {
|
||||
Message.BLANK.send(sender, "&aShowing options matching contexts &bANY&a.");
|
||||
Map<ImmutableContextSet, ImmutableMap<String, String>> options = subjectData.getAllOptions();
|
||||
|
@ -28,7 +28,7 @@ package me.lucko.luckperms.sponge.commands;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
@ -39,18 +39,16 @@ import me.lucko.luckperms.sponge.service.model.LPSubjectData;
|
||||
|
||||
import net.luckperms.api.context.ImmutableContextSet;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class OptionSet extends ChildCommand<LPSubjectData> {
|
||||
public OptionSet(LocaleManager locale) {
|
||||
super(CommandSpec.SPONGE_OPTION_SET.localize(locale), "set", CommandPermission.SPONGE_OPTION_SET, Predicates.inRange(0, 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, ArgumentList args, String label) {
|
||||
String key = args.get(0);
|
||||
String value = args.get(1);
|
||||
ImmutableContextSet contextSet = ArgumentParser.parseContextSponge(2, args);
|
||||
ImmutableContextSet contextSet = args.getContextOrEmpty(2);
|
||||
|
||||
if (subjectData.setOption(contextSet, key, value).join()) {
|
||||
Message.BLANK.send(sender, "&aSet &f\"" + key + "&f\"&a to &f\"" + value + "&f\"&a in context " + SpongeCommandUtils.contextToString(contextSet, plugin.getLocaleManager()));
|
||||
|
@ -28,7 +28,7 @@ package me.lucko.luckperms.sponge.commands;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
@ -39,17 +39,15 @@ import me.lucko.luckperms.sponge.service.model.LPSubjectData;
|
||||
|
||||
import net.luckperms.api.context.ImmutableContextSet;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class OptionUnset extends ChildCommand<LPSubjectData> {
|
||||
public OptionUnset(LocaleManager locale) {
|
||||
super(CommandSpec.SPONGE_OPTION_UNSET.localize(locale), "unset", CommandPermission.SPONGE_OPTION_UNSET, Predicates.is(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, ArgumentList args, String label) {
|
||||
String key = args.get(0);
|
||||
ImmutableContextSet contextSet = ArgumentParser.parseContextSponge(1, args);
|
||||
ImmutableContextSet contextSet = args.getContextOrEmpty(1);
|
||||
|
||||
if (subjectData.unsetOption(contextSet, key).join()) {
|
||||
Message.BLANK.send(sender, "&aUnset &f\"" + key + "&f\"&a in context " + SpongeCommandUtils.contextToString(contextSet, plugin.getLocaleManager()));
|
||||
|
@ -28,7 +28,7 @@ package me.lucko.luckperms.sponge.commands;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
@ -44,18 +44,16 @@ import net.luckperms.api.context.ImmutableContextSet;
|
||||
|
||||
import org.spongepowered.api.Sponge;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ParentAdd extends ChildCommand<LPSubjectData> {
|
||||
public ParentAdd(LocaleManager locale) {
|
||||
super(CommandSpec.SPONGE_PARENT_ADD.localize(locale), "add", CommandPermission.SPONGE_PARENT_ADD, Predicates.inRange(0, 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, ArgumentList args, String label) {
|
||||
String collection = args.get(0);
|
||||
String name = args.get(1);
|
||||
ImmutableContextSet contextSet = ArgumentParser.parseContextSponge(2, args);
|
||||
ImmutableContextSet contextSet = args.getContextOrEmpty(2);
|
||||
|
||||
LPPermissionService service = Sponge.getServiceManager().provideUnchecked(LPPermissionService.class);
|
||||
if (service.getLoadedCollections().keySet().stream().map(String::toLowerCase).noneMatch(s -> s.equalsIgnoreCase(collection))) {
|
||||
|
@ -28,7 +28,7 @@ package me.lucko.luckperms.sponge.commands;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
@ -39,16 +39,14 @@ import me.lucko.luckperms.sponge.service.model.LPSubjectData;
|
||||
|
||||
import net.luckperms.api.context.ImmutableContextSet;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ParentClear extends ChildCommand<LPSubjectData> {
|
||||
public ParentClear(LocaleManager locale) {
|
||||
super(CommandSpec.SPONGE_PARENT_CLEAR.localize(locale), "clear", CommandPermission.SPONGE_PARENT_CLEAR, Predicates.alwaysFalse());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) {
|
||||
ImmutableContextSet contextSet = ArgumentParser.parseContextSponge(0, args);
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, ArgumentList args, String label) {
|
||||
ImmutableContextSet contextSet = args.getContextOrEmpty(0);
|
||||
if (contextSet.isEmpty()) {
|
||||
subjectData.clearParents();
|
||||
Message.BLANK.send(sender, "&aCleared parents matching contexts &bANY&a.");
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user