mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-30 22:53:27 +01:00
Nest the 'switchprimarygroup' command under the 'parent' subcommand
This commit is contained in:
parent
662b958a7f
commit
b800db03fc
@ -378,8 +378,10 @@ public class CommandManager {
|
|||||||
|
|
||||||
// Provide backwards compatibility
|
// Provide backwards compatibility
|
||||||
case "setprimarygroup":
|
case "setprimarygroup":
|
||||||
|
case "switchprimarygroup":
|
||||||
args.remove(2);
|
args.remove(2);
|
||||||
args.add(2, "switchprimarygroup");
|
args.add(2, "parent");
|
||||||
|
args.add(3, "switchprimarygroup");
|
||||||
break;
|
break;
|
||||||
case "listnodes":
|
case "listnodes":
|
||||||
args.remove(2);
|
args.remove(2);
|
||||||
|
@ -77,6 +77,7 @@ public enum CommandPermission {
|
|||||||
USER_PARENT_REMOVE_TEMP("parent.removetemp", USER),
|
USER_PARENT_REMOVE_TEMP("parent.removetemp", USER),
|
||||||
USER_PARENT_CLEAR("parent.clear", USER),
|
USER_PARENT_CLEAR("parent.clear", USER),
|
||||||
USER_PARENT_CLEAR_TRACK("parent.cleartrack", USER),
|
USER_PARENT_CLEAR_TRACK("parent.cleartrack", USER),
|
||||||
|
USER_PARENT_SWITCHPRIMARYGROUP("parent.switchprimarygroup", USER),
|
||||||
USER_META_INFO("meta.info", USER),
|
USER_META_INFO("meta.info", USER),
|
||||||
USER_META_SET("meta.set", USER),
|
USER_META_SET("meta.set", USER),
|
||||||
USER_META_UNSET("meta.unset", USER),
|
USER_META_UNSET("meta.unset", USER),
|
||||||
@ -92,7 +93,6 @@ public enum CommandPermission {
|
|||||||
USER_META_REMOVE_TEMP_SUFFIX("meta.removetempsuffix", USER),
|
USER_META_REMOVE_TEMP_SUFFIX("meta.removetempsuffix", USER),
|
||||||
USER_META_CLEAR("meta.clear", USER),
|
USER_META_CLEAR("meta.clear", USER),
|
||||||
USER_EDITOR("editor", USER),
|
USER_EDITOR("editor", USER),
|
||||||
USER_SWITCHPRIMARYGROUP("switchprimarygroup", USER),
|
|
||||||
USER_SHOW_TRACKS("showtracks", USER),
|
USER_SHOW_TRACKS("showtracks", USER),
|
||||||
USER_PROMOTE("promote", USER),
|
USER_PROMOTE("promote", USER),
|
||||||
USER_DEMOTE("demote", USER),
|
USER_DEMOTE("demote", USER),
|
||||||
|
@ -128,7 +128,7 @@ public class SharedMainCommand<T extends PermissionHolder> extends SubCommand<T>
|
|||||||
.limit(1)
|
.limit(1)
|
||||||
.findAny();
|
.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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 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();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,6 +33,8 @@ import me.lucko.luckperms.common.locale.CommandSpec;
|
|||||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||||
import me.lucko.luckperms.common.model.PermissionHolder;
|
import me.lucko.luckperms.common.model.PermissionHolder;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
public class CommandParent<T extends PermissionHolder> extends SharedMainCommand<T> {
|
public class CommandParent<T extends PermissionHolder> extends SharedMainCommand<T> {
|
||||||
public CommandParent(LocaleManager locale, boolean user) {
|
public CommandParent(LocaleManager locale, boolean user) {
|
||||||
super(CommandSpec.PARENT.spec(locale), "Parent", user, ImmutableList.<SharedSubCommand>builder()
|
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 ParentRemoveTemp(locale))
|
||||||
.add(new ParentClear(locale))
|
.add(new ParentClear(locale))
|
||||||
.add(new ParentClearTrack(locale))
|
.add(new ParentClearTrack(locale))
|
||||||
|
.addAll(user ? Collections.singleton(new UserSwitchPrimaryGroup(locale)) : Collections.emptySet())
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ public class ParentAdd extends SharedSubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
return getGroupTabComplete(args, plugin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ public class ParentAddTemp extends SharedSubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
return getGroupTabComplete(args, plugin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,7 @@ public class ParentClearTrack extends SharedSubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
return getTrackTabComplete(args, plugin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,7 +110,7 @@ public class ParentRemove extends SharedSubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
return getGroupTabComplete(args, plugin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ public class ParentRemoveTemp extends SharedSubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
return getGroupTabComplete(args, plugin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,7 @@ public class ParentSet extends SharedSubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
return getGroupTabComplete(args, plugin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -139,7 +139,7 @@ public class ParentSetTrack extends SharedSubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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) {
|
if (args.isEmpty() || args.size() == 1) {
|
||||||
return getTrackTabComplete(args, plugin);
|
return getTrackTabComplete(args, plugin);
|
||||||
}
|
}
|
||||||
|
@ -23,19 +23,20 @@
|
|||||||
* SOFTWARE.
|
* 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.actionlog.ExtendedLogEntry;
|
||||||
import me.lucko.luckperms.common.commands.ArgumentPermissions;
|
import me.lucko.luckperms.common.commands.ArgumentPermissions;
|
||||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||||
import me.lucko.luckperms.common.commands.CommandResult;
|
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.commands.sender.Sender;
|
||||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||||
import me.lucko.luckperms.common.locale.CommandSpec;
|
import me.lucko.luckperms.common.locale.CommandSpec;
|
||||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||||
import me.lucko.luckperms.common.locale.Message;
|
import me.lucko.luckperms.common.locale.Message;
|
||||||
import me.lucko.luckperms.common.model.Group;
|
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.model.User;
|
||||||
import me.lucko.luckperms.common.node.NodeFactory;
|
import me.lucko.luckperms.common.node.NodeFactory;
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
@ -43,14 +44,21 @@ import me.lucko.luckperms.common.utils.Predicates;
|
|||||||
|
|
||||||
import java.util.List;
|
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) {
|
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
|
@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 label, CommandPermission permission) {
|
||||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, getPermission().get(), user)) {
|
// 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);
|
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||||
return CommandResult.NO_PERMISSION;
|
return CommandResult.NO_PERMISSION;
|
||||||
}
|
}
|
||||||
@ -80,7 +88,7 @@ public class UserSwitchPrimaryGroup extends SubCommand<User> {
|
|||||||
Message.USER_PRIMARYGROUP_SUCCESS.send(sender, user.getFriendlyName(), group.getFriendlyName());
|
Message.USER_PRIMARYGROUP_SUCCESS.send(sender, user.getFriendlyName(), group.getFriendlyName());
|
||||||
|
|
||||||
ExtendedLogEntry.build().actor(sender).acted(user)
|
ExtendedLogEntry.build().actor(sender).acted(user)
|
||||||
.action("setprimarygroup", group.getName())
|
.action("parent", "switchprimarygroup", group.getName())
|
||||||
.build().submit(plugin, sender);
|
.build().submit(plugin, sender);
|
||||||
|
|
||||||
save(user, sender, plugin);
|
save(user, sender, plugin);
|
@ -70,7 +70,7 @@ public class PermissionCheck extends SharedSubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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());
|
return getPermissionTabComplete(args, plugin.getPermissionVault());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ public class PermissionCheckInherits extends SharedSubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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());
|
return getPermissionTabComplete(args, plugin.getPermissionVault());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,7 @@ public class PermissionSet extends SharedSubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
List<String> ret = getBoolTabComplete(args);
|
||||||
if (!ret.isEmpty()) {
|
if (!ret.isEmpty()) {
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -101,7 +101,7 @@ public class PermissionSetTemp extends SharedSubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
List<String> ret = getBoolTabComplete(args);
|
||||||
if (!ret.isEmpty()) {
|
if (!ret.isEmpty()) {
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -91,7 +91,7 @@ public class PermissionUnset extends SharedSubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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());
|
return getPermissionTabComplete(args, plugin.getPermissionVault());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ public class PermissionUnsetTemp extends SharedSubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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());
|
return getPermissionTabComplete(args, plugin.getPermissionVault());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.HolderEditor;
|
||||||
import me.lucko.luckperms.common.commands.impl.generic.other.HolderShowTracks;
|
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.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.impl.generic.permission.CommandPermission;
|
||||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
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 CommandParent<>(locale, true))
|
||||||
.add(new CommandMeta<>(locale, true))
|
.add(new CommandMeta<>(locale, true))
|
||||||
.add(new HolderEditor<>(locale, true))
|
.add(new HolderEditor<>(locale, true))
|
||||||
.add(new UserSwitchPrimaryGroup(locale))
|
|
||||||
.add(new UserPromote(locale))
|
.add(new UserPromote(locale))
|
||||||
.add(new UserDemote(locale))
|
.add(new UserDemote(locale))
|
||||||
.add(new HolderShowTracks<>(locale, true))
|
.add(new HolderShowTracks<>(locale, true))
|
||||||
|
Loading…
Reference in New Issue
Block a user