Use generics for sub commands, fix user lookup bugs

This commit is contained in:
Luck 2016-08-03 00:54:50 +02:00
parent 98c5a91beb
commit 5e23b6961e
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
60 changed files with 570 additions and 794 deletions

View File

@ -114,7 +114,7 @@ public class CommandManager {
} }
final MainCommand main = o.get(); final MainCommand main = o.get();
if (!main.canUse(sender)) { if (!main.isAuthorized(sender)) {
sendCommandUsage(sender, label); sendCommandUsage(sender, label);
return true; return true;
} }
@ -140,8 +140,9 @@ public class CommandManager {
* @param args the arguments provided so far * @param args the arguments provided so far
* @return a list of suggestions * @return a list of suggestions
*/ */
@SuppressWarnings("unchecked")
public List<String> onTabComplete(Sender sender, List<String> args) { public List<String> onTabComplete(Sender sender, List<String> args) {
final List<MainCommand> mains = mainCommands.stream().filter(m -> m.canUse(sender)).collect(Collectors.toList()); final List<MainCommand> mains = mainCommands.stream().filter(m -> m.isAuthorized(sender)).collect(Collectors.toList());
if (args.size() <= 1) { if (args.size() <= 1) {
if (args.isEmpty() || args.get(0).equalsIgnoreCase("")) { if (args.isEmpty() || args.get(0).equalsIgnoreCase("")) {
@ -169,7 +170,7 @@ public class CommandManager {
Message.INFO_BRIEF.send(sender, plugin.getVersion()); Message.INFO_BRIEF.send(sender, plugin.getVersion());
mainCommands.stream() mainCommands.stream()
.filter(c -> c.canUse(sender)) .filter(c -> c.isAuthorized(sender))
.forEach(c -> Util.sendPluginMessage(sender, "&e-> &d" + String.format(c.getUsage(), label))); .forEach(c -> Util.sendPluginMessage(sender, "&e-> &d" + String.format(c.getUsage(), label)));
} }
} }

View File

@ -1,27 +1,103 @@
package me.lucko.luckperms.commands; package me.lucko.luckperms.commands;
import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.api.data.Callback;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Getter @Getter
@AllArgsConstructor @RequiredArgsConstructor
public abstract class MainCommand { public abstract class MainCommand<T> {
/**
* The name of the main command
*/
private final String name; private final String name;
/**
* The command usage
*/
private final String usage; private final String usage;
/**
* How many arguments are required for the command to run
*/
private final int requiredArgsLength; private final int requiredArgsLength;
protected abstract void execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label); /**
protected abstract List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin); * A list of the sub commands under this main command
public abstract List<? extends SubCommand> getSubCommands(); */
@Getter
private final List<SubCommand<T>> subCommands = new ArrayList<>();
/**
* Called when this main command is ran
* @param plugin a link to the main plugin instance
* @param sender the sender to executed the command
* @param args the stripped arguments given
* @param label the command label used
*/
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
if (args.size() < 2) {
sendUsage(sender, label);
return;
}
Optional<SubCommand<T>> o = subCommands.stream().filter(s -> s.getName().equalsIgnoreCase(args.get(1))).limit(1).findAny();
if (!o.isPresent()) {
Message.COMMAND_NOT_RECOGNISED.send(sender);
return;
}
final SubCommand<T> sub = o.get();
if (!sub.isAuthorized(sender)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
List<String> strippedArgs = new ArrayList<>();
if (args.size() > 2) {
strippedArgs.addAll(args.subList(2, args.size()));
}
if (sub.getIsArgumentInvalid().test(strippedArgs.size())) {
sub.sendUsage(sender, label);
return;
}
final String name = args.get(0).toLowerCase();
getTarget(name, plugin, sender, t -> sub.execute(plugin, sender, t, strippedArgs, label));
}
/**
* 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
* @param plugin a link to the main plugin instance
* @param sender the user who send the command (used to send error messages if the lookup was unsuccessful)
* @param onSuccess the callback to run when the lookup is completed
*/
protected abstract void getTarget(String target, LuckPermsPlugin plugin, Sender sender, Callback<T> onSuccess);
/**
* Get a list of objects for tab completion
* @param plugin a link to the main plugin instance
* @return a list of strings
*/
protected abstract List<String> getObjects(LuckPermsPlugin plugin);
/**
* Send the command usage to a sender
* @param sender the sender to send the usage to
* @param label the command label used
*/
protected void sendUsage(Sender sender, String label) { protected void sendUsage(Sender sender, String label) {
if (getSubCommands().isEmpty()) { if (getSubCommands().isEmpty()) {
Util.sendPluginMessage(sender, "&e-> &d" + String.format(getUsage(), label)); Util.sendPluginMessage(sender, "&e-> &d" + String.format(getUsage(), label));
@ -41,12 +117,27 @@ public abstract class MainCommand {
} }
} }
protected boolean canUse(Sender sender) { /**
* If a sender has permission to use this command
* @param sender the sender trying to use the command
* @return true if the sender can use the command
*/
protected boolean isAuthorized(Sender sender) {
return getSubCommands().stream().filter(sc -> sc.isAuthorized(sender)).count() != 0; return getSubCommands().stream().filter(sc -> sc.isAuthorized(sender)).count() != 0;
} }
protected List<String> onAbstractTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) { protected List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
final List<SubCommand> subs = getSubCommands().stream().filter(s -> s.isAuthorized(sender)).collect(Collectors.toList()); final List<String> objects = getObjects(plugin);
if (args.size() <= 1) {
if (args.isEmpty() || args.get(0).equalsIgnoreCase("")) {
return objects;
}
return objects.stream().filter(s -> s.toLowerCase().startsWith(args.get(0).toLowerCase())).collect(Collectors.toList());
}
final List<SubCommand<T>> subs = getSubCommands().stream().filter(s -> s.isAuthorized(sender)).collect(Collectors.toList());
if (args.size() == 2) { if (args.size() == 2) {
if (args.get(1).equalsIgnoreCase("")) { if (args.get(1).equalsIgnoreCase("")) {
return subs.stream().map(SubCommand::getName).map(String::toLowerCase).collect(Collectors.toList()); return subs.stream().map(SubCommand::getName).map(String::toLowerCase).collect(Collectors.toList());
@ -56,11 +147,15 @@ public abstract class MainCommand {
.filter(s -> s.toLowerCase().startsWith(args.get(1).toLowerCase())).collect(Collectors.toList()); .filter(s -> s.toLowerCase().startsWith(args.get(1).toLowerCase())).collect(Collectors.toList());
} }
Optional<SubCommand> o = subs.stream().filter(s -> s.getName().equalsIgnoreCase(args.get(1))).limit(1).findAny(); Optional<SubCommand<T>> o = subs.stream().filter(s -> s.getName().equalsIgnoreCase(args.get(1))).limit(1).findAny();
if (!o.isPresent()) { if (!o.isPresent()) {
return Collections.emptyList(); return Collections.emptyList();
} }
return o.get().onTabComplete(sender, args.subList(2, args.size()), plugin); return o.get().onTabComplete(sender, args.subList(2, args.size()), plugin);
} }
public void registerSubCommand(SubCommand<T> subCommand) {
subCommands.add(subCommand);
}
} }

View File

@ -0,0 +1,43 @@
package me.lucko.luckperms.commands;
import lombok.experimental.UtilityClass;
import java.util.stream.IntStream;
@UtilityClass
public class Predicate {
public static <T> java.util.function.Predicate<T> alwaysFalse() {
return t -> false;
}
public static <T> java.util.function.Predicate<T> alwaysTrue() {
return t -> true;
}
public static java.util.function.Predicate<Integer> notinRange(Integer start, Integer end) {
return inverse(inRange(start, end));
}
public static java.util.function.Predicate<Integer> inRange(Integer start, Integer end) {
return isOneOf(IntStream.rangeClosed(start, end).boxed().toArray(Integer[]::new));
}
public static <T> java.util.function.Predicate<T> notOneOf(T[] ts) {
return inverse(isOneOf(ts));
}
public static <T> java.util.function.Predicate<T> isOneOf(T[] ta) {
return t -> {
for (T i : ta) {
if (i == t) {
return true;
}
}
return false;
};
}
public static <T> java.util.function.Predicate<T> inverse(java.util.function.Predicate<T> t) {
return t2 -> !t.test(t2);
}
}

View File

@ -0,0 +1,36 @@
package me.lucko.luckperms.commands;
import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.api.data.Callback;
import java.util.Collections;
import java.util.List;
/**
* An extension of {@link MainCommand} for implementations without any subcommands
*/
public class SingleMainCommand extends MainCommand<Object> {
public SingleMainCommand(String name, String usage, int requiredArgsLength) {
super(name, usage, requiredArgsLength);
}
@Override
protected void getTarget(String target, LuckPermsPlugin plugin, Sender sender, Callback onSuccess) {
}
@Override
protected List<String> getObjects(LuckPermsPlugin plugin) {
return Collections.emptyList();
}
@Override
protected List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
return Collections.emptyList();
}
@Override
public List<SubCommand<Object>> getSubCommands() {
return Collections.emptyList();
}
}

View File

@ -3,44 +3,78 @@ package me.lucko.luckperms.commands;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.groups.Group;
import me.lucko.luckperms.tracks.Track;
import me.lucko.luckperms.users.User; import me.lucko.luckperms.users.User;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
* Abstract SubCommand class * Abstract SubCommand class
* Doesn't declare any abstract onCommand methods, as sub classes declare their own with parameters unique to the sub command type.
* For example, see: {@link me.lucko.luckperms.commands.user.UserSubCommand#execute(LuckPermsPlugin, Sender, User, List, String)}
*
* SubCommand #execute methods are always called from the {@link MainCommand} class related to them, so abstraction is not needed.
*/ */
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public abstract class SubCommand { public abstract class SubCommand<T> {
/**
* The name of the sub command
*/
private final String name; private final String name;
/**
* A brief description of what the sub command does
*/
private final String description; private final String description;
/**
* The command usage
*/
private final String usage; private final String usage;
/**
* The permission needed to use this command
*/
private final Permission permission; private final Permission permission;
public abstract boolean isArgLengthInvalid(int argLength); /**
* Predicate to test if the argument length given is invalid
*/
private final Predicate<? super Integer> isArgumentInvalid;
public boolean isAuthorized(Sender sender) { /**
return permission.isAuthorized(sender); * Called when this sub command is ran
} * @param plugin a link to the main plugin instance
* @param sender the sender to executed the command
* @param t the object the command is operating on
* @param args the stripped arguments given
* @param label the command label used
*/
public abstract void execute(LuckPermsPlugin plugin, Sender sender, T t, List<String> args, String label);
/**
* Send the command usage to a sender
* @param sender the sender to send the usage to
* @param label the command label used
*/
public void sendUsage(Sender sender, String label) { public void sendUsage(Sender sender, String label) {
Util.sendPluginMessage(sender, "&e-> &d" + String.format(getUsage(), label)); Util.sendPluginMessage(sender, "&e-> &d" + String.format(getUsage(), label));
} }
/* /**
* Returns a list of suggestions, which are empty by default. Sub classes that give tab complete suggestions override * If a sender has permission to use this command
* this method to give their own list. * @param sender the sender trying to use the command
* @return true if the sender can use the command
*/ */
public boolean isAuthorized(Sender sender) {
return permission.isAuthorized(sender);
}
/** /**
* Returns a list of suggestions, which are empty by default. Sub classes that give tab complete suggestions override * Returns a list of suggestions, which are empty by default. Sub classes that give tab complete suggestions override
@ -54,7 +88,12 @@ public abstract class SubCommand {
return Collections.emptyList(); return Collections.emptyList();
} }
/* Utility methods used by #onTabComplete implementations in sub classes */ /*
----------------------------------------------------------------------------------
Utility methods used by #onTabComplete and #execute implementations in sub classes
----------------------------------------------------------------------------------
*/
protected static List<String> getGroupTabComplete(List<String> args, LuckPermsPlugin plugin) { protected static List<String> getGroupTabComplete(List<String> args, LuckPermsPlugin plugin) {
return getTabComplete(new ArrayList<>(plugin.getGroupManager().getGroups().keySet()), args); return getTabComplete(new ArrayList<>(plugin.getGroupManager().getGroups().keySet()), args);
} }
@ -82,4 +121,40 @@ public abstract class SubCommand {
return Collections.emptyList(); return Collections.emptyList();
} }
protected static void saveUser(User user, Sender sender, LuckPermsPlugin plugin) {
user.refreshPermissions();
plugin.getDatastore().saveUser(user, success -> {
if (success) {
Message.USER_SAVE_SUCCESS.send(sender);
} else {
Message.USER_SAVE_ERROR.send(sender);
}
});
}
protected static void saveGroup(Group group, Sender sender, LuckPermsPlugin plugin) {
plugin.getDatastore().saveGroup(group, success -> {
if (success) {
Message.GROUP_SAVE_SUCCESS.send(sender);
} else {
Message.GROUP_SAVE_ERROR.send(sender);
}
plugin.runUpdateTask();
});
}
protected static void saveTrack(Track track, Sender sender, LuckPermsPlugin plugin) {
plugin.getDatastore().saveTrack(track, success -> {
if (success) {
Message.TRACK_SAVE_SUCCESS.send(sender);
} else {
Message.TRACK_SAVE_ERROR.send(sender);
}
plugin.runUpdateTask();
});
}
} }

View File

@ -1,17 +1,15 @@
package me.lucko.luckperms.commands.group; package me.lucko.luckperms.commands.group;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.MainCommand;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand; import me.lucko.luckperms.commands.SingleMainCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.utils.Patterns; import me.lucko.luckperms.utils.Patterns;
import java.util.Collections;
import java.util.List; import java.util.List;
public class CreateGroup extends MainCommand { public class CreateGroup extends SingleMainCommand {
public CreateGroup() { public CreateGroup() {
super("CreateGroup", "/%s creategroup <group>", 1); super("CreateGroup", "/%s creategroup <group>", 1);
} }
@ -52,17 +50,7 @@ public class CreateGroup extends MainCommand {
} }
@Override @Override
protected List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) { protected boolean isAuthorized(Sender sender) {
return Collections.emptyList();
}
@Override
public List<SubCommand> getSubCommands() {
return Collections.emptyList();
}
@Override
protected boolean canUse(Sender sender) {
return Permission.CREATE_GROUP.isAuthorized(sender); return Permission.CREATE_GROUP.isAuthorized(sender);
} }
} }

View File

@ -1,9 +1,8 @@
package me.lucko.luckperms.commands.group; package me.lucko.luckperms.commands.group;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.MainCommand;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand; import me.lucko.luckperms.commands.SingleMainCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.groups.Group; import me.lucko.luckperms.groups.Group;
@ -14,7 +13,7 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class DeleteGroup extends MainCommand { public class DeleteGroup extends SingleMainCommand {
public DeleteGroup() { public DeleteGroup() {
super("DeleteGroup", "/%s deletegroup <group>", 1); super("DeleteGroup", "/%s deletegroup <group>", 1);
} }
@ -76,12 +75,7 @@ public class DeleteGroup extends MainCommand {
} }
@Override @Override
public List<SubCommand> getSubCommands() { protected boolean isAuthorized(Sender sender) {
return Collections.emptyList();
}
@Override
protected boolean canUse(Sender sender) {
return Permission.DELETE_GROUP.isAuthorized(sender); return Permission.DELETE_GROUP.isAuthorized(sender);
} }
} }

View File

@ -1,101 +1,46 @@
package me.lucko.luckperms.commands.group; package me.lucko.luckperms.commands.group;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.api.data.Callback;
import me.lucko.luckperms.commands.MainCommand; import me.lucko.luckperms.commands.MainCommand;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.groups.Group; import me.lucko.luckperms.groups.Group;
import me.lucko.luckperms.utils.Patterns; import me.lucko.luckperms.utils.Patterns;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
public class GroupMainCommand extends MainCommand {
private final List<GroupSubCommand> subCommands = new ArrayList<>();
public class GroupMainCommand extends MainCommand<Group> {
public GroupMainCommand() { public GroupMainCommand() {
super("Group", "/%s group <group>", 2); super("Group", "/%s group <group>", 2);
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) { protected void getTarget(String target, LuckPermsPlugin plugin, Sender sender, Callback<Group> onSuccess) {
if (args.size() < 2) { if (Patterns.NON_ALPHA_NUMERIC.matcher(target).find()) {
sendUsage(sender, label);
return;
}
Optional<GroupSubCommand> o = subCommands.stream().filter(s -> s.getName().equalsIgnoreCase(args.get(1))).limit(1).findAny();
if (!o.isPresent()) {
Message.COMMAND_NOT_RECOGNISED.send(sender);
return;
}
final GroupSubCommand sub = o.get();
if (!sub.isAuthorized(sender)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
List<String> strippedArgs = new ArrayList<>();
if (args.size() > 2) {
strippedArgs.addAll(args.subList(2, args.size()));
}
if (sub.isArgLengthInvalid(strippedArgs.size())) {
sub.sendUsage(sender, label);
return;
}
final String groupName = args.get(0).toLowerCase();
if (Patterns.NON_ALPHA_NUMERIC.matcher(groupName).find()) {
Message.GROUP_INVALID_ENTRY.send(sender); Message.GROUP_INVALID_ENTRY.send(sender);
return; return;
} }
plugin.getDatastore().loadGroup(groupName, success -> { plugin.getDatastore().loadGroup(target, success -> {
if (!success) { if (!success) {
Message.GROUP_NOT_FOUND.send(sender); Message.GROUP_NOT_FOUND.send(sender);
return; return;
} }
Group group = plugin.getGroupManager().getGroup(groupName); Group group = plugin.getGroupManager().getGroup(target);
if (group == null) { if (group == null) {
Message.GROUP_NOT_FOUND.send(sender); Message.GROUP_NOT_FOUND.send(sender);
return; return;
} }
sub.execute(plugin, sender, group, strippedArgs, label); onSuccess.onComplete(group);
}); });
} }
@Override @Override
protected List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) { protected List<String> getObjects(LuckPermsPlugin plugin) {
final List<String> groups = new ArrayList<>(plugin.getGroupManager().getGroups().keySet()); return new ArrayList<>(plugin.getGroupManager().getGroups().keySet());
if (args.size() <= 1) {
if (args.isEmpty() || args.get(0).equalsIgnoreCase("")) {
return groups;
} }
return groups.stream().filter(s -> s.toLowerCase().startsWith(args.get(0).toLowerCase())).collect(Collectors.toList());
}
return onAbstractTabComplete(sender, args, plugin);
}
@Override
public List<? extends SubCommand> getSubCommands() {
return subCommands;
}
public void registerSubCommand(GroupSubCommand subCommand) {
subCommands.add(subCommand);
}
} }

View File

@ -1,30 +0,0 @@
package me.lucko.luckperms.commands.group;
import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.groups.Group;
import java.util.List;
public abstract class GroupSubCommand extends SubCommand {
protected GroupSubCommand(String name, String description, String usage, Permission permission) {
super(name, description, usage, permission);
}
protected abstract void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label);
protected void saveGroup(Group group, Sender sender, LuckPermsPlugin plugin) {
plugin.getDatastore().saveGroup(group, success -> {
if (success) {
Message.GROUP_SAVE_SUCCESS.send(sender);
} else {
Message.GROUP_SAVE_ERROR.send(sender);
}
plugin.runUpdateTask();
});
}
}

View File

@ -1,18 +1,16 @@
package me.lucko.luckperms.commands.group; package me.lucko.luckperms.commands.group;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.MainCommand;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand; import me.lucko.luckperms.commands.SingleMainCommand;
import me.lucko.luckperms.commands.Util; import me.lucko.luckperms.commands.Util;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
public class ListGroups extends MainCommand { public class ListGroups extends SingleMainCommand {
public ListGroups() { public ListGroups() {
super("ListGroups", "/%s listgroups", 0); super("ListGroups", "/%s listgroups", 0);
} }
@ -29,17 +27,7 @@ public class ListGroups extends MainCommand {
} }
@Override @Override
protected List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) { protected boolean isAuthorized(Sender sender) {
return Collections.emptyList();
}
@Override
public List<SubCommand> getSubCommands() {
return Collections.emptyList();
}
@Override
protected boolean canUse(Sender sender) {
return Permission.LIST_GROUPS.isAuthorized(sender); return Permission.LIST_GROUPS.isAuthorized(sender);
} }
} }

View File

@ -1,29 +1,26 @@
package me.lucko.luckperms.commands.group.subcommands; package me.lucko.luckperms.commands.group.subcommands;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.group.GroupSubCommand; import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.groups.Group; import me.lucko.luckperms.groups.Group;
import java.util.List; import java.util.List;
public class GroupClear extends GroupSubCommand { public class GroupClear extends SubCommand<Group> {
public GroupClear() { public GroupClear() {
super("clear", "Clears a groups permissions", "/%s group <group> clear", Permission.GROUP_CLEAR); super("clear", "Clears a groups permissions", "/%s group <group> clear", Permission.GROUP_CLEAR,
Predicate.alwaysFalse());
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) { public void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
group.clearNodes(); group.clearNodes();
Message.CLEAR_SUCCESS.send(sender, group.getName()); Message.CLEAR_SUCCESS.send(sender, group.getName());
saveGroup(group, sender, plugin); saveGroup(group, sender, plugin);
} }
@Override
public boolean isArgLengthInvalid(int argLength) {
return false;
}
} }

View File

@ -1,9 +1,10 @@
package me.lucko.luckperms.commands.group.subcommands; package me.lucko.luckperms.commands.group.subcommands;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.commands.Util; import me.lucko.luckperms.commands.Util;
import me.lucko.luckperms.commands.group.GroupSubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.groups.Group; import me.lucko.luckperms.groups.Group;
@ -11,14 +12,15 @@ import me.lucko.luckperms.utils.Patterns;
import java.util.List; import java.util.List;
public class GroupHasPerm extends GroupSubCommand { public class GroupHasPerm extends SubCommand<Group> {
public GroupHasPerm() { public GroupHasPerm() {
super("haspermission", "Checks to see if a group has a certain permission node", super("haspermission", "Checks to see if a group has a certain permission node",
"/%s group <group> haspermission <node> [server] [world]", Permission.GROUP_HASPERMISSION); "/%s group <group> haspermission <node> [server] [world]", Permission.GROUP_HASPERMISSION,
Predicate.notinRange(1, 3));
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) { public void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
if (args.size() >= 2) { if (args.size() >= 2) {
if (Patterns.NON_ALPHA_NUMERIC.matcher(args.get(1)).find()) { if (Patterns.NON_ALPHA_NUMERIC.matcher(args.get(1)).find()) {
Message.SERVER_INVALID_ENTRY.send(sender); Message.SERVER_INVALID_ENTRY.send(sender);
@ -35,9 +37,4 @@ public class GroupHasPerm extends GroupSubCommand {
Util.sendBoolean(sender, args.get(0), group.hasPermission(args.get(0), true, "global")); Util.sendBoolean(sender, args.get(0), group.hasPermission(args.get(0), true, "global"));
} }
} }
@Override
public boolean isArgLengthInvalid(int argLength) {
return argLength != 1 && argLength != 2 && argLength != 3;
}
} }

View File

@ -1,27 +1,24 @@
package me.lucko.luckperms.commands.group.subcommands; package me.lucko.luckperms.commands.group.subcommands;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.group.GroupSubCommand; import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.groups.Group; import me.lucko.luckperms.groups.Group;
import java.util.List; import java.util.List;
public class GroupInfo extends GroupSubCommand { public class GroupInfo extends SubCommand<Group> {
public GroupInfo() { public GroupInfo() {
super("info", "Gives info about the group", "/%s group <group> info", Permission.GROUP_INFO); super("info", "Gives info about the group", "/%s group <group> info", Permission.GROUP_INFO,
Predicate.alwaysFalse());
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) { public void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
Message.GROUP_INFO.send(sender, group.getName(), group.getPermanentNodes().keySet().size(), Message.GROUP_INFO.send(sender, group.getName(), group.getPermanentNodes().keySet().size(),
group.getTemporaryNodes().keySet().size(), label, group.getName()); group.getTemporaryNodes().keySet().size(), label, group.getName());
} }
@Override
public boolean isArgLengthInvalid(int argLength) {
return false;
}
} }

View File

@ -1,9 +1,10 @@
package me.lucko.luckperms.commands.group.subcommands; package me.lucko.luckperms.commands.group.subcommands;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.commands.Util; import me.lucko.luckperms.commands.Util;
import me.lucko.luckperms.commands.group.GroupSubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.groups.Group; import me.lucko.luckperms.groups.Group;
@ -11,14 +12,15 @@ import me.lucko.luckperms.utils.Patterns;
import java.util.List; import java.util.List;
public class GroupInheritsPerm extends GroupSubCommand { public class GroupInheritsPerm extends SubCommand<Group> {
public GroupInheritsPerm() { public GroupInheritsPerm() {
super("inheritspermission", "Checks to see if a group inherits a certain permission node", super("inheritspermission", "Checks to see if a group inherits a certain permission node",
"/%s group <group> inheritspermission <node> [server] [world]", Permission.GROUP_INHERITSPERMISSION); "/%s group <group> inheritspermission <node> [server] [world]", Permission.GROUP_INHERITSPERMISSION,
Predicate.notinRange(1, 3));
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) { public void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
if (args.size() >= 2) { if (args.size() >= 2) {
if (Patterns.NON_ALPHA_NUMERIC.matcher(args.get(1)).find()) { if (Patterns.NON_ALPHA_NUMERIC.matcher(args.get(1)).find()) {
Message.SERVER_INVALID_ENTRY.send(sender); Message.SERVER_INVALID_ENTRY.send(sender);
@ -35,9 +37,4 @@ public class GroupInheritsPerm extends GroupSubCommand {
Util.sendBoolean(sender, args.get(0), group.inheritsPermission(args.get(0), true)); Util.sendBoolean(sender, args.get(0), group.inheritsPermission(args.get(0), true));
} }
} }
@Override
public boolean isArgLengthInvalid(int argLength) {
return argLength != 1 && argLength != 2 && argLength != 3;
}
} }

View File

@ -1,29 +1,25 @@
package me.lucko.luckperms.commands.group.subcommands; package me.lucko.luckperms.commands.group.subcommands;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.commands.Util; import me.lucko.luckperms.commands.Util;
import me.lucko.luckperms.commands.group.GroupSubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.groups.Group; import me.lucko.luckperms.groups.Group;
import java.util.List; import java.util.List;
public class GroupListNodes extends GroupSubCommand { public class GroupListNodes extends SubCommand<Group> {
public GroupListNodes() { public GroupListNodes() {
super("listnodes", "Lists the permission nodes the group has", "/%s group <group> listnodes", super("listnodes", "Lists the permission nodes the group has", "/%s group <group> listnodes",
Permission.GROUP_LISTNODES); Permission.GROUP_LISTNODES, Predicate.alwaysFalse());
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) { public void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
Message.LISTNODES.send(sender, group.getName(), Util.permNodesToString(group.getPermanentNodes())); Message.LISTNODES.send(sender, group.getName(), Util.permNodesToString(group.getPermanentNodes()));
Message.LISTNODES_TEMP.send(sender, group.getName(), Util.tempNodesToString(group.getTemporaryNodes())); Message.LISTNODES_TEMP.send(sender, group.getName(), Util.tempNodesToString(group.getTemporaryNodes()));
} }
@Override
public boolean isArgLengthInvalid(int argLength) {
return false;
}
} }

View File

@ -1,8 +1,9 @@
package me.lucko.luckperms.commands.group.subcommands; package me.lucko.luckperms.commands.group.subcommands;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.group.GroupSubCommand; import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
@ -11,14 +12,15 @@ import me.lucko.luckperms.utils.Patterns;
import java.util.List; import java.util.List;
public class GroupSetInherit extends GroupSubCommand { public class GroupSetInherit extends SubCommand<Group> {
public GroupSetInherit() { public GroupSetInherit() {
super("setinherit", "Sets another group for this group to inherit permissions from", super("setinherit", "Sets another group for this group to inherit permissions from",
"/%s group <group> setinherit <group> [server] [world]", Permission.GROUP_SETINHERIT); "/%s group <group> setinherit <group> [server] [world]", Permission.GROUP_SETINHERIT,
Predicate.notinRange(1, 3));
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) { public void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
String groupName = args.get(0).toLowerCase(); String groupName = args.get(0).toLowerCase();
if (groupName.contains("/") || groupName.contains("$")) { if (groupName.contains("/") || groupName.contains("$")) {
@ -64,9 +66,4 @@ public class GroupSetInherit extends GroupSubCommand {
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) { public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
return getGroupTabComplete(args, plugin); return getGroupTabComplete(args, plugin);
} }
@Override
public boolean isArgLengthInvalid(int argLength) {
return argLength != 1 && argLength != 2 && argLength != 3;
}
} }

View File

@ -1,8 +1,9 @@
package me.lucko.luckperms.commands.group.subcommands; package me.lucko.luckperms.commands.group.subcommands;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.group.GroupSubCommand; import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
@ -11,14 +12,14 @@ import me.lucko.luckperms.utils.Patterns;
import java.util.List; import java.util.List;
public class GroupSetPermission extends GroupSubCommand { public class GroupSetPermission extends SubCommand<Group> {
public GroupSetPermission() { public GroupSetPermission() {
super("set", "Sets a permission for a group", "/%s group <group> set <node> <true|false> [server] [world]", super("set", "Sets a permission for a group", "/%s group <group> set <node> <true|false> [server] [world]",
Permission.GROUP_SETPERMISSION); Permission.GROUP_SETPERMISSION, Predicate.notinRange(2, 4));
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) { public void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
String node = args.get(0); String node = args.get(0);
String bool = args.get(1).toLowerCase(); String bool = args.get(1).toLowerCase();
@ -71,9 +72,4 @@ public class GroupSetPermission extends GroupSubCommand {
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) { public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
return getBoolTabComplete(args); return getBoolTabComplete(args);
} }
@Override
public boolean isArgLengthInvalid(int argLength) {
return argLength != 2 && argLength != 3 && argLength != 4;
}
} }

View File

@ -1,8 +1,9 @@
package me.lucko.luckperms.commands.group.subcommands; package me.lucko.luckperms.commands.group.subcommands;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.group.GroupSubCommand; import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
@ -12,14 +13,15 @@ import me.lucko.luckperms.utils.Patterns;
import java.util.List; import java.util.List;
public class GroupSetTempInherit extends GroupSubCommand { public class GroupSetTempInherit extends SubCommand<Group> {
public GroupSetTempInherit() { public GroupSetTempInherit() {
super("settempinherit", "Sets another group for this group to inherit permissions from temporarily", super("settempinherit", "Sets another group for this group to inherit permissions from temporarily",
"/%s group <group> settempinherit <group> <duration> [server] [world]", Permission.GROUP_SET_TEMP_INHERIT); "/%s group <group> settempinherit <group> <duration> [server] [world]",
Permission.GROUP_SET_TEMP_INHERIT, Predicate.notinRange(2, 4));
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) { public void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
String groupName = args.get(0).toLowerCase(); String groupName = args.get(0).toLowerCase();
if (groupName.contains("/") || groupName.contains("$")) { if (groupName.contains("/") || groupName.contains("$")) {
@ -80,9 +82,4 @@ public class GroupSetTempInherit extends GroupSubCommand {
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) { public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
return getGroupTabComplete(args, plugin); return getGroupTabComplete(args, plugin);
} }
@Override
public boolean isArgLengthInvalid(int argLength) {
return argLength != 2 && argLength != 3 && argLength != 4;
}
} }

View File

@ -1,8 +1,9 @@
package me.lucko.luckperms.commands.group.subcommands; package me.lucko.luckperms.commands.group.subcommands;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.group.GroupSubCommand; import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
@ -12,14 +13,15 @@ import me.lucko.luckperms.utils.Patterns;
import java.util.List; import java.util.List;
public class GroupSetTempPermission extends GroupSubCommand { public class GroupSetTempPermission extends SubCommand<Group> {
public GroupSetTempPermission() { public GroupSetTempPermission() {
super("settemp", "Sets a temporary permission for a group", super("settemp", "Sets a temporary permission for a group",
"/%s group <group> settemp <node> <true|false> <duration> [server] [world]", Permission.GROUP_SET_TEMP_PERMISSION); "/%s group <group> settemp <node> <true|false> <duration> [server] [world]",
Permission.GROUP_SET_TEMP_PERMISSION, Predicate.notinRange(3, 5));
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) { public void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
String node = args.get(0); String node = args.get(0);
String bool = args.get(1).toLowerCase(); String bool = args.get(1).toLowerCase();
@ -87,9 +89,4 @@ public class GroupSetTempPermission extends GroupSubCommand {
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) { public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
return getBoolTabComplete(args); return getBoolTabComplete(args);
} }
@Override
public boolean isArgLengthInvalid(int argLength) {
return argLength != 3 && argLength != 4 && argLength != 5;
}
} }

View File

@ -1,9 +1,10 @@
package me.lucko.luckperms.commands.group.subcommands; package me.lucko.luckperms.commands.group.subcommands;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.commands.Util; import me.lucko.luckperms.commands.Util;
import me.lucko.luckperms.commands.group.GroupSubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.groups.Group; import me.lucko.luckperms.groups.Group;
@ -12,13 +13,14 @@ import me.lucko.luckperms.tracks.Track;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class GroupShowTracks extends GroupSubCommand { public class GroupShowTracks extends SubCommand<Group> {
public GroupShowTracks() { public GroupShowTracks() {
super("showtracks", "Lists the tracks that this group features on", "/%s group <group> showtracks", Permission.GROUP_SHOWTRACKS); super("showtracks", "Lists the tracks that this group features on", "/%s group <group> showtracks",
Permission.GROUP_SHOWTRACKS, Predicate.alwaysFalse());
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) { public void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
plugin.getDatastore().loadAllTracks(success -> { plugin.getDatastore().loadAllTracks(success -> {
if (!success) { if (!success) {
Message.TRACKS_LOAD_ERROR.send(sender); Message.TRACKS_LOAD_ERROR.send(sender);
@ -29,9 +31,4 @@ public class GroupShowTracks extends GroupSubCommand {
plugin.getTrackManager().getApplicableTracks(group.getName()).stream().map(Track::getName).collect(Collectors.toList()))); plugin.getTrackManager().getApplicableTracks(group.getName()).stream().map(Track::getName).collect(Collectors.toList())));
}); });
} }
@Override
public boolean isArgLengthInvalid(int argLength) {
return false;
}
} }

View File

@ -1,8 +1,9 @@
package me.lucko.luckperms.commands.group.subcommands; package me.lucko.luckperms.commands.group.subcommands;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.group.GroupSubCommand; import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.exceptions.ObjectLacksException; import me.lucko.luckperms.exceptions.ObjectLacksException;
@ -11,14 +12,14 @@ import me.lucko.luckperms.utils.Patterns;
import java.util.List; import java.util.List;
public class GroupUnSetPermission extends GroupSubCommand { public class GroupUnSetPermission extends SubCommand<Group> {
public GroupUnSetPermission() { public GroupUnSetPermission() {
super("unset", "Unsets a permission for a group", super("unset", "Unsets a permission for a group", "/%s group <group> unset <node> [server] [world]",
"/%s group <group> unset <node> [server] [world]", Permission.GROUP_UNSETPERMISSION); Permission.GROUP_UNSETPERMISSION, Predicate.notinRange(1, 3));
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) { public void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
String node = args.get(0); String node = args.get(0);
if (node.contains("/") || node.contains("$")) { if (node.contains("/") || node.contains("$")) {
@ -58,9 +59,4 @@ public class GroupUnSetPermission extends GroupSubCommand {
Message.DOES_NOT_HAVEPERMISSION.send(sender, group.getName()); Message.DOES_NOT_HAVEPERMISSION.send(sender, group.getName());
} }
} }
@Override
public boolean isArgLengthInvalid(int argLength) {
return argLength != 1 && argLength != 2 && argLength != 3;
}
} }

View File

@ -1,8 +1,9 @@
package me.lucko.luckperms.commands.group.subcommands; package me.lucko.luckperms.commands.group.subcommands;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.group.GroupSubCommand; import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.exceptions.ObjectLacksException; import me.lucko.luckperms.exceptions.ObjectLacksException;
@ -11,14 +12,15 @@ import me.lucko.luckperms.utils.Patterns;
import java.util.List; import java.util.List;
public class GroupUnsetInherit extends GroupSubCommand { public class GroupUnsetInherit extends SubCommand<Group> {
public GroupUnsetInherit() { public GroupUnsetInherit() {
super("unsetinherit", "Unsets another group for this group to inherit permissions from", super("unsetinherit", "Unsets another group for this group to inherit permissions from",
"/%s group <group> unsetinherit <group> [server] [world]", Permission.GROUP_UNSETINHERIT); "/%s group <group> unsetinherit <group> [server] [world]", Permission.GROUP_UNSETINHERIT,
Predicate.notinRange(1, 3));
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) { public void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
String groupName = args.get(0).toLowerCase(); String groupName = args.get(0).toLowerCase();
if (groupName.contains("/") || groupName.contains("$")) { if (groupName.contains("/") || groupName.contains("$")) {
@ -58,9 +60,4 @@ public class GroupUnsetInherit extends GroupSubCommand {
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) { public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
return getGroupTabComplete(args, plugin); return getGroupTabComplete(args, plugin);
} }
@Override
public boolean isArgLengthInvalid(int argLength) {
return argLength != 1 && argLength != 2 && argLength != 3;
}
} }

View File

@ -1,8 +1,9 @@
package me.lucko.luckperms.commands.group.subcommands; package me.lucko.luckperms.commands.group.subcommands;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.group.GroupSubCommand; import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.exceptions.ObjectLacksException; import me.lucko.luckperms.exceptions.ObjectLacksException;
@ -11,14 +12,15 @@ import me.lucko.luckperms.utils.Patterns;
import java.util.List; import java.util.List;
public class GroupUnsetTempInherit extends GroupSubCommand { public class GroupUnsetTempInherit extends SubCommand<Group> {
public GroupUnsetTempInherit() { public GroupUnsetTempInherit() {
super("unsettempinherit", "Unsets another group for this group to inherit permissions from", super("unsettempinherit", "Unsets another group for this group to inherit permissions from",
"/%s group <group> unsettempinherit <group> [server] [world]", Permission.GROUP_UNSET_TEMP_INHERIT); "/%s group <group> unsettempinherit <group> [server] [world]", Permission.GROUP_UNSET_TEMP_INHERIT,
Predicate.notinRange(1, 3));
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) { public void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
String groupName = args.get(0).toLowerCase(); String groupName = args.get(0).toLowerCase();
if (groupName.contains("/") || groupName.contains("$")) { if (groupName.contains("/") || groupName.contains("$")) {
@ -58,9 +60,4 @@ public class GroupUnsetTempInherit extends GroupSubCommand {
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) { public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
return getGroupTabComplete(args, plugin); return getGroupTabComplete(args, plugin);
} }
@Override
public boolean isArgLengthInvalid(int argLength) {
return argLength != 1 && argLength != 2 && argLength != 3;
}
} }

View File

@ -1,8 +1,9 @@
package me.lucko.luckperms.commands.group.subcommands; package me.lucko.luckperms.commands.group.subcommands;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.group.GroupSubCommand; import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.exceptions.ObjectLacksException; import me.lucko.luckperms.exceptions.ObjectLacksException;
@ -11,14 +12,15 @@ import me.lucko.luckperms.utils.Patterns;
import java.util.List; import java.util.List;
public class GroupUnsetTempPermission extends GroupSubCommand { public class GroupUnsetTempPermission extends SubCommand<Group> {
public GroupUnsetTempPermission() { public GroupUnsetTempPermission() {
super("unsettemp", "Unsets a temporary permission for a group", super("unsettemp", "Unsets a temporary permission for a group",
"/%s group <group> unsettemp <node> [server] [world]", Permission.GROUP_UNSET_TEMP_PERMISSION); "/%s group <group> unsettemp <node> [server] [world]", Permission.GROUP_UNSET_TEMP_PERMISSION,
Predicate.notinRange(1, 3));
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) { public void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
String node = args.get(0); String node = args.get(0);
if (node.contains("/") || node.contains("$")) { if (node.contains("/") || node.contains("$")) {
@ -58,9 +60,4 @@ public class GroupUnsetTempPermission extends GroupSubCommand {
Message.DOES_NOT_HAVE_TEMP_PERMISSION.send(sender, group.getName()); Message.DOES_NOT_HAVE_TEMP_PERMISSION.send(sender, group.getName());
} }
} }
@Override
public boolean isArgLengthInvalid(int argLength) {
return argLength != 1 && argLength != 2 && argLength != 3;
}
} }

View File

@ -1,16 +1,14 @@
package me.lucko.luckperms.commands.misc; package me.lucko.luckperms.commands.misc;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.MainCommand;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand; import me.lucko.luckperms.commands.SingleMainCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import java.util.Collections;
import java.util.List; import java.util.List;
public class DebugCommand extends MainCommand { public class DebugCommand extends SingleMainCommand {
public DebugCommand() { public DebugCommand() {
super("Debug", "/%s debug", 0); super("Debug", "/%s debug", 0);
} }
@ -23,17 +21,7 @@ public class DebugCommand extends MainCommand {
} }
@Override @Override
protected List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) { protected boolean isAuthorized(Sender sender) {
return Collections.emptyList();
}
@Override
public List<? extends SubCommand> getSubCommands() {
return Collections.emptyList();
}
@Override
protected boolean canUse(Sender sender) {
return Permission.DEBUG.isAuthorized(sender); return Permission.DEBUG.isAuthorized(sender);
} }
} }

View File

@ -1,17 +1,15 @@
package me.lucko.luckperms.commands.misc; package me.lucko.luckperms.commands.misc;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.MainCommand;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand; import me.lucko.luckperms.commands.SingleMainCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.utils.LPConfiguration; import me.lucko.luckperms.utils.LPConfiguration;
import java.util.Collections;
import java.util.List; import java.util.List;
public class InfoCommand extends MainCommand { public class InfoCommand extends SingleMainCommand {
public InfoCommand() { public InfoCommand() {
super("Info", "/%s info", 0); super("Info", "/%s info", 0);
} }
@ -24,17 +22,7 @@ public class InfoCommand extends MainCommand {
} }
@Override @Override
protected List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) { protected boolean isAuthorized(Sender sender) {
return Collections.emptyList();
}
@Override
public List<? extends SubCommand> getSubCommands() {
return Collections.emptyList();
}
@Override
protected boolean canUse(Sender sender) {
return Permission.INFO.isAuthorized(sender); return Permission.INFO.isAuthorized(sender);
} }
} }

View File

@ -1,16 +1,14 @@
package me.lucko.luckperms.commands.misc; package me.lucko.luckperms.commands.misc;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.MainCommand;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand; import me.lucko.luckperms.commands.SingleMainCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import java.util.Collections;
import java.util.List; import java.util.List;
public class SyncCommand extends MainCommand { public class SyncCommand extends SingleMainCommand {
public SyncCommand() { public SyncCommand() {
super("Sync", "/%s sync", 0); super("Sync", "/%s sync", 0);
} }
@ -22,17 +20,7 @@ public class SyncCommand extends MainCommand {
} }
@Override @Override
protected List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) { protected boolean isAuthorized(Sender sender) {
return Collections.emptyList();
}
@Override
public List<? extends SubCommand> getSubCommands() {
return Collections.emptyList();
}
@Override
protected boolean canUse(Sender sender) {
return Permission.SYNC.isAuthorized(sender); return Permission.SYNC.isAuthorized(sender);
} }
} }

View File

@ -1,17 +1,15 @@
package me.lucko.luckperms.commands.track; package me.lucko.luckperms.commands.track;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.MainCommand;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand; import me.lucko.luckperms.commands.SingleMainCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.utils.Patterns; import me.lucko.luckperms.utils.Patterns;
import java.util.Collections;
import java.util.List; import java.util.List;
public class CreateTrack extends MainCommand { public class CreateTrack extends SingleMainCommand {
public CreateTrack() { public CreateTrack() {
super("CreateTrack", "/%s createtrack <track>", 1); super("CreateTrack", "/%s createtrack <track>", 1);
} }
@ -52,17 +50,7 @@ public class CreateTrack extends MainCommand {
} }
@Override @Override
protected List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) { protected boolean isAuthorized(Sender sender) {
return Collections.emptyList();
}
@Override
public List<? extends SubCommand> getSubCommands() {
return Collections.emptyList();
}
@Override
protected boolean canUse(Sender sender) {
return Permission.CREATE_TRACK.isAuthorized(sender); return Permission.CREATE_TRACK.isAuthorized(sender);
} }
} }

View File

@ -1,9 +1,8 @@
package me.lucko.luckperms.commands.track; package me.lucko.luckperms.commands.track;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.MainCommand;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand; import me.lucko.luckperms.commands.SingleMainCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.tracks.Track; import me.lucko.luckperms.tracks.Track;
@ -14,7 +13,7 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class DeleteTrack extends MainCommand { public class DeleteTrack extends SingleMainCommand {
public DeleteTrack() { public DeleteTrack() {
super("DeleteTrack", "/%s deletetrack <track>", 1); super("DeleteTrack", "/%s deletetrack <track>", 1);
} }
@ -71,12 +70,7 @@ public class DeleteTrack extends MainCommand {
} }
@Override @Override
public List<SubCommand> getSubCommands() { protected boolean isAuthorized(Sender sender) {
return Collections.emptyList();
}
@Override
protected boolean canUse(Sender sender) {
return Permission.DELETE_TRACK.isAuthorized(sender); return Permission.DELETE_TRACK.isAuthorized(sender);
} }
} }

View File

@ -1,18 +1,16 @@
package me.lucko.luckperms.commands.track; package me.lucko.luckperms.commands.track;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.MainCommand;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand; import me.lucko.luckperms.commands.SingleMainCommand;
import me.lucko.luckperms.commands.Util; import me.lucko.luckperms.commands.Util;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
public class ListTracks extends MainCommand { public class ListTracks extends SingleMainCommand {
public ListTracks() { public ListTracks() {
super("ListTracks", "/%s listtracks", 0); super("ListTracks", "/%s listtracks", 0);
} }
@ -29,17 +27,7 @@ public class ListTracks extends MainCommand {
} }
@Override @Override
protected List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) { protected boolean isAuthorized(Sender sender) {
return Collections.emptyList();
}
@Override
public List<SubCommand> getSubCommands() {
return Collections.emptyList();
}
@Override
protected boolean canUse(Sender sender) {
return Permission.LIST_TRACKS.isAuthorized(sender); return Permission.LIST_TRACKS.isAuthorized(sender);
} }
} }

View File

@ -1,101 +1,40 @@
package me.lucko.luckperms.commands.track; package me.lucko.luckperms.commands.track;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.api.data.Callback;
import me.lucko.luckperms.commands.MainCommand; import me.lucko.luckperms.commands.MainCommand;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.tracks.Track; import me.lucko.luckperms.tracks.Track;
import me.lucko.luckperms.utils.Patterns;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
public class TrackMainCommand extends MainCommand {
private final List<TrackSubCommand> subCommands = new ArrayList<>();
public class TrackMainCommand extends MainCommand<Track> {
public TrackMainCommand() { public TrackMainCommand() {
super("Track", "/%s track <track>", 2); super("Track", "/%s track <track>", 2);
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) { protected void getTarget(String target, LuckPermsPlugin plugin, Sender sender, Callback<Track> onSuccess) {
if (args.size() < 2) { plugin.getDatastore().loadTrack(target, success -> {
sendUsage(sender, label);
return;
}
Optional<TrackSubCommand> o = subCommands.stream().filter(s -> s.getName().equalsIgnoreCase(args.get(1))).limit(1).findAny();
if (!o.isPresent()) {
Message.COMMAND_NOT_RECOGNISED.send(sender);
return;
}
final TrackSubCommand sub = o.get();
if (!sub.isAuthorized(sender)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
List<String> strippedArgs = new ArrayList<>();
if (args.size() > 2) {
strippedArgs.addAll(args.subList(2, args.size()));
}
if (sub.isArgLengthInvalid(strippedArgs.size())) {
sub.sendUsage(sender, label);
return;
}
final String trackName = args.get(0).toLowerCase();
if (Patterns.NON_ALPHA_NUMERIC.matcher(trackName).find()) {
Message.TRACK_INVALID_ENTRY.send(sender);
return;
}
plugin.getDatastore().loadTrack(trackName, success -> {
if (!success) { if (!success) {
Message.TRACK_NOT_FOUND.send(sender); Message.TRACK_NOT_FOUND.send(sender);
return; return;
} }
Track track = plugin.getTrackManager().getTrack(trackName); Track track = plugin.getTrackManager().getTrack(target);
if (track == null) { if (track == null) {
Message.TRACK_NOT_FOUND.send(sender); Message.TRACK_NOT_FOUND.send(sender);
return; return;
} }
sub.execute(plugin, sender, track, strippedArgs, label); onSuccess.onComplete(track);
}); });
} }
@Override @Override
protected List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) { protected List<String> getObjects(LuckPermsPlugin plugin) {
final List<String> tracks = new ArrayList<>(plugin.getTrackManager().getTracks().keySet()); return new ArrayList<>(plugin.getTrackManager().getTracks().keySet());
if (args.size() <= 1) {
if (args.isEmpty() || args.get(0).equalsIgnoreCase("")) {
return tracks;
} }
return tracks.stream().filter(s -> s.toLowerCase().startsWith(args.get(0).toLowerCase())).collect(Collectors.toList());
}
return onAbstractTabComplete(sender, args, plugin);
}
@Override
public List<? extends SubCommand> getSubCommands() {
return subCommands;
}
public void registerSubCommand(TrackSubCommand subCommand) {
subCommands.add(subCommand);
}
} }

View File

@ -1,30 +0,0 @@
package me.lucko.luckperms.commands.track;
import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.tracks.Track;
import java.util.List;
public abstract class TrackSubCommand extends SubCommand {
public TrackSubCommand(String name, String description, String usage, Permission permission) {
super(name, description, usage, permission);
}
protected abstract void execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label);
protected void saveTrack(Track track, Sender sender, LuckPermsPlugin plugin) {
plugin.getDatastore().saveTrack(track, success -> {
if (success) {
Message.TRACK_SAVE_SUCCESS.send(sender);
} else {
Message.TRACK_SAVE_ERROR.send(sender);
}
plugin.runUpdateTask();
});
}
}

View File

@ -1,9 +1,10 @@
package me.lucko.luckperms.commands.track.subcommands; package me.lucko.luckperms.commands.track.subcommands;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.commands.Util; import me.lucko.luckperms.commands.Util;
import me.lucko.luckperms.commands.track.TrackSubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
@ -12,13 +13,14 @@ import me.lucko.luckperms.tracks.Track;
import java.util.List; import java.util.List;
public class TrackAppend extends TrackSubCommand { public class TrackAppend extends SubCommand<Track> {
public TrackAppend() { public TrackAppend() {
super("append", "Appends a group onto the end of the track", "/%s track <track> append <group>", Permission.TRACK_APPEND); super("append", "Appends a group onto the end of the track", "/%s track <track> append <group>",
Permission.TRACK_APPEND, Predicate.notOneOf(new Integer[]{1}));
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) { public void execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) {
String groupName = args.get(0).toLowerCase(); String groupName = args.get(0).toLowerCase();
plugin.getDatastore().loadGroup(groupName, success -> { plugin.getDatastore().loadGroup(groupName, success -> {
@ -47,9 +49,4 @@ public class TrackAppend extends TrackSubCommand {
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) { public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
return getGroupTabComplete(args, plugin); return getGroupTabComplete(args, plugin);
} }
@Override
public boolean isArgLengthInvalid(int argLength) {
return argLength != 1;
}
} }

View File

@ -1,28 +1,25 @@
package me.lucko.luckperms.commands.track.subcommands; package me.lucko.luckperms.commands.track.subcommands;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.track.TrackSubCommand; import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.tracks.Track; import me.lucko.luckperms.tracks.Track;
import java.util.List; import java.util.List;
public class TrackClear extends TrackSubCommand { public class TrackClear extends SubCommand<Track> {
public TrackClear() { public TrackClear() {
super("clear", "Clears the groups on the track", "/%s track <track> clear", Permission.TRACK_CLEAR); super("clear", "Clears the groups on the track", "/%s track <track> clear", Permission.TRACK_CLEAR,
Predicate.alwaysFalse());
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) { public void execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) {
track.clearGroups(); track.clearGroups();
Message.TRACK_CLEAR.send(sender, track.getName()); Message.TRACK_CLEAR.send(sender, track.getName());
saveTrack(track, sender, plugin); saveTrack(track, sender, plugin);
} }
@Override
public boolean isArgLengthInvalid(int argLength) {
return false;
}
} }

View File

@ -1,27 +1,24 @@
package me.lucko.luckperms.commands.track.subcommands; package me.lucko.luckperms.commands.track.subcommands;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.commands.Util; import me.lucko.luckperms.commands.Util;
import me.lucko.luckperms.commands.track.TrackSubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.tracks.Track; import me.lucko.luckperms.tracks.Track;
import java.util.List; import java.util.List;
public class TrackInfo extends TrackSubCommand { public class TrackInfo extends SubCommand<Track> {
public TrackInfo() { public TrackInfo() {
super("info", "Gives info about the track", "/%s track <track> info", Permission.TRACK_INFO); super("info", "Gives info about the track", "/%s track <track> info", Permission.TRACK_INFO,
Predicate.alwaysFalse());
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) { public void execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) {
Message.TRACK_INFO.send(sender, track.getName(), Util.listToArrowSep(track.getGroups())); Message.TRACK_INFO.send(sender, track.getName(), Util.listToArrowSep(track.getGroups()));
} }
@Override
public boolean isArgLengthInvalid(int argLength) {
return false;
}
} }

View File

@ -1,9 +1,10 @@
package me.lucko.luckperms.commands.track.subcommands; package me.lucko.luckperms.commands.track.subcommands;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.commands.Util; import me.lucko.luckperms.commands.Util;
import me.lucko.luckperms.commands.track.TrackSubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
@ -12,14 +13,14 @@ import me.lucko.luckperms.tracks.Track;
import java.util.List; import java.util.List;
public class TrackInsert extends TrackSubCommand { public class TrackInsert extends SubCommand<Track> {
public TrackInsert() { public TrackInsert() {
super("insert", "Inserts a group at a given position along the track", super("insert", "Inserts a group at a given position along the track",
"/%s track <track> insert <group> <position>", Permission.TRACK_INSERT); "/%s track <track> insert <group> <position>", Permission.TRACK_INSERT, Predicate.notOneOf(new Integer[]{2}));
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) { public void execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) {
String groupName = args.get(0).toLowerCase(); String groupName = args.get(0).toLowerCase();
int pos; int pos;
try { try {
@ -57,9 +58,4 @@ public class TrackInsert extends TrackSubCommand {
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) { public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
return getGroupTabComplete(args, plugin); return getGroupTabComplete(args, plugin);
} }
@Override
public boolean isArgLengthInvalid(int argLength) {
return argLength != 2;
}
} }

View File

@ -1,8 +1,9 @@
package me.lucko.luckperms.commands.track.subcommands; package me.lucko.luckperms.commands.track.subcommands;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.track.TrackSubCommand; import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.exceptions.ObjectLacksException; import me.lucko.luckperms.exceptions.ObjectLacksException;
@ -10,13 +11,14 @@ import me.lucko.luckperms.tracks.Track;
import java.util.List; import java.util.List;
public class TrackRemove extends TrackSubCommand { public class TrackRemove extends SubCommand<Track> {
public TrackRemove() { public TrackRemove() {
super("remove", "Removes a group from the track", "/%s track <track> remove <group>", Permission.TRACK_REMOVE); super("remove", "Removes a group from the track", "/%s track <track> remove <group>", Permission.TRACK_REMOVE,
Predicate.notOneOf(new Integer[]{1}));
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) { public void execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) {
String groupName = args.get(0).toLowerCase(); String groupName = args.get(0).toLowerCase();
try { try {
track.removeGroup(groupName); track.removeGroup(groupName);
@ -31,9 +33,4 @@ public class TrackRemove extends TrackSubCommand {
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) { public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
return getGroupTabComplete(args, plugin); return getGroupTabComplete(args, plugin);
} }
@Override
public boolean isArgLengthInvalid(int argLength) {
return argLength != 1;
}
} }

View File

@ -1,104 +1,53 @@
package me.lucko.luckperms.commands.user; package me.lucko.luckperms.commands.user;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.api.data.Callback;
import me.lucko.luckperms.commands.MainCommand; import me.lucko.luckperms.commands.MainCommand;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.commands.Util; import me.lucko.luckperms.commands.Util;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.users.User; import me.lucko.luckperms.users.User;
import me.lucko.luckperms.utils.Patterns; import me.lucko.luckperms.utils.Patterns;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors;
public class UserMainCommand extends MainCommand {
private final List<UserSubCommand> subCommands = new ArrayList<>();
public class UserMainCommand extends MainCommand<User> {
public UserMainCommand() { public UserMainCommand() {
super("User", "/%s user <user>", 2); super("User", "/%s user <user>", 2);
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) { protected void getTarget(String target, LuckPermsPlugin plugin, Sender sender, Callback<User> onSuccess) {
if (args.size() < 2) { UUID u = Util.parseUuid(target);
sendUsage(sender, label);
return;
}
Optional<UserSubCommand> o = subCommands.stream().filter(s -> s.getName().equalsIgnoreCase(args.get(1))).limit(1).findAny();
if (!o.isPresent()) {
Message.COMMAND_NOT_RECOGNISED.send(sender);
return;
}
final UserSubCommand sub = o.get();
if (!sub.isAuthorized(sender)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
// The arguments to be passed onto the sub command
List<String> strippedArgs = new ArrayList<>();
if (args.size() > 2) {
strippedArgs.addAll(args.subList(2, args.size()));
}
if (sub.isArgLengthInvalid(strippedArgs.size())) {
sub.sendUsage(sender, label);
return;
}
final String user = args.get(0);
if (Patterns.NON_USERNAME.matcher(user).find()) {
Message.USER_INVALID_ENTRY.send(sender, user);
return;
}
UUID u = Util.parseUuid(user);
if (u != null) { if (u != null) {
runSub(plugin, sender, u, sub, strippedArgs, label); runSub(plugin, sender, u, onSuccess);
return;
}
if (target.length() <= 16) {
if (Patterns.NON_USERNAME.matcher(target).find()) {
Message.USER_INVALID_ENTRY.send(sender, target);
return; return;
} }
if (user.length() <= 16) {
Message.USER_ATTEMPTING_LOOKUP.send(sender); Message.USER_ATTEMPTING_LOOKUP.send(sender);
plugin.getDatastore().getUUID(user, uuid -> { plugin.getDatastore().getUUID(target, uuid -> {
if (uuid == null) { if (uuid == null) {
Message.USER_NOT_FOUND.send(sender); Message.USER_NOT_FOUND.send(sender);
return; return;
} }
runSub(plugin, sender, uuid, sub, strippedArgs, label);
runSub(plugin, sender, uuid, onSuccess);
}); });
return; return;
} }
Message.USER_INVALID_ENTRY.send(sender, user); Message.USER_INVALID_ENTRY.send(sender, target);
} }
@Override private void runSub(LuckPermsPlugin plugin, Sender sender, UUID uuid, Callback<User> onSuccess) {
protected List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
final List<String> onlinePlayers = plugin.getPlayerList();
if (args.size() <= 1) {
if (args.isEmpty() || args.get(0).equalsIgnoreCase("")) {
return onlinePlayers;
}
return onlinePlayers.stream().filter(s -> s.toLowerCase().startsWith(args.get(0).toLowerCase())).collect(Collectors.toList());
}
return onAbstractTabComplete(sender, args, plugin);
}
private void runSub(LuckPermsPlugin plugin, Sender sender, UUID uuid, UserSubCommand command, List<String> strippedArgs, String label) {
plugin.getDatastore().loadUser(uuid, success -> { plugin.getDatastore().loadUser(uuid, success -> {
if (!success) { if (!success) {
Message.USER_NOT_FOUND.send(sender); Message.USER_NOT_FOUND.send(sender);
@ -108,19 +57,16 @@ public class UserMainCommand extends MainCommand {
User user = plugin.getUserManager().getUser(uuid); User user = plugin.getUserManager().getUser(uuid);
if (user == null) { if (user == null) {
Message.USER_NOT_FOUND.send(sender); Message.USER_NOT_FOUND.send(sender);
return;
} }
command.execute(plugin, sender, user, strippedArgs, label); onSuccess.onComplete(user);
plugin.getUserManager().cleanupUser(user); plugin.getUserManager().cleanupUser(user);
}); });
} }
@Override @Override
public List<? extends SubCommand> getSubCommands() { protected List<String> getObjects(LuckPermsPlugin plugin) {
return subCommands; return plugin.getPlayerList();
}
public void registerSubCommand(UserSubCommand subCommand) {
subCommands.add(subCommand);
} }
} }

View File

@ -1,30 +0,0 @@
package me.lucko.luckperms.commands.user;
import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.users.User;
import java.util.List;
public abstract class UserSubCommand extends SubCommand {
protected UserSubCommand(String name, String description, String usage, Permission permission) {
super(name, description, usage, permission);
}
protected abstract void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label);
protected void saveUser(User user, Sender sender, LuckPermsPlugin plugin) {
user.refreshPermissions();
plugin.getDatastore().saveUser(user, success -> {
if (success) {
Message.USER_SAVE_SUCCESS.send(sender);
} else {
Message.USER_SAVE_ERROR.send(sender);
}
});
}
}

View File

@ -1,8 +1,9 @@
package me.lucko.luckperms.commands.user.subcommands; package me.lucko.luckperms.commands.user.subcommands;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.user.UserSubCommand; import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
@ -12,13 +13,14 @@ import me.lucko.luckperms.utils.Patterns;
import java.util.List; import java.util.List;
public class UserAddGroup extends UserSubCommand { public class UserAddGroup extends SubCommand<User> {
public UserAddGroup() { public UserAddGroup() {
super("addgroup", "Adds the user to a group", "/%s user <user> addgroup <group> [server] [world]", Permission.USER_ADDGROUP); super("addgroup", "Adds the user to a group", "/%s user <user> addgroup <group> [server] [world]",
Permission.USER_ADDGROUP, Predicate.notinRange(1, 3));
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) { public void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
String groupName = args.get(0).toLowerCase(); String groupName = args.get(0).toLowerCase();
if (groupName.contains("/") || groupName.contains("$")) { if (groupName.contains("/") || groupName.contains("$")) {
@ -70,9 +72,4 @@ public class UserAddGroup extends UserSubCommand {
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) { public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
return getGroupTabComplete(args, plugin); return getGroupTabComplete(args, plugin);
} }
@Override
public boolean isArgLengthInvalid(int argLength) {
return (argLength != 1 && argLength != 2 && argLength != 3);
}
} }

View File

@ -1,8 +1,9 @@
package me.lucko.luckperms.commands.user.subcommands; package me.lucko.luckperms.commands.user.subcommands;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.user.UserSubCommand; import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
@ -13,14 +14,15 @@ import me.lucko.luckperms.utils.Patterns;
import java.util.List; import java.util.List;
public class UserAddTempGroup extends UserSubCommand { public class UserAddTempGroup extends SubCommand<User> {
public UserAddTempGroup() { public UserAddTempGroup() {
super("addtempgroup", "Adds the user to a group temporarily", super("addtempgroup", "Adds the user to a group temporarily",
"/%s user <user> addtempgroup <group> <duration> [server] [world]", Permission.USER_ADDTEMPGROUP); "/%s user <user> addtempgroup <group> <duration> [server] [world]", Permission.USER_ADDTEMPGROUP,
Predicate.notinRange(2, 4));
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) { public void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
String groupName = args.get(0).toLowerCase(); String groupName = args.get(0).toLowerCase();
if (groupName.contains("/") || groupName.contains("$")) { if (groupName.contains("/") || groupName.contains("$")) {
@ -87,9 +89,4 @@ public class UserAddTempGroup extends UserSubCommand {
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) { public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
return getGroupTabComplete(args, plugin); return getGroupTabComplete(args, plugin);
} }
@Override
public boolean isArgLengthInvalid(int argLength) {
return (argLength != 2 && argLength != 3 && argLength != 4);
}
} }

View File

@ -1,30 +1,27 @@
package me.lucko.luckperms.commands.user.subcommands; package me.lucko.luckperms.commands.user.subcommands;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.user.UserSubCommand; import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.users.User; import me.lucko.luckperms.users.User;
import java.util.List; import java.util.List;
public class UserClear extends UserSubCommand { public class UserClear extends SubCommand<User> {
public UserClear() { public UserClear() {
super("clear", "Clears a users permissions and groups", "/%s user <user> clear", Permission.USER_CLEAR); super("clear", "Clears a users permissions and groups", "/%s user <user> clear", Permission.USER_CLEAR,
Predicate.alwaysFalse());
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) { public void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
user.clearNodes(); user.clearNodes();
plugin.getUserManager().giveDefaults(user); plugin.getUserManager().giveDefaults(user);
Message.CLEAR_SUCCESS.send(sender, user.getName()); Message.CLEAR_SUCCESS.send(sender, user.getName());
saveUser(user, sender, plugin); saveUser(user, sender, plugin);
} }
@Override
public boolean isArgLengthInvalid(int argLength) {
return false;
}
} }

View File

@ -1,9 +1,10 @@
package me.lucko.luckperms.commands.user.subcommands; package me.lucko.luckperms.commands.user.subcommands;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.commands.Util; import me.lucko.luckperms.commands.Util;
import me.lucko.luckperms.commands.user.UserSubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
@ -14,13 +15,14 @@ import me.lucko.luckperms.users.User;
import java.util.List; import java.util.List;
public class UserDemote extends UserSubCommand { public class UserDemote extends SubCommand<User> {
public UserDemote() { public UserDemote() {
super("demote", "Demotes a user along a track", "/%s user <user> demote <track>", Permission.USER_DEMOTE); super("demote", "Demotes a user along a track", "/%s user <user> demote <track>", Permission.USER_DEMOTE,
Predicate.notOneOf(new Integer[]{1}));
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) { public void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
final String trackName = args.get(0).toLowerCase(); final String trackName = args.get(0).toLowerCase();
plugin.getDatastore().loadTrack(trackName, success -> { plugin.getDatastore().loadTrack(trackName, success -> {
@ -85,9 +87,4 @@ public class UserDemote extends UserSubCommand {
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) { public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
return getTrackTabComplete(args, plugin); return getTrackTabComplete(args, plugin);
} }
@Override
public boolean isArgLengthInvalid(int argLength) {
return argLength != 1;
}
} }

View File

@ -1,26 +1,23 @@
package me.lucko.luckperms.commands.user.subcommands; package me.lucko.luckperms.commands.user.subcommands;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.user.UserSubCommand; import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.users.User; import me.lucko.luckperms.users.User;
import java.util.List; import java.util.List;
public class UserGetUUID extends UserSubCommand { public class UserGetUUID extends SubCommand<User> {
public UserGetUUID() { public UserGetUUID() {
super("getuuid", "Get the UUID of a user", "/%s user <user> getuuid", Permission.USER_GETUUID); super("getuuid", "Get the UUID of a user", "/%s user <user> getuuid", Permission.USER_GETUUID,
Predicate.alwaysFalse());
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) { public void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
Message.USER_GETUUID.send(sender, user.getName(), user.getUuid().toString()); Message.USER_GETUUID.send(sender, user.getName(), user.getUuid().toString());
} }
@Override
public boolean isArgLengthInvalid(int argLength) {
return false;
}
} }

View File

@ -1,9 +1,10 @@
package me.lucko.luckperms.commands.user.subcommands; package me.lucko.luckperms.commands.user.subcommands;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.commands.Util; import me.lucko.luckperms.commands.Util;
import me.lucko.luckperms.commands.user.UserSubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.users.User; import me.lucko.luckperms.users.User;
@ -11,14 +12,15 @@ import me.lucko.luckperms.utils.Patterns;
import java.util.List; import java.util.List;
public class UserHasPerm extends UserSubCommand { public class UserHasPerm extends SubCommand<User> {
public UserHasPerm() { public UserHasPerm() {
super("haspermission", "Checks to see if a user has a certain permission node", super("haspermission", "Checks to see if a user has a certain permission node",
"/%s user <user> haspermission <node> [server] [world]", Permission.USER_HASPERMISSION); "/%s user <user> haspermission <node> [server] [world]", Permission.USER_HASPERMISSION,
Predicate.notinRange(1, 3));
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) { public void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
if (args.size() >= 2) { if (args.size() >= 2) {
if (Patterns.NON_ALPHA_NUMERIC.matcher(args.get(1)).find()) { if (Patterns.NON_ALPHA_NUMERIC.matcher(args.get(1)).find()) {
Message.SERVER_INVALID_ENTRY.send(sender); Message.SERVER_INVALID_ENTRY.send(sender);
@ -35,9 +37,4 @@ public class UserHasPerm extends UserSubCommand {
Util.sendBoolean(sender, args.get(0), user.hasPermission(args.get(0), true, "global")); Util.sendBoolean(sender, args.get(0), user.hasPermission(args.get(0), true, "global"));
} }
} }
@Override
public boolean isArgLengthInvalid(int argLength) {
return argLength != 1 && argLength != 2 && argLength != 3;
}
} }

View File

@ -1,30 +1,26 @@
package me.lucko.luckperms.commands.user.subcommands; package me.lucko.luckperms.commands.user.subcommands;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.commands.Util; import me.lucko.luckperms.commands.Util;
import me.lucko.luckperms.commands.user.UserSubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.users.User; import me.lucko.luckperms.users.User;
import java.util.List; import java.util.List;
public class UserInfo extends UserSubCommand { public class UserInfo extends SubCommand<User> {
public UserInfo() { public UserInfo() {
super("info", "Gives info about the user", "/%s user <user> info", Permission.USER_INFO); super("info", "Gives info about the user", "/%s user <user> info", Permission.USER_INFO, Predicate.alwaysFalse());
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) { public void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
Message.USER_INFO.send(sender, user.getName(), user.getUuid(), plugin.getPlayerStatus(user.getUuid()), Message.USER_INFO.send(sender, user.getName(), user.getUuid(), plugin.getPlayerStatus(user.getUuid()),
Util.listToCommaSep(user.getGroupNames()), user.getPrimaryGroup(), Util.listToCommaSep(user.getGroupNames()), user.getPrimaryGroup(),
user.getPermanentNodes().keySet().size(), user.getTemporaryNodes().keySet().size(), label, user.getName() user.getPermanentNodes().keySet().size(), user.getTemporaryNodes().keySet().size(), label, user.getName()
); );
} }
@Override
public boolean isArgLengthInvalid(int argLength) {
return false;
}
} }

View File

@ -1,9 +1,10 @@
package me.lucko.luckperms.commands.user.subcommands; package me.lucko.luckperms.commands.user.subcommands;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.commands.Util; import me.lucko.luckperms.commands.Util;
import me.lucko.luckperms.commands.user.UserSubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.users.User; import me.lucko.luckperms.users.User;
@ -11,14 +12,15 @@ import me.lucko.luckperms.utils.Patterns;
import java.util.List; import java.util.List;
public class UserInheritsPerm extends UserSubCommand { public class UserInheritsPerm extends SubCommand<User> {
public UserInheritsPerm() { public UserInheritsPerm() {
super("inheritspermission", "Checks to see if a user inherits a certain permission node", super("inheritspermission", "Checks to see if a user inherits a certain permission node",
"/%s user <user> inheritspermission <node> [server] [world]", Permission.USER_INHERITSPERMISSION); "/%s user <user> inheritspermission <node> [server] [world]", Permission.USER_INHERITSPERMISSION,
Predicate.notinRange(1, 3));
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) { public void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
if (args.size() >= 2) { if (args.size() >= 2) {
if (Patterns.NON_ALPHA_NUMERIC.matcher(args.get(1)).find()) { if (Patterns.NON_ALPHA_NUMERIC.matcher(args.get(1)).find()) {
Message.SERVER_INVALID_ENTRY.send(sender); Message.SERVER_INVALID_ENTRY.send(sender);
@ -35,9 +37,4 @@ public class UserInheritsPerm extends UserSubCommand {
Util.sendBoolean(sender, args.get(0), user.inheritsPermission(args.get(0), true)); Util.sendBoolean(sender, args.get(0), user.inheritsPermission(args.get(0), true));
} }
} }
@Override
public boolean isArgLengthInvalid(int argLength) {
return argLength != 1 && argLength != 2 && argLength != 3;
}
} }

View File

@ -1,28 +1,25 @@
package me.lucko.luckperms.commands.user.subcommands; package me.lucko.luckperms.commands.user.subcommands;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.commands.Util; import me.lucko.luckperms.commands.Util;
import me.lucko.luckperms.commands.user.UserSubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.users.User; import me.lucko.luckperms.users.User;
import java.util.List; import java.util.List;
public class UserListNodes extends UserSubCommand { public class UserListNodes extends SubCommand<User> {
public UserListNodes() { public UserListNodes() {
super("listnodes", "Lists the permission nodes the user has", "/%s user <user> listnodes", Permission.USER_LISTNODES); super("listnodes", "Lists the permission nodes the user has", "/%s user <user> listnodes",
Permission.USER_LISTNODES, Predicate.alwaysFalse());
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) { public void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
Message.LISTNODES.send(sender, user.getName(), Util.permNodesToString(user.getPermanentNodes())); Message.LISTNODES.send(sender, user.getName(), Util.permNodesToString(user.getPermanentNodes()));
Message.LISTNODES_TEMP.send(sender, user.getName(), Util.tempNodesToString(user.getTemporaryNodes())); Message.LISTNODES_TEMP.send(sender, user.getName(), Util.tempNodesToString(user.getTemporaryNodes()));
} }
@Override
public boolean isArgLengthInvalid(int argLength) {
return false;
}
} }

View File

@ -1,9 +1,10 @@
package me.lucko.luckperms.commands.user.subcommands; package me.lucko.luckperms.commands.user.subcommands;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.commands.Util; import me.lucko.luckperms.commands.Util;
import me.lucko.luckperms.commands.user.UserSubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
@ -14,13 +15,14 @@ import me.lucko.luckperms.users.User;
import java.util.List; import java.util.List;
public class UserPromote extends UserSubCommand { public class UserPromote extends SubCommand<User> {
public UserPromote() { public UserPromote() {
super("promote", "Promotes the user along a track", "/%s user <user> promote <track>", Permission.USER_PROMOTE); super("promote", "Promotes the user along a track", "/%s user <user> promote <track>", Permission.USER_PROMOTE,
Predicate.notOneOf(new Integer[]{1}));
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) { public void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
final String trackName = args.get(0).toLowerCase(); final String trackName = args.get(0).toLowerCase();
plugin.getDatastore().loadTrack(trackName, success -> { plugin.getDatastore().loadTrack(trackName, success -> {
@ -85,9 +87,4 @@ public class UserPromote extends UserSubCommand {
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) { public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
return getTrackTabComplete(args, plugin); return getTrackTabComplete(args, plugin);
} }
@Override
public boolean isArgLengthInvalid(int argLength) {
return argLength != 1;
}
} }

View File

@ -1,8 +1,9 @@
package me.lucko.luckperms.commands.user.subcommands; package me.lucko.luckperms.commands.user.subcommands;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.user.UserSubCommand; import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.exceptions.ObjectLacksException; import me.lucko.luckperms.exceptions.ObjectLacksException;
@ -11,13 +12,14 @@ import me.lucko.luckperms.utils.Patterns;
import java.util.List; import java.util.List;
public class UserRemoveGroup extends UserSubCommand { public class UserRemoveGroup extends SubCommand<User> {
public UserRemoveGroup() { public UserRemoveGroup() {
super("removegroup", "Removes a user from a group", "/%s user <user> removegroup <group> [server] [world]", Permission.USER_REMOVEGROUP); super("removegroup", "Removes a user from a group", "/%s user <user> removegroup <group> [server] [world]",
Permission.USER_REMOVEGROUP, Predicate.notinRange(1, 3));
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) { public void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
String groupName = args.get(0).toLowerCase(); String groupName = args.get(0).toLowerCase();
if (groupName.contains("/") || groupName.contains("$")) { if (groupName.contains("/") || groupName.contains("$")) {
@ -63,9 +65,4 @@ public class UserRemoveGroup extends UserSubCommand {
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) { public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
return getGroupTabComplete(args, plugin); return getGroupTabComplete(args, plugin);
} }
@Override
public boolean isArgLengthInvalid(int argLength) {
return (argLength != 1 && argLength != 2 && argLength != 3);
}
} }

View File

@ -1,8 +1,9 @@
package me.lucko.luckperms.commands.user.subcommands; package me.lucko.luckperms.commands.user.subcommands;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.user.UserSubCommand; import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.exceptions.ObjectLacksException; import me.lucko.luckperms.exceptions.ObjectLacksException;
@ -11,14 +12,15 @@ import me.lucko.luckperms.utils.Patterns;
import java.util.List; import java.util.List;
public class UserRemoveTempGroup extends UserSubCommand { public class UserRemoveTempGroup extends SubCommand<User> {
public UserRemoveTempGroup() { public UserRemoveTempGroup() {
super("removetempgroup", "Removes a user from a temporary group", super("removetempgroup", "Removes a user from a temporary group",
"/%s user <user> removetempgroup <group> [server] [world]", Permission.USER_REMOVETEMPGROUP); "/%s user <user> removetempgroup <group> [server] [world]", Permission.USER_REMOVETEMPGROUP,
Predicate.notinRange(1, 3));
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) { public void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
String groupName = args.get(0).toLowerCase(); String groupName = args.get(0).toLowerCase();
if (groupName.contains("/") || groupName.contains("$")) { if (groupName.contains("/") || groupName.contains("$")) {
@ -58,9 +60,4 @@ public class UserRemoveTempGroup extends UserSubCommand {
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) { public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
return getGroupTabComplete(args, plugin); return getGroupTabComplete(args, plugin);
} }
@Override
public boolean isArgLengthInvalid(int argLength) {
return (argLength != 1 && argLength != 2 && argLength != 3);
}
} }

View File

@ -1,8 +1,9 @@
package me.lucko.luckperms.commands.user.subcommands; package me.lucko.luckperms.commands.user.subcommands;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.user.UserSubCommand; import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
@ -11,14 +12,15 @@ import me.lucko.luckperms.utils.Patterns;
import java.util.List; import java.util.List;
public class UserSetPermission extends UserSubCommand { public class UserSetPermission extends SubCommand<User> {
public UserSetPermission() { public UserSetPermission() {
super("set", "Sets a permission for a user", super("set", "Sets a permission for a user",
"/%s user <user> set <node> <true|false> [server] [world]", Permission.USER_SETPERMISSION); "/%s user <user> set <node> <true|false> [server] [world]", Permission.USER_SETPERMISSION,
Predicate.notinRange(2, 4));
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) { public void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
String node = args.get(0); String node = args.get(0);
String bool = args.get(1).toLowerCase(); String bool = args.get(1).toLowerCase();
@ -71,9 +73,4 @@ public class UserSetPermission extends UserSubCommand {
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) { public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
return getBoolTabComplete(args); return getBoolTabComplete(args);
} }
@Override
public boolean isArgLengthInvalid(int argLength) {
return argLength != 2 && argLength != 3 && argLength != 4;
}
} }

View File

@ -1,8 +1,9 @@
package me.lucko.luckperms.commands.user.subcommands; package me.lucko.luckperms.commands.user.subcommands;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.user.UserSubCommand; import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.groups.Group; import me.lucko.luckperms.groups.Group;
@ -10,14 +11,14 @@ import me.lucko.luckperms.users.User;
import java.util.List; import java.util.List;
public class UserSetPrimaryGroup extends UserSubCommand { public class UserSetPrimaryGroup extends SubCommand<User> {
public UserSetPrimaryGroup() { public UserSetPrimaryGroup() {
super("setprimarygroup", "Sets a users primary group", super("setprimarygroup", "Sets a users primary group",
"/%s user <user> setprimarygroup <group>", Permission.USER_SETPRIMARYGROUP); "/%s user <user> setprimarygroup <group>", Permission.USER_SETPRIMARYGROUP, Predicate.notOneOf(new Integer[]{1}));
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) { public void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
Group group = plugin.getGroupManager().getGroup(args.get(0).toLowerCase()); Group group = plugin.getGroupManager().getGroup(args.get(0).toLowerCase());
if (group == null) { if (group == null) {
Message.GROUP_DOES_NOT_EXIST.send(sender); Message.GROUP_DOES_NOT_EXIST.send(sender);
@ -44,9 +45,4 @@ public class UserSetPrimaryGroup extends UserSubCommand {
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) { public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
return getGroupTabComplete(args, plugin); return getGroupTabComplete(args, plugin);
} }
@Override
public boolean isArgLengthInvalid(int argLength) {
return argLength != 1;
}
} }

View File

@ -1,8 +1,9 @@
package me.lucko.luckperms.commands.user.subcommands; package me.lucko.luckperms.commands.user.subcommands;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.user.UserSubCommand; import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
@ -12,14 +13,15 @@ import me.lucko.luckperms.utils.Patterns;
import java.util.List; import java.util.List;
public class UserSetTempPermission extends UserSubCommand { public class UserSetTempPermission extends SubCommand<User> {
public UserSetTempPermission() { public UserSetTempPermission() {
super("settemp", "Sets a temporary permission for a user", super("settemp", "Sets a temporary permission for a user",
"/%s user <user> settemp <node> <true|false> <duration> [server] [world]", Permission.USER_SET_TEMP_PERMISSION); "/%s user <user> settemp <node> <true|false> <duration> [server] [world]",
Permission.USER_SET_TEMP_PERMISSION, Predicate.notinRange(3, 5));
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) { public void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
String node = args.get(0); String node = args.get(0);
String bool = args.get(1).toLowerCase(); String bool = args.get(1).toLowerCase();
@ -85,9 +87,4 @@ public class UserSetTempPermission extends UserSubCommand {
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) { public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
return getBoolTabComplete(args); return getBoolTabComplete(args);
} }
@Override
public boolean isArgLengthInvalid(int argLength) {
return argLength != 3 && argLength != 4 && argLength != 5;
}
} }

View File

@ -1,9 +1,10 @@
package me.lucko.luckperms.commands.user.subcommands; package me.lucko.luckperms.commands.user.subcommands;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.commands.Util; import me.lucko.luckperms.commands.Util;
import me.lucko.luckperms.commands.user.UserSubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.tracks.Track; import me.lucko.luckperms.tracks.Track;
@ -11,13 +12,14 @@ import me.lucko.luckperms.users.User;
import java.util.List; import java.util.List;
public class UserShowPos extends UserSubCommand { public class UserShowPos extends SubCommand<User> {
public UserShowPos() { public UserShowPos() {
super("showpos", "Shows a users position on a track", "/%s user <user> showpos <track>", Permission.USER_SHOWPOS); super("showpos", "Shows a users position on a track", "/%s user <user> showpos <track>", Permission.USER_SHOWPOS,
Predicate.notOneOf(new Integer[]{1}));
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) { public void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
final String trackName = args.get(0).toLowerCase(); final String trackName = args.get(0).toLowerCase();
plugin.getDatastore().loadTrack(trackName, success -> { plugin.getDatastore().loadTrack(trackName, success -> {
@ -49,9 +51,4 @@ public class UserShowPos extends UserSubCommand {
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) { public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
return getTrackTabComplete(args, plugin); return getTrackTabComplete(args, plugin);
} }
@Override
public boolean isArgLengthInvalid(int argLength) {
return argLength != 1;
}
} }

View File

@ -1,9 +1,10 @@
package me.lucko.luckperms.commands.user.subcommands; package me.lucko.luckperms.commands.user.subcommands;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.commands.Util; import me.lucko.luckperms.commands.Util;
import me.lucko.luckperms.commands.user.UserSubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.tracks.Track; import me.lucko.luckperms.tracks.Track;
@ -12,14 +13,14 @@ import me.lucko.luckperms.users.User;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class UserShowTracks extends UserSubCommand { public class UserShowTracks extends SubCommand<User> {
public UserShowTracks() { public UserShowTracks() {
super("showtracks", "Lists the tracks that this user's primary group features on", "/%s user <user> showtracks", super("showtracks", "Lists the tracks that this user's primary group features on", "/%s user <user> showtracks",
Permission.USER_SHOWTRACKS); Permission.USER_SHOWTRACKS, Predicate.alwaysFalse());
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) { public void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
plugin.getDatastore().loadAllTracks(success -> { plugin.getDatastore().loadAllTracks(success -> {
if (!success) { if (!success) {
Message.TRACKS_LOAD_ERROR.send(sender); Message.TRACKS_LOAD_ERROR.send(sender);
@ -31,9 +32,4 @@ public class UserShowTracks extends UserSubCommand {
plugin.getTrackManager().getApplicableTracks(user.getPrimaryGroup()).stream().map(Track::getName).collect(Collectors.toList()))); plugin.getTrackManager().getApplicableTracks(user.getPrimaryGroup()).stream().map(Track::getName).collect(Collectors.toList())));
}); });
} }
@Override
public boolean isArgLengthInvalid(int argLength) {
return false;
}
} }

View File

@ -1,8 +1,9 @@
package me.lucko.luckperms.commands.user.subcommands; package me.lucko.luckperms.commands.user.subcommands;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.user.UserSubCommand; import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.exceptions.ObjectLacksException; import me.lucko.luckperms.exceptions.ObjectLacksException;
@ -11,14 +12,14 @@ import me.lucko.luckperms.utils.Patterns;
import java.util.List; import java.util.List;
public class UserUnSetPermission extends UserSubCommand { public class UserUnSetPermission extends SubCommand<User> {
public UserUnSetPermission() { public UserUnSetPermission() {
super("unset", "Unsets a permission for a user", super("unset", "Unsets a permission for a user",
"/%s user <user> unset <node> [server] [world]", Permission.USER_UNSETPERMISSION); "/%s user <user> unset <node> [server] [world]", Permission.USER_UNSETPERMISSION, Predicate.notinRange(1, 3));
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) { public void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
String node = args.get(0); String node = args.get(0);
if (node.contains("/") || node.contains("$")) { if (node.contains("/") || node.contains("$")) {
@ -58,9 +59,4 @@ public class UserUnSetPermission extends UserSubCommand {
Message.DOES_NOT_HAVEPERMISSION.send(sender, user.getName()); Message.DOES_NOT_HAVEPERMISSION.send(sender, user.getName());
} }
} }
@Override
public boolean isArgLengthInvalid(int argLength) {
return argLength != 1 && argLength != 2 && argLength != 3;
}
} }

View File

@ -1,8 +1,9 @@
package me.lucko.luckperms.commands.user.subcommands; package me.lucko.luckperms.commands.user.subcommands;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.user.UserSubCommand; import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.exceptions.ObjectLacksException; import me.lucko.luckperms.exceptions.ObjectLacksException;
@ -11,14 +12,15 @@ import me.lucko.luckperms.utils.Patterns;
import java.util.List; import java.util.List;
public class UserUnsetTempPermission extends UserSubCommand { public class UserUnsetTempPermission extends SubCommand<User> {
public UserUnsetTempPermission() { public UserUnsetTempPermission() {
super("unsettemp", "Unsets a temporary permission for a user", super("unsettemp", "Unsets a temporary permission for a user",
"/%s user <user> unsettemp <node> [server] [world]", Permission.USER_UNSET_TEMP_PERMISSION); "/%s user <user> unsettemp <node> [server] [world]", Permission.USER_UNSET_TEMP_PERMISSION,
Predicate.notinRange(1, 3));
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) { public void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
String node = args.get(0); String node = args.get(0);
if (node.contains("/") || node.contains("$")) { if (node.contains("/") || node.contains("$")) {
@ -58,9 +60,4 @@ public class UserUnsetTempPermission extends UserSubCommand {
Message.DOES_NOT_HAVE_TEMP_PERMISSION.send(sender, user.getName()); Message.DOES_NOT_HAVE_TEMP_PERMISSION.send(sender, user.getName());
} }
} }
@Override
public boolean isArgLengthInvalid(int argLength) {
return argLength != 1 && argLength != 2 && argLength != 3;
}
} }

View File

@ -503,12 +503,14 @@ public class FlatfileDatastore extends Datastore {
@Override @Override
public boolean saveUUIDData(String username, UUID uuid) { public boolean saveUUIDData(String username, UUID uuid) {
username = username.toLowerCase();
uuidCache.put(username, uuid.toString()); uuidCache.put(username, uuid.toString());
return true; return true;
} }
@Override @Override
public UUID getUUID(String username) { public UUID getUUID(String username) {
username = username.toLowerCase();
if (uuidCache.get(username) == null) return null; if (uuidCache.get(username) == null) return null;
return UUID.fromString(uuidCache.get(username)); return UUID.fromString(uuidCache.get(username));
} }

View File

@ -80,7 +80,7 @@ abstract class SQLDatastore extends Datastore {
boolean success = false; boolean success = false;
try { try {
@Cleanup Connection connection = getConnection(); @Cleanup Connection connection = getConnection();
if (connection == null) { if (connection == null || connection.isClosed()) {
throw new IllegalStateException("SQL connection is null"); throw new IllegalStateException("SQL connection is null");
} }
@ -396,10 +396,11 @@ abstract class SQLDatastore extends Datastore {
@Override @Override
public boolean saveUUIDData(String username, UUID uuid) { public boolean saveUUIDData(String username, UUID uuid) {
final String u = username.toLowerCase();
boolean success = runQuery(new QueryRS(UUIDCACHE_SELECT) { boolean success = runQuery(new QueryRS(UUIDCACHE_SELECT) {
@Override @Override
void onRun(PreparedStatement preparedStatement) throws SQLException { void onRun(PreparedStatement preparedStatement) throws SQLException {
preparedStatement.setString(1, username); preparedStatement.setString(1, u);
} }
@Override @Override
@ -410,14 +411,14 @@ abstract class SQLDatastore extends Datastore {
@Override @Override
void onRun(PreparedStatement preparedStatement) throws SQLException { void onRun(PreparedStatement preparedStatement) throws SQLException {
preparedStatement.setString(1, uuid.toString()); preparedStatement.setString(1, uuid.toString());
preparedStatement.setString(2, username); preparedStatement.setString(2, u);
} }
}); });
} else { } else {
success = runQuery(new QueryPS(UUIDCACHE_INSERT) { success = runQuery(new QueryPS(UUIDCACHE_INSERT) {
@Override @Override
void onRun(PreparedStatement preparedStatement) throws SQLException { void onRun(PreparedStatement preparedStatement) throws SQLException {
preparedStatement.setString(1, username); preparedStatement.setString(1, u);
preparedStatement.setString(2, uuid.toString()); preparedStatement.setString(2, uuid.toString());
} }
}); });
@ -431,12 +432,13 @@ abstract class SQLDatastore extends Datastore {
@Override @Override
public UUID getUUID(String username) { public UUID getUUID(String username) {
final String u = username.toLowerCase();
final UUID[] uuid = {null}; final UUID[] uuid = {null};
boolean success = runQuery(new QueryRS(UUIDCACHE_SELECT) { boolean success = runQuery(new QueryRS(UUIDCACHE_SELECT) {
@Override @Override
void onRun(PreparedStatement preparedStatement) throws SQLException { void onRun(PreparedStatement preparedStatement) throws SQLException {
preparedStatement.setString(1, username); preparedStatement.setString(1, u);
} }
@Override @Override