diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java index 8298aec0..f75c4593 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java @@ -36,7 +36,6 @@ import me.lucko.luckperms.common.calculators.CalculatorFactory; import me.lucko.luckperms.common.commands.ConsecutiveExecutor; import me.lucko.luckperms.common.commands.Sender; import me.lucko.luckperms.common.config.LPConfiguration; -import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.contexts.ContextManager; import me.lucko.luckperms.common.contexts.ServerCalculator; import me.lucko.luckperms.common.core.UuidCache; diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultChatHook.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultChatHook.java index 64a9c278..acb843b2 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultChatHook.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultChatHook.java @@ -29,7 +29,6 @@ import me.lucko.luckperms.common.caching.MetaData; import me.lucko.luckperms.common.core.PermissionHolder; 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 me.lucko.luckperms.exceptions.ObjectLacksException; import net.milkbowl.vault.chat.Chat; @@ -39,8 +38,8 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; -import static me.lucko.luckperms.common.utils.ArgumentChecker.escapeCharacters; -import static me.lucko.luckperms.common.utils.ArgumentChecker.unescapeCharacters; +import static me.lucko.luckperms.api.MetaUtils.escapeCharacters; +import static me.lucko.luckperms.api.MetaUtils.unescapeCharacters; /** * Provides the Vault Chat service through the use of normal permission nodes. @@ -56,7 +55,7 @@ import static me.lucko.luckperms.common.utils.ArgumentChecker.unescapeCharacters * Permission Nodes = meta.node.value * * Node that special characters used within LuckPerms are escaped: - * See {@link ArgumentChecker#escapeCharacters(String)} + * See {@link me.lucko.luckperms.api.MetaUtils#unescapeCharacters(String)} */ public class VaultChatHook extends Chat { private final VaultPermissionHook perms; diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java b/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java index 22bbebe3..f75d2081 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java @@ -34,7 +34,6 @@ import me.lucko.luckperms.common.commands.CommandManager; import me.lucko.luckperms.common.commands.ConsecutiveExecutor; import me.lucko.luckperms.common.commands.Sender; import me.lucko.luckperms.common.config.LPConfiguration; -import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.contexts.ContextManager; import me.lucko.luckperms.common.contexts.ServerCalculator; diff --git a/common/src/main/java/me/lucko/luckperms/common/caching/MetaData.java b/common/src/main/java/me/lucko/luckperms/common/caching/MetaData.java index fd2a4e33..d6fb870b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/caching/MetaData.java +++ b/common/src/main/java/me/lucko/luckperms/common/caching/MetaData.java @@ -62,7 +62,7 @@ public class MetaData { continue; } - if (!n.isMeta() || !n.isPrefix() || n.isSuffix()) { + if (!n.isMeta() && !n.isPrefix() && n.isSuffix()) { continue; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/SecondarySubCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/SecondarySubCommand.java index c1399450..96319e45 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/SecondarySubCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/SecondarySubCommand.java @@ -27,7 +27,6 @@ import lombok.AllArgsConstructor; import lombok.Getter; 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.PermissionHolder; import me.lucko.luckperms.common.groups.Group; diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/CommandMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/CommandMeta.java index 54309657..fce7fc14 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/CommandMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/CommandMeta.java @@ -30,16 +30,20 @@ import me.lucko.luckperms.common.core.PermissionHolder; public class CommandMeta extends SecondaryMainCommand { public CommandMeta(boolean user) { super("Meta", "Edit metadata values", user, ImmutableList.builder() - .add(new MetaInfo()) - .add(new MetaAddPrefix()) - .add(new MetaAddSuffix()) - .add(new MetaRemovePrefix()) - .add(new MetaRemoveSuffix()) - .add(new MetaAddTempPrefix()) - .add(new MetaAddTempSuffix()) - .add(new MetaRemoveTempPrefix()) - .add(new MetaRemoveTempSuffix()) - .add(new MetaClear()) - .build()); + .add(new MetaInfo()) + .add(new MetaSet()) + .add(new MetaUnset()) + .add(new MetaSetTemp()) + .add(new MetaUnsetTemp()) + .add(new MetaAddPrefix()) + .add(new MetaAddSuffix()) + .add(new MetaRemovePrefix()) + .add(new MetaRemoveSuffix()) + .add(new MetaAddTempPrefix()) + .add(new MetaAddTempSuffix()) + .add(new MetaRemoveTempPrefix()) + .add(new MetaRemoveTempSuffix()) + .add(new MetaClear()) + .build()); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddPrefix.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddPrefix.java index 450e1a08..0545fa4e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddPrefix.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddPrefix.java @@ -22,6 +22,7 @@ package me.lucko.luckperms.common.commands.generic.meta; +import me.lucko.luckperms.api.MetaUtils; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.Arg; import me.lucko.luckperms.common.commands.CommandResult; @@ -60,7 +61,7 @@ public class MetaAddPrefix extends SecondarySubCommand { return CommandResult.INVALID_ARGS; } - final String node = "prefix." + priority + "." + ArgumentChecker.escapeCharacters(prefix); + final String node = "prefix." + priority + "." + MetaUtils.escapeCharacters(prefix); try { if (args.size() >= 3) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddSuffix.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddSuffix.java index 3bb495d6..e57b64e6 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddSuffix.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddSuffix.java @@ -22,6 +22,7 @@ package me.lucko.luckperms.common.commands.generic.meta; +import me.lucko.luckperms.api.MetaUtils; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.Arg; import me.lucko.luckperms.common.commands.CommandResult; @@ -60,7 +61,7 @@ public class MetaAddSuffix extends SecondarySubCommand { return CommandResult.INVALID_ARGS; } - final String node = "suffix." + priority + "." + ArgumentChecker.escapeCharacters(suffix); + final String node = "suffix." + priority + "." + MetaUtils.escapeCharacters(suffix); try { if (args.size() >= 3) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempPrefix.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempPrefix.java index 0e38fc99..70a1fa8f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempPrefix.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempPrefix.java @@ -22,6 +22,7 @@ package me.lucko.luckperms.common.commands.generic.meta; +import me.lucko.luckperms.api.MetaUtils; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.Arg; import me.lucko.luckperms.common.commands.CommandResult; @@ -79,7 +80,7 @@ public class MetaAddTempPrefix extends SecondarySubCommand { return CommandResult.INVALID_ARGS; } - final String node = "prefix." + priority + "." + ArgumentChecker.escapeCharacters(prefix); + final String node = "prefix." + priority + "." + MetaUtils.escapeCharacters(prefix); try { if (args.size() >= 4) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempSuffix.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempSuffix.java index 185f1a64..712b8dbc 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempSuffix.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempSuffix.java @@ -22,6 +22,7 @@ package me.lucko.luckperms.common.commands.generic.meta; +import me.lucko.luckperms.api.MetaUtils; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.Arg; import me.lucko.luckperms.common.commands.CommandResult; @@ -79,7 +80,7 @@ public class MetaAddTempSuffix extends SecondarySubCommand { return CommandResult.INVALID_ARGS; } - final String node = "suffix." + priority + "." + ArgumentChecker.escapeCharacters(suffix); + final String node = "suffix." + priority + "." + MetaUtils.escapeCharacters(suffix); try { if (args.size() >= 4) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemovePrefix.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemovePrefix.java index 936f0a81..1cb3544d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemovePrefix.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemovePrefix.java @@ -22,6 +22,7 @@ package me.lucko.luckperms.common.commands.generic.meta; +import me.lucko.luckperms.api.MetaUtils; import me.lucko.luckperms.api.Node; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.Arg; @@ -113,7 +114,7 @@ public class MetaRemovePrefix extends SecondarySubCommand { } else { - final String node = "prefix." + priority + "." + ArgumentChecker.escapeCharacters(prefix); + final String node = "prefix." + priority + "." + MetaUtils.escapeCharacters(prefix); try { if (args.size() >= 3) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveSuffix.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveSuffix.java index 7f5939c8..6f84bbc7 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveSuffix.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveSuffix.java @@ -22,6 +22,7 @@ package me.lucko.luckperms.common.commands.generic.meta; +import me.lucko.luckperms.api.MetaUtils; import me.lucko.luckperms.api.Node; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.Arg; @@ -113,7 +114,7 @@ public class MetaRemoveSuffix extends SecondarySubCommand { } else { - final String node = "suffix." + priority + "." + ArgumentChecker.escapeCharacters(suffix); + final String node = "suffix." + priority + "." + MetaUtils.escapeCharacters(suffix); try { if (args.size() >= 3) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempPrefix.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempPrefix.java index 41626ddd..447f6630 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempPrefix.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempPrefix.java @@ -22,6 +22,7 @@ package me.lucko.luckperms.common.commands.generic.meta; +import me.lucko.luckperms.api.MetaUtils; import me.lucko.luckperms.api.Node; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.Arg; @@ -113,7 +114,7 @@ public class MetaRemoveTempPrefix extends SecondarySubCommand { } else { - final String node = "prefix." + priority + "." + ArgumentChecker.escapeCharacters(prefix); + final String node = "prefix." + priority + "." + MetaUtils.escapeCharacters(prefix); try { if (args.size() >= 3) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempSuffix.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempSuffix.java index ab057899..1542dc89 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempSuffix.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempSuffix.java @@ -22,6 +22,7 @@ package me.lucko.luckperms.common.commands.generic.meta; +import me.lucko.luckperms.api.MetaUtils; import me.lucko.luckperms.api.Node; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.Arg; @@ -113,7 +114,7 @@ public class MetaRemoveTempSuffix extends SecondarySubCommand { } else { - final String node = "suffix." + priority + "." + ArgumentChecker.escapeCharacters(suffix); + final String node = "suffix." + priority + "." + MetaUtils.escapeCharacters(suffix); try { if (args.size() >= 3) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSet.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSet.java new file mode 100644 index 00000000..44c4760c --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSet.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2016 Lucko (Luck) + * + * 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.meta; + +import me.lucko.luckperms.api.MetaUtils; +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.Node; +import me.lucko.luckperms.common.core.PermissionHolder; +import me.lucko.luckperms.common.data.LogEntry; +import me.lucko.luckperms.common.utils.ArgumentChecker; +import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; + +import java.util.List; + +public class MetaSet extends SecondarySubCommand { + public MetaSet() { + super("set", "Sets a meta value", Permission.USER_SET_META, Permission.GROUP_SET_META, Predicate.notInRange(2, 4), + Arg.list( + Arg.create("key", true, "the key to set"), + Arg.create("value", true, "the value to set"), + Arg.create("server", false, "the server to add the meta pair on"), + Arg.create("world", false, "the world to add the meta pair on") + ) + ); + } + + @Override + public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args) { + String key = MetaUtils.escapeCharacters(args.get(0)); + String value = MetaUtils.escapeCharacters(args.get(1)); + + String node = "meta." + key + "." + value; + String server = null; + String world = null; + + if (args.size() >= 3) { + server = args.get(2).toLowerCase(); + if (ArgumentChecker.checkServer(server)) { + Message.SERVER_INVALID_ENTRY.send(sender); + return CommandResult.INVALID_ARGS; + } + + if (args.size() != 3) { + world = args.get(3).toLowerCase(); + } + } + + me.lucko.luckperms.api.Node n = new Node.Builder(node).setServer(server).setWorld(world).build(); + + if (holder.hasPermission(n).asBoolean()) { + Message.ALREADY_HAS_META.send(sender, holder.getFriendlyName()); + return CommandResult.STATE_ERROR; + } + + holder.clearMetaKeys(key, server, world, false); + + try { + holder.setPermission(n); + } catch (ObjectAlreadyHasException ignored) {} + + if (server == null) { + Message.SET_META_SUCCESS.send(sender, key, value, holder.getFriendlyName()); + LogEntry.build().actor(sender).acted(holder) + .action("meta set " + key + " " + value) + .build().submit(plugin, sender); + } else { + if (world == null) { + Message.SET_META_SERVER_SUCCESS.send(sender, key, value, holder.getFriendlyName(), server); + LogEntry.build().actor(sender).acted(holder) + .action("meta set " + key + " " + value + " " + server) + .build().submit(plugin, sender); + } else { + Message.SET_META_SERVER_WORLD_SUCCESS.send(sender, key, value, holder.getFriendlyName(), server, world); + LogEntry.build().actor(sender).acted(holder) + .action("meta set " + key + " " + value + " " + server + " " + world) + .build().submit(plugin, sender); + } + } + + save(holder, sender, plugin); + return CommandResult.SUCCESS; + } +} diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetTemp.java new file mode 100644 index 00000000..8497490c --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetTemp.java @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2016 Lucko (Luck) + * + * 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.meta; + +import me.lucko.luckperms.api.MetaUtils; +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.Node; +import me.lucko.luckperms.common.core.PermissionHolder; +import me.lucko.luckperms.common.data.LogEntry; +import me.lucko.luckperms.common.utils.ArgumentChecker; +import me.lucko.luckperms.common.utils.DateUtil; +import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; + +import java.util.List; + +public class MetaSetTemp extends SecondarySubCommand { + public MetaSetTemp() { + super("settemp", "Sets a meta value temporarily", Permission.USER_SET_TEMP_META, Permission.GROUP_SET_TEMP_META, Predicate.notInRange(3, 5), + Arg.list( + Arg.create("key", true, "the key to set"), + Arg.create("value", true, "the value to set"), + Arg.create("duration", true, "the duration until the meta value expires"), + Arg.create("server", false, "the server to add the meta pair on"), + Arg.create("world", false, "the world to add the meta pair on") + ) + ); + } + + @Override + public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args) { + long duration; + try { + duration = Long.parseLong(args.get(2)); + } catch (NumberFormatException e) { + try { + duration = DateUtil.parseDateDiff(args.get(2), true); + } catch (DateUtil.IllegalDateException e1) { + Message.ILLEGAL_DATE_ERROR.send(sender, args.get(2)); + return CommandResult.INVALID_ARGS; + } + } + + if (DateUtil.shouldExpire(duration)) { + Message.PAST_DATE_ERROR.send(sender); + return CommandResult.INVALID_ARGS; + } + + String key = MetaUtils.escapeCharacters(args.get(0)); + String value = MetaUtils.escapeCharacters(args.get(1)); + + String node = "meta." + key + "." + value; + String server = null; + String world = null; + + if (args.size() >= 3) { + server = args.get(2).toLowerCase(); + if (ArgumentChecker.checkServer(server)) { + Message.SERVER_INVALID_ENTRY.send(sender); + return CommandResult.INVALID_ARGS; + } + + if (args.size() != 3) { + world = args.get(3).toLowerCase(); + } + } + + me.lucko.luckperms.api.Node n = new Node.Builder(node).setServer(server).setWorld(world).setExpiry(duration).build(); + + if (holder.hasPermission(n).asBoolean()) { + Message.ALREADY_HAS_META.send(sender, holder.getFriendlyName()); + return CommandResult.STATE_ERROR; + } + + holder.clearMetaKeys(key, server, world, true); + + try { + holder.setPermission(n); + } catch (ObjectAlreadyHasException ignored) {} + + if (server == null) { + Message.SET_META_TEMP_SUCCESS.send(sender, key, value, holder.getFriendlyName(), DateUtil.formatDateDiff(duration)); + LogEntry.build().actor(sender).acted(holder) + .action("meta settemp " + key + " " + value + " " + duration) + .build().submit(plugin, sender); + } else { + if (world == null) { + Message.SET_META_TEMP_SERVER_SUCCESS.send(sender, key, value, holder.getFriendlyName(), server, DateUtil.formatDateDiff(duration)); + LogEntry.build().actor(sender).acted(holder) + .action("meta settemp " + key + " " + value + " " + duration + " " + server) + .build().submit(plugin, sender); + } else { + Message.SET_META_TEMP_SERVER_WORLD_SUCCESS.send(sender, key, value, holder.getFriendlyName(), server, world, DateUtil.formatDateDiff(duration)); + LogEntry.build().actor(sender).acted(holder) + .action("meta settemp " + key + " " + value + " " + duration + " " + server + " " + world) + .build().submit(plugin, sender); + } + } + + save(holder, sender, plugin); + return CommandResult.SUCCESS; + } +} diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnset.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnset.java new file mode 100644 index 00000000..9ff9e7a4 --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnset.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2016 Lucko (Luck) + * + * 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.meta; + +import me.lucko.luckperms.api.MetaUtils; +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.utils.ArgumentChecker; + +import java.util.List; +import java.util.stream.Collectors; + +public class MetaUnset extends SecondarySubCommand { + public MetaUnset() { + super("unset", "Unsets a meta value", Permission.USER_UNSET_META, Permission.GROUP_UNSET_META, Predicate.notInRange(1, 3), + Arg.list( + Arg.create("key", true, "the key to unset"), + Arg.create("server", false, "the server to remove the meta pair on"), + Arg.create("world", false, "the world to remove the meta pair on") + ) + ); + } + + @Override + public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args) { + String key = MetaUtils.escapeCharacters(args.get(0)); + + String server = null; + String world = null; + + if (args.size() >= 2) { + server = args.get(1).toLowerCase(); + if (ArgumentChecker.checkServer(server)) { + Message.SERVER_INVALID_ENTRY.send(sender); + return CommandResult.INVALID_ARGS; + } + + if (args.size() != 2) { + world = args.get(2).toLowerCase(); + } + } + + holder.clearMetaKeys(key, server, world, false); + + if (server == null) { + Message.UNSET_META_SUCCESS.send(sender, key, holder.getFriendlyName()); + } else { + if (world == null) { + Message.UNSET_META_SERVER_SUCCESS.send(sender, key, holder.getFriendlyName(), server); + } else { + Message.UNSET_META_SERVER_WORLD_SUCCESS.send(sender, key, holder.getFriendlyName(), server, world); + } + } + + LogEntry.build().actor(sender).acted(holder) + .action("meta unset " + args.stream().collect(Collectors.joining(" "))) + .build().submit(plugin, sender); + + save(holder, sender, plugin); + return CommandResult.SUCCESS; + } +} diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnsetTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnsetTemp.java new file mode 100644 index 00000000..36e1d460 --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnsetTemp.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2016 Lucko (Luck) + * + * 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.meta; + +import me.lucko.luckperms.api.MetaUtils; +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.utils.ArgumentChecker; + +import java.util.List; +import java.util.stream.Collectors; + +public class MetaUnsetTemp extends SecondarySubCommand { + public MetaUnsetTemp() { + super("unset", "Unsets a temporary meta value", Permission.USER_UNSET_TEMP_META, Permission.GROUP_UNSET_TEMP_META, Predicate.notInRange(1, 3), + Arg.list( + Arg.create("key", true, "the key to unset"), + Arg.create("server", false, "the server to remove the meta pair on"), + Arg.create("world", false, "the world to remove the meta pair on") + ) + ); + } + + @Override + public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args) { + String key = MetaUtils.escapeCharacters(args.get(0)); + + String server = null; + String world = null; + + if (args.size() >= 2) { + server = args.get(1).toLowerCase(); + if (ArgumentChecker.checkServer(server)) { + Message.SERVER_INVALID_ENTRY.send(sender); + return CommandResult.INVALID_ARGS; + } + + if (args.size() != 2) { + world = args.get(2).toLowerCase(); + } + } + + holder.clearMetaKeys(key, server, world, true); + + if (server == null) { + Message.UNSET_META_TEMP_SUCCESS.send(sender, key, holder.getFriendlyName()); + } else { + if (world == null) { + Message.UNSET_META_TEMP_SERVER_SUCCESS.send(sender, key, holder.getFriendlyName(), server); + } else { + Message.UNSET_META_TEMP_SERVER_WORLD_SUCCESS.send(sender, key, holder.getFriendlyName(), server, world); + } + } + + LogEntry.build().actor(sender).acted(holder) + .action("meta unsettemp " + args.stream().collect(Collectors.joining(" "))) + .build().submit(plugin, sender); + + save(holder, sender, plugin); + return CommandResult.SUCCESS; + } +} diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/CommandParent.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/CommandParent.java index 9676e63e..c2aca71c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/CommandParent.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/CommandParent.java @@ -30,11 +30,11 @@ import me.lucko.luckperms.common.core.PermissionHolder; public class CommandParent extends SecondaryMainCommand { public CommandParent(boolean user) { super("Parent", "Edit inheritances", user, ImmutableList.builder() - .add(new ParentInfo()) - .add(new ParentAdd()) - .add(new ParentRemove()) - .add(new ParentAddTemp()) - .add(new ParentRemoveTemp()) - .build()); + .add(new ParentInfo()) + .add(new ParentAdd()) + .add(new ParentRemove()) + .add(new ParentAddTemp()) + .add(new ParentRemoveTemp()) + .build()); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/CommandPermission.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/CommandPermission.java index 40985485..8f79a49f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/CommandPermission.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/CommandPermission.java @@ -30,11 +30,11 @@ import me.lucko.luckperms.common.core.PermissionHolder; public class CommandPermission extends SecondaryMainCommand { public CommandPermission(boolean user) { super("Permission", "Edit permissions", user, ImmutableList.builder() - .add(new PermissionInfo()) - .add(new PermissionSet()) - .add(new PermissionUnset()) - .add(new PermissionSetTemp()) - .add(new PermissionUnsetTemp()) - .build()); + .add(new PermissionInfo()) + .add(new PermissionSet()) + .add(new PermissionUnset()) + .add(new PermissionSetTemp()) + .add(new PermissionUnsetTemp()) + .build()); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupMainCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupMainCommand.java index 0826206e..f91984bd 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupMainCommand.java @@ -27,10 +27,10 @@ import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.MainCommand; import me.lucko.luckperms.common.commands.Sender; import me.lucko.luckperms.common.commands.SubCommand; +import me.lucko.luckperms.common.commands.generic.meta.CommandMeta; import me.lucko.luckperms.common.commands.generic.parent.CommandParent; import me.lucko.luckperms.common.commands.generic.permission.CommandPermission; import me.lucko.luckperms.common.commands.group.subcommands.*; -import me.lucko.luckperms.common.commands.generic.meta.CommandMeta; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.groups.Group; diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationBPermissions.java b/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationBPermissions.java index 5c171a9a..87a2605c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationBPermissions.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationBPermissions.java @@ -24,6 +24,7 @@ package me.lucko.luckperms.common.commands.migration.subcommands; import de.bananaco.bpermissions.api.*; import me.lucko.luckperms.api.Logger; +import me.lucko.luckperms.api.MetaUtils; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.Predicate; @@ -222,7 +223,7 @@ public class MigrationBPermissions extends SubCommand { // Migrate existing meta for (Map.Entry meta : c.getMeta().entrySet()) { if (meta.getKey().equalsIgnoreCase("prefix") || meta.getKey().equalsIgnoreCase("suffix")) { - String chatMeta = ArgumentChecker.escapeCharacters(meta.getValue()); + String chatMeta = MetaUtils.escapeCharacters(meta.getValue()); try { holder.setPermission(meta.getKey().toLowerCase() + "." + c.getPriority() + "." + chatMeta, true); LogEntry.build() diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationBungeePerms.java b/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationBungeePerms.java index 3a88c29e..32ec58b4 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationBungeePerms.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationBungeePerms.java @@ -23,6 +23,7 @@ package me.lucko.luckperms.common.commands.migration.subcommands; import me.lucko.luckperms.api.Logger; +import me.lucko.luckperms.api.MetaUtils; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.Predicate; @@ -144,7 +145,7 @@ public class MigrationBungeePerms extends SubCommand { String suffix = g.getSuffix(); if (prefix != null && !prefix.equals("")) { - prefix = ArgumentChecker.escapeCharacters(prefix); + prefix = MetaUtils.escapeCharacters(prefix); try { group.setPermission("prefix.50." + prefix, true); LogEntry.build() @@ -159,7 +160,7 @@ public class MigrationBungeePerms extends SubCommand { } if (suffix != null && !suffix.equals("")) { - suffix = ArgumentChecker.escapeCharacters(suffix); + suffix = MetaUtils.escapeCharacters(suffix); try { group.setPermission("suffix.50." + suffix, true); LogEntry.build() @@ -259,7 +260,7 @@ public class MigrationBungeePerms extends SubCommand { String suffix = u.getSuffix(); if (prefix != null && !prefix.equals("")) { - prefix = ArgumentChecker.escapeCharacters(prefix); + prefix = MetaUtils.escapeCharacters(prefix); try { user.setPermission("prefix.100." + prefix, true); LogEntry.build() @@ -274,7 +275,7 @@ public class MigrationBungeePerms extends SubCommand { } if (suffix != null && !suffix.equals("")) { - suffix = ArgumentChecker.escapeCharacters(suffix); + suffix = MetaUtils.escapeCharacters(suffix); try { user.setPermission("suffix.100." + suffix, true); LogEntry.build() diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationPermissionsEx.java b/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationPermissionsEx.java index 65826a22..2d8f0b4e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationPermissionsEx.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationPermissionsEx.java @@ -23,6 +23,7 @@ package me.lucko.luckperms.common.commands.migration.subcommands; import me.lucko.luckperms.api.Logger; +import me.lucko.luckperms.api.MetaUtils; import me.lucko.luckperms.api.PlatformType; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.*; @@ -197,7 +198,7 @@ public class MigrationPermissionsEx extends SubCommand { String suffix = group.getOwnSuffix(); if (prefix != null && !prefix.equals("")) { - prefix = ArgumentChecker.escapeCharacters(prefix); + prefix = MetaUtils.escapeCharacters(prefix); try { lpGroup.setPermission("prefix." + groupWeight + "." + prefix, true); LogEntry.build() @@ -212,7 +213,7 @@ public class MigrationPermissionsEx extends SubCommand { } if (suffix != null && !suffix.equals("")) { - suffix = ArgumentChecker.escapeCharacters(suffix); + suffix = MetaUtils.escapeCharacters(suffix); try { lpGroup.setPermission("suffix." + groupWeight + "." + suffix, true); LogEntry.build() @@ -341,7 +342,7 @@ public class MigrationPermissionsEx extends SubCommand { String suffix = user.getOwnSuffix(); if (prefix != null && !prefix.equals("")) { - prefix = ArgumentChecker.escapeCharacters(prefix); + prefix = MetaUtils.escapeCharacters(prefix); try { lpUser.setPermission("prefix." + maxGroupWeight + "." + prefix, true); LogEntry.build() @@ -356,7 +357,7 @@ public class MigrationPermissionsEx extends SubCommand { } if (suffix != null && !suffix.equals("")) { - suffix = ArgumentChecker.escapeCharacters(suffix); + suffix = MetaUtils.escapeCharacters(suffix); try { lpUser.setPermission("suffix." + maxGroupWeight + "." + suffix, true); LogEntry.build() diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationZPermissions.java b/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationZPermissions.java index aede139b..faa0db22 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationZPermissions.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationZPermissions.java @@ -23,6 +23,7 @@ package me.lucko.luckperms.common.commands.migration.subcommands; import me.lucko.luckperms.api.Logger; +import me.lucko.luckperms.api.MetaUtils; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.*; import me.lucko.luckperms.common.constants.Constants; @@ -213,7 +214,7 @@ public class MigrationZPermissions extends SubCommand { String suffix = service.getPlayerSuffix(u); if (prefix != null && !prefix.equals("")) { - prefix = ArgumentChecker.escapeCharacters(prefix); + prefix = MetaUtils.escapeCharacters(prefix); try { user.setPermission("prefix.100." + prefix, true); LogEntry.build() @@ -228,7 +229,7 @@ public class MigrationZPermissions extends SubCommand { } if (suffix != null && !suffix.equals("")) { - suffix = ArgumentChecker.escapeCharacters(suffix); + suffix = MetaUtils.escapeCharacters(suffix); try { user.setPermission("suffix.100." + suffix, true); LogEntry.build() diff --git a/common/src/main/java/me/lucko/luckperms/common/constants/Message.java b/common/src/main/java/me/lucko/luckperms/common/constants/Message.java index 7e892a1d..e7cf1ca1 100644 --- a/common/src/main/java/me/lucko/luckperms/common/constants/Message.java +++ b/common/src/main/java/me/lucko/luckperms/common/constants/Message.java @@ -223,6 +223,22 @@ 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), + ALREADY_HAS_META("{0} already has that meta key value pair set.", true), + + SET_META_SUCCESS("&aSet meta value for key &f\"{0}&f\"&a to &f\"{1}&f\"&a for &b{2}&a.", true), + SET_META_SERVER_SUCCESS("&aSet meta value for key &f\"{0}&f\"&a to &f\"{1}&f\"&a for &b{2}&a on server &b{3}&a.", true), + SET_META_SERVER_WORLD_SUCCESS("&aSet meta value for key &f\"{0}&f\"&a to &f\"{1}&f\"&a for &b{2}&a on server &b{3}&a, world &b{4}&a.", true), + SET_META_TEMP_SUCCESS("&aSet meta value for key &f\"{0}&f\"&a to &f\"{1}&f\"&a for &b{2}&a for a duration of &b{3}&a.", true), + SET_META_TEMP_SERVER_SUCCESS("&aSet meta value for key &f\"{0}&f\"&a to &f\"{1}&f\"&a for &b{2}&a on server &b{3}&a for a duration of &b{4}&a.", true), + SET_META_TEMP_SERVER_WORLD_SUCCESS("&aSet meta value for key &f\"{0}&f\"&a to &f\"{1}&f\"&a for &b{2}&a on server &b{3}&a, world &b{4}&a, for a duration of &b{5}&a.", true), + + UNSET_META_SUCCESS("&aUnset meta value with key &f\"{0}&f\"&a for &b{1}&a.", true), + UNSET_META_SERVER_SUCCESS("&aUnset meta value with key &f\"{0}&f\"&a for &b{1}&a on server &b{2}&a.", true), + UNSET_META_SERVER_WORLD_SUCCESS("&aUnset meta value with key &f\"{0}&f\"&a for &b{1}&a on server &b{2}&a, world &b{3}&a.", true), + UNSET_META_TEMP_SUCCESS("&aUnset temporary meta value with key &f\"{0}&f\"&a for &b{1}&a.", true), + UNSET_META_TEMP_SERVER_SUCCESS("&aUnset temporary meta value with key &f\"{0}&f\"&a for &b{1}&a on server &b{2}&a.", true), + UNSET_META_TEMP_SERVER_WORLD_SUCCESS("&aUnset temporary meta value with key &f\"{0}&f\"&a for &b{1}&a on server &b{2}&a, world &b{3}&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), diff --git a/common/src/main/java/me/lucko/luckperms/common/constants/Permission.java b/common/src/main/java/me/lucko/luckperms/common/constants/Permission.java index da8d5a63..bfcedf0b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/constants/Permission.java +++ b/common/src/main/java/me/lucko/luckperms/common/constants/Permission.java @@ -72,6 +72,10 @@ public enum Permission { USER_REMOVE_TEMP_PREFIX("removetempprefix", "user"), USER_ADD_TEMP_SUFFIX("addtempsuffix", "user"), USER_REMOVE_TEMP_SUFFIX("removetempsuffix", "user"), + USER_SET_META("setmeta", "user"), + USER_UNSET_META("unsetmeta", "user"), + USER_SET_TEMP_META("settempmeta", "user"), + USER_UNSET_TEMP_META("unsettempmeta", "user"), USER_CLEARMETA("clearmeta", "user"), USER_BULKCHANGE("bulkchange", "user"), USER_CLEAR("clear", "user"), @@ -99,6 +103,10 @@ public enum Permission { GROUP_REMOVE_TEMP_PREFIX("removetempprefix", "group"), GROUP_ADD_TEMP_SUFFIX("addtempsuffix", "group"), GROUP_REMOVE_TEMP_SUFFIX("removetempsuffix", "group"), + GROUP_SET_META("setmeta", "group"), + GROUP_UNSET_META("unsetmeta", "group"), + GROUP_SET_TEMP_META("settempmeta", "group"), + GROUP_UNSET_TEMP_META("unsettempmeta", "group"), GROUP_CLEARMETA("clearmeta", "group"), GROUP_BULKCHANGE("bulkchange", "group"), GROUP_CLEAR("clear", "group"), diff --git a/common/src/main/java/me/lucko/luckperms/common/core/PermissionHolder.java b/common/src/main/java/me/lucko/luckperms/common/core/PermissionHolder.java index 256f4ad4..294fa277 100644 --- a/common/src/main/java/me/lucko/luckperms/common/core/PermissionHolder.java +++ b/common/src/main/java/me/lucko/luckperms/common/core/PermissionHolder.java @@ -232,6 +232,47 @@ public abstract class PermissionHolder { } } + public void clearMetaKeys(String key, boolean temp) { + synchronized (nodes) { + nodes.removeIf(n -> n.isMeta() && (n.isTemporary() == temp) && n.getMeta().getKey().equalsIgnoreCase(key)); + invalidateCache(true); + } + } + + public void clearMetaKeys(String key, String server, boolean temp) { + if (server == null) { + server = "global"; + } + String finalServer = server; + + synchronized (nodes) { + nodes.removeIf(n -> n.isMeta() && (n.isTemporary() == temp) && n.getMeta().getKey().equalsIgnoreCase(key) && + n.getServer().orElse("global").equalsIgnoreCase(finalServer) + ); + invalidateCache(true); + } + } + + public void clearMetaKeys(String key, String server, String world, boolean temp) { + if (server == null) { + server = "global"; + } + String finalServer = server; + + if (world == null) { + world = "null"; + } + String finalWorld = world; + + synchronized (nodes) { + nodes.removeIf(n -> n.isMeta() && (n.isTemporary() == temp) && n.getMeta().getKey().equalsIgnoreCase(key) && + n.getServer().orElse("global").equalsIgnoreCase(finalServer) && + n.getWorld().orElse("null").equalsIgnoreCase(finalWorld) + ); + invalidateCache(true); + } + } + public void clearTransientNodes() { synchronized (transientNodes) { transientNodes.clear(); diff --git a/common/src/main/java/me/lucko/luckperms/common/users/User.java b/common/src/main/java/me/lucko/luckperms/common/users/User.java index 8674bb9f..5614a652 100644 --- a/common/src/main/java/me/lucko/luckperms/common/users/User.java +++ b/common/src/main/java/me/lucko/luckperms/common/users/User.java @@ -90,7 +90,7 @@ public class User extends PermissionHolder implements Identifiable