mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-24 19:46:32 +01:00
Remove old bulk edit commands
This commit is contained in:
parent
c32c975a71
commit
242672f49d
@ -48,7 +48,6 @@ import me.lucko.luckperms.common.commands.impl.track.DeleteTrack;
|
|||||||
import me.lucko.luckperms.common.commands.impl.track.ListTracks;
|
import me.lucko.luckperms.common.commands.impl.track.ListTracks;
|
||||||
import me.lucko.luckperms.common.commands.impl.track.TrackMainCommand;
|
import me.lucko.luckperms.common.commands.impl.track.TrackMainCommand;
|
||||||
import me.lucko.luckperms.common.commands.impl.user.UserMainCommand;
|
import me.lucko.luckperms.common.commands.impl.user.UserMainCommand;
|
||||||
import me.lucko.luckperms.common.commands.impl.usersbulkedit.UsersBulkEditMainCommand;
|
|
||||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||||
import me.lucko.luckperms.common.commands.utils.ArgumentUtils;
|
import me.lucko.luckperms.common.commands.utils.ArgumentUtils;
|
||||||
import me.lucko.luckperms.common.commands.utils.Util;
|
import me.lucko.luckperms.common.commands.utils.Util;
|
||||||
@ -99,7 +98,6 @@ public class CommandManager {
|
|||||||
.add(new ExportCommand())
|
.add(new ExportCommand())
|
||||||
.add(new ReloadConfigCommand())
|
.add(new ReloadConfigCommand())
|
||||||
.add(new MigrationMainCommand())
|
.add(new MigrationMainCommand())
|
||||||
.add(new UsersBulkEditMainCommand())
|
|
||||||
.add(new CreateGroup())
|
.add(new CreateGroup())
|
||||||
.add(new DeleteGroup())
|
.add(new DeleteGroup())
|
||||||
.add(new ListGroups())
|
.add(new ListGroups())
|
||||||
|
@ -1,103 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.impl.group;
|
|
||||||
|
|
||||||
import me.lucko.luckperms.api.Node;
|
|
||||||
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.abstraction.SubCommand;
|
|
||||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
|
||||||
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.plugin.LuckPermsPlugin;
|
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
|
||||||
|
|
||||||
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 group's permissions", Permission.GROUP_BULKCHANGE, Predicates.not(3),
|
|
||||||
Arg.list(
|
|
||||||
Arg.create("server|world", true, "if the bulk change is modifying a 'server' or a 'world'"),
|
|
||||||
Arg.create("from", true, "the server/world to be changed from. can be 'global' or 'null' respectively"),
|
|
||||||
Arg.create("to", true, "the server/world to replace 'from' (can be 'null')")
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) throws CommandException {
|
|
||||||
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<>();
|
|
||||||
Set<Node> toRemove = new HashSet<>();
|
|
||||||
|
|
||||||
if (!type.equals("world") && !type.equals("server")) {
|
|
||||||
Message.BULK_CHANGE_TYPE_ERROR.send(sender);
|
|
||||||
return CommandResult.FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
Iterator<Node> iterator = group.getNodes().values().iterator();
|
|
||||||
if (type.equals("world")) {
|
|
||||||
while (iterator.hasNext()) {
|
|
||||||
Node element = iterator.next();
|
|
||||||
String world = element.getWorld().orElse("null");
|
|
||||||
if (!world.equals(from)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
toRemove.add(element);
|
|
||||||
toAdd.add(NodeFactory.builderFromExisting(element).setWorld(to).build());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
while (iterator.hasNext()) {
|
|
||||||
Node element = iterator.next();
|
|
||||||
String server = element.getServer().orElse("global");
|
|
||||||
if (!server.equals(from)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
toRemove.add(element);
|
|
||||||
toAdd.add(NodeFactory.builderFromExisting(element).setServer(to).build());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
toRemove.forEach(group::unsetPermission);
|
|
||||||
toAdd.forEach(group::setPermission);
|
|
||||||
|
|
||||||
save(group, sender, plugin);
|
|
||||||
Message.BULK_CHANGE_SUCCESS.send(sender, toAdd.size());
|
|
||||||
return CommandResult.SUCCESS;
|
|
||||||
}
|
|
||||||
}
|
|
@ -49,7 +49,6 @@ public class GroupMainCommand extends MainCommand<Group> {
|
|||||||
.add(new GroupListMembers())
|
.add(new GroupListMembers())
|
||||||
.add(new GroupSetWeight())
|
.add(new GroupSetWeight())
|
||||||
.add(new HolderShowTracks<>(false))
|
.add(new HolderShowTracks<>(false))
|
||||||
.add(new GroupBulkChange())
|
|
||||||
.add(new HolderClear<>(false))
|
.add(new HolderClear<>(false))
|
||||||
.add(new GroupRename())
|
.add(new GroupRename())
|
||||||
.add(new GroupClone())
|
.add(new GroupClone())
|
||||||
|
@ -1,113 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.impl.user;
|
|
||||||
|
|
||||||
import me.lucko.luckperms.api.Node;
|
|
||||||
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.abstraction.SubCommand;
|
|
||||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
|
||||||
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.User;
|
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
|
||||||
|
|
||||||
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 user's permissions", Permission.USER_BULKCHANGE, Predicates.not(3),
|
|
||||||
Arg.list(
|
|
||||||
Arg.create("server|world", true, "if the bulk change is modifying a 'server' or a 'world'"),
|
|
||||||
Arg.create("from", true, "the server/world to be changed from. can be 'global' or 'null' respectively"),
|
|
||||||
Arg.create("to", true, "the server/world to replace 'from' (can be 'null')")
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) throws CommandException {
|
|
||||||
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<>();
|
|
||||||
Set<Node> toRemove = new HashSet<>();
|
|
||||||
|
|
||||||
if (!type.equals("world") && !type.equals("server")) {
|
|
||||||
Message.BULK_CHANGE_TYPE_ERROR.send(sender);
|
|
||||||
return CommandResult.FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
Iterator<Node> iterator = user.getNodes().values().iterator();
|
|
||||||
if (type.equals("world")) {
|
|
||||||
while (iterator.hasNext()) {
|
|
||||||
Node element = iterator.next();
|
|
||||||
|
|
||||||
if (element.isGroupNode()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
String world = element.getWorld().orElse("null");
|
|
||||||
if (!world.equals(from)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
toRemove.add(element);
|
|
||||||
toAdd.add(NodeFactory.builderFromExisting(element).setWorld(to).build());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
while (iterator.hasNext()) {
|
|
||||||
Node element = iterator.next();
|
|
||||||
|
|
||||||
if (element.isGroupNode()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
String server = element.getServer().orElse("global");
|
|
||||||
if (!server.equals(from)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
toRemove.add(element);
|
|
||||||
toAdd.add(NodeFactory.builderFromExisting(element).setServer(to).build());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
toRemove.forEach(user::unsetPermission);
|
|
||||||
toAdd.forEach(user::setPermission);
|
|
||||||
|
|
||||||
save(user, sender, plugin);
|
|
||||||
Message.BULK_CHANGE_SUCCESS.send(sender, toAdd.size());
|
|
||||||
return CommandResult.SUCCESS;
|
|
||||||
}
|
|
||||||
}
|
|
@ -53,7 +53,6 @@ public class UserMainCommand extends MainCommand<User> {
|
|||||||
.add(new UserPromote())
|
.add(new UserPromote())
|
||||||
.add(new UserDemote())
|
.add(new UserDemote())
|
||||||
.add(new HolderShowTracks<>(true))
|
.add(new HolderShowTracks<>(true))
|
||||||
.add(new UserBulkChange())
|
|
||||||
.add(new HolderClear<>(true))
|
.add(new HolderClear<>(true))
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
|
@ -1,146 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.impl.usersbulkedit;
|
|
||||||
|
|
||||||
import me.lucko.luckperms.api.Node;
|
|
||||||
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.abstraction.SubCommand;
|
|
||||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
|
||||||
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.User;
|
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
|
||||||
import me.lucko.luckperms.common.storage.Storage;
|
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class BulkEditGroup extends SubCommand<Storage> {
|
|
||||||
public BulkEditGroup() {
|
|
||||||
super("group", "Bulk edit group memberships", Permission.USER_BULKCHANGE, Predicates.not(4),
|
|
||||||
Arg.list(
|
|
||||||
Arg.create("group|null", true, "the group to edit ('null' to select and edit all groups)"),
|
|
||||||
Arg.create("server|world", true, "if the bulk change is modifying a 'server' or a 'world'"),
|
|
||||||
Arg.create("from", true, "the server/world to be changed from. can be 'global' or 'null' respectively"),
|
|
||||||
Arg.create("to", true, "the server/world to replace 'from' (can be 'null')")
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Storage storage, List<String> args, String label) throws CommandException {
|
|
||||||
String group = args.get(0);
|
|
||||||
String type = args.get(1).toLowerCase();
|
|
||||||
String from = args.get(2);
|
|
||||||
String to = args.get(3);
|
|
||||||
if (to.equals("null")) {
|
|
||||||
to = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!type.equals("world") && !type.equals("server")) {
|
|
||||||
Message.BULK_CHANGE_TYPE_ERROR.send(sender);
|
|
||||||
return CommandResult.FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
Set<UUID> uuids = storage.getUniqueUsers().join();
|
|
||||||
|
|
||||||
for (UUID u : uuids) {
|
|
||||||
plugin.getStorage().loadUser(u, "null").join();
|
|
||||||
User user = plugin.getUserManager().get(u);
|
|
||||||
if (user == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Set<Node> toAdd = new HashSet<>();
|
|
||||||
Set<Node> toRemove = new HashSet<>();
|
|
||||||
Iterator<Node> iterator = user.getNodes().values().iterator();
|
|
||||||
if (type.equals("world")) {
|
|
||||||
while (iterator.hasNext()) {
|
|
||||||
Node element = iterator.next();
|
|
||||||
|
|
||||||
if (!element.isGroupNode()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (element.getGroupName().equals(user.getPrimaryGroup().getStoredValue())) {
|
|
||||||
if (!element.isServerSpecific() && !element.isWorldSpecific() && !element.isTemporary()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!group.equals("null") && !element.getGroupName().equals(group)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
String world = element.getWorld().orElse("null");
|
|
||||||
if (!world.equals(from)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
toRemove.add(element);
|
|
||||||
toAdd.add(NodeFactory.builderFromExisting(element).setWorld(to).build());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
while (iterator.hasNext()) {
|
|
||||||
Node element = iterator.next();
|
|
||||||
|
|
||||||
if (!element.isGroupNode()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (element.getGroupName().equals(user.getPrimaryGroup().getStoredValue())) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!group.equals("null") && !element.getGroupName().equals(group)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
String server = element.getServer().orElse("global");
|
|
||||||
if (!server.equals(from)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
toRemove.add(element);
|
|
||||||
toAdd.add(NodeFactory.builderFromExisting(element).setServer(to).build());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
toRemove.forEach(user::unsetPermission);
|
|
||||||
toAdd.forEach(user::setPermission);
|
|
||||||
|
|
||||||
plugin.getStorage().saveUser(user);
|
|
||||||
plugin.getUserManager().cleanup(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
Message.BULK_CHANGE_SUCCESS.send(sender, uuids.size());
|
|
||||||
return CommandResult.SUCCESS;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,136 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.impl.usersbulkedit;
|
|
||||||
|
|
||||||
import me.lucko.luckperms.api.Node;
|
|
||||||
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.abstraction.SubCommand;
|
|
||||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
|
||||||
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.User;
|
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
|
||||||
import me.lucko.luckperms.common.storage.Storage;
|
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class BulkEditPermission extends SubCommand<Storage> {
|
|
||||||
public BulkEditPermission() {
|
|
||||||
super("permission", "Bulk edit permissions", Permission.USER_BULKCHANGE, Predicates.not(4),
|
|
||||||
Arg.list(
|
|
||||||
Arg.create("node|null", true, "the node to edit ('null' to select and edit all nodes)"),
|
|
||||||
Arg.create("server|world", true, "if the bulk change is modifying a 'server' or a 'world'"),
|
|
||||||
Arg.create("from", true, "the server/world to be changed from. can be 'global' or 'null' respectively"),
|
|
||||||
Arg.create("to", true, "the server/world to replace 'from' (can be 'null')")
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Storage storage, List<String> args, String label) throws CommandException {
|
|
||||||
String node = args.get(0);
|
|
||||||
String type = args.get(1).toLowerCase();
|
|
||||||
String from = args.get(2);
|
|
||||||
String to = args.get(3);
|
|
||||||
if (to.equals("null")) {
|
|
||||||
to = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!type.equals("world") && !type.equals("server")) {
|
|
||||||
Message.BULK_CHANGE_TYPE_ERROR.send(sender);
|
|
||||||
return CommandResult.FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
Set<UUID> uuids = storage.getUniqueUsers().join();
|
|
||||||
|
|
||||||
for (UUID u : uuids) {
|
|
||||||
plugin.getStorage().loadUser(u, "null").join();
|
|
||||||
User user = plugin.getUserManager().get(u);
|
|
||||||
if (user == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Set<Node> toAdd = new HashSet<>();
|
|
||||||
Set<Node> toRemove = new HashSet<>();
|
|
||||||
Iterator<Node> iterator = user.getNodes().values().iterator();
|
|
||||||
if (type.equals("world")) {
|
|
||||||
while (iterator.hasNext()) {
|
|
||||||
Node element = iterator.next();
|
|
||||||
|
|
||||||
if (element.isGroupNode()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!node.equals("null") && !element.getPermission().equals(node)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
String world = element.getWorld().orElse("null");
|
|
||||||
if (!world.equals(from)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
toRemove.add(element);
|
|
||||||
toAdd.add(NodeFactory.builderFromExisting(element).setWorld(to).build());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
while (iterator.hasNext()) {
|
|
||||||
Node element = iterator.next();
|
|
||||||
|
|
||||||
if (element.isGroupNode()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!node.equals("null") && !element.getPermission().equals(node)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
String server = element.getServer().orElse("global");
|
|
||||||
if (!server.equals(from)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
toRemove.add(element);
|
|
||||||
toAdd.add(NodeFactory.builderFromExisting(element).setServer(to).build());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
toRemove.forEach(user::unsetPermission);
|
|
||||||
toAdd.forEach(user::setPermission);
|
|
||||||
|
|
||||||
plugin.getStorage().saveUser(user);
|
|
||||||
plugin.getUserManager().cleanup(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
Message.BULK_CHANGE_SUCCESS.send(sender, uuids.size());
|
|
||||||
return CommandResult.SUCCESS;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,93 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.impl.usersbulkedit;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
|
|
||||||
import me.lucko.luckperms.common.commands.abstraction.Command;
|
|
||||||
import me.lucko.luckperms.common.commands.abstraction.MainCommand;
|
|
||||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
|
||||||
import me.lucko.luckperms.common.storage.Storage;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class UsersBulkEditMainCommand extends MainCommand<Storage> {
|
|
||||||
|
|
||||||
public UsersBulkEditMainCommand() {
|
|
||||||
super("UsersBulkEdit", "User bulk edit commands", "/%s usersbulkedit", 1, ImmutableList.<Command<Storage, ?>>builder()
|
|
||||||
.add(new BulkEditGroup())
|
|
||||||
.add(new BulkEditPermission())
|
|
||||||
.build()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Storage getTarget(String target, LuckPermsPlugin plugin, Sender sender) {
|
|
||||||
return plugin.getStorage();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void cleanup(Storage storage, LuckPermsPlugin plugin) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<String> getTargets(LuckPermsPlugin plugin) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
|
||||||
final List<Command<Storage, ?>> subs = getChildren().get().stream()
|
|
||||||
.filter(s -> s.isAuthorized(sender))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
if (args.size() <= 1) {
|
|
||||||
if (args.isEmpty() || args.get(0).equalsIgnoreCase("")) {
|
|
||||||
return subs.stream()
|
|
||||||
.map(m -> m.getName().toLowerCase())
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
return subs.stream()
|
|
||||||
.map(m -> m.getName().toLowerCase())
|
|
||||||
.filter(s -> s.toLowerCase().startsWith(args.get(0).toLowerCase()))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
Optional<Command<Storage, ?>> o = subs.stream()
|
|
||||||
.filter(s -> s.getName().equalsIgnoreCase(args.get(0)))
|
|
||||||
.limit(1)
|
|
||||||
.findAny();
|
|
||||||
|
|
||||||
if (!o.isPresent()) {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
return o.get().tabComplete(plugin, sender, args.subList(1, args.size()));
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user