Add group setweight command - closes #94

This commit is contained in:
Luck 2016-12-21 21:22:48 +00:00
parent c7d3d87b09
commit 61fd14c816
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
5 changed files with 79 additions and 1 deletions

View File

@ -45,6 +45,7 @@ public class GroupMainCommand extends MainCommand<Group> {
.add(new CommandPermission<>(false)) .add(new CommandPermission<>(false))
.add(new CommandParent<>(false)) .add(new CommandParent<>(false))
.add(new CommandMeta<>(false)) .add(new CommandMeta<>(false))
.add(new GroupSetWeight())
.add(new HolderShowTracks<>(false)) .add(new HolderShowTracks<>(false))
.add(new GroupBulkChange()) .add(new GroupBulkChange())
.add(new GroupClear()) .add(new GroupClear())

View File

@ -0,0 +1,74 @@
/*
* 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;
import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.commands.utils.ArgumentUtils;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.NodeFactory;
import me.lucko.luckperms.common.core.model.Group;
import me.lucko.luckperms.common.utils.Predicates;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import me.lucko.luckperms.exceptions.ObjectLacksException;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
public class GroupSetWeight extends SubCommand<Group> {
public GroupSetWeight() {
super("setweight", "Set the groups weight", Permission.GROUP_SETWEIGHT, Predicates.not(1),
Arg.list(Arg.create("weight", true, "the weight to set"))
);
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) throws CommandException {
int weight = ArgumentUtils.handlePriority(0, args);
Set<Node> existingWeightNodes = group.getNodes().stream()
.filter(n -> n.getPermission().startsWith("weight."))
.collect(Collectors.toSet());
existingWeightNodes.forEach(n -> {
try {
group.unsetPermission(n);
} catch (ObjectLacksException ignored) {}
});
try {
group.setPermission(NodeFactory.newBuilder("weight." + weight).build());
} catch (ObjectAlreadyHasException ignored) {}
save(group, sender, plugin);
Message.GROUP_SET_WEIGHT.send(sender, weight, group.getDisplayName());
return CommandResult.SUCCESS;
}
}

View File

@ -334,6 +334,7 @@ public enum Message {
"{PREFIX}&f- &3Meta: &a{6}", "{PREFIX}&f- &3Meta: &a{6}",
false false
), ),
GROUP_SET_WEIGHT("&aSet weight to &b{0}&a for group &b{1}&a.", true),
TRACK_INFO( TRACK_INFO(
"{PREFIX}&b&l> &bShowing Track: &f{0}" + "\n" + "{PREFIX}&b&l> &bShowing Track: &f{0}" + "\n" +

View File

@ -115,6 +115,7 @@ public enum Permission {
GROUP_META_REMOVETEMP_SUFFIX(l("meta.removetempsuffix", "removetempsuffix"), Type.GROUP), GROUP_META_REMOVETEMP_SUFFIX(l("meta.removetempsuffix", "removetempsuffix"), Type.GROUP),
GROUP_META_CLEAR(l("meta.clear", "clearmeta"), Type.GROUP), GROUP_META_CLEAR(l("meta.clear", "clearmeta"), Type.GROUP),
GROUP_SHOWTRACKS(l("showtracks"), Type.GROUP), GROUP_SHOWTRACKS(l("showtracks"), Type.GROUP),
GROUP_SETWEIGHT(l("setweight"), Type.GROUP),
GROUP_BULKCHANGE(l("bulkchange"), Type.GROUP), GROUP_BULKCHANGE(l("bulkchange"), Type.GROUP),
GROUP_CLEAR(l("clear"), Type.GROUP), GROUP_CLEAR(l("clear"), Type.GROUP),
GROUP_RENAME(l("rename"), Type.GROUP), GROUP_RENAME(l("rename"), Type.GROUP),

View File

@ -271,7 +271,7 @@ user-demote-error-malformed: >
user-demote-error-not-contain-group: "Demotions are done based on primary groups. The users primary group is not on the track specified." user-demote-error-not-contain-group: "Demotions are done based on primary groups. The users primary group is not on the track specified."
user-showpos: "&aShowing &b{0}&a's position on track &b{1}&a.{2}" user-showpos: "&aShowing &b{0}&a's position on track &b{1}&a.{2}"
user-info-general: > group-info-general: >
{PREFIX}&b&l> &bGroup Info: &f{0}\n {PREFIX}&b&l> &bGroup Info: &f{0}\n
{PREFIX}&f- &3Diaplay Name: &f{1}\n {PREFIX}&f- &3Diaplay Name: &f{1}\n
{PREFIX}&f- &aCounts:\n {PREFIX}&f- &aCounts:\n
@ -280,6 +280,7 @@ user-info-general: >
{PREFIX}&f- &3Prefixes: &a{4}\n {PREFIX}&f- &3Prefixes: &a{4}\n
{PREFIX}&f- &3Suffixes: &a{5}\n {PREFIX}&f- &3Suffixes: &a{5}\n
{PREFIX}&f- &3Meta: &a{6} {PREFIX}&f- &3Meta: &a{6}
group-set-weight: "&aSet weight to &b{0}&a for group &b{1}&a."
track-info: > track-info: >
{PREFIX}&b&l> &bShowing Track: &f{0}\n {PREFIX}&b&l> &bShowing Track: &f{0}\n