refactor permission commands

This commit is contained in:
Luck 2016-10-14 19:55:22 +01:00
parent 045539c752
commit f1d670dc46
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
13 changed files with 156 additions and 592 deletions

View File

@ -20,25 +20,21 @@
* SOFTWARE.
*/
package me.lucko.luckperms.common.commands.user.subcommands;
package me.lucko.luckperms.common.commands.generic.permission;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.users.User;
import com.google.common.collect.ImmutableList;
import me.lucko.luckperms.common.commands.generic.SecondaryMainCommand;
import me.lucko.luckperms.common.commands.generic.SecondarySubCommand;
import me.lucko.luckperms.common.core.PermissionHolder;
import java.util.List;
public class UserListNodes extends SubCommand<User> {
public UserListNodes() {
super("listnodes", "Lists the permission nodes the user has", Permission.USER_LISTNODES, Predicate.alwaysFalse(), null);
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
Message.LISTNODES.send(sender, user.getName(), Util.permNodesToString(user.getPermissions(false)));
Message.LISTNODES_TEMP.send(sender, user.getName(), Util.tempNodesToString(user.getPermissions(false)));
return CommandResult.SUCCESS;
public class CommandPermission<T extends PermissionHolder> extends SecondaryMainCommand<T> {
public CommandPermission(boolean user) {
super("Permission", "Edit permissions", user, ImmutableList.<SecondarySubCommand>builder()
.add(new PermissionInfo())
.add(new PermissionSet())
.add(new PermissionUnset())
.add(new PermissionSetTemp())
.add(new PermissionUnsetTemp())
.build());
}
}

View File

@ -20,25 +20,29 @@
* SOFTWARE.
*/
package me.lucko.luckperms.common.commands.group.subcommands;
package me.lucko.luckperms.common.commands.generic.permission;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Predicate;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.Util;
import me.lucko.luckperms.common.commands.generic.SecondarySubCommand;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.groups.Group;
import me.lucko.luckperms.common.core.PermissionHolder;
import java.util.List;
public class GroupListNodes extends SubCommand<Group> {
public GroupListNodes() {
super("listnodes", "Lists the permission nodes the group has", Permission.GROUP_LISTNODES, Predicate.alwaysFalse(), null);
public class PermissionInfo extends SecondarySubCommand {
public PermissionInfo() {
super("info", "Lists the permission nodes the object has", Permission.USER_LISTNODES, Permission.GROUP_LISTNODES, Predicate.alwaysFalse(), null);
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
Message.LISTNODES.send(sender, group.getDisplayName(), Util.permNodesToString(group.getPermissions(false)));
Message.LISTNODES_TEMP.send(sender, group.getDisplayName(), Util.tempNodesToString(group.getPermissions(false)));
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
Message.LISTNODES.send(sender, holder.getFriendlyName(), Util.permNodesToString(holder.getPermissions(false)));
Message.LISTNODES_TEMP.send(sender, holder.getFriendlyName(), Util.tempNodesToString(holder.getPermissions(false)));
return CommandResult.SUCCESS;
}
}

View File

@ -20,22 +20,28 @@
* SOFTWARE.
*/
package me.lucko.luckperms.common.commands.group.subcommands;
package me.lucko.luckperms.common.commands.generic.permission;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Predicate;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.generic.SecondarySubCommand;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.PermissionHolder;
import me.lucko.luckperms.common.data.LogEntry;
import me.lucko.luckperms.common.groups.Group;
import me.lucko.luckperms.common.utils.ArgumentChecker;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import java.util.List;
public class GroupSetPermission extends SubCommand<Group> {
public GroupSetPermission() {
super("set", "Sets a permission for the group", Permission.GROUP_SETPERMISSION, Predicate.notInRange(2, 4),
import static me.lucko.luckperms.common.commands.SubCommand.getBoolTabComplete;
public class PermissionSet extends SecondarySubCommand {
public PermissionSet() {
super("set", "Sets a permission for the object", Permission.USER_SETPERMISSION, Permission.GROUP_SETPERMISSION, Predicate.notInRange(2, 4),
Arg.list(
Arg.create("node", true, "the permission node to set"),
Arg.create("true|false", true, "the value of the node"),
@ -46,7 +52,7 @@ public class GroupSetPermission extends SubCommand<Group> {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
String node = args.get(0).replace("{SPACE}", " ");
String bool = args.get(1).toLowerCase();
@ -56,7 +62,7 @@ public class GroupSetPermission extends SubCommand<Group> {
}
if (node.toLowerCase().startsWith("group.")) {
Message.GROUP_USE_INHERIT.send(sender);
Message.USE_INHERIT_COMMAND.send(sender);
return CommandResult.INVALID_ARGS;
}
@ -76,32 +82,32 @@ public class GroupSetPermission extends SubCommand<Group> {
}
if (args.size() == 3) {
group.setPermission(node, b, server);
Message.SETPERMISSION_SERVER_SUCCESS.send(sender, node, bool, group.getDisplayName(), server);
LogEntry.build().actor(sender).acted(group)
.action("set " + node + " " + b + " " + server)
holder.setPermission(node, b, server);
Message.SETPERMISSION_SERVER_SUCCESS.send(sender, node, bool, holder.getFriendlyName(), server);
LogEntry.build().actor(sender).acted(holder)
.action("permission set " + node + " " + b + " " + server)
.build().submit(plugin, sender);
} else {
final String world = args.get(3).toLowerCase();
group.setPermission(node, b, server, world);
Message.SETPERMISSION_SERVER_WORLD_SUCCESS.send(sender, node, bool, group.getDisplayName(), server, world);
LogEntry.build().actor(sender).acted(group)
.action("set " + node + " " + b + " " + server + " " + world)
holder.setPermission(node, b, server, world);
Message.SETPERMISSION_SERVER_WORLD_SUCCESS.send(sender, node, bool, holder.getFriendlyName(), server, world);
LogEntry.build().actor(sender).acted(holder)
.action("permission set " + node + " " + b + " " + server + " " + world)
.build().submit(plugin, sender);
}
} else {
group.setPermission(node, b);
Message.SETPERMISSION_SUCCESS.send(sender, node, bool, group.getDisplayName());
LogEntry.build().actor(sender).acted(group)
.action("set " + node + " " + b)
holder.setPermission(node, b);
Message.SETPERMISSION_SUCCESS.send(sender, node, bool, holder.getFriendlyName());
LogEntry.build().actor(sender).acted(holder)
.action("permission set " + node + " " + b)
.build().submit(plugin, sender);
}
save(group, sender, plugin);
save(holder, sender, plugin);
return CommandResult.SUCCESS;
} catch (ObjectAlreadyHasException e) {
Message.ALREADY_HASPERMISSION.send(sender, group.getDisplayName());
Message.ALREADY_HASPERMISSION.send(sender, holder.getFriendlyName());
return CommandResult.STATE_ERROR;
}
}

View File

@ -20,23 +20,29 @@
* SOFTWARE.
*/
package me.lucko.luckperms.common.commands.group.subcommands;
package me.lucko.luckperms.common.commands.generic.permission;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Predicate;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.generic.SecondarySubCommand;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.PermissionHolder;
import me.lucko.luckperms.common.data.LogEntry;
import me.lucko.luckperms.common.groups.Group;
import me.lucko.luckperms.common.utils.ArgumentChecker;
import me.lucko.luckperms.common.utils.DateUtil;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import java.util.List;
public class GroupSetTempPermission extends SubCommand<Group> {
public GroupSetTempPermission() {
super("settemp", "Sets a permission for the group temporarily", Permission.GROUP_SET_TEMP_PERMISSION,
import static me.lucko.luckperms.common.commands.SubCommand.getBoolTabComplete;
public class PermissionSetTemp extends SecondarySubCommand {
public PermissionSetTemp() {
super("settemp", "Sets a permission for the object temporarily", Permission.USER_SET_TEMP_PERMISSION, Permission.GROUP_SET_TEMP_PERMISSION,
Predicate.notInRange(3, 5),
Arg.list(
Arg.create("node", true, "the permission node to set"),
@ -49,7 +55,7 @@ public class GroupSetTempPermission extends SubCommand<Group> {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
String node = args.get(0).replace("{SPACE}", " ");
String bool = args.get(1).toLowerCase();
@ -59,7 +65,7 @@ public class GroupSetTempPermission extends SubCommand<Group> {
}
if (node.toLowerCase().startsWith("group.")) {
Message.GROUP_USE_INHERIT.send(sender);
Message.USE_INHERIT_COMMAND.send(sender);
return CommandResult.INVALID_ARGS;
}
@ -96,34 +102,34 @@ public class GroupSetTempPermission extends SubCommand<Group> {
}
if (args.size() == 4) {
group.setPermission(node, b, server, duration);
Message.SETPERMISSION_TEMP_SERVER_SUCCESS.send(sender, node, bool, group.getDisplayName(), server,
holder.setPermission(node, b, server, duration);
Message.SETPERMISSION_TEMP_SERVER_SUCCESS.send(sender, node, bool, holder.getFriendlyName(), server,
DateUtil.formatDateDiff(duration));
LogEntry.build().actor(sender).acted(group)
.action("settemp " + node + " " + b + " " + duration + " " + server)
LogEntry.build().actor(sender).acted(holder)
.action("permission settemp " + node + " " + b + " " + duration + " " + server)
.build().submit(plugin, sender);
} else {
final String world = args.get(4).toLowerCase();
group.setPermission(node, b, server, world, duration);
Message.SETPERMISSION_TEMP_SERVER_WORLD_SUCCESS.send(sender, node, bool, group.getDisplayName(), server,
holder.setPermission(node, b, server, world, duration);
Message.SETPERMISSION_TEMP_SERVER_WORLD_SUCCESS.send(sender, node, bool, holder.getFriendlyName(), server,
world, DateUtil.formatDateDiff(duration));
LogEntry.build().actor(sender).acted(group)
.action("settemp " + node + " " + b + " " + duration + " " + server + " " + world)
LogEntry.build().actor(sender).acted(holder)
.action("permission settemp " + node + " " + b + " " + duration + " " + server + " " + world)
.build().submit(plugin, sender);
}
} else {
group.setPermission(node, b, duration);
Message.SETPERMISSION_TEMP_SUCCESS.send(sender, node, bool, group.getDisplayName(), DateUtil.formatDateDiff(duration));
LogEntry.build().actor(sender).acted(group)
.action("settemp " + node + " " + b + " " + duration)
holder.setPermission(node, b, duration);
Message.SETPERMISSION_TEMP_SUCCESS.send(sender, node, bool, holder.getFriendlyName(), DateUtil.formatDateDiff(duration));
LogEntry.build().actor(sender).acted(holder)
.action("permission settemp " + node + " " + b + " " + duration)
.build().submit(plugin, sender);
}
save(group, sender, plugin);
save(holder, sender, plugin);
return CommandResult.SUCCESS;
} catch (ObjectAlreadyHasException e) {
Message.ALREADY_HAS_TEMP_PERMISSION.send(sender, group.getDisplayName());
Message.ALREADY_HAS_TEMP_PERMISSION.send(sender, holder.getFriendlyName());
return CommandResult.STATE_ERROR;
}
}

View File

@ -20,22 +20,26 @@
* SOFTWARE.
*/
package me.lucko.luckperms.common.commands.user.subcommands;
package me.lucko.luckperms.common.commands.generic.permission;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Predicate;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.generic.SecondarySubCommand;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.PermissionHolder;
import me.lucko.luckperms.common.data.LogEntry;
import me.lucko.luckperms.common.users.User;
import me.lucko.luckperms.common.utils.ArgumentChecker;
import me.lucko.luckperms.exceptions.ObjectLacksException;
import java.util.List;
public class UserUnSetPermission extends SubCommand<User> {
public UserUnSetPermission() {
super("unset", "Unsets a permission for the user", Permission.USER_UNSETPERMISSION, Predicate.notInRange(1, 3),
public class PermissionUnset extends SecondarySubCommand {
public PermissionUnset() {
super("unset", "Unsets a permission for the object", Permission.USER_UNSETPERMISSION, Permission.GROUP_UNSETPERMISSION, Predicate.notInRange(1, 3),
Arg.list(
Arg.create("node", true, "the permission node to unset"),
Arg.create("server", false, "the server to remove the permission node on"),
@ -45,7 +49,7 @@ public class UserUnSetPermission extends SubCommand<User> {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
String node = args.get(0).replace("{SPACE}", " ");
if (ArgumentChecker.checkNode(node)) {
@ -54,7 +58,7 @@ public class UserUnSetPermission extends SubCommand<User> {
}
if (node.toLowerCase().startsWith("group.")) {
Message.USER_USE_REMOVEGROUP.send(sender);
Message.USE_UNINHERIT_COMMAND.send(sender);
return CommandResult.INVALID_ARGS;
}
@ -67,32 +71,32 @@ public class UserUnSetPermission extends SubCommand<User> {
}
if (args.size() == 2) {
user.unsetPermission(node, server);
Message.UNSETPERMISSION_SERVER_SUCCESS.send(sender, node, user.getName(), server);
LogEntry.build().actor(sender).acted(user)
.action("unset " + node + " " + server)
holder.unsetPermission(node, server);
Message.UNSETPERMISSION_SERVER_SUCCESS.send(sender, node, holder.getFriendlyName(), server);
LogEntry.build().actor(sender).acted(holder)
.action("permission unset " + node + " " + server)
.build().submit(plugin, sender);
} else {
final String world = args.get(2).toLowerCase();
user.unsetPermission(node, server, world);
Message.UNSETPERMISSION_SERVER_WORLD_SUCCESS.send(sender, node, user.getName(), server, world);
LogEntry.build().actor(sender).acted(user)
.action("unset " + node + " " + server + " " + world)
holder.unsetPermission(node, server, world);
Message.UNSETPERMISSION_SERVER_WORLD_SUCCESS.send(sender, node, holder.getFriendlyName(), server, world);
LogEntry.build().actor(sender).acted(holder)
.action("permission unset " + node + " " + server + " " + world)
.build().submit(plugin, sender);
}
} else {
user.unsetPermission(node);
Message.UNSETPERMISSION_SUCCESS.send(sender, node, user.getName());
LogEntry.build().actor(sender).acted(user)
.action("unset " + node)
holder.unsetPermission(node);
Message.UNSETPERMISSION_SUCCESS.send(sender, node, holder.getFriendlyName());
LogEntry.build().actor(sender).acted(holder)
.action("permission unset " + node)
.build().submit(plugin, sender);
}
save(user, sender, plugin);
save(holder, sender, plugin);
return CommandResult.SUCCESS;
} catch (ObjectLacksException e) {
Message.DOES_NOT_HAVEPERMISSION.send(sender, user.getName());
Message.DOES_NOT_HAVEPERMISSION.send(sender, holder.getFriendlyName());
return CommandResult.STATE_ERROR;
}
}

View File

@ -20,22 +20,26 @@
* SOFTWARE.
*/
package me.lucko.luckperms.common.commands.group.subcommands;
package me.lucko.luckperms.common.commands.generic.permission;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.Predicate;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.generic.SecondarySubCommand;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.PermissionHolder;
import me.lucko.luckperms.common.data.LogEntry;
import me.lucko.luckperms.common.groups.Group;
import me.lucko.luckperms.common.utils.ArgumentChecker;
import me.lucko.luckperms.exceptions.ObjectLacksException;
import java.util.List;
public class GroupUnsetTempPermission extends SubCommand<Group> {
public GroupUnsetTempPermission() {
super("unsettemp", "Unsets a temporary permission for the group", Permission.GROUP_UNSET_TEMP_PERMISSION,
public class PermissionUnsetTemp extends SecondarySubCommand {
public PermissionUnsetTemp() {
super("unsettemp", "Unsets a temporary permission for the object", Permission.USER_UNSET_TEMP_PERMISSION, Permission.GROUP_UNSET_TEMP_PERMISSION,
Predicate.notInRange(1, 3),
Arg.list(
Arg.create("node", true, "the permission node to unset"),
@ -46,7 +50,7 @@ public class GroupUnsetTempPermission extends SubCommand<Group> {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
String node = args.get(0).replace("{SPACE}", " ");
if (ArgumentChecker.checkNode(node)) {
@ -55,7 +59,7 @@ public class GroupUnsetTempPermission extends SubCommand<Group> {
}
if (node.toLowerCase().startsWith("group.")) {
Message.GROUP_USE_UNINHERIT.send(sender);
Message.USE_UNINHERIT_COMMAND.send(sender);
return CommandResult.INVALID_ARGS;
}
@ -68,32 +72,32 @@ public class GroupUnsetTempPermission extends SubCommand<Group> {
}
if (args.size() == 2) {
group.unsetPermission(node, server);
Message.UNSET_TEMP_PERMISSION_SERVER_SUCCESS.send(sender, node, group.getDisplayName(), server);
LogEntry.build().actor(sender).acted(group)
.action("unsettemp " + node + " " + server)
holder.unsetPermission(node, server);
Message.UNSET_TEMP_PERMISSION_SERVER_SUCCESS.send(sender, node, holder.getFriendlyName(), server);
LogEntry.build().actor(sender).acted(holder)
.action("permission unsettemp " + node + " " + server)
.build().submit(plugin, sender);
} else {
final String world = args.get(2).toLowerCase();
group.unsetPermission(node, server, world);
Message.UNSET_TEMP_PERMISSION_SERVER_WORLD_SUCCESS.send(sender, node, group.getDisplayName(), server, world);
LogEntry.build().actor(sender).acted(group)
.action("unsettemp " + node + " " + server + " " + world)
holder.unsetPermission(node, server, world);
Message.UNSET_TEMP_PERMISSION_SERVER_WORLD_SUCCESS.send(sender, node, holder.getFriendlyName(), server, world);
LogEntry.build().actor(sender).acted(holder)
.action("permission unsettemp " + node + " " + server + " " + world)
.build().submit(plugin, sender);
}
} else {
group.unsetPermission(node, true);
Message.UNSET_TEMP_PERMISSION_SUCCESS.send(sender, node, group.getDisplayName());
LogEntry.build().actor(sender).acted(group)
.action("unsettemp " + node)
holder.unsetPermission(node, true);
Message.UNSET_TEMP_PERMISSION_SUCCESS.send(sender, node, holder.getFriendlyName());
LogEntry.build().actor(sender).acted(holder)
.action("permission unsettemp " + node)
.build().submit(plugin, sender);
}
save(group, sender, plugin);
save(holder, sender, plugin);
return CommandResult.SUCCESS;
} catch (ObjectLacksException e) {
Message.DOES_NOT_HAVE_TEMP_PERMISSION.send(sender, group.getDisplayName());
Message.DOES_NOT_HAVE_TEMP_PERMISSION.send(sender, holder.getFriendlyName());
return CommandResult.STATE_ERROR;
}
}

View File

@ -28,6 +28,7 @@ import me.lucko.luckperms.common.commands.MainCommand;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.generic.parent.CommandParent;
import me.lucko.luckperms.common.commands.generic.permission.CommandPermission;
import me.lucko.luckperms.common.commands.group.subcommands.*;
import me.lucko.luckperms.common.commands.generic.meta.CommandMeta;
import me.lucko.luckperms.common.constants.Message;
@ -40,15 +41,11 @@ public class GroupMainCommand extends MainCommand<Group> {
public GroupMainCommand() {
super("Group", "/%s group <group>", 2, ImmutableList.<SubCommand<Group>>builder()
.add(new GroupInfo())
.add(new CommandPermission<>(false))
.add(new CommandParent<>(false))
.add(new CommandMeta<>(false))
.add(new GroupListNodes())
.add(new GroupHasPerm())
.add(new GroupInheritsPerm())
.add(new GroupSetPermission())
.add(new GroupUnSetPermission())
.add(new GroupSetTempPermission())
.add(new GroupUnsetTempPermission())
.add(new GroupShowTracks())
.add(new GroupBulkChange())
.add(new GroupClear())

View File

@ -1,99 +0,0 @@
/*
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.lucko.luckperms.common.commands.group.subcommands;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.data.LogEntry;
import me.lucko.luckperms.common.groups.Group;
import me.lucko.luckperms.common.utils.ArgumentChecker;
import me.lucko.luckperms.exceptions.ObjectLacksException;
import java.util.List;
public class GroupUnSetPermission extends SubCommand<Group> {
public GroupUnSetPermission() {
super("unset", "Unsets a permission for the group", Permission.GROUP_UNSETPERMISSION, Predicate.notInRange(1, 3),
Arg.list(
Arg.create("node", true, "the permission node to unset"),
Arg.create("server", false, "the server to remove the permission node on"),
Arg.create("world", false, "the world to remove the permission node on")
)
);
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
String node = args.get(0).replace("{SPACE}", " ");
if (ArgumentChecker.checkNode(node)) {
sendDetailedUsage(sender);
return CommandResult.INVALID_ARGS;
}
if (node.toLowerCase().startsWith("group.")) {
Message.GROUP_USE_UNINHERIT.send(sender);
return CommandResult.INVALID_ARGS;
}
try {
if (args.size() >= 2) {
final String server = args.get(1).toLowerCase();
if (ArgumentChecker.checkServer(server)) {
Message.SERVER_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
if (args.size() == 2) {
group.unsetPermission(node, server);
Message.UNSETPERMISSION_SERVER_SUCCESS.send(sender, node, group.getDisplayName(), server);
LogEntry.build().actor(sender).acted(group)
.action("unset " + node + " " + server)
.build().submit(plugin, sender);
} else {
final String world = args.get(2).toLowerCase();
group.unsetPermission(node, server, world);
Message.UNSETPERMISSION_SERVER_WORLD_SUCCESS.send(sender, node, group.getDisplayName(), server, world);
LogEntry.build().actor(sender).acted(group)
.action("unset " + node + " " + server + " " + world)
.build().submit(plugin, sender);
}
} else {
group.unsetPermission(node);
Message.UNSETPERMISSION_SUCCESS.send(sender, node, group.getDisplayName());
LogEntry.build().actor(sender).acted(group)
.action("unset " + node)
.build().submit(plugin, sender);
}
save(group, sender, plugin);
return CommandResult.SUCCESS;
} catch (ObjectLacksException e) {
Message.DOES_NOT_HAVEPERMISSION.send(sender, group.getDisplayName());
return CommandResult.STATE_ERROR;
}
}
}

View File

@ -30,6 +30,7 @@ import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.Util;
import me.lucko.luckperms.common.commands.generic.meta.CommandMeta;
import me.lucko.luckperms.common.commands.generic.parent.CommandParent;
import me.lucko.luckperms.common.commands.generic.permission.CommandPermission;
import me.lucko.luckperms.common.commands.user.subcommands.*;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Patterns;
@ -41,25 +42,21 @@ import java.util.UUID;
public class UserMainCommand extends MainCommand<User> {
public UserMainCommand() {
super("User", "/%s user <user>", 2, ImmutableList.<SubCommand<User>>builder()
.add(new UserInfo())
.add(new CommandParent<>(true))
.add(new CommandMeta<>(true))
.add(new UserGetUUID())
.add(new UserListNodes())
.add(new UserHasPerm())
.add(new UserInheritsPerm())
.add(new UserSetPermission())
.add(new UserUnSetPermission())
.add(new UserSetTempPermission())
.add(new UserUnsetTempPermission())
.add(new UserSetPrimaryGroup())
.add(new UserShowTracks())
.add(new UserPromote())
.add(new UserDemote())
.add(new UserShowPos())
.add(new UserBulkChange())
.add(new UserClear())
.build()
.add(new UserInfo())
.add(new CommandPermission<>(true))
.add(new CommandParent<>(true))
.add(new CommandMeta<>(true))
.add(new UserGetUUID())
.add(new UserHasPerm())
.add(new UserInheritsPerm())
.add(new UserSetPrimaryGroup())
.add(new UserShowTracks())
.add(new UserPromote())
.add(new UserDemote())
.add(new UserShowPos())
.add(new UserBulkChange())
.add(new UserClear())
.build()
);
}

View File

@ -1,113 +0,0 @@
/*
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.lucko.luckperms.common.commands.user.subcommands;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.data.LogEntry;
import me.lucko.luckperms.common.users.User;
import me.lucko.luckperms.common.utils.ArgumentChecker;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import java.util.List;
public class UserSetPermission extends SubCommand<User> {
public UserSetPermission() {
super("set", "Sets a permission for the user", Permission.USER_SETPERMISSION, Predicate.notInRange(2, 4),
Arg.list(
Arg.create("node", true, "the permission node to set"),
Arg.create("true|false", true, "the value of the node"),
Arg.create("server", false, "the server to add the permission node on"),
Arg.create("world", false, "the world to add the permission node on")
)
);
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
String node = args.get(0).replace("{SPACE}", " ");
String bool = args.get(1).toLowerCase();
if (ArgumentChecker.checkNode(node)) {
sendDetailedUsage(sender);
return CommandResult.INVALID_ARGS;
}
if (node.toLowerCase().startsWith("group.")) {
Message.USER_USE_ADDGROUP.send(sender);
return CommandResult.INVALID_ARGS;
}
if (!bool.equalsIgnoreCase("true") && !bool.equalsIgnoreCase("false")) {
sendDetailedUsage(sender);
return CommandResult.INVALID_ARGS;
}
boolean b = Boolean.parseBoolean(bool);
try {
if (args.size() >= 3) {
final String server = args.get(2).toLowerCase();
if (ArgumentChecker.checkServer(server)) {
Message.SERVER_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
if (args.size() == 3) {
user.setPermission(node, b, server);
Message.SETPERMISSION_SERVER_SUCCESS.send(sender, node, bool, user.getName(), server);
LogEntry.build().actor(sender).acted(user)
.action("set " + node + " " + b + " " + server)
.build().submit(plugin, sender);
} else {
final String world = args.get(3).toLowerCase();
user.setPermission(node, b, server, world);
Message.SETPERMISSION_SERVER_WORLD_SUCCESS.send(sender, node, bool, user.getName(), server, world);
LogEntry.build().actor(sender).acted(user)
.action("set " + node + " " + b + " " + server + " " + world)
.build().submit(plugin, sender);
}
} else {
user.setPermission(node, b);
Message.SETPERMISSION_SUCCESS.send(sender, node, bool, user.getName());
LogEntry.build().actor(sender).acted(user)
.action("set " + node + " " + b)
.build().submit(plugin, sender);
}
save(user, sender, plugin);
return CommandResult.SUCCESS;
} catch (ObjectAlreadyHasException e) {
Message.ALREADY_HASPERMISSION.send(sender, user.getName());
return CommandResult.STATE_ERROR;
}
}
@Override
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return getBoolTabComplete(args);
}
}

View File

@ -1,133 +0,0 @@
/*
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.lucko.luckperms.common.commands.user.subcommands;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.data.LogEntry;
import me.lucko.luckperms.common.users.User;
import me.lucko.luckperms.common.utils.ArgumentChecker;
import me.lucko.luckperms.common.utils.DateUtil;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import java.util.List;
public class UserSetTempPermission extends SubCommand<User> {
public UserSetTempPermission() {
super("settemp", "Sets a permission for the user temporarily", Permission.USER_SET_TEMP_PERMISSION,
Predicate.notInRange(3, 5),
Arg.list(
Arg.create("node", true, "the permission node to set"),
Arg.create("true|false", true, "the value of the node"),
Arg.create("duration", true, "the duration until the permission node expires"),
Arg.create("server", false, "the server to add the permission node on"),
Arg.create("world", false, "the world to add the permission node on")
)
);
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
String node = args.get(0).replace("{SPACE}", " ");
String bool = args.get(1).toLowerCase();
if (ArgumentChecker.checkNode(node)) {
sendDetailedUsage(sender);
return CommandResult.INVALID_ARGS;
}
if (node.toLowerCase().startsWith("group.")) {
Message.USER_USE_ADDGROUP.send(sender);
return CommandResult.INVALID_ARGS;
}
if (!bool.equalsIgnoreCase("true") && !bool.equalsIgnoreCase("false")) {
sendDetailedUsage(sender);
return CommandResult.INVALID_ARGS;
}
boolean b = Boolean.parseBoolean(bool);
long duration;
try {
duration = Long.parseLong(args.get(2));
} catch (NumberFormatException e) {
try {
duration = DateUtil.parseDateDiff(args.get(2), true);
} catch (DateUtil.IllegalDateException e1) {
Message.ILLEGAL_DATE_ERROR.send(sender, args.get(2));
return CommandResult.INVALID_ARGS;
}
}
if (DateUtil.shouldExpire(duration)) {
Message.PAST_DATE_ERROR.send(sender);
return CommandResult.INVALID_ARGS;
}
try {
if (args.size() >= 4) {
final String server = args.get(3).toLowerCase();
if (ArgumentChecker.checkServer(server)) {
Message.SERVER_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
if (args.size() == 4) {
user.setPermission(node, b, server, duration);
Message.SETPERMISSION_TEMP_SERVER_SUCCESS.send(sender, node, bool, user.getName(), server, DateUtil.formatDateDiff(duration));
LogEntry.build().actor(sender).acted(user)
.action("settemp " + node + " " + b + " " + duration + " " + server)
.build().submit(plugin, sender);
} else {
final String world = args.get(4).toLowerCase();
user.setPermission(node, b, server, world, duration);
Message.SETPERMISSION_TEMP_SERVER_WORLD_SUCCESS.send(sender, node, bool, user.getName(), server, world, DateUtil.formatDateDiff(duration));
LogEntry.build().actor(sender).acted(user)
.action("settemp " + node + " " + b + " " + duration + " " + server + " " + world)
.build().submit(plugin, sender);
}
} else {
user.setPermission(node, b, duration);
Message.SETPERMISSION_TEMP_SUCCESS.send(sender, node, bool, user.getName(), DateUtil.formatDateDiff(duration));
LogEntry.build().actor(sender).acted(user)
.action("settemp " + node + " " + b + " " + duration)
.build().submit(plugin, sender);
}
save(user, sender, plugin);
return CommandResult.SUCCESS;
} catch (ObjectAlreadyHasException e) {
Message.ALREADY_HAS_TEMP_PERMISSION.send(sender, user.getName());
return CommandResult.STATE_ERROR;
}
}
@Override
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return getBoolTabComplete(args);
}
}

View File

@ -1,100 +0,0 @@
/*
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.lucko.luckperms.common.commands.user.subcommands;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.data.LogEntry;
import me.lucko.luckperms.common.users.User;
import me.lucko.luckperms.common.utils.ArgumentChecker;
import me.lucko.luckperms.exceptions.ObjectLacksException;
import java.util.List;
public class UserUnsetTempPermission extends SubCommand<User> {
public UserUnsetTempPermission() {
super("unsettemp", "Unsets a temporary permission for the user", Permission.USER_UNSET_TEMP_PERMISSION,
Predicate.notInRange(1, 3),
Arg.list(
Arg.create("node", true, "the permission node to unset"),
Arg.create("server", false, "the server to remove the permission node on"),
Arg.create("world", false, "the world to remove the permission node on")
)
);
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
String node = args.get(0).replace("{SPACE}", " ");
if (ArgumentChecker.checkNode(node)) {
sendDetailedUsage(sender);
return CommandResult.INVALID_ARGS;
}
if (node.toLowerCase().startsWith("group.")) {
Message.USER_USE_REMOVEGROUP.send(sender);
return CommandResult.INVALID_ARGS;
}
try {
if (args.size() >= 2) {
final String server = args.get(1).toLowerCase();
if (ArgumentChecker.checkServer(server)) {
Message.SERVER_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
if (args.size() == 2) {
user.unsetPermission(node, server, true);
Message.UNSET_TEMP_PERMISSION_SERVER_SUCCESS.send(sender, node, user.getName(), server);
LogEntry.build().actor(sender).acted(user)
.action("unsettemp " + node + " " + server)
.build().submit(plugin, sender);
} else {
final String world = args.get(2).toLowerCase();
user.unsetPermission(node, server, world, true);
Message.UNSET_TEMP_PERMISSION_SERVER_WORLD_SUCCESS.send(sender, node, user.getName(), server, world);
LogEntry.build().actor(sender).acted(user)
.action("unsettemp " + node + " " + server + " " + world)
.build().submit(plugin, sender);
}
} else {
user.unsetPermission(node, true);
Message.UNSET_TEMP_PERMISSION_SUCCESS.send(sender, node, user.getName());
LogEntry.build().actor(sender).acted(user)
.action("unsettemp " + node)
.build().submit(plugin, sender);
}
save(user, sender, plugin);
return CommandResult.SUCCESS;
} catch (ObjectLacksException e) {
Message.DOES_NOT_HAVE_TEMP_PERMISSION.send(sender, user.getName());
return CommandResult.STATE_ERROR;
}
}
}

View File

@ -73,17 +73,12 @@ public enum Message {
/*
* Command Syntax
*/
USER_USE_ADDGROUP("Use the addgroup command instead of specifying the node.", true),
USER_USE_REMOVEGROUP("Use the removegroup command instead of specifying the node.", true),
USER_INVALID_ENTRY("&d{0}&c is not a valid username/uuid.", true),
GROUP_USE_INHERIT("Use the setinherit command instead of specifying the node.", true),
GROUP_USE_UNINHERIT("Use the unsetinherit command instead of specifying the node.", true),
GROUP_INVALID_ENTRY("Group names can only contain alphanumeric characters.", true),
TRACK_INVALID_ENTRY("Track names can only contain alphanumeric characters.", true),
SERVER_INVALID_ENTRY("Server names can only contain alphanumeric characters.", true),
USE_INHERIT_COMMAND("Use the 'parent add' command instead of specifying the node.", true),
USE_UNINHERIT_COMMAND("Use the 'parent remove' command instead of specifying the node.", true),
/*