mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-24 19:46:32 +01:00
add parent clear command - closes #67
This commit is contained in:
parent
21135dac07
commit
053066f1a7
@ -37,6 +37,7 @@ public class CommandParent<T extends PermissionHolder> extends SharedMainCommand
|
||||
.add(new ParentRemove())
|
||||
.add(new ParentAddTemp())
|
||||
.add(new ParentRemoveTemp())
|
||||
.add(new ParentClear())
|
||||
.build());
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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.generic.parent;
|
||||
|
||||
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.generic.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||
import me.lucko.luckperms.common.commands.utils.ArgumentUtils;
|
||||
import me.lucko.luckperms.common.commands.utils.ContextHelper;
|
||||
import me.lucko.luckperms.common.constants.Message;
|
||||
import me.lucko.luckperms.common.constants.Permission;
|
||||
import me.lucko.luckperms.common.core.model.PermissionHolder;
|
||||
import me.lucko.luckperms.common.data.LogEntry;
|
||||
import me.lucko.luckperms.common.utils.Predicates;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ParentClear extends SharedSubCommand {
|
||||
public ParentClear() {
|
||||
super("clear", "Clears all parents", Permission.USER_PARENT_CLEAR, Permission.GROUP_PARENT_CLEAR, Predicates.notInRange(0, 2),
|
||||
Arg.list(
|
||||
Arg.create("server", false, "the server name to filter by"),
|
||||
Arg.create("world", false, "the world name to filter by")
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label) throws CommandException {
|
||||
int before = holder.getNodes().size();
|
||||
|
||||
String server = ArgumentUtils.handleServer(0, args);
|
||||
String world = ArgumentUtils.handleWorld(1, args);
|
||||
|
||||
switch (ContextHelper.determine(server, world)) {
|
||||
case NONE:
|
||||
holder.clearParents();
|
||||
break;
|
||||
case SERVER:
|
||||
holder.clearParents(server);
|
||||
break;
|
||||
case SERVER_AND_WORLD:
|
||||
holder.clearParents(server, world);
|
||||
break;
|
||||
}
|
||||
|
||||
int changed = before - holder.getNodes().size();
|
||||
if (changed == 1) {
|
||||
Message.PARENT_CLEAR_SUCCESS_SINGULAR.send(sender, holder.getFriendlyName(), changed);
|
||||
} else {
|
||||
Message.PARENT_CLEAR_SUCCESS.send(sender, holder.getFriendlyName(), changed);
|
||||
}
|
||||
|
||||
LogEntry.build().actor(sender).acted(holder)
|
||||
.action("parent clear " + args.stream().map(ArgumentUtils.WRAPPER).collect(Collectors.joining(" ")))
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
save(holder, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
@ -200,6 +200,8 @@ public enum Message {
|
||||
|
||||
CLEAR_SUCCESS("&b{0}&a's permissions were cleared. (&b{1}&a nodes were removed.)", true),
|
||||
CLEAR_SUCCESS_SINGULAR("&b{0}&a's permissions were cleared. (&b{1}&a node was removed.)", true),
|
||||
PARENT_CLEAR_SUCCESS("&b{0}&a's parents were cleared. (&b{1}&a nodes were removed.)", true),
|
||||
PARENT_CLEAR_SUCCESS_SINGULAR("&b{0}&a's parents were cleared. (&b{1}&a node was removed.)", true),
|
||||
META_CLEAR_SUCCESS("&b{0}&a's meta was cleared. (&b{1}&a nodes were removed.)", true),
|
||||
META_CLEAR_SUCCESS_SINGULAR("&b{0}&a's meta was cleared. (&b{1}&a node was removed.)", true),
|
||||
ILLEGAL_DATE_ERROR("Could not parse date '{0}'.", true),
|
||||
|
@ -62,6 +62,7 @@ public enum Permission {
|
||||
USER_PARENT_REMOVE(l("parent.remove", "removegroup"), Type.USER),
|
||||
USER_PARENT_ADDTEMP(l("parent.addtemp", "addtempgroup"), Type.USER),
|
||||
USER_PARENT_REMOVETEMP(l("parent.removetemp", "removetempgroup"), Type.USER),
|
||||
USER_PARENT_CLEAR(l("parent.clear"), Type.USER),
|
||||
USER_META_INFO(l("meta.info", "chatmeta"), Type.USER),
|
||||
USER_META_SET(l("meta.set", "setmeta"), Type.USER),
|
||||
USER_META_UNSET(l("meta.unset", "unsetmeta"), Type.USER),
|
||||
@ -98,6 +99,7 @@ public enum Permission {
|
||||
GROUP_PARENT_REMOVE(l("parent.remove", "unsetinherit"), Type.GROUP),
|
||||
GROUP_PARENT_ADDTEMP(l("parent.addtemp", "settempinherit"), Type.GROUP),
|
||||
GROUP_PARENT_REMOVETEMP(l("parent.removetemp", "unsettempinherit"), Type.GROUP),
|
||||
GROUP_PARENT_CLEAR(l("parent.clear"), Type.GROUP),
|
||||
GROUP_META_INFO(l("meta.info", "chatmeta"), Type.GROUP),
|
||||
GROUP_META_SET(l("meta.set", "setmeta"), Type.GROUP),
|
||||
GROUP_META_UNSET(l("meta.unset", "unsetmeta"), Type.GROUP),
|
||||
|
@ -948,6 +948,36 @@ public abstract class PermissionHolder {
|
||||
invalidateCache(true);
|
||||
}
|
||||
|
||||
public void clearParents() {
|
||||
synchronized (nodes) {
|
||||
boolean b = nodes.removeIf(Node::isGroupNode);
|
||||
if (!b) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (this instanceof User) {
|
||||
plugin.getUserManager().giveDefaultIfNeeded((User) this, false);
|
||||
}
|
||||
invalidateCache(true);
|
||||
}
|
||||
|
||||
public void clearParents(String server) {
|
||||
String finalServer = Optional.ofNullable(server).orElse("global");
|
||||
|
||||
synchronized (nodes) {
|
||||
boolean b = nodes.removeIf(n ->
|
||||
n.isGroupNode() && n.getServer().orElse("global").equalsIgnoreCase(finalServer)
|
||||
);
|
||||
if (!b) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (this instanceof User) {
|
||||
plugin.getUserManager().giveDefaultIfNeeded((User) this, false);
|
||||
}
|
||||
invalidateCache(true);
|
||||
}
|
||||
|
||||
public void clearParents(String server, String world) {
|
||||
String finalServer = Optional.ofNullable(server).orElse("global");
|
||||
String finalWorld = Optional.ofNullable(world).orElse("null");
|
||||
@ -962,6 +992,9 @@ public abstract class PermissionHolder {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (this instanceof User) {
|
||||
plugin.getUserManager().giveDefaultIfNeeded((User) this, false);
|
||||
}
|
||||
invalidateCache(true);
|
||||
}
|
||||
|
||||
|
@ -120,7 +120,7 @@ create-track-error: "There was an error whilst creating the track."
|
||||
delete-track-error: "There was an error whilst deleting the track."
|
||||
tracks-list: "&aTracks: {0}"
|
||||
|
||||
listnodes: "&b{0}'s Nodes:\n{1}"
|
||||
listnodes: "&b{0}'s Nodes:"
|
||||
listnodes-temp: "&b{0}'s Temporary Nodes:\n{1}"
|
||||
listparents: "&b{0}'s Parent Groups:\n{1}"
|
||||
listparents-temp: "&b{0}'s Temporary Parent Groups:\n{1}"
|
||||
@ -158,6 +158,8 @@ unset-temp-inherit-server-success: "&b{0}&a no longer temporarily inherits permi
|
||||
unset-temp-inherit-server-world-success: "&b{0}&a no longer temporarily inherits permissions from &b{1}&a on server &b{2}&a, world &b{3}&a."
|
||||
clear-success: "&b{0}&a's permissions were cleared. (&b{1}&a nodes were removed.)"
|
||||
clear-success-singular: "&b{0}&a's permissions were cleared. (&b{1}&a node was removed.)"
|
||||
parent-clear-success: "&b{0}&a's parents were cleared. (&b{1}&a nodes were removed.)"
|
||||
parent-clear-success-singular: "&b{0}&a's parents were cleared. (&b{1}&a node was removed.)"
|
||||
meta-clear-success: "&b{0}&a's meta was cleared. (&b{1}&a nodes were removed.)"
|
||||
meta-clear-success-singular: "&b{0}&a's meta was cleared. (&b{1}&a node was removed.)"
|
||||
illegal-date-error: "Could not parse date '{0}'."
|
||||
|
Loading…
Reference in New Issue
Block a user