mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-27 21:29:47 +01:00
Allow creategroup command to take weight and display name as optional arguments (#2698)
This commit is contained in:
parent
5d0c578da1
commit
5bdc798237
@ -64,7 +64,11 @@ luckperms {
|
|||||||
install;
|
install;
|
||||||
}
|
}
|
||||||
creategroup {
|
creategroup {
|
||||||
name brigadier:string single_word;
|
name brigadier:string single_word {
|
||||||
|
weight brigadier:integer {
|
||||||
|
displayname brigadier:string quotable_phrase;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
deletegroup {
|
deletegroup {
|
||||||
name brigadier:string single_word;
|
name brigadier:string single_word;
|
||||||
@ -631,4 +635,4 @@ luckperms {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,9 @@ public enum CommandSpec {
|
|||||||
),
|
),
|
||||||
|
|
||||||
CREATE_GROUP("/%s creategroup <group>",
|
CREATE_GROUP("/%s creategroup <group>",
|
||||||
arg("name", true)
|
arg("name", true),
|
||||||
|
arg("weight", false),
|
||||||
|
arg("display-name", "displayname", false)
|
||||||
),
|
),
|
||||||
DELETE_GROUP("/%s deletegroup <group>",
|
DELETE_GROUP("/%s deletegroup <group>",
|
||||||
arg("name", true)
|
arg("name", true)
|
||||||
|
@ -30,8 +30,12 @@ import me.lucko.luckperms.common.command.CommandResult;
|
|||||||
import me.lucko.luckperms.common.command.abstraction.SingleCommand;
|
import me.lucko.luckperms.common.command.abstraction.SingleCommand;
|
||||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||||
import me.lucko.luckperms.common.command.spec.CommandSpec;
|
import me.lucko.luckperms.common.command.spec.CommandSpec;
|
||||||
|
import me.lucko.luckperms.common.command.utils.ArgumentException;
|
||||||
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
import me.lucko.luckperms.common.command.utils.ArgumentList;
|
||||||
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.node.types.DisplayName;
|
||||||
|
import me.lucko.luckperms.common.node.types.Weight;
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.sender.Sender;
|
import me.lucko.luckperms.common.sender.Sender;
|
||||||
import me.lucko.luckperms.common.storage.misc.DataConstraints;
|
import me.lucko.luckperms.common.storage.misc.DataConstraints;
|
||||||
@ -40,10 +44,11 @@ import me.lucko.luckperms.common.util.Predicates;
|
|||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.luckperms.api.actionlog.Action;
|
import net.luckperms.api.actionlog.Action;
|
||||||
import net.luckperms.api.event.cause.CreationCause;
|
import net.luckperms.api.event.cause.CreationCause;
|
||||||
|
import net.luckperms.api.model.data.DataType;
|
||||||
|
|
||||||
public class CreateGroup extends SingleCommand {
|
public class CreateGroup extends SingleCommand {
|
||||||
public CreateGroup() {
|
public CreateGroup() {
|
||||||
super(CommandSpec.CREATE_GROUP, "CreateGroup", CommandPermission.CREATE_GROUP, Predicates.not(1));
|
super(CommandSpec.CREATE_GROUP, "CreateGroup", CommandPermission.CREATE_GROUP, Predicates.notInRange(1, 3));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -64,8 +69,32 @@ public class CreateGroup extends SingleCommand {
|
|||||||
return CommandResult.INVALID_ARGS;
|
return CommandResult.INVALID_ARGS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Integer weight = null;
|
||||||
try {
|
try {
|
||||||
plugin.getStorage().createAndLoadGroup(groupName, CreationCause.COMMAND).get();
|
weight = args.getPriority(1);
|
||||||
|
} catch (ArgumentException | IndexOutOfBoundsException e) {
|
||||||
|
// ignored
|
||||||
|
}
|
||||||
|
|
||||||
|
String displayName = null;
|
||||||
|
try {
|
||||||
|
displayName = args.get(weight != null ? 2 : 1);
|
||||||
|
} catch (IndexOutOfBoundsException e) {
|
||||||
|
// ignored
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Group group = plugin.getStorage().createAndLoadGroup(groupName, CreationCause.COMMAND).get();
|
||||||
|
|
||||||
|
if (weight != null) {
|
||||||
|
group.setNode(DataType.NORMAL, Weight.builder(weight).build(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (displayName != null) {
|
||||||
|
group.setNode(DataType.NORMAL, DisplayName.builder(displayName).build(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin.getStorage().saveGroup(group);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
plugin.getLogger().warn("Error whilst creating group", e);
|
plugin.getLogger().warn("Error whilst creating group", e);
|
||||||
Message.CREATE_ERROR.send(sender, Component.text(groupName));
|
Message.CREATE_ERROR.send(sender, Component.text(groupName));
|
||||||
|
@ -388,6 +388,8 @@ luckperms.usage.apply-edits.argument.code=the unique code for the data
|
|||||||
luckperms.usage.apply-edits.argument.target=who to apply the data to
|
luckperms.usage.apply-edits.argument.target=who to apply the data to
|
||||||
luckperms.usage.create-group.description=Create a new group
|
luckperms.usage.create-group.description=Create a new group
|
||||||
luckperms.usage.create-group.argument.name=the name of the group
|
luckperms.usage.create-group.argument.name=the name of the group
|
||||||
|
luckperms.usage.create-group.argument.weight=the weight of the group
|
||||||
|
luckperms.usage.create-group.argument.display-name=the display name of the group
|
||||||
luckperms.usage.delete-group.description=Delete a group
|
luckperms.usage.delete-group.description=Delete a group
|
||||||
luckperms.usage.delete-group.argument.name=the name of the group
|
luckperms.usage.delete-group.argument.name=the name of the group
|
||||||
luckperms.usage.list-groups.description=List all groups on the platform
|
luckperms.usage.list-groups.description=List all groups on the platform
|
||||||
|
Loading…
Reference in New Issue
Block a user