Move hasperm/inheritsperm commands & add parent set command. Resolves #40

This commit is contained in:
Luck 2016-10-31 19:27:04 +00:00
parent e2cebfbd16
commit d2de26f765
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
19 changed files with 238 additions and 193 deletions

View File

@ -231,6 +231,16 @@ public class CommandManager {
case "unsettemp":
args.add(2, "permission");
break;
case "haspermission":
args.remove(2);
args.add(2, "permission");
args.add(3, "check");
break;
case "inheritspermission":
args.remove(2);
args.add(2, "permission");
args.add(3, "checkinherits");
break;
case "listgroups":
args.remove(2);
args.add(2, "parent");
@ -242,6 +252,11 @@ public class CommandManager {
args.add(2, "parent");
args.add(3, "add");
break;
case "setgroup":
args.remove(2);
args.add(2, "parent");
args.add(3, "set");
break;
case "removegroup":
case "unsetinherit":
args.remove(2);

View File

@ -22,7 +22,6 @@
package me.lucko.luckperms.common.commands.generic;
import com.google.common.collect.ImmutableList;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.constants.Message;
@ -39,12 +38,7 @@ public class SecondaryMainCommand<T extends PermissionHolder> extends SubCommand
private final List<SecondarySubCommand> secondaryCommands;
public SecondaryMainCommand(String name, String description, boolean user, List<SecondarySubCommand> secondaryCommands) {
super(name, description, null, Predicate.alwaysFalse(),
!name.equals("Meta") ? ImmutableList.copyOf(secondaryCommands.stream()
.map(s -> Arg.create(s.getName(), false, s.getDescription()))
.collect(Collectors.toList())
) : null
);
super(name, description, null, Predicate.alwaysFalse(), null);
this.secondaryCommands = secondaryCommands;
this.user = user;
}

View File

@ -31,6 +31,7 @@ public class CommandParent<T extends PermissionHolder> extends SecondaryMainComm
public CommandParent(boolean user) {
super("Parent", "Edit inheritances", user, ImmutableList.<SecondarySubCommand>builder()
.add(new ParentInfo())
.add(new ParentSet())
.add(new ParentAdd())
.add(new ParentRemove())
.add(new ParentAddTemp())

View File

@ -56,7 +56,7 @@ public class ParentAdd extends SecondarySubCommand {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
String groupName = args.get(0).toLowerCase();
if (ArgumentChecker.checkNode(groupName)) {
if (ArgumentChecker.checkName(groupName)) {
sendDetailedUsage(sender);
return CommandResult.INVALID_ARGS;
}

View File

@ -58,7 +58,7 @@ public class ParentAddTemp extends SecondarySubCommand {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
String groupName = args.get(0).toLowerCase();
if (ArgumentChecker.checkNode(groupName)) {
if (ArgumentChecker.checkName(groupName)) {
sendDetailedUsage(sender);
return CommandResult.INVALID_ARGS;
}

View File

@ -56,7 +56,7 @@ public class ParentRemove extends SecondarySubCommand {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
String groupName = args.get(0).toLowerCase();
if (ArgumentChecker.checkNode(groupName)) {
if (ArgumentChecker.checkName(groupName)) {
sendDetailedUsage(sender);
return CommandResult.INVALID_ARGS;
}

View File

@ -55,7 +55,7 @@ public class ParentRemoveTemp extends SecondarySubCommand {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
String groupName = args.get(0).toLowerCase();
if (ArgumentChecker.checkNode(groupName)) {
if (ArgumentChecker.checkName(groupName)) {
sendDetailedUsage(sender);
return CommandResult.INVALID_ARGS;
}

View File

@ -0,0 +1,130 @@
/*
* 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.CommandResult;
import me.lucko.luckperms.common.commands.Predicate;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.commands.generic.SecondarySubCommand;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.PermissionHolder;
import me.lucko.luckperms.common.data.LogEntry;
import me.lucko.luckperms.common.groups.Group;
import me.lucko.luckperms.common.users.User;
import me.lucko.luckperms.common.utils.ArgumentChecker;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import java.util.List;
import static me.lucko.luckperms.common.commands.SubCommand.getGroupTabComplete;
public class ParentSet extends SecondarySubCommand {
public ParentSet() {
super("set", "Removes all other groups the object inherits already and adds them to the one given",
Permission.USER_PARENT_SET, Permission.GROUP_PARENT_SET, Predicate.notInRange(1, 3),
Arg.list(
Arg.create("group", true, "the group to set to"),
Arg.create("server", false, "the server to set the group on"),
Arg.create("world", false, "the world to set the group on")
)
);
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
String groupName = args.get(0).toLowerCase();
if (ArgumentChecker.checkNode(groupName)) {
sendDetailedUsage(sender);
return CommandResult.INVALID_ARGS;
}
if (!plugin.getDatastore().loadGroup(groupName).getUnchecked()) {
Message.GROUP_DOES_NOT_EXIST.send(sender);
return CommandResult.INVALID_ARGS;
}
Group group = plugin.getGroupManager().get(groupName);
if (group == null) {
Message.GROUP_DOES_NOT_EXIST.send(sender);
return CommandResult.LOADING_ERROR;
}
try {
if (args.size() >= 2) {
final String server = args.get(1).toLowerCase();
if (ArgumentChecker.checkServer(server)) {
Message.SERVER_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
if (args.size() == 2) {
holder.clearParents(server);
holder.setInheritGroup(group, server);
Message.SET_PARENT_SERVER_SUCCESS.send(sender, holder.getFriendlyName(), group.getDisplayName(), server);
LogEntry.build().actor(sender).acted(holder)
.action("parent set " + group.getName() + " " + server)
.build().submit(plugin, sender);
} else {
final String world = args.get(2).toLowerCase();
holder.clearParents(server, world);
holder.setInheritGroup(group, server, world);
Message.SET_PARENT_SERVER_WORLD_SUCCESS.send(sender, holder.getFriendlyName(), group.getDisplayName(), server, world);
LogEntry.build().actor(sender).acted(holder)
.action("parent set " + group.getName() + " " + server + " " + world)
.build().submit(plugin, sender);
}
} else {
holder.clearParents();
holder.setInheritGroup(group);
if (holder instanceof User) {
((User) holder).setPrimaryGroup(group.getName());
}
Message.SET_PARENT_SUCCESS.send(sender, holder.getFriendlyName(), group.getDisplayName());
LogEntry.build().actor(sender).acted(holder)
.action("parent set " + group.getName())
.build().submit(plugin, sender);
}
save(holder, sender, plugin);
return CommandResult.SUCCESS;
} catch (ObjectAlreadyHasException e) {
Message.ALREADY_INHERITS.send(sender, holder.getFriendlyName(), group.getDisplayName());
return CommandResult.STATE_ERROR;
}
}
@Override
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return getGroupTabComplete(args, plugin);
}
}

View File

@ -35,6 +35,8 @@ public class CommandPermission<T extends PermissionHolder> extends SecondaryMain
.add(new PermissionUnset())
.add(new PermissionSetTemp())
.add(new PermissionUnsetTemp())
.add(new PermissionCheck())
.add(new PermissionCheckInherits())
.build());
}
}

View File

@ -20,21 +20,22 @@
* SOFTWARE.
*/
package me.lucko.luckperms.common.commands.group.subcommands;
package me.lucko.luckperms.common.commands.generic.permission;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.commands.generic.SecondarySubCommand;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.NodeBuilder;
import me.lucko.luckperms.common.groups.Group;
import me.lucko.luckperms.common.core.PermissionHolder;
import me.lucko.luckperms.common.utils.ArgumentChecker;
import java.util.List;
public class GroupHasPerm extends SubCommand<Group> {
public GroupHasPerm() {
super("haspermission", "Checks to see if the group has a certain permission node", Permission.GROUP_HASPERMISSION,
public class PermissionCheck extends SecondarySubCommand {
public PermissionCheck() {
super("check", "Checks to see if the object has a certain permission node", Permission.USER_PERM_CHECK, Permission.GROUP_PERM_CHECK,
Predicate.notInRange(1, 3),
Arg.list(
Arg.create("node", true, "the permission node to check for"),
@ -45,7 +46,7 @@ public class GroupHasPerm extends SubCommand<Group> {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
if (args.size() >= 2) {
if (ArgumentChecker.checkServer(args.get(1))) {
Message.SERVER_INVALID_ENTRY.send(sender);
@ -53,13 +54,13 @@ public class GroupHasPerm extends SubCommand<Group> {
}
if (args.size() == 2) {
Util.sendTristate(sender, args.get(0), group.hasPermission(new NodeBuilder(args.get(0)).setServer(args.get(1)).build()));
Util.sendTristate(sender, args.get(0), holder.hasPermission(new NodeBuilder(args.get(0)).setServer(args.get(1)).build()));
} else {
Util.sendTristate(sender, args.get(0), group.hasPermission(new NodeBuilder(args.get(0)).setServer(args.get(1)).setWorld(args.get(2)).build()));
Util.sendTristate(sender, args.get(0), holder.hasPermission(new NodeBuilder(args.get(0)).setServer(args.get(1)).setWorld(args.get(2)).build()));
}
} else {
Util.sendTristate(sender, args.get(0), group.hasPermission(new NodeBuilder(args.get(0)).build()));
Util.sendTristate(sender, args.get(0), holder.hasPermission(new NodeBuilder(args.get(0)).build()));
}
return CommandResult.SUCCESS;
}

View File

@ -20,23 +20,24 @@
* SOFTWARE.
*/
package me.lucko.luckperms.common.commands.group.subcommands;
package me.lucko.luckperms.common.commands.generic.permission;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.commands.generic.SecondarySubCommand;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.InheritanceInfo;
import me.lucko.luckperms.common.core.NodeBuilder;
import me.lucko.luckperms.common.groups.Group;
import me.lucko.luckperms.common.core.PermissionHolder;
import me.lucko.luckperms.common.utils.ArgumentChecker;
import java.util.List;
public class GroupInheritsPerm extends SubCommand<Group> {
public GroupInheritsPerm() {
super("inheritspermission", "Checks to see if the group inherits a certain permission node",
Permission.GROUP_INHERITSPERMISSION, Predicate.notInRange(1, 3),
public class PermissionCheckInherits extends SecondarySubCommand {
public PermissionCheckInherits() {
super("checkinherits", "Checks to see if the object inherits a certain permission node", Permission.USER_PERM_CHECK_INHERITS, Permission.GROUP_PERM_CHECK_INHERITS,
Predicate.notInRange(1, 3),
Arg.list(
Arg.create("node", true, "the permission node to check for"),
Arg.create("server", false, "the server to check on"),
@ -46,7 +47,7 @@ public class GroupInheritsPerm extends SubCommand<Group> {
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
InheritanceInfo result;
if (args.size() >= 2) {
if (ArgumentChecker.checkServer(args.get(1))) {
@ -55,18 +56,18 @@ public class GroupInheritsPerm extends SubCommand<Group> {
}
if (args.size() == 2) {
result = group.inheritsPermissionInfo(new NodeBuilder(args.get(0)).setServer(args.get(1)).build());
result = holder.inheritsPermissionInfo(new NodeBuilder(args.get(0)).setServer(args.get(1)).build());
} else {
result = group.inheritsPermissionInfo(new NodeBuilder(args.get(0)).setServer(args.get(1)).setWorld(args.get(2)).build());
result = holder.inheritsPermissionInfo(new NodeBuilder(args.get(0)).setServer(args.get(1)).setWorld(args.get(2)).build());
}
} else {
result = group.inheritsPermissionInfo(new NodeBuilder(args.get(0)).build());
result = holder.inheritsPermissionInfo(new NodeBuilder(args.get(0)).build());
}
String location = null;
if (result.getLocation().isPresent()) {
if (result.getLocation().get().equals(group.getObjectName())) {
if (result.getLocation().get().equals(holder.getObjectName())) {
location = "self";
} else {
location = result.getLocation().get();

View File

@ -44,8 +44,6 @@ public class GroupMainCommand extends MainCommand<Group> {
.add(new CommandPermission<>(false))
.add(new CommandParent<>(false))
.add(new CommandMeta<>(false))
.add(new GroupHasPerm())
.add(new GroupInheritsPerm())
.add(new GroupShowTracks())
.add(new GroupBulkChange())
.add(new GroupClear())

View File

@ -47,8 +47,6 @@ public class UserMainCommand extends MainCommand<User> {
.add(new CommandParent<>(true))
.add(new CommandMeta<>(true))
.add(new UserGetUUID())
.add(new UserHasPerm())
.add(new UserInheritsPerm())
.add(new UserSetPrimaryGroup())
.add(new UserShowTracks())
.add(new UserPromote())

View File

@ -1,66 +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.user.subcommands;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.NodeBuilder;
import me.lucko.luckperms.common.users.User;
import me.lucko.luckperms.common.utils.ArgumentChecker;
import java.util.List;
public class UserHasPerm extends SubCommand<User> {
public UserHasPerm() {
super("haspermission", "Checks to see if the user has a certain permission node", Permission.USER_HASPERMISSION,
Predicate.notInRange(1, 3),
Arg.list(
Arg.create("node", true, "the permission node to check for"),
Arg.create("server", false, "the server to check on"),
Arg.create("world", false, "the world to check on")
)
);
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
if (args.size() >= 2) {
if (ArgumentChecker.checkServer(args.get(1))) {
Message.SERVER_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
if (args.size() == 2) {
Util.sendTristate(sender, args.get(0), user.hasPermission(new NodeBuilder(args.get(0)).setServer(args.get(1)).build()));
} else {
Util.sendTristate(sender, args.get(0), user.hasPermission(new NodeBuilder(args.get(0)).setServer(args.get(1)).setWorld(args.get(2)).build()));
}
} else {
Util.sendTristate(sender, args.get(0), user.hasPermission(new NodeBuilder(args.get(0)).build()));
}
return CommandResult.SUCCESS;
}
}

View File

@ -1,80 +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.user.subcommands;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.InheritanceInfo;
import me.lucko.luckperms.common.core.NodeBuilder;
import me.lucko.luckperms.common.users.User;
import me.lucko.luckperms.common.utils.ArgumentChecker;
import java.util.List;
public class UserInheritsPerm extends SubCommand<User> {
public UserInheritsPerm() {
super("inheritspermission", "Checks to see if the user inherits a certain permission node",
Permission.USER_INHERITSPERMISSION, Predicate.notInRange(1, 3),
Arg.list(
Arg.create("node", true, "the permission node to check for"),
Arg.create("server", false, "the server to check on"),
Arg.create("world", false, "the world to check on")
)
);
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
InheritanceInfo result;
if (args.size() >= 2) {
if (ArgumentChecker.checkServer(args.get(1))) {
Message.SERVER_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
if (args.size() == 2) {
result = user.inheritsPermissionInfo(new NodeBuilder(args.get(0)).setServer(args.get(1)).build());
} else {
result = user.inheritsPermissionInfo(new NodeBuilder(args.get(0)).setServer(args.get(1)).setWorld(args.get(2)).build());
}
} else {
result = user.inheritsPermissionInfo(new NodeBuilder(args.get(0)).build());
}
String location = null;
if (result.getLocation().isPresent()) {
if (result.getLocation().get().equals(user.getObjectName())) {
location = "self";
} else {
location = result.getLocation().get();
}
}
Util.sendPluginMessage(sender, "&b" + args.get(0) + ": " + Util.formatTristate(result.getResult()) +
(result.getLocation().isPresent() ? " &7(inherited from &a" + location + "&7)" : ""));
return CommandResult.SUCCESS;
}
}

View File

@ -174,6 +174,9 @@ public enum Message {
SET_INHERIT_SUCCESS("&b{0}&a now inherits permissions from &b{1}&a.", true),
SET_INHERIT_SERVER_SUCCESS("&b{0}&a now inherits permissions from &b{1}&a on server &b{2}&a.", true),
SET_INHERIT_SERVER_WORLD_SUCCESS("&b{0}&a now inherits permissions from &b{1}&a on server &b{2}&a, world &b{3}&a.", true),
SET_PARENT_SUCCESS("&b{0}&a had their existing parent groups cleared, and now only inherits &b{1}&a.", true),
SET_PARENT_SERVER_SUCCESS("&b{0}&a had their existing parent groups cleared, and now only inherits &b{1}&a on server &b{2}&a.", true),
SET_PARENT_SERVER_WORLD_SUCCESS("&b{0}&a had their existing parent groups cleared, and now only inherits &b{1}&a on server &b{2}&a, world &b{3}&a.", true),
SET_TEMP_INHERIT_SUCCESS("&b{0}&a now inherits permissions from &b{1}&a for a duration of &b{2}&a.", true),
SET_TEMP_INHERIT_SERVER_SUCCESS("&b{0}&a now inherits permissions from &b{1}&a on server &b{2}&a for a duration of &b{3}&a.", true),
SET_TEMP_INHERIT_SERVER_WORLD_SUCCESS("&b{0}&a now inherits permissions from &b{1}&a on server &b{2}&a, world &b{3}&a, for a duration of &b{4}&a.", true),

View File

@ -54,7 +54,10 @@ public enum Permission {
USER_PERM_UNSET(set("permission.unset", "unsetpermission"), Type.USER),
USER_PERM_SETTEMP(set("permission.settemp", "settemppermission"), Type.USER),
USER_PERM_UNSETTEMP(set("permission.unsettemp", "unsettemppermission"), Type.USER),
USER_PERM_CHECK(set("permission.check", "haspermission"), Type.USER),
USER_PERM_CHECK_INHERITS(set("permission.checkinherits", "inheritspermission"), Type.USER),
USER_PARENT_INFO(set("parent.info", "listgroups"), Type.USER),
USER_PARENT_SET(set("parent.set"), Type.USER),
USER_PARENT_ADD(set("parent.add", "addgroup"), Type.USER),
USER_PARENT_REMOVE(set("parent.remove", "removegroup"), Type.USER),
USER_PARENT_ADDTEMP(set("parent.addtemp", "addtempgroup"), Type.USER),
@ -74,8 +77,6 @@ public enum Permission {
USER_META_REMOVETEMP_SUFFIX(set("meta.removetempsuffix", "removetempsuffix"), Type.USER),
USER_META_CLEAR(set("meta.clear", "clearmeta"), Type.USER),
USER_GETUUID(set("getuuid"), Type.USER),
USER_HASPERMISSION(set("haspermission"), Type.USER),
USER_INHERITSPERMISSION(set("inheritspermission"), Type.USER),
USER_SETPRIMARYGROUP(set("setprimarygroup"), Type.USER),
USER_SHOWTRACKS(set("showtracks"), Type.USER),
USER_PROMOTE(set("promote"), Type.USER),
@ -90,7 +91,10 @@ public enum Permission {
GROUP_PERM_UNSET(set("permission.unset", "unsetpermission"), Type.GROUP),
GROUP_PERM_SETTEMP(set("permission.settemp", "settemppermission"), Type.GROUP),
GROUP_PERM_UNSETTEMP(set("permission.unsettemp", "unsettemppermission"), Type.GROUP),
GROUP_PERM_CHECK(set("permission.check", "haspermission"), Type.GROUP),
GROUP_PERM_CHECK_INHERITS(set("permission.checkinherits", "inheritspermission"), Type.GROUP),
GROUP_PARENT_INFO(set("parent.info", "listparents"), Type.GROUP),
GROUP_PARENT_SET(set("parent.set"), Type.GROUP),
GROUP_PARENT_ADD(set("parent.add", "setinherit"), Type.GROUP),
GROUP_PARENT_REMOVE(set("parent.remove", "unsetinherit"), Type.GROUP),
GROUP_PARENT_ADDTEMP(set("parent.addtemp", "settempinherit"), Type.GROUP),
@ -109,8 +113,6 @@ public enum Permission {
GROUP_META_REMOVETEMP_PREFIX(set("meta.removetempprefix", "removetempprefix"), Type.GROUP),
GROUP_META_REMOVETEMP_SUFFIX(set("meta.removetempsuffix", "removetempsuffix"), Type.GROUP),
GROUP_META_CLEAR(set("meta.clear", "clearmeta"), Type.GROUP),
GROUP_HASPERMISSION(set("haspermission"), Type.GROUP),
GROUP_INHERITSPERMISSION(set("inheritspermission"), Type.GROUP),
GROUP_SHOWTRACKS(set("showtracks"), Type.GROUP),
GROUP_BULKCHANGE(set("bulkchange"), Type.GROUP),
GROUP_CLEAR(set("clear"), Type.GROUP),

View File

@ -129,14 +129,21 @@ public abstract class PermissionHolder {
TreeSet<LocalizedNode> combined = new TreeSet<>(PriorityComparator.reverse());
// Flatten enduring and transient nodes
combined.addAll(getNodes().stream()
.map(n -> makeLocal(n, getObjectName()))
.collect(Collectors.toList())
);
combined.addAll(getTransientNodes().stream()
.map(n -> makeLocal(n, getObjectName()))
.collect(Collectors.toList())
);
Set<Node> enduring = getNodes();
if (!enduring.isEmpty()) {
combined.addAll(getNodes().stream()
.map(n -> makeLocal(n, getObjectName()))
.collect(Collectors.toList())
);
}
Set<Node> tran = getTransientNodes();
if (!tran.isEmpty()) {
combined.addAll(getTransientNodes().stream()
.map(n -> makeLocal(n, getObjectName()))
.collect(Collectors.toList())
);
}
// Create an iterator over all permissions being considered
Iterator<LocalizedNode> it = combined.iterator();
@ -735,6 +742,42 @@ public abstract class PermissionHolder {
}
}
public void clearParents() {
synchronized (nodes) {
boolean b = nodes.removeIf(Node::isGroupNode);
if (b) {
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) {
invalidateCache(true);
}
}
}
public void clearParents(String server, String world) {
String finalServer = Optional.ofNullable(server).orElse("global");
String finalWorld = Optional.ofNullable(world).orElse("null");
synchronized (nodes) {
boolean b = nodes.removeIf(n ->
n.isGroupNode() &&
n.getServer().orElse("global").equalsIgnoreCase(finalServer) &&
n.getWorld().orElse("null").equalsIgnoreCase(finalWorld)
);
if (b) {
invalidateCache(true);
}
}
}
public void clearMeta() {
synchronized (nodes) {
boolean b = nodes.removeIf(n -> n.isMeta() || n.isPrefix() || n.isSuffix());

View File

@ -129,6 +129,9 @@ unset-temp-permission-server-world-success: "&aUnset temporary permission &b{0}&
set-inherit-success: "&b{0}&a now inherits permissions from &b{1}&a."
set-inherit-server-success: "&b{0}&a now inherits permissions from &b{2}&a on server &b{3}&a."
set-inherit-server-world-success: "&b{0}&a now inherits permissions from &b{1}&a on server &b{2}&a, world &b{3}&a."
set-parent-success: "&b{0}&a had their existing parent groups cleared, and now only inherits &b{1}&a."
set-parent-server-success: "&b{0}&a had their existing parent groups cleared, and now only inherits &b{1}&a on server &b{2}&a."
set-parent-server-world-success: "&b{0}&a had their existing parent groups cleared, and now only inherits &b{1}&a on server &b{2}&a, world &b{3}&a."
set-temp-inherit-success: "&b{0}&a now inherits permissions from &b{1}&a for a duration of &b{2}&a."
set-temp-inherit-server-success: "&b{0}&a now inherits permissions from &b{1}&a on server &b{2}&a for a duration of &b{3}&a."
set-temp-inherit-server-world-success: "&b{0}&a now inherits permissions from &b{1}&a on server &b{2}&a, world &b{3}&a, for a duration of &b{4}&a."