Refactor commands

This commit is contained in:
Luck 2016-11-07 22:02:48 +00:00
parent 0c33b26fa9
commit 90f8dbe243
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
72 changed files with 1009 additions and 1282 deletions

View File

@ -26,6 +26,7 @@ import de.bananaco.bpermissions.api.*;
import me.lucko.luckperms.api.Logger;
import me.lucko.luckperms.api.MetaUtils;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.SubCommand;
@ -86,7 +87,7 @@ public class MigrationBPermissions extends SubCommand<Object> {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
final Logger log = plugin.getLog();
WorldManager worldManager = WorldManager.getInstance();

View File

@ -24,10 +24,7 @@ package me.lucko.luckperms.bukkit.migration;
import me.lucko.luckperms.api.Logger;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.constants.Constants;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.NodeFactory;
@ -53,7 +50,7 @@ public class MigrationGroupManager extends SubCommand<Object> {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
final Logger log = plugin.getLog();
if (!plugin.isPluginLoaded("GroupManager")) {
log.severe("GroupManager Migration: Error -> GroupManager is not loaded.");

View File

@ -26,10 +26,7 @@ import me.lucko.luckperms.api.Logger;
import me.lucko.luckperms.api.MetaUtils;
import me.lucko.luckperms.api.PlatformType;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.constants.Constants;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.data.LogEntry;
@ -57,7 +54,7 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
@SuppressWarnings("deprecation")
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
final Logger log = plugin.getLog();
if (!plugin.isPluginLoaded("PermissionsEx")) {
log.severe("PermissionsEx Migration: Error -> PermissionsEx is not loaded.");

View File

@ -30,10 +30,7 @@ import me.lucko.luckperms.api.Logger;
import me.lucko.luckperms.api.data.Callback;
import me.lucko.luckperms.bukkit.migration.utils.LPResultRunnable;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.constants.Constants;
import me.lucko.luckperms.common.core.PermissionHolder;
import me.lucko.luckperms.common.data.LogEntry;
@ -132,7 +129,7 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
try {
return run(plugin, args);
} catch (Throwable t) {

View File

@ -25,10 +25,7 @@ package me.lucko.luckperms.bukkit.migration;
import me.lucko.luckperms.api.Logger;
import me.lucko.luckperms.api.MetaUtils;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.constants.Constants;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.data.LogEntry;
@ -52,7 +49,7 @@ public class MigrationZPermissions extends SubCommand<Object> {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
final Logger log = plugin.getLog();
if (!plugin.isPluginLoaded("zPermissions")) {
log.severe("zPermissions Migration: Error -> zPermissions is not loaded.");

View File

@ -25,6 +25,7 @@ package me.lucko.luckperms.bungee.migration;
import me.lucko.luckperms.api.Logger;
import me.lucko.luckperms.api.MetaUtils;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.SubCommand;
@ -47,7 +48,7 @@ public class MigrationBungeePerms extends SubCommand<Object> {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
final Logger log = plugin.getLog();
BungeePerms bp = BungeePerms.getInstance();

View File

@ -0,0 +1,132 @@
/*
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
*
* 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.commands;
import lombok.AllArgsConstructor;
import lombok.Getter;
import me.lucko.luckperms.common.utils.ArgumentChecker;
import me.lucko.luckperms.common.utils.DateUtil;
import java.util.List;
import java.util.function.Function;
/**
* Utility class to help process arguments, and throw checked exceptions if the arguments are invalid.
*/
public class ArgumentUtils {
public static final Function<String, String> WRAPPER = s -> s.contains(" ") ? "\"" + s + "\"" : s;
public static String handleNodeWithoutCheck(int index, List<String> args) {
return args.get(index).replace("{SPACE}", " ");
}
public static String handleNode(int index, List<String> args) throws ArgumentException {
String node = args.get(index).replace("{SPACE}", " ");
if (ArgumentChecker.checkNode(node)) {
throw new DetailedUsageException();
}
if (node.toLowerCase().startsWith("group.")) {
throw new UseInheritException();
}
return node;
}
public static String handleName(int index, List<String> args) throws ArgumentException {
String groupName = args.get(index).toLowerCase();
if (ArgumentChecker.checkName(groupName)) {
throw new DetailedUsageException();
}
return groupName;
}
public static boolean handleBoolean(int index, List<String> args) throws ArgumentException {
String bool = args.get(index);
if (!bool.equalsIgnoreCase("true") && !bool.equalsIgnoreCase("false")) {
throw new DetailedUsageException();
}
return Boolean.parseBoolean(bool);
}
public static String handleServer(int index, List<String> args) throws ArgumentException {
if (args.size() > index) {
final String server = args.get(index).toLowerCase();
if (ArgumentChecker.checkServer(server)) {
throw new InvalidServerException();
}
return server;
}
return null;
}
public static long handleDuration(int index, List<String> args) throws ArgumentException {
long duration;
try {
duration = Long.parseLong(args.get(index));
} catch (NumberFormatException e) {
try {
duration = DateUtil.parseDateDiff(args.get(index), true);
} catch (DateUtil.IllegalDateException e1) {
throw new InvalidDateException(args.get(index));
}
}
if (DateUtil.shouldExpire(duration)) {
throw new PastDateException();
}
return duration;
}
public static String handleWorld(int index, List<String> args) {
return args.size() > index ? args.get(index).toLowerCase() : null;
}
public static int handlePriority(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 abstract class ArgumentException extends CommandException {}
public static class DetailedUsageException extends ArgumentException {}
public static class UseInheritException extends ArgumentException {}
public static class InvalidServerException extends ArgumentException {}
public static class PastDateException extends ArgumentException {}
@Getter
@AllArgsConstructor
public static class InvalidDateException extends ArgumentException {
private final String invalidDate;
}
@Getter
@AllArgsConstructor
public static class InvalidPriorityException extends ArgumentException {
private final String invalidPriority;
}
}

View File

@ -0,0 +1,30 @@
/*
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
*
* 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.commands;
/**
* Exception to be thrown if there is an error processing a command
*/
public class CommandException extends Exception {
}

View File

@ -0,0 +1,38 @@
/*
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
*
* 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.commands;
/**
* Utility used to help in commands that take arguments for different contexts
*/
public class ContextHelper {
public enum CommandContext {
NONE, SERVER, SERVER_AND_WORLD
}
public static CommandContext determine(String server, String world) {
return server == null ? CommandContext.NONE : (world == null ? CommandContext.SERVER : CommandContext.SERVER_AND_WORLD);
}
}

View File

@ -105,7 +105,12 @@ public abstract class MainCommand<T> {
final String name = args.get(0).toLowerCase();
T t = getTarget(name, plugin, sender);
if (t != null) {
CommandResult result = sub.execute(plugin, sender, t, strippedArgs, label);
CommandResult result;
try {
result = sub.execute(plugin, sender, t, strippedArgs, label);
} catch (CommandException e) {
result = handleException(e, sender, sub);
}
cleanup(t, plugin);
return result;
}
@ -113,6 +118,44 @@ public abstract class MainCommand<T> {
return CommandResult.LOADING_ERROR;
}
private static CommandResult handleException(CommandException e, Sender sender, SubCommand command) {
if (e instanceof ArgumentUtils.ArgumentException) {
if (e instanceof ArgumentUtils.DetailedUsageException) {
command.sendDetailedUsage(sender);
return CommandResult.INVALID_ARGS;
}
if (e instanceof ArgumentUtils.UseInheritException) {
Message.USE_INHERIT_COMMAND.send(sender);
return CommandResult.INVALID_ARGS;
}
if (e instanceof ArgumentUtils.InvalidServerException) {
Message.SERVER_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
if (e instanceof ArgumentUtils.PastDateException) {
Message.PAST_DATE_ERROR.send(sender);
return CommandResult.INVALID_ARGS;
}
if (e instanceof ArgumentUtils.InvalidDateException) {
Message.ILLEGAL_DATE_ERROR.send(sender, ((ArgumentUtils.InvalidDateException) e).getInvalidDate());
return CommandResult.INVALID_ARGS;
}
if (e instanceof ArgumentUtils.InvalidPriorityException) {
Message.META_INVALID_PRIORITY.send(sender, ((ArgumentUtils.InvalidPriorityException) e).getInvalidPriority());
return CommandResult.INVALID_ARGS;
}
}
// Not something we can catch.
e.printStackTrace();
return CommandResult.FAILURE;
}
/**
* Gets the object the command is acting upon, and runs the callback if successful
* @param target the name of the object to be looked up

View File

@ -76,7 +76,7 @@ public abstract class SubCommand<T> {
* @param args the stripped arguments given
* @param label the command label used
*/
public abstract CommandResult execute(LuckPermsPlugin plugin, Sender sender, T t, List<String> args, String label);
public abstract CommandResult execute(LuckPermsPlugin plugin, Sender sender, T t, List<String> args, String label) throws CommandException;
/**
* Returns a list of suggestions, which are empty by default. Sub classes that give tab complete suggestions override

View File

@ -23,10 +23,7 @@
package me.lucko.luckperms.common.commands.generic;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.Util;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.core.PermissionHolder;
import me.lucko.luckperms.common.utils.Predicates;
@ -48,7 +45,7 @@ public class SecondaryMainCommand<T extends PermissionHolder> extends SubCommand
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, T t, List<String> args, String label) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, T t, List<String> args, String label) throws CommandException {
if (args.size() == 0) {
sendUsageDetailed(sender, user, label);
return CommandResult.INVALID_ARGS;
@ -80,7 +77,51 @@ public class SecondaryMainCommand<T extends PermissionHolder> extends SubCommand
return CommandResult.INVALID_ARGS;
}
return sub.execute(plugin, sender, t, strippedArgs);
CommandResult result;
try {
result = sub.execute(plugin, sender, t, strippedArgs);
} catch (CommandException e) {
result = handleException(e, sender, sub);
}
return result;
}
private static CommandResult handleException(CommandException e, Sender sender, SecondarySubCommand command) {
if (e instanceof ArgumentUtils.ArgumentException) {
if (e instanceof ArgumentUtils.DetailedUsageException) {
command.sendDetailedUsage(sender);
return CommandResult.INVALID_ARGS;
}
if (e instanceof ArgumentUtils.UseInheritException) {
Message.USE_INHERIT_COMMAND.send(sender);
return CommandResult.INVALID_ARGS;
}
if (e instanceof ArgumentUtils.InvalidServerException) {
Message.SERVER_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
if (e instanceof ArgumentUtils.PastDateException) {
Message.PAST_DATE_ERROR.send(sender);
return CommandResult.INVALID_ARGS;
}
if (e instanceof ArgumentUtils.InvalidDateException) {
Message.ILLEGAL_DATE_ERROR.send(sender, ((ArgumentUtils.InvalidDateException) e).getInvalidDate());
return CommandResult.INVALID_ARGS;
}
if (e instanceof ArgumentUtils.InvalidPriorityException) {
Message.META_INVALID_PRIORITY.send(sender, ((ArgumentUtils.InvalidPriorityException) e).getInvalidPriority());
return CommandResult.INVALID_ARGS;
}
}
// Not something we can catch.
e.printStackTrace();
return CommandResult.FAILURE;
}
@Override

View File

@ -63,7 +63,7 @@ public abstract class SecondarySubCommand {
private final ImmutableList<Arg> args;
public abstract CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args);
public abstract CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) throws CommandException;
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return Collections.emptyList();

View File

@ -24,23 +24,22 @@ package me.lucko.luckperms.common.commands.generic.meta;
import me.lucko.luckperms.api.MetaUtils;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.commands.generic.SecondarySubCommand;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.PermissionHolder;
import me.lucko.luckperms.common.data.LogEntry;
import me.lucko.luckperms.common.utils.ArgumentChecker;
import me.lucko.luckperms.common.utils.Predicates;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import java.util.List;
import java.util.stream.Collectors;
public class MetaAddPrefix extends SecondarySubCommand {
public MetaAddPrefix() {
super("addprefix", "Adds a prefix", Permission.USER_META_ADDPREFIX, Permission.GROUP_META_ADDPREFIX, Predicates.notInRange(2, 4),
super("addprefix", "Adds a prefix", Permission.USER_META_ADDPREFIX, Permission.GROUP_META_ADDPREFIX,
Predicates.notInRange(2, 4),
Arg.list(
Arg.create("priority", true, "the priority to add the prefix at"),
Arg.create("prefix", true, "the prefix string"),
@ -51,51 +50,37 @@ public class MetaAddPrefix extends SecondarySubCommand {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
final String prefix = args.get(1).replace("{SPACE}", " ");
int priority;
try {
priority = Integer.parseInt(args.get(0));
} catch (NumberFormatException e) {
Message.META_INVALID_PRIORITY.send(sender, args.get(0));
return CommandResult.INVALID_ARGS;
}
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) throws CommandException {
int priority = ArgumentUtils.handlePriority(0, args);
String prefix = ArgumentUtils.handleNodeWithoutCheck(1, args);
String server = ArgumentUtils.handleServer(2, args);
String world = ArgumentUtils.handleWorld(3, args);
final String node = "prefix." + priority + "." + MetaUtils.escapeCharacters(prefix);
try {
if (args.size() >= 3) {
final String server = args.get(2).toLowerCase();
if (ArgumentChecker.checkServer(server)) {
Message.SERVER_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
if (args.size() == 3) {
switch (ContextHelper.determine(server, world)) {
case NONE:
holder.setPermission(node, true);
Message.ADDPREFIX_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority);
break;
case SERVER:
holder.setPermission(node, true, server);
Message.ADDPREFIX_SERVER_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority, server);
LogEntry.build().actor(sender).acted(holder)
.action("meta addprefix " + priority + " " + args.get(1) + " " + server)
.build().submit(plugin, sender);
} else {
final String world = args.get(3).toLowerCase();
break;
case SERVER_AND_WORLD:
holder.setPermission(node, true, server, world);
Message.ADDPREFIX_SERVER_WORLD_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority, server, world);
LogEntry.build().actor(sender).acted(holder)
.action("meta addprefix " + priority + " " + args.get(1) + " " + server + " " + world)
.build().submit(plugin, sender);
}
} else {
holder.setPermission(node, true);
Message.ADDPREFIX_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority);
LogEntry.build().actor(sender).acted(holder)
.action("meta addprefix " + priority + " " + args.get(1))
.build().submit(plugin, sender);
break;
}
LogEntry.build().actor(sender).acted(holder)
.action("meta addprefix " + args.stream().map(ArgumentUtils.WRAPPER).collect(Collectors.joining(" ")))
.build().submit(plugin, sender);
save(holder, sender, plugin);
return CommandResult.SUCCESS;
} catch (ObjectAlreadyHasException e) {
Message.ALREADY_HAS_PREFIX.send(sender, holder.getFriendlyName());
return CommandResult.STATE_ERROR;

View File

@ -24,23 +24,22 @@ package me.lucko.luckperms.common.commands.generic.meta;
import me.lucko.luckperms.api.MetaUtils;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.commands.generic.SecondarySubCommand;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.PermissionHolder;
import me.lucko.luckperms.common.data.LogEntry;
import me.lucko.luckperms.common.utils.ArgumentChecker;
import me.lucko.luckperms.common.utils.Predicates;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import java.util.List;
import java.util.stream.Collectors;
public class MetaAddSuffix extends SecondarySubCommand {
public MetaAddSuffix() {
super("addsuffix", "Adds a suffix", Permission.USER_META_ADDSUFFIX, Permission.GROUP_META_ADDSUFFIX, Predicates.notInRange(2, 4),
super("addsuffix", "Adds a suffix", Permission.USER_META_ADDSUFFIX, Permission.GROUP_META_ADDSUFFIX,
Predicates.notInRange(2, 4),
Arg.list(
Arg.create("priority", true, "the priority to add the suffix at"),
Arg.create("suffix", true, "the suffix string"),
@ -51,51 +50,37 @@ public class MetaAddSuffix extends SecondarySubCommand {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
final String suffix = args.get(1).replace("{SPACE}", " ");
int priority;
try {
priority = Integer.parseInt(args.get(0));
} catch (NumberFormatException e) {
Message.META_INVALID_PRIORITY.send(sender, args.get(0));
return CommandResult.INVALID_ARGS;
}
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) throws CommandException {
int priority = ArgumentUtils.handlePriority(0, args);
String suffix = ArgumentUtils.handleNodeWithoutCheck(1, args);
String server = ArgumentUtils.handleServer(2, args);
String world = ArgumentUtils.handleWorld(3, args);
final String node = "suffix." + priority + "." + MetaUtils.escapeCharacters(suffix);
try {
if (args.size() >= 3) {
final String server = args.get(2).toLowerCase();
if (ArgumentChecker.checkServer(server)) {
Message.SERVER_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
if (args.size() == 3) {
switch (ContextHelper.determine(server, world)) {
case NONE:
holder.setPermission(node, true);
Message.ADDSUFFIX_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority);
break;
case SERVER:
holder.setPermission(node, true, server);
Message.ADDSUFFIX_SERVER_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority, server);
LogEntry.build().actor(sender).acted(holder)
.action("meta addsuffix " + priority + " " + args.get(1) + " " + server)
.build().submit(plugin, sender);
} else {
final String world = args.get(3).toLowerCase();
break;
case SERVER_AND_WORLD:
holder.setPermission(node, true, server, world);
Message.ADDSUFFIX_SERVER_WORLD_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority, server, world);
LogEntry.build().actor(sender).acted(holder)
.action("meta addsuffix " + priority + " " + args.get(1) + " " + server + " " + world)
.build().submit(plugin, sender);
}
} else {
holder.setPermission(node, true);
Message.ADDSUFFIX_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority);
LogEntry.build().actor(sender).acted(holder)
.action("meta addsuffix " + priority + " " + args.get(1))
.build().submit(plugin, sender);
break;
}
LogEntry.build().actor(sender).acted(holder)
.action("meta addsuffix " + args.stream().map(ArgumentUtils.WRAPPER).collect(Collectors.joining(" ")))
.build().submit(plugin, sender);
save(holder, sender, plugin);
return CommandResult.SUCCESS;
} catch (ObjectAlreadyHasException e) {
Message.ALREADY_HAS_SUFFIX.send(sender, holder.getFriendlyName());
return CommandResult.STATE_ERROR;

View File

@ -24,24 +24,23 @@ package me.lucko.luckperms.common.commands.generic.meta;
import me.lucko.luckperms.api.MetaUtils;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.commands.generic.SecondarySubCommand;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.PermissionHolder;
import me.lucko.luckperms.common.data.LogEntry;
import me.lucko.luckperms.common.utils.ArgumentChecker;
import me.lucko.luckperms.common.utils.DateUtil;
import me.lucko.luckperms.common.utils.Predicates;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import java.util.List;
import java.util.stream.Collectors;
public class MetaAddTempPrefix extends SecondarySubCommand {
public MetaAddTempPrefix() {
super("addtempprefix", "Adds a prefix temporarily", Permission.USER_META_ADDTEMP_PREFIX, Permission.GROUP_META_ADDTEMP_PREFIX, Predicates.notInRange(3, 5),
super("addtempprefix", "Adds a prefix temporarily", Permission.USER_META_ADDTEMP_PREFIX,
Permission.GROUP_META_ADDTEMP_PREFIX, Predicates.notInRange(3, 5),
Arg.list(
Arg.create("priority", true, "the priority to add the prefix at"),
Arg.create("prefix", true, "the prefix string"),
@ -53,68 +52,44 @@ public class MetaAddTempPrefix extends SecondarySubCommand {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
final String prefix = args.get(1).replace("{SPACE}", " ");
int priority;
try {
priority = Integer.parseInt(args.get(0));
} catch (NumberFormatException e) {
Message.META_INVALID_PRIORITY.send(sender, args.get(0));
return CommandResult.INVALID_ARGS;
}
long duration;
try {
duration = Long.parseLong(args.get(2));
} catch (NumberFormatException e) {
try {
duration = DateUtil.parseDateDiff(args.get(2), true);
} catch (DateUtil.IllegalDateException e1) {
Message.ILLEGAL_DATE_ERROR.send(sender, args.get(2));
return CommandResult.INVALID_ARGS;
}
}
if (DateUtil.shouldExpire(duration)) {
Message.PAST_DATE_ERROR.send(sender);
return CommandResult.INVALID_ARGS;
}
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) throws CommandException {
int priority = ArgumentUtils.handlePriority(0, args);
String prefix = ArgumentUtils.handleNodeWithoutCheck(1, args);
long duration = ArgumentUtils.handleDuration(2, args);
String server = ArgumentUtils.handleServer(3, args);
String world = ArgumentUtils.handleWorld(4, args);
final String node = "prefix." + priority + "." + MetaUtils.escapeCharacters(prefix);
try {
if (args.size() >= 4) {
final String server = args.get(3).toLowerCase();
if (ArgumentChecker.checkServer(server)) {
Message.SERVER_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
if (args.size() == 4) {
switch (ContextHelper.determine(server, world)) {
case NONE:
holder.setPermission(node, true, duration);
Message.ADD_TEMP_PREFIX_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority,
DateUtil.formatDateDiff(duration)
);
break;
case SERVER:
holder.setPermission(node, true, server, duration);
Message.ADD_TEMP_PREFIX_SERVER_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority, server, DateUtil.formatDateDiff(duration));
LogEntry.build().actor(sender).acted(holder)
.action("meta addtempprefix " + priority + " " + args.get(1) + " " + duration + " " + server)
.build().submit(plugin, sender);
} else {
final String world = args.get(4).toLowerCase();
Message.ADD_TEMP_PREFIX_SERVER_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority,
server, DateUtil.formatDateDiff(duration)
);
break;
case SERVER_AND_WORLD:
holder.setPermission(node, true, server, world, duration);
Message.ADD_TEMP_PREFIX_SERVER_WORLD_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority, server, world, DateUtil.formatDateDiff(duration));
LogEntry.build().actor(sender).acted(holder)
.action("meta addtempprefix " + priority + " " + args.get(1) + " " + duration + " " + server + " " + world)
.build().submit(plugin, sender);
}
} else {
holder.setPermission(node, true, duration);
Message.ADD_TEMP_PREFIX_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority, DateUtil.formatDateDiff(duration));
LogEntry.build().actor(sender).acted(holder)
.action("meta addtempprefix " + priority + " " + args.get(1) + " " + duration)
.build().submit(plugin, sender);
Message.ADD_TEMP_PREFIX_SERVER_WORLD_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority,
server, world, DateUtil.formatDateDiff(duration)
);
break;
}
LogEntry.build().actor(sender).acted(holder)
.action("meta addtempprefix " + args.stream().map(ArgumentUtils.WRAPPER).collect(Collectors.joining(" ")))
.build().submit(plugin, sender);
save(holder, sender, plugin);
return CommandResult.SUCCESS;
} catch (ObjectAlreadyHasException e) {
Message.ALREADY_HAS_PREFIX.send(sender, holder.getFriendlyName());
return CommandResult.STATE_ERROR;

View File

@ -24,24 +24,23 @@ package me.lucko.luckperms.common.commands.generic.meta;
import me.lucko.luckperms.api.MetaUtils;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.commands.generic.SecondarySubCommand;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.PermissionHolder;
import me.lucko.luckperms.common.data.LogEntry;
import me.lucko.luckperms.common.utils.ArgumentChecker;
import me.lucko.luckperms.common.utils.DateUtil;
import me.lucko.luckperms.common.utils.Predicates;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import java.util.List;
import java.util.stream.Collectors;
public class MetaAddTempSuffix extends SecondarySubCommand {
public MetaAddTempSuffix() {
super("addtempsuffix", "Adds a suffix temporarily", Permission.USER_META_ADDTEMP_SUFFIX, Permission.GROUP_META_ADDTEMP_SUFFIX, Predicates.notInRange(3, 5),
super("addtempsuffix", "Adds a suffix temporarily", Permission.USER_META_ADDTEMP_SUFFIX,
Permission.GROUP_META_ADDTEMP_SUFFIX, Predicates.notInRange(3, 5),
Arg.list(
Arg.create("priority", true, "the priority to add the suffix at"),
Arg.create("suffix", true, "the suffix string"),
@ -53,68 +52,44 @@ public class MetaAddTempSuffix extends SecondarySubCommand {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
final String suffix = args.get(1).replace("{SPACE}", " ");
int priority;
try {
priority = Integer.parseInt(args.get(0));
} catch (NumberFormatException e) {
Message.META_INVALID_PRIORITY.send(sender, args.get(0));
return CommandResult.INVALID_ARGS;
}
long duration;
try {
duration = Long.parseLong(args.get(2));
} catch (NumberFormatException e) {
try {
duration = DateUtil.parseDateDiff(args.get(2), true);
} catch (DateUtil.IllegalDateException e1) {
Message.ILLEGAL_DATE_ERROR.send(sender, args.get(2));
return CommandResult.INVALID_ARGS;
}
}
if (DateUtil.shouldExpire(duration)) {
Message.PAST_DATE_ERROR.send(sender);
return CommandResult.INVALID_ARGS;
}
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) throws CommandException {
int priority = ArgumentUtils.handlePriority(0, args);
String suffix = ArgumentUtils.handleNodeWithoutCheck(1, args);
long duration = ArgumentUtils.handleDuration(2, args);
String server = ArgumentUtils.handleServer(3, args);
String world = ArgumentUtils.handleWorld(4, args);
final String node = "suffix." + priority + "." + MetaUtils.escapeCharacters(suffix);
try {
if (args.size() >= 4) {
final String server = args.get(3).toLowerCase();
if (ArgumentChecker.checkServer(server)) {
Message.SERVER_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
if (args.size() == 4) {
switch (ContextHelper.determine(server, world)) {
case NONE:
holder.setPermission(node, true, duration);
Message.ADD_TEMP_SUFFIX_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority,
DateUtil.formatDateDiff(duration)
);
break;
case SERVER:
holder.setPermission(node, true, server, duration);
Message.ADD_TEMP_SUFFIX_SERVER_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority, server, DateUtil.formatDateDiff(duration));
LogEntry.build().actor(sender).acted(holder)
.action("meta addtempsuffix " + priority + " " + args.get(1) + " " + duration + " " + server)
.build().submit(plugin, sender);
} else {
final String world = args.get(4).toLowerCase();
Message.ADD_TEMP_SUFFIX_SERVER_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority,
server, DateUtil.formatDateDiff(duration)
);
break;
case SERVER_AND_WORLD:
holder.setPermission(node, true, server, world, duration);
Message.ADD_TEMP_SUFFIX_SERVER_WORLD_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority, server, world, DateUtil.formatDateDiff(duration));
LogEntry.build().actor(sender).acted(holder)
.action("meta addtempsuffix " + priority + " " + args.get(1) + " " + duration + " " + server + " " + world)
.build().submit(plugin, sender);
}
} else {
holder.setPermission(node, true, duration);
Message.ADD_TEMP_SUFFIX_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority, DateUtil.formatDateDiff(duration));
LogEntry.build().actor(sender).acted(holder)
.action("meta addtempsuffix " + priority + " " + args.get(1) + " " + duration)
.build().submit(plugin, sender);
Message.ADD_TEMP_SUFFIX_SERVER_WORLD_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority,
server, world, DateUtil.formatDateDiff(duration)
);
break;
}
LogEntry.build().actor(sender).acted(holder)
.action("meta addtempsuffix " + args.stream().map(ArgumentUtils.WRAPPER).collect(Collectors.joining(" ")))
.build().submit(plugin, sender);
save(holder, sender, plugin);
return CommandResult.SUCCESS;
} catch (ObjectAlreadyHasException e) {
Message.ALREADY_HAS_SUFFIX.send(sender, holder.getFriendlyName());
return CommandResult.STATE_ERROR;

View File

@ -23,15 +23,12 @@
package me.lucko.luckperms.common.commands.generic.meta;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.commands.generic.SecondarySubCommand;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.PermissionHolder;
import me.lucko.luckperms.common.data.LogEntry;
import me.lucko.luckperms.common.utils.ArgumentChecker;
import me.lucko.luckperms.common.utils.Predicates;
import java.util.List;
@ -48,25 +45,22 @@ public class MetaClear extends SecondarySubCommand {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) throws CommandException {
int before = holder.getNodes().size();
if (args.size() == 0) {
holder.clearMeta();
} else {
final String server = args.get(0);
if (ArgumentChecker.checkServer(server)) {
Message.SERVER_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
String server = ArgumentUtils.handleServer(0, args);
String world = ArgumentUtils.handleWorld(1, args);
if (args.size() == 2) {
final String world = args.get(1);
holder.clearMeta(server, world);
} else {
switch (ContextHelper.determine(server, world)) {
case NONE:
holder.clearMeta();
break;
case SERVER:
holder.clearMeta(server);
}
break;
case SERVER_AND_WORLD:
holder.clearMeta(server, world);
break;
}
int changed = before - holder.getNodes().size();
@ -76,7 +70,10 @@ public class MetaClear extends SecondarySubCommand {
Message.META_CLEAR_SUCCESS.send(sender, holder.getFriendlyName(), changed);
}
LogEntry.build().actor(sender).acted(holder).action("meta clear " + args.stream().collect(Collectors.joining(" "))).build().submit(plugin, sender);
LogEntry.build().actor(sender).acted(holder)
.action("meta clear " + args.stream().map(ArgumentUtils.WRAPPER).collect(Collectors.joining(" ")))
.build().submit(plugin, sender);
save(holder, sender, plugin);
return CommandResult.SUCCESS;
}

View File

@ -25,6 +25,7 @@ package me.lucko.luckperms.common.commands.generic.meta;
import me.lucko.luckperms.api.Contexts;
import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.Util;
@ -42,7 +43,7 @@ public class MetaInfo extends SecondarySubCommand {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) throws CommandException {
SortedSet<Map.Entry<Integer, Node>> prefixes = new TreeSet<>(Util.getMetaComparator().reversed());
SortedSet<Map.Entry<Integer, Node>> suffixes = new TreeSet<>(Util.getMetaComparator().reversed());
Set<Node> meta = new HashSet<>();

View File

@ -25,24 +25,23 @@ package me.lucko.luckperms.common.commands.generic.meta;
import me.lucko.luckperms.api.MetaUtils;
import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.commands.generic.SecondarySubCommand;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.PermissionHolder;
import me.lucko.luckperms.common.data.LogEntry;
import me.lucko.luckperms.common.utils.ArgumentChecker;
import me.lucko.luckperms.common.utils.Predicates;
import me.lucko.luckperms.exceptions.ObjectLacksException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class MetaRemovePrefix extends SecondarySubCommand {
public MetaRemovePrefix() {
super("removeprefix", "Removes a prefix", Permission.USER_META_REMOVEPREFIX, Permission.GROUP_META_REMOVEPREFIX, Predicates.notInRange(2, 4),
super("removeprefix", "Removes a prefix", Permission.USER_META_REMOVEPREFIX, Permission.GROUP_META_REMOVEPREFIX,
Predicates.notInRange(2, 4),
Arg.list(
Arg.create("priority", true, "the priority to add the prefix at"),
Arg.create("prefix", true, "the prefix string"),
@ -53,32 +52,14 @@ public class MetaRemovePrefix extends SecondarySubCommand {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
final String prefix = args.get(1).replace("{SPACE}", " ");
int priority;
try {
priority = Integer.parseInt(args.get(0));
} catch (NumberFormatException e) {
Message.META_INVALID_PRIORITY.send(sender, args.get(0));
return CommandResult.INVALID_ARGS;
}
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) throws CommandException {
int priority = ArgumentUtils.handlePriority(0, args);
String prefix = ArgumentUtils.handleNodeWithoutCheck(1, args);
String server = ArgumentUtils.handleServer(2, args);
String world = ArgumentUtils.handleWorld(3, args);
// Handle bulk removal
if (prefix.equalsIgnoreCase("null")) {
String server = null;
String world = null;
if (args.size() >= 3) {
server = args.get(2).toLowerCase();
if (ArgumentChecker.checkServer(server)) {
Message.SERVER_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
if (args.size() != 3) {
world = args.get(3).toLowerCase();
}
}
List<Node> toRemove = new ArrayList<>();
for (Node node : holder.getNodes()) {
if (!node.isPrefix()) continue;
@ -111,48 +92,36 @@ public class MetaRemovePrefix extends SecondarySubCommand {
Message.BULK_CHANGE_SUCCESS.send(sender, toRemove.size());
save(holder, sender, plugin);
return CommandResult.SUCCESS;
}
} else {
final String node = "prefix." + priority + "." + MetaUtils.escapeCharacters(prefix);
final String node = "prefix." + priority + "." + MetaUtils.escapeCharacters(prefix);
try {
if (args.size() >= 3) {
final String server = args.get(2).toLowerCase();
if (ArgumentChecker.checkServer(server)) {
Message.SERVER_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
if (args.size() == 3) {
holder.unsetPermission(node, server);
Message.REMOVEPREFIX_SERVER_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority, server);
LogEntry.build().actor(sender).acted(holder)
.action("meta removeprefix " + priority + " " + args.get(1) + " " + server)
.build().submit(plugin, sender);
} else {
final String world = args.get(3).toLowerCase();
holder.unsetPermission(node, server, world);
Message.REMOVEPREFIX_SERVER_WORLD_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority, server, world);
LogEntry.build().actor(sender).acted(holder)
.action("meta removeprefix " + priority + " " + args.get(1) + " " + server + " " + world)
.build().submit(plugin, sender);
}
} else {
try {
switch (ContextHelper.determine(server, world)) {
case NONE:
holder.unsetPermission(node);
Message.REMOVEPREFIX_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority);
LogEntry.build().actor(sender).acted(holder)
.action("meta removeprefix " + priority + " " + args.get(1))
.build().submit(plugin, sender);
}
save(holder, sender, plugin);
return CommandResult.SUCCESS;
} catch (ObjectLacksException e) {
Message.DOES_NOT_HAVE_PREFIX.send(sender, holder.getFriendlyName());
return CommandResult.STATE_ERROR;
break;
case SERVER:
holder.unsetPermission(node, server);
Message.REMOVEPREFIX_SERVER_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority, server);
break;
case SERVER_AND_WORLD:
holder.unsetPermission(node, server, world);
Message.REMOVEPREFIX_SERVER_WORLD_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority, server, world);
break;
}
LogEntry.build().actor(sender).acted(holder)
.action("meta removeprefix " + args.stream().map(ArgumentUtils.WRAPPER).collect(Collectors.joining(" ")))
.build().submit(plugin, sender);
save(holder, sender, plugin);
return CommandResult.SUCCESS;
} catch (ObjectLacksException e) {
Message.DOES_NOT_HAVE_PREFIX.send(sender, holder.getFriendlyName());
return CommandResult.STATE_ERROR;
}
}
}

View File

@ -25,24 +25,23 @@ package me.lucko.luckperms.common.commands.generic.meta;
import me.lucko.luckperms.api.MetaUtils;
import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.commands.generic.SecondarySubCommand;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.PermissionHolder;
import me.lucko.luckperms.common.data.LogEntry;
import me.lucko.luckperms.common.utils.ArgumentChecker;
import me.lucko.luckperms.common.utils.Predicates;
import me.lucko.luckperms.exceptions.ObjectLacksException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class MetaRemoveSuffix extends SecondarySubCommand {
public MetaRemoveSuffix() {
super("removesuffix", "Removes a suffix", Permission.USER_META_REMOVESUFFIX, Permission.GROUP_META_REMOVESUFFIX, Predicates.notInRange(2, 4),
super("removesuffix", "Removes a suffix", Permission.USER_META_REMOVESUFFIX, Permission.GROUP_META_REMOVESUFFIX,
Predicates.notInRange(2, 4),
Arg.list(
Arg.create("priority", true, "the priority to add the suffix at"),
Arg.create("suffix", true, "the suffix string"),
@ -53,32 +52,14 @@ public class MetaRemoveSuffix extends SecondarySubCommand {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
final String suffix = args.get(1).replace("{SPACE}", " ");
int priority;
try {
priority = Integer.parseInt(args.get(0));
} catch (NumberFormatException e) {
Message.META_INVALID_PRIORITY.send(sender, args.get(0));
return CommandResult.INVALID_ARGS;
}
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) throws CommandException {
int priority = ArgumentUtils.handlePriority(0, args);
String suffix = ArgumentUtils.handleNodeWithoutCheck(1, args);
String server = ArgumentUtils.handleServer(2, args);
String world = ArgumentUtils.handleWorld(3, args);
// Handle bulk removal
if (suffix.equalsIgnoreCase("null")) {
String server = null;
String world = null;
if (args.size() >= 3) {
server = args.get(2).toLowerCase();
if (ArgumentChecker.checkServer(server)) {
Message.SERVER_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
if (args.size() != 3) {
world = args.get(3).toLowerCase();
}
}
List<Node> toRemove = new ArrayList<>();
for (Node node : holder.getNodes()) {
if (!node.isSuffix()) continue;
@ -111,48 +92,36 @@ public class MetaRemoveSuffix extends SecondarySubCommand {
Message.BULK_CHANGE_SUCCESS.send(sender, toRemove.size());
save(holder, sender, plugin);
return CommandResult.SUCCESS;
}
} else {
final String node = "suffix." + priority + "." + MetaUtils.escapeCharacters(suffix);
final String node = "suffix." + priority + "." + MetaUtils.escapeCharacters(suffix);
try {
if (args.size() >= 3) {
final String server = args.get(2).toLowerCase();
if (ArgumentChecker.checkServer(server)) {
Message.SERVER_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
if (args.size() == 3) {
holder.unsetPermission(node, server);
Message.REMOVESUFFIX_SERVER_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority, server);
LogEntry.build().actor(sender).acted(holder)
.action("meta removesuffix " + priority + " " + args.get(1) + " " + server)
.build().submit(plugin, sender);
} else {
final String world = args.get(3).toLowerCase();
holder.unsetPermission(node, server, world);
Message.REMOVESUFFIX_SERVER_WORLD_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority, server, world);
LogEntry.build().actor(sender).acted(holder)
.action("meta removesuffix " + priority + " " + args.get(1) + " " + server + " " + world)
.build().submit(plugin, sender);
}
} else {
try {
switch (ContextHelper.determine(server, world)) {
case NONE:
holder.unsetPermission(node);
Message.REMOVESUFFIX_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority);
LogEntry.build().actor(sender).acted(holder)
.action("meta removesuffix " + priority + " " + args.get(1))
.build().submit(plugin, sender);
}
save(holder, sender, plugin);
return CommandResult.SUCCESS;
} catch (ObjectLacksException e) {
Message.DOES_NOT_HAVE_SUFFIX.send(sender, holder.getFriendlyName());
return CommandResult.STATE_ERROR;
break;
case SERVER:
holder.unsetPermission(node, server);
Message.REMOVESUFFIX_SERVER_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority, server);
break;
case SERVER_AND_WORLD:
holder.unsetPermission(node, server, world);
Message.REMOVESUFFIX_SERVER_WORLD_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority, server, world);
break;
}
LogEntry.build().actor(sender).acted(holder)
.action("meta removesuffix " + args.stream().map(ArgumentUtils.WRAPPER).collect(Collectors.joining(" ")))
.build().submit(plugin, sender);
save(holder, sender, plugin);
return CommandResult.SUCCESS;
} catch (ObjectLacksException e) {
Message.DOES_NOT_HAVE_SUFFIX.send(sender, holder.getFriendlyName());
return CommandResult.STATE_ERROR;
}
}
}

View File

@ -25,20 +25,18 @@ package me.lucko.luckperms.common.commands.generic.meta;
import me.lucko.luckperms.api.MetaUtils;
import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.commands.generic.SecondarySubCommand;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.PermissionHolder;
import me.lucko.luckperms.common.data.LogEntry;
import me.lucko.luckperms.common.utils.ArgumentChecker;
import me.lucko.luckperms.common.utils.Predicates;
import me.lucko.luckperms.exceptions.ObjectLacksException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class MetaRemoveTempPrefix extends SecondarySubCommand {
public MetaRemoveTempPrefix() {
@ -53,32 +51,14 @@ public class MetaRemoveTempPrefix extends SecondarySubCommand {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
final String prefix = args.get(1).replace("{SPACE}", " ");
int priority;
try {
priority = Integer.parseInt(args.get(0));
} catch (NumberFormatException e) {
Message.META_INVALID_PRIORITY.send(sender, args.get(0));
return CommandResult.INVALID_ARGS;
}
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) throws CommandException {
int priority = ArgumentUtils.handlePriority(0, args);
String prefix = ArgumentUtils.handleNodeWithoutCheck(1, args);
String server = ArgumentUtils.handleServer(2, args);
String world = ArgumentUtils.handleWorld(3, args);
// Handle bulk removal
if (prefix.equalsIgnoreCase("null")) {
String server = null;
String world = null;
if (args.size() >= 3) {
server = args.get(2).toLowerCase();
if (ArgumentChecker.checkServer(server)) {
Message.SERVER_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
if (args.size() != 3) {
world = args.get(3).toLowerCase();
}
}
List<Node> toRemove = new ArrayList<>();
for (Node node : holder.getNodes()) {
if (!node.isPrefix()) continue;
@ -111,48 +91,36 @@ public class MetaRemoveTempPrefix extends SecondarySubCommand {
Message.BULK_CHANGE_SUCCESS.send(sender, toRemove.size());
save(holder, sender, plugin);
return CommandResult.SUCCESS;
}
} else {
final String node = "prefix." + priority + "." + MetaUtils.escapeCharacters(prefix);
final String node = "prefix." + priority + "." + MetaUtils.escapeCharacters(prefix);
try {
if (args.size() >= 3) {
final String server = args.get(2).toLowerCase();
if (ArgumentChecker.checkServer(server)) {
Message.SERVER_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
if (args.size() == 3) {
holder.unsetPermission(node, server, true);
Message.REMOVE_TEMP_PREFIX_SERVER_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority, server);
LogEntry.build().actor(sender).acted(holder)
.action("meta removetempprefix " + priority + " " + args.get(1) + " " + server)
.build().submit(plugin, sender);
} else {
final String world = args.get(3).toLowerCase();
holder.unsetPermission(node, server, world, true);
Message.REMOVE_TEMP_PREFIX_SERVER_WORLD_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority, server, world);
LogEntry.build().actor(sender).acted(holder)
.action("meta removetempprefix " + priority + " " + args.get(1) + " " + server + " " + world)
.build().submit(plugin, sender);
}
} else {
try {
switch (ContextHelper.determine(server, world)) {
case NONE:
holder.unsetPermission(node, true);
Message.REMOVE_TEMP_PREFIX_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority);
LogEntry.build().actor(sender).acted(holder)
.action("meta removetempprefix " + priority + " " + args.get(1))
.build().submit(plugin, sender);
}
save(holder, sender, plugin);
return CommandResult.SUCCESS;
} catch (ObjectLacksException e) {
Message.DOES_NOT_HAVE_PREFIX.send(sender, holder.getFriendlyName());
return CommandResult.STATE_ERROR;
break;
case SERVER:
holder.unsetPermission(node, server, true);
Message.REMOVE_TEMP_PREFIX_SERVER_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority, server);
break;
case SERVER_AND_WORLD:
holder.unsetPermission(node, server, world, true);
Message.REMOVE_TEMP_PREFIX_SERVER_WORLD_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority, server, world);
break;
}
LogEntry.build().actor(sender).acted(holder)
.action("meta removetempprefix " + args.stream().map(ArgumentUtils.WRAPPER).collect(Collectors.joining(" ")))
.build().submit(plugin, sender);
save(holder, sender, plugin);
return CommandResult.SUCCESS;
} catch (ObjectLacksException e) {
Message.DOES_NOT_HAVE_PREFIX.send(sender, holder.getFriendlyName());
return CommandResult.STATE_ERROR;
}
}
}

View File

@ -25,20 +25,18 @@ package me.lucko.luckperms.common.commands.generic.meta;
import me.lucko.luckperms.api.MetaUtils;
import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.commands.generic.SecondarySubCommand;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.PermissionHolder;
import me.lucko.luckperms.common.data.LogEntry;
import me.lucko.luckperms.common.utils.ArgumentChecker;
import me.lucko.luckperms.common.utils.Predicates;
import me.lucko.luckperms.exceptions.ObjectLacksException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class MetaRemoveTempSuffix extends SecondarySubCommand {
public MetaRemoveTempSuffix() {
@ -53,32 +51,14 @@ public class MetaRemoveTempSuffix extends SecondarySubCommand {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
final String suffix = args.get(1).replace("{SPACE}", " ");
int priority;
try {
priority = Integer.parseInt(args.get(0));
} catch (NumberFormatException e) {
Message.META_INVALID_PRIORITY.send(sender, args.get(0));
return CommandResult.INVALID_ARGS;
}
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) throws CommandException {
int priority = ArgumentUtils.handlePriority(0, args);
String suffix = ArgumentUtils.handleNodeWithoutCheck(1, args);
String server = ArgumentUtils.handleServer(2, args);
String world = ArgumentUtils.handleWorld(3, args);
// Handle bulk removal
if (suffix.equalsIgnoreCase("null")) {
String server = null;
String world = null;
if (args.size() >= 3) {
server = args.get(2).toLowerCase();
if (ArgumentChecker.checkServer(server)) {
Message.SERVER_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
if (args.size() != 3) {
world = args.get(3).toLowerCase();
}
}
List<Node> toRemove = new ArrayList<>();
for (Node node : holder.getNodes()) {
if (!node.isSuffix()) continue;
@ -111,48 +91,36 @@ public class MetaRemoveTempSuffix extends SecondarySubCommand {
Message.BULK_CHANGE_SUCCESS.send(sender, toRemove.size());
save(holder, sender, plugin);
return CommandResult.SUCCESS;
}
} else {
final String node = "suffix." + priority + "." + MetaUtils.escapeCharacters(suffix);
final String node = "suffix." + priority + "." + MetaUtils.escapeCharacters(suffix);
try {
if (args.size() >= 3) {
final String server = args.get(2).toLowerCase();
if (ArgumentChecker.checkServer(server)) {
Message.SERVER_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
if (args.size() == 3) {
holder.unsetPermission(node, server, true);
Message.REMOVE_TEMP_SUFFIX_SERVER_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority, server);
LogEntry.build().actor(sender).acted(holder)
.action("meta removetempsuffix " + priority + " " + args.get(1) + " " + server)
.build().submit(plugin, sender);
} else {
final String world = args.get(3).toLowerCase();
holder.unsetPermission(node, server, world, true);
Message.REMOVE_TEMP_SUFFIX_SERVER_WORLD_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority, server, world);
LogEntry.build().actor(sender).acted(holder)
.action("meta removetempsuffix " + priority + " " + args.get(1) + " " + server + " " + world)
.build().submit(plugin, sender);
}
} else {
try {
switch (ContextHelper.determine(server, world)) {
case NONE:
holder.unsetPermission(node, true);
Message.REMOVE_TEMP_SUFFIX_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority);
LogEntry.build().actor(sender).acted(holder)
.action("meta removetempsuffix " + priority + " " + args.get(1))
.build().submit(plugin, sender);
}
save(holder, sender, plugin);
return CommandResult.SUCCESS;
} catch (ObjectLacksException e) {
Message.DOES_NOT_HAVE_SUFFIX.send(sender, holder.getFriendlyName());
return CommandResult.STATE_ERROR;
break;
case SERVER:
holder.unsetPermission(node, server, true);
Message.REMOVE_TEMP_SUFFIX_SERVER_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority, server);
break;
case SERVER_AND_WORLD:
holder.unsetPermission(node, server, world, true);
Message.REMOVE_TEMP_SUFFIX_SERVER_WORLD_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority, server, world);
break;
}
LogEntry.build().actor(sender).acted(holder)
.action("meta removetempsuffix " + args.stream().map(ArgumentUtils.WRAPPER).collect(Collectors.joining(" ")))
.build().submit(plugin, sender);
save(holder, sender, plugin);
return CommandResult.SUCCESS;
} catch (ObjectLacksException e) {
Message.DOES_NOT_HAVE_SUFFIX.send(sender, holder.getFriendlyName());
return CommandResult.STATE_ERROR;
}
}
}

View File

@ -25,20 +25,18 @@ package me.lucko.luckperms.common.commands.generic.meta;
import me.lucko.luckperms.api.MetaUtils;
import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.commands.generic.SecondarySubCommand;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.NodeBuilder;
import me.lucko.luckperms.common.core.PermissionHolder;
import me.lucko.luckperms.common.data.LogEntry;
import me.lucko.luckperms.common.utils.ArgumentChecker;
import me.lucko.luckperms.common.utils.Predicates;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import java.util.List;
import java.util.stream.Collectors;
public class MetaSet extends SecondarySubCommand {
public MetaSet() {
@ -53,25 +51,13 @@ public class MetaSet extends SecondarySubCommand {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) throws CommandException {
String key = MetaUtils.escapeCharacters(args.get(0));
String value = MetaUtils.escapeCharacters(args.get(1));
String node = "meta." + key + "." + value;
String server = null;
String world = null;
if (args.size() >= 3) {
server = args.get(2).toLowerCase();
if (ArgumentChecker.checkServer(server)) {
Message.SERVER_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
if (args.size() != 3) {
world = args.get(3).toLowerCase();
}
}
String server = ArgumentUtils.handleServer(2, args);
String world = ArgumentUtils.handleWorld(3, args);
Node n = new NodeBuilder(node).setServer(server).setWorld(world).build();
@ -86,25 +72,22 @@ public class MetaSet extends SecondarySubCommand {
holder.setPermission(n);
} catch (ObjectAlreadyHasException ignored) {}
if (server == null) {
Message.SET_META_SUCCESS.send(sender, key, value, holder.getFriendlyName());
LogEntry.build().actor(sender).acted(holder)
.action("meta set " + key + " " + value)
.build().submit(plugin, sender);
} else {
if (world == null) {
switch (ContextHelper.determine(server, world)) {
case NONE:
Message.SET_META_SUCCESS.send(sender, key, value, holder.getFriendlyName());
break;
case SERVER:
Message.SET_META_SERVER_SUCCESS.send(sender, key, value, holder.getFriendlyName(), server);
LogEntry.build().actor(sender).acted(holder)
.action("meta set " + key + " " + value + " " + server)
.build().submit(plugin, sender);
} else {
break;
case SERVER_AND_WORLD:
Message.SET_META_SERVER_WORLD_SUCCESS.send(sender, key, value, holder.getFriendlyName(), server, world);
LogEntry.build().actor(sender).acted(holder)
.action("meta set " + key + " " + value + " " + server + " " + world)
.build().submit(plugin, sender);
}
break;
}
LogEntry.build().actor(sender).acted(holder)
.action("meta set " + args.stream().map(ArgumentUtils.WRAPPER).collect(Collectors.joining(" ")))
.build().submit(plugin, sender);
save(holder, sender, plugin);
return CommandResult.SUCCESS;
}

View File

@ -25,21 +25,19 @@ package me.lucko.luckperms.common.commands.generic.meta;
import me.lucko.luckperms.api.MetaUtils;
import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.commands.generic.SecondarySubCommand;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.NodeBuilder;
import me.lucko.luckperms.common.core.PermissionHolder;
import me.lucko.luckperms.common.data.LogEntry;
import me.lucko.luckperms.common.utils.ArgumentChecker;
import me.lucko.luckperms.common.utils.DateUtil;
import me.lucko.luckperms.common.utils.Predicates;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import java.util.List;
import java.util.stream.Collectors;
public class MetaSetTemp extends SecondarySubCommand {
public MetaSetTemp() {
@ -55,42 +53,13 @@ public class MetaSetTemp extends SecondarySubCommand {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
long duration;
try {
duration = Long.parseLong(args.get(2));
} catch (NumberFormatException e) {
try {
duration = DateUtil.parseDateDiff(args.get(2), true);
} catch (DateUtil.IllegalDateException e1) {
Message.ILLEGAL_DATE_ERROR.send(sender, args.get(2));
return CommandResult.INVALID_ARGS;
}
}
if (DateUtil.shouldExpire(duration)) {
Message.PAST_DATE_ERROR.send(sender);
return CommandResult.INVALID_ARGS;
}
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) throws CommandException {
String key = MetaUtils.escapeCharacters(args.get(0));
String value = MetaUtils.escapeCharacters(args.get(1));
long duration = ArgumentUtils.handleDuration(2, args);
String node = "meta." + key + "." + value;
String server = null;
String world = null;
if (args.size() >= 3) {
server = args.get(2).toLowerCase();
if (ArgumentChecker.checkServer(server)) {
Message.SERVER_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
if (args.size() != 3) {
world = args.get(3).toLowerCase();
}
}
String server = ArgumentUtils.handleServer(3, args);
String world = ArgumentUtils.handleWorld(4, args);
Node n = new NodeBuilder(node).setServer(server).setWorld(world).setExpiry(duration).build();
@ -105,25 +74,22 @@ public class MetaSetTemp extends SecondarySubCommand {
holder.setPermission(n);
} catch (ObjectAlreadyHasException ignored) {}
if (server == null) {
Message.SET_META_TEMP_SUCCESS.send(sender, key, value, holder.getFriendlyName(), DateUtil.formatDateDiff(duration));
LogEntry.build().actor(sender).acted(holder)
.action("meta settemp " + key + " " + value + " " + duration)
.build().submit(plugin, sender);
} else {
if (world == null) {
switch (ContextHelper.determine(server, world)) {
case NONE:
Message.SET_META_TEMP_SUCCESS.send(sender, key, value, holder.getFriendlyName(), DateUtil.formatDateDiff(duration));
break;
case SERVER:
Message.SET_META_TEMP_SERVER_SUCCESS.send(sender, key, value, holder.getFriendlyName(), server, DateUtil.formatDateDiff(duration));
LogEntry.build().actor(sender).acted(holder)
.action("meta settemp " + key + " " + value + " " + duration + " " + server)
.build().submit(plugin, sender);
} else {
break;
case SERVER_AND_WORLD:
Message.SET_META_TEMP_SERVER_WORLD_SUCCESS.send(sender, key, value, holder.getFriendlyName(), server, world, DateUtil.formatDateDiff(duration));
LogEntry.build().actor(sender).acted(holder)
.action("meta settemp " + key + " " + value + " " + duration + " " + server + " " + world)
.build().submit(plugin, sender);
}
break;
}
LogEntry.build().actor(sender).acted(holder)
.action("meta settemp " + args.stream().map(ArgumentUtils.WRAPPER).collect(Collectors.joining(" ")))
.build().submit(plugin, sender);
save(holder, sender, plugin);
return CommandResult.SUCCESS;
}

View File

@ -24,15 +24,12 @@ package me.lucko.luckperms.common.commands.generic.meta;
import me.lucko.luckperms.api.MetaUtils;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.commands.generic.SecondarySubCommand;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.PermissionHolder;
import me.lucko.luckperms.common.data.LogEntry;
import me.lucko.luckperms.common.utils.ArgumentChecker;
import me.lucko.luckperms.common.utils.Predicates;
import java.util.List;
@ -40,7 +37,8 @@ import java.util.stream.Collectors;
public class MetaUnset extends SecondarySubCommand {
public MetaUnset() {
super("unset", "Unsets a meta value", Permission.USER_META_UNSET, Permission.GROUP_META_UNSET, Predicates.notInRange(1, 3),
super("unset", "Unsets a meta value", Permission.USER_META_UNSET, Permission.GROUP_META_UNSET,
Predicates.notInRange(1, 3),
Arg.list(
Arg.create("key", true, "the key to unset"),
Arg.create("server", false, "the server to remove the meta pair on"),
@ -50,38 +48,27 @@ public class MetaUnset extends SecondarySubCommand {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) throws CommandException {
String key = MetaUtils.escapeCharacters(args.get(0));
String server = null;
String world = null;
if (args.size() >= 2) {
server = args.get(1).toLowerCase();
if (ArgumentChecker.checkServer(server)) {
Message.SERVER_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
if (args.size() != 2) {
world = args.get(2).toLowerCase();
}
}
String server = ArgumentUtils.handleServer(1, args);
String world = ArgumentUtils.handleWorld(2, args);
holder.clearMetaKeys(key, server, world, false);
if (server == null) {
Message.UNSET_META_SUCCESS.send(sender, key, holder.getFriendlyName());
} else {
if (world == null) {
switch (ContextHelper.determine(server, world)) {
case NONE:
Message.UNSET_META_SUCCESS.send(sender, key, holder.getFriendlyName());
break;
case SERVER:
Message.UNSET_META_SERVER_SUCCESS.send(sender, key, holder.getFriendlyName(), server);
} else {
break;
case SERVER_AND_WORLD:
Message.UNSET_META_SERVER_WORLD_SUCCESS.send(sender, key, holder.getFriendlyName(), server, world);
}
break;
}
LogEntry.build().actor(sender).acted(holder)
.action("meta unset " + args.stream().collect(Collectors.joining(" ")))
.action("meta unset " + args.stream().map(ArgumentUtils.WRAPPER).collect(Collectors.joining(" ")))
.build().submit(plugin, sender);
save(holder, sender, plugin);

View File

@ -24,15 +24,12 @@ package me.lucko.luckperms.common.commands.generic.meta;
import me.lucko.luckperms.api.MetaUtils;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.commands.generic.SecondarySubCommand;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.PermissionHolder;
import me.lucko.luckperms.common.data.LogEntry;
import me.lucko.luckperms.common.utils.ArgumentChecker;
import me.lucko.luckperms.common.utils.Predicates;
import java.util.List;
@ -40,7 +37,8 @@ import java.util.stream.Collectors;
public class MetaUnsetTemp extends SecondarySubCommand {
public MetaUnsetTemp() {
super("unsettemp", "Unsets a temporary meta value", Permission.USER_META_UNSETTEMP, Permission.GROUP_META_UNSETTEMP, Predicates.notInRange(1, 3),
super("unsettemp", "Unsets a temporary meta value", Permission.USER_META_UNSETTEMP, Permission.GROUP_META_UNSETTEMP,
Predicates.notInRange(1, 3),
Arg.list(
Arg.create("key", true, "the key to unset"),
Arg.create("server", false, "the server to remove the meta pair on"),
@ -50,38 +48,27 @@ public class MetaUnsetTemp extends SecondarySubCommand {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) throws CommandException {
String key = MetaUtils.escapeCharacters(args.get(0));
String server = null;
String world = null;
if (args.size() >= 2) {
server = args.get(1).toLowerCase();
if (ArgumentChecker.checkServer(server)) {
Message.SERVER_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
if (args.size() != 2) {
world = args.get(2).toLowerCase();
}
}
String server = ArgumentUtils.handleServer(1, args);
String world = ArgumentUtils.handleWorld(2, args);
holder.clearMetaKeys(key, server, world, true);
if (server == null) {
Message.UNSET_META_TEMP_SUCCESS.send(sender, key, holder.getFriendlyName());
} else {
if (world == null) {
switch (ContextHelper.determine(server, world)) {
case NONE:
Message.UNSET_META_TEMP_SUCCESS.send(sender, key, holder.getFriendlyName());
break;
case SERVER:
Message.UNSET_META_TEMP_SERVER_SUCCESS.send(sender, key, holder.getFriendlyName(), server);
} else {
break;
case SERVER_AND_WORLD:
Message.UNSET_META_TEMP_SERVER_WORLD_SUCCESS.send(sender, key, holder.getFriendlyName(), server, world);
}
break;
}
LogEntry.build().actor(sender).acted(holder)
.action("meta unsettemp " + args.stream().collect(Collectors.joining(" ")))
.action("meta unsettemp " + args.stream().map(ArgumentUtils.WRAPPER).collect(Collectors.joining(" ")))
.build().submit(plugin, sender);
save(holder, sender, plugin);

View File

@ -24,10 +24,7 @@ package me.lucko.luckperms.common.commands.generic.other;
import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.Util;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.PermissionHolder;
@ -44,7 +41,7 @@ public class HolderShowTracks<T extends PermissionHolder> extends SubCommand<T>
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, T holder, List<String> args, String label) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, T holder, List<String> args, String label) throws CommandException {
if (!plugin.getDatastore().loadAllTracks().getUnchecked()) {
Message.TRACKS_LOAD_ERROR.send(sender);
return CommandResult.LOADING_ERROR;

View File

@ -23,27 +23,25 @@
package me.lucko.luckperms.common.commands.generic.parent;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.commands.generic.SecondarySubCommand;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.PermissionHolder;
import me.lucko.luckperms.common.data.LogEntry;
import me.lucko.luckperms.common.groups.Group;
import me.lucko.luckperms.common.utils.ArgumentChecker;
import me.lucko.luckperms.common.utils.Predicates;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import java.util.List;
import java.util.stream.Collectors;
import static me.lucko.luckperms.common.commands.SubCommand.getGroupTabComplete;
public class ParentAdd extends SecondarySubCommand {
public ParentAdd() {
super("add", "Sets another group for the object to inherit permissions from",
Permission.USER_PARENT_ADD, Permission.GROUP_PARENT_ADD, Predicates.notInRange(1, 3),
super("add", "Sets another group for the object to inherit permissions from", Permission.USER_PARENT_ADD,
Permission.GROUP_PARENT_ADD, Predicates.notInRange(1, 3),
Arg.list(
Arg.create("group", true, "the group to inherit from"),
Arg.create("server", false, "the server to inherit the group on"),
@ -53,13 +51,10 @@ public class ParentAdd extends SecondarySubCommand {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
String groupName = args.get(0).toLowerCase();
if (ArgumentChecker.checkName(groupName)) {
sendDetailedUsage(sender);
return CommandResult.INVALID_ARGS;
}
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) throws CommandException {
String groupName = ArgumentUtils.handleName(0, args);
String server = ArgumentUtils.handleServer(1, args);
String world = ArgumentUtils.handleWorld(2, args);
if (!plugin.getDatastore().loadGroup(groupName).getUnchecked()) {
Message.GROUP_DOES_NOT_EXIST.send(sender);
@ -73,38 +68,28 @@ public class ParentAdd extends SecondarySubCommand {
}
try {
if (args.size() >= 2) {
final String server = args.get(1).toLowerCase();
if (ArgumentChecker.checkServer(server)) {
Message.SERVER_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
if (args.size() == 2) {
switch (ContextHelper.determine(server, world)) {
case NONE:
holder.setInheritGroup(group);
Message.SET_INHERIT_SUCCESS.send(sender, holder.getFriendlyName(), group.getDisplayName());
break;
case SERVER:
holder.setInheritGroup(group, server);
Message.SET_INHERIT_SERVER_SUCCESS.send(sender, holder.getFriendlyName(), group.getDisplayName(), server);
LogEntry.build().actor(sender).acted(holder)
.action("parent add " + group.getName() + " " + server)
.build().submit(plugin, sender);
} else {
final String world = args.get(2).toLowerCase();
break;
case SERVER_AND_WORLD:
holder.setInheritGroup(group, server, world);
Message.SET_INHERIT_SERVER_WORLD_SUCCESS.send(sender, holder.getFriendlyName(), group.getDisplayName(), server, world);
LogEntry.build().actor(sender).acted(holder)
.action("parent add " + group.getName() + " " + server + " " + world)
.build().submit(plugin, sender);
}
} else {
holder.setInheritGroup(group);
Message.SET_INHERIT_SUCCESS.send(sender, holder.getFriendlyName(), group.getDisplayName());
LogEntry.build().actor(sender).acted(holder)
.action("parent add " + group.getName())
.build().submit(plugin, sender);
break;
}
LogEntry.build().actor(sender).acted(holder)
.action("parent add " + args.stream().map(ArgumentUtils.WRAPPER).collect(Collectors.joining(" ")))
.build().submit(plugin, sender);
save(holder, sender, plugin);
return CommandResult.SUCCESS;
} catch (ObjectAlreadyHasException e) {
Message.ALREADY_INHERITS.send(sender, holder.getFriendlyName(), group.getDisplayName());
return CommandResult.STATE_ERROR;

View File

@ -23,21 +23,19 @@
package me.lucko.luckperms.common.commands.generic.parent;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.commands.generic.SecondarySubCommand;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.PermissionHolder;
import me.lucko.luckperms.common.data.LogEntry;
import me.lucko.luckperms.common.groups.Group;
import me.lucko.luckperms.common.utils.ArgumentChecker;
import me.lucko.luckperms.common.utils.DateUtil;
import me.lucko.luckperms.common.utils.Predicates;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import java.util.List;
import java.util.stream.Collectors;
import static me.lucko.luckperms.common.commands.SubCommand.getGroupTabComplete;
@ -55,30 +53,11 @@ public class ParentAddTemp extends SecondarySubCommand {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
String groupName = args.get(0).toLowerCase();
if (ArgumentChecker.checkName(groupName)) {
sendDetailedUsage(sender);
return CommandResult.INVALID_ARGS;
}
long duration;
try {
duration = Long.parseLong(args.get(1));
} catch (NumberFormatException e) {
try {
duration = DateUtil.parseDateDiff(args.get(1), true);
} catch (DateUtil.IllegalDateException e1) {
Message.ILLEGAL_DATE_ERROR.send(sender, args.get(1));
return CommandResult.INVALID_ARGS;
}
}
if (DateUtil.shouldExpire(duration)) {
Message.PAST_DATE_ERROR.send(sender);
return CommandResult.INVALID_ARGS;
}
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) throws CommandException {
String groupName = ArgumentUtils.handleName(0, args);
long duration = ArgumentUtils.handleDuration(1, args);
String server = ArgumentUtils.handleServer(2, args);
String world = ArgumentUtils.handleWorld(3, args);
if (!plugin.getDatastore().loadGroup(groupName).getUnchecked()) {
Message.GROUP_DOES_NOT_EXIST.send(sender);
@ -92,40 +71,34 @@ public class ParentAddTemp extends SecondarySubCommand {
}
try {
if (args.size() >= 3) {
final String server = args.get(2).toLowerCase();
if (ArgumentChecker.checkServer(server)) {
Message.SERVER_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
if (args.size() == 3) {
switch (ContextHelper.determine(server, world)) {
case NONE:
holder.setInheritGroup(group, duration);
Message.SET_TEMP_INHERIT_SUCCESS.send(sender, holder.getFriendlyName(), group.getDisplayName(),
DateUtil.formatDateDiff(duration)
);
break;
case SERVER:
holder.setInheritGroup(group, server, duration);
Message.SET_TEMP_INHERIT_SERVER_SUCCESS.send(sender, holder.getFriendlyName(), group.getDisplayName(), server,
DateUtil.formatDateDiff(duration));
LogEntry.build().actor(sender).acted(holder)
.action("parent addtemp " + group.getName() + " " + duration + " " + server)
.build().submit(plugin, sender);
} else {
final String world = args.get(3).toLowerCase();
Message.SET_TEMP_INHERIT_SERVER_SUCCESS.send(sender, holder.getFriendlyName(), group.getDisplayName(),
server, DateUtil.formatDateDiff(duration)
);
break;
case SERVER_AND_WORLD:
holder.setInheritGroup(group, server, world, duration);
Message.SET_TEMP_INHERIT_SERVER_WORLD_SUCCESS.send(sender, holder.getFriendlyName(), group.getDisplayName(), server,
world, DateUtil.formatDateDiff(duration));
LogEntry.build().actor(sender).acted(holder)
.action("parent addtemp " + group.getName() + " " + duration + " " + server + " " + world)
.build().submit(plugin, sender);
}
} else {
holder.setInheritGroup(group, duration);
Message.SET_TEMP_INHERIT_SUCCESS.send(sender, holder.getFriendlyName(), group.getDisplayName(), DateUtil.formatDateDiff(duration));
LogEntry.build().actor(sender).acted(holder)
.action("parent addtemp " + group.getName() + " " + duration)
.build().submit(plugin, sender);
Message.SET_TEMP_INHERIT_SERVER_WORLD_SUCCESS.send(sender, holder.getFriendlyName(), group.getDisplayName(),
server, world, DateUtil.formatDateDiff(duration)
);
break;
}
LogEntry.build().actor(sender).acted(holder)
.action("parent addtemp " + args.stream().map(ArgumentUtils.WRAPPER).collect(Collectors.joining(" ")))
.build().submit(plugin, sender);
save(holder, sender, plugin);
return CommandResult.SUCCESS;
} catch (ObjectAlreadyHasException e) {
Message.ALREADY_TEMP_INHERITS.send(sender, holder.getFriendlyName(), group.getDisplayName());
return CommandResult.STATE_ERROR;

View File

@ -23,6 +23,7 @@
package me.lucko.luckperms.common.commands.generic.parent;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.Util;
@ -41,7 +42,7 @@ public class ParentInfo extends SecondarySubCommand {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) throws CommandException {
Message.LISTPARENTS.send(sender, holder.getFriendlyName(), Util.permGroupsToString(holder.getPermissions(false)));
Message.LISTPARENTS_TEMP.send(sender, holder.getFriendlyName(), Util.tempGroupsToString(holder.getPermissions(false)));
return CommandResult.SUCCESS;

View File

@ -23,27 +23,25 @@
package me.lucko.luckperms.common.commands.generic.parent;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.commands.generic.SecondarySubCommand;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.PermissionHolder;
import me.lucko.luckperms.common.data.LogEntry;
import me.lucko.luckperms.common.users.User;
import me.lucko.luckperms.common.utils.ArgumentChecker;
import me.lucko.luckperms.common.utils.Predicates;
import me.lucko.luckperms.exceptions.ObjectLacksException;
import java.util.List;
import java.util.stream.Collectors;
import static me.lucko.luckperms.common.commands.SubCommand.getGroupTabComplete;
public class ParentRemove extends SecondarySubCommand {
public ParentRemove() {
super("remove", "Removes a previously set inheritance rule", Permission.USER_PARENT_REMOVE, Permission.GROUP_PARENT_REMOVE,
Predicates.notInRange(1, 3),
super("remove", "Removes a previously set inheritance rule", Permission.USER_PARENT_REMOVE,
Permission.GROUP_PARENT_REMOVE, Predicates.notInRange(1, 3),
Arg.list(
Arg.create("group", true, "the group to remove"),
Arg.create("server", false, "the server to remove the group on"),
@ -53,56 +51,49 @@ public class ParentRemove extends SecondarySubCommand {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
String groupName = args.get(0).toLowerCase();
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) throws CommandException {
String groupName = ArgumentUtils.handleName(0, args);
String server = ArgumentUtils.handleServer(1, args);
String world = ArgumentUtils.handleWorld(2, args);
if (ArgumentChecker.checkName(groupName)) {
sendDetailedUsage(sender);
return CommandResult.INVALID_ARGS;
}
ContextHelper.CommandContext context = ContextHelper.determine(server, world);
if (holder instanceof User) {
User user = (User) holder;
if ((args.size() == 1 || (args.size() == 2 && args.get(1).equalsIgnoreCase("global")))
&& user.getPrimaryGroup().equalsIgnoreCase(groupName)) {
boolean shouldPrevent = (context == ContextHelper.CommandContext.NONE ||
(context == ContextHelper.CommandContext.SERVER && server.equalsIgnoreCase("global"))) &&
user.getPrimaryGroup().equalsIgnoreCase(groupName);
if (shouldPrevent) {
Message.USER_REMOVEGROUP_ERROR_PRIMARY.send(sender);
return CommandResult.STATE_ERROR;
}
}
try {
if (args.size() >= 2) {
final String server = args.get(1).toLowerCase();
if (ArgumentChecker.checkServer(server)) {
Message.SERVER_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
if (args.size() == 2) {
switch (context) {
case NONE:
holder.unsetPermission("group." + groupName);
Message.UNSET_INHERIT_SUCCESS.send(sender, holder.getFriendlyName(), groupName);
break;
case SERVER:
holder.unsetPermission("group." + groupName, server);
Message.UNSET_INHERIT_SERVER_SUCCESS.send(sender, holder.getFriendlyName(), groupName, server);
LogEntry.build().actor(sender).acted(holder)
.action("parent remove " + groupName + " " + server)
.build().submit(plugin, sender);
} else {
final String world = args.get(2).toLowerCase();
break;
case SERVER_AND_WORLD:
holder.unsetPermission("group." + groupName, server, world);
Message.UNSET_INHERIT_SERVER_WORLD_SUCCESS.send(sender, holder.getFriendlyName(), groupName, server, world);
LogEntry.build().actor(sender).acted(holder)
.action("parent remove " + groupName + " " + server + " " + world)
.build().submit(plugin, sender);
}
} else {
holder.unsetPermission("group." + groupName);
Message.UNSET_INHERIT_SUCCESS.send(sender, holder.getFriendlyName(), groupName);
LogEntry.build().actor(sender).acted(holder)
.action("parent remove " + groupName)
.build().submit(plugin, sender);
break;
}
LogEntry.build().actor(sender).acted(holder)
.action("parent remove " + args.stream().map(ArgumentUtils.WRAPPER).collect(Collectors.joining(" ")))
.build().submit(plugin, sender);
save(holder, sender, plugin);
return CommandResult.SUCCESS;
} catch (ObjectLacksException e) {
Message.DOES_NOT_INHERIT.send(sender, holder.getFriendlyName(), groupName);
return CommandResult.STATE_ERROR;

View File

@ -23,19 +23,17 @@
package me.lucko.luckperms.common.commands.generic.parent;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.commands.generic.SecondarySubCommand;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.PermissionHolder;
import me.lucko.luckperms.common.data.LogEntry;
import me.lucko.luckperms.common.utils.ArgumentChecker;
import me.lucko.luckperms.common.utils.Predicates;
import me.lucko.luckperms.exceptions.ObjectLacksException;
import java.util.List;
import java.util.stream.Collectors;
import static me.lucko.luckperms.common.commands.SubCommand.getGroupTabComplete;
@ -52,47 +50,34 @@ public class ParentRemoveTemp extends SecondarySubCommand {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
String groupName = args.get(0).toLowerCase();
if (ArgumentChecker.checkName(groupName)) {
sendDetailedUsage(sender);
return CommandResult.INVALID_ARGS;
}
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) throws CommandException {
String groupName = ArgumentUtils.handleName(0, args);
String server = ArgumentUtils.handleServer(1, args);
String world = ArgumentUtils.handleWorld(2, args);
try {
if (args.size() >= 2) {
final String server = args.get(1).toLowerCase();
if (ArgumentChecker.checkServer(server)) {
Message.SERVER_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
if (args.size() == 2) {
switch (ContextHelper.determine(server, world)) {
case NONE:
holder.unsetPermission("group." + groupName, true);
Message.UNSET_TEMP_INHERIT_SUCCESS.send(sender, holder.getFriendlyName(), groupName);
break;
case SERVER:
holder.unsetPermission("group." + groupName, server, true);
Message.UNSET_TEMP_INHERIT_SERVER_SUCCESS.send(sender, holder.getFriendlyName(), groupName, server);
LogEntry.build().actor(sender).acted(holder)
.action("parent removetemp " + groupName + " " + server)
.build().submit(plugin, sender);
} else {
final String world = args.get(2).toLowerCase();
break;
case SERVER_AND_WORLD:
holder.unsetPermission("group." + groupName, server, world, true);
Message.UNSET_TEMP_INHERIT_SERVER_WORLD_SUCCESS.send(sender, holder.getFriendlyName(), groupName, server, world);
LogEntry.build().actor(sender).acted(holder)
.action("parent removetemp " + groupName + " " + server + " " + world)
.build().submit(plugin, sender);
}
} else {
holder.unsetPermission("group." + groupName, true);
Message.UNSET_TEMP_INHERIT_SUCCESS.send(sender, holder.getFriendlyName(), groupName);
LogEntry.build().actor(sender).acted(holder)
.action("parent removetemp " + groupName)
.build().submit(plugin, sender);
break;
}
LogEntry.build().actor(sender).acted(holder)
.action("parent removetemp " + args.stream().map(ArgumentUtils.WRAPPER).collect(Collectors.joining(" ")))
.build().submit(plugin, sender);
save(holder, sender, plugin);
return CommandResult.SUCCESS;
} catch (ObjectLacksException e) {
Message.DOES_NOT_TEMP_INHERIT.send(sender, holder.getFriendlyName(), groupName);
return CommandResult.STATE_ERROR;

View File

@ -23,9 +23,7 @@
package me.lucko.luckperms.common.commands.generic.parent;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.commands.generic.SecondarySubCommand;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
@ -33,11 +31,11 @@ import me.lucko.luckperms.common.core.PermissionHolder;
import me.lucko.luckperms.common.data.LogEntry;
import me.lucko.luckperms.common.groups.Group;
import me.lucko.luckperms.common.users.User;
import me.lucko.luckperms.common.utils.ArgumentChecker;
import me.lucko.luckperms.common.utils.Predicates;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import java.util.List;
import java.util.stream.Collectors;
import static me.lucko.luckperms.common.commands.SubCommand.getGroupTabComplete;
@ -54,13 +52,10 @@ public class ParentSet extends SecondarySubCommand {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
String groupName = args.get(0).toLowerCase();
if (ArgumentChecker.checkNode(groupName)) {
sendDetailedUsage(sender);
return CommandResult.INVALID_ARGS;
}
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) throws CommandException {
String groupName = ArgumentUtils.handleName(0, args);
String server = ArgumentUtils.handleServer(1, args);
String world = ArgumentUtils.handleWorld(2, args);
if (!plugin.getDatastore().loadGroup(groupName).getUnchecked()) {
Message.GROUP_DOES_NOT_EXIST.send(sender);
@ -73,54 +68,50 @@ public class ParentSet extends SecondarySubCommand {
return CommandResult.LOADING_ERROR;
}
try {
if (args.size() >= 2) {
final String server = args.get(1).toLowerCase();
if (ArgumentChecker.checkServer(server)) {
Message.SERVER_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
if (args.size() == 2) {
holder.clearParents(server, null);
holder.setInheritGroup(group, server);
Message.SET_PARENT_SERVER_SUCCESS.send(sender, holder.getFriendlyName(), group.getDisplayName(), server);
LogEntry.build().actor(sender).acted(holder)
.action("parent set " + group.getName() + " " + server)
.build().submit(plugin, sender);
} else {
final String world = args.get(2).toLowerCase();
holder.clearParents(server, world);
holder.setInheritGroup(group, server, world);
Message.SET_PARENT_SERVER_WORLD_SUCCESS.send(sender, holder.getFriendlyName(), group.getDisplayName(), server, world);
LogEntry.build().actor(sender).acted(holder)
.action("parent set " + group.getName() + " " + server + " " + world)
.build().submit(plugin, sender);
}
} else {
switch (ContextHelper.determine(server, world)) {
case NONE:
holder.clearParents(null, null);
holder.setInheritGroup(group);
try {
holder.setInheritGroup(group);
} catch (ObjectAlreadyHasException ignored) {}
if (holder instanceof User) {
((User) holder).setPrimaryGroup(group.getName());
}
Message.SET_PARENT_SUCCESS.send(sender, holder.getFriendlyName(), group.getDisplayName());
LogEntry.build().actor(sender).acted(holder)
.action("parent set " + group.getName())
.build().submit(plugin, sender);
}
break;
case SERVER:
holder.clearParents(server, null);
save(holder, sender, plugin);
return CommandResult.SUCCESS;
} catch (ObjectAlreadyHasException e) {
Message.ALREADY_INHERITS.send(sender, holder.getFriendlyName(), group.getDisplayName());
return CommandResult.STATE_ERROR;
try {
holder.setInheritGroup(group, server);
} catch (ObjectAlreadyHasException ignored) {}
if (server.equalsIgnoreCase("global") && holder instanceof User) {
((User) holder).setPrimaryGroup(group.getName());
}
Message.SET_PARENT_SERVER_SUCCESS.send(sender, holder.getFriendlyName(), group.getDisplayName(), server);
break;
case SERVER_AND_WORLD:
holder.clearParents(server, world);
try {
holder.setInheritGroup(group, server, world);
} catch (ObjectAlreadyHasException ignored) {}
Message.SET_PARENT_SERVER_WORLD_SUCCESS.send(sender, holder.getFriendlyName(), group.getDisplayName(), server, world);
break;
}
LogEntry.build().actor(sender).acted(holder)
.action("parent set " + args.stream().map(ArgumentUtils.WRAPPER).collect(Collectors.joining(" ")))
.build().submit(plugin, sender);
save(holder, sender, plugin);
return CommandResult.SUCCESS;
}
@Override

View File

@ -23,24 +23,19 @@
package me.lucko.luckperms.common.commands.generic.permission;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.Util;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.commands.generic.SecondarySubCommand;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.NodeBuilder;
import me.lucko.luckperms.common.core.PermissionHolder;
import me.lucko.luckperms.common.utils.ArgumentChecker;
import me.lucko.luckperms.common.utils.Predicates;
import java.util.List;
public class PermissionCheck extends SecondarySubCommand {
public PermissionCheck() {
super("check", "Checks to see if the object has a certain permission node", Permission.USER_PERM_CHECK, Permission.GROUP_PERM_CHECK,
Predicates.notInRange(1, 3),
super("check", "Checks to see if the object has a certain permission node", Permission.USER_PERM_CHECK,
Permission.GROUP_PERM_CHECK, Predicates.notInRange(1, 3),
Arg.list(
Arg.create("node", true, "the permission node to check for"),
Arg.create("server", false, "the server to check on"),
@ -50,22 +45,23 @@ public class PermissionCheck extends SecondarySubCommand {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
if (args.size() >= 2) {
if (ArgumentChecker.checkServer(args.get(1))) {
Message.SERVER_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) throws CommandException {
String node = ArgumentUtils.handleNodeWithoutCheck(0, args);
String server = ArgumentUtils.handleServer(1, args);
String world = ArgumentUtils.handleWorld(2, args);
if (args.size() == 2) {
Util.sendTristate(sender, args.get(0), holder.hasPermission(new NodeBuilder(args.get(0)).setServer(args.get(1)).build()));
} else {
Util.sendTristate(sender, args.get(0), holder.hasPermission(new NodeBuilder(args.get(0)).setServer(args.get(1)).setWorld(args.get(2)).build()));
}
} else {
Util.sendTristate(sender, args.get(0), holder.hasPermission(new NodeBuilder(args.get(0)).build()));
switch (ContextHelper.determine(server, world)) {
case NONE:
Util.sendTristate(sender, node, holder.hasPermission(new NodeBuilder(node).build()));
break;
case SERVER:
Util.sendTristate(sender, node, holder.hasPermission(new NodeBuilder(node).setServer(server).build()));
break;
case SERVER_AND_WORLD:
Util.sendTristate(sender, node, holder.hasPermission(new NodeBuilder(node).setServer(server).setWorld(world).build()));
break;
}
return CommandResult.SUCCESS;
}
}

View File

@ -23,25 +23,20 @@
package me.lucko.luckperms.common.commands.generic.permission;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.Util;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.commands.generic.SecondarySubCommand;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.InheritanceInfo;
import me.lucko.luckperms.common.core.NodeBuilder;
import me.lucko.luckperms.common.core.PermissionHolder;
import me.lucko.luckperms.common.utils.ArgumentChecker;
import me.lucko.luckperms.common.utils.Predicates;
import java.util.List;
public class PermissionCheckInherits extends SecondarySubCommand {
public PermissionCheckInherits() {
super("checkinherits", "Checks to see if the object inherits a certain permission node", Permission.USER_PERM_CHECK_INHERITS, Permission.GROUP_PERM_CHECK_INHERITS,
Predicates.notInRange(1, 3),
super("checkinherits", "Checks to see if the object inherits a certain permission node",
Permission.USER_PERM_CHECK_INHERITS, Permission.GROUP_PERM_CHECK_INHERITS, Predicates.notInRange(1, 3),
Arg.list(
Arg.create("node", true, "the permission node to check for"),
Arg.create("server", false, "the server to check on"),
@ -51,22 +46,22 @@ public class PermissionCheckInherits extends SecondarySubCommand {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
InheritanceInfo result;
if (args.size() >= 2) {
if (ArgumentChecker.checkServer(args.get(1))) {
Message.SERVER_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) throws CommandException {
String node = ArgumentUtils.handleNodeWithoutCheck(0, args);
String server = ArgumentUtils.handleServer(1, args);
String world = ArgumentUtils.handleWorld(2, args);
if (args.size() == 2) {
result = holder.inheritsPermissionInfo(new NodeBuilder(args.get(0)).setServer(args.get(1)).build());
} else {
result = holder.inheritsPermissionInfo(new NodeBuilder(args.get(0)).setServer(args.get(1)).setWorld(args.get(2)).build());
}
} else {
result = holder.inheritsPermissionInfo(new NodeBuilder(args.get(0)).build());
InheritanceInfo result = null;
switch (ContextHelper.determine(server, world)) {
case NONE:
result = holder.inheritsPermissionInfo(new NodeBuilder(node).build());
break;
case SERVER:
result = holder.inheritsPermissionInfo(new NodeBuilder(node).setServer(server).build());
break;
case SERVER_AND_WORLD:
result = holder.inheritsPermissionInfo(new NodeBuilder(node).setServer(server).setWorld(world).build());
break;
}
String location = null;
@ -78,7 +73,7 @@ public class PermissionCheckInherits extends SecondarySubCommand {
}
}
Util.sendPluginMessage(sender, "&b" + args.get(0) + ": " + Util.formatTristate(result.getResult()) +
Util.sendPluginMessage(sender, "&b" + node + ": " + Util.formatTristate(result.getResult()) +
(result.getLocation().isPresent() ? " &7(inherited from &a" + location + "&7)" : ""));
return CommandResult.SUCCESS;
}

View File

@ -23,6 +23,7 @@
package me.lucko.luckperms.common.commands.generic.permission;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.Util;
@ -40,7 +41,7 @@ public class PermissionInfo extends SecondarySubCommand {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) throws CommandException {
Message.LISTNODES.send(sender, holder.getFriendlyName(), Util.permNodesToString(holder.getPermissions(false)));
Message.LISTNODES_TEMP.send(sender, holder.getFriendlyName(), Util.tempNodesToString(holder.getPermissions(false)));
return CommandResult.SUCCESS;

View File

@ -23,25 +23,24 @@
package me.lucko.luckperms.common.commands.generic.permission;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.commands.generic.SecondarySubCommand;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.PermissionHolder;
import me.lucko.luckperms.common.data.LogEntry;
import me.lucko.luckperms.common.utils.ArgumentChecker;
import me.lucko.luckperms.common.utils.Predicates;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import java.util.List;
import java.util.stream.Collectors;
import static me.lucko.luckperms.common.commands.SubCommand.getBoolTabComplete;
public class PermissionSet extends SecondarySubCommand {
public PermissionSet() {
super("set", "Sets a permission for the object", Permission.USER_PERM_SET, Permission.GROUP_PERM_SET, Predicates.notInRange(2, 4),
super("set", "Sets a permission for the object", Permission.USER_PERM_SET, Permission.GROUP_PERM_SET,
Predicates.notInRange(2, 4),
Arg.list(
Arg.create("node", true, "the permission node to set"),
Arg.create("true|false", true, "the value of the node"),
@ -52,60 +51,36 @@ public class PermissionSet extends SecondarySubCommand {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
String node = args.get(0).replace("{SPACE}", " ");
String bool = args.get(1).toLowerCase();
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) throws CommandException {
String node = ArgumentUtils.handleNode(0, args);
boolean b = ArgumentUtils.handleBoolean(1, args);
if (ArgumentChecker.checkNode(node)) {
sendDetailedUsage(sender);
return CommandResult.INVALID_ARGS;
}
if (node.toLowerCase().startsWith("group.")) {
Message.USE_INHERIT_COMMAND.send(sender);
return CommandResult.INVALID_ARGS;
}
if (!bool.equalsIgnoreCase("true") && !bool.equalsIgnoreCase("false")) {
sendDetailedUsage(sender);
return CommandResult.INVALID_ARGS;
}
boolean b = Boolean.parseBoolean(bool);
String server = ArgumentUtils.handleServer(2, args);
String world = ArgumentUtils.handleWorld(3, args);
try {
if (args.size() >= 3) {
final String server = args.get(2).toLowerCase();
if (ArgumentChecker.checkServer(server)) {
Message.SERVER_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
if (args.size() == 3) {
switch (ContextHelper.determine(server, world)) {
case NONE:
holder.setPermission(node, b);
Message.SETPERMISSION_SUCCESS.send(sender, node, b, holder.getFriendlyName());
break;
case SERVER:
holder.setPermission(node, b, server);
Message.SETPERMISSION_SERVER_SUCCESS.send(sender, node, bool, holder.getFriendlyName(), server);
LogEntry.build().actor(sender).acted(holder)
.action("permission set " + node + " " + b + " " + server)
.build().submit(plugin, sender);
} else {
final String world = args.get(3).toLowerCase();
Message.SETPERMISSION_SERVER_SUCCESS.send(sender, node, b, holder.getFriendlyName(), server);
break;
case SERVER_AND_WORLD:
holder.setPermission(node, b, server, world);
Message.SETPERMISSION_SERVER_WORLD_SUCCESS.send(sender, node, bool, holder.getFriendlyName(), server, world);
LogEntry.build().actor(sender).acted(holder)
.action("permission set " + node + " " + b + " " + server + " " + world)
.build().submit(plugin, sender);
}
} else {
holder.setPermission(node, b);
Message.SETPERMISSION_SUCCESS.send(sender, node, bool, holder.getFriendlyName());
LogEntry.build().actor(sender).acted(holder)
.action("permission set " + node + " " + b)
.build().submit(plugin, sender);
Message.SETPERMISSION_SERVER_WORLD_SUCCESS.send(sender, node, b, holder.getFriendlyName(), server, world);
break;
}
LogEntry.build().actor(sender).acted(holder)
.action("permission set " + args.stream().map(ArgumentUtils.WRAPPER).collect(Collectors.joining(" ")))
.build().submit(plugin, sender);
save(holder, sender, plugin);
return CommandResult.SUCCESS;
} catch (ObjectAlreadyHasException e) {
Message.ALREADY_HASPERMISSION.send(sender, holder.getFriendlyName());
return CommandResult.STATE_ERROR;

View File

@ -23,27 +23,25 @@
package me.lucko.luckperms.common.commands.generic.permission;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.commands.generic.SecondarySubCommand;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.PermissionHolder;
import me.lucko.luckperms.common.data.LogEntry;
import me.lucko.luckperms.common.utils.ArgumentChecker;
import me.lucko.luckperms.common.utils.DateUtil;
import me.lucko.luckperms.common.utils.Predicates;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import java.util.List;
import java.util.stream.Collectors;
import static me.lucko.luckperms.common.commands.SubCommand.getBoolTabComplete;
public class PermissionSetTemp extends SecondarySubCommand {
public PermissionSetTemp() {
super("settemp", "Sets a permission for the object temporarily", Permission.USER_PERM_SETTEMP, Permission.GROUP_PERM_SETTEMP,
Predicates.notInRange(3, 5),
super("settemp", "Sets a permission for the object temporarily", Permission.USER_PERM_SETTEMP,
Permission.GROUP_PERM_SETTEMP, Predicates.notInRange(3, 5),
Arg.list(
Arg.create("node", true, "the permission node to set"),
Arg.create("true|false", true, "the value of the node"),
@ -55,79 +53,44 @@ public class PermissionSetTemp extends SecondarySubCommand {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
String node = args.get(0).replace("{SPACE}", " ");
String bool = args.get(1).toLowerCase();
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) throws CommandException {
String node = ArgumentUtils.handleNode(0, args);
boolean b = ArgumentUtils.handleBoolean(1, args);
if (ArgumentChecker.checkNode(node)) {
sendDetailedUsage(sender);
return CommandResult.INVALID_ARGS;
}
long duration = ArgumentUtils.handleDuration(2, args);
if (node.toLowerCase().startsWith("group.")) {
Message.USE_INHERIT_COMMAND.send(sender);
return CommandResult.INVALID_ARGS;
}
if (!bool.equalsIgnoreCase("true") && !bool.equalsIgnoreCase("false")) {
sendDetailedUsage(sender);
return CommandResult.INVALID_ARGS;
}
boolean b = Boolean.parseBoolean(bool);
long duration;
try {
duration = Long.parseLong(args.get(2));
} catch (NumberFormatException e) {
try {
duration = DateUtil.parseDateDiff(args.get(2), true);
} catch (DateUtil.IllegalDateException e1) {
Message.ILLEGAL_DATE_ERROR.send(sender, args.get(2));
return CommandResult.INVALID_ARGS;
}
}
if (DateUtil.shouldExpire(duration)) {
Message.PAST_DATE_ERROR.send(sender);
return CommandResult.INVALID_ARGS;
}
String server = ArgumentUtils.handleServer(3, args);
String world = ArgumentUtils.handleWorld(4, args);
try {
if (args.size() >= 4) {
final String server = args.get(3).toLowerCase();
if (ArgumentChecker.checkServer(server)) {
Message.SERVER_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
if (args.size() == 4) {
switch (ContextHelper.determine(server, world)) {
case NONE:
holder.setPermission(node, b, duration);
Message.SETPERMISSION_TEMP_SUCCESS.send(sender, node, b, holder.getFriendlyName(),
DateUtil.formatDateDiff(duration)
);
break;
case SERVER:
holder.setPermission(node, b, server, duration);
Message.SETPERMISSION_TEMP_SERVER_SUCCESS.send(sender, node, bool, holder.getFriendlyName(), server,
DateUtil.formatDateDiff(duration));
LogEntry.build().actor(sender).acted(holder)
.action("permission settemp " + node + " " + b + " " + duration + " " + server)
.build().submit(plugin, sender);
} else {
final String world = args.get(4).toLowerCase();
Message.SETPERMISSION_TEMP_SERVER_SUCCESS.send(sender, node, b, holder.getFriendlyName(), server,
DateUtil.formatDateDiff(duration)
);
break;
case SERVER_AND_WORLD:
holder.setPermission(node, b, server, world, duration);
Message.SETPERMISSION_TEMP_SERVER_WORLD_SUCCESS.send(sender, node, bool, holder.getFriendlyName(), server,
world, DateUtil.formatDateDiff(duration));
LogEntry.build().actor(sender).acted(holder)
.action("permission settemp " + node + " " + b + " " + duration + " " + server + " " + world)
.build().submit(plugin, sender);
}
} else {
holder.setPermission(node, b, duration);
Message.SETPERMISSION_TEMP_SUCCESS.send(sender, node, bool, holder.getFriendlyName(), DateUtil.formatDateDiff(duration));
LogEntry.build().actor(sender).acted(holder)
.action("permission settemp " + node + " " + b + " " + duration)
.build().submit(plugin, sender);
Message.SETPERMISSION_TEMP_SERVER_WORLD_SUCCESS.send(sender, node, b, holder.getFriendlyName(),
server, world, DateUtil.formatDateDiff(duration)
);
break;
}
LogEntry.build().actor(sender).acted(holder)
.action("permission settemp " + args.stream().map(ArgumentUtils.WRAPPER).collect(Collectors.joining(" ")))
.build().submit(plugin, sender);
save(holder, sender, plugin);
return CommandResult.SUCCESS;
} catch (ObjectAlreadyHasException e) {
Message.ALREADY_HAS_TEMP_PERMISSION.send(sender, holder.getFriendlyName());
return CommandResult.STATE_ERROR;

View File

@ -23,23 +23,22 @@
package me.lucko.luckperms.common.commands.generic.permission;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.commands.generic.SecondarySubCommand;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.PermissionHolder;
import me.lucko.luckperms.common.data.LogEntry;
import me.lucko.luckperms.common.utils.ArgumentChecker;
import me.lucko.luckperms.common.utils.Predicates;
import me.lucko.luckperms.exceptions.ObjectLacksException;
import java.util.List;
import java.util.stream.Collectors;
public class PermissionUnset extends SecondarySubCommand {
public PermissionUnset() {
super("unset", "Unsets a permission for the object", Permission.USER_PERM_UNSET, Permission.GROUP_PERM_UNSET, Predicates.notInRange(1, 3),
super("unset", "Unsets a permission for the object", Permission.USER_PERM_UNSET, Permission.GROUP_PERM_UNSET,
Predicates.notInRange(1, 3),
Arg.list(
Arg.create("node", true, "the permission node to unset"),
Arg.create("server", false, "the server to remove the permission node on"),
@ -49,52 +48,34 @@ public class PermissionUnset extends SecondarySubCommand {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
String node = args.get(0).replace("{SPACE}", " ");
if (ArgumentChecker.checkNode(node)) {
sendDetailedUsage(sender);
return CommandResult.INVALID_ARGS;
}
if (node.toLowerCase().startsWith("group.")) {
Message.USE_UNINHERIT_COMMAND.send(sender);
return CommandResult.INVALID_ARGS;
}
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) throws CommandException {
String node = ArgumentUtils.handleNode(0, args);
String server = ArgumentUtils.handleServer(1, args);
String world = ArgumentUtils.handleWorld(2, args);
try {
if (args.size() >= 2) {
final String server = args.get(1).toLowerCase();
if (ArgumentChecker.checkServer(server)) {
Message.SERVER_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
if (args.size() == 2) {
switch (ContextHelper.determine(server, world)) {
case NONE:
holder.unsetPermission(node);
Message.UNSETPERMISSION_SUCCESS.send(sender, node, holder.getFriendlyName());
break;
case SERVER:
holder.unsetPermission(node, server);
Message.UNSETPERMISSION_SERVER_SUCCESS.send(sender, node, holder.getFriendlyName(), server);
LogEntry.build().actor(sender).acted(holder)
.action("permission unset " + node + " " + server)
.build().submit(plugin, sender);
} else {
final String world = args.get(2).toLowerCase();
break;
case SERVER_AND_WORLD:
holder.unsetPermission(node, server, world);
Message.UNSETPERMISSION_SERVER_WORLD_SUCCESS.send(sender, node, holder.getFriendlyName(), server, world);
LogEntry.build().actor(sender).acted(holder)
.action("permission unset " + node + " " + server + " " + world)
.build().submit(plugin, sender);
}
} else {
holder.unsetPermission(node);
Message.UNSETPERMISSION_SUCCESS.send(sender, node, holder.getFriendlyName());
LogEntry.build().actor(sender).acted(holder)
.action("permission unset " + node)
.build().submit(plugin, sender);
break;
}
LogEntry.build().actor(sender).acted(holder)
.action("permission unset " + args.stream().map(ArgumentUtils.WRAPPER).collect(Collectors.joining(" ")))
.build().submit(plugin, sender);
save(holder, sender, plugin);
return CommandResult.SUCCESS;
} catch (ObjectLacksException e) {
Message.DOES_NOT_HAVEPERMISSION.send(sender, holder.getFriendlyName());
return CommandResult.STATE_ERROR;

View File

@ -23,24 +23,22 @@
package me.lucko.luckperms.common.commands.generic.permission;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.commands.generic.SecondarySubCommand;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.PermissionHolder;
import me.lucko.luckperms.common.data.LogEntry;
import me.lucko.luckperms.common.utils.ArgumentChecker;
import me.lucko.luckperms.common.utils.Predicates;
import me.lucko.luckperms.exceptions.ObjectLacksException;
import java.util.List;
import java.util.stream.Collectors;
public class PermissionUnsetTemp extends SecondarySubCommand {
public PermissionUnsetTemp() {
super("unsettemp", "Unsets a temporary permission for the object", Permission.USER_PERM_UNSETTEMP, Permission.GROUP_PERM_UNSETTEMP,
Predicates.notInRange(1, 3),
super("unsettemp", "Unsets a temporary permission for the object", Permission.USER_PERM_UNSETTEMP,
Permission.GROUP_PERM_UNSETTEMP, Predicates.notInRange(1, 3),
Arg.list(
Arg.create("node", true, "the permission node to unset"),
Arg.create("server", false, "the server to remove the permission node on"),
@ -50,52 +48,34 @@ public class PermissionUnsetTemp extends SecondarySubCommand {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
String node = args.get(0).replace("{SPACE}", " ");
if (ArgumentChecker.checkNode(node)) {
sendDetailedUsage(sender);
return CommandResult.INVALID_ARGS;
}
if (node.toLowerCase().startsWith("group.")) {
Message.USE_UNINHERIT_COMMAND.send(sender);
return CommandResult.INVALID_ARGS;
}
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) throws CommandException {
String node = ArgumentUtils.handleNode(0, args);
String server = ArgumentUtils.handleServer(1, args);
String world = ArgumentUtils.handleWorld(2, args);
try {
if (args.size() >= 2) {
final String server = args.get(1).toLowerCase();
if (ArgumentChecker.checkServer(server)) {
Message.SERVER_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
if (args.size() == 2) {
holder.unsetPermission(node, server);
switch (ContextHelper.determine(server, world)) {
case NONE:
holder.unsetPermission(node, true);
Message.UNSET_TEMP_PERMISSION_SUCCESS.send(sender, node, holder.getFriendlyName());
break;
case SERVER:
holder.unsetPermission(node, server, true);
Message.UNSET_TEMP_PERMISSION_SERVER_SUCCESS.send(sender, node, holder.getFriendlyName(), server);
LogEntry.build().actor(sender).acted(holder)
.action("permission unsettemp " + node + " " + server)
.build().submit(plugin, sender);
} else {
final String world = args.get(2).toLowerCase();
holder.unsetPermission(node, server, world);
break;
case SERVER_AND_WORLD:
holder.unsetPermission(node, server, world, true);
Message.UNSET_TEMP_PERMISSION_SERVER_WORLD_SUCCESS.send(sender, node, holder.getFriendlyName(), server, world);
LogEntry.build().actor(sender).acted(holder)
.action("permission unsettemp " + node + " " + server + " " + world)
.build().submit(plugin, sender);
}
} else {
holder.unsetPermission(node, true);
Message.UNSET_TEMP_PERMISSION_SUCCESS.send(sender, node, holder.getFriendlyName());
LogEntry.build().actor(sender).acted(holder)
.action("permission unsettemp " + node)
.build().submit(plugin, sender);
break;
}
LogEntry.build().actor(sender).acted(holder)
.action("permission unsettemp " + args.stream().map(ArgumentUtils.WRAPPER).collect(Collectors.joining(" ")))
.build().submit(plugin, sender);
save(holder, sender, plugin);
return CommandResult.SUCCESS;
} catch (ObjectLacksException e) {
Message.DOES_NOT_HAVE_TEMP_PERMISSION.send(sender, holder.getFriendlyName());
return CommandResult.STATE_ERROR;

View File

@ -24,10 +24,7 @@ package me.lucko.luckperms.common.commands.group.subcommands;
import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.NodeFactory;
@ -53,7 +50,7 @@ public class GroupBulkChange extends SubCommand<Group> {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) throws CommandException {
String type = args.get(0).toLowerCase();
String from = args.get(1);
String to = args.get(2);

View File

@ -23,15 +23,11 @@
package me.lucko.luckperms.common.commands.group.subcommands;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.data.LogEntry;
import me.lucko.luckperms.common.groups.Group;
import me.lucko.luckperms.common.utils.ArgumentChecker;
import me.lucko.luckperms.common.utils.Predicates;
import java.util.List;
@ -48,25 +44,22 @@ public class GroupClear extends SubCommand<Group> {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) throws CommandException {
int before = group.getNodes().size();
if (args.size() == 0) {
group.clearNodes();
} else {
final String server = args.get(0);
if (ArgumentChecker.checkServer(server)) {
Message.SERVER_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
String server = ArgumentUtils.handleServer(0, args);
String world = ArgumentUtils.handleWorld(1, args);
if (args.size() == 2) {
final String world = args.get(1);
group.clearNodes(server, world);
} else {
switch (ContextHelper.determine(server, world)) {
case NONE:
group.clearNodes();
break;
case SERVER:
group.clearNodes(server);
}
break;
case SERVER_AND_WORLD:
group.clearNodes(server, world);
break;
}
int changed = before - group.getNodes().size();
@ -76,7 +69,10 @@ public class GroupClear extends SubCommand<Group> {
Message.CLEAR_SUCCESS.send(sender, group.getName(), changed);
}
LogEntry.build().actor(sender).acted(group).action("clear " + args.stream().collect(Collectors.joining(" "))).build().submit(plugin, sender);
LogEntry.build().actor(sender).acted(group)
.action("clear " + args.stream().map(ArgumentUtils.WRAPPER).collect(Collectors.joining(" ")))
.build().submit(plugin, sender);
save(group, sender, plugin);
return CommandResult.SUCCESS;
}

View File

@ -23,10 +23,7 @@
package me.lucko.luckperms.common.commands.group.subcommands;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.data.LogEntry;
@ -44,7 +41,7 @@ public class GroupClone extends SubCommand<Group> {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) throws CommandException {
String newGroupName = args.get(0).toLowerCase();
if (ArgumentChecker.checkName(newGroupName)) {
Message.GROUP_INVALID_ENTRY.send(sender);

View File

@ -23,6 +23,7 @@
package me.lucko.luckperms.common.commands.group.subcommands;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.SubCommand;
@ -39,7 +40,7 @@ public class GroupInfo extends SubCommand<Group> {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) throws CommandException {
Message.GROUP_INFO.send(sender,
group.getDisplayName(),
group.getPermanentNodes().size(),

View File

@ -23,10 +23,7 @@
package me.lucko.luckperms.common.commands.group.subcommands;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.data.LogEntry;
@ -44,7 +41,7 @@ public class GroupRename extends SubCommand<Group> {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) throws CommandException {
String newGroupName = args.get(0).toLowerCase();
if (ArgumentChecker.checkName(newGroupName)) {
Message.GROUP_INVALID_ENTRY.send(sender);

View File

@ -24,10 +24,7 @@ package me.lucko.luckperms.common.commands.log.subcommands;
import me.lucko.luckperms.api.LogEntry;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.data.Log;
@ -48,7 +45,7 @@ public class LogExport extends SubCommand<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, List<String> args, String label) throws CommandException {
File f = new File(plugin.getMainDir(), args.get(0));
if (f.exists()) {
Message.LOG_EXPORT_ALREADY_EXISTS.send(sender, f.getAbsolutePath());

View File

@ -24,10 +24,7 @@ package me.lucko.luckperms.common.commands.log.subcommands;
import me.lucko.luckperms.api.LogEntry;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.data.Log;
@ -50,7 +47,7 @@ public class LogGroupHistory extends SubCommand<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, List<String> args, String label) throws CommandException {
String group = args.get(0).toLowerCase();
int page = -999;

View File

@ -23,10 +23,7 @@
package me.lucko.luckperms.common.commands.log.subcommands;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.data.Log;
@ -44,7 +41,7 @@ public class LogNotify extends SubCommand<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, List<String> args, String label) throws CommandException {
final Set<UUID> ignoring = plugin.getIgnoringLogs();
final UUID uuid = sender.getUuid();
if (args.size() == 0) {

View File

@ -48,7 +48,7 @@ public class LogRecent extends SubCommand<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, List<String> args, String label) throws CommandException {
if (args.size() == 0) {
// No page or user
return showLog(log.getRecentMaxPages(), null, sender, log);

View File

@ -24,10 +24,7 @@ package me.lucko.luckperms.common.commands.log.subcommands;
import me.lucko.luckperms.api.LogEntry;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.data.Log;
@ -50,7 +47,7 @@ public class LogSearch extends SubCommand<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, List<String> args, String label) throws CommandException {
int page = -999;
if (args.size() > 1) {
try {

View File

@ -24,10 +24,7 @@ package me.lucko.luckperms.common.commands.log.subcommands;
import me.lucko.luckperms.api.LogEntry;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.data.Log;
@ -50,7 +47,7 @@ public class LogTrackHistory extends SubCommand<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, List<String> args, String label) throws CommandException {
String track = args.get(0).toLowerCase();
int page = -999;

View File

@ -48,7 +48,7 @@ public class LogUserHistory extends SubCommand<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, List<String> args, String label) throws CommandException {
String user = args.get(0);
int page = -999;

View File

@ -43,7 +43,7 @@ public class TrackAppend extends SubCommand<Track> {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) throws CommandException {
String groupName = args.get(0).toLowerCase();
if (ArgumentChecker.checkNode(groupName)) {

View File

@ -23,6 +23,7 @@
package me.lucko.luckperms.common.commands.track.subcommands;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.SubCommand;
@ -40,7 +41,7 @@ public class TrackClear extends SubCommand<Track> {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) throws CommandException {
track.clearGroups();
Message.TRACK_CLEAR.send(sender, track.getName());
LogEntry.build().actor(sender).acted(track).action("clear").build().submit(plugin, sender);

View File

@ -23,10 +23,7 @@
package me.lucko.luckperms.common.commands.track.subcommands;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.data.LogEntry;
@ -44,7 +41,7 @@ public class TrackClone extends SubCommand<Track> {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) throws CommandException {
String newTrackName = args.get(0).toLowerCase();
if (ArgumentChecker.checkName(newTrackName)) {
Message.TRACK_INVALID_ENTRY.send(sender);

View File

@ -23,10 +23,7 @@
package me.lucko.luckperms.common.commands.track.subcommands;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.Util;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.tracks.Track;
@ -40,7 +37,7 @@ public class TrackInfo extends SubCommand<Track> {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) throws CommandException {
Message.TRACK_INFO.send(sender, track.getName(), Util.listToArrowSep(track.getGroups()));
return CommandResult.SUCCESS;
}

View File

@ -46,7 +46,7 @@ public class TrackInsert extends SubCommand<Track> {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) throws CommandException {
String groupName = args.get(0).toLowerCase();
if (ArgumentChecker.checkNode(groupName)) {

View File

@ -42,7 +42,7 @@ public class TrackRemove extends SubCommand<Track> {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) throws CommandException {
String groupName = args.get(0).toLowerCase();
if (ArgumentChecker.checkNode(groupName)) {

View File

@ -23,10 +23,7 @@
package me.lucko.luckperms.common.commands.track.subcommands;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.data.LogEntry;
@ -44,7 +41,7 @@ public class TrackRename extends SubCommand<Track> {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) throws CommandException {
String newTrackName = args.get(0).toLowerCase();
if (ArgumentChecker.checkName(newTrackName)) {
Message.TRACK_INVALID_ENTRY.send(sender);

View File

@ -24,10 +24,7 @@ package me.lucko.luckperms.common.commands.user.subcommands;
import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.NodeFactory;
@ -53,7 +50,7 @@ public class UserBulkChange extends SubCommand<User> {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) throws CommandException {
String type = args.get(0).toLowerCase();
String from = args.get(1);
String to = args.get(2);

View File

@ -23,15 +23,11 @@
package me.lucko.luckperms.common.commands.user.subcommands;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.data.LogEntry;
import me.lucko.luckperms.common.users.User;
import me.lucko.luckperms.common.utils.ArgumentChecker;
import me.lucko.luckperms.common.utils.Predicates;
import java.util.List;
@ -48,25 +44,22 @@ public class UserClear extends SubCommand<User> {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) throws CommandException {
int before = user.getNodes().size();
if (args.size() == 0) {
user.clearNodes();
} else {
final String server = args.get(0);
if (ArgumentChecker.checkServer(server)) {
Message.SERVER_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
String server = ArgumentUtils.handleServer(0, args);
String world = ArgumentUtils.handleWorld(1, args);
if (args.size() == 2) {
final String world = args.get(1);
user.clearNodes(server, world);
} else {
switch (ContextHelper.determine(server, world)) {
case NONE:
user.clearNodes();
break;
case SERVER:
user.clearNodes(server);
}
break;
case SERVER_AND_WORLD:
user.clearNodes(server, world);
break;
}
int changed = before - user.getNodes().size();
@ -76,7 +69,10 @@ public class UserClear extends SubCommand<User> {
Message.CLEAR_SUCCESS.send(sender, user.getName(), changed);
}
LogEntry.build().actor(sender).acted(user).action("clear " + args.stream().collect(Collectors.joining(" "))).build().submit(plugin, sender);
LogEntry.build().actor(sender).acted(user)
.action("clear " + args.stream().map(ArgumentUtils.WRAPPER).collect(Collectors.joining(" ")))
.build().submit(plugin, sender);
save(user, sender, plugin);
return CommandResult.SUCCESS;
}

View File

@ -59,7 +59,7 @@ public class UserDemote extends SubCommand<User> {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) throws CommandException {
final String trackName = args.get(0).toLowerCase();
if (ArgumentChecker.checkName(trackName)) {
Message.TRACK_INVALID_ENTRY.send(sender);
@ -82,19 +82,8 @@ public class UserDemote extends SubCommand<User> {
return CommandResult.STATE_ERROR;
}
String server = null;
String world = null;
if (args.size() > 1) {
server = args.get(1);
if (ArgumentChecker.checkServer(server)) {
Message.SERVER_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
if (args.size() > 2) {
world = args.get(2);
}
}
String server = ArgumentUtils.handleServer(1, args);
String world = ArgumentUtils.handleWorld(2, args);
// Load applicable groups
Set<Node> nodes = new HashSet<>();

View File

@ -23,6 +23,7 @@
package me.lucko.luckperms.common.commands.user.subcommands;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.SubCommand;
@ -39,7 +40,7 @@ public class UserGetUUID extends SubCommand<User> {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) throws CommandException {
Message.USER_GETUUID.send(sender, user.getName(), user.getUuid().toString());
return CommandResult.SUCCESS;
}

View File

@ -23,6 +23,7 @@
package me.lucko.luckperms.common.commands.user.subcommands;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.SubCommand;
@ -39,7 +40,7 @@ public class UserInfo extends SubCommand<User> {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) throws CommandException {
Message.USER_INFO.send(sender,
user.getName(),
user.getUuid(),

View File

@ -59,7 +59,7 @@ public class UserPromote extends SubCommand<User> {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) throws CommandException {
final String trackName = args.get(0).toLowerCase();
if (ArgumentChecker.checkName(trackName)) {
Message.TRACK_INVALID_ENTRY.send(sender);
@ -82,19 +82,8 @@ public class UserPromote extends SubCommand<User> {
return CommandResult.STATE_ERROR;
}
String server = null;
String world = null;
if (args.size() > 1) {
server = args.get(1);
if (ArgumentChecker.checkServer(server)) {
Message.SERVER_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
if (args.size() > 2) {
world = args.get(2);
}
}
String server = ArgumentUtils.handleServer(1, args);
String world = ArgumentUtils.handleWorld(2, args);
// Load applicable groups
Set<Node> nodes = new HashSet<>();

View File

@ -23,10 +23,7 @@
package me.lucko.luckperms.common.commands.user.subcommands;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.data.LogEntry;
@ -45,7 +42,7 @@ public class UserSetPrimaryGroup extends SubCommand<User> {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) throws CommandException {
Group group = plugin.getGroupManager().get(args.get(0).toLowerCase());
if (group == null) {
Message.GROUP_DOES_NOT_EXIST.send(sender);

View File

@ -24,10 +24,7 @@ package me.lucko.luckperms.common.commands.usersbulkedit.subcommands;
import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.NodeFactory;
@ -52,7 +49,7 @@ public class BulkEditGroup extends SubCommand<Datastore> {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Datastore datastore, List<String> args, String label) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Datastore datastore, List<String> args, String label) throws CommandException {
String group = args.get(0);
String type = args.get(1).toLowerCase();
String from = args.get(2);

View File

@ -24,10 +24,7 @@ package me.lucko.luckperms.common.commands.usersbulkedit.subcommands;
import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.NodeFactory;
@ -52,7 +49,7 @@ public class BulkEditPermission extends SubCommand<Datastore> {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Datastore datastore, List<String> args, String label) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Datastore datastore, List<String> args, String label) throws CommandException {
String node = args.get(0);
String type = args.get(1).toLowerCase();
String from = args.get(2);

View File

@ -77,8 +77,7 @@ public enum Message {
GROUP_INVALID_ENTRY("Group names can only contain alphanumeric characters.", true),
TRACK_INVALID_ENTRY("Track names can only contain alphanumeric characters.", true),
SERVER_INVALID_ENTRY("Server names can only contain alphanumeric characters.", true),
USE_INHERIT_COMMAND("Use the 'parent add' command instead of specifying the node.", true),
USE_UNINHERIT_COMMAND("Use the 'parent remove' command instead of specifying the node.", true),
USE_INHERIT_COMMAND("Use the 'parent add' and 'parent remove' commands instead of specifying the node.", true),
/*

View File

@ -41,7 +41,6 @@ track-invalid-entry: "Track names can only contain alphanumeric characters."
server-invalid-entry: "Server names can only contain alphanumeric characters."
use-inherit-command: "Use the 'parent add' command instead of specifying the node."
use-uninherit-command: "Use the 'parent remove' command instead of specifying the node."

View File

@ -26,10 +26,7 @@ import me.lucko.luckperms.api.Logger;
import me.lucko.luckperms.api.context.ContextSet;
import me.lucko.luckperms.api.context.MutableContextSet;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.Util;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.NodeBuilder;
import me.lucko.luckperms.common.core.PermissionHolder;
@ -52,7 +49,7 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
final Logger log = plugin.getLog();
Optional<PluginContainer> pex = Sponge.getPluginManager().getPlugin("permissionsex");