Nest the 'switchprimarygroup' command under the 'parent' subcommand

This commit is contained in:
Luck 2018-01-15 21:09:30 +00:00
parent 662b958a7f
commit b800db03fc
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
20 changed files with 38 additions and 25 deletions

View File

@ -378,8 +378,10 @@ public class CommandManager {
// Provide backwards compatibility
case "setprimarygroup":
case "switchprimarygroup":
args.remove(2);
args.add(2, "switchprimarygroup");
args.add(2, "parent");
args.add(3, "switchprimarygroup");
break;
case "listnodes":
args.remove(2);

View File

@ -77,6 +77,7 @@ public enum CommandPermission {
USER_PARENT_REMOVE_TEMP("parent.removetemp", USER),
USER_PARENT_CLEAR("parent.clear", USER),
USER_PARENT_CLEAR_TRACK("parent.cleartrack", USER),
USER_PARENT_SWITCHPRIMARYGROUP("parent.switchprimarygroup", USER),
USER_META_INFO("meta.info", USER),
USER_META_SET("meta.set", USER),
USER_META_UNSET("meta.unset", USER),
@ -92,7 +93,6 @@ public enum CommandPermission {
USER_META_REMOVE_TEMP_SUFFIX("meta.removetempsuffix", USER),
USER_META_CLEAR("meta.clear", USER),
USER_EDITOR("editor", USER),
USER_SWITCHPRIMARYGROUP("switchprimarygroup", USER),
USER_SHOW_TRACKS("showtracks", USER),
USER_PROMOTE("promote", USER),
USER_DEMOTE("demote", USER),

View File

@ -128,7 +128,7 @@ public class SharedMainCommand<T extends PermissionHolder> extends SubCommand<T>
.limit(1)
.findAny();
return o.map(cmd -> cmd.onTabComplete(plugin, sender, args.subList(1, args.size()))).orElseGet(Collections::emptyList);
return o.map(cmd -> cmd.tabComplete(plugin, sender, args.subList(1, args.size()))).orElseGet(Collections::emptyList);
}

View File

@ -75,7 +75,7 @@ public abstract class SharedSubCommand {
public abstract CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException;
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return Collections.emptyList();
}

View File

@ -33,6 +33,8 @@ import me.lucko.luckperms.common.locale.CommandSpec;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.model.PermissionHolder;
import java.util.Collections;
public class CommandParent<T extends PermissionHolder> extends SharedMainCommand<T> {
public CommandParent(LocaleManager locale, boolean user) {
super(CommandSpec.PARENT.spec(locale), "Parent", user, ImmutableList.<SharedSubCommand>builder()
@ -45,6 +47,7 @@ public class CommandParent<T extends PermissionHolder> extends SharedMainCommand
.add(new ParentRemoveTemp(locale))
.add(new ParentClear(locale))
.add(new ParentClearTrack(locale))
.addAll(user ? Collections.singleton(new UserSwitchPrimaryGroup(locale)) : Collections.emptySet())
.build());
}
}

View File

@ -103,7 +103,7 @@ public class ParentAdd extends SharedSubCommand {
}
@Override
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return getGroupTabComplete(args, plugin);
}
}

View File

@ -116,7 +116,7 @@ public class ParentAddTemp extends SharedSubCommand {
}
@Override
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return getGroupTabComplete(args, plugin);
}
}

View File

@ -124,7 +124,7 @@ public class ParentClearTrack extends SharedSubCommand {
}
@Override
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return getTrackTabComplete(args, plugin);
}
}

View File

@ -110,7 +110,7 @@ public class ParentRemove extends SharedSubCommand {
}
@Override
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return getGroupTabComplete(args, plugin);
}
}

View File

@ -91,7 +91,7 @@ public class ParentRemoveTemp extends SharedSubCommand {
}
@Override
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return getGroupTabComplete(args, plugin);
}
}

View File

@ -102,7 +102,7 @@ public class ParentSet extends SharedSubCommand {
}
@Override
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return getGroupTabComplete(args, plugin);
}
}

View File

@ -139,7 +139,7 @@ public class ParentSetTrack extends SharedSubCommand {
}
@Override
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
if (args.isEmpty() || args.size() == 1) {
return getTrackTabComplete(args, plugin);
}

View File

@ -23,19 +23,20 @@
* SOFTWARE.
*/
package me.lucko.luckperms.common.commands.impl.user;
package me.lucko.luckperms.common.commands.impl.generic.parent;
import me.lucko.luckperms.common.actionlog.ExtendedLogEntry;
import me.lucko.luckperms.common.commands.ArgumentPermissions;
import me.lucko.luckperms.common.commands.CommandPermission;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
import me.lucko.luckperms.common.commands.abstraction.SharedSubCommand;
import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.locale.CommandSpec;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.model.User;
import me.lucko.luckperms.common.node.NodeFactory;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
@ -43,14 +44,21 @@ import me.lucko.luckperms.common.utils.Predicates;
import java.util.List;
public class UserSwitchPrimaryGroup extends SubCommand<User> {
import static me.lucko.luckperms.common.commands.abstraction.SubCommand.getGroupTabComplete;
public class UserSwitchPrimaryGroup extends SharedSubCommand {
public UserSwitchPrimaryGroup(LocaleManager locale) {
super(CommandSpec.USER_SWITCHPRIMARYGROUP.spec(locale), "switchprimarygroup", CommandPermission.USER_SWITCHPRIMARYGROUP, Predicates.not(1));
super(CommandSpec.USER_SWITCHPRIMARYGROUP.spec(locale), "switchprimarygroup", CommandPermission.USER_PARENT_SWITCHPRIMARYGROUP, null, Predicates.not(1));
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
if (ArgumentPermissions.checkModifyPerms(plugin, sender, getPermission().get(), user)) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) {
// cast to user
// although this command is build as a sharedsubcommand,
// it is only added to the listings for users.
User user = ((User) holder);
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, user)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return CommandResult.NO_PERMISSION;
}
@ -80,7 +88,7 @@ public class UserSwitchPrimaryGroup extends SubCommand<User> {
Message.USER_PRIMARYGROUP_SUCCESS.send(sender, user.getFriendlyName(), group.getFriendlyName());
ExtendedLogEntry.build().actor(sender).acted(user)
.action("setprimarygroup", group.getName())
.action("parent", "switchprimarygroup", group.getName())
.build().submit(plugin, sender);
save(user, sender, plugin);

View File

@ -70,7 +70,7 @@ public class PermissionCheck extends SharedSubCommand {
}
@Override
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return getPermissionTabComplete(args, plugin.getPermissionVault());
}
}

View File

@ -75,7 +75,7 @@ public class PermissionCheckInherits extends SharedSubCommand {
}
@Override
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return getPermissionTabComplete(args, plugin.getPermissionVault());
}
}

View File

@ -93,7 +93,7 @@ public class PermissionSet extends SharedSubCommand {
}
@Override
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
List<String> ret = getBoolTabComplete(args);
if (!ret.isEmpty()) {
return ret;

View File

@ -101,7 +101,7 @@ public class PermissionSetTemp extends SharedSubCommand {
}
@Override
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
List<String> ret = getBoolTabComplete(args);
if (!ret.isEmpty()) {
return ret;

View File

@ -91,7 +91,7 @@ public class PermissionUnset extends SharedSubCommand {
}
@Override
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return getPermissionTabComplete(args, plugin.getPermissionVault());
}
}

View File

@ -91,7 +91,7 @@ public class PermissionUnsetTemp extends SharedSubCommand {
}
@Override
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return getPermissionTabComplete(args, plugin.getPermissionVault());
}
}

View File

@ -36,6 +36,7 @@ import me.lucko.luckperms.common.commands.impl.generic.other.HolderClear;
import me.lucko.luckperms.common.commands.impl.generic.other.HolderEditor;
import me.lucko.luckperms.common.commands.impl.generic.other.HolderShowTracks;
import me.lucko.luckperms.common.commands.impl.generic.parent.CommandParent;
import me.lucko.luckperms.common.commands.impl.generic.parent.UserSwitchPrimaryGroup;
import me.lucko.luckperms.common.commands.impl.generic.permission.CommandPermission;
import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.config.ConfigKeys;
@ -71,7 +72,6 @@ public class UserMainCommand extends MainCommand<User, UserIdentifier> {
.add(new CommandParent<>(locale, true))
.add(new CommandMeta<>(locale, true))
.add(new HolderEditor<>(locale, true))
.add(new UserSwitchPrimaryGroup(locale))
.add(new UserPromote(locale))
.add(new UserDemote(locale))
.add(new HolderShowTracks<>(locale, true))