Add bulkchange commands

This commit is contained in:
Luck 2016-09-25 17:29:11 +01:00
parent 4da7fe4ff9
commit fec90b8958
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
8 changed files with 208 additions and 1 deletions

View File

@ -60,6 +60,7 @@ public class GroupMainCommand extends MainCommand<Group> {
.add(new GroupAddTempSuffix())
.add(new GroupRemoveTempPrefix())
.add(new GroupRemoveTempSuffix())
.add(new GroupBulkChange())
.add(new GroupClear())
.add(new GroupRename())
.build()

View File

@ -0,0 +1,92 @@
/*
* 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.commands.group.subcommands;
import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.commands.CommandResult;
import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.groups.Group;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
public class GroupBulkChange extends SubCommand<Group> {
public GroupBulkChange() {
super("bulkchange", "Applies a bulk permission change to the groups permissions", "<server|world> <from> <to>",
Permission.GROUP_BULKCHANGE, Predicate.not(3));
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
String type = args.get(0).toLowerCase();
String from = args.get(1);
String to = args.get(2);
if (to.equals("null")) {
to = null;
}
Set<Node> toAdd = new HashSet<>();
if (!type.equals("world") && !type.equals("server")) {
Message.BULK_CHANGE_TYPE_ERROR.send(sender);
return CommandResult.FAILURE;
}
Iterator<Node> iterator = group.getNodes().iterator();
if (type.equals("world")) {
while (iterator.hasNext()) {
Node element = iterator.next();
String world = element.getWorld().orElse("null");
if (!world.equals(from)) {
continue;
}
iterator.remove();
toAdd.add(me.lucko.luckperms.core.Node.builderFromExisting(element).setWorld(to).build());
}
} else {
while (iterator.hasNext()) {
Node element = iterator.next();
String server = element.getServer().orElse("global");
if (!server.equals(from)) {
continue;
}
iterator.remove();
toAdd.add(me.lucko.luckperms.core.Node.builderFromExisting(element).setServer(to).build());
}
}
group.getNodes().addAll(toAdd);
save(group, sender, plugin);
Message.BULK_CHANGE_SUCCESS.send(sender, toAdd.size());
return CommandResult.SUCCESS;
}
}

View File

@ -67,6 +67,7 @@ public class UserMainCommand extends MainCommand<User> {
.add(new UserAddTempSuffix())
.add(new UserRemoveTempPrefix())
.add(new UserRemoveTempSuffix())
.add(new UserBulkChange())
.add(new UserClear())
.build()
);

View File

@ -0,0 +1,92 @@
/*
* 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.commands.user.subcommands;
import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.commands.CommandResult;
import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.users.User;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
public class UserBulkChange extends SubCommand<User> {
public UserBulkChange() {
super("bulkchange", "Applies a bulk permission change to the users permissions", "<server|world> <from> <to>",
Permission.USER_BULKCHANGE, Predicate.not(3));
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
String type = args.get(0).toLowerCase();
String from = args.get(1);
String to = args.get(2);
if (to.equals("null")) {
to = null;
}
Set<Node> toAdd = new HashSet<>();
if (!type.equals("world") && !type.equals("server")) {
Message.BULK_CHANGE_TYPE_ERROR.send(sender);
return CommandResult.FAILURE;
}
Iterator<Node> iterator = user.getNodes().iterator();
if (type.equals("world")) {
while (iterator.hasNext()) {
Node element = iterator.next();
String world = element.getWorld().orElse("null");
if (!world.equals(from)) {
continue;
}
iterator.remove();
toAdd.add(me.lucko.luckperms.core.Node.builderFromExisting(element).setWorld(to).build());
}
} else {
while (iterator.hasNext()) {
Node element = iterator.next();
String server = element.getServer().orElse("global");
if (!server.equals(from)) {
continue;
}
iterator.remove();
toAdd.add(me.lucko.luckperms.core.Node.builderFromExisting(element).setServer(to).build());
}
}
user.getNodes().addAll(toAdd);
save(user, sender, plugin);
Message.BULK_CHANGE_SUCCESS.send(sender, toAdd.size());
return CommandResult.SUCCESS;
}
}

View File

@ -215,6 +215,9 @@ public enum Message {
REMOVE_TEMP_SUFFIX_SERVER_SUCCESS("&b{0}&a had temporary suffix &f\"{1}&f\"&a at priority &b{2}&a removed on server &b{3}&a.", true),
REMOVE_TEMP_SUFFIX_SERVER_WORLD_SUCCESS("&b{0}&a had temporary suffix &f\"{1}&f\"&a at priority &b{2}&a removed on server &b{3}&a, world &b{4}&a.", true),
BULK_CHANGE_TYPE_ERROR("Invalid type. Was expecting 'server' or 'world'.", true),
BULK_CHANGE_SUCCESS("&aApplied bulk change successfully. {0} records were changed.", true),
USER_INFO(
PREFIX + "&d-> &eUser: &6{0}" + "\n" +
PREFIX + "&d-> &eUUID: &6{1}" + "\n" +

View File

@ -72,6 +72,7 @@ public enum Permission {
USER_REMOVE_TEMP_PREFIX("removetempprefix", "user"),
USER_ADD_TEMP_SUFFIX("addtempsuffix", "user"),
USER_REMOVE_TEMP_SUFFIX("removetempsuffix", "user"),
USER_BULKCHANGE("bulkchange", "user"),
USER_CLEAR("clear", "user"),
GROUP_INFO("info", "group"),
@ -97,6 +98,7 @@ public enum Permission {
GROUP_REMOVE_TEMP_PREFIX("removetempprefix", "group"),
GROUP_ADD_TEMP_SUFFIX("addtempsuffix", "group"),
GROUP_REMOVE_TEMP_SUFFIX("removetempsuffix", "group"),
GROUP_BULKCHANGE("bulkchange", "group"),
GROUP_CLEAR("clear", "group"),
GROUP_RENAME("rename", "group"),

View File

@ -87,6 +87,10 @@ public class Node implements me.lucko.luckperms.api.Node {
}
}
public static me.lucko.luckperms.api.Node.Builder builderFromExisting(me.lucko.luckperms.api.Node other) {
return new Builder(other);
}
@Getter
private final String permission;
@ -697,6 +701,15 @@ public class Node implements me.lucko.luckperms.api.Node {
}
}
Builder(me.lucko.luckperms.api.Node other) {
this.permission = other.getPermission();
this.value = other.getValue();
this.override = other.isOverride();
this.server = other.getServer().orElse(null);
this.world = other.getWorld().orElse(null);
this.expireAt = other.getExpiryUnixTime();
}
@Override
public me.lucko.luckperms.api.Node.Builder setNegated(boolean negated) {
value = !negated;

View File

@ -171,6 +171,9 @@ remove-temp-suffix-success: "&b{0}&a had temporary suffix &f\"{1}&f\"&a at prior
remove-temp-suffix-server-success: "&b{0}&a had temporary suffix &f\"{1}&f\"&a at priority &b{2}&a removed on server &b{3}&a."
remove-temp-suffix-server-world-success: "&b{0}&a had temporary suffix &f\"{1}&f\"&a at priority &b{2}&a removed on server &b{3}&a, world &b{4}&a."
bulk-change-type-error: "Invalid type. Was expecting 'server' or 'world'."
bulk-change-success: "&aApplied bulk change successfully. {0} records were changed."
user-info: >
{PREFIX}&d-> &eUser: &6{0}\n
{PREFIX}&d-> &eUUID: &6{1}\n