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 b289ce4d..7e41e662 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java @@ -578,7 +578,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { MutableContextSet set = MutableContextSet.create(); set.add("server", getConfiguration().get(ConfigKeys.SERVER)); set.add("world", s); - set.addAll(configuration.getStaticContexts().getContextSet()); + set.addAll(configuration.getContextsFile().getStaticContexts()); return set.makeImmutable(); }) .collect(Collectors.toList()) @@ -593,7 +593,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { MutableContextSet set = MutableContextSet.create(); set.add("server", getConfiguration().get(ConfigKeys.VAULT_SERVER)); set.add("world", s); - set.addAll(configuration.getStaticContexts().getContextSet()); + set.addAll(configuration.getContextsFile().getStaticContexts()); return set.makeImmutable(); }) .collect(Collectors.toList()) diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaAddChatMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaAddChatMeta.java index 5a419d90..17ba15aa 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaAddChatMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaAddChatMeta.java @@ -69,7 +69,7 @@ public class MetaAddChatMeta extends SharedSubCommand { public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args, String label) throws CommandException { int priority = ArgumentUtils.handlePriority(0, args); String meta = ArgumentUtils.handleString(1, args); - MutableContextSet context = ArgumentUtils.handleContext(2, args); + MutableContextSet context = ArgumentUtils.handleContext(2, args, plugin); DataMutateResult result = holder.setPermission(NodeFactory.makeChatMetaNode(isPrefix, priority, meta).withExtraContext(context).build()); if (result.asBoolean()) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaAddTempChatMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaAddTempChatMeta.java index 96770264..8b515c2d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaAddTempChatMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaAddTempChatMeta.java @@ -76,7 +76,7 @@ public class MetaAddTempChatMeta extends SharedSubCommand { int priority = ArgumentUtils.handlePriority(0, args); String meta = ArgumentUtils.handleString(1, args); long duration = ArgumentUtils.handleDuration(2, args); - MutableContextSet context = ArgumentUtils.handleContext(3, args); + MutableContextSet context = ArgumentUtils.handleContext(3, args, plugin); TemporaryModifier modifier = plugin.getConfiguration().get(ConfigKeys.TEMPORARY_ADD_BEHAVIOUR); Map.Entry ret = holder.setPermission(NodeFactory.makeChatMetaNode(isPrefix, priority, meta).setExpiry(duration).withExtraContext(context).build(), modifier); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaClear.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaClear.java index d22ca565..d86c4676 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaClear.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaClear.java @@ -55,7 +55,7 @@ public class MetaClear extends SharedSubCommand { public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args, String label) throws CommandException { int before = holder.getNodes().size(); - MutableContextSet context = ArgumentUtils.handleContext(0, args); + MutableContextSet context = ArgumentUtils.handleContext(0, args, plugin); if (context.isEmpty()) { holder.clearMeta(); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaRemoveChatMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaRemoveChatMeta.java index 8001c69d..b20699bf 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaRemoveChatMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaRemoveChatMeta.java @@ -69,7 +69,7 @@ public class MetaRemoveChatMeta extends SharedSubCommand { public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args, String label) throws CommandException { int priority = ArgumentUtils.handlePriority(0, args); String meta = ArgumentUtils.handleStringOrElse(1, args, "null"); - MutableContextSet context = ArgumentUtils.handleContext(2, args); + MutableContextSet context = ArgumentUtils.handleContext(2, args, plugin); // Handle bulk removal if (meta.equalsIgnoreCase("null") || meta.equals("*")) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaRemoveTempChatMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaRemoveTempChatMeta.java index 6f99286f..2d26150d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaRemoveTempChatMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaRemoveTempChatMeta.java @@ -69,7 +69,7 @@ public class MetaRemoveTempChatMeta extends SharedSubCommand { public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args, String label) throws CommandException { int priority = ArgumentUtils.handlePriority(0, args); String meta = ArgumentUtils.handleStringOrElse(1, args, "null"); - MutableContextSet context = ArgumentUtils.handleContext(2, args); + MutableContextSet context = ArgumentUtils.handleContext(2, args, plugin); // Handle bulk removal if (meta.equalsIgnoreCase("null") || meta.equals("*")) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaSet.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaSet.java index 4728653a..4019165d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaSet.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaSet.java @@ -60,7 +60,7 @@ public class MetaSet extends SharedSubCommand { public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args, String label) throws CommandException { String key = args.get(0); String value = args.get(1); - MutableContextSet context = ArgumentUtils.handleContext(2, args); + MutableContextSet context = ArgumentUtils.handleContext(2, args, plugin); Node n = NodeFactory.makeMetaNode(key, value).withExtraContext(context).build(); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaSetTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaSetTemp.java index c23330a5..e63c82db 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaSetTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaSetTemp.java @@ -65,7 +65,7 @@ public class MetaSetTemp extends SharedSubCommand { String key = args.get(0); String value = args.get(1); long duration = ArgumentUtils.handleDuration(2, args); - MutableContextSet context = ArgumentUtils.handleContext(2, args); + MutableContextSet context = ArgumentUtils.handleContext(2, args, plugin); TemporaryModifier modifier = plugin.getConfiguration().get(ConfigKeys.TEMPORARY_ADD_BEHAVIOUR); Node n = NodeFactory.makeMetaNode(key, value).withExtraContext(context).setExpiry(duration).build(); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaUnset.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaUnset.java index db3da41f..920f7b0d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaUnset.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaUnset.java @@ -57,7 +57,7 @@ public class MetaUnset extends SharedSubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args, String label) throws CommandException { String key = args.get(0); - MutableContextSet context = ArgumentUtils.handleContext(1, args); + MutableContextSet context = ArgumentUtils.handleContext(1, args, plugin); holder.clearMetaKeys(key, context, false); Message.UNSET_META_SUCCESS.send(sender, key, holder.getFriendlyName(), Util.contextSetToString(context)); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaUnsetTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaUnsetTemp.java index 57464d08..4c1eee40 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaUnsetTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaUnsetTemp.java @@ -57,7 +57,7 @@ public class MetaUnsetTemp extends SharedSubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args, String label) throws CommandException { String key = args.get(0); - MutableContextSet context = ArgumentUtils.handleContext(1, args); + MutableContextSet context = ArgumentUtils.handleContext(1, args, plugin); holder.clearMetaKeys(key, context, true); Message.UNSET_META_TEMP_SUCCESS.send(sender, key, holder.getFriendlyName(), Util.contextSetToString(context)); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/other/HolderClear.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/other/HolderClear.java index c817dc32..8ee1deac 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/other/HolderClear.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/other/HolderClear.java @@ -58,7 +58,7 @@ public class HolderClear extends SubCommand { public CommandResult execute(LuckPermsPlugin plugin, Sender sender, T holder, List args, String label) throws CommandException { int before = holder.getNodes().size(); - MutableContextSet context = ArgumentUtils.handleContext(0, args); + MutableContextSet context = ArgumentUtils.handleContext(0, args, plugin); if (context.isEmpty()) { holder.clearNodes(); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentAdd.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentAdd.java index 75d55ad0..73d309ac 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentAdd.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentAdd.java @@ -61,7 +61,7 @@ public class ParentAdd extends SharedSubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args, String label) throws CommandException { String groupName = ArgumentUtils.handleName(0, args); - MutableContextSet context = ArgumentUtils.handleContext(1, args); + MutableContextSet context = ArgumentUtils.handleContext(1, args, plugin); if (!plugin.getStorage().loadGroup(groupName).join()) { Message.GROUP_DOES_NOT_EXIST.send(sender); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentAddTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentAddTemp.java index f7558d00..5c6966d6 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentAddTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentAddTemp.java @@ -69,7 +69,7 @@ public class ParentAddTemp extends SharedSubCommand { public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args, String label) throws CommandException { String groupName = ArgumentUtils.handleName(0, args); long duration = ArgumentUtils.handleDuration(1, args); - MutableContextSet context = ArgumentUtils.handleContext(2, args); + MutableContextSet context = ArgumentUtils.handleContext(2, args, plugin); TemporaryModifier modifier = plugin.getConfiguration().get(ConfigKeys.TEMPORARY_ADD_BEHAVIOUR); if (!plugin.getStorage().loadGroup(groupName).join()) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentClear.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentClear.java index 43997f63..6dc610d0 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentClear.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentClear.java @@ -55,7 +55,7 @@ public class ParentClear extends SharedSubCommand { public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args, String label) throws CommandException { int before = holder.getNodes().size(); - MutableContextSet context = ArgumentUtils.handleContext(0, args); + MutableContextSet context = ArgumentUtils.handleContext(0, args, plugin); if (context.isEmpty()) { holder.clearParents(true); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentRemove.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentRemove.java index 20cbe861..74324dc7 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentRemove.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentRemove.java @@ -63,7 +63,7 @@ public class ParentRemove extends SharedSubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args, String label) throws CommandException { String groupName = ArgumentUtils.handleNameWithSpace(0, args); - MutableContextSet context = ArgumentUtils.handleContext(1, args); + MutableContextSet context = ArgumentUtils.handleContext(1, args, plugin); if (holder instanceof User) { User user = (User) holder; diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentRemoveTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentRemoveTemp.java index 0e7659d2..5fff4b81 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentRemoveTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentRemoveTemp.java @@ -61,7 +61,7 @@ public class ParentRemoveTemp extends SharedSubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args, String label) throws CommandException { String groupName = ArgumentUtils.handleNameWithSpace(0, args); - MutableContextSet context = ArgumentUtils.handleContext(1, args); + MutableContextSet context = ArgumentUtils.handleContext(1, args, plugin); DataMutateResult result = holder.unsetPermission(NodeFactory.newBuilder("group." + groupName).setExpiry(10L).withExtraContext(context).build()); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentSet.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentSet.java index 0658f264..bc74faf8 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentSet.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentSet.java @@ -61,7 +61,7 @@ public class ParentSet extends SharedSubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args, String label) throws CommandException { String groupName = ArgumentUtils.handleName(0, args); - MutableContextSet context = ArgumentUtils.handleContext(1, args); + MutableContextSet context = ArgumentUtils.handleContext(1, args, plugin); if (!plugin.getStorage().loadGroup(groupName).join()) { Message.GROUP_DOES_NOT_EXIST.send(sender); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/permission/PermissionCheck.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/permission/PermissionCheck.java index fcf0e098..eb5a42b7 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/permission/PermissionCheck.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/permission/PermissionCheck.java @@ -59,7 +59,7 @@ public class PermissionCheck extends SharedSubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args, String label) throws CommandException { String node = ArgumentUtils.handleString(0, args); - MutableContextSet context = ArgumentUtils.handleContext(1, args); + MutableContextSet context = ArgumentUtils.handleContext(1, args, plugin); Tristate result = holder.hasPermission(NodeFactory.newBuilder(node).withExtraContext(context).build()); String s = Util.formatTristate(result); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/permission/PermissionCheckInherits.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/permission/PermissionCheckInherits.java index 0c7e7e8c..c996c6fe 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/permission/PermissionCheckInherits.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/permission/PermissionCheckInherits.java @@ -59,7 +59,7 @@ public class PermissionCheckInherits extends SharedSubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args, String label) throws CommandException { String node = ArgumentUtils.handleString(0, args); - MutableContextSet context = ArgumentUtils.handleContext(1, args); + MutableContextSet context = ArgumentUtils.handleContext(1, args, plugin); InheritanceInfo result = holder.inheritsPermissionInfo(NodeFactory.newBuilder(node).withExtraContext(context).build()); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/permission/PermissionSet.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/permission/PermissionSet.java index 691502d3..84b4194c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/permission/PermissionSet.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/permission/PermissionSet.java @@ -64,7 +64,7 @@ public class PermissionSet extends SharedSubCommand { public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args, String label) throws CommandException { boolean b = ArgumentUtils.handleBoolean(1, args); String node = b ? ArgumentUtils.handleNode(0, args) : ArgumentUtils.handleString(0, args); - MutableContextSet context = ArgumentUtils.handleContext(2, args); + MutableContextSet context = ArgumentUtils.handleContext(2, args, plugin); DataMutateResult result = holder.setPermission(NodeFactory.newBuilder(node).setValue(b).withExtraContext(context).build()); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/permission/PermissionSetTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/permission/PermissionSetTemp.java index a9aa7623..99c73def 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/permission/PermissionSetTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/permission/PermissionSetTemp.java @@ -71,7 +71,7 @@ public class PermissionSetTemp extends SharedSubCommand { boolean b = ArgumentUtils.handleBoolean(1, args); String node = b ? ArgumentUtils.handleNode(0, args) : ArgumentUtils.handleString(0, args); long duration = ArgumentUtils.handleDuration(2, args); - MutableContextSet context = ArgumentUtils.handleContext(3, args); + MutableContextSet context = ArgumentUtils.handleContext(3, args, plugin); TemporaryModifier modifier = plugin.getConfiguration().get(ConfigKeys.TEMPORARY_ADD_BEHAVIOUR); Map.Entry result = holder.setPermission(NodeFactory.newBuilder(node).setValue(b).withExtraContext(context).setExpiry(duration).build(), modifier); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/permission/PermissionUnset.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/permission/PermissionUnset.java index a5607e5c..a23b2c4c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/permission/PermissionUnset.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/permission/PermissionUnset.java @@ -59,7 +59,7 @@ public class PermissionUnset extends SharedSubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args, String label) throws CommandException { String node = ArgumentUtils.handleString(0, args); - MutableContextSet context = ArgumentUtils.handleContext(1, args); + MutableContextSet context = ArgumentUtils.handleContext(1, args, plugin); DataMutateResult result; if (node.startsWith("group.")) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/permission/PermissionUnsetTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/permission/PermissionUnsetTemp.java index d30ab6ab..5dfde4d0 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/permission/PermissionUnsetTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/permission/PermissionUnsetTemp.java @@ -59,7 +59,7 @@ public class PermissionUnsetTemp extends SharedSubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args, String label) throws CommandException { String node = ArgumentUtils.handleString(0, args); - MutableContextSet context = ArgumentUtils.handleContext(1, args); + MutableContextSet context = ArgumentUtils.handleContext(1, args, plugin); DataMutateResult result = holder.unsetPermission(NodeFactory.newBuilder(node).setExpiry(10L).withExtraContext(context).build()); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserDemote.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserDemote.java index c410573e..57e60c6b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserDemote.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserDemote.java @@ -84,7 +84,7 @@ public class UserDemote extends SubCommand { return CommandResult.STATE_ERROR; } - MutableContextSet context = ArgumentUtils.handleContext(1, args); + MutableContextSet context = ArgumentUtils.handleContext(1, args, plugin); boolean silent = false; if (args.contains("-s")) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserPromote.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserPromote.java index 37f81c71..580d4531 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserPromote.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserPromote.java @@ -84,7 +84,7 @@ public class UserPromote extends SubCommand { return CommandResult.STATE_ERROR; } - MutableContextSet context = ArgumentUtils.handleContext(1, args); + MutableContextSet context = ArgumentUtils.handleContext(1, args, plugin); boolean silent = false; if (args.contains("-s")) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/utils/ArgumentUtils.java b/common/src/main/java/me/lucko/luckperms/common/commands/utils/ArgumentUtils.java index bdbdaf20..6ed6a72d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/utils/ArgumentUtils.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/utils/ArgumentUtils.java @@ -32,6 +32,7 @@ import me.lucko.luckperms.api.context.ImmutableContextSet; import me.lucko.luckperms.api.context.MutableContextSet; import me.lucko.luckperms.common.commands.CommandException; import me.lucko.luckperms.common.constants.DataConstraints; +import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.utils.DateUtil; import java.util.ArrayList; @@ -137,7 +138,7 @@ public class ArgumentUtils { return args.size() > index ? args.get(index).toLowerCase() : null; } - public static MutableContextSet handleContext(int fromIndex, List args) throws CommandException { + public static MutableContextSet handleContext(int fromIndex, List args, LuckPermsPlugin plugin) throws CommandException { if (args.size() > fromIndex) { MutableContextSet set = MutableContextSet.create(); @@ -149,14 +150,6 @@ public class ArgumentUtils { // one of the first two values, and doesn't have a key if (i <= 1 && !pair.contains("=")) { String key = i == 0 ? "server" : "world"; - - if (key.equals("server") && !DataConstraints.SERVER_NAME_TEST.test(pair)) { - throw new InvalidServerWorldException(); - } - if (key.equals("world") && !DataConstraints.WORLD_NAME_TEST.test(pair)) { - throw new InvalidServerWorldException(); - } - set.add(key, pair); continue; } @@ -176,48 +169,59 @@ public class ArgumentUtils { continue; } - if (key.equals("server") && !DataConstraints.SERVER_NAME_TEST.test(value)) { - throw new InvalidServerWorldException(); - } - if (key.equals("world") && !DataConstraints.WORLD_NAME_TEST.test(value)) { - throw new InvalidServerWorldException(); - } - set.add(key, value); } - // remove any potential "global" context mappings - set.remove("server", "global"); - set.remove("world", "global"); - set.remove("server", "null"); - set.remove("world", "null"); - set.remove("server", "*"); - set.remove("world", "*"); - - // remove excess entries from the set. - // (it can only have one server and one world.) - List servers = new ArrayList<>(set.getValues("server")); - if (servers.size() > 1) { - // start iterating at index 1 - for (int i = 1; i < servers.size(); i++) { - set.remove("server", servers.get(i)); - } - } - - List worlds = new ArrayList<>(set.getValues("world")); - if (worlds.size() > 1) { - // start iterating at index 1 - for (int i = 1; i < worlds.size(); i++) { - set.remove("world", worlds.get(i)); - } - } - - return set; + return sanitizeContexts(set); } else { - return MutableContextSet.create(); + return sanitizeContexts(plugin.getConfiguration().getContextsFile().getDefaultContexts().mutableCopy()); } } + public static MutableContextSet sanitizeContexts(MutableContextSet set) throws ArgumentException { + // remove any potential "global" context mappings + set.remove("server", "global"); + set.remove("world", "global"); + set.remove("server", "null"); + set.remove("world", "null"); + set.remove("server", "*"); + set.remove("world", "*"); + + // remove excess entries from the set. + // (it can only have one server and one world.) + List servers = new ArrayList<>(set.getValues("server")); + if (servers.size() > 1) { + // start iterating at index 1 + for (int i = 1; i < servers.size(); i++) { + set.remove("server", servers.get(i)); + } + } + + List worlds = new ArrayList<>(set.getValues("world")); + if (worlds.size() > 1) { + // start iterating at index 1 + for (int i = 1; i < worlds.size(); i++) { + set.remove("world", worlds.get(i)); + } + } + + // there's either none or 1 + for (String server : servers) { + if (!DataConstraints.SERVER_NAME_TEST.test(server)) { + throw new InvalidServerWorldException(); + } + } + + // there's either none or 1 + for (String world : worlds) { + if (!DataConstraints.WORLD_NAME_TEST.test(world)) { + throw new InvalidServerWorldException(); + } + } + + return set; + } + public static int handlePriority(int index, List args) throws ArgumentException { try { return Integer.parseInt(args.get(index)); @@ -226,7 +230,7 @@ public class ArgumentUtils { } } - public static ImmutableContextSet handleContexts(int fromIndex, List args) { + public static ImmutableContextSet handleContextSponge(int fromIndex, List args) { if (args.size() <= fromIndex) { return ImmutableContextSet.empty(); } diff --git a/common/src/main/java/me/lucko/luckperms/common/config/AbstractConfiguration.java b/common/src/main/java/me/lucko/luckperms/common/config/AbstractConfiguration.java index ea13a9aa..ad3a2753 100644 --- a/common/src/main/java/me/lucko/luckperms/common/config/AbstractConfiguration.java +++ b/common/src/main/java/me/lucko/luckperms/common/config/AbstractConfiguration.java @@ -45,7 +45,7 @@ public abstract class AbstractConfiguration implements LuckPermsConfiguration { private final LPConfigurationDelegate delegate = new LPConfigurationDelegate(this); @Getter - private final StaticContextsFile staticContexts = new StaticContextsFile(this); + private final ContextsFile contextsFile = new ContextsFile(this); @SuppressWarnings("unchecked") @Override @@ -56,7 +56,7 @@ public abstract class AbstractConfiguration implements LuckPermsConfiguration { @Override public void loadAll() { ConfigKeys.getAllKeys().forEach(cache::get); - staticContexts.reload(); + contextsFile.load(); } @Override @@ -67,7 +67,7 @@ public abstract class AbstractConfiguration implements LuckPermsConfiguration { cache.invalidateAll(toInvalidate); loadAll(); - staticContexts.reload(); + contextsFile.load(); getPlugin().getApiProvider().getEventFactory().handleConfigReload(); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/config/StaticContextsFile.java b/common/src/main/java/me/lucko/luckperms/common/config/ContextsFile.java similarity index 55% rename from common/src/main/java/me/lucko/luckperms/common/config/StaticContextsFile.java rename to common/src/main/java/me/lucko/luckperms/common/config/ContextsFile.java index b293c2f4..81d0a415 100644 --- a/common/src/main/java/me/lucko/luckperms/common/config/StaticContextsFile.java +++ b/common/src/main/java/me/lucko/luckperms/common/config/ContextsFile.java @@ -27,6 +27,7 @@ package me.lucko.luckperms.common.config; import lombok.Getter; import lombok.RequiredArgsConstructor; +import lombok.Setter; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -43,35 +44,66 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; @RequiredArgsConstructor -public class StaticContextsFile { +public class ContextsFile { private final LuckPermsConfiguration configuration; @Getter - private ImmutableContextSet contextSet = ImmutableContextSet.empty(); + @Setter + private ImmutableContextSet staticContexts = ImmutableContextSet.empty(); + + @Getter + @Setter + private ImmutableContextSet defaultContexts = ImmutableContextSet.empty(); + + public void load() { + File file = new File(configuration.getPlugin().getConfigDirectory(), "contexts.json"); + File oldFile = new File(configuration.getPlugin().getConfigDirectory(), "static-contexts.json"); + if (oldFile.exists()) { + oldFile.renameTo(file); + } - public void reload() { - File file = new File(configuration.getPlugin().getConfigDirectory(), "static-contexts.json"); if (!file.exists()) { - try (BufferedWriter writer = Files.newBufferedWriter(file.toPath(), StandardCharsets.UTF_8)) { - JsonObject template = new JsonObject(); - template.add("context", new JsonObject()); - new GsonBuilder().setPrettyPrinting().create().toJson(template, writer); - } catch (IOException e) { - e.printStackTrace(); - } - contextSet = ImmutableContextSet.empty(); + save(); return; } + boolean save = false; try (BufferedReader reader = Files.newBufferedReader(file.toPath(), StandardCharsets.UTF_8)) { JsonObject data = new Gson().fromJson(reader, JsonObject.class); - if (!data.has("context") || !data.get("context").isJsonObject()) { - return; + if (data.has("context")) { + staticContexts = NodeModel.deserializeContextSet(data.get("context").getAsJsonObject()).makeImmutable(); + save = true; } - JsonObject contexts = data.get("context").getAsJsonObject(); - contextSet = NodeModel.deserializeContextSet(contexts).makeImmutable(); + if (data.has("static-contexts")) { + staticContexts = NodeModel.deserializeContextSet(data.get("static-contexts").getAsJsonObject()).makeImmutable(); + } + + if (data.has("default-contexts")) { + defaultContexts = NodeModel.deserializeContextSet(data.get("default-contexts").getAsJsonObject()).makeImmutable(); + } + + } catch (IOException e) { + e.printStackTrace(); + } + + if (save) { + save(); + } + } + + public void save() { + File file = new File(configuration.getPlugin().getConfigDirectory(), "contexts.json"); + + try (BufferedWriter writer = Files.newBufferedWriter(file.toPath(), StandardCharsets.UTF_8)) { + + JsonObject data = new JsonObject(); + data.add("static-contexts", NodeModel.serializeContextSet(staticContexts)); + data.add("default-contexts", NodeModel.serializeContextSet(defaultContexts)); + + new GsonBuilder().setPrettyPrinting().create().toJson(data, writer); + writer.flush(); } catch (IOException e) { e.printStackTrace(); } diff --git a/common/src/main/java/me/lucko/luckperms/common/config/LuckPermsConfiguration.java b/common/src/main/java/me/lucko/luckperms/common/config/LuckPermsConfiguration.java index e8e33e9d..540e7155 100644 --- a/common/src/main/java/me/lucko/luckperms/common/config/LuckPermsConfiguration.java +++ b/common/src/main/java/me/lucko/luckperms/common/config/LuckPermsConfiguration.java @@ -37,7 +37,7 @@ public interface LuckPermsConfiguration { LuckPermsPlugin getPlugin(); - StaticContextsFile getStaticContexts(); + ContextsFile getContextsFile(); void init(); diff --git a/common/src/main/java/me/lucko/luckperms/common/contexts/StaticCalculator.java b/common/src/main/java/me/lucko/luckperms/common/contexts/StaticCalculator.java index 58e6d407..9e89f9dc 100644 --- a/common/src/main/java/me/lucko/luckperms/common/contexts/StaticCalculator.java +++ b/common/src/main/java/me/lucko/luckperms/common/contexts/StaticCalculator.java @@ -43,7 +43,7 @@ public class StaticCalculator implements ContextCalculator { accumulator.add("server", server); } - accumulator.addAll(config.getStaticContexts().getContextSet()); + accumulator.addAll(config.getContextsFile().getStaticContexts()); return accumulator; } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionClear.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionClear.java index 1eb5b6fd..4600891f 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionClear.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionClear.java @@ -51,7 +51,7 @@ public class OptionClear extends SubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List args, String label) throws CommandException { - ImmutableContextSet contextSet = ArgumentUtils.handleContexts(0, args); + ImmutableContextSet contextSet = ArgumentUtils.handleContextSponge(0, args); if (contextSet.isEmpty()) { subjectData.clearOptions(); Util.sendPluginMessage(sender, "&aCleared options matching contexts &bANY&a."); diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionInfo.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionInfo.java index 282cb978..538b59fd 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionInfo.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionInfo.java @@ -52,7 +52,7 @@ public class OptionInfo extends SubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List args, String label) throws CommandException { - ImmutableContextSet contextSet = ArgumentUtils.handleContexts(0, args); + ImmutableContextSet contextSet = ArgumentUtils.handleContextSponge(0, args); if (contextSet.isEmpty()) { Util.sendPluginMessage(sender, "&aShowing options matching contexts &bANY&a."); Map> options = subjectData.getAllOptions(); diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionSet.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionSet.java index 94c98b70..64b6dd95 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionSet.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionSet.java @@ -55,7 +55,7 @@ public class OptionSet extends SubCommand { public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List args, String label) throws CommandException { String key = args.get(0); String value = args.get(1); - ImmutableContextSet contextSet = ArgumentUtils.handleContexts(2, args); + ImmutableContextSet contextSet = ArgumentUtils.handleContextSponge(2, args); if (subjectData.setOption(contextSet, key, value).join()) { Util.sendPluginMessage(sender, "&aSet &f\"" + key + "&f\"&a to &f\"" + value + "&f\"&a in context " + SpongeUtils.contextToString(contextSet)); diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionUnset.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionUnset.java index 818f0491..0c6759e7 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionUnset.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionUnset.java @@ -53,7 +53,7 @@ public class OptionUnset extends SubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List args, String label) throws CommandException { String key = args.get(0); - ImmutableContextSet contextSet = ArgumentUtils.handleContexts(1, args); + ImmutableContextSet contextSet = ArgumentUtils.handleContextSponge(1, args); if (subjectData.unsetOption(contextSet, key).join()) { Util.sendPluginMessage(sender, "&aUnset &f\"" + key + "&f\"&a in context " + SpongeUtils.contextToString(contextSet)); diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentAdd.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentAdd.java index 4574db0a..ef701ee2 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentAdd.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentAdd.java @@ -60,7 +60,7 @@ public class ParentAdd extends SubCommand { public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List args, String label) throws CommandException { String collection = args.get(0); String name = args.get(1); - ImmutableContextSet contextSet = ArgumentUtils.handleContexts(2, args); + ImmutableContextSet contextSet = ArgumentUtils.handleContextSponge(2, args); LuckPermsService service = Sponge.getServiceManager().provideUnchecked(LuckPermsService.class); if (service.getLoadedCollections().keySet().stream().map(String::toLowerCase).noneMatch(s -> s.equalsIgnoreCase(collection))) { diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentClear.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentClear.java index 56bb4d07..3b257162 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentClear.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentClear.java @@ -51,7 +51,7 @@ public class ParentClear extends SubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List args, String label) throws CommandException { - ImmutableContextSet contextSet = ArgumentUtils.handleContexts(0, args); + ImmutableContextSet contextSet = ArgumentUtils.handleContextSponge(0, args); if (contextSet.isEmpty()) { subjectData.clearParents(); Util.sendPluginMessage(sender, "&aCleared parents matching contexts &bANY&a."); diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentInfo.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentInfo.java index 704dc20f..2a353aff 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentInfo.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentInfo.java @@ -53,7 +53,7 @@ public class ParentInfo extends SubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List args, String label) throws CommandException { - ImmutableContextSet contextSet = ArgumentUtils.handleContexts(0, args); + ImmutableContextSet contextSet = ArgumentUtils.handleContextSponge(0, args); if (contextSet.isEmpty()) { Util.sendPluginMessage(sender, "&aShowing parents matching contexts &bANY&a."); Map> parents = subjectData.getAllParents(); diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentRemove.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentRemove.java index 7e342b94..fae713e8 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentRemove.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentRemove.java @@ -60,7 +60,7 @@ public class ParentRemove extends SubCommand { public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List args, String label) throws CommandException { String collection = args.get(0); String name = args.get(1); - ImmutableContextSet contextSet = ArgumentUtils.handleContexts(2, args); + ImmutableContextSet contextSet = ArgumentUtils.handleContextSponge(2, args); LuckPermsService service = Sponge.getServiceManager().provideUnchecked(LuckPermsService.class); if (service.getLoadedCollections().keySet().stream().map(String::toLowerCase).noneMatch(s -> s.equalsIgnoreCase(collection))) { diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionClear.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionClear.java index 9954d9b1..fe8dc9cb 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionClear.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionClear.java @@ -51,7 +51,7 @@ public class PermissionClear extends SubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List args, String label) throws CommandException { - ImmutableContextSet contextSet = ArgumentUtils.handleContexts(0, args); + ImmutableContextSet contextSet = ArgumentUtils.handleContextSponge(0, args); if (contextSet.isEmpty()) { subjectData.clearPermissions(); Util.sendPluginMessage(sender, "&aCleared permissions matching contexts &bANY&a."); diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionInfo.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionInfo.java index 299e4931..1704280c 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionInfo.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionInfo.java @@ -52,7 +52,7 @@ public class PermissionInfo extends SubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List args, String label) throws CommandException { - ImmutableContextSet contextSet = ArgumentUtils.handleContexts(0, args); + ImmutableContextSet contextSet = ArgumentUtils.handleContextSponge(0, args); if (contextSet.isEmpty()) { Util.sendPluginMessage(sender, "&aShowing permissions matching contexts &bANY&a."); Map> permissions = subjectData.getAllPermissions(); diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionSet.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionSet.java index 371776f3..ccf7dcf5 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionSet.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionSet.java @@ -56,7 +56,7 @@ public class PermissionSet extends SubCommand { public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List args, String label) throws CommandException { String node = args.get(0); Tristate tristate = SpongeUtils.parseTristate(1, args); - ImmutableContextSet contextSet = ArgumentUtils.handleContexts(2, args); + ImmutableContextSet contextSet = ArgumentUtils.handleContextSponge(2, args); if (subjectData.setPermission(contextSet, node, tristate).join()) { Util.sendPluginMessage(sender, "&aSet &b" + node + "&a to &b" + tristate.toString().toLowerCase() + "&a in context " + SpongeUtils.contextToString(contextSet));