mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-27 21:29:47 +01:00
Changes to option keys
This commit is contained in:
parent
fd954d8293
commit
9438df787a
@ -45,12 +45,12 @@ public interface MetaStackDefinition {
|
||||
/**
|
||||
* The {@link OptionKey} for the prefix {@link MetaStackDefinition}.
|
||||
*/
|
||||
OptionKey<MetaStackDefinition> PREFIX_STACK_KEY = new OptionKey<MetaStackDefinition>(){};
|
||||
OptionKey<MetaStackDefinition> PREFIX_STACK_KEY = OptionKey.of("prefixstack", MetaStackDefinition.class);
|
||||
|
||||
/**
|
||||
* The {@link OptionKey} for the suffix {@link MetaStackDefinition}.
|
||||
*/
|
||||
OptionKey<MetaStackDefinition> SUFFIX_STACK_KEY = new OptionKey<MetaStackDefinition>(){};
|
||||
OptionKey<MetaStackDefinition> SUFFIX_STACK_KEY = OptionKey.of("suffixstack", MetaStackDefinition.class);
|
||||
|
||||
/**
|
||||
* Gets an immutable list of the elements in this stack definition
|
||||
|
@ -32,13 +32,10 @@ import java.util.Objects;
|
||||
/**
|
||||
* Represents a key for a specific type of node metadata.
|
||||
*
|
||||
* <p>Metadata keys are compared using reference equality, the
|
||||
* {@link #equals(Object)} method should not be implemented.</p>
|
||||
*
|
||||
* <p>It is intended that {@link NodeMetadataKey}s are obtained and stored as
|
||||
* follows.</p>
|
||||
* <p><blockquote><pre>
|
||||
* public static final NodeMetadataKey<SpecialMetadata> SPECIAL_METADATA_KEY = NodeMetadataKey.of("SpecialMetadata", SpecialMetadata.class);
|
||||
* public static final NodeMetadataKey<SpecialMetadata> SPECIAL_METADATA_KEY = NodeMetadataKey.of("specialmetadata", SpecialMetadata.class);
|
||||
* </pre></blockquote></p>
|
||||
*
|
||||
* @param <T> the metadata type
|
||||
|
@ -27,12 +27,14 @@ package net.luckperms.api.node.metadata;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
final class SimpleNodeMetadataKey<T> implements NodeMetadataKey<T> {
|
||||
private final String name;
|
||||
private final Class<T> type;
|
||||
|
||||
SimpleNodeMetadataKey(String name, Class<T> type) {
|
||||
this.name = name;
|
||||
this.name = name.toLowerCase();
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@ -50,4 +52,18 @@ final class SimpleNodeMetadataKey<T> implements NodeMetadataKey<T> {
|
||||
public String toString() {
|
||||
return "NodeMetadataKey(name=" + this.name + ", type=" + this.type.getName() + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
SimpleNodeMetadataKey<?> that = (SimpleNodeMetadataKey<?>) o;
|
||||
return this.name.equals(that.name) &&
|
||||
this.type.equals(that.type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.name, this.type);
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ public interface InheritanceOriginMetadata {
|
||||
/**
|
||||
* The {@link NodeMetadataKey} for {@link InheritanceOriginMetadata}.
|
||||
*/
|
||||
NodeMetadataKey<InheritanceOriginMetadata> KEY = NodeMetadataKey.of("InheritanceOrigin", InheritanceOriginMetadata.class);
|
||||
NodeMetadataKey<InheritanceOriginMetadata> KEY = NodeMetadataKey.of("inheritanceorigin", InheritanceOriginMetadata.class);
|
||||
|
||||
/**
|
||||
* Gets the location where the {@link Node} is inherited from.
|
||||
|
@ -25,19 +25,52 @@
|
||||
|
||||
package net.luckperms.api.query;
|
||||
|
||||
import net.luckperms.api.node.metadata.NodeMetadataKey;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Represents a key for a custom option defined in {@link QueryOptions}.
|
||||
*
|
||||
* <p>Option keys are compared using reference equality, the
|
||||
* {@link #equals(Object)} method should not be implemented.</p>
|
||||
*
|
||||
* <p>It is intended that {@link OptionKey}s are created and defined as follows.</p>
|
||||
* <p><blockquote><pre>
|
||||
* public static final OptionKey<String> SPECIAL_OPTION = new OptionKey<String>(){};
|
||||
* public static final OptionKey<String> SPECIAL_OPTION = OptionKey.of("special", String.class);
|
||||
* </pre></blockquote></p>
|
||||
*
|
||||
* @param <O> the option type
|
||||
* @param <T> the option type
|
||||
*/
|
||||
public interface OptionKey<O> {
|
||||
public interface OptionKey<T> {
|
||||
|
||||
/**
|
||||
* Creates a new {@link NodeMetadataKey} for the given name and type.
|
||||
*
|
||||
* <p>Note that the returned key implements object reference equality.</p>
|
||||
*
|
||||
* @param name the name
|
||||
* @param type the type
|
||||
* @param <T> the type parameter
|
||||
* @return the key
|
||||
*/
|
||||
static <T> @NonNull OptionKey<T> of(@NonNull String name, @NonNull Class<T> type) {
|
||||
Objects.requireNonNull(name, "name");
|
||||
Objects.requireNonNull(type, "type");
|
||||
return new SimpleOptionKey<>(name, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a name describing the key type.
|
||||
*
|
||||
* @return the key name
|
||||
*/
|
||||
@NonNull String name();
|
||||
|
||||
/**
|
||||
* Gets the type of the key
|
||||
*
|
||||
* @return the type
|
||||
*/
|
||||
@NonNull Class<T> getType();
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* 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 net.luckperms.api.query;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
final class SimpleOptionKey<T> implements OptionKey<T> {
|
||||
private final String name;
|
||||
private final Class<T> type;
|
||||
|
||||
SimpleOptionKey(String name, Class<T> type) {
|
||||
this.name = name.toLowerCase();
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull String name() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Class<T> getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "OptionKey(name=" + this.name + ", type=" + this.type.getName() + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
SimpleOptionKey<?> that = (SimpleOptionKey<?>) o;
|
||||
return this.name.equals(that.name) &&
|
||||
this.type.equals(that.type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.name, this.type);
|
||||
}
|
||||
}
|
@ -42,7 +42,7 @@ public interface DataQueryOrderFunction {
|
||||
/**
|
||||
* The {@link OptionKey} for {@link DataQueryOrderFunction}.
|
||||
*/
|
||||
OptionKey<DataQueryOrderFunction> KEY = new OptionKey<DataQueryOrderFunction>(){};
|
||||
OptionKey<DataQueryOrderFunction> KEY = OptionKey.of("dataqueryorderfunction", DataQueryOrderFunction.class);
|
||||
|
||||
/**
|
||||
* Gets the {@link DataQueryOrder} comparator for the given
|
||||
|
@ -45,7 +45,7 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class BukkitContextManager extends ContextManager<Player> {
|
||||
|
||||
public static final OptionKey<Boolean> OP_OPTION = new OptionKey<Boolean>(){};
|
||||
public static final OptionKey<Boolean> OP_OPTION = OptionKey.of("op", Boolean.class);
|
||||
|
||||
// cache the creation of ContextsCache instances for online players with no expiry
|
||||
private final LoadingMap<Player, QueryOptionsCache<Player>> onlineSubjectCaches = LoadingMap.of(key -> new QueryOptionsCache<>(key, this));
|
||||
|
@ -56,7 +56,7 @@ import java.util.Set;
|
||||
*/
|
||||
public class LPPermissionAttachment extends PermissionAttachment {
|
||||
|
||||
public static final NodeMetadataKey<LPPermissionAttachment> TRANSIENT_SOURCE_KEY = NodeMetadataKey.of("TransientSource", LPPermissionAttachment.class);
|
||||
public static final NodeMetadataKey<LPPermissionAttachment> TRANSIENT_SOURCE_KEY = NodeMetadataKey.of("transientsource", LPPermissionAttachment.class);
|
||||
|
||||
/**
|
||||
* The field in PermissionAttachment where the attachments applied permissions
|
||||
|
@ -56,29 +56,14 @@ public class ContextsFile {
|
||||
|
||||
public void load() {
|
||||
Path file = this.configuration.getPlugin().getBootstrap().getDataDirectory().resolve("contexts.json");
|
||||
Path oldFile = this.configuration.getPlugin().getBootstrap().getDataDirectory().resolve("static-contexts.json");
|
||||
if (Files.exists(oldFile)) {
|
||||
try {
|
||||
Files.move(oldFile, file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (!Files.exists(file)) {
|
||||
save();
|
||||
return;
|
||||
}
|
||||
|
||||
boolean save = false;
|
||||
try (BufferedReader reader = Files.newBufferedReader(file, StandardCharsets.UTF_8)) {
|
||||
JsonObject data = GsonProvider.normal().fromJson(reader, JsonObject.class);
|
||||
|
||||
if (data.has("context")) {
|
||||
this.staticContexts = ContextSetJsonSerializer.deserializeContextSet(data.get("context").getAsJsonObject()).immutableCopy();
|
||||
save = true;
|
||||
}
|
||||
|
||||
if (data.has("static-contexts")) {
|
||||
this.staticContexts = ContextSetJsonSerializer.deserializeContextSet(data.get("static-contexts").getAsJsonObject()).immutableCopy();
|
||||
}
|
||||
@ -90,10 +75,6 @@ public class ContextsFile {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (save) {
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
public void save() {
|
||||
|
@ -45,7 +45,7 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class NukkitContextManager extends ContextManager<Player> {
|
||||
|
||||
public static final OptionKey<Boolean> OP_OPTION = new OptionKey<Boolean>(){};
|
||||
public static final OptionKey<Boolean> OP_OPTION = OptionKey.of("op", Boolean.class);
|
||||
|
||||
// cache the creation of ContextsCache instances for online players with no expiry
|
||||
private final LoadingMap<Player, QueryOptionsCache<Player>> onlineSubjectCaches = LoadingMap.of(key -> new QueryOptionsCache<>(key, this));
|
||||
|
@ -58,7 +58,7 @@ import java.util.Set;
|
||||
*/
|
||||
public class LPPermissionAttachment extends PermissionAttachment {
|
||||
|
||||
public static final NodeMetadataKey<LPPermissionAttachment> TRANSIENT_SOURCE_KEY = NodeMetadataKey.of("TransientSource", LPPermissionAttachment.class);
|
||||
public static final NodeMetadataKey<LPPermissionAttachment> TRANSIENT_SOURCE_KEY = NodeMetadataKey.of("transientsource", LPPermissionAttachment.class);
|
||||
|
||||
/**
|
||||
* The field in PermissionAttachment where the attachments applied permissions
|
||||
|
Loading…
Reference in New Issue
Block a user