|
|
|
@@ -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;
|
|
|
|
|
}
|
|
|
|
|
}
|