mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-28 05:35:26 +01:00
Implement default contexts - closes #241
This commit is contained in:
parent
e835b31277
commit
1fee47e087
@ -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())
|
||||
|
@ -69,7 +69,7 @@ public class MetaAddChatMeta extends SharedSubCommand {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> 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()) {
|
||||
|
@ -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<DataMutateResult, Node> ret = holder.setPermission(NodeFactory.makeChatMetaNode(isPrefix, priority, meta).setExpiry(duration).withExtraContext(context).build(), modifier);
|
||||
|
@ -55,7 +55,7 @@ public class MetaClear extends SharedSubCommand {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> 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();
|
||||
|
@ -69,7 +69,7 @@ public class MetaRemoveChatMeta extends SharedSubCommand {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> 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("*")) {
|
||||
|
@ -69,7 +69,7 @@ public class MetaRemoveTempChatMeta extends SharedSubCommand {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> 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("*")) {
|
||||
|
@ -60,7 +60,7 @@ public class MetaSet extends SharedSubCommand {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> 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();
|
||||
|
||||
|
@ -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();
|
||||
|
@ -57,7 +57,7 @@ public class MetaUnset extends SharedSubCommand {
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> 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));
|
||||
|
@ -57,7 +57,7 @@ public class MetaUnsetTemp extends SharedSubCommand {
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> 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));
|
||||
|
@ -58,7 +58,7 @@ public class HolderClear<T extends PermissionHolder> extends SubCommand<T> {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, T holder, List<String> 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();
|
||||
|
@ -61,7 +61,7 @@ public class ParentAdd extends SharedSubCommand {
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> 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);
|
||||
|
@ -69,7 +69,7 @@ public class ParentAddTemp extends SharedSubCommand {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> 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()) {
|
||||
|
@ -55,7 +55,7 @@ public class ParentClear extends SharedSubCommand {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> 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);
|
||||
|
@ -63,7 +63,7 @@ public class ParentRemove extends SharedSubCommand {
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> 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;
|
||||
|
@ -61,7 +61,7 @@ public class ParentRemoveTemp extends SharedSubCommand {
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> 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());
|
||||
|
||||
|
@ -61,7 +61,7 @@ public class ParentSet extends SharedSubCommand {
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> 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);
|
||||
|
@ -59,7 +59,7 @@ public class PermissionCheck extends SharedSubCommand {
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> 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);
|
||||
|
@ -59,7 +59,7 @@ public class PermissionCheckInherits extends SharedSubCommand {
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> 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());
|
||||
|
||||
|
@ -64,7 +64,7 @@ public class PermissionSet extends SharedSubCommand {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> 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());
|
||||
|
||||
|
@ -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<DataMutateResult, Node> result = holder.setPermission(NodeFactory.newBuilder(node).setValue(b).withExtraContext(context).setExpiry(duration).build(), modifier);
|
||||
|
@ -59,7 +59,7 @@ public class PermissionUnset extends SharedSubCommand {
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> 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.")) {
|
||||
|
@ -59,7 +59,7 @@ public class PermissionUnsetTemp extends SharedSubCommand {
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> 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());
|
||||
|
||||
|
@ -84,7 +84,7 @@ public class UserDemote extends SubCommand<User> {
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
MutableContextSet context = ArgumentUtils.handleContext(1, args);
|
||||
MutableContextSet context = ArgumentUtils.handleContext(1, args, plugin);
|
||||
boolean silent = false;
|
||||
|
||||
if (args.contains("-s")) {
|
||||
|
@ -84,7 +84,7 @@ public class UserPromote extends SubCommand<User> {
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
MutableContextSet context = ArgumentUtils.handleContext(1, args);
|
||||
MutableContextSet context = ArgumentUtils.handleContext(1, args, plugin);
|
||||
boolean silent = false;
|
||||
|
||||
if (args.contains("-s")) {
|
||||
|
@ -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<String> args) throws CommandException {
|
||||
public static MutableContextSet handleContext(int fromIndex, List<String> 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,16 +169,16 @@ 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);
|
||||
}
|
||||
|
||||
return sanitizeContexts(set);
|
||||
} else {
|
||||
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");
|
||||
@ -212,12 +205,23 @@ public class ArgumentUtils {
|
||||
}
|
||||
}
|
||||
|
||||
return set;
|
||||
} else {
|
||||
return MutableContextSet.create();
|
||||
// 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<String> args) throws ArgumentException {
|
||||
try {
|
||||
return Integer.parseInt(args.get(index));
|
||||
@ -226,7 +230,7 @@ public class ArgumentUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static ImmutableContextSet handleContexts(int fromIndex, List<String> args) {
|
||||
public static ImmutableContextSet handleContextSponge(int fromIndex, List<String> args) {
|
||||
if (args.size() <= fromIndex) {
|
||||
return ImmutableContextSet.empty();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
||||
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();
|
||||
@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);
|
||||
}
|
||||
contextSet = ImmutableContextSet.empty();
|
||||
|
||||
if (!file.exists()) {
|
||||
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();
|
||||
}
|
@ -37,7 +37,7 @@ public interface LuckPermsConfiguration {
|
||||
|
||||
LuckPermsPlugin getPlugin();
|
||||
|
||||
StaticContextsFile getStaticContexts();
|
||||
ContextsFile getContextsFile();
|
||||
|
||||
void init();
|
||||
|
||||
|
@ -43,7 +43,7 @@ public class StaticCalculator<T> implements ContextCalculator<T> {
|
||||
accumulator.add("server", server);
|
||||
}
|
||||
|
||||
accumulator.addAll(config.getStaticContexts().getContextSet());
|
||||
accumulator.addAll(config.getContextsFile().getStaticContexts());
|
||||
|
||||
return accumulator;
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ public class OptionClear extends SubCommand<LPSubjectData> {
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> 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.");
|
||||
|
@ -52,7 +52,7 @@ public class OptionInfo extends SubCommand<LPSubjectData> {
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> 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<ImmutableContextSet, ImmutableMap<String, String>> options = subjectData.getAllOptions();
|
||||
|
@ -55,7 +55,7 @@ public class OptionSet extends SubCommand<LPSubjectData> {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> 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));
|
||||
|
@ -53,7 +53,7 @@ public class OptionUnset extends SubCommand<LPSubjectData> {
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> 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));
|
||||
|
@ -60,7 +60,7 @@ public class ParentAdd extends SubCommand<LPSubjectData> {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> 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))) {
|
||||
|
@ -51,7 +51,7 @@ public class ParentClear extends SubCommand<LPSubjectData> {
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> 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.");
|
||||
|
@ -53,7 +53,7 @@ public class ParentInfo extends SubCommand<LPSubjectData> {
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> 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<ImmutableContextSet, ImmutableList<SubjectReference>> parents = subjectData.getAllParents();
|
||||
|
@ -60,7 +60,7 @@ public class ParentRemove extends SubCommand<LPSubjectData> {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> 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))) {
|
||||
|
@ -51,7 +51,7 @@ public class PermissionClear extends SubCommand<LPSubjectData> {
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> 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.");
|
||||
|
@ -52,7 +52,7 @@ public class PermissionInfo extends SubCommand<LPSubjectData> {
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> 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<ImmutableContextSet, ImmutableMap<String, Boolean>> permissions = subjectData.getAllPermissions();
|
||||
|
@ -56,7 +56,7 @@ public class PermissionSet extends SubCommand<LPSubjectData> {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> 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));
|
||||
|
Loading…
Reference in New Issue
Block a user