Remove lombok from the project
This commit is contained in:
parent
17ff9ac328
commit
f646c04d09
@ -11,9 +11,6 @@ If you're unsure, feel free to ask using the above resources BEFORE making a rep
|
||||
Bugs or issues should be reported using the [GitHub Issues tab](https://github.com/lucko/LuckPerms/issues).
|
||||
|
||||
### :pencil: Want to contribute code?
|
||||
|
||||
In order to contribute to and make changes to the plugin, you will need the dependencies listed in the [README](https://github.com/lucko/LuckPerms), plus the [Lombok plugin](https://projectlombok.org/download.html) for your IDE.
|
||||
|
||||
#### Pull Requests
|
||||
If you make any changes or improvements to the plugin which you think would be beneficial to others, please consider making a pull request to merge your changes back into the upstream project. (especially if your changes are bug fixes!)
|
||||
|
||||
|
@ -32,8 +32,6 @@ mvn clean package
|
||||
You can find the output jars in the `target` directories.
|
||||
|
||||
## Contributing
|
||||
In order to contribute to and make changes to the plugin, you will need the dependencies listed above, plus the [Lombok plugin](https://projectlombok.org/download.html) for your IDE.
|
||||
|
||||
#### Pull Requests
|
||||
If you make any changes or improvements to the plugin which you think would be beneficial to others, please consider making a pull request to merge your changes back into the upstream project. (especially if your changes are bug fixes!)
|
||||
|
||||
|
@ -25,9 +25,8 @@
|
||||
|
||||
package me.lucko.luckperms.api;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@ -45,13 +44,13 @@ public enum ChatMetaType {
|
||||
PREFIX("prefix") {
|
||||
@Override
|
||||
public boolean matches(@Nonnull Node node) {
|
||||
return Preconditions.checkNotNull(node, "node").isPrefix();
|
||||
return Objects.requireNonNull(node, "node").isPrefix();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Map.Entry<Integer, String> getEntry(@Nonnull Node node) {
|
||||
return Preconditions.checkNotNull(node, "node").getPrefix();
|
||||
return Objects.requireNonNull(node, "node").getPrefix();
|
||||
}
|
||||
},
|
||||
|
||||
@ -61,13 +60,13 @@ public enum ChatMetaType {
|
||||
SUFFIX("suffix") {
|
||||
@Override
|
||||
public boolean matches(@Nonnull Node node) {
|
||||
return Preconditions.checkNotNull(node, "node").isSuffix();
|
||||
return Objects.requireNonNull(node, "node").isSuffix();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Map.Entry<Integer, String> getEntry(@Nonnull Node node) {
|
||||
return Preconditions.checkNotNull(node, "node").getSuffix();
|
||||
return Objects.requireNonNull(node, "node").getSuffix();
|
||||
}
|
||||
};
|
||||
|
||||
@ -107,7 +106,7 @@ public enum ChatMetaType {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return str;
|
||||
return this.str;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -25,11 +25,11 @@
|
||||
|
||||
package me.lucko.luckperms.api;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import me.lucko.luckperms.api.context.ContextSet;
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@ -89,6 +89,7 @@ public class Contexts {
|
||||
return GLOBAL;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static Contexts of(@Nonnull ContextSet context, boolean includeGlobal, boolean includeGlobalWorld, boolean applyGroups, boolean applyGlobalGroups, boolean applyGlobalWorldGroups, boolean op) {
|
||||
return new Contexts(context, includeGlobal, includeGlobalWorld, applyGroups, applyGlobalGroups, applyGlobalWorldGroups, op);
|
||||
}
|
||||
@ -135,7 +136,7 @@ public class Contexts {
|
||||
private final int hashCode;
|
||||
|
||||
public Contexts(@Nonnull ContextSet context, boolean includeGlobal, boolean includeGlobalWorld, boolean applyGroups, boolean applyGlobalGroups, boolean applyGlobalWorldGroups, boolean op) {
|
||||
this.context = Preconditions.checkNotNull(context, "context").makeImmutable();
|
||||
this.context = Objects.requireNonNull(context, "context").makeImmutable();
|
||||
this.includeGlobal = includeGlobal;
|
||||
this.includeGlobalWorld = includeGlobalWorld;
|
||||
this.applyGroups = applyGroups;
|
||||
@ -211,18 +212,17 @@ public class Contexts {
|
||||
return this.applyGlobalWorldGroups;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Contexts(" +
|
||||
"context=" + this.getContexts() + ", " +
|
||||
"op=" + this.isOp() + ", " +
|
||||
"includeGlobal=" + this.isIncludeGlobal() + ", " +
|
||||
"includeGlobalWorld=" + this.isIncludeGlobalWorld() + ", " +
|
||||
"applyGroups=" + this.isApplyGroups() + ", " +
|
||||
"applyGlobalGroups=" + this.isApplyGlobalGroups() + ", " +
|
||||
"applyGlobalWorldGroups=" + this.isApplyGlobalWorldGroups() +
|
||||
")";
|
||||
"context=" + this.context + ", " +
|
||||
"op=" + this.op + ", " +
|
||||
"includeGlobal=" + this.includeGlobal + ", " +
|
||||
"includeGlobalWorld=" + this.includeGlobalWorld + ", " +
|
||||
"applyGroups=" + this.applyGroups + ", " +
|
||||
"applyGlobalGroups=" + this.applyGlobalGroups + ", " +
|
||||
"applyGlobalWorldGroups=" + this.applyGlobalWorldGroups + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -230,33 +230,23 @@ public class Contexts {
|
||||
if (o == this) return true;
|
||||
if (o == allowAll()) return false;
|
||||
if (!(o instanceof Contexts)) return false;
|
||||
final Contexts that = (Contexts) o;
|
||||
|
||||
final Contexts other = (Contexts) o;
|
||||
return this.getContexts().equals(other.getContexts()) &&
|
||||
this.isOp() == other.isOp() &&
|
||||
this.isIncludeGlobal() == other.isIncludeGlobal() &&
|
||||
this.isIncludeGlobalWorld() == other.isIncludeGlobalWorld() &&
|
||||
this.isApplyGroups() == other.isApplyGroups() &&
|
||||
this.isApplyGlobalGroups() == other.isApplyGlobalGroups() &&
|
||||
this.isApplyGlobalWorldGroups() == other.isApplyGlobalWorldGroups();
|
||||
return this.context.equals(that.context) &&
|
||||
this.op == that.op &&
|
||||
this.includeGlobal == that.includeGlobal &&
|
||||
this.includeGlobalWorld == that.includeGlobalWorld &&
|
||||
this.applyGroups == that.applyGroups &&
|
||||
this.applyGlobalGroups == that.applyGlobalGroups &&
|
||||
this.applyGlobalWorldGroups == that.applyGlobalWorldGroups;
|
||||
}
|
||||
|
||||
private int calculateHashCode() {
|
||||
final int PRIME = 59;
|
||||
int result = 1;
|
||||
final Object contexts = this.getContexts();
|
||||
result = result * PRIME + contexts.hashCode();
|
||||
result = result * PRIME + (this.isOp() ? 79 : 97);
|
||||
result = result * PRIME + (this.isIncludeGlobal() ? 79 : 97);
|
||||
result = result * PRIME + (this.isIncludeGlobalWorld() ? 79 : 97);
|
||||
result = result * PRIME + (this.isApplyGroups() ? 79 : 97);
|
||||
result = result * PRIME + (this.isApplyGlobalGroups() ? 79 : 97);
|
||||
result = result * PRIME + (this.isApplyGlobalWorldGroups() ? 79 : 97);
|
||||
return result;
|
||||
return Objects.hash(this.context, this.op, this.includeGlobal, this.includeGlobalWorld, this.applyGroups, this.applyGlobalGroups, this.applyGlobalWorldGroups);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return hashCode;
|
||||
return this.hashCode;
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ public enum DataMutateResult {
|
||||
* @return a boolean representation
|
||||
*/
|
||||
public boolean asBoolean() {
|
||||
return value;
|
||||
return this.value;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -72,7 +72,7 @@ public enum DataMutateResult {
|
||||
* @since 3.4
|
||||
*/
|
||||
public boolean wasSuccess() {
|
||||
return value;
|
||||
return this.value;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -82,7 +82,7 @@ public enum DataMutateResult {
|
||||
* @since 3.4
|
||||
*/
|
||||
public boolean wasFailure() {
|
||||
return !value;
|
||||
return !this.value;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -96,6 +96,6 @@ public enum Tristate {
|
||||
* @return a boolean representation of the Tristate.
|
||||
*/
|
||||
public boolean asBoolean() {
|
||||
return booleanValue;
|
||||
return this.booleanValue;
|
||||
}
|
||||
}
|
||||
|
@ -25,11 +25,11 @@
|
||||
|
||||
package me.lucko.luckperms.api.caching;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.metastacking.MetaStackDefinition;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@ -71,9 +71,9 @@ public final class MetaContexts {
|
||||
* @param suffixStackDefinition the suffix stack definition to be used
|
||||
*/
|
||||
public MetaContexts(@Nonnull Contexts contexts, @Nonnull MetaStackDefinition prefixStackDefinition, @Nonnull MetaStackDefinition suffixStackDefinition) {
|
||||
this.contexts = Preconditions.checkNotNull(contexts, "contexts");
|
||||
this.prefixStackDefinition = Preconditions.checkNotNull(prefixStackDefinition, "prefixStackDefinition");
|
||||
this.suffixStackDefinition = Preconditions.checkNotNull(suffixStackDefinition, "suffixStackDefinition");
|
||||
this.contexts = Objects.requireNonNull(contexts, "contexts");
|
||||
this.prefixStackDefinition = Objects.requireNonNull(prefixStackDefinition, "prefixStackDefinition");
|
||||
this.suffixStackDefinition = Objects.requireNonNull(suffixStackDefinition, "suffixStackDefinition");
|
||||
this.hashCode = calculateHashCode();
|
||||
}
|
||||
|
||||
@ -106,23 +106,18 @@ public final class MetaContexts {
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof MetaContexts)) return false;
|
||||
final MetaContexts other = (MetaContexts) o;
|
||||
return this.getContexts().equals(other.getContexts()) &&
|
||||
this.getPrefixStackDefinition().equals(other.getPrefixStackDefinition()) &&
|
||||
this.getSuffixStackDefinition().equals(other.getSuffixStackDefinition());
|
||||
final MetaContexts that = (MetaContexts) o;
|
||||
return this.contexts.equals(that.contexts) &&
|
||||
this.prefixStackDefinition.equals(that.prefixStackDefinition) &&
|
||||
this.suffixStackDefinition.equals(that.suffixStackDefinition);
|
||||
}
|
||||
|
||||
private int calculateHashCode() {
|
||||
final int PRIME = 59;
|
||||
int result = 1;
|
||||
result = result * PRIME + this.getContexts().hashCode();
|
||||
result = result * PRIME + this.getPrefixStackDefinition().hashCode();
|
||||
result = result * PRIME + this.getSuffixStackDefinition().hashCode();
|
||||
return result;
|
||||
return Objects.hash(this.contexts, this.prefixStackDefinition, this.suffixStackDefinition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return hashCode;
|
||||
return this.hashCode;
|
||||
}
|
||||
}
|
||||
|
@ -31,12 +31,11 @@ import com.google.common.collect.Multimap;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
abstract class AbstractContextSet implements ContextSet {
|
||||
|
||||
protected abstract Multimap<String, String> backing();
|
||||
@ -104,14 +103,14 @@ abstract class AbstractContextSet implements ContextSet {
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof ContextSet)) return false;
|
||||
final ContextSet other = (ContextSet) o;
|
||||
final ContextSet that = (ContextSet) o;
|
||||
|
||||
final Multimap<String, String> otherContexts;
|
||||
|
||||
if (other instanceof AbstractContextSet) {
|
||||
otherContexts = ((AbstractContextSet) other).backing();
|
||||
if (that instanceof AbstractContextSet) {
|
||||
otherContexts = ((AbstractContextSet) that).backing();
|
||||
} else {
|
||||
otherContexts = other.toMultimap();
|
||||
otherContexts = that.toMultimap();
|
||||
}
|
||||
|
||||
return backing().equals(otherContexts);
|
||||
@ -123,11 +122,11 @@ abstract class AbstractContextSet implements ContextSet {
|
||||
}
|
||||
|
||||
static String sanitizeKey(String key) {
|
||||
return checkNotNull(key, "key is null").toLowerCase().intern();
|
||||
return Objects.requireNonNull(key, "key is null").toLowerCase().intern();
|
||||
}
|
||||
|
||||
static String sanitizeValue(String value) {
|
||||
return checkNotNull(value, "value is null").intern();
|
||||
return Objects.requireNonNull(value, "value is null").intern();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -153,7 +153,6 @@ public interface ContextManager {
|
||||
*
|
||||
* @param calculator the calculator
|
||||
*/
|
||||
@Nonnull
|
||||
void registerCalculator(@Nonnull ContextCalculator<?> calculator);
|
||||
|
||||
/**
|
||||
@ -163,7 +162,6 @@ public interface ContextManager {
|
||||
*
|
||||
* @param calculator the calculator
|
||||
*/
|
||||
@Nonnull
|
||||
void registerStaticCalculator(@Nonnull StaticContextCalculator calculator);
|
||||
|
||||
/**
|
||||
@ -171,7 +169,6 @@ public interface ContextManager {
|
||||
*
|
||||
* @param subject the subject
|
||||
*/
|
||||
@Nonnull
|
||||
void invalidateCache(@Nonnull Object subject);
|
||||
|
||||
}
|
||||
|
@ -25,10 +25,10 @@
|
||||
|
||||
package me.lucko.luckperms.api.context;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
@ -302,7 +302,7 @@ public interface ContextSet {
|
||||
* @throws NullPointerException if the key or value is null
|
||||
*/
|
||||
default boolean has(@Nonnull Map.Entry<String, String> entry) {
|
||||
Preconditions.checkNotNull(entry, "entry");
|
||||
Objects.requireNonNull(entry, "entry");
|
||||
return has(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
@ -317,7 +317,7 @@ public interface ContextSet {
|
||||
* @throws NullPointerException if the key or value is null
|
||||
*/
|
||||
default boolean hasIgnoreCase(@Nonnull Map.Entry<String, String> entry) {
|
||||
Preconditions.checkNotNull(entry, "entry");
|
||||
Objects.requireNonNull(entry, "entry");
|
||||
return hasIgnoreCase(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
@ -358,7 +358,7 @@ public interface ContextSet {
|
||||
return true;
|
||||
}
|
||||
|
||||
Preconditions.checkNotNull(other, "other");
|
||||
Objects.requireNonNull(other, "other");
|
||||
if (this.isEmpty()) {
|
||||
// this is empty, so is therefore always satisfied.
|
||||
return true;
|
||||
|
@ -29,13 +29,12 @@ import com.google.common.collect.ImmutableSetMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* An immutable implementation of {@link ContextSet}.
|
||||
*
|
||||
@ -99,7 +98,7 @@ public final class ImmutableContextSet extends AbstractContextSet implements Con
|
||||
*/
|
||||
@Nonnull
|
||||
public static ImmutableContextSet fromEntries(@Nonnull Iterable<? extends Map.Entry<String, String>> iterable) {
|
||||
checkNotNull(iterable, "iterable");
|
||||
Objects.requireNonNull(iterable, "iterable");
|
||||
ImmutableContextSet.Builder builder = builder();
|
||||
for (Map.Entry<String, String> entry : iterable) {
|
||||
builder.add(entry);
|
||||
@ -116,7 +115,7 @@ public final class ImmutableContextSet extends AbstractContextSet implements Con
|
||||
*/
|
||||
@Nonnull
|
||||
public static ImmutableContextSet fromMap(@Nonnull Map<String, String> map) {
|
||||
return fromEntries(checkNotNull(map, "map").entrySet());
|
||||
return fromEntries(Objects.requireNonNull(map, "map").entrySet());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -129,7 +128,7 @@ public final class ImmutableContextSet extends AbstractContextSet implements Con
|
||||
*/
|
||||
@Nonnull
|
||||
public static ImmutableContextSet fromMultimap(@Nonnull Multimap<String, String> multimap) {
|
||||
return fromEntries(checkNotNull(multimap, "multimap").entries());
|
||||
return fromEntries(Objects.requireNonNull(multimap, "multimap").entries());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -143,7 +142,7 @@ public final class ImmutableContextSet extends AbstractContextSet implements Con
|
||||
*/
|
||||
@Nonnull
|
||||
public static ImmutableContextSet fromSet(@Nonnull ContextSet contextSet) {
|
||||
return checkNotNull(contextSet, "contextSet").makeImmutable();
|
||||
return Objects.requireNonNull(contextSet, "contextSet").makeImmutable();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -161,12 +160,12 @@ public final class ImmutableContextSet extends AbstractContextSet implements Con
|
||||
|
||||
ImmutableContextSet(ImmutableSetMultimap<String, String> contexts) {
|
||||
this.map = contexts;
|
||||
this.hashCode = map.hashCode();
|
||||
this.hashCode = this.map.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Multimap<String, String> backing() {
|
||||
return map;
|
||||
return this.map;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -190,18 +189,18 @@ public final class ImmutableContextSet extends AbstractContextSet implements Con
|
||||
@Nonnull
|
||||
@Override
|
||||
public Set<Map.Entry<String, String>> toSet() {
|
||||
return map.entries();
|
||||
return this.map.entries();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Multimap<String, String> toMultimap() {
|
||||
return map;
|
||||
return this.map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return hashCode;
|
||||
return this.hashCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -222,10 +221,10 @@ public final class ImmutableContextSet extends AbstractContextSet implements Con
|
||||
}
|
||||
|
||||
private synchronized ImmutableSetMultimap.Builder<String, String> builder() {
|
||||
if (builder == null) {
|
||||
builder = ImmutableSetMultimap.builder();
|
||||
if (this.builder == null) {
|
||||
this.builder = ImmutableSetMultimap.builder();
|
||||
}
|
||||
return builder;
|
||||
return this.builder;
|
||||
}
|
||||
|
||||
private void put(String key, String value) {
|
||||
@ -257,7 +256,7 @@ public final class ImmutableContextSet extends AbstractContextSet implements Con
|
||||
*/
|
||||
@Nonnull
|
||||
public Builder add(@Nonnull Map.Entry<String, String> entry) {
|
||||
checkNotNull(entry, "entry");
|
||||
Objects.requireNonNull(entry, "entry");
|
||||
add(entry.getKey(), entry.getValue());
|
||||
return this;
|
||||
}
|
||||
@ -272,7 +271,7 @@ public final class ImmutableContextSet extends AbstractContextSet implements Con
|
||||
*/
|
||||
@Nonnull
|
||||
public Builder addAll(@Nonnull Iterable<? extends Map.Entry<String, String>> iterable) {
|
||||
for (Map.Entry<String, String> e : checkNotNull(iterable, "iterable")) {
|
||||
for (Map.Entry<String, String> e : Objects.requireNonNull(iterable, "iterable")) {
|
||||
add(e);
|
||||
}
|
||||
return this;
|
||||
@ -288,7 +287,7 @@ public final class ImmutableContextSet extends AbstractContextSet implements Con
|
||||
*/
|
||||
@Nonnull
|
||||
public Builder addAll(@Nonnull Map<String, String> map) {
|
||||
addAll(checkNotNull(map, "map").entrySet());
|
||||
addAll(Objects.requireNonNull(map, "map").entrySet());
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -303,7 +302,7 @@ public final class ImmutableContextSet extends AbstractContextSet implements Con
|
||||
*/
|
||||
@Nonnull
|
||||
public Builder addAll(@Nonnull Multimap<String, String> multimap) {
|
||||
addAll(checkNotNull(multimap, "multimap").entries());
|
||||
addAll(Objects.requireNonNull(multimap, "multimap").entries());
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -317,7 +316,7 @@ public final class ImmutableContextSet extends AbstractContextSet implements Con
|
||||
*/
|
||||
@Nonnull
|
||||
public Builder addAll(@Nonnull ContextSet contextSet) {
|
||||
checkNotNull(contextSet, "contextSet");
|
||||
Objects.requireNonNull(contextSet, "contextSet");
|
||||
if (contextSet instanceof AbstractContextSet) {
|
||||
AbstractContextSet other = ((AbstractContextSet) contextSet);
|
||||
if (!other.isEmpty()) {
|
||||
@ -337,10 +336,10 @@ public final class ImmutableContextSet extends AbstractContextSet implements Con
|
||||
*/
|
||||
@Nonnull
|
||||
public ImmutableContextSet build() {
|
||||
if (builder == null) {
|
||||
if (this.builder == null) {
|
||||
return empty();
|
||||
} else {
|
||||
return new ImmutableContextSet(builder.build());
|
||||
return new ImmutableContextSet(this.builder.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.api.context;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSetMultimap;
|
||||
@ -35,12 +34,11 @@ import com.google.common.collect.SetMultimap;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* A mutable implementation of {@link ContextSet}.
|
||||
*
|
||||
@ -58,8 +56,8 @@ public final class MutableContextSet extends AbstractContextSet implements Conte
|
||||
*/
|
||||
@Nonnull
|
||||
public static MutableContextSet singleton(@Nonnull String key, @Nonnull String value) {
|
||||
checkNotNull(key, "key");
|
||||
checkNotNull(value, "value");
|
||||
Objects.requireNonNull(key, "key");
|
||||
Objects.requireNonNull(value, "value");
|
||||
MutableContextSet set = MutableContextSet.create();
|
||||
set.add(key, value);
|
||||
return set;
|
||||
@ -78,10 +76,10 @@ public final class MutableContextSet extends AbstractContextSet implements Conte
|
||||
*/
|
||||
@Nonnull
|
||||
public static MutableContextSet of(@Nonnull String key1, @Nonnull String value1, @Nonnull String key2, @Nonnull String value2) {
|
||||
checkNotNull(key1, "key1");
|
||||
checkNotNull(value1, "value1");
|
||||
checkNotNull(key2, "key2");
|
||||
checkNotNull(value2, "value2");
|
||||
Objects.requireNonNull(key1, "key1");
|
||||
Objects.requireNonNull(value1, "value1");
|
||||
Objects.requireNonNull(key2, "key2");
|
||||
Objects.requireNonNull(value2, "value2");
|
||||
MutableContextSet set = create();
|
||||
set.add(key1, value1);
|
||||
set.add(key2, value2);
|
||||
@ -97,7 +95,7 @@ public final class MutableContextSet extends AbstractContextSet implements Conte
|
||||
*/
|
||||
@Nonnull
|
||||
public static MutableContextSet fromEntries(@Nonnull Iterable<? extends Map.Entry<String, String>> iterable) {
|
||||
checkNotNull(iterable, "iterable");
|
||||
Objects.requireNonNull(iterable, "iterable");
|
||||
MutableContextSet set = create();
|
||||
set.addAll(iterable);
|
||||
return set;
|
||||
@ -112,7 +110,7 @@ public final class MutableContextSet extends AbstractContextSet implements Conte
|
||||
*/
|
||||
@Nonnull
|
||||
public static MutableContextSet fromMap(@Nonnull Map<String, String> map) {
|
||||
checkNotNull(map, "map");
|
||||
Objects.requireNonNull(map, "map");
|
||||
MutableContextSet set = create();
|
||||
set.addAll(map);
|
||||
return set;
|
||||
@ -128,7 +126,7 @@ public final class MutableContextSet extends AbstractContextSet implements Conte
|
||||
*/
|
||||
@Nonnull
|
||||
public static MutableContextSet fromMultimap(@Nonnull Multimap<String, String> multimap) {
|
||||
checkNotNull(multimap, "multimap");
|
||||
Objects.requireNonNull(multimap, "multimap");
|
||||
MutableContextSet set = create();
|
||||
set.addAll(multimap);
|
||||
return set;
|
||||
@ -145,7 +143,7 @@ public final class MutableContextSet extends AbstractContextSet implements Conte
|
||||
*/
|
||||
@Nonnull
|
||||
public static MutableContextSet fromSet(@Nonnull ContextSet contextSet) {
|
||||
Preconditions.checkNotNull(contextSet, "contextSet");
|
||||
Objects.requireNonNull(contextSet, "contextSet");
|
||||
MutableContextSet set = create();
|
||||
set.addAll(contextSet);
|
||||
return set;
|
||||
@ -173,7 +171,7 @@ public final class MutableContextSet extends AbstractContextSet implements Conte
|
||||
|
||||
@Override
|
||||
protected Multimap<String, String> backing() {
|
||||
return map;
|
||||
return this.map;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -185,10 +183,10 @@ public final class MutableContextSet extends AbstractContextSet implements Conte
|
||||
@Override
|
||||
public ImmutableContextSet makeImmutable() {
|
||||
// if the map is empty, don't create a new instance
|
||||
if (map.isEmpty()) {
|
||||
if (this.map.isEmpty()) {
|
||||
return ImmutableContextSet.empty();
|
||||
}
|
||||
return new ImmutableContextSet(ImmutableSetMultimap.copyOf(map));
|
||||
return new ImmutableContextSet(ImmutableSetMultimap.copyOf(this.map));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@ -200,13 +198,13 @@ public final class MutableContextSet extends AbstractContextSet implements Conte
|
||||
@Nonnull
|
||||
@Override
|
||||
public Set<Map.Entry<String, String>> toSet() {
|
||||
return ImmutableSet.copyOf(map.entries());
|
||||
return ImmutableSet.copyOf(this.map.entries());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Multimap<String, String> toMultimap() {
|
||||
return ImmutableSetMultimap.copyOf(map);
|
||||
return ImmutableSetMultimap.copyOf(this.map);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -217,7 +215,7 @@ public final class MutableContextSet extends AbstractContextSet implements Conte
|
||||
* @throws NullPointerException if the key or value is null
|
||||
*/
|
||||
public void add(@Nonnull String key, @Nonnull String value) {
|
||||
map.put(sanitizeKey(key), sanitizeValue(value));
|
||||
this.map.put(sanitizeKey(key), sanitizeValue(value));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -227,7 +225,7 @@ public final class MutableContextSet extends AbstractContextSet implements Conte
|
||||
* @throws NullPointerException if the entry is null
|
||||
*/
|
||||
public void add(@Nonnull Map.Entry<String, String> entry) {
|
||||
checkNotNull(entry, "entry");
|
||||
Objects.requireNonNull(entry, "entry");
|
||||
add(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
@ -238,7 +236,7 @@ public final class MutableContextSet extends AbstractContextSet implements Conte
|
||||
* @throws NullPointerException if iterable is null
|
||||
*/
|
||||
public void addAll(@Nonnull Iterable<? extends Map.Entry<String, String>> iterable) {
|
||||
for (Map.Entry<String, String> e : checkNotNull(iterable, "iterable")) {
|
||||
for (Map.Entry<String, String> e : Objects.requireNonNull(iterable, "iterable")) {
|
||||
add(e);
|
||||
}
|
||||
}
|
||||
@ -250,7 +248,7 @@ public final class MutableContextSet extends AbstractContextSet implements Conte
|
||||
* @throws NullPointerException if the map is null
|
||||
*/
|
||||
public void addAll(@Nonnull Map<String, String> map) {
|
||||
addAll(checkNotNull(map, "map").entrySet());
|
||||
addAll(Objects.requireNonNull(map, "map").entrySet());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -261,7 +259,7 @@ public final class MutableContextSet extends AbstractContextSet implements Conte
|
||||
* @since 3.4
|
||||
*/
|
||||
public void addAll(@Nonnull Multimap<String, String> multimap) {
|
||||
addAll(checkNotNull(multimap, "multimap").entries());
|
||||
addAll(Objects.requireNonNull(multimap, "multimap").entries());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -271,7 +269,7 @@ public final class MutableContextSet extends AbstractContextSet implements Conte
|
||||
* @throws NullPointerException if the contextSet is null
|
||||
*/
|
||||
public void addAll(@Nonnull ContextSet contextSet) {
|
||||
checkNotNull(contextSet, "contextSet");
|
||||
Objects.requireNonNull(contextSet, "contextSet");
|
||||
if (contextSet instanceof AbstractContextSet) {
|
||||
AbstractContextSet other = ((AbstractContextSet) contextSet);
|
||||
this.map.putAll(other.backing());
|
||||
@ -288,7 +286,7 @@ public final class MutableContextSet extends AbstractContextSet implements Conte
|
||||
* @throws NullPointerException if the key or value is null
|
||||
*/
|
||||
public void remove(@Nonnull String key, @Nonnull String value) {
|
||||
map.remove(sanitizeKey(key), sanitizeValue(value));
|
||||
this.map.remove(sanitizeKey(key), sanitizeValue(value));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -300,7 +298,7 @@ public final class MutableContextSet extends AbstractContextSet implements Conte
|
||||
*/
|
||||
public void removeIgnoreCase(@Nonnull String key, @Nonnull String value) {
|
||||
String v = sanitizeValue(value);
|
||||
Collection<String> strings = map.asMap().get(sanitizeKey(key));
|
||||
Collection<String> strings = this.map.asMap().get(sanitizeKey(key));
|
||||
if (strings != null) {
|
||||
strings.removeIf(e -> e.equalsIgnoreCase(v));
|
||||
}
|
||||
@ -313,14 +311,14 @@ public final class MutableContextSet extends AbstractContextSet implements Conte
|
||||
* @throws NullPointerException if the key is null
|
||||
*/
|
||||
public void removeAll(@Nonnull String key) {
|
||||
map.removeAll(sanitizeKey(key));
|
||||
this.map.removeAll(sanitizeKey(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all contexts from the set.
|
||||
*/
|
||||
public void clear() {
|
||||
map.clear();
|
||||
this.map.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -51,6 +51,6 @@ public enum PlatformType {
|
||||
*/
|
||||
@Nonnull
|
||||
public String getFriendlyName() {
|
||||
return friendlyName;
|
||||
return this.friendlyName;
|
||||
}
|
||||
}
|
||||
|
@ -92,11 +92,10 @@
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- Lombok -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
<groupId>com.google.code.findbugs</groupId>
|
||||
<artifactId>jsr305</artifactId>
|
||||
<version>3.0.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- LilyPad -->
|
||||
@ -166,6 +165,16 @@
|
||||
<artifactId>bukkit-permissions</artifactId>
|
||||
<version>2.5</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.mcstats.bukkit</groupId>
|
||||
<artifactId>metrics</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -52,7 +52,7 @@ public class BukkitCommandExecutor extends CommandManager implements CommandExec
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
Sender lpSender = plugin.getSenderFactory().wrap(sender);
|
||||
Sender lpSender = this.plugin.getSenderFactory().wrap(sender);
|
||||
List<String> arguments = stripQuotes(ARGUMENT_SPLITTER.splitToList(ARGUMENT_JOINER.join(args)));
|
||||
|
||||
onCommand(lpSender, label, arguments);
|
||||
@ -61,7 +61,7 @@ public class BukkitCommandExecutor extends CommandManager implements CommandExec
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
|
||||
Sender lpSender = plugin.getSenderFactory().wrap(sender);
|
||||
Sender lpSender = this.plugin.getSenderFactory().wrap(sender);
|
||||
List<String> arguments = stripQuotes(TAB_COMPLETE_ARGUMENT_SPLITTER.splitToList(ARGUMENT_JOINER.join(args)));
|
||||
|
||||
return onTabComplete(lpSender, arguments);
|
||||
|
@ -52,38 +52,38 @@ public class BukkitConfigAdapter extends AbstractConfigurationAdapter implements
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
configuration = YamlConfiguration.loadConfiguration(file);
|
||||
this.configuration = YamlConfiguration.loadConfiguration(this.file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(String path) {
|
||||
return configuration.contains(path);
|
||||
return this.configuration.contains(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString(String path, String def) {
|
||||
return configuration.getString(path, def);
|
||||
return this.configuration.getString(path, def);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInt(String path, int def) {
|
||||
return configuration.getInt(path, def);
|
||||
return this.configuration.getInt(path, def);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBoolean(String path, boolean def) {
|
||||
return configuration.getBoolean(path, def);
|
||||
return this.configuration.getBoolean(path, def);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getList(String path, List<String> def) {
|
||||
List<String> ret = configuration.getStringList(path);
|
||||
List<String> ret = this.configuration.getStringList(path);
|
||||
return ret == null ? def : ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getObjectList(String path, List<String> def) {
|
||||
ConfigurationSection section = configuration.getConfigurationSection(path);
|
||||
ConfigurationSection section = this.configuration.getConfigurationSection(path);
|
||||
if (section == null) {
|
||||
return def;
|
||||
}
|
||||
@ -95,7 +95,7 @@ public class BukkitConfigAdapter extends AbstractConfigurationAdapter implements
|
||||
@Override
|
||||
public Map<String, String> getMap(String path, Map<String, String> def) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
ConfigurationSection section = configuration.getConfigurationSection(path);
|
||||
ConfigurationSection section = this.configuration.getConfigurationSection(path);
|
||||
if (section == null) {
|
||||
return def;
|
||||
}
|
||||
|
@ -25,10 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.bukkit;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
|
||||
import me.lucko.luckperms.common.plugin.SchedulerAdapter;
|
||||
@ -43,27 +39,16 @@ import java.util.concurrent.SynchronousQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class BukkitSchedulerAdapter implements SchedulerAdapter {
|
||||
private final LPBukkitPlugin plugin;
|
||||
|
||||
@Getter
|
||||
@Accessors(fluent = true)
|
||||
private final ExecutorService asyncFallback;
|
||||
|
||||
@Getter
|
||||
@Accessors(fluent = true)
|
||||
private final Executor asyncBukkit;
|
||||
|
||||
@Getter
|
||||
@Accessors(fluent = true)
|
||||
private final Executor sync;
|
||||
|
||||
@Getter
|
||||
@Accessors(fluent = true)
|
||||
private final Executor async;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean useFallback = true;
|
||||
|
||||
private final Set<BukkitTask> tasks = ConcurrentHashMap.newKeySet();
|
||||
@ -89,61 +74,84 @@ public class BukkitSchedulerAdapter implements SchedulerAdapter {
|
||||
|
||||
@Override
|
||||
public void asyncRepeating(Runnable runnable, long intervalTicks) {
|
||||
BukkitTask task = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, runnable, intervalTicks, intervalTicks);
|
||||
tasks.add(task);
|
||||
BukkitTask task = this.plugin.getServer().getScheduler().runTaskTimerAsynchronously(this.plugin, runnable, intervalTicks, intervalTicks);
|
||||
this.tasks.add(task);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void syncRepeating(Runnable runnable, long intervalTicks) {
|
||||
BukkitTask task = plugin.getServer().getScheduler().runTaskTimer(plugin, runnable, intervalTicks, intervalTicks);
|
||||
tasks.add(task);
|
||||
BukkitTask task = this.plugin.getServer().getScheduler().runTaskTimer(this.plugin, runnable, intervalTicks, intervalTicks);
|
||||
this.tasks.add(task);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void asyncLater(Runnable runnable, long delayTicks) {
|
||||
plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, runnable, delayTicks);
|
||||
this.plugin.getServer().getScheduler().runTaskLaterAsynchronously(this.plugin, runnable, delayTicks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void syncLater(Runnable runnable, long delayTicks) {
|
||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, runnable, delayTicks);
|
||||
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, runnable, delayTicks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
tasks.forEach(BukkitTask::cancel);
|
||||
this.tasks.forEach(BukkitTask::cancel);
|
||||
|
||||
// wait for executor
|
||||
asyncFallback.shutdown();
|
||||
this.asyncFallback.shutdown();
|
||||
try {
|
||||
asyncFallback.awaitTermination(30, TimeUnit.SECONDS);
|
||||
this.asyncFallback.awaitTermination(30, TimeUnit.SECONDS);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ExecutorService asyncFallback() {
|
||||
return this.asyncFallback;
|
||||
}
|
||||
|
||||
public Executor asyncBukkit() {
|
||||
return this.asyncBukkit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Executor sync() {
|
||||
return this.sync;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Executor async() {
|
||||
return this.async;
|
||||
}
|
||||
|
||||
public void setUseFallback(boolean useFallback) {
|
||||
this.useFallback = useFallback;
|
||||
}
|
||||
|
||||
private final class SyncExecutor implements Executor {
|
||||
@Override
|
||||
public void execute(Runnable runnable) {
|
||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, runnable);
|
||||
public void execute(@Nonnull Runnable runnable) {
|
||||
BukkitSchedulerAdapter.this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(BukkitSchedulerAdapter.this.plugin, runnable);
|
||||
}
|
||||
}
|
||||
|
||||
private final class AsyncExecutor implements Executor {
|
||||
@Override
|
||||
public void execute(Runnable runnable) {
|
||||
if (useFallback || !plugin.isEnabled()) {
|
||||
asyncFallback.execute(runnable);
|
||||
public void execute(@Nonnull Runnable runnable) {
|
||||
if (BukkitSchedulerAdapter.this.useFallback || !BukkitSchedulerAdapter.this.plugin.isEnabled()) {
|
||||
BukkitSchedulerAdapter.this.asyncFallback.execute(runnable);
|
||||
} else {
|
||||
asyncBukkit.execute(runnable);
|
||||
BukkitSchedulerAdapter.this.asyncBukkit.execute(runnable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final class BukkitAsyncExecutor implements Executor {
|
||||
@Override
|
||||
public void execute(Runnable runnable) {
|
||||
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, runnable);
|
||||
public void execute(@Nonnull Runnable runnable) {
|
||||
BukkitSchedulerAdapter.this.plugin.getServer().getScheduler().runTaskAsynchronously(BukkitSchedulerAdapter.this.plugin, runnable);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.bukkit;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.api.Tristate;
|
||||
import me.lucko.luckperms.bukkit.compat.BukkitJsonMessageHandler;
|
||||
import me.lucko.luckperms.bukkit.compat.ReflectionUtil;
|
||||
@ -51,8 +49,8 @@ public class BukkitSenderFactory extends SenderFactory<CommandSender> {
|
||||
|
||||
public BukkitSenderFactory(LuckPermsPlugin plugin) {
|
||||
super(plugin);
|
||||
bukkitHandler = new BukkitJsonMessageHandler();
|
||||
spigotHandler = isSpigot() ? new SpigotJsonMessageHandler() : null;
|
||||
this.bukkitHandler = new BukkitJsonMessageHandler();
|
||||
this.spigotHandler = isSpigot() ? new SpigotJsonMessageHandler() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -89,12 +87,12 @@ public class BukkitSenderFactory extends SenderFactory<CommandSender> {
|
||||
String json = ComponentSerializers.JSON.serialize(message);
|
||||
|
||||
// Try Bukkit.
|
||||
if (bukkitHandler.sendJsonMessage(player, json)) {
|
||||
if (this.bukkitHandler.sendJsonMessage(player, json)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Try Spigot.
|
||||
if (spigotHandler != null && spigotHandler.sendJsonMessage(player, json)) {
|
||||
if (this.spigotHandler != null && this.spigotHandler.sendJsonMessage(player, json)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -125,14 +123,18 @@ public class BukkitSenderFactory extends SenderFactory<CommandSender> {
|
||||
}
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
private static final class BlockMessengerAgent implements Runnable {
|
||||
private final BlockCommandSender block;
|
||||
private final String message;
|
||||
|
||||
private BlockMessengerAgent(BlockCommandSender block, String message) {
|
||||
this.block = block;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
block.sendMessage(message);
|
||||
this.block.sendMessage(this.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.bukkit;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.LuckPermsApi;
|
||||
import me.lucko.luckperms.api.platform.PlatformType;
|
||||
@ -110,7 +108,6 @@ import java.util.stream.Stream;
|
||||
/**
|
||||
* LuckPerms implementation for the Bukkit API.
|
||||
*/
|
||||
@Getter
|
||||
public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
|
||||
private long startTime;
|
||||
@ -150,13 +147,13 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
}
|
||||
|
||||
// setup minimal functionality in order to load initial dependencies
|
||||
scheduler = new BukkitSchedulerAdapter(this);
|
||||
localeManager = new NoopLocaleManager();
|
||||
senderFactory = new BukkitSenderFactory(this);
|
||||
log = new SenderLogger(this, getConsoleSender());
|
||||
this.scheduler = new BukkitSchedulerAdapter(this);
|
||||
this.localeManager = new NoopLocaleManager();
|
||||
this.senderFactory = new BukkitSenderFactory(this);
|
||||
this.log = new SenderLogger(this, getConsoleSender());
|
||||
|
||||
dependencyManager = new DependencyManager(this);
|
||||
dependencyManager.loadDependencies(Collections.singleton(Dependency.CAFFEINE));
|
||||
this.dependencyManager = new DependencyManager(this);
|
||||
this.dependencyManager.loadDependencies(Collections.singleton(Dependency.CAFFEINE));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -178,103 +175,103 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
} finally {
|
||||
// count down the latch when onEnable has been called
|
||||
// we don't care about the result here
|
||||
enableLatch.countDown();
|
||||
this.enableLatch.countDown();
|
||||
}
|
||||
}
|
||||
|
||||
private void enable() {
|
||||
startTime = System.currentTimeMillis();
|
||||
this.startTime = System.currentTimeMillis();
|
||||
sendStartupBanner(getConsoleSender());
|
||||
verboseHandler = new VerboseHandler(scheduler.asyncBukkit(), getVersion());
|
||||
permissionVault = new PermissionVault(scheduler.asyncBukkit());
|
||||
logDispatcher = new LogDispatcher(this);
|
||||
this.verboseHandler = new VerboseHandler(this.scheduler.asyncBukkit(), getVersion());
|
||||
this.permissionVault = new PermissionVault(this.scheduler.asyncBukkit());
|
||||
this.logDispatcher = new LogDispatcher(this);
|
||||
|
||||
getLog().info("Loading configuration...");
|
||||
configuration = new AbstractConfiguration(this, new BukkitConfigAdapter(this, resolveConfig("config.yml")));
|
||||
configuration.loadAll();
|
||||
this.configuration = new AbstractConfiguration(this, new BukkitConfigAdapter(this, resolveConfig("config.yml")));
|
||||
this.configuration.loadAll();
|
||||
|
||||
StorageFactory storageFactory = new StorageFactory(this);
|
||||
Set<StorageType> storageTypes = storageFactory.getRequiredTypes(StorageType.H2);
|
||||
dependencyManager.loadStorageDependencies(storageTypes);
|
||||
this.dependencyManager.loadStorageDependencies(storageTypes);
|
||||
|
||||
// setup the Bukkit defaults hook
|
||||
defaultsProvider = new DefaultsProvider();
|
||||
childPermissionProvider = new ChildPermissionProvider();
|
||||
this.defaultsProvider = new DefaultsProvider();
|
||||
this.childPermissionProvider = new ChildPermissionProvider();
|
||||
|
||||
// give all plugins a chance to load their permissions, then refresh.
|
||||
scheduler.syncLater(new BukkitProcessorsSetupTask(this), 1L);
|
||||
this.scheduler.syncLater(new BukkitProcessorsSetupTask(this), 1L);
|
||||
|
||||
// register events
|
||||
getServer().getPluginManager().registerEvents(new BukkitConnectionListener(this), this);
|
||||
getServer().getPluginManager().registerEvents(new BukkitPlatformListener(this), this);
|
||||
|
||||
if (getConfiguration().get(ConfigKeys.WATCH_FILES)) {
|
||||
fileWatcher = new FileWatcher(this);
|
||||
getScheduler().asyncRepeating(fileWatcher, 30L);
|
||||
this.fileWatcher = new FileWatcher(this);
|
||||
getScheduler().asyncRepeating(this.fileWatcher, 30L);
|
||||
}
|
||||
|
||||
// initialise datastore
|
||||
storage = storageFactory.getInstance(StorageType.H2);
|
||||
this.storage = storageFactory.getInstance(StorageType.H2);
|
||||
|
||||
// initialise messaging
|
||||
messagingService = new BukkitMessagingFactory(this).getInstance();
|
||||
this.messagingService = new BukkitMessagingFactory(this).getInstance();
|
||||
|
||||
// setup the update task buffer
|
||||
updateTaskBuffer = new UpdateTaskBuffer(this);
|
||||
this.updateTaskBuffer = new UpdateTaskBuffer(this);
|
||||
|
||||
// load locale
|
||||
localeManager = new SimpleLocaleManager();
|
||||
localeManager.tryLoad(this, new File(getDataFolder(), "lang.yml"));
|
||||
this.localeManager = new SimpleLocaleManager();
|
||||
this.localeManager.tryLoad(this, new File(getDataFolder(), "lang.yml"));
|
||||
|
||||
// register commands
|
||||
commandManager = new BukkitCommandExecutor(this);
|
||||
this.commandManager = new BukkitCommandExecutor(this);
|
||||
PluginCommand main = getServer().getPluginCommand("luckperms");
|
||||
main.setExecutor(commandManager);
|
||||
main.setTabCompleter(commandManager);
|
||||
main.setExecutor(this.commandManager);
|
||||
main.setTabCompleter(this.commandManager);
|
||||
main.setDescription("Manage permissions");
|
||||
main.setAliases(Arrays.asList("lp", "perm", "perms", "permission", "permissions"));
|
||||
|
||||
// load internal managers
|
||||
getLog().info("Loading internal permission managers...");
|
||||
uuidCache = new UuidCache(this);
|
||||
userManager = new GenericUserManager(this);
|
||||
groupManager = new GenericGroupManager(this);
|
||||
trackManager = new GenericTrackManager(this);
|
||||
calculatorFactory = new BukkitCalculatorFactory(this);
|
||||
cachedStateManager = new CachedStateManager();
|
||||
this.uuidCache = new UuidCache(this);
|
||||
this.userManager = new GenericUserManager(this);
|
||||
this.groupManager = new GenericGroupManager(this);
|
||||
this.trackManager = new GenericTrackManager(this);
|
||||
this.calculatorFactory = new BukkitCalculatorFactory(this);
|
||||
this.cachedStateManager = new CachedStateManager();
|
||||
|
||||
// setup context manager
|
||||
contextManager = new BukkitContextManager(this);
|
||||
contextManager.registerCalculator(new WorldCalculator(this));
|
||||
contextManager.registerStaticCalculator(new LuckPermsCalculator(getConfiguration()));
|
||||
this.contextManager = new BukkitContextManager(this);
|
||||
this.contextManager.registerCalculator(new WorldCalculator(this));
|
||||
this.contextManager.registerStaticCalculator(new LuckPermsCalculator(getConfiguration()));
|
||||
|
||||
// inject our own subscription map
|
||||
new SubscriptionMapInjector(this).run();
|
||||
|
||||
// schedule another injection after all plugins have loaded - the entire pluginmanager instance
|
||||
// is replaced by some plugins :(
|
||||
scheduler.asyncLater(new SubscriptionMapInjector(this), 2L);
|
||||
this.scheduler.asyncLater(new SubscriptionMapInjector(this), 2L);
|
||||
|
||||
// Provide vault support
|
||||
tryVaultHook(false);
|
||||
|
||||
// register with the LP API
|
||||
apiProvider = new LuckPermsApiProvider(this);
|
||||
this.apiProvider = new LuckPermsApiProvider(this);
|
||||
|
||||
// setup event factory
|
||||
eventFactory = new EventFactory(this, apiProvider);
|
||||
this.eventFactory = new EventFactory(this, this.apiProvider);
|
||||
|
||||
ApiRegistrationUtil.registerProvider(apiProvider);
|
||||
getServer().getServicesManager().register(LuckPermsApi.class, apiProvider, this, ServicePriority.Normal);
|
||||
ApiRegistrationUtil.registerProvider(this.apiProvider);
|
||||
getServer().getServicesManager().register(LuckPermsApi.class, this.apiProvider, this, ServicePriority.Normal);
|
||||
|
||||
|
||||
// schedule update tasks
|
||||
int mins = getConfiguration().get(ConfigKeys.SYNC_TIME);
|
||||
if (mins > 0) {
|
||||
long ticks = mins * 60 * 20;
|
||||
scheduler.asyncRepeating(() -> updateTaskBuffer.request(), ticks);
|
||||
this.scheduler.asyncRepeating(() -> this.updateTaskBuffer.request(), ticks);
|
||||
}
|
||||
scheduler.asyncLater(() -> updateTaskBuffer.request(), 40L);
|
||||
this.scheduler.asyncLater(() -> this.updateTaskBuffer.request(), 40L);
|
||||
|
||||
// run an update instantly.
|
||||
getLog().info("Performing initial data load...");
|
||||
@ -286,8 +283,8 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
|
||||
|
||||
// register tasks
|
||||
scheduler.asyncRepeating(new ExpireTemporaryTask(this), 60L);
|
||||
scheduler.asyncRepeating(new CacheHousekeepingTask(this), 2400L);
|
||||
this.scheduler.asyncRepeating(new ExpireTemporaryTask(this), 60L);
|
||||
this.scheduler.asyncRepeating(new CacheHousekeepingTask(this), 2400L);
|
||||
|
||||
// register permissions
|
||||
try {
|
||||
@ -302,20 +299,20 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
}
|
||||
|
||||
if (!getConfiguration().get(ConfigKeys.OPS_ENABLED)) {
|
||||
scheduler.doSync(() -> getServer().getOperators().forEach(o -> o.setOp(false)));
|
||||
this.scheduler.doSync(() -> getServer().getOperators().forEach(o -> o.setOp(false)));
|
||||
}
|
||||
|
||||
// replace the temporary executor when the Bukkit one starts
|
||||
getServer().getScheduler().runTaskAsynchronously(this, () -> scheduler.setUseFallback(false));
|
||||
getServer().getScheduler().runTaskAsynchronously(this, () -> this.scheduler.setUseFallback(false));
|
||||
|
||||
// Load any online users (in the case of a reload)
|
||||
for (Player player : getServer().getOnlinePlayers()) {
|
||||
scheduler.doAsync(() -> {
|
||||
this.scheduler.doAsync(() -> {
|
||||
try {
|
||||
LoginHelper.loadUser(this, player.getUniqueId(), player.getName(), false);
|
||||
User user = getUserManager().getIfLoaded(getUuidCache().getUUID(player.getUniqueId()));
|
||||
if (user != null) {
|
||||
scheduler.doSync(() -> {
|
||||
this.scheduler.doSync(() -> {
|
||||
try {
|
||||
LPPermissible lpPermissible = new LPPermissible(player, user, this);
|
||||
PermissibleInjector.inject(player, lpPermissible);
|
||||
@ -330,7 +327,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
});
|
||||
}
|
||||
|
||||
getLog().info("Successfully enabled. (took " + (System.currentTimeMillis() - startTime) + "ms)");
|
||||
getLog().info("Successfully enabled. (took " + (System.currentTimeMillis() - this.startTime) + "ms)");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -340,11 +337,11 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
}
|
||||
|
||||
// Switch back to the fallback executor, the bukkit one won't allow new tasks
|
||||
scheduler.setUseFallback(true);
|
||||
this.scheduler.setUseFallback(true);
|
||||
|
||||
defaultsProvider.close();
|
||||
permissionVault.shutdown();
|
||||
verboseHandler.shutdown();
|
||||
this.defaultsProvider.close();
|
||||
this.permissionVault.shutdown();
|
||||
this.verboseHandler.shutdown();
|
||||
|
||||
// uninject from players
|
||||
for (Player player : getServer().getOnlinePlayers()) {
|
||||
@ -369,26 +366,26 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
SubscriptionMapInjector.uninject();
|
||||
|
||||
getLog().info("Closing storage...");
|
||||
storage.shutdown();
|
||||
this.storage.shutdown();
|
||||
|
||||
if (fileWatcher != null) {
|
||||
fileWatcher.close();
|
||||
if (this.fileWatcher != null) {
|
||||
this.fileWatcher.close();
|
||||
}
|
||||
|
||||
if (messagingService != null) {
|
||||
if (this.messagingService != null) {
|
||||
getLog().info("Closing messaging service...");
|
||||
messagingService.close();
|
||||
this.messagingService.close();
|
||||
}
|
||||
|
||||
ApiRegistrationUtil.unregisterProvider();
|
||||
getServer().getServicesManager().unregisterAll(this);
|
||||
|
||||
if (vaultHookManager != null) {
|
||||
vaultHookManager.unhook(this);
|
||||
if (this.vaultHookManager != null) {
|
||||
this.vaultHookManager.unhook(this);
|
||||
}
|
||||
|
||||
getLog().info("Shutting down internal scheduler...");
|
||||
scheduler.shutdown();
|
||||
this.scheduler.shutdown();
|
||||
|
||||
// Bukkit will do this again when #onDisable completes, but we do it early to prevent NPEs elsewhere.
|
||||
getServer().getScheduler().cancelTasks(this);
|
||||
@ -397,18 +394,18 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
}
|
||||
|
||||
public void tryVaultHook(boolean force) {
|
||||
if (vaultHookManager != null) {
|
||||
if (this.vaultHookManager != null) {
|
||||
return; // already hooked
|
||||
}
|
||||
|
||||
try {
|
||||
if (force || getServer().getPluginManager().isPluginEnabled("Vault")) {
|
||||
vaultHookManager = new VaultHookManager();
|
||||
vaultHookManager.hook(this);
|
||||
this.vaultHookManager = new VaultHookManager();
|
||||
this.vaultHookManager.hook(this);
|
||||
getLog().info("Registered Vault permission & chat hook.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
vaultHookManager = null;
|
||||
this.vaultHookManager = null;
|
||||
getLog().severe("Error occurred whilst hooking into Vault.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -420,7 +417,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
}
|
||||
|
||||
if (getConfiguration().get(ConfigKeys.AUTO_OP)) {
|
||||
Map<String, Boolean> backing = user.getCachedData().getPermissionData(contextManager.getApplicableContexts(player)).getImmutableBacking();
|
||||
Map<String, Boolean> backing = user.getCachedData().getPermissionData(this.contextManager.getApplicableContexts(player)).getImmutableBacking();
|
||||
boolean op = Optional.ofNullable(backing.get("luckperms.autoop")).orElse(false);
|
||||
player.setOp(op);
|
||||
}
|
||||
@ -439,11 +436,12 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
|
||||
@Override
|
||||
public Optional<ExtendedMessagingService> getMessagingService() {
|
||||
return Optional.ofNullable(messagingService);
|
||||
return Optional.ofNullable(this.messagingService);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<FileWatcher> getFileWatcher() {
|
||||
return Optional.ofNullable(fileWatcher);
|
||||
return Optional.ofNullable(this.fileWatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -483,7 +481,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
|
||||
@Override
|
||||
public Player getPlayer(User user) {
|
||||
return getServer().getPlayer(uuidCache.getExternalUUID(user.getUuid()));
|
||||
return getServer().getPlayer(this.uuidCache.getExternalUUID(user.getUuid()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -503,7 +501,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
if (player == null) {
|
||||
return null;
|
||||
}
|
||||
return contextManager.getApplicableContexts(player);
|
||||
return this.contextManager.getApplicableContexts(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -543,9 +541,9 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
@Override
|
||||
public Map<String, Object> getExtraInfo() {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("Vault Enabled", vaultHookManager != null);
|
||||
map.put("Bukkit Defaults count", defaultsProvider.size());
|
||||
map.put("Bukkit Child Permissions count", childPermissionProvider.getPermissions().size());
|
||||
map.put("Vault Enabled", this.vaultHookManager != null);
|
||||
map.put("Bukkit Defaults count", this.defaultsProvider.size());
|
||||
map.put("Bukkit Child Permissions count", this.childPermissionProvider.getPermissions().size());
|
||||
return map;
|
||||
}
|
||||
|
||||
@ -557,4 +555,134 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getStartTime() {
|
||||
return this.startTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BukkitSchedulerAdapter getScheduler() {
|
||||
return this.scheduler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BukkitCommandExecutor getCommandManager() {
|
||||
return this.commandManager;
|
||||
}
|
||||
|
||||
public VaultHookManager getVaultHookManager() {
|
||||
return this.vaultHookManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LuckPermsConfiguration getConfiguration() {
|
||||
return this.configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserManager getUserManager() {
|
||||
return this.userManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupManager getGroupManager() {
|
||||
return this.groupManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrackManager getTrackManager() {
|
||||
return this.trackManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Storage getStorage() {
|
||||
return this.storage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UuidCache getUuidCache() {
|
||||
return this.uuidCache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LuckPermsApiProvider getApiProvider() {
|
||||
return this.apiProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventFactory getEventFactory() {
|
||||
return this.eventFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Logger getLog() {
|
||||
return this.log;
|
||||
}
|
||||
|
||||
public DefaultsProvider getDefaultsProvider() {
|
||||
return this.defaultsProvider;
|
||||
}
|
||||
|
||||
public ChildPermissionProvider getChildPermissionProvider() {
|
||||
return this.childPermissionProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocaleManager getLocaleManager() {
|
||||
return this.localeManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DependencyManager getDependencyManager() {
|
||||
return this.dependencyManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CachedStateManager getCachedStateManager() {
|
||||
return this.cachedStateManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContextManager<Player> getContextManager() {
|
||||
return this.contextManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CalculatorFactory getCalculatorFactory() {
|
||||
return this.calculatorFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedRequest<Void> getUpdateTaskBuffer() {
|
||||
return this.updateTaskBuffer;
|
||||
}
|
||||
|
||||
public CountDownLatch getEnableLatch() {
|
||||
return this.enableLatch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VerboseHandler getVerboseHandler() {
|
||||
return this.verboseHandler;
|
||||
}
|
||||
|
||||
public BukkitSenderFactory getSenderFactory() {
|
||||
return this.senderFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionVault getPermissionVault() {
|
||||
return this.permissionVault;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LogDispatcher getLogDispatcher() {
|
||||
return this.logDispatcher;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UUID> getUniqueConnections() {
|
||||
return this.uniqueConnections;
|
||||
}
|
||||
}
|
||||
|
@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.bukkit.calculators;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
@ -45,44 +43,47 @@ import me.lucko.luckperms.common.references.HolderType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class BukkitCalculatorFactory extends AbstractCalculatorFactory {
|
||||
private final LPBukkitPlugin plugin;
|
||||
|
||||
public BukkitCalculatorFactory(LPBukkitPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionCalculator build(Contexts contexts, PermissionCalculatorMetadata metadata) {
|
||||
ImmutableList.Builder<PermissionProcessor> processors = ImmutableList.builder();
|
||||
|
||||
processors.add(new MapProcessor());
|
||||
|
||||
if (plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_CHILD_PERMISSIONS)) {
|
||||
processors.add(new ChildProcessor(plugin.getChildPermissionProvider()));
|
||||
if (this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_CHILD_PERMISSIONS)) {
|
||||
processors.add(new ChildProcessor(this.plugin.getChildPermissionProvider()));
|
||||
}
|
||||
|
||||
if (plugin.getConfiguration().get(ConfigKeys.APPLYING_REGEX)) {
|
||||
if (this.plugin.getConfiguration().get(ConfigKeys.APPLYING_REGEX)) {
|
||||
processors.add(new RegexProcessor());
|
||||
}
|
||||
|
||||
if (plugin.getConfiguration().get(ConfigKeys.APPLYING_WILDCARDS)) {
|
||||
if (this.plugin.getConfiguration().get(ConfigKeys.APPLYING_WILDCARDS)) {
|
||||
processors.add(new WildcardProcessor());
|
||||
}
|
||||
|
||||
if (plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_DEFAULT_PERMISSIONS) && metadata.getHolderType() == HolderType.USER) {
|
||||
processors.add(new DefaultsProcessor(contexts.isOp(), plugin.getDefaultsProvider()));
|
||||
if (this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_DEFAULT_PERMISSIONS) && metadata.getHolderType() == HolderType.USER) {
|
||||
processors.add(new DefaultsProcessor(contexts.isOp(), this.plugin.getDefaultsProvider()));
|
||||
}
|
||||
|
||||
return registerCalculator(new PermissionCalculator(plugin, metadata, processors.build()));
|
||||
return registerCalculator(new PermissionCalculator(this.plugin, metadata, processors.build()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getActiveProcessors() {
|
||||
ImmutableList.Builder<String> ret = ImmutableList.builder();
|
||||
ret.add("Map");
|
||||
if (plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_CHILD_PERMISSIONS)) ret.add("Child");
|
||||
if (plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_ATTACHMENT_PERMISSIONS)) ret.add("Attachment");
|
||||
if (plugin.getConfiguration().get(ConfigKeys.APPLYING_REGEX)) ret.add("Regex");
|
||||
if (plugin.getConfiguration().get(ConfigKeys.APPLYING_WILDCARDS)) ret.add("Wildcard");
|
||||
if (plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_DEFAULT_PERMISSIONS)) ret.add("Defaults");
|
||||
if (this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_CHILD_PERMISSIONS)) ret.add("Child");
|
||||
if (this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_ATTACHMENT_PERMISSIONS)) ret.add("Attachment");
|
||||
if (this.plugin.getConfiguration().get(ConfigKeys.APPLYING_REGEX)) ret.add("Regex");
|
||||
if (this.plugin.getConfiguration().get(ConfigKeys.APPLYING_WILDCARDS)) ret.add("Wildcard");
|
||||
if (this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_DEFAULT_PERMISSIONS)) ret.add("Defaults");
|
||||
return ret.build();
|
||||
}
|
||||
}
|
||||
|
@ -25,12 +25,9 @@
|
||||
|
||||
package me.lucko.luckperms.bukkit.compat;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
@UtilityClass
|
||||
public class ReflectionUtil {
|
||||
public final class ReflectionUtil {
|
||||
private static final String SERVER_VERSION = _getServerVersion();
|
||||
private static final boolean CHAT_COMPATIBLE = !SERVER_VERSION.startsWith(".v1_7_");
|
||||
|
||||
@ -71,4 +68,7 @@ public class ReflectionUtil {
|
||||
public static Class<?> obcClass(String className) throws ClassNotFoundException {
|
||||
return Class.forName(obc(className));
|
||||
}
|
||||
|
||||
private ReflectionUtil() {}
|
||||
|
||||
}
|
||||
|
@ -42,11 +42,11 @@ public class BukkitContextManager extends AbstractContextManager<Player> {
|
||||
public Contexts formContexts(Player subject, ImmutableContextSet contextSet) {
|
||||
return new Contexts(
|
||||
contextSet,
|
||||
plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_PERMS),
|
||||
plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS),
|
||||
this.plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_PERMS),
|
||||
this.plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS),
|
||||
true,
|
||||
plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_GROUPS),
|
||||
plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_WORLD_GROUPS),
|
||||
this.plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_GROUPS),
|
||||
this.plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_WORLD_GROUPS),
|
||||
subject.isOp()
|
||||
);
|
||||
}
|
||||
|
@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.bukkit.contexts;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.context.ContextCalculator;
|
||||
import me.lucko.luckperms.api.context.MutableContextSet;
|
||||
@ -35,16 +33,22 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class WorldCalculator implements ContextCalculator<Player> {
|
||||
private final LuckPermsPlugin plugin;
|
||||
|
||||
public WorldCalculator(LuckPermsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public MutableContextSet giveApplicableContext(Player subject, MutableContextSet accumulator) {
|
||||
public MutableContextSet giveApplicableContext(@Nonnull Player subject, @Nonnull MutableContextSet accumulator) {
|
||||
String world = subject.getWorld().getName().toLowerCase();
|
||||
while (!accumulator.has(Contexts.WORLD_KEY, world)) {
|
||||
accumulator.add(Contexts.WORLD_KEY, world);
|
||||
world = plugin.getConfiguration().get(ConfigKeys.WORLD_REWRITES).getOrDefault(world, world).toLowerCase();
|
||||
world = this.plugin.getConfiguration().get(ConfigKeys.WORLD_REWRITES).getOrDefault(world, world).toLowerCase();
|
||||
}
|
||||
|
||||
return accumulator;
|
||||
|
@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.bukkit.listeners;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
|
||||
import me.lucko.luckperms.bukkit.model.LPPermissible;
|
||||
import me.lucko.luckperms.bukkit.model.PermissibleInjector;
|
||||
@ -49,13 +47,16 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class BukkitConnectionListener implements Listener {
|
||||
private final LPBukkitPlugin plugin;
|
||||
|
||||
private final Set<UUID> deniedAsyncLogin = Collections.synchronizedSet(new HashSet<>());
|
||||
private final Set<UUID> deniedLogin = Collections.synchronizedSet(new HashSet<>());
|
||||
|
||||
public BukkitConnectionListener(LPBukkitPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerPreLogin(AsyncPlayerPreLoginEvent e) {
|
||||
/* Called when the player first attempts a connection with the server.
|
||||
@ -64,16 +65,16 @@ public class BukkitConnectionListener implements Listener {
|
||||
/* wait for the plugin to enable. because these events are fired async, they can be called before
|
||||
the plugin has enabled. */
|
||||
try {
|
||||
plugin.getEnableLatch().await(60, TimeUnit.SECONDS);
|
||||
this.plugin.getEnableLatch().await(60, TimeUnit.SECONDS);
|
||||
} catch (InterruptedException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
if (plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) {
|
||||
plugin.getLog().info("Processing pre-login for " + e.getUniqueId() + " - " + e.getName());
|
||||
if (this.plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) {
|
||||
this.plugin.getLog().info("Processing pre-login for " + e.getUniqueId() + " - " + e.getName());
|
||||
}
|
||||
|
||||
plugin.getUniqueConnections().add(e.getUniqueId());
|
||||
this.plugin.getUniqueConnections().add(e.getUniqueId());
|
||||
|
||||
/* Actually process the login for the connection.
|
||||
We do this here to delay the login until the data is ready.
|
||||
@ -85,15 +86,15 @@ public class BukkitConnectionListener implements Listener {
|
||||
- creating a user instance in the UserManager for this connection.
|
||||
- setting up cached data. */
|
||||
try {
|
||||
User user = LoginHelper.loadUser(plugin, e.getUniqueId(), e.getName(), false);
|
||||
plugin.getEventFactory().handleUserLoginProcess(e.getUniqueId(), e.getName(), user);
|
||||
User user = LoginHelper.loadUser(this.plugin, e.getUniqueId(), e.getName(), false);
|
||||
this.plugin.getEventFactory().handleUserLoginProcess(e.getUniqueId(), e.getName(), user);
|
||||
} catch (Exception ex) {
|
||||
plugin.getLog().severe("Exception occured whilst loading data for " + e.getUniqueId() + " - " + e.getName());
|
||||
this.plugin.getLog().severe("Exception occured whilst loading data for " + e.getUniqueId() + " - " + e.getName());
|
||||
ex.printStackTrace();
|
||||
|
||||
// deny the connection
|
||||
deniedAsyncLogin.add(e.getUniqueId());
|
||||
e.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, Message.LOADING_ERROR.asString(plugin.getLocaleManager()));
|
||||
this.deniedAsyncLogin.add(e.getUniqueId());
|
||||
e.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, Message.LOADING_ERROR.asString(this.plugin.getLocaleManager()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -103,12 +104,12 @@ public class BukkitConnectionListener implements Listener {
|
||||
If the connection was cancelled here, we need to do something to clean up the data that was loaded. */
|
||||
|
||||
// Check to see if this connection was denied at LOW.
|
||||
if (deniedAsyncLogin.remove(e.getUniqueId())) {
|
||||
if (this.deniedAsyncLogin.remove(e.getUniqueId())) {
|
||||
// their data was never loaded at LOW priority, now check to see if they have been magically allowed since then.
|
||||
|
||||
// This is a problem, as they were denied at low priority, but are now being allowed.
|
||||
if (e.getLoginResult() == AsyncPlayerPreLoginEvent.Result.ALLOWED) {
|
||||
plugin.getLog().severe("Player connection was re-allowed for " + e.getUniqueId());
|
||||
this.plugin.getLog().severe("Player connection was re-allowed for " + e.getUniqueId());
|
||||
e.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, "");
|
||||
}
|
||||
|
||||
@ -118,7 +119,7 @@ public class BukkitConnectionListener implements Listener {
|
||||
// Login event was cancelled by another plugin, but it wasn't cancelled when we handled it at LOW
|
||||
if (e.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED) {
|
||||
// Schedule cleanup of this user.
|
||||
plugin.getUserManager().scheduleUnload(e.getUniqueId());
|
||||
this.plugin.getUserManager().scheduleUnload(e.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
@ -129,18 +130,18 @@ public class BukkitConnectionListener implements Listener {
|
||||
|
||||
final Player player = e.getPlayer();
|
||||
|
||||
if (plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) {
|
||||
plugin.getLog().info("Processing login for " + player.getUniqueId() + " - " + player.getName());
|
||||
if (this.plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) {
|
||||
this.plugin.getLog().info("Processing login for " + player.getUniqueId() + " - " + player.getName());
|
||||
}
|
||||
|
||||
final User user = plugin.getUserManager().getIfLoaded(plugin.getUuidCache().getUUID(player.getUniqueId()));
|
||||
final User user = this.plugin.getUserManager().getIfLoaded(this.plugin.getUuidCache().getUUID(player.getUniqueId()));
|
||||
|
||||
/* User instance is null for whatever reason. Could be that it was unloaded between asyncpre and now. */
|
||||
if (user == null) {
|
||||
deniedLogin.add(e.getPlayer().getUniqueId());
|
||||
this.deniedLogin.add(e.getPlayer().getUniqueId());
|
||||
|
||||
plugin.getLog().warn("User " + player.getUniqueId() + " - " + player.getName() + " doesn't have data pre-loaded. - denying login.");
|
||||
e.disallow(PlayerLoginEvent.Result.KICK_OTHER, Message.LOADING_ERROR.asString(plugin.getLocaleManager()));
|
||||
this.plugin.getLog().warn("User " + player.getUniqueId() + " - " + player.getName() + " doesn't have data pre-loaded. - denying login.");
|
||||
e.disallow(PlayerLoginEvent.Result.KICK_OTHER, Message.LOADING_ERROR.asString(this.plugin.getLocaleManager()));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -148,7 +149,7 @@ public class BukkitConnectionListener implements Listener {
|
||||
// Care should be taken at this stage to ensure that async tasks which manipulate bukkit data check that the player is still online.
|
||||
try {
|
||||
// Make a new permissible for the user
|
||||
LPPermissible lpPermissible = new LPPermissible(player, user, plugin);
|
||||
LPPermissible lpPermissible = new LPPermissible(player, user, this.plugin);
|
||||
|
||||
// Inject into the player
|
||||
PermissibleInjector.inject(player, lpPermissible);
|
||||
@ -157,7 +158,7 @@ public class BukkitConnectionListener implements Listener {
|
||||
t.printStackTrace();
|
||||
}
|
||||
|
||||
plugin.refreshAutoOp(user, player);
|
||||
this.plugin.refreshAutoOp(user, player);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
@ -167,12 +168,12 @@ public class BukkitConnectionListener implements Listener {
|
||||
|
||||
// Check to see if this connection was denied at LOW. Even if it was denied at LOW, their data will still be present.
|
||||
boolean denied = false;
|
||||
if (deniedLogin.remove(e.getPlayer().getUniqueId())) {
|
||||
if (this.deniedLogin.remove(e.getPlayer().getUniqueId())) {
|
||||
denied = true;
|
||||
|
||||
// This is a problem, as they were denied at low priority, but are now being allowed.
|
||||
if (e.getResult() == PlayerLoginEvent.Result.ALLOWED) {
|
||||
plugin.getLog().severe("Player connection was re-allowed for " + e.getPlayer().getUniqueId());
|
||||
this.plugin.getLog().severe("Player connection was re-allowed for " + e.getPlayer().getUniqueId());
|
||||
e.disallow(PlayerLoginEvent.Result.KICK_OTHER, "");
|
||||
}
|
||||
}
|
||||
@ -180,12 +181,12 @@ public class BukkitConnectionListener implements Listener {
|
||||
// Login event was cancelled by another plugin since we first loaded their data
|
||||
if (denied || e.getResult() != PlayerLoginEvent.Result.ALLOWED) {
|
||||
// Schedule cleanup of this user.
|
||||
plugin.getUserManager().scheduleUnload(e.getPlayer().getUniqueId());
|
||||
this.plugin.getUserManager().scheduleUnload(e.getPlayer().getUniqueId());
|
||||
return;
|
||||
}
|
||||
|
||||
// everything is going well. login was processed ok, this is just to refresh auto-op status.
|
||||
plugin.refreshAutoOp(plugin.getUserManager().getIfLoaded(e.getPlayer().getUniqueId()), e.getPlayer());
|
||||
this.plugin.refreshAutoOp(this.plugin.getUserManager().getIfLoaded(e.getPlayer().getUniqueId()), e.getPlayer());
|
||||
}
|
||||
|
||||
// Wait until the last priority to unload, so plugins can still perform permission checks on this event
|
||||
@ -201,12 +202,12 @@ public class BukkitConnectionListener implements Listener {
|
||||
}
|
||||
|
||||
// Handle auto op
|
||||
if (plugin.getConfiguration().get(ConfigKeys.AUTO_OP)) {
|
||||
if (this.plugin.getConfiguration().get(ConfigKeys.AUTO_OP)) {
|
||||
player.setOp(false);
|
||||
}
|
||||
|
||||
// Request that the users data is unloaded.
|
||||
plugin.getUserManager().scheduleUnload(player.getUniqueId());
|
||||
this.plugin.getUserManager().scheduleUnload(player.getUniqueId());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.bukkit.listeners;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.locale.Message;
|
||||
@ -42,10 +40,13 @@ import org.bukkit.event.server.PluginEnableEvent;
|
||||
import org.bukkit.event.server.RemoteServerCommandEvent;
|
||||
import org.bukkit.event.server.ServerCommandEvent;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class BukkitPlatformListener implements Listener {
|
||||
private final LPBukkitPlugin plugin;
|
||||
|
||||
public BukkitPlatformListener(LPBukkitPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerCommand(PlayerCommandPreprocessEvent e) {
|
||||
handleCommand(e.getPlayer(), e.getMessage().toLowerCase(), e);
|
||||
@ -66,7 +67,7 @@ public class BukkitPlatformListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.getConfiguration().get(ConfigKeys.OPS_ENABLED)) {
|
||||
if (this.plugin.getConfiguration().get(ConfigKeys.OPS_ENABLED)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -80,21 +81,21 @@ public class BukkitPlatformListener implements Listener {
|
||||
|
||||
if (s.equals("op") || s.startsWith("op ") || s.equals("deop") || s.startsWith("deop ")) {
|
||||
event.setCancelled(true);
|
||||
sender.sendMessage(Message.OP_DISABLED.asString(plugin.getLocaleManager()));
|
||||
sender.sendMessage(Message.OP_DISABLED.asString(this.plugin.getLocaleManager()));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPluginEnable(PluginEnableEvent e) {
|
||||
if (e.getPlugin().getName().equalsIgnoreCase("Vault")) {
|
||||
plugin.tryVaultHook(true);
|
||||
this.plugin.tryVaultHook(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onWorldChange(PlayerChangedWorldEvent e) {
|
||||
plugin.getContextManager().invalidateCache(e.getPlayer());
|
||||
plugin.refreshAutoOp(plugin.getUserManager().getIfLoaded(e.getPlayer().getUniqueId()), e.getPlayer());
|
||||
this.plugin.getContextManager().invalidateCache(e.getPlayer());
|
||||
this.plugin.refreshAutoOp(this.plugin.getUserManager().getIfLoaded(e.getPlayer().getUniqueId()), e.getPlayer());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -52,14 +52,14 @@ public class BungeeMessagingService extends AbstractMessagingService implements
|
||||
}
|
||||
|
||||
public void init() {
|
||||
plugin.getServer().getMessenger().registerOutgoingPluginChannel(plugin, CHANNEL);
|
||||
plugin.getServer().getMessenger().registerIncomingPluginChannel(plugin, CHANNEL, this);
|
||||
this.plugin.getServer().getMessenger().registerOutgoingPluginChannel(this.plugin, CHANNEL);
|
||||
this.plugin.getServer().getMessenger().registerIncomingPluginChannel(this.plugin, CHANNEL, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
plugin.getServer().getMessenger().unregisterIncomingPluginChannel(plugin, CHANNEL);
|
||||
plugin.getServer().getMessenger().unregisterOutgoingPluginChannel(plugin, CHANNEL);
|
||||
this.plugin.getServer().getMessenger().unregisterIncomingPluginChannel(this.plugin, CHANNEL);
|
||||
this.plugin.getServer().getMessenger().unregisterOutgoingPluginChannel(this.plugin, CHANNEL);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -67,7 +67,7 @@ public class BungeeMessagingService extends AbstractMessagingService implements
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Collection<? extends Player> players = plugin.getServer().getOnlinePlayers();
|
||||
Collection<? extends Player> players = BungeeMessagingService.this.plugin.getServer().getOnlinePlayers();
|
||||
Player p = Iterables.getFirst(players, null);
|
||||
if (p == null) {
|
||||
return;
|
||||
@ -78,10 +78,10 @@ public class BungeeMessagingService extends AbstractMessagingService implements
|
||||
|
||||
byte[] data = out.toByteArray();
|
||||
|
||||
p.sendPluginMessage(plugin, CHANNEL, data);
|
||||
p.sendPluginMessage(BungeeMessagingService.this.plugin, CHANNEL, data);
|
||||
cancel();
|
||||
}
|
||||
}.runTaskTimer(plugin, 1L, 100L);
|
||||
}.runTaskTimer(this.plugin, 1L, 100L);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -51,13 +51,13 @@ public class LilyPadMessagingService extends AbstractMessagingService {
|
||||
}
|
||||
|
||||
public void init() {
|
||||
connect = plugin.getServer().getServicesManager().getRegistration(Connect.class).getProvider();
|
||||
connect.registerEvents(this);
|
||||
this.connect = this.plugin.getServer().getServicesManager().getRegistration(Connect.class).getProvider();
|
||||
this.connect.registerEvents(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
connect.unregisterEvents(this);
|
||||
this.connect.unregisterEvents(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -72,7 +72,7 @@ public class LilyPadMessagingService extends AbstractMessagingService {
|
||||
}
|
||||
|
||||
try {
|
||||
connect.request(request);
|
||||
this.connect.request(request);
|
||||
} catch (RequestException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -80,7 +80,7 @@ public class LilyPadMessagingService extends AbstractMessagingService {
|
||||
|
||||
@EventListener
|
||||
public void onMessage(MessageEvent event) {
|
||||
plugin.getScheduler().doAsync(() -> {
|
||||
this.plugin.getScheduler().doAsync(() -> {
|
||||
try {
|
||||
String channel = event.getChannel();
|
||||
|
||||
|
@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.bukkit.migration;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import me.lucko.luckperms.common.commands.utils.CommandUtils;
|
||||
import me.lucko.luckperms.common.logging.ProgressLogger;
|
||||
|
||||
@ -34,8 +32,7 @@ import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@UtilityClass
|
||||
public class BukkitMigrationUtils {
|
||||
public final class BukkitMigrationUtils {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static UUID lookupUuid(ProgressLogger log, String s) {
|
||||
@ -53,4 +50,6 @@ public class BukkitMigrationUtils {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
private BukkitMigrationUtils() {}
|
||||
|
||||
}
|
||||
|
@ -34,7 +34,6 @@ import de.bananaco.bpermissions.api.WorldManager;
|
||||
|
||||
import me.lucko.luckperms.api.ChatMetaType;
|
||||
import me.lucko.luckperms.api.event.cause.CreationCause;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||
import me.lucko.luckperms.common.commands.impl.migration.MigrationUtils;
|
||||
@ -77,7 +76,7 @@ public class MigrationBPermissions extends SubCommand<Object> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) {
|
||||
ProgressLogger log = new ProgressLogger("bPermissions");
|
||||
log.addListener(plugin.getConsoleSender());
|
||||
log.addListener(sender);
|
||||
|
@ -28,7 +28,6 @@ package me.lucko.luckperms.bukkit.migration;
|
||||
import me.lucko.luckperms.api.ChatMetaType;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.api.event.cause.CreationCause;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||
@ -65,7 +64,7 @@ public class MigrationGroupManager extends SubCommand<Object> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) {
|
||||
ProgressLogger log = new ProgressLogger("GroupManager");
|
||||
log.addListener(plugin.getConsoleSender());
|
||||
log.addListener(sender);
|
||||
|
@ -28,7 +28,6 @@ package me.lucko.luckperms.bukkit.migration;
|
||||
import com.platymuus.bukkit.permissions.PermissionsPlugin;
|
||||
|
||||
import me.lucko.luckperms.api.event.cause.CreationCause;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||
@ -59,7 +58,7 @@ public class MigrationPermissionsBukkit extends SubCommand<Object> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) {
|
||||
ProgressLogger log = new ProgressLogger("PermissionsBukkit");
|
||||
log.addListener(plugin.getConsoleSender());
|
||||
log.addListener(sender);
|
||||
|
@ -26,7 +26,6 @@
|
||||
package me.lucko.luckperms.bukkit.migration;
|
||||
|
||||
import me.lucko.luckperms.api.event.cause.CreationCause;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||
@ -67,7 +66,7 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) {
|
||||
ProgressLogger log = new ProgressLogger("PermissionsEx");
|
||||
log.addListener(plugin.getConsoleSender());
|
||||
log.addListener(sender);
|
||||
|
@ -34,7 +34,6 @@ import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.api.event.cause.CreationCause;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||
import me.lucko.luckperms.common.commands.impl.migration.MigrationUtils;
|
||||
@ -77,7 +76,7 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) {
|
||||
ProgressLogger log = new ProgressLogger("PowerfulPerms");
|
||||
log.addListener(plugin.getConsoleSender());
|
||||
log.addListener(sender);
|
||||
|
@ -28,7 +28,6 @@ package me.lucko.luckperms.bukkit.migration;
|
||||
import me.lucko.luckperms.api.ChatMetaType;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.api.event.cause.CreationCause;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||
@ -69,7 +68,7 @@ public class MigrationZPermissions extends SubCommand<Object> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) {
|
||||
ProgressLogger log = new ProgressLogger("zPermissions");
|
||||
log.addListener(plugin.getConsoleSender());
|
||||
log.addListener(sender);
|
||||
|
@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.bukkit.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
import org.bukkit.permissions.Permissible;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionAttachment;
|
||||
@ -36,13 +34,16 @@ import org.bukkit.plugin.Plugin;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class DummyPermissible implements Permissible {
|
||||
private final Runnable onRefresh;
|
||||
|
||||
public DummyPermissible(Runnable onRefresh) {
|
||||
this.onRefresh = onRefresh;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recalculatePermissions() {
|
||||
onRefresh.run();
|
||||
this.onRefresh.run();
|
||||
}
|
||||
|
||||
@Override public Set<PermissionAttachmentInfo> getEffectivePermissions() { return Collections.emptySet(); }
|
||||
|
@ -25,10 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.bukkit.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.Tristate;
|
||||
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
|
||||
@ -46,6 +42,7 @@ import org.bukkit.plugin.Plugin;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
@ -64,7 +61,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
* This class is **thread safe**. This means that when LuckPerms is installed on the server,
|
||||
* is is safe to call Player#hasPermission asynchronously.
|
||||
*/
|
||||
@Getter
|
||||
public class LPPermissible extends PermissibleBase {
|
||||
|
||||
// the LuckPerms user this permissible references.
|
||||
@ -77,7 +73,6 @@ public class LPPermissible extends PermissibleBase {
|
||||
private final LPBukkitPlugin plugin;
|
||||
|
||||
// the players previous permissible. (the one they had before this one was injected)
|
||||
@Setter
|
||||
private PermissibleBase oldPermissible = null;
|
||||
|
||||
// if the permissible is currently active.
|
||||
@ -87,27 +82,35 @@ public class LPPermissible extends PermissibleBase {
|
||||
// this collection is only modified by the attachments themselves
|
||||
final Set<LPPermissionAttachment> attachments = ConcurrentHashMap.newKeySet();
|
||||
|
||||
public LPPermissible(@NonNull Player player, @NonNull User user, @NonNull LPBukkitPlugin plugin) {
|
||||
public LPPermissible(Player player, User user, LPBukkitPlugin plugin) {
|
||||
super(player);
|
||||
this.user = user;
|
||||
this.player = player;
|
||||
this.plugin = plugin;
|
||||
this.user = Objects.requireNonNull(user, "user");
|
||||
this.player = Objects.requireNonNull(player, "player");
|
||||
this.plugin = Objects.requireNonNull(plugin, "plugin");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPermissionSet(@NonNull String permission) {
|
||||
Tristate ts = user.getCachedData().getPermissionData(calculateContexts()).getPermissionValue(permission, CheckOrigin.PLATFORM_LOOKUP_CHECK);
|
||||
public boolean isPermissionSet(String permission) {
|
||||
if (permission == null) {
|
||||
throw new NullPointerException("permission");
|
||||
}
|
||||
|
||||
Tristate ts = this.user.getCachedData().getPermissionData(calculateContexts()).getPermissionValue(permission, CheckOrigin.PLATFORM_LOOKUP_CHECK);
|
||||
return ts != Tristate.UNDEFINED || Permission.DEFAULT_PERMISSION.getValue(isOp());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPermissionSet(@NonNull Permission permission) {
|
||||
Tristate ts = user.getCachedData().getPermissionData(calculateContexts()).getPermissionValue(permission.getName(), CheckOrigin.PLATFORM_LOOKUP_CHECK);
|
||||
public boolean isPermissionSet(Permission permission) {
|
||||
if (permission == null) {
|
||||
throw new NullPointerException("permission");
|
||||
}
|
||||
|
||||
Tristate ts = this.user.getCachedData().getPermissionData(calculateContexts()).getPermissionValue(permission.getName(), CheckOrigin.PLATFORM_LOOKUP_CHECK);
|
||||
if (ts != Tristate.UNDEFINED) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_DEFAULT_PERMISSIONS)) {
|
||||
if (!this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_DEFAULT_PERMISSIONS)) {
|
||||
return Permission.DEFAULT_PERMISSION.getValue(isOp());
|
||||
} else {
|
||||
return permission.getDefault().getValue(isOp());
|
||||
@ -115,19 +118,27 @@ public class LPPermissible extends PermissibleBase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(@NonNull String permission) {
|
||||
Tristate ts = user.getCachedData().getPermissionData(calculateContexts()).getPermissionValue(permission, CheckOrigin.PLATFORM_PERMISSION_CHECK);
|
||||
public boolean hasPermission(String permission) {
|
||||
if (permission == null) {
|
||||
throw new NullPointerException("permission");
|
||||
}
|
||||
|
||||
Tristate ts = this.user.getCachedData().getPermissionData(calculateContexts()).getPermissionValue(permission, CheckOrigin.PLATFORM_PERMISSION_CHECK);
|
||||
return ts != Tristate.UNDEFINED ? ts.asBoolean() : Permission.DEFAULT_PERMISSION.getValue(isOp());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(@NonNull Permission permission) {
|
||||
Tristate ts = user.getCachedData().getPermissionData(calculateContexts()).getPermissionValue(permission.getName(), CheckOrigin.PLATFORM_PERMISSION_CHECK);
|
||||
public boolean hasPermission(Permission permission) {
|
||||
if (permission == null) {
|
||||
throw new NullPointerException("permission");
|
||||
}
|
||||
|
||||
Tristate ts = this.user.getCachedData().getPermissionData(calculateContexts()).getPermissionValue(permission.getName(), CheckOrigin.PLATFORM_PERMISSION_CHECK);
|
||||
if (ts != Tristate.UNDEFINED) {
|
||||
return ts.asBoolean();
|
||||
}
|
||||
|
||||
if (!plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_DEFAULT_PERMISSIONS)) {
|
||||
if (!this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_DEFAULT_PERMISSIONS)) {
|
||||
return Permission.DEFAULT_PERMISSION.getValue(isOp());
|
||||
} else {
|
||||
return permission.getDefault().getValue(isOp());
|
||||
@ -152,21 +163,21 @@ public class LPPermissible extends PermissibleBase {
|
||||
* @return the calculated contexts for the player.
|
||||
*/
|
||||
private Contexts calculateContexts() {
|
||||
return plugin.getContextManager().getApplicableContexts(player);
|
||||
return this.plugin.getContextManager().getApplicableContexts(this.player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOp(boolean value) {
|
||||
player.setOp(value);
|
||||
this.player.setOp(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<PermissionAttachmentInfo> getEffectivePermissions() {
|
||||
Set<Map.Entry<String, Boolean>> permissions = user.getCachedData().getPermissionData(calculateContexts()).getImmutableBacking().entrySet();
|
||||
Set<Map.Entry<String, Boolean>> permissions = this.user.getCachedData().getPermissionData(calculateContexts()).getImmutableBacking().entrySet();
|
||||
Set<PermissionAttachmentInfo> ret = new HashSet<>(permissions.size());
|
||||
|
||||
for (Map.Entry<String, Boolean> entry : permissions) {
|
||||
ret.add(new PermissionAttachmentInfo(player, entry.getKey(), null, entry.getValue()));
|
||||
ret.add(new PermissionAttachmentInfo(this.player, entry.getKey(), null, entry.getValue()));
|
||||
}
|
||||
|
||||
return ret;
|
||||
@ -174,20 +185,35 @@ public class LPPermissible extends PermissibleBase {
|
||||
|
||||
@Override
|
||||
public LPPermissionAttachment addAttachment(Plugin plugin) {
|
||||
if (plugin == null) {
|
||||
throw new NullPointerException("plugin");
|
||||
}
|
||||
|
||||
LPPermissionAttachment ret = new LPPermissionAttachment(this, plugin);
|
||||
ret.hook();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionAttachment addAttachment(Plugin plugin, @NonNull String name, boolean value) {
|
||||
public PermissionAttachment addAttachment(Plugin plugin, String permission, boolean value) {
|
||||
if (plugin == null) {
|
||||
throw new NullPointerException("plugin");
|
||||
}
|
||||
if (permission == null) {
|
||||
throw new NullPointerException("permission");
|
||||
}
|
||||
|
||||
PermissionAttachment ret = addAttachment(plugin);
|
||||
ret.setPermission(name, value);
|
||||
ret.setPermission(permission, value);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LPPermissionAttachment addAttachment(@NonNull Plugin plugin, int ticks) {
|
||||
public LPPermissionAttachment addAttachment(Plugin plugin, int ticks) {
|
||||
if (plugin == null) {
|
||||
throw new NullPointerException("plugin");
|
||||
}
|
||||
|
||||
if (!plugin.isEnabled()) {
|
||||
throw new IllegalArgumentException("Plugin " + plugin.getDescription().getFullName() + " is not enabled");
|
||||
}
|
||||
@ -195,20 +221,31 @@ public class LPPermissible extends PermissibleBase {
|
||||
LPPermissionAttachment ret = addAttachment(plugin);
|
||||
if (getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(plugin, ret::remove, ticks) == -1) {
|
||||
ret.remove();
|
||||
throw new RuntimeException("Could not add PermissionAttachment to " + player + " for plugin " + plugin.getDescription().getFullName() + ": Scheduler returned -1");
|
||||
throw new RuntimeException("Could not add PermissionAttachment to " + this.player + " for plugin " + plugin.getDescription().getFullName() + ": Scheduler returned -1");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LPPermissionAttachment addAttachment(Plugin plugin, @NonNull String name, boolean value, int ticks) {
|
||||
public LPPermissionAttachment addAttachment(Plugin plugin, String permission, boolean value, int ticks) {
|
||||
if (plugin == null) {
|
||||
throw new NullPointerException("plugin");
|
||||
}
|
||||
if (permission == null) {
|
||||
throw new NullPointerException("permission");
|
||||
}
|
||||
|
||||
LPPermissionAttachment ret = addAttachment(plugin, ticks);
|
||||
ret.setPermission(name, value);
|
||||
ret.setPermission(permission, value);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAttachment(@NonNull PermissionAttachment attachment) {
|
||||
public void removeAttachment(PermissionAttachment attachment) {
|
||||
if (attachment == null) {
|
||||
throw new NullPointerException("attachment");
|
||||
}
|
||||
|
||||
if (!(attachment instanceof LPPermissionAttachment)) {
|
||||
throw new IllegalArgumentException("Given attachment is not a LPPermissionAttachment.");
|
||||
}
|
||||
@ -228,6 +265,30 @@ public class LPPermissible extends PermissibleBase {
|
||||
|
||||
@Override
|
||||
public void clearPermissions() {
|
||||
attachments.forEach(LPPermissionAttachment::remove);
|
||||
this.attachments.forEach(LPPermissionAttachment::remove);
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
return this.user;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
public LPBukkitPlugin getPlugin() {
|
||||
return this.plugin;
|
||||
}
|
||||
|
||||
public PermissibleBase getOldPermissible() {
|
||||
return this.oldPermissible;
|
||||
}
|
||||
|
||||
public AtomicBoolean getActive() {
|
||||
return this.active;
|
||||
}
|
||||
|
||||
public void setOldPermissible(PermissibleBase oldPermissible) {
|
||||
this.oldPermissible = oldPermissible;
|
||||
}
|
||||
}
|
||||
|
@ -25,9 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.bukkit.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import me.lucko.luckperms.api.Node;
|
||||
@ -45,6 +42,7 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@ -74,7 +72,6 @@ public class LPPermissionAttachment extends PermissionAttachment {
|
||||
/**
|
||||
* The parent LPPermissible
|
||||
*/
|
||||
@Getter
|
||||
private final LPPermissible permissible;
|
||||
|
||||
/**
|
||||
@ -95,8 +92,6 @@ public class LPPermissionAttachment extends PermissionAttachment {
|
||||
/**
|
||||
* Callback to run when the attachment is removed
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
private PermissionRemovedExecutor removalCallback = null;
|
||||
|
||||
public LPPermissionAttachment(LPPermissible permissible, Plugin owner) {
|
||||
@ -113,7 +108,7 @@ public class LPPermissionAttachment extends PermissionAttachment {
|
||||
this.owner = null;
|
||||
|
||||
// copy
|
||||
perms.putAll(bukkit.getPermissions());
|
||||
this.perms.putAll(bukkit.getPermissions());
|
||||
|
||||
injectFakeMap();
|
||||
}
|
||||
@ -138,13 +133,28 @@ public class LPPermissionAttachment extends PermissionAttachment {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public LPPermissible getPermissible() {
|
||||
return this.permissible;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionRemovedExecutor getRemovalCallback() {
|
||||
return this.removalCallback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRemovalCallback(PermissionRemovedExecutor removalCallback) {
|
||||
this.removalCallback = removalCallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hooks this attachment with the parent {@link User} instance.
|
||||
*/
|
||||
public void hook() {
|
||||
hooked = true;
|
||||
permissible.attachments.add(this);
|
||||
for (Map.Entry<String, Boolean> entry : perms.entrySet()) {
|
||||
this.hooked = true;
|
||||
this.permissible.attachments.add(this);
|
||||
for (Map.Entry<String, Boolean> entry : this.perms.entrySet()) {
|
||||
if (entry.getKey() == null || entry.getKey().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
@ -153,7 +163,7 @@ public class LPPermissionAttachment extends PermissionAttachment {
|
||||
}
|
||||
|
||||
private void setPermissionInternal(String name, boolean value) {
|
||||
if (!permissible.getPlugin().getConfiguration().get(ConfigKeys.APPLY_BUKKIT_ATTACHMENT_PERMISSIONS)) {
|
||||
if (!this.permissible.getPlugin().getConfiguration().get(ConfigKeys.APPLY_BUKKIT_ATTACHMENT_PERMISSIONS)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -161,26 +171,26 @@ public class LPPermissionAttachment extends PermissionAttachment {
|
||||
// we use the servers static context to *try* to ensure that the node will apply
|
||||
Node node = NodeFactory.builder(name)
|
||||
.setValue(value)
|
||||
.withExtraContext(permissible.getPlugin().getContextManager().getStaticContext())
|
||||
.withExtraContext(this.permissible.getPlugin().getContextManager().getStaticContext())
|
||||
.build();
|
||||
|
||||
// convert the constructed node to a transient node instance to refer back to this attachment
|
||||
ImmutableTransientNode transientNode = ImmutableTransientNode.of(node, this);
|
||||
|
||||
// set the transient node
|
||||
User user = permissible.getUser();
|
||||
User user = this.permissible.getUser();
|
||||
if (user.setTransientPermission(transientNode).asBoolean()) {
|
||||
user.reloadCachedData();
|
||||
}
|
||||
}
|
||||
|
||||
private void unsetPermissionInternal(String name) {
|
||||
if (!permissible.getPlugin().getConfiguration().get(ConfigKeys.APPLY_BUKKIT_ATTACHMENT_PERMISSIONS)) {
|
||||
if (!this.permissible.getPlugin().getConfiguration().get(ConfigKeys.APPLY_BUKKIT_ATTACHMENT_PERMISSIONS)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// remove transient permissions from the holder which were added by this attachment & equal the permission
|
||||
User user = permissible.getUser();
|
||||
User user = this.permissible.getUser();
|
||||
if (user.removeIfTransient(n -> n instanceof ImmutableTransientNode && ((ImmutableTransientNode) n).getOwner() == this && n.getPermission().equals(name))) {
|
||||
user.reloadCachedData();
|
||||
}
|
||||
@ -188,7 +198,7 @@ public class LPPermissionAttachment extends PermissionAttachment {
|
||||
|
||||
private void clearInternal() {
|
||||
// remove all transient permissions added by this attachment
|
||||
User user = permissible.getUser();
|
||||
User user = this.permissible.getUser();
|
||||
if (user.removeIfTransient(n -> n instanceof ImmutableTransientNode && ((ImmutableTransientNode) n).getOwner() == this)) {
|
||||
user.reloadCachedData();
|
||||
}
|
||||
@ -196,7 +206,7 @@ public class LPPermissionAttachment extends PermissionAttachment {
|
||||
|
||||
@Override
|
||||
public boolean remove() {
|
||||
if (!hooked) {
|
||||
if (!this.hooked) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -204,31 +214,31 @@ public class LPPermissionAttachment extends PermissionAttachment {
|
||||
clearInternal();
|
||||
|
||||
// run the callback
|
||||
if (removalCallback != null) {
|
||||
removalCallback.attachmentRemoved(this);
|
||||
if (this.removalCallback != null) {
|
||||
this.removalCallback.attachmentRemoved(this);
|
||||
}
|
||||
|
||||
// unhook from the permissible
|
||||
hooked = false;
|
||||
permissible.attachments.remove(this);
|
||||
this.hooked = false;
|
||||
this.permissible.attachments.remove(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPermission(String name, boolean value) {
|
||||
Preconditions.checkNotNull(name, "name is null");
|
||||
Objects.requireNonNull(name, "name is null");
|
||||
Preconditions.checkArgument(!name.isEmpty(), "name is empty");
|
||||
|
||||
String permission = name.toLowerCase();
|
||||
|
||||
Boolean previous = perms.put(permission, value);
|
||||
Boolean previous = this.perms.put(permission, value);
|
||||
if (previous != null && previous == value) {
|
||||
return;
|
||||
}
|
||||
|
||||
// if we're not hooked, then don't actually apply the change
|
||||
// it will get applied on hook - if that ever happens
|
||||
if (!hooked) {
|
||||
if (!this.hooked) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -241,19 +251,19 @@ public class LPPermissionAttachment extends PermissionAttachment {
|
||||
|
||||
@Override
|
||||
public void unsetPermission(String name) {
|
||||
Preconditions.checkNotNull(name, "name is null");
|
||||
Objects.requireNonNull(name, "name is null");
|
||||
Preconditions.checkArgument(!name.isEmpty(), "name is empty");
|
||||
|
||||
String permission = name.toLowerCase();
|
||||
|
||||
Boolean previous = perms.remove(permission);
|
||||
Boolean previous = this.perms.remove(permission);
|
||||
if (previous == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// if we're not hooked, then don't actually apply the change
|
||||
// it will get applied on hook - if that ever happens
|
||||
if (!hooked) {
|
||||
if (!this.hooked) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -262,12 +272,12 @@ public class LPPermissionAttachment extends PermissionAttachment {
|
||||
|
||||
@Override
|
||||
public Map<String, Boolean> getPermissions() {
|
||||
return perms;
|
||||
return this.perms;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Plugin getPlugin() {
|
||||
return owner != null ? owner : permissible.getPlugin();
|
||||
return this.owner != null ? this.owner : this.permissible.getPlugin();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -295,7 +305,7 @@ public class LPPermissionAttachment extends PermissionAttachment {
|
||||
@Override
|
||||
public Boolean put(String key, Boolean value) {
|
||||
// grab the previous result, so we can still satisfy the method signature of Map
|
||||
Boolean previous = perms.get(key);
|
||||
Boolean previous = LPPermissionAttachment.this.perms.get(key);
|
||||
|
||||
// proxy the call back through the PermissionAttachment instance
|
||||
setPermission(key, value);
|
||||
@ -314,7 +324,7 @@ public class LPPermissionAttachment extends PermissionAttachment {
|
||||
String permission = ((String) key);
|
||||
|
||||
// grab the previous result, so we can still satisfy the method signature of Map
|
||||
Boolean previous = perms.get(permission);
|
||||
Boolean previous = LPPermissionAttachment.this.perms.get(permission);
|
||||
|
||||
// proxy the call back through the PermissionAttachment instance
|
||||
unsetPermission(permission);
|
||||
@ -333,61 +343,61 @@ public class LPPermissionAttachment extends PermissionAttachment {
|
||||
@Override
|
||||
public void clear() {
|
||||
// remove the permissions which have already been applied
|
||||
if (hooked) {
|
||||
if (LPPermissionAttachment.this.hooked) {
|
||||
clearInternal();
|
||||
}
|
||||
|
||||
// clear the backing map
|
||||
perms.clear();
|
||||
LPPermissionAttachment.this.perms.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
// return the size of the permissions map - probably the most accurate value we have
|
||||
return perms.size();
|
||||
return LPPermissionAttachment.this.perms.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
// return if the permissions map is empty - again probably the most accurate thing
|
||||
// we can return
|
||||
return perms.isEmpty();
|
||||
return LPPermissionAttachment.this.perms.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsKey(Object key) {
|
||||
// just proxy
|
||||
return perms.containsKey(key);
|
||||
return LPPermissionAttachment.this.perms.containsKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsValue(Object value) {
|
||||
// just proxy
|
||||
return perms.containsValue(value);
|
||||
return LPPermissionAttachment.this.perms.containsValue(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean get(Object key) {
|
||||
// just proxy
|
||||
return perms.get(key);
|
||||
return LPPermissionAttachment.this.perms.get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> keySet() {
|
||||
// just proxy
|
||||
return perms.keySet();
|
||||
return LPPermissionAttachment.this.perms.keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Boolean> values() {
|
||||
// just proxy
|
||||
return perms.values();
|
||||
return LPPermissionAttachment.this.perms.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Entry<String, Boolean>> entrySet() {
|
||||
// just proxy
|
||||
return perms.entrySet();
|
||||
return LPPermissionAttachment.this.perms.entrySet();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -44,6 +44,8 @@ import java.util.Set;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* A replacement map for the 'permSubs' instance in Bukkit's SimplePluginManager.
|
||||
*
|
||||
@ -171,13 +173,13 @@ public class LPSubscriptionMap extends HashMap<String, Map<Permissible, Boolean>
|
||||
// if the key is a player, check their LPPermissible first
|
||||
if (isPlayer) {
|
||||
Permissible p = (Permissible) key;
|
||||
if (p.isPermissionSet(permission)) {
|
||||
return p.hasPermission(permission);
|
||||
if (p.isPermissionSet(this.permission)) {
|
||||
return p.hasPermission(this.permission);
|
||||
}
|
||||
}
|
||||
|
||||
// then try the map
|
||||
Boolean result = backing.get(key);
|
||||
Boolean result = this.backing.get(key);
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
@ -185,8 +187,8 @@ public class LPSubscriptionMap extends HashMap<String, Map<Permissible, Boolean>
|
||||
// then try the permissible, if we haven't already
|
||||
if (!isPlayer && key instanceof Permissible) {
|
||||
Permissible p = (Permissible) key;
|
||||
if (p.isPermissionSet(permission)) {
|
||||
return p.hasPermission(permission);
|
||||
if (p.isPermissionSet(this.permission)) {
|
||||
return p.hasPermission(this.permission);
|
||||
}
|
||||
}
|
||||
|
||||
@ -200,17 +202,19 @@ public class LPSubscriptionMap extends HashMap<String, Map<Permissible, Boolean>
|
||||
return get(key) != null;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Set<Permissible> keySet() {
|
||||
// gather players (LPPermissibles)
|
||||
Set<Permissible> players = plugin.getServer().getOnlinePlayers().stream()
|
||||
.filter(player -> player.isPermissionSet(permission))
|
||||
Set<Permissible> players = LPSubscriptionMap.this.plugin.getServer().getOnlinePlayers().stream()
|
||||
.filter(player -> player.isPermissionSet(this.permission))
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
// then combine the players with the backing map
|
||||
return Sets.union(players, backing.keySet());
|
||||
return Sets.union(players, this.backing.keySet());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Set<Entry<Permissible, Boolean>> entrySet() {
|
||||
return keySet().stream()
|
||||
@ -233,39 +237,40 @@ public class LPSubscriptionMap extends HashMap<String, Map<Permissible, Boolean>
|
||||
|
||||
@Override
|
||||
public Boolean put(Permissible key, Boolean value) {
|
||||
return backing.put(key, value);
|
||||
return this.backing.put(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean remove(Object key) {
|
||||
return backing.remove(key);
|
||||
return this.backing.remove(key);
|
||||
}
|
||||
|
||||
// the following methods are not used in the current impls of PluginManager, but just delegate them for now
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return backing.size();
|
||||
return this.backing.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsValue(Object value) {
|
||||
return backing.containsValue(value);
|
||||
return this.backing.containsValue(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putAll(Map<? extends Permissible, ? extends Boolean> m) {
|
||||
backing.putAll(m);
|
||||
public void putAll(@Nonnull Map<? extends Permissible, ? extends Boolean> m) {
|
||||
this.backing.putAll(m);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
backing.clear();
|
||||
this.backing.clear();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Collection<Boolean> values() {
|
||||
return backing.values();
|
||||
return this.backing.values();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.bukkit.model;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import me.lucko.luckperms.bukkit.compat.ReflectionUtil;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
@ -42,8 +40,7 @@ import java.util.List;
|
||||
* This allows LuckPerms to directly intercept permission checks and take over all handling of
|
||||
* checks made by plugins.
|
||||
*/
|
||||
@UtilityClass
|
||||
public class PermissibleInjector {
|
||||
public final class PermissibleInjector {
|
||||
|
||||
/**
|
||||
* All permission checks made on standard Bukkit objects are effectively proxied to a
|
||||
@ -162,4 +159,6 @@ public class PermissibleInjector {
|
||||
}
|
||||
}
|
||||
|
||||
private PermissibleInjector() {}
|
||||
|
||||
}
|
||||
|
@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.bukkit.model;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
@ -37,7 +35,6 @@ import org.bukkit.plugin.SimplePluginManager;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Map;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class SubscriptionMapInjector implements Runnable {
|
||||
private static final Field PERM_SUBS_FIELD;
|
||||
|
||||
@ -54,22 +51,26 @@ public class SubscriptionMapInjector implements Runnable {
|
||||
|
||||
private final LPBukkitPlugin plugin;
|
||||
|
||||
public SubscriptionMapInjector(LPBukkitPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
inject();
|
||||
} catch (Exception e) {
|
||||
plugin.getLog().severe("Exception occurred whilst injecting LuckPerms Permission Subscription map.");
|
||||
this.plugin.getLog().severe("Exception occurred whilst injecting LuckPerms Permission Subscription map.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void inject() throws Exception {
|
||||
PluginManager pluginManager = plugin.getServer().getPluginManager();
|
||||
PluginManager pluginManager = this.plugin.getServer().getPluginManager();
|
||||
|
||||
if (!(pluginManager instanceof SimplePluginManager)) {
|
||||
plugin.getLog().severe("PluginManager instance is not a 'SimplePluginManager', instead: " + pluginManager.getClass());
|
||||
plugin.getLog().severe("Unable to inject LuckPerms Permission Subscription map.");
|
||||
this.plugin.getLog().severe("PluginManager instance is not a 'SimplePluginManager', instead: " + pluginManager.getClass());
|
||||
this.plugin.getLog().severe("Unable to inject LuckPerms Permission Subscription map.");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -82,7 +83,7 @@ public class SubscriptionMapInjector implements Runnable {
|
||||
Map<String, Map<Permissible, Boolean>> castedMap = (Map<String, Map<Permissible, Boolean>>) map;
|
||||
|
||||
// make a new subscription map
|
||||
LPSubscriptionMap newMap = new LPSubscriptionMap(plugin, castedMap);
|
||||
LPSubscriptionMap newMap = new LPSubscriptionMap(this.plugin, castedMap);
|
||||
|
||||
// inject it
|
||||
PERM_SUBS_FIELD.set(pluginManager, newMap);
|
||||
|
@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.bukkit.processors;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
|
||||
|
||||
import java.util.HashSet;
|
||||
@ -35,21 +33,24 @@ import java.util.Set;
|
||||
/**
|
||||
* Performs the initial setup for Bukkit permission processors
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
public class BukkitProcessorsSetupTask implements Runnable {
|
||||
private final LPBukkitPlugin plugin;
|
||||
|
||||
public BukkitProcessorsSetupTask(LPBukkitPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
plugin.getDefaultsProvider().refresh();
|
||||
plugin.getChildPermissionProvider().setup();
|
||||
this.plugin.getDefaultsProvider().refresh();
|
||||
this.plugin.getChildPermissionProvider().setup();
|
||||
|
||||
Set<String> perms = new HashSet<>();
|
||||
plugin.getServer().getPluginManager().getPermissions().forEach(p -> {
|
||||
this.plugin.getServer().getPluginManager().getPermissions().forEach(p -> {
|
||||
perms.add(p.getName());
|
||||
perms.addAll(p.getChildren().keySet());
|
||||
});
|
||||
|
||||
perms.forEach(p -> plugin.getPermissionVault().offer(p));
|
||||
perms.forEach(p -> this.plugin.getPermissionVault().offer(p));
|
||||
}
|
||||
}
|
||||
|
@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.bukkit.processors;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
@ -51,7 +49,6 @@ import java.util.Map;
|
||||
public class ChildPermissionProvider {
|
||||
|
||||
// in the format: permission+value ===> children (a map of child permissions)
|
||||
@Getter
|
||||
private ImmutableMap<Map.Entry<String, Boolean>, ImmutableMap<String, Boolean>> permissions = ImmutableMap.of();
|
||||
|
||||
public void setup() {
|
||||
@ -102,4 +99,9 @@ public class ChildPermissionProvider {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ImmutableMap<Map.Entry<String, Boolean>, ImmutableMap<String, Boolean>> getPermissions() {
|
||||
return this.permissions;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.bukkit.processors;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import me.lucko.luckperms.api.Tristate;
|
||||
@ -38,23 +36,26 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
/**
|
||||
* Permission Processor for Bukkits "child" permission system.
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
public class ChildProcessor implements PermissionProcessor {
|
||||
private final ChildPermissionProvider provider;
|
||||
private final Map<String, Boolean> childPermissions = new ConcurrentHashMap<>();
|
||||
|
||||
public ChildProcessor(ChildPermissionProvider provider) {
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tristate hasPermission(String permission) {
|
||||
return Tristate.fromNullableBoolean(childPermissions.get(permission));
|
||||
return Tristate.fromNullableBoolean(this.childPermissions.get(permission));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateBacking(Map<String, Boolean> map) {
|
||||
childPermissions.clear();
|
||||
this.childPermissions.clear();
|
||||
for (Map.Entry<String, Boolean> e : map.entrySet()) {
|
||||
Map<String, Boolean> children = provider.getPermissions().get(Maps.immutableEntry(e.getKey(), e.getValue()));
|
||||
Map<String, Boolean> children = this.provider.getPermissions().get(Maps.immutableEntry(e.getKey(), e.getValue()));
|
||||
if (children != null) {
|
||||
childPermissions.putAll(children);
|
||||
this.childPermissions.putAll(children);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.bukkit.processors;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.api.Tristate;
|
||||
import me.lucko.luckperms.common.processors.PermissionProcessor;
|
||||
|
||||
@ -38,20 +36,24 @@ import java.util.Map;
|
||||
/**
|
||||
* Permission Processor for Bukkits "default" permission system.
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
public class DefaultsProcessor implements PermissionProcessor {
|
||||
private final boolean isOp;
|
||||
private final DefaultsProvider defaultsProvider;
|
||||
|
||||
public DefaultsProcessor(boolean isOp, DefaultsProvider defaultsProvider) {
|
||||
this.isOp = isOp;
|
||||
this.defaultsProvider = defaultsProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tristate hasPermission(String permission) {
|
||||
Tristate t = defaultsProvider.lookup(permission, isOp);
|
||||
Tristate t = this.defaultsProvider.lookup(permission, this.isOp);
|
||||
if (t != Tristate.UNDEFINED) {
|
||||
return t;
|
||||
}
|
||||
|
||||
Permission defPerm = Bukkit.getServer().getPluginManager().getPermission(permission);
|
||||
return defPerm == null ? Tristate.UNDEFINED : Tristate.fromBoolean(defPerm.getDefault().getValue(isOp));
|
||||
return defPerm == null ? Tristate.UNDEFINED : Tristate.fromBoolean(defPerm.getDefault().getValue(this.isOp));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.bukkit.processors;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import me.lucko.luckperms.api.Tristate;
|
||||
@ -54,12 +52,10 @@ import java.util.Set;
|
||||
public class DefaultsProvider {
|
||||
|
||||
// defaults for opped players
|
||||
@Getter
|
||||
private Map<String, Boolean> opDefaults = ImmutableMap.of();
|
||||
private final DummyPermissible opDummy = new DummyPermissible(this::refreshOp);
|
||||
|
||||
// defaults for non-opped players
|
||||
@Getter
|
||||
private Map<String, Boolean> nonOpDefaults = ImmutableMap.of();
|
||||
private final DummyPermissible nonOpDummy = new DummyPermissible(this::refreshNonOp);
|
||||
|
||||
@ -79,7 +75,7 @@ public class DefaultsProvider {
|
||||
* @return a tristate result
|
||||
*/
|
||||
public Tristate lookup(String permission, boolean isOp) {
|
||||
Map<String, Boolean> map = isOp ? opDefaults : nonOpDefaults;
|
||||
Map<String, Boolean> map = isOp ? this.opDefaults : this.nonOpDefaults;
|
||||
return Tristate.fromNullableBoolean(map.get(permission));
|
||||
}
|
||||
|
||||
@ -89,39 +85,39 @@ public class DefaultsProvider {
|
||||
* @return the number of permissions held
|
||||
*/
|
||||
public int size() {
|
||||
return opDefaults.size() + nonOpDefaults.size();
|
||||
return this.opDefaults.size() + this.nonOpDefaults.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Refreshes the op data in this provider.
|
||||
*/
|
||||
private void refreshOp() {
|
||||
unregisterDefaults(opDefaults, opDummy, true);
|
||||
unregisterDefaults(this.opDefaults, this.opDummy, true);
|
||||
|
||||
Map<String, Boolean> builder = new HashMap<>();
|
||||
calculateDefaults(builder, opDummy, true);
|
||||
calculateDefaults(builder, this.opDummy, true);
|
||||
|
||||
opDefaults = ImmutableMap.copyOf(builder);
|
||||
this.opDefaults = ImmutableMap.copyOf(builder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Refreshes the non op data in this provider.
|
||||
*/
|
||||
private void refreshNonOp() {
|
||||
unregisterDefaults(nonOpDefaults, nonOpDummy, false);
|
||||
unregisterDefaults(this.nonOpDefaults, this.nonOpDummy, false);
|
||||
|
||||
Map<String, Boolean> builder = new HashMap<>();
|
||||
calculateDefaults(builder, nonOpDummy, false);
|
||||
calculateDefaults(builder, this.nonOpDummy, false);
|
||||
|
||||
nonOpDefaults = ImmutableMap.copyOf(builder);
|
||||
this.nonOpDefaults = ImmutableMap.copyOf(builder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters the dummy permissibles with Bukkit.
|
||||
*/
|
||||
public void close() {
|
||||
unregisterDefaults(opDefaults, opDummy, true);
|
||||
unregisterDefaults(nonOpDefaults, nonOpDummy, false);
|
||||
unregisterDefaults(this.opDefaults, this.opDummy, true);
|
||||
unregisterDefaults(this.nonOpDefaults, this.nonOpDummy, false);
|
||||
}
|
||||
|
||||
private static PluginManager pm() {
|
||||
|
@ -146,7 +146,7 @@ public abstract class AbstractVaultChat extends Chat {
|
||||
}
|
||||
|
||||
private String world(String world) {
|
||||
return worldMappingFunction.apply(world);
|
||||
return this.worldMappingFunction.apply(world);
|
||||
}
|
||||
|
||||
private String world(Player player) {
|
||||
@ -525,67 +525,67 @@ public abstract class AbstractVaultChat extends Chat {
|
||||
|
||||
@Override
|
||||
public boolean playerInGroup(String world, OfflinePlayer player, String group) {
|
||||
return permissionApi.playerInGroup(world, player, group);
|
||||
return this.permissionApi.playerInGroup(world, player, group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerInGroup(String world, String player, String group) {
|
||||
return permissionApi.playerInGroup(world, player, group);
|
||||
return this.permissionApi.playerInGroup(world, player, group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerInGroup(World world, String player, String group) {
|
||||
return permissionApi.playerInGroup(world, player, group);
|
||||
return this.permissionApi.playerInGroup(world, player, group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerInGroup(Player player, String group) {
|
||||
return permissionApi.playerInGroup(player, group);
|
||||
return this.permissionApi.playerInGroup(player, group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getPlayerGroups(String world, OfflinePlayer player) {
|
||||
return permissionApi.getPlayerGroups(world, player);
|
||||
return this.permissionApi.getPlayerGroups(world, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getPlayerGroups(String world, String player) {
|
||||
return permissionApi.getPlayerGroups(world, player);
|
||||
return this.permissionApi.getPlayerGroups(world, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getPlayerGroups(World world, String player) {
|
||||
return permissionApi.getPlayerGroups(world, player);
|
||||
return this.permissionApi.getPlayerGroups(world, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getPlayerGroups(Player player) {
|
||||
return permissionApi.getPlayerGroups(player);
|
||||
return this.permissionApi.getPlayerGroups(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrimaryGroup(String world, OfflinePlayer player) {
|
||||
return permissionApi.getPrimaryGroup(world, player);
|
||||
return this.permissionApi.getPrimaryGroup(world, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrimaryGroup(String world, String player) {
|
||||
return permissionApi.getPrimaryGroup(world, player);
|
||||
return this.permissionApi.getPrimaryGroup(world, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrimaryGroup(World world, String player) {
|
||||
return permissionApi.getPrimaryGroup(world, player);
|
||||
return this.permissionApi.getPrimaryGroup(world, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrimaryGroup(Player player) {
|
||||
return permissionApi.getPrimaryGroup(player);
|
||||
return this.permissionApi.getPrimaryGroup(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getGroups() {
|
||||
return permissionApi.getGroups();
|
||||
return this.permissionApi.getGroups();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ public abstract class AbstractVaultPermission extends Permission {
|
||||
}
|
||||
|
||||
private String world(String world) {
|
||||
return worldMappingFunction.apply(world);
|
||||
return this.worldMappingFunction.apply(world);
|
||||
}
|
||||
|
||||
private String world(Player player) {
|
||||
|
@ -25,7 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.bukkit.vault;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
import me.lucko.luckperms.api.ChatMetaType;
|
||||
@ -44,6 +43,7 @@ import me.lucko.luckperms.common.node.NodeFactory;
|
||||
|
||||
import net.milkbowl.vault.chat.Chat;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@ -78,18 +78,19 @@ public class VaultChatHook extends AbstractVaultChat {
|
||||
this.worldMappingFunction = world -> permissionHook.isIgnoreWorld() ? null : world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "LuckPerms";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerPrefix(String world, UUID uuid) {
|
||||
Preconditions.checkNotNull(uuid, "uuid");
|
||||
Objects.requireNonNull(uuid, "uuid");
|
||||
User user = getUser(uuid);
|
||||
if (user == null) {
|
||||
return null;
|
||||
}
|
||||
Contexts contexts = permissionHook.contextForLookup(user, world);
|
||||
Contexts contexts = this.permissionHook.contextForLookup(user, world);
|
||||
MetaCache metaData = user.getCachedData().getMetaData(contexts);
|
||||
String ret = metaData.getPrefix();
|
||||
if (log()) {
|
||||
@ -100,12 +101,12 @@ public class VaultChatHook extends AbstractVaultChat {
|
||||
|
||||
@Override
|
||||
public String getPlayerSuffix(String world, UUID uuid) {
|
||||
Preconditions.checkNotNull(uuid, "uuid");
|
||||
Objects.requireNonNull(uuid, "uuid");
|
||||
User user = getUser(uuid);
|
||||
if (user == null) {
|
||||
return null;
|
||||
}
|
||||
Contexts contexts = permissionHook.contextForLookup(user, world);
|
||||
Contexts contexts = this.permissionHook.contextForLookup(user, world);
|
||||
MetaCache metaData = user.getCachedData().getMetaData(contexts);
|
||||
String ret = metaData.getSuffix();
|
||||
if (log()) {
|
||||
@ -116,7 +117,7 @@ public class VaultChatHook extends AbstractVaultChat {
|
||||
|
||||
@Override
|
||||
public void setPlayerPrefix(String world, UUID uuid, String prefix) {
|
||||
Preconditions.checkNotNull(uuid, "uuid");
|
||||
Objects.requireNonNull(uuid, "uuid");
|
||||
User user = getUser(uuid);
|
||||
if (user == null) {
|
||||
return;
|
||||
@ -126,7 +127,7 @@ public class VaultChatHook extends AbstractVaultChat {
|
||||
|
||||
@Override
|
||||
public void setPlayerSuffix(String world, UUID uuid, String suffix) {
|
||||
Preconditions.checkNotNull(uuid, "uuid");
|
||||
Objects.requireNonNull(uuid, "uuid");
|
||||
User user = getUser(uuid);
|
||||
if (user == null) {
|
||||
return;
|
||||
@ -136,13 +137,13 @@ public class VaultChatHook extends AbstractVaultChat {
|
||||
|
||||
@Override
|
||||
public String getPlayerInfo(String world, UUID uuid, String key) {
|
||||
Preconditions.checkNotNull(uuid, "uuid");
|
||||
Preconditions.checkNotNull(key, "key");
|
||||
Objects.requireNonNull(uuid, "uuid");
|
||||
Objects.requireNonNull(key, "key");
|
||||
User user = getUser(uuid);
|
||||
if (user == null) {
|
||||
return null;
|
||||
}
|
||||
Contexts contexts = permissionHook.contextForLookup(user, world);
|
||||
Contexts contexts = this.permissionHook.contextForLookup(user, world);
|
||||
MetaCache metaData = user.getCachedData().getMetaData(contexts);
|
||||
String ret = metaData.getMeta().get(key);
|
||||
if (log()) {
|
||||
@ -153,8 +154,8 @@ public class VaultChatHook extends AbstractVaultChat {
|
||||
|
||||
@Override
|
||||
public void setPlayerInfo(String world, UUID uuid, String key, Object value) {
|
||||
Preconditions.checkNotNull(uuid, "uuid");
|
||||
Preconditions.checkNotNull(key, "key");
|
||||
Objects.requireNonNull(uuid, "uuid");
|
||||
Objects.requireNonNull(key, "key");
|
||||
User user = getUser(uuid);
|
||||
if (user == null) {
|
||||
return;
|
||||
@ -164,12 +165,12 @@ public class VaultChatHook extends AbstractVaultChat {
|
||||
|
||||
@Override
|
||||
public String getGroupsPrefix(String world, String name) {
|
||||
Preconditions.checkNotNull(name, "name");
|
||||
Objects.requireNonNull(name, "name");
|
||||
Group group = getGroup(name);
|
||||
if (group == null) {
|
||||
return null;
|
||||
}
|
||||
Contexts contexts = permissionHook.contextForLookup(null, world);
|
||||
Contexts contexts = this.permissionHook.contextForLookup(null, world);
|
||||
MetaCache metaData = group.getCachedData().getMetaData(contexts);
|
||||
String ret = metaData.getPrefix();
|
||||
if (log()) {
|
||||
@ -180,12 +181,12 @@ public class VaultChatHook extends AbstractVaultChat {
|
||||
|
||||
@Override
|
||||
public String getGroupsSuffix(String world, String name) {
|
||||
Preconditions.checkNotNull(name, "name");
|
||||
Objects.requireNonNull(name, "name");
|
||||
Group group = getGroup(name);
|
||||
if (group == null) {
|
||||
return null;
|
||||
}
|
||||
Contexts contexts = permissionHook.contextForLookup(null, world);
|
||||
Contexts contexts = this.permissionHook.contextForLookup(null, world);
|
||||
MetaCache metaData = group.getCachedData().getMetaData(contexts);
|
||||
String ret = metaData.getSuffix();
|
||||
if (log()) {
|
||||
@ -196,7 +197,7 @@ public class VaultChatHook extends AbstractVaultChat {
|
||||
|
||||
@Override
|
||||
public void setGroupsPrefix(String world, String name, String prefix) {
|
||||
Preconditions.checkNotNull(name, "name");
|
||||
Objects.requireNonNull(name, "name");
|
||||
Group group = getGroup(name);
|
||||
if (group == null) {
|
||||
return;
|
||||
@ -206,7 +207,7 @@ public class VaultChatHook extends AbstractVaultChat {
|
||||
|
||||
@Override
|
||||
public void setGroupsSuffix(String world, String name, String suffix) {
|
||||
Preconditions.checkNotNull(name, "name");
|
||||
Objects.requireNonNull(name, "name");
|
||||
Group group = getGroup(name);
|
||||
if (group == null) {
|
||||
return;
|
||||
@ -216,13 +217,13 @@ public class VaultChatHook extends AbstractVaultChat {
|
||||
|
||||
@Override
|
||||
public String getGroupInfo(String world, String name, String key) {
|
||||
Preconditions.checkNotNull(name, "name");
|
||||
Preconditions.checkNotNull(key, "key");
|
||||
Objects.requireNonNull(name, "name");
|
||||
Objects.requireNonNull(key, "key");
|
||||
Group group = getGroup(name);
|
||||
if (group == null) {
|
||||
return null;
|
||||
}
|
||||
Contexts contexts = permissionHook.contextForLookup(null, world);
|
||||
Contexts contexts = this.permissionHook.contextForLookup(null, world);
|
||||
MetaCache metaData = group.getCachedData().getMetaData(contexts);
|
||||
String ret = metaData.getMeta().get(key);
|
||||
if (log()) {
|
||||
@ -233,8 +234,8 @@ public class VaultChatHook extends AbstractVaultChat {
|
||||
|
||||
@Override
|
||||
public void setGroupInfo(String world, String name, String key, Object value) {
|
||||
Preconditions.checkNotNull(name, "name");
|
||||
Preconditions.checkNotNull(key, "key");
|
||||
Objects.requireNonNull(name, "name");
|
||||
Objects.requireNonNull(key, "key");
|
||||
Group group = getGroup(name);
|
||||
if (group == null) {
|
||||
return;
|
||||
@ -245,19 +246,19 @@ public class VaultChatHook extends AbstractVaultChat {
|
||||
// utility methods for getting user and group instances
|
||||
|
||||
private User getUser(UUID uuid) {
|
||||
return plugin.getUserManager().getIfLoaded(plugin.getUuidCache().getUUID(uuid));
|
||||
return this.plugin.getUserManager().getIfLoaded(this.plugin.getUuidCache().getUUID(uuid));
|
||||
}
|
||||
|
||||
private Group getGroup(String name) {
|
||||
return plugin.getGroupManager().getByDisplayName(name);
|
||||
return this.plugin.getGroupManager().getByDisplayName(name);
|
||||
}
|
||||
|
||||
// logging
|
||||
private boolean log() {
|
||||
return plugin.getConfiguration().get(ConfigKeys.VAULT_DEBUG);
|
||||
return this.plugin.getConfiguration().get(ConfigKeys.VAULT_DEBUG);
|
||||
}
|
||||
private void logMsg(String format, Object... args) {
|
||||
plugin.getLog().info("[VAULT-CHAT] " + String.format(format, args)
|
||||
this.plugin.getLog().info("[VAULT-CHAT] " + String.format(format, args)
|
||||
.replace(CommandManager.SECTION_CHAR, '$')
|
||||
.replace(CommandManager.AMPERSAND_CHAR, '$')
|
||||
);
|
||||
@ -268,12 +269,12 @@ public class VaultChatHook extends AbstractVaultChat {
|
||||
logMsg("#setChatMeta: %s - %s - %s - %s", holder.getFriendlyName(), type, value, world);
|
||||
}
|
||||
|
||||
permissionHook.getExecutor().execute(() -> {
|
||||
this.permissionHook.getExecutor().execute(() -> {
|
||||
// remove all prefixes/suffixes directly set on the user/group
|
||||
holder.removeIf(type::matches);
|
||||
|
||||
if (value == null) {
|
||||
permissionHook.holderSave(holder);
|
||||
this.permissionHook.holderSave(holder);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -283,11 +284,11 @@ public class VaultChatHook extends AbstractVaultChat {
|
||||
.mapToInt(e -> e).max().orElse(0) + 10;
|
||||
|
||||
Node.Builder chatMetaNode = NodeFactory.buildChatMetaNode(type, priority, value);
|
||||
chatMetaNode.setServer(permissionHook.getVaultServer());
|
||||
chatMetaNode.setServer(this.permissionHook.getVaultServer());
|
||||
chatMetaNode.setWorld(world);
|
||||
|
||||
holder.setPermission(chatMetaNode.build());
|
||||
permissionHook.holderSave(holder);
|
||||
this.permissionHook.holderSave(holder);
|
||||
});
|
||||
}
|
||||
|
||||
@ -296,11 +297,11 @@ public class VaultChatHook extends AbstractVaultChat {
|
||||
logMsg("#setMeta: %s - %s - %s - %s", holder.getFriendlyName(), key, value, world);
|
||||
}
|
||||
|
||||
permissionHook.getExecutor().execute(() -> {
|
||||
this.permissionHook.getExecutor().execute(() -> {
|
||||
holder.removeIf(n -> n.isMeta() && n.getMeta().getKey().equals(key));
|
||||
|
||||
if (value == null) {
|
||||
permissionHook.holderSave(holder);
|
||||
this.permissionHook.holderSave(holder);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -311,11 +312,11 @@ public class VaultChatHook extends AbstractVaultChat {
|
||||
metaNode = NodeFactory.buildMetaNode(key, value.toString());
|
||||
}
|
||||
|
||||
metaNode.setServer(permissionHook.getVaultServer());
|
||||
metaNode.setServer(this.permissionHook.getVaultServer());
|
||||
metaNode.setWorld(world);
|
||||
|
||||
holder.setPermission(metaNode.build());
|
||||
permissionHook.holderSave(holder);
|
||||
this.permissionHook.holderSave(holder);
|
||||
});
|
||||
}
|
||||
|
||||
@ -324,7 +325,7 @@ public class VaultChatHook extends AbstractVaultChat {
|
||||
if (world != null && !world.equals("") && !world.equalsIgnoreCase("global")) {
|
||||
context.add(Contexts.WORLD_KEY, world.toLowerCase());
|
||||
}
|
||||
context.add(Contexts.SERVER_KEY, permissionHook.getVaultServer());
|
||||
return new Contexts(context.build(), permissionHook.isIncludeGlobal(), true, true, true, true, false);
|
||||
context.add(Contexts.SERVER_KEY, this.permissionHook.getVaultServer());
|
||||
return new Contexts(context.build(), this.permissionHook.isIncludeGlobal(), true, true, true, true, false);
|
||||
}
|
||||
}
|
||||
|
@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.bukkit.vault;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
|
||||
|
||||
import net.milkbowl.vault.chat.Chat;
|
||||
@ -38,7 +36,6 @@ import org.bukkit.plugin.ServicesManager;
|
||||
/**
|
||||
* Handles hooking with the Vault API
|
||||
*/
|
||||
@Getter
|
||||
public class VaultHookManager {
|
||||
private VaultChatHook chatHook = null;
|
||||
private VaultPermissionHook permissionHook = null;
|
||||
@ -51,17 +48,17 @@ public class VaultHookManager {
|
||||
*/
|
||||
public void hook(LPBukkitPlugin plugin) {
|
||||
try {
|
||||
if (permissionHook == null) {
|
||||
permissionHook = new VaultPermissionHook(plugin);
|
||||
if (this.permissionHook == null) {
|
||||
this.permissionHook = new VaultPermissionHook(plugin);
|
||||
}
|
||||
|
||||
if (chatHook == null) {
|
||||
chatHook = new VaultChatHook(plugin, permissionHook);
|
||||
if (this.chatHook == null) {
|
||||
this.chatHook = new VaultChatHook(plugin, this.permissionHook);
|
||||
}
|
||||
|
||||
final ServicesManager sm = plugin.getServer().getServicesManager();
|
||||
sm.register(Permission.class, permissionHook, plugin, ServicePriority.High);
|
||||
sm.register(Chat.class, chatHook, plugin, ServicePriority.High);
|
||||
sm.register(Permission.class, this.permissionHook, plugin, ServicePriority.High);
|
||||
sm.register(Chat.class, this.chatHook, plugin, ServicePriority.High);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@ -76,25 +73,16 @@ public class VaultHookManager {
|
||||
public void unhook(LPBukkitPlugin plugin) {
|
||||
final ServicesManager sm = plugin.getServer().getServicesManager();
|
||||
|
||||
if (permissionHook != null) {
|
||||
sm.unregister(Permission.class, permissionHook);
|
||||
permissionHook.getExecutor().shutdown();
|
||||
permissionHook = null;
|
||||
if (this.permissionHook != null) {
|
||||
sm.unregister(Permission.class, this.permissionHook);
|
||||
this.permissionHook.getExecutor().shutdown();
|
||||
this.permissionHook = null;
|
||||
}
|
||||
|
||||
if (chatHook != null) {
|
||||
sm.unregister(Chat.class, chatHook);
|
||||
chatHook = null;
|
||||
if (this.chatHook != null) {
|
||||
sm.unregister(Chat.class, this.chatHook);
|
||||
this.chatHook = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets if the Vault classes are registered.
|
||||
*
|
||||
* @return true if hooked
|
||||
*/
|
||||
public boolean isHooked() {
|
||||
return permissionHook != null && chatHook != null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.bukkit.vault;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
@ -49,6 +47,7 @@ import net.milkbowl.vault.permission.Permission;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
@ -70,7 +69,6 @@ import java.util.concurrent.Executors;
|
||||
* We cannot risk blocking the main thread to load in their data. Again, this is due to crap Vault
|
||||
* design. There is nothing I can do about it.
|
||||
*/
|
||||
@Getter
|
||||
public class VaultPermissionHook extends AbstractVaultPermission {
|
||||
|
||||
// the plugin instance
|
||||
@ -85,6 +83,14 @@ public class VaultPermissionHook extends AbstractVaultPermission {
|
||||
this.worldMappingFunction = world -> isIgnoreWorld() ? null : world;
|
||||
}
|
||||
|
||||
public LPBukkitPlugin getPlugin() {
|
||||
return this.plugin;
|
||||
}
|
||||
|
||||
public ExecutorService getExecutor() {
|
||||
return this.executor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "LuckPerms";
|
||||
@ -104,15 +110,15 @@ public class VaultPermissionHook extends AbstractVaultPermission {
|
||||
|
||||
@Override
|
||||
public String[] getGroups() {
|
||||
return plugin.getGroupManager().getAll().values().stream()
|
||||
return this.plugin.getGroupManager().getAll().values().stream()
|
||||
.map(g -> g.getDisplayName().orElse(g.getName()))
|
||||
.toArray(String[]::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String world, UUID uuid, String permission) {
|
||||
Preconditions.checkNotNull(uuid, "uuid");
|
||||
Preconditions.checkNotNull(permission, "permission");
|
||||
Objects.requireNonNull(uuid, "uuid");
|
||||
Objects.requireNonNull(permission, "permission");
|
||||
|
||||
User user = getUser(uuid);
|
||||
if (user == null) {
|
||||
@ -131,8 +137,8 @@ public class VaultPermissionHook extends AbstractVaultPermission {
|
||||
|
||||
@Override
|
||||
public boolean playerAddPermission(String world, UUID uuid, String permission) {
|
||||
Preconditions.checkNotNull(uuid, "uuid");
|
||||
Preconditions.checkNotNull(permission, "permission");
|
||||
Objects.requireNonNull(uuid, "uuid");
|
||||
Objects.requireNonNull(permission, "permission");
|
||||
|
||||
User user = getUser(uuid);
|
||||
if (user == null) {
|
||||
@ -145,8 +151,8 @@ public class VaultPermissionHook extends AbstractVaultPermission {
|
||||
|
||||
@Override
|
||||
public boolean playerRemovePermission(String world, UUID uuid, String permission) {
|
||||
Preconditions.checkNotNull(uuid, "uuid");
|
||||
Preconditions.checkNotNull(permission, "permission");
|
||||
Objects.requireNonNull(uuid, "uuid");
|
||||
Objects.requireNonNull(permission, "permission");
|
||||
|
||||
User user = getUser(uuid);
|
||||
if (user == null) {
|
||||
@ -159,28 +165,28 @@ public class VaultPermissionHook extends AbstractVaultPermission {
|
||||
|
||||
@Override
|
||||
public boolean playerInGroup(String world, UUID uuid, String group) {
|
||||
Preconditions.checkNotNull(uuid, "uuid");
|
||||
Preconditions.checkNotNull(group, "group");
|
||||
Objects.requireNonNull(uuid, "uuid");
|
||||
Objects.requireNonNull(group, "group");
|
||||
return hasPermission(world, uuid, NodeFactory.groupNode(rewriteGroupName(group)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerAddGroup(String world, UUID uuid, String group) {
|
||||
Preconditions.checkNotNull(uuid, "uuid");
|
||||
Preconditions.checkNotNull(group, "group");
|
||||
Objects.requireNonNull(uuid, "uuid");
|
||||
Objects.requireNonNull(group, "group");
|
||||
return checkGroupExists(group) && playerAddPermission(world, uuid, NodeFactory.groupNode(rewriteGroupName(group)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerRemoveGroup(String world, UUID uuid, String group) {
|
||||
Preconditions.checkNotNull(uuid, "uuid");
|
||||
Preconditions.checkNotNull(group, "group");
|
||||
Objects.requireNonNull(uuid, "uuid");
|
||||
Objects.requireNonNull(group, "group");
|
||||
return checkGroupExists(group) && playerRemovePermission(world, uuid, NodeFactory.groupNode(rewriteGroupName(group)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] playerGetGroups(String world, UUID uuid) {
|
||||
Preconditions.checkNotNull(uuid, "uuid");
|
||||
Objects.requireNonNull(uuid, "uuid");
|
||||
|
||||
User user = getUser(uuid);
|
||||
if (user == null) {
|
||||
@ -193,7 +199,7 @@ public class VaultPermissionHook extends AbstractVaultPermission {
|
||||
.filter(Node::isGroupNode)
|
||||
.filter(n -> n.shouldApplyWithContext(contexts))
|
||||
.map(n -> {
|
||||
Group group = plugin.getGroupManager().getIfLoaded(n.getGroupName());
|
||||
Group group = this.plugin.getGroupManager().getIfLoaded(n.getGroupName());
|
||||
if (group != null) {
|
||||
return group.getDisplayName().orElse(group.getName());
|
||||
}
|
||||
@ -210,7 +216,7 @@ public class VaultPermissionHook extends AbstractVaultPermission {
|
||||
|
||||
@Override
|
||||
public String playerPrimaryGroup(String world, UUID uuid) {
|
||||
Preconditions.checkNotNull(uuid, "uuid");
|
||||
Objects.requireNonNull(uuid, "uuid");
|
||||
|
||||
User user = getUser(uuid);
|
||||
if (user == null) {
|
||||
@ -232,8 +238,8 @@ public class VaultPermissionHook extends AbstractVaultPermission {
|
||||
|
||||
@Override
|
||||
public boolean groupHasPermission(String world, String name, String permission) {
|
||||
Preconditions.checkNotNull(name, "name");
|
||||
Preconditions.checkNotNull(permission, "permission");
|
||||
Objects.requireNonNull(name, "name");
|
||||
Objects.requireNonNull(permission, "permission");
|
||||
|
||||
Group group = getGroup(name);
|
||||
if (group == null) {
|
||||
@ -252,8 +258,8 @@ public class VaultPermissionHook extends AbstractVaultPermission {
|
||||
|
||||
@Override
|
||||
public boolean groupAddPermission(String world, String name, String permission) {
|
||||
Preconditions.checkNotNull(name, "name");
|
||||
Preconditions.checkNotNull(permission, "permission");
|
||||
Objects.requireNonNull(name, "name");
|
||||
Objects.requireNonNull(permission, "permission");
|
||||
|
||||
Group group = getGroup(name);
|
||||
if (group == null) {
|
||||
@ -266,8 +272,8 @@ public class VaultPermissionHook extends AbstractVaultPermission {
|
||||
|
||||
@Override
|
||||
public boolean groupRemovePermission(String world, String name, String permission) {
|
||||
Preconditions.checkNotNull(name, "name");
|
||||
Preconditions.checkNotNull(permission, "permission");
|
||||
Objects.requireNonNull(name, "name");
|
||||
Objects.requireNonNull(permission, "permission");
|
||||
|
||||
Group group = getGroup(name);
|
||||
if (group == null) {
|
||||
@ -281,19 +287,19 @@ public class VaultPermissionHook extends AbstractVaultPermission {
|
||||
// utility methods for getting user and group instances
|
||||
|
||||
private User getUser(UUID uuid) {
|
||||
return plugin.getUserManager().getIfLoaded(plugin.getUuidCache().getUUID(uuid));
|
||||
return this.plugin.getUserManager().getIfLoaded(this.plugin.getUuidCache().getUUID(uuid));
|
||||
}
|
||||
|
||||
private Group getGroup(String name) {
|
||||
return plugin.getGroupManager().getByDisplayName(name);
|
||||
return this.plugin.getGroupManager().getByDisplayName(name);
|
||||
}
|
||||
|
||||
private boolean checkGroupExists(String group) {
|
||||
return plugin.getGroupManager().getByDisplayName(group) != null;
|
||||
return this.plugin.getGroupManager().getByDisplayName(group) != null;
|
||||
}
|
||||
|
||||
private String rewriteGroupName(String name) {
|
||||
Group group = plugin.getGroupManager().getByDisplayName(name);
|
||||
Group group = this.plugin.getGroupManager().getByDisplayName(name);
|
||||
if (group != null) {
|
||||
return group.getName();
|
||||
}
|
||||
@ -302,10 +308,10 @@ public class VaultPermissionHook extends AbstractVaultPermission {
|
||||
|
||||
// logging
|
||||
private boolean log() {
|
||||
return plugin.getConfiguration().get(ConfigKeys.VAULT_DEBUG);
|
||||
return this.plugin.getConfiguration().get(ConfigKeys.VAULT_DEBUG);
|
||||
}
|
||||
private void logMsg(String format, Object... args) {
|
||||
plugin.getLog().info("[VAULT-PERMS] " + String.format(format, args)
|
||||
this.plugin.getLog().info("[VAULT-PERMS] " + String.format(format, args)
|
||||
.replace(CommandManager.SECTION_CHAR, '$')
|
||||
.replace(CommandManager.AMPERSAND_CHAR, '$')
|
||||
);
|
||||
@ -315,11 +321,11 @@ public class VaultPermissionHook extends AbstractVaultPermission {
|
||||
Contexts contextForLookup(User user, String world) {
|
||||
MutableContextSet context;
|
||||
|
||||
Player player = user == null ? null : plugin.getPlayer(user);
|
||||
Player player = user == null ? null : this.plugin.getPlayer(user);
|
||||
if (player != null) {
|
||||
context = plugin.getContextManager().getApplicableContext(player).mutableCopy();
|
||||
context = this.plugin.getContextManager().getApplicableContext(player).mutableCopy();
|
||||
} else {
|
||||
context = plugin.getContextManager().getStaticContext().mutableCopy();
|
||||
context = this.plugin.getContextManager().getStaticContext().mutableCopy();
|
||||
}
|
||||
|
||||
// if world is null, we want to do a lookup in the players current context
|
||||
@ -348,14 +354,14 @@ public class VaultPermissionHook extends AbstractVaultPermission {
|
||||
// utility methods for modifying the state of PermissionHolders
|
||||
|
||||
private void holderAddPermission(PermissionHolder holder, String permission, String world) {
|
||||
Preconditions.checkNotNull(permission, "permission is null");
|
||||
Objects.requireNonNull(permission, "permission is null");
|
||||
Preconditions.checkArgument(!permission.isEmpty(), "permission is an empty string");
|
||||
|
||||
if (log()) {
|
||||
logMsg("#holderAddPermission: %s - %s - %s", holder.getFriendlyName(), permission, world);
|
||||
}
|
||||
|
||||
executor.execute(() -> {
|
||||
this.executor.execute(() -> {
|
||||
if (holder.setPermission(NodeFactory.make(permission, true, getVaultServer(), world)).asBoolean()) {
|
||||
holderSave(holder);
|
||||
}
|
||||
@ -363,14 +369,14 @@ public class VaultPermissionHook extends AbstractVaultPermission {
|
||||
}
|
||||
|
||||
private void holderRemovePermission(PermissionHolder holder, String permission, String world) {
|
||||
Preconditions.checkNotNull(permission, "permission is null");
|
||||
Objects.requireNonNull(permission, "permission is null");
|
||||
Preconditions.checkArgument(!permission.isEmpty(), "permission is an empty string");
|
||||
|
||||
if (log()) {
|
||||
logMsg("#holderRemovePermission: %s - %s - %s", holder.getFriendlyName(), permission, world);
|
||||
}
|
||||
|
||||
executor.execute(() -> {
|
||||
this.executor.execute(() -> {
|
||||
if (holder.unsetPermission(NodeFactory.make(permission, getVaultServer(), world)).asBoolean()) {
|
||||
holderSave(holder);
|
||||
}
|
||||
@ -380,33 +386,33 @@ public class VaultPermissionHook extends AbstractVaultPermission {
|
||||
void holderSave(PermissionHolder holder) {
|
||||
if (holder.getType().isUser()) {
|
||||
User u = (User) holder;
|
||||
plugin.getStorage().saveUser(u).thenRunAsync(() -> u.getRefreshBuffer().request(), plugin.getScheduler().async());
|
||||
this.plugin.getStorage().saveUser(u).thenRunAsync(() -> u.getRefreshBuffer().request(), this.plugin.getScheduler().async());
|
||||
}
|
||||
if (holder.getType().isGroup()) {
|
||||
Group g = (Group) holder;
|
||||
plugin.getStorage().saveGroup(g).thenRunAsync(() -> plugin.getUpdateTaskBuffer().request(), plugin.getScheduler().async());
|
||||
this.plugin.getStorage().saveGroup(g).thenRunAsync(() -> this.plugin.getUpdateTaskBuffer().request(), this.plugin.getScheduler().async());
|
||||
}
|
||||
}
|
||||
|
||||
// helper methods to just pull values from the config.
|
||||
|
||||
String getServer() {
|
||||
return plugin.getConfiguration().get(ConfigKeys.SERVER);
|
||||
return this.plugin.getConfiguration().get(ConfigKeys.SERVER);
|
||||
}
|
||||
|
||||
String getVaultServer() {
|
||||
return plugin.getConfiguration().get(ConfigKeys.VAULT_SERVER);
|
||||
return this.plugin.getConfiguration().get(ConfigKeys.VAULT_SERVER);
|
||||
}
|
||||
|
||||
boolean isIncludeGlobal() {
|
||||
return plugin.getConfiguration().get(ConfigKeys.VAULT_INCLUDING_GLOBAL);
|
||||
return this.plugin.getConfiguration().get(ConfigKeys.VAULT_INCLUDING_GLOBAL);
|
||||
}
|
||||
|
||||
boolean isIgnoreWorld() {
|
||||
return plugin.getConfiguration().get(ConfigKeys.VAULT_IGNORE_WORLD);
|
||||
return this.plugin.getConfiguration().get(ConfigKeys.VAULT_IGNORE_WORLD);
|
||||
}
|
||||
|
||||
private boolean useVaultServer() {
|
||||
return plugin.getConfiguration().get(ConfigKeys.USE_VAULT_SERVER);
|
||||
return this.plugin.getConfiguration().get(ConfigKeys.USE_VAULT_SERVER);
|
||||
}
|
||||
}
|
||||
|
@ -79,11 +79,10 @@
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- Lombok -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
<groupId>com.google.code.findbugs</groupId>
|
||||
<artifactId>jsr305</artifactId>
|
||||
<version>3.0.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- RedisBungee -->
|
||||
|
@ -53,17 +53,17 @@ public class BungeeCommandExecutor extends Command implements TabExecutor {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
Sender lpSender = plugin.getSenderFactory().wrap(sender);
|
||||
Sender lpSender = this.plugin.getSenderFactory().wrap(sender);
|
||||
List<String> arguments = CommandManager.stripQuotes(ARGUMENT_SPLITTER.splitToList(ARGUMENT_JOINER.join(args)));
|
||||
|
||||
manager.onCommand(lpSender, "lpb", arguments);
|
||||
this.manager.onCommand(lpSender, "lpb", arguments);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<String> onTabComplete(CommandSender sender, String[] args) {
|
||||
Sender lpSender = plugin.getSenderFactory().wrap(sender);
|
||||
Sender lpSender = this.plugin.getSenderFactory().wrap(sender);
|
||||
List<String> arguments = CommandManager.stripQuotes(TAB_COMPLETE_ARGUMENT_SPLITTER.splitToList(ARGUMENT_JOINER.join(args)));
|
||||
|
||||
return manager.onTabComplete(lpSender, arguments);
|
||||
return this.manager.onTabComplete(lpSender, arguments);
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ public class BungeeConfigAdapter extends AbstractConfigurationAdapter implements
|
||||
@Override
|
||||
public void reload() {
|
||||
try {
|
||||
configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file);
|
||||
this.configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(this.file);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@ -63,32 +63,32 @@ public class BungeeConfigAdapter extends AbstractConfigurationAdapter implements
|
||||
|
||||
@Override
|
||||
public boolean contains(String path) {
|
||||
return configuration.contains(path);
|
||||
return this.configuration.contains(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString(String path, String def) {
|
||||
return configuration.getString(path, def);
|
||||
return this.configuration.getString(path, def);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInt(String path, int def) {
|
||||
return configuration.getInt(path, def);
|
||||
return this.configuration.getInt(path, def);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBoolean(String path, boolean def) {
|
||||
return configuration.getBoolean(path, def);
|
||||
return this.configuration.getBoolean(path, def);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getList(String path, List<String> def) {
|
||||
return Optional.ofNullable(configuration.getStringList(path)).orElse(def);
|
||||
return Optional.ofNullable(this.configuration.getStringList(path)).orElse(def);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getObjectList(String path, List<String> def) {
|
||||
Configuration section = configuration.getSection(path);
|
||||
Configuration section = this.configuration.getSection(path);
|
||||
if (section == null) {
|
||||
return def;
|
||||
}
|
||||
@ -99,7 +99,7 @@ public class BungeeConfigAdapter extends AbstractConfigurationAdapter implements
|
||||
@Override
|
||||
public Map<String, String> getMap(String path, Map<String, String> def) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
Configuration section = configuration.getSection(path);
|
||||
Configuration section = this.configuration.getSection(path);
|
||||
if (section == null) {
|
||||
return def;
|
||||
}
|
||||
|
@ -47,17 +47,17 @@ public class BungeeSchedulerAdapter implements SchedulerAdapter {
|
||||
|
||||
@Override
|
||||
public Executor async() {
|
||||
return asyncExecutor;
|
||||
return this.asyncExecutor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Executor sync() {
|
||||
return asyncExecutor;
|
||||
return this.asyncExecutor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doAsync(Runnable runnable) {
|
||||
asyncExecutor.execute(runnable);
|
||||
this.asyncExecutor.execute(runnable);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -68,8 +68,8 @@ public class BungeeSchedulerAdapter implements SchedulerAdapter {
|
||||
@Override
|
||||
public void asyncRepeating(Runnable runnable, long intervalTicks) {
|
||||
long millis = intervalTicks * 50L; // convert from ticks to milliseconds
|
||||
ScheduledTask task = plugin.getProxy().getScheduler().schedule(plugin, runnable, millis, millis, TimeUnit.MILLISECONDS);
|
||||
tasks.add(task);
|
||||
ScheduledTask task = this.plugin.getProxy().getScheduler().schedule(this.plugin, runnable, millis, millis, TimeUnit.MILLISECONDS);
|
||||
this.tasks.add(task);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -80,7 +80,7 @@ public class BungeeSchedulerAdapter implements SchedulerAdapter {
|
||||
@Override
|
||||
public void asyncLater(Runnable runnable, long delayTicks) {
|
||||
long millis = delayTicks * 50L; // convert from ticks to milliseconds
|
||||
plugin.getProxy().getScheduler().schedule(plugin, runnable, millis, TimeUnit.MILLISECONDS);
|
||||
this.plugin.getProxy().getScheduler().schedule(this.plugin, runnable, millis, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -90,6 +90,6 @@ public class BungeeSchedulerAdapter implements SchedulerAdapter {
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
tasks.forEach(ScheduledTask::cancel);
|
||||
this.tasks.forEach(ScheduledTask::cancel);
|
||||
}
|
||||
}
|
||||
|
@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.bungee;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.platform.PlatformType;
|
||||
import me.lucko.luckperms.bungee.calculators.BungeeCalculatorFactory;
|
||||
@ -97,7 +95,6 @@ import java.util.stream.Stream;
|
||||
/**
|
||||
* LuckPerms implementation for the BungeeCord API.
|
||||
*/
|
||||
@Getter
|
||||
public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
||||
|
||||
private long startTime;
|
||||
@ -129,93 +126,93 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
||||
@Override
|
||||
public void onLoad() {
|
||||
// setup minimal functionality in order to load initial dependencies
|
||||
scheduler = new BungeeSchedulerAdapter(this);
|
||||
localeManager = new NoopLocaleManager();
|
||||
senderFactory = new BungeeSenderFactory(this);
|
||||
log = new SenderLogger(this, getConsoleSender());
|
||||
this.scheduler = new BungeeSchedulerAdapter(this);
|
||||
this.localeManager = new NoopLocaleManager();
|
||||
this.senderFactory = new BungeeSenderFactory(this);
|
||||
this.log = new SenderLogger(this, getConsoleSender());
|
||||
|
||||
dependencyManager = new DependencyManager(this);
|
||||
dependencyManager.loadDependencies(Collections.singleton(Dependency.CAFFEINE));
|
||||
this.dependencyManager = new DependencyManager(this);
|
||||
this.dependencyManager.loadDependencies(Collections.singleton(Dependency.CAFFEINE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
startTime = System.currentTimeMillis();
|
||||
this.startTime = System.currentTimeMillis();
|
||||
sendStartupBanner(getConsoleSender());
|
||||
verboseHandler = new VerboseHandler(scheduler.async(), getVersion());
|
||||
permissionVault = new PermissionVault(scheduler.async());
|
||||
logDispatcher = new LogDispatcher(this);
|
||||
this.verboseHandler = new VerboseHandler(this.scheduler.async(), getVersion());
|
||||
this.permissionVault = new PermissionVault(this.scheduler.async());
|
||||
this.logDispatcher = new LogDispatcher(this);
|
||||
|
||||
getLog().info("Loading configuration...");
|
||||
configuration = new AbstractConfiguration(this, new BungeeConfigAdapter(this, resolveConfig("config.yml")));
|
||||
configuration.loadAll();
|
||||
this.configuration = new AbstractConfiguration(this, new BungeeConfigAdapter(this, resolveConfig("config.yml")));
|
||||
this.configuration.loadAll();
|
||||
|
||||
StorageFactory storageFactory = new StorageFactory(this);
|
||||
Set<StorageType> storageTypes = storageFactory.getRequiredTypes(StorageType.H2);
|
||||
dependencyManager.loadStorageDependencies(storageTypes);
|
||||
this.dependencyManager.loadStorageDependencies(storageTypes);
|
||||
|
||||
// register events
|
||||
getProxy().getPluginManager().registerListener(this, new BungeeConnectionListener(this));
|
||||
getProxy().getPluginManager().registerListener(this, new BungeePermissionCheckListener(this));
|
||||
|
||||
if (getConfiguration().get(ConfigKeys.WATCH_FILES)) {
|
||||
fileWatcher = new FileWatcher(this);
|
||||
getScheduler().asyncRepeating(fileWatcher, 30L);
|
||||
this.fileWatcher = new FileWatcher(this);
|
||||
getScheduler().asyncRepeating(this.fileWatcher, 30L);
|
||||
}
|
||||
|
||||
// initialise datastore
|
||||
storage = storageFactory.getInstance(StorageType.H2);
|
||||
this.storage = storageFactory.getInstance(StorageType.H2);
|
||||
|
||||
// initialise messaging
|
||||
messagingService = new BungeeMessagingFactory(this).getInstance();
|
||||
this.messagingService = new BungeeMessagingFactory(this).getInstance();
|
||||
|
||||
// setup the update task buffer
|
||||
updateTaskBuffer = new UpdateTaskBuffer(this);
|
||||
this.updateTaskBuffer = new UpdateTaskBuffer(this);
|
||||
|
||||
// load locale
|
||||
localeManager = new SimpleLocaleManager();
|
||||
localeManager.tryLoad(this, new File(getDataFolder(), "lang.yml"));
|
||||
this.localeManager = new SimpleLocaleManager();
|
||||
this.localeManager.tryLoad(this, new File(getDataFolder(), "lang.yml"));
|
||||
|
||||
// register commands
|
||||
commandManager = new CommandManager(this);
|
||||
getProxy().getPluginManager().registerCommand(this, new BungeeCommandExecutor(this, commandManager));
|
||||
this.commandManager = new CommandManager(this);
|
||||
getProxy().getPluginManager().registerCommand(this, new BungeeCommandExecutor(this, this.commandManager));
|
||||
|
||||
// disable the default Bungee /perms command so it gets handled by the Bukkit plugin
|
||||
getProxy().getDisabledCommands().add("perms");
|
||||
|
||||
// load internal managers
|
||||
getLog().info("Loading internal permission managers...");
|
||||
uuidCache = new UuidCache(this);
|
||||
userManager = new GenericUserManager(this);
|
||||
groupManager = new GenericGroupManager(this);
|
||||
trackManager = new GenericTrackManager(this);
|
||||
calculatorFactory = new BungeeCalculatorFactory(this);
|
||||
cachedStateManager = new CachedStateManager();
|
||||
this.uuidCache = new UuidCache(this);
|
||||
this.userManager = new GenericUserManager(this);
|
||||
this.groupManager = new GenericGroupManager(this);
|
||||
this.trackManager = new GenericTrackManager(this);
|
||||
this.calculatorFactory = new BungeeCalculatorFactory(this);
|
||||
this.cachedStateManager = new CachedStateManager();
|
||||
|
||||
// setup context manager
|
||||
contextManager = new BungeeContextManager(this);
|
||||
contextManager.registerCalculator(new BackendServerCalculator(this));
|
||||
contextManager.registerStaticCalculator(new LuckPermsCalculator(getConfiguration()));
|
||||
this.contextManager = new BungeeContextManager(this);
|
||||
this.contextManager.registerCalculator(new BackendServerCalculator(this));
|
||||
this.contextManager.registerStaticCalculator(new LuckPermsCalculator(getConfiguration()));
|
||||
|
||||
if (getProxy().getPluginManager().getPlugin("RedisBungee") != null) {
|
||||
contextManager.registerStaticCalculator(new RedisBungeeCalculator());
|
||||
this.contextManager.registerStaticCalculator(new RedisBungeeCalculator());
|
||||
}
|
||||
|
||||
// register with the LP API
|
||||
apiProvider = new LuckPermsApiProvider(this);
|
||||
this.apiProvider = new LuckPermsApiProvider(this);
|
||||
|
||||
// setup event factory
|
||||
eventFactory = new EventFactory(this, apiProvider);
|
||||
this.eventFactory = new EventFactory(this, this.apiProvider);
|
||||
|
||||
ApiRegistrationUtil.registerProvider(apiProvider);
|
||||
ApiRegistrationUtil.registerProvider(this.apiProvider);
|
||||
|
||||
// schedule update tasks
|
||||
int mins = getConfiguration().get(ConfigKeys.SYNC_TIME);
|
||||
if (mins > 0) {
|
||||
long ticks = mins * 60 * 20;
|
||||
scheduler.asyncRepeating(() -> updateTaskBuffer.request(), ticks);
|
||||
this.scheduler.asyncRepeating(() -> this.updateTaskBuffer.request(), ticks);
|
||||
}
|
||||
scheduler.asyncLater(() -> updateTaskBuffer.request(), 40L);
|
||||
this.scheduler.asyncLater(() -> this.updateTaskBuffer.request(), 40L);
|
||||
|
||||
// run an update instantly.
|
||||
getLog().info("Performing initial data load...");
|
||||
@ -227,33 +224,33 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
||||
|
||||
|
||||
// register tasks
|
||||
scheduler.asyncRepeating(new ExpireTemporaryTask(this), 60L);
|
||||
scheduler.asyncRepeating(new CacheHousekeepingTask(this), 2400L);
|
||||
this.scheduler.asyncRepeating(new ExpireTemporaryTask(this), 60L);
|
||||
this.scheduler.asyncRepeating(new CacheHousekeepingTask(this), 2400L);
|
||||
|
||||
getLog().info("Successfully enabled. (took " + (System.currentTimeMillis() - startTime) + "ms)");
|
||||
getLog().info("Successfully enabled. (took " + (System.currentTimeMillis() - this.startTime) + "ms)");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
permissionVault.shutdown();
|
||||
verboseHandler.shutdown();
|
||||
this.permissionVault.shutdown();
|
||||
this.verboseHandler.shutdown();
|
||||
|
||||
getLog().info("Closing storage...");
|
||||
storage.shutdown();
|
||||
this.storage.shutdown();
|
||||
|
||||
if (fileWatcher != null) {
|
||||
fileWatcher.close();
|
||||
if (this.fileWatcher != null) {
|
||||
this.fileWatcher.close();
|
||||
}
|
||||
|
||||
if (messagingService != null) {
|
||||
if (this.messagingService != null) {
|
||||
getLog().info("Closing messaging service...");
|
||||
messagingService.close();
|
||||
this.messagingService.close();
|
||||
}
|
||||
|
||||
ApiRegistrationUtil.unregisterProvider();
|
||||
|
||||
getLog().info("Shutting down internal scheduler...");
|
||||
scheduler.shutdown();
|
||||
this.scheduler.shutdown();
|
||||
|
||||
getProxy().getScheduler().cancel(this);
|
||||
getProxy().getPluginManager().unregisterListeners(this);
|
||||
@ -277,11 +274,12 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
||||
|
||||
@Override
|
||||
public Optional<ExtendedMessagingService> getMessagingService() {
|
||||
return Optional.ofNullable(messagingService);
|
||||
return Optional.ofNullable(this.messagingService);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<FileWatcher> getFileWatcher() {
|
||||
return Optional.ofNullable(fileWatcher);
|
||||
return Optional.ofNullable(this.fileWatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -316,7 +314,7 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
||||
|
||||
@Override
|
||||
public ProxiedPlayer getPlayer(User user) {
|
||||
return getProxy().getPlayer(uuidCache.getExternalUUID(user.getUuid()));
|
||||
return getProxy().getPlayer(this.uuidCache.getExternalUUID(user.getUuid()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -338,7 +336,7 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
||||
if (player == null) {
|
||||
return null;
|
||||
}
|
||||
return contextManager.getApplicableContexts(player);
|
||||
return this.contextManager.getApplicableContexts(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -374,4 +372,118 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
||||
public Sender getConsoleSender() {
|
||||
return getSenderFactory().wrap(getProxy().getConsole());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getStartTime() {
|
||||
return this.startTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SchedulerAdapter getScheduler() {
|
||||
return this.scheduler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandManager getCommandManager() {
|
||||
return this.commandManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LuckPermsConfiguration getConfiguration() {
|
||||
return this.configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserManager getUserManager() {
|
||||
return this.userManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupManager getGroupManager() {
|
||||
return this.groupManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrackManager getTrackManager() {
|
||||
return this.trackManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Storage getStorage() {
|
||||
return this.storage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UuidCache getUuidCache() {
|
||||
return this.uuidCache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LuckPermsApiProvider getApiProvider() {
|
||||
return this.apiProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventFactory getEventFactory() {
|
||||
return this.eventFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Logger getLog() {
|
||||
return this.log;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocaleManager getLocaleManager() {
|
||||
return this.localeManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DependencyManager getDependencyManager() {
|
||||
return this.dependencyManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CachedStateManager getCachedStateManager() {
|
||||
return this.cachedStateManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContextManager<ProxiedPlayer> getContextManager() {
|
||||
return this.contextManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CalculatorFactory getCalculatorFactory() {
|
||||
return this.calculatorFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedRequest<Void> getUpdateTaskBuffer() {
|
||||
return this.updateTaskBuffer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VerboseHandler getVerboseHandler() {
|
||||
return this.verboseHandler;
|
||||
}
|
||||
|
||||
public BungeeSenderFactory getSenderFactory() {
|
||||
return this.senderFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionVault getPermissionVault() {
|
||||
return this.permissionVault;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LogDispatcher getLogDispatcher() {
|
||||
return this.logDispatcher;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UUID> getUniqueConnections() {
|
||||
return this.uniqueConnections;
|
||||
}
|
||||
}
|
||||
|
@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.bungee.calculators;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
@ -42,33 +40,36 @@ import me.lucko.luckperms.common.processors.WildcardProcessor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class BungeeCalculatorFactory extends AbstractCalculatorFactory {
|
||||
private final LPBungeePlugin plugin;
|
||||
|
||||
public BungeeCalculatorFactory(LPBungeePlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionCalculator build(Contexts contexts, PermissionCalculatorMetadata metadata) {
|
||||
ImmutableList.Builder<PermissionProcessor> processors = ImmutableList.builder();
|
||||
|
||||
processors.add(new MapProcessor());
|
||||
|
||||
if (plugin.getConfiguration().get(ConfigKeys.APPLYING_REGEX)) {
|
||||
if (this.plugin.getConfiguration().get(ConfigKeys.APPLYING_REGEX)) {
|
||||
processors.add(new RegexProcessor());
|
||||
}
|
||||
|
||||
if (plugin.getConfiguration().get(ConfigKeys.APPLYING_WILDCARDS)) {
|
||||
if (this.plugin.getConfiguration().get(ConfigKeys.APPLYING_WILDCARDS)) {
|
||||
processors.add(new WildcardProcessor());
|
||||
}
|
||||
|
||||
return registerCalculator(new PermissionCalculator(plugin, metadata, processors.build()));
|
||||
return registerCalculator(new PermissionCalculator(this.plugin, metadata, processors.build()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getActiveProcessors() {
|
||||
ImmutableList.Builder<String> ret = ImmutableList.builder();
|
||||
ret.add("Map");
|
||||
if (plugin.getConfiguration().get(ConfigKeys.APPLYING_REGEX)) ret.add("Regex");
|
||||
if (plugin.getConfiguration().get(ConfigKeys.APPLYING_WILDCARDS)) ret.add("Wildcards");
|
||||
if (this.plugin.getConfiguration().get(ConfigKeys.APPLYING_REGEX)) ret.add("Regex");
|
||||
if (this.plugin.getConfiguration().get(ConfigKeys.APPLYING_WILDCARDS)) ret.add("Wildcards");
|
||||
return ret.build();
|
||||
}
|
||||
}
|
||||
|
@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.bungee.contexts;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.context.ContextCalculator;
|
||||
import me.lucko.luckperms.api.context.MutableContextSet;
|
||||
@ -35,7 +33,8 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class BackendServerCalculator implements ContextCalculator<ProxiedPlayer> {
|
||||
|
||||
private static String getServer(ProxiedPlayer player) {
|
||||
@ -44,12 +43,17 @@ public class BackendServerCalculator implements ContextCalculator<ProxiedPlayer>
|
||||
|
||||
private final LuckPermsPlugin plugin;
|
||||
|
||||
public BackendServerCalculator(LuckPermsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public MutableContextSet giveApplicableContext(ProxiedPlayer subject, MutableContextSet accumulator) {
|
||||
public MutableContextSet giveApplicableContext(@Nonnull ProxiedPlayer subject, @Nonnull MutableContextSet accumulator) {
|
||||
String server = getServer(subject);
|
||||
while (server != null && !accumulator.has(Contexts.WORLD_KEY, server)) {
|
||||
accumulator.add(Contexts.WORLD_KEY, server);
|
||||
server = plugin.getConfiguration().get(ConfigKeys.WORLD_REWRITES).getOrDefault(server, server).toLowerCase();
|
||||
server = this.plugin.getConfiguration().get(ConfigKeys.WORLD_REWRITES).getOrDefault(server, server).toLowerCase();
|
||||
}
|
||||
|
||||
return accumulator;
|
||||
|
@ -42,11 +42,11 @@ public class BungeeContextManager extends AbstractContextManager<ProxiedPlayer>
|
||||
public Contexts formContexts(ProxiedPlayer subject, ImmutableContextSet contextSet) {
|
||||
return new Contexts(
|
||||
contextSet,
|
||||
plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_PERMS),
|
||||
plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS),
|
||||
this.plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_PERMS),
|
||||
this.plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS),
|
||||
true,
|
||||
plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_GROUPS),
|
||||
plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_WORLD_GROUPS),
|
||||
this.plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_GROUPS),
|
||||
this.plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_WORLD_GROUPS),
|
||||
false
|
||||
);
|
||||
}
|
||||
|
@ -31,11 +31,14 @@ import com.imaginarycode.minecraft.redisbungee.RedisBungeeAPI;
|
||||
import me.lucko.luckperms.api.context.MutableContextSet;
|
||||
import me.lucko.luckperms.api.context.StaticContextCalculator;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class RedisBungeeCalculator implements StaticContextCalculator {
|
||||
private static final String PROXY_KEY = "proxy";
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public MutableContextSet giveApplicableContext(MutableContextSet accumulator) {
|
||||
public MutableContextSet giveApplicableContext(@Nonnull MutableContextSet accumulator) {
|
||||
RedisBungeeAPI redisBungee = RedisBungee.getApi();
|
||||
if (redisBungee != null) {
|
||||
accumulator.add(PROXY_KEY, redisBungee.getServerId());
|
||||
|
@ -25,12 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.bungee.event;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
import me.lucko.luckperms.api.Tristate;
|
||||
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
@ -40,10 +34,6 @@ import net.md_5.bungee.api.plugin.Event;
|
||||
/**
|
||||
* Copy of the internal BungeeCord "PermissionCheckEvent", returning a tristate instead of a boolean.
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@ToString
|
||||
public class TristateCheckEvent extends Event {
|
||||
public static Tristate call(CommandSender sender, String permission) {
|
||||
return ProxyServer.getInstance().getPluginManager().callEvent(new TristateCheckEvent(sender, permission)).getResult();
|
||||
@ -52,11 +42,40 @@ public class TristateCheckEvent extends Event {
|
||||
private final CommandSender sender;
|
||||
private final String permission;
|
||||
|
||||
@Setter
|
||||
private Tristate result;
|
||||
|
||||
public TristateCheckEvent(CommandSender sender, String permission) {
|
||||
this(sender, permission, sender.getPermissions().contains(permission) ? Tristate.TRUE : Tristate.UNDEFINED);
|
||||
}
|
||||
|
||||
public TristateCheckEvent(CommandSender sender, String permission, Tristate result) {
|
||||
this.sender = sender;
|
||||
this.permission = permission;
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public CommandSender getSender() {
|
||||
return this.sender;
|
||||
}
|
||||
|
||||
public String getPermission() {
|
||||
return this.permission;
|
||||
}
|
||||
|
||||
public Tristate getResult() {
|
||||
return this.result;
|
||||
}
|
||||
|
||||
public void setResult(Tristate result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TristateCheckEvent(" +
|
||||
"sender=" + this.sender + ", " +
|
||||
"permission=" + this.permission + ", " +
|
||||
"result=" + this.result + ")";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.bungee.listeners;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.bungee.LPBungeePlugin;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.locale.Message;
|
||||
@ -45,10 +43,13 @@ import net.md_5.bungee.event.EventPriority;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class BungeeConnectionListener implements Listener {
|
||||
private final LPBungeePlugin plugin;
|
||||
|
||||
public BungeeConnectionListener(LPBungeePlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerLogin(LoginEvent e) {
|
||||
/* Called when the player first attempts a connection with the server.
|
||||
@ -60,16 +61,16 @@ public class BungeeConnectionListener implements Listener {
|
||||
|
||||
/* registers the plugins intent to modify this events state going forward.
|
||||
this will prevent the event from completing until we're finished handling. */
|
||||
e.registerIntent(plugin);
|
||||
e.registerIntent(this.plugin);
|
||||
|
||||
final PendingConnection c = e.getConnection();
|
||||
|
||||
if (plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) {
|
||||
plugin.getLog().info("Processing pre-login for " + c.getUniqueId() + " - " + c.getName());
|
||||
if (this.plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) {
|
||||
this.plugin.getLog().info("Processing pre-login for " + c.getUniqueId() + " - " + c.getName());
|
||||
}
|
||||
|
||||
plugin.getScheduler().doAsync(() -> {
|
||||
plugin.getUniqueConnections().add(c.getUniqueId());
|
||||
this.plugin.getScheduler().doAsync(() -> {
|
||||
this.plugin.getUniqueConnections().add(c.getUniqueId());
|
||||
|
||||
/* Actually process the login for the connection.
|
||||
We do this here to delay the login until the data is ready.
|
||||
@ -81,51 +82,51 @@ public class BungeeConnectionListener implements Listener {
|
||||
- creating a user instance in the UserManager for this connection.
|
||||
- setting up cached data. */
|
||||
try {
|
||||
User user = LoginHelper.loadUser(plugin, c.getUniqueId(), c.getName(), true);
|
||||
plugin.getEventFactory().handleUserLoginProcess(c.getUniqueId(), c.getName(), user);
|
||||
User user = LoginHelper.loadUser(this.plugin, c.getUniqueId(), c.getName(), true);
|
||||
this.plugin.getEventFactory().handleUserLoginProcess(c.getUniqueId(), c.getName(), user);
|
||||
} catch (Exception ex) {
|
||||
plugin.getLog().severe("Exception occured whilst loading data for " + c.getUniqueId() + " - " + c.getName());
|
||||
this.plugin.getLog().severe("Exception occured whilst loading data for " + c.getUniqueId() + " - " + c.getName());
|
||||
ex.printStackTrace();
|
||||
|
||||
// there was some error loading
|
||||
if (plugin.getConfiguration().get(ConfigKeys.CANCEL_FAILED_LOGINS)) {
|
||||
if (this.plugin.getConfiguration().get(ConfigKeys.CANCEL_FAILED_LOGINS)) {
|
||||
// cancel the login attempt
|
||||
e.setCancelReason(TextComponent.fromLegacyText(Message.LOADING_ERROR.asString(plugin.getLocaleManager())));
|
||||
e.setCancelReason(TextComponent.fromLegacyText(Message.LOADING_ERROR.asString(this.plugin.getLocaleManager())));
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
// finally, complete our intent to modify state, so the proxy can continue handling the connection.
|
||||
e.completeIntent(plugin);
|
||||
e.completeIntent(this.plugin);
|
||||
|
||||
// schedule a cleanup of the users data in a few seconds.
|
||||
// this should cover the eventuality that the login fails.
|
||||
plugin.getUserManager().scheduleUnload(c.getUniqueId());
|
||||
this.plugin.getUserManager().scheduleUnload(c.getUniqueId());
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerPostLogin(PostLoginEvent e) {
|
||||
final ProxiedPlayer player = e.getPlayer();
|
||||
final User user = plugin.getUserManager().getIfLoaded(plugin.getUuidCache().getUUID(e.getPlayer().getUniqueId()));
|
||||
final User user = this.plugin.getUserManager().getIfLoaded(this.plugin.getUuidCache().getUUID(e.getPlayer().getUniqueId()));
|
||||
|
||||
if (plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) {
|
||||
plugin.getLog().info("Processing post-login for " + player.getUniqueId() + " - " + player.getName());
|
||||
if (this.plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) {
|
||||
this.plugin.getLog().info("Processing post-login for " + player.getUniqueId() + " - " + player.getName());
|
||||
}
|
||||
|
||||
if (user == null) {
|
||||
if (plugin.getConfiguration().get(ConfigKeys.CANCEL_FAILED_LOGINS)) {
|
||||
if (this.plugin.getConfiguration().get(ConfigKeys.CANCEL_FAILED_LOGINS)) {
|
||||
// disconnect the user
|
||||
plugin.getLog().warn("User " + player.getUniqueId() + " - " + player.getName() + " doesn't have data pre-loaded - cancelling login.");
|
||||
e.getPlayer().disconnect(TextComponent.fromLegacyText(Message.LOADING_ERROR.asString(plugin.getLocaleManager())));
|
||||
this.plugin.getLog().warn("User " + player.getUniqueId() + " - " + player.getName() + " doesn't have data pre-loaded - cancelling login.");
|
||||
e.getPlayer().disconnect(TextComponent.fromLegacyText(Message.LOADING_ERROR.asString(this.plugin.getLocaleManager())));
|
||||
} else {
|
||||
// just send a message
|
||||
plugin.getProxy().getScheduler().schedule(plugin, () -> {
|
||||
this.plugin.getProxy().getScheduler().schedule(this.plugin, () -> {
|
||||
if (!player.isConnected()) {
|
||||
return;
|
||||
}
|
||||
|
||||
player.sendMessage(TextComponent.fromLegacyText(Message.LOADING_ERROR.asString(plugin.getLocaleManager())));
|
||||
player.sendMessage(TextComponent.fromLegacyText(Message.LOADING_ERROR.asString(this.plugin.getLocaleManager())));
|
||||
}, 1, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
@ -135,7 +136,7 @@ public class BungeeConnectionListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerQuit(PlayerDisconnectEvent e) {
|
||||
// Request that the users data is unloaded.
|
||||
plugin.getUserManager().scheduleUnload(e.getPlayer().getUniqueId());
|
||||
this.plugin.getUserManager().scheduleUnload(e.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.bungee.listeners;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.Tristate;
|
||||
import me.lucko.luckperms.bungee.LPBungeePlugin;
|
||||
@ -41,10 +39,13 @@ import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
import net.md_5.bungee.event.EventPriority;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class BungeePermissionCheckListener implements Listener {
|
||||
private final LPBungeePlugin plugin;
|
||||
|
||||
public BungeePermissionCheckListener(LPBungeePlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onPlayerPermissionCheck(PermissionCheckEvent e) {
|
||||
if (!(e.getSender() instanceof ProxiedPlayer)) {
|
||||
@ -53,15 +54,15 @@ public class BungeePermissionCheckListener implements Listener {
|
||||
|
||||
ProxiedPlayer player = ((ProxiedPlayer) e.getSender());
|
||||
|
||||
User user = plugin.getUserManager().getIfLoaded(plugin.getUuidCache().getUUID(player.getUniqueId()));
|
||||
User user = this.plugin.getUserManager().getIfLoaded(this.plugin.getUuidCache().getUUID(player.getUniqueId()));
|
||||
if (user == null) {
|
||||
e.setHasPermission(false);
|
||||
return;
|
||||
}
|
||||
|
||||
Contexts contexts = plugin.getContextManager().getApplicableContexts(player);
|
||||
Contexts contexts = this.plugin.getContextManager().getApplicableContexts(player);
|
||||
Tristate result = user.getCachedData().getPermissionData(contexts).getPermissionValue(e.getPermission(), CheckOrigin.PLATFORM_PERMISSION_CHECK);
|
||||
if (result == Tristate.UNDEFINED && plugin.getConfiguration().get(ConfigKeys.APPLY_BUNGEE_CONFIG_PERMISSIONS)) {
|
||||
if (result == Tristate.UNDEFINED && this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUNGEE_CONFIG_PERMISSIONS)) {
|
||||
return; // just use the result provided by the proxy when the event was created
|
||||
}
|
||||
|
||||
@ -76,15 +77,15 @@ public class BungeePermissionCheckListener implements Listener {
|
||||
|
||||
ProxiedPlayer player = ((ProxiedPlayer) e.getSender());
|
||||
|
||||
User user = plugin.getUserManager().getIfLoaded(plugin.getUuidCache().getUUID(player.getUniqueId()));
|
||||
User user = this.plugin.getUserManager().getIfLoaded(this.plugin.getUuidCache().getUUID(player.getUniqueId()));
|
||||
if (user == null) {
|
||||
e.setResult(Tristate.UNDEFINED);
|
||||
return;
|
||||
}
|
||||
|
||||
Contexts contexts = plugin.getContextManager().getApplicableContexts(player);
|
||||
Contexts contexts = this.plugin.getContextManager().getApplicableContexts(player);
|
||||
Tristate result = user.getCachedData().getPermissionData(contexts).getPermissionValue(e.getPermission(), CheckOrigin.PLATFORM_LOOKUP_CHECK);
|
||||
if (result == Tristate.UNDEFINED && plugin.getConfiguration().get(ConfigKeys.APPLY_BUNGEE_CONFIG_PERMISSIONS)) {
|
||||
if (result == Tristate.UNDEFINED && this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUNGEE_CONFIG_PERMISSIONS)) {
|
||||
return; // just use the result provided by the proxy when the event was created
|
||||
}
|
||||
|
||||
|
@ -51,13 +51,13 @@ public class BungeeMessagingService extends AbstractMessagingService implements
|
||||
}
|
||||
|
||||
public void init() {
|
||||
plugin.getProxy().getPluginManager().registerListener(plugin, this);
|
||||
plugin.getProxy().registerChannel(CHANNEL);
|
||||
this.plugin.getProxy().getPluginManager().registerListener(this.plugin, this);
|
||||
this.plugin.getProxy().registerChannel(CHANNEL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
plugin.getProxy().unregisterChannel(CHANNEL);
|
||||
this.plugin.getProxy().unregisterChannel(CHANNEL);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -68,7 +68,7 @@ public class BungeeMessagingService extends AbstractMessagingService implements
|
||||
|
||||
byte[] data = out.toByteArray();
|
||||
|
||||
for (ServerInfo server : plugin.getProxy().getServers().values()) {
|
||||
for (ServerInfo server : this.plugin.getProxy().getServers().values()) {
|
||||
server.sendData(CHANNEL, data, true);
|
||||
}
|
||||
}
|
||||
@ -90,7 +90,7 @@ public class BungeeMessagingService extends AbstractMessagingService implements
|
||||
|
||||
onMessage(msg, u -> {
|
||||
// Forward to other servers
|
||||
plugin.getScheduler().doAsync(() -> sendMessage(u));
|
||||
this.plugin.getScheduler().doAsync(() -> sendMessage(u));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -50,22 +50,22 @@ public class RedisBungeeMessagingService extends AbstractMessagingService implem
|
||||
|
||||
public void init() {
|
||||
this.redisBungee = RedisBungee.getApi();
|
||||
redisBungee.registerPubSubChannels(CHANNEL);
|
||||
this.redisBungee.registerPubSubChannels(CHANNEL);
|
||||
|
||||
plugin.getProxy().getPluginManager().registerListener(plugin, this);
|
||||
this.plugin.getProxy().getPluginManager().registerListener(this.plugin, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
redisBungee.unregisterPubSubChannels(CHANNEL);
|
||||
redisBungee = null;
|
||||
this.redisBungee.unregisterPubSubChannels(CHANNEL);
|
||||
this.redisBungee = null;
|
||||
|
||||
plugin.getProxy().getPluginManager().unregisterListener(this);
|
||||
this.plugin.getProxy().getPluginManager().unregisterListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void sendMessage(String message) {
|
||||
redisBungee.sendChannelMessage(CHANNEL, message);
|
||||
this.redisBungee.sendChannelMessage(CHANNEL, message);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
@ -26,7 +26,6 @@
|
||||
package me.lucko.luckperms.bungee.migration;
|
||||
|
||||
import me.lucko.luckperms.api.event.cause.CreationCause;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||
@ -57,7 +56,7 @@ public class MigrationBungeePerms extends SubCommand<Object> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) {
|
||||
ProgressLogger log = new ProgressLogger("BungeePerms");
|
||||
log.addListener(plugin.getConsoleSender());
|
||||
log.addListener(sender);
|
||||
|
@ -25,15 +25,12 @@
|
||||
|
||||
package me.lucko.luckperms.bungee.util;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import com.imaginarycode.minecraft.redisbungee.RedisBungee;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
@UtilityClass
|
||||
public class RedisBungeeUtil {
|
||||
public final class RedisBungeeUtil {
|
||||
|
||||
/**
|
||||
* Looks up a UUID from username via RedisBungee's uuid cache.
|
||||
@ -45,4 +42,6 @@ public class RedisBungeeUtil {
|
||||
return Optional.ofNullable(RedisBungee.getApi()).flatMap(a -> Optional.ofNullable(a.getUuidFromName(username, true)));
|
||||
}
|
||||
|
||||
private RedisBungeeUtil() {}
|
||||
|
||||
}
|
||||
|
@ -153,11 +153,10 @@
|
||||
<version>2.6.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Lombok -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
<groupId>com.google.code.findbugs</groupId>
|
||||
<artifactId>jsr305</artifactId>
|
||||
<version>3.0.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
@ -25,11 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.actionlog;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.JsonObject;
|
||||
@ -50,16 +45,18 @@ import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* An implementation of {@link LogEntry} and {@link LogEntry.Builder},
|
||||
* with helper methods for populating and using the entry using internal
|
||||
* LuckPerms classes.
|
||||
*/
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class ExtendedLogEntry implements LogEntry {
|
||||
|
||||
private static final Comparator<LogEntry> COMPARATOR = Comparator
|
||||
@ -88,68 +85,84 @@ public class ExtendedLogEntry implements LogEntry {
|
||||
private final String actedName;
|
||||
private final String action;
|
||||
|
||||
private ExtendedLogEntry(long timestamp, UUID actor, String actorName, Type type, UUID acted, String actedName, String action) {
|
||||
this.timestamp = timestamp;
|
||||
this.actor = actor;
|
||||
this.actorName = actorName;
|
||||
this.type = type;
|
||||
this.acted = acted;
|
||||
this.actedName = actedName;
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTimestamp() {
|
||||
return timestamp;
|
||||
return this.timestamp;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public UUID getActor() {
|
||||
return actor;
|
||||
return this.actor;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getActorName() {
|
||||
return actorName;
|
||||
return this.actorName;
|
||||
}
|
||||
|
||||
public String getActorFriendlyString() {
|
||||
if (Strings.isNullOrEmpty(actorName) || actorName.equals("null")) {
|
||||
return actor.toString();
|
||||
if (Strings.isNullOrEmpty(this.actorName) || this.actorName.equals("null")) {
|
||||
return this.actor.toString();
|
||||
}
|
||||
return actorName;
|
||||
return this.actorName;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Type getType() {
|
||||
return type;
|
||||
return this.type;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Optional<UUID> getActed() {
|
||||
return Optional.ofNullable(acted);
|
||||
return Optional.ofNullable(this.acted);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getActedName() {
|
||||
return actedName;
|
||||
return this.actedName;
|
||||
}
|
||||
|
||||
public String getActedFriendlyString() {
|
||||
if (Strings.isNullOrEmpty(actedName) || actedName.equals("null")) {
|
||||
if (acted != null) {
|
||||
return acted.toString();
|
||||
if (Strings.isNullOrEmpty(this.actedName) || this.actedName.equals("null")) {
|
||||
if (this.acted != null) {
|
||||
return this.acted.toString();
|
||||
}
|
||||
}
|
||||
return String.valueOf(actedName);
|
||||
return String.valueOf(this.actedName);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getAction() {
|
||||
return action;
|
||||
return this.action;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(LogEntry other) {
|
||||
Preconditions.checkNotNull(other, "other");
|
||||
public int compareTo(@Nonnull LogEntry other) {
|
||||
Objects.requireNonNull(other, "other");
|
||||
return COMPARATOR.compare(this, other);
|
||||
}
|
||||
|
||||
public boolean matchesSearch(String query) {
|
||||
query = Preconditions.checkNotNull(query, "query").toLowerCase();
|
||||
return actorName.toLowerCase().contains(query) ||
|
||||
actedName.toLowerCase().contains(query) ||
|
||||
action.toLowerCase().contains(query);
|
||||
query = Objects.requireNonNull(query, "query").toLowerCase();
|
||||
return this.actorName.toLowerCase().contains(query) ||
|
||||
this.actedName.toLowerCase().contains(query) ||
|
||||
this.action.toLowerCase().contains(query);
|
||||
}
|
||||
|
||||
public void submit(LuckPermsPlugin plugin, Sender sender) {
|
||||
@ -172,15 +185,15 @@ public class ExtendedLogEntry implements LogEntry {
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof LogEntry)) return false;
|
||||
final LogEntry other = (LogEntry) o;
|
||||
final LogEntry that = (LogEntry) o;
|
||||
|
||||
return this.getTimestamp() == other.getTimestamp() &&
|
||||
this.getActor().equals(other.getActor()) &&
|
||||
this.getActorName().equals(other.getActorName()) &&
|
||||
this.getType() == other.getType() &&
|
||||
this.getActed().equals(other.getActed()) &&
|
||||
this.getActedName().equals(other.getActedName()) &&
|
||||
this.getAction().equals(other.getAction());
|
||||
return this.getTimestamp() == that.getTimestamp() &&
|
||||
this.getActor().equals(that.getActor()) &&
|
||||
this.getActorName().equals(that.getActorName()) &&
|
||||
this.getType() == that.getType() &&
|
||||
this.getActed().equals(that.getActed()) &&
|
||||
this.getActedName().equals(that.getActedName()) &&
|
||||
this.getAction().equals(that.getAction());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -197,7 +210,6 @@ public class ExtendedLogEntry implements LogEntry {
|
||||
return result;
|
||||
}
|
||||
|
||||
@ToString
|
||||
public static class ExtendedLogEntryBuilder implements LogEntry.Builder {
|
||||
|
||||
private long timestamp = 0L;
|
||||
@ -208,45 +220,52 @@ public class ExtendedLogEntry implements LogEntry {
|
||||
private String actedName = null;
|
||||
private String action = null;
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ExtendedLogEntryBuilder setTimestamp(long timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ExtendedLogEntryBuilder setActor(UUID actor) {
|
||||
this.actor = Preconditions.checkNotNull(actor, "actor");
|
||||
public ExtendedLogEntryBuilder setActor(@Nonnull UUID actor) {
|
||||
this.actor = Objects.requireNonNull(actor, "actor");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ExtendedLogEntryBuilder setActorName(String actorName) {
|
||||
this.actorName = Preconditions.checkNotNull(actorName, "actorName");
|
||||
public ExtendedLogEntryBuilder setActorName(@Nonnull String actorName) {
|
||||
this.actorName = Objects.requireNonNull(actorName, "actorName");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ExtendedLogEntryBuilder setType(Type type) {
|
||||
this.type = Preconditions.checkNotNull(type, "type");
|
||||
public ExtendedLogEntryBuilder setType(@Nonnull Type type) {
|
||||
this.type = Objects.requireNonNull(type, "type");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ExtendedLogEntryBuilder setActed(UUID acted) {
|
||||
this.acted = acted; // nullable
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ExtendedLogEntryBuilder setActedName(String actedName) {
|
||||
this.actedName = Preconditions.checkNotNull(actedName, "actedName");
|
||||
public ExtendedLogEntryBuilder setActedName(@Nonnull String actedName) {
|
||||
this.actedName = Objects.requireNonNull(actedName, "actedName");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ExtendedLogEntryBuilder setAction(String action) {
|
||||
this.action = Preconditions.checkNotNull(action, "action");
|
||||
public ExtendedLogEntryBuilder setAction(@Nonnull String action) {
|
||||
this.action = Objects.requireNonNull(action, "action");
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -333,19 +352,32 @@ public class ExtendedLogEntry implements LogEntry {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ExtendedLogEntry build() {
|
||||
if (timestamp == 0L) {
|
||||
if (this.timestamp == 0L) {
|
||||
timestamp(DateUtil.unixSecondsNow());
|
||||
}
|
||||
|
||||
Preconditions.checkNotNull(actor, "actor");
|
||||
Preconditions.checkNotNull(actorName, "actorName");
|
||||
Preconditions.checkNotNull(type, "type");
|
||||
Preconditions.checkNotNull(actedName, "actedName");
|
||||
Preconditions.checkNotNull(action, "action");
|
||||
Objects.requireNonNull(this.actor, "actor");
|
||||
Objects.requireNonNull(this.actorName, "actorName");
|
||||
Objects.requireNonNull(this.type, "type");
|
||||
Objects.requireNonNull(this.actedName, "actedName");
|
||||
Objects.requireNonNull(this.action, "action");
|
||||
|
||||
return new ExtendedLogEntry(timestamp, actor, actorName, type, acted, actedName, action);
|
||||
return new ExtendedLogEntry(this.timestamp, this.actor, this.actorName, this.type, this.acted, this.actedName, this.action);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ExtendedLogEntry.ExtendedLogEntryBuilder(" +
|
||||
"timestamp=" + this.timestamp + ", " +
|
||||
"actor=" + this.actor + ", " +
|
||||
"actorName=" + this.actorName + ", " +
|
||||
"type=" + this.type + ", " +
|
||||
"acted=" + this.acted + ", " +
|
||||
"actedName=" + this.actedName + ", " +
|
||||
"action=" + this.action + ")";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.actionlog;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import com.google.common.collect.ImmutableSortedSet;
|
||||
|
||||
import me.lucko.luckperms.api.LogEntry;
|
||||
@ -77,7 +75,6 @@ public class Log {
|
||||
return (int) Math.ceil((double) size / (double) entries);
|
||||
}
|
||||
|
||||
@Getter
|
||||
private final SortedSet<ExtendedLogEntry> content;
|
||||
|
||||
public Log(SortedSet<ExtendedLogEntry> content) {
|
||||
@ -85,19 +82,19 @@ public class Log {
|
||||
}
|
||||
|
||||
public SortedSet<ExtendedLogEntry> getRecent() {
|
||||
return content;
|
||||
return this.content;
|
||||
}
|
||||
|
||||
public SortedMap<Integer, ExtendedLogEntry> getRecent(int pageNo, int entriesPerPage) {
|
||||
return getPage(content, pageNo, entriesPerPage);
|
||||
return getPage(this.content, pageNo, entriesPerPage);
|
||||
}
|
||||
|
||||
public int getRecentMaxPages(int entriesPerPage) {
|
||||
return getMaxPages(content.size(), entriesPerPage);
|
||||
return getMaxPages(this.content.size(), entriesPerPage);
|
||||
}
|
||||
|
||||
public SortedSet<ExtendedLogEntry> getRecent(UUID actor) {
|
||||
return content.stream()
|
||||
return this.content.stream()
|
||||
.filter(e -> e.getActor().equals(actor))
|
||||
.collect(Collectors.toCollection(TreeSet::new));
|
||||
}
|
||||
@ -107,13 +104,13 @@ public class Log {
|
||||
}
|
||||
|
||||
public int getRecentMaxPages(UUID actor, int entriesPerPage) {
|
||||
return getMaxPages(content.stream()
|
||||
return getMaxPages(this.content.stream()
|
||||
.filter(e -> e.getActor().equals(actor))
|
||||
.mapToInt(x -> 1).sum(), entriesPerPage);
|
||||
}
|
||||
|
||||
public SortedSet<ExtendedLogEntry> getUserHistory(UUID uuid) {
|
||||
return content.stream()
|
||||
return this.content.stream()
|
||||
.filter(e -> e.getType() == LogEntry.Type.USER)
|
||||
.filter(e -> e.getActed().isPresent())
|
||||
.filter(e -> e.getActed().get().equals(uuid))
|
||||
@ -125,7 +122,7 @@ public class Log {
|
||||
}
|
||||
|
||||
public int getUserHistoryMaxPages(UUID uuid, int entriesPerPage) {
|
||||
return getMaxPages(content.stream()
|
||||
return getMaxPages(this.content.stream()
|
||||
.filter(e -> e.getType() == LogEntry.Type.USER)
|
||||
.filter(e -> e.getActed().isPresent())
|
||||
.filter(e -> e.getActed().get().equals(uuid))
|
||||
@ -133,7 +130,7 @@ public class Log {
|
||||
}
|
||||
|
||||
public SortedSet<ExtendedLogEntry> getGroupHistory(String name) {
|
||||
return content.stream()
|
||||
return this.content.stream()
|
||||
.filter(e -> e.getType() == LogEntry.Type.GROUP)
|
||||
.filter(e -> e.getActedName().equals(name))
|
||||
.collect(Collectors.toCollection(TreeSet::new));
|
||||
@ -144,14 +141,14 @@ public class Log {
|
||||
}
|
||||
|
||||
public int getGroupHistoryMaxPages(String name, int entriesPerPage) {
|
||||
return getMaxPages(content.stream()
|
||||
return getMaxPages(this.content.stream()
|
||||
.filter(e -> e.getType() == LogEntry.Type.GROUP)
|
||||
.filter(e -> e.getActedName().equals(name))
|
||||
.mapToInt(x -> 1).sum(), entriesPerPage);
|
||||
}
|
||||
|
||||
public SortedSet<ExtendedLogEntry> getTrackHistory(String name) {
|
||||
return content.stream()
|
||||
return this.content.stream()
|
||||
.filter(e -> e.getType() == LogEntry.Type.TRACK)
|
||||
.filter(e -> e.getActedName().equals(name))
|
||||
.collect(Collectors.toCollection(TreeSet::new));
|
||||
@ -162,14 +159,14 @@ public class Log {
|
||||
}
|
||||
|
||||
public int getTrackHistoryMaxPages(String name, int entriesPerPage) {
|
||||
return getMaxPages(content.stream()
|
||||
return getMaxPages(this.content.stream()
|
||||
.filter(e -> e.getType() == LogEntry.Type.TRACK)
|
||||
.filter(e -> e.getActedName().equals(name))
|
||||
.mapToInt(x -> 1).sum(), entriesPerPage);
|
||||
}
|
||||
|
||||
public SortedSet<ExtendedLogEntry> getSearch(String query) {
|
||||
return content.stream()
|
||||
return this.content.stream()
|
||||
.filter(e -> e.matchesSearch(query))
|
||||
.collect(Collectors.toCollection(TreeSet::new));
|
||||
}
|
||||
@ -179,22 +176,26 @@ public class Log {
|
||||
}
|
||||
|
||||
public int getSearchMaxPages(String query, int entriesPerPage) {
|
||||
return getMaxPages(content.stream()
|
||||
return getMaxPages(this.content.stream()
|
||||
.filter(e -> e.matchesSearch(query))
|
||||
.mapToInt(x -> 1).sum(), entriesPerPage);
|
||||
}
|
||||
|
||||
public SortedSet<ExtendedLogEntry> getContent() {
|
||||
return this.content;
|
||||
}
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public static class Builder {
|
||||
private final SortedSet<ExtendedLogEntry> content = new TreeSet<>();
|
||||
|
||||
public Builder add(ExtendedLogEntry e) {
|
||||
content.add(e);
|
||||
this.content.add(e);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Log build() {
|
||||
return new Log(content);
|
||||
return new Log(this.content);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.actionlog;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.api.event.log.LogBroadcastEvent;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.impl.log.LogNotify;
|
||||
@ -38,16 +36,19 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class LogDispatcher {
|
||||
private final LuckPermsPlugin plugin;
|
||||
|
||||
public LogDispatcher(LuckPermsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
private void broadcast(ExtendedLogEntry entry, LogBroadcastEvent.Origin origin, Sender sender) {
|
||||
plugin.getOnlineSenders()
|
||||
this.plugin.getOnlineSenders()
|
||||
.filter(CommandPermission.LOG_NOTIFY::isAuthorized)
|
||||
.filter(s -> {
|
||||
boolean shouldCancel = LogNotify.isIgnoring(plugin, s.getUuid()) || (sender != null && s.getUuid().equals(sender.getUuid()));
|
||||
return !plugin.getEventFactory().handleLogNotify(shouldCancel, entry, origin, s);
|
||||
boolean shouldCancel = LogNotify.isIgnoring(this.plugin, s.getUuid()) || (sender != null && s.getUuid().equals(sender.getUuid()));
|
||||
return !this.plugin.getEventFactory().handleLogNotify(shouldCancel, entry, origin, s);
|
||||
})
|
||||
.forEach(s -> Message.LOG.send(s,
|
||||
entry.getActorFriendlyString(),
|
||||
@ -59,8 +60,8 @@ public class LogDispatcher {
|
||||
|
||||
public void dispatch(ExtendedLogEntry entry, Sender sender) {
|
||||
// set the event to cancelled if the sender is import
|
||||
if (!plugin.getEventFactory().handleLogPublish(sender.isImport(), entry)) {
|
||||
plugin.getStorage().logAction(entry);
|
||||
if (!this.plugin.getEventFactory().handleLogPublish(sender.isImport(), entry)) {
|
||||
this.plugin.getStorage().logAction(entry);
|
||||
}
|
||||
|
||||
// don't dispatch log entries sent by an import process
|
||||
@ -68,21 +69,21 @@ public class LogDispatcher {
|
||||
return;
|
||||
}
|
||||
|
||||
Optional<ExtendedMessagingService> messagingService = plugin.getMessagingService();
|
||||
Optional<ExtendedMessagingService> messagingService = this.plugin.getMessagingService();
|
||||
if (!sender.isImport() && messagingService.isPresent()) {
|
||||
messagingService.get().pushLog(entry);
|
||||
}
|
||||
|
||||
boolean shouldCancel = !plugin.getConfiguration().get(ConfigKeys.LOG_NOTIFY);
|
||||
if (!plugin.getEventFactory().handleLogBroadcast(shouldCancel, entry, LogBroadcastEvent.Origin.LOCAL)) {
|
||||
boolean shouldCancel = !this.plugin.getConfiguration().get(ConfigKeys.LOG_NOTIFY);
|
||||
if (!this.plugin.getEventFactory().handleLogBroadcast(shouldCancel, entry, LogBroadcastEvent.Origin.LOCAL)) {
|
||||
broadcast(entry, LogBroadcastEvent.Origin.LOCAL, sender);
|
||||
}
|
||||
}
|
||||
|
||||
public void dispatchFromApi(ExtendedLogEntry entry) {
|
||||
if (!plugin.getEventFactory().handleLogPublish(false, entry)) {
|
||||
if (!this.plugin.getEventFactory().handleLogPublish(false, entry)) {
|
||||
try {
|
||||
plugin.getStorage().logAction(entry).get();
|
||||
this.plugin.getStorage().logAction(entry).get();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -92,17 +93,17 @@ public class LogDispatcher {
|
||||
}
|
||||
|
||||
public void broadcastFromApi(ExtendedLogEntry entry) {
|
||||
plugin.getMessagingService().ifPresent(extendedMessagingService -> extendedMessagingService.pushLog(entry));
|
||||
this.plugin.getMessagingService().ifPresent(extendedMessagingService -> extendedMessagingService.pushLog(entry));
|
||||
|
||||
boolean shouldCancel = !plugin.getConfiguration().get(ConfigKeys.LOG_NOTIFY);
|
||||
if (!plugin.getEventFactory().handleLogBroadcast(shouldCancel, entry, LogBroadcastEvent.Origin.LOCAL_API)) {
|
||||
boolean shouldCancel = !this.plugin.getConfiguration().get(ConfigKeys.LOG_NOTIFY);
|
||||
if (!this.plugin.getEventFactory().handleLogBroadcast(shouldCancel, entry, LogBroadcastEvent.Origin.LOCAL_API)) {
|
||||
broadcast(entry, LogBroadcastEvent.Origin.LOCAL_API, null);
|
||||
}
|
||||
}
|
||||
|
||||
public void dispatchFromRemote(ExtendedLogEntry entry) {
|
||||
boolean shouldCancel = !plugin.getConfiguration().get(ConfigKeys.BROADCAST_RECEIVED_LOG_ENTRIES) || !plugin.getConfiguration().get(ConfigKeys.LOG_NOTIFY);
|
||||
if (!plugin.getEventFactory().handleLogBroadcast(shouldCancel, entry, LogBroadcastEvent.Origin.REMOTE)) {
|
||||
boolean shouldCancel = !this.plugin.getConfiguration().get(ConfigKeys.BROADCAST_RECEIVED_LOG_ENTRIES) || !this.plugin.getConfiguration().get(ConfigKeys.LOG_NOTIFY);
|
||||
if (!this.plugin.getEventFactory().handleLogBroadcast(shouldCancel, entry, LogBroadcastEvent.Origin.REMOTE)) {
|
||||
broadcast(entry, LogBroadcastEvent.Origin.LOCAL_API, null);
|
||||
}
|
||||
}
|
||||
|
@ -25,14 +25,11 @@
|
||||
|
||||
package me.lucko.luckperms.common.api;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import me.lucko.luckperms.common.storage.DataConstraints;
|
||||
|
||||
@UtilityClass
|
||||
public class ApiUtils {
|
||||
public final class ApiUtils {
|
||||
|
||||
public static String checkUsername(String s) {
|
||||
Preconditions.checkArgument(
|
||||
@ -50,4 +47,6 @@ public class ApiUtils {
|
||||
return s.toLowerCase();
|
||||
}
|
||||
|
||||
private ApiUtils() {}
|
||||
|
||||
}
|
||||
|
@ -25,9 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.api;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
|
||||
import me.lucko.luckperms.api.ActionLogger;
|
||||
import me.lucko.luckperms.api.LPConfiguration;
|
||||
import me.lucko.luckperms.api.LuckPermsApi;
|
||||
@ -56,12 +53,13 @@ import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* Implements the LuckPerms API using the plugin instance
|
||||
*/
|
||||
public class LuckPermsApiProvider implements LuckPermsApi {
|
||||
|
||||
@Getter(AccessLevel.NONE)
|
||||
private final LuckPermsPlugin plugin;
|
||||
|
||||
private final PlatformInfo platformInfo;
|
||||
@ -84,74 +82,86 @@ public class LuckPermsApiProvider implements LuckPermsApi {
|
||||
this.metaStackFactory = new ApiMetaStackFactory(plugin);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public PlatformInfo getPlatformInfo() {
|
||||
return platformInfo;
|
||||
return this.platformInfo;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public UserManager getUserManager() {
|
||||
return userManager;
|
||||
return this.userManager;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public GroupManager getGroupManager() {
|
||||
return groupManager;
|
||||
return this.groupManager;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public TrackManager getTrackManager() {
|
||||
return trackManager;
|
||||
return this.trackManager;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Void> runUpdateTask() {
|
||||
return plugin.getUpdateTaskBuffer().request();
|
||||
return this.plugin.getUpdateTaskBuffer().request();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public EventBus getEventBus() {
|
||||
return plugin.getEventFactory().getEventBus();
|
||||
return this.plugin.getEventFactory().getEventBus();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public LPConfiguration getConfiguration() {
|
||||
return plugin.getConfiguration().getDelegate();
|
||||
return this.plugin.getConfiguration().getDelegate();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Storage getStorage() {
|
||||
return plugin.getStorage().getDelegate();
|
||||
return this.plugin.getStorage().getDelegate();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Optional<MessagingService> getMessagingService() {
|
||||
return plugin.getMessagingService().map(Function.identity());
|
||||
return this.plugin.getMessagingService().map(Function.identity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionLogger getActionLogger() {
|
||||
return actionLogger;
|
||||
return this.actionLogger;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public UuidCache getUuidCache() {
|
||||
return plugin.getUuidCache().getDelegate();
|
||||
return this.plugin.getUuidCache().getDelegate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContextManager getContextManager() {
|
||||
return contextManager;
|
||||
return this.contextManager;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public NodeFactory getNodeFactory() {
|
||||
return ApiNodeFactory.INSTANCE;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public MetaStackFactory getMetaStackFactory() {
|
||||
return metaStackFactory;
|
||||
return this.metaStackFactory;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,9 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.api.delegates.manager;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.User;
|
||||
import me.lucko.luckperms.api.context.ContextCalculator;
|
||||
@ -37,73 +34,98 @@ import me.lucko.luckperms.api.context.StaticContextCalculator;
|
||||
import me.lucko.luckperms.common.api.delegates.model.ApiUser;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
@AllArgsConstructor
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class ApiContextManager implements ContextManager {
|
||||
private final LuckPermsPlugin plugin;
|
||||
private final me.lucko.luckperms.common.contexts.ContextManager handle;
|
||||
|
||||
public ApiContextManager(LuckPermsPlugin plugin, me.lucko.luckperms.common.contexts.ContextManager handle) {
|
||||
this.plugin = plugin;
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
private Object checkType(Object subject) {
|
||||
if (!handle.getSubjectClass().isAssignableFrom(subject.getClass())) {
|
||||
throw new IllegalStateException("Subject class " + subject.getClass() + " is not assignable from " + handle.getSubjectClass());
|
||||
if (!this.handle.getSubjectClass().isAssignableFrom(subject.getClass())) {
|
||||
throw new IllegalStateException("Subject class " + subject.getClass() + " is not assignable from " + this.handle.getSubjectClass());
|
||||
}
|
||||
return subject;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ImmutableContextSet getApplicableContext(@NonNull Object subject) {
|
||||
return handle.getApplicableContext(checkType(subject));
|
||||
public ImmutableContextSet getApplicableContext(@Nonnull Object subject) {
|
||||
Objects.requireNonNull(subject, "subject");
|
||||
return this.handle.getApplicableContext(checkType(subject));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Contexts getApplicableContexts(@NonNull Object subject) {
|
||||
return handle.getApplicableContexts(checkType(subject));
|
||||
public Contexts getApplicableContexts(@Nonnull Object subject) {
|
||||
Objects.requireNonNull(subject, "subject");
|
||||
return this.handle.getApplicableContexts(checkType(subject));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Optional<ImmutableContextSet> lookupApplicableContext(@NonNull User user) {
|
||||
return Optional.ofNullable(plugin.getContextForUser(ApiUser.cast(user))).map(c -> c.getContexts().makeImmutable());
|
||||
public Optional<ImmutableContextSet> lookupApplicableContext(@Nonnull User user) {
|
||||
Objects.requireNonNull(user, "user");
|
||||
return Optional.ofNullable(this.plugin.getContextForUser(ApiUser.cast(user))).map(c -> c.getContexts().makeImmutable());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Optional<Contexts> lookupApplicableContexts(@NonNull User user) {
|
||||
return Optional.ofNullable(plugin.getContextForUser(ApiUser.cast(user)));
|
||||
public Optional<Contexts> lookupApplicableContexts(@Nonnull User user) {
|
||||
Objects.requireNonNull(user, "user");
|
||||
return Optional.ofNullable(this.plugin.getContextForUser(ApiUser.cast(user)));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ImmutableContextSet getStaticContext() {
|
||||
return handle.getStaticContext();
|
||||
return this.handle.getStaticContext();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Contexts getStaticContexts() {
|
||||
return handle.getStaticContexts();
|
||||
return this.handle.getStaticContexts();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Contexts formContexts(@Nonnull Object subject, @Nonnull ImmutableContextSet contextSet) {
|
||||
Objects.requireNonNull(subject, "subject");
|
||||
Objects.requireNonNull(contextSet, "contextSet");
|
||||
return this.handle.formContexts(checkType(subject), contextSet);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Contexts formContexts(@Nonnull ImmutableContextSet contextSet) {
|
||||
Objects.requireNonNull(contextSet, "contextSet");
|
||||
return this.handle.formContexts(contextSet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Contexts formContexts(@NonNull Object subject, @NonNull ImmutableContextSet contextSet) {
|
||||
return handle.formContexts(checkType(subject), contextSet);
|
||||
public void registerCalculator(@Nonnull ContextCalculator<?> calculator) {
|
||||
Objects.requireNonNull(calculator, "calculator");
|
||||
this.handle.registerCalculator(calculator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Contexts formContexts(@NonNull ImmutableContextSet contextSet) {
|
||||
return handle.formContexts(contextSet);
|
||||
public void registerStaticCalculator(@Nonnull StaticContextCalculator calculator) {
|
||||
Objects.requireNonNull(calculator, "calculator");
|
||||
this.handle.registerStaticCalculator(calculator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerCalculator(@NonNull ContextCalculator<?> calculator) {
|
||||
handle.registerCalculator(calculator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerStaticCalculator(@NonNull StaticContextCalculator calculator) {
|
||||
handle.registerStaticCalculator(calculator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidateCache(@NonNull Object subject) {
|
||||
handle.invalidateCache(checkType(subject));
|
||||
public void invalidateCache(@Nonnull Object subject) {
|
||||
Objects.requireNonNull(subject, "subject");
|
||||
this.handle.invalidateCache(checkType(subject));
|
||||
}
|
||||
}
|
||||
|
@ -25,32 +25,38 @@
|
||||
|
||||
package me.lucko.luckperms.common.api.delegates.manager;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
|
||||
import me.lucko.luckperms.api.Group;
|
||||
import me.lucko.luckperms.api.manager.GroupManager;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@AllArgsConstructor
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ApiGroupManager implements GroupManager {
|
||||
private final me.lucko.luckperms.common.managers.GroupManager handle;
|
||||
|
||||
public ApiGroupManager(me.lucko.luckperms.common.managers.GroupManager handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Group getGroup(@NonNull String name) {
|
||||
me.lucko.luckperms.common.model.Group group = handle.getIfLoaded(name);
|
||||
public Group getGroup(@Nonnull String name) {
|
||||
Objects.requireNonNull(name, "name");
|
||||
me.lucko.luckperms.common.model.Group group = this.handle.getIfLoaded(name);
|
||||
return group == null ? null : group.getDelegate();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Set<Group> getLoadedGroups() {
|
||||
return handle.getAll().values().stream().map(me.lucko.luckperms.common.model.Group::getDelegate).collect(Collectors.toSet());
|
||||
return this.handle.getAll().values().stream().map(me.lucko.luckperms.common.model.Group::getDelegate).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLoaded(@NonNull String name) {
|
||||
return handle.isLoaded(name);
|
||||
public boolean isLoaded(@Nonnull String name) {
|
||||
Objects.requireNonNull(name, "name");
|
||||
return this.handle.isLoaded(name);
|
||||
}
|
||||
}
|
||||
|
@ -25,32 +25,38 @@
|
||||
|
||||
package me.lucko.luckperms.common.api.delegates.manager;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
|
||||
import me.lucko.luckperms.api.Track;
|
||||
import me.lucko.luckperms.api.manager.TrackManager;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@AllArgsConstructor
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ApiTrackManager implements TrackManager {
|
||||
private final me.lucko.luckperms.common.managers.TrackManager handle;
|
||||
|
||||
public ApiTrackManager(me.lucko.luckperms.common.managers.TrackManager handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Track getTrack(@NonNull String name) {
|
||||
me.lucko.luckperms.common.model.Track track = handle.getIfLoaded(name);
|
||||
public Track getTrack(@Nonnull String name) {
|
||||
Objects.requireNonNull(name, "name");
|
||||
me.lucko.luckperms.common.model.Track track = this.handle.getIfLoaded(name);
|
||||
return track == null ? null : track.getDelegate();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Set<Track> getLoadedTracks() {
|
||||
return handle.getAll().values().stream().map(me.lucko.luckperms.common.model.Track::getDelegate).collect(Collectors.toSet());
|
||||
return this.handle.getAll().values().stream().map(me.lucko.luckperms.common.model.Track::getDelegate).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLoaded(@NonNull String name) {
|
||||
return handle.isLoaded(name);
|
||||
public boolean isLoaded(@Nonnull String name) {
|
||||
Objects.requireNonNull(name, "name");
|
||||
return this.handle.isLoaded(name);
|
||||
}
|
||||
}
|
||||
|
@ -25,48 +25,57 @@
|
||||
|
||||
package me.lucko.luckperms.common.api.delegates.manager;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
|
||||
import me.lucko.luckperms.api.User;
|
||||
import me.lucko.luckperms.api.manager.UserManager;
|
||||
import me.lucko.luckperms.common.api.delegates.model.ApiUser;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.references.UserIdentifier;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@AllArgsConstructor
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ApiUserManager implements UserManager {
|
||||
private final LuckPermsPlugin plugin;
|
||||
private final me.lucko.luckperms.common.managers.UserManager handle;
|
||||
|
||||
public ApiUserManager(LuckPermsPlugin plugin, me.lucko.luckperms.common.managers.UserManager handle) {
|
||||
this.plugin = plugin;
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUser(@NonNull UUID uuid) {
|
||||
me.lucko.luckperms.common.model.User user = handle.getIfLoaded(uuid);
|
||||
public User getUser(@Nonnull UUID uuid) {
|
||||
Objects.requireNonNull(uuid, "uuid");
|
||||
me.lucko.luckperms.common.model.User user = this.handle.getIfLoaded(uuid);
|
||||
return user == null ? null : user.getDelegate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUser(@NonNull String name) {
|
||||
me.lucko.luckperms.common.model.User user = handle.getByUsername(name);
|
||||
public User getUser(@Nonnull String name) {
|
||||
Objects.requireNonNull(name, "name");
|
||||
me.lucko.luckperms.common.model.User user = this.handle.getByUsername(name);
|
||||
return user == null ? null : user.getDelegate();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Set<User> getLoadedUsers() {
|
||||
return handle.getAll().values().stream().map(me.lucko.luckperms.common.model.User::getDelegate).collect(Collectors.toSet());
|
||||
return this.handle.getAll().values().stream().map(me.lucko.luckperms.common.model.User::getDelegate).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLoaded(@NonNull UUID uuid) {
|
||||
return handle.isLoaded(UserIdentifier.of(uuid, null));
|
||||
public boolean isLoaded(@Nonnull UUID uuid) {
|
||||
Objects.requireNonNull(uuid, "uuid");
|
||||
return this.handle.isLoaded(UserIdentifier.of(uuid, null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanupUser(@NonNull User user) {
|
||||
handle.scheduleUnload(plugin.getUuidCache().getExternalUUID(ApiUser.cast(user).getUuid()));
|
||||
public void cleanupUser(@Nonnull User user) {
|
||||
Objects.requireNonNull(user, "user");
|
||||
this.handle.scheduleUnload(this.plugin.getUuidCache().getExternalUUID(ApiUser.cast(user).getUuid()));
|
||||
}
|
||||
}
|
||||
|
@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.api.delegates.misc;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.api.ActionLogger;
|
||||
import me.lucko.luckperms.api.Log;
|
||||
import me.lucko.luckperms.api.LogEntry;
|
||||
@ -36,32 +34,42 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ApiActionLogger implements ActionLogger {
|
||||
private final LuckPermsPlugin plugin;
|
||||
|
||||
public ApiActionLogger(LuckPermsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public LogEntry.Builder newEntryBuilder() {
|
||||
return ExtendedLogEntry.build();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Log> getLog() {
|
||||
return plugin.getStorage().noBuffer().getLog().thenApply(log -> log == null ? null : new ApiLog(log));
|
||||
return this.plugin.getStorage().noBuffer().getLog().thenApply(log -> log == null ? null : new ApiLog(log));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Void> submit(LogEntry entry) {
|
||||
return CompletableFuture.runAsync(() -> plugin.getLogDispatcher().dispatchFromApi((ExtendedLogEntry) entry), plugin.getScheduler().async());
|
||||
public CompletableFuture<Void> submit(@Nonnull LogEntry entry) {
|
||||
return CompletableFuture.runAsync(() -> this.plugin.getLogDispatcher().dispatchFromApi((ExtendedLogEntry) entry), this.plugin.getScheduler().async());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Void> submitToStorage(LogEntry entry) {
|
||||
return plugin.getStorage().noBuffer().logAction(entry);
|
||||
public CompletableFuture<Void> submitToStorage(@Nonnull LogEntry entry) {
|
||||
return this.plugin.getStorage().noBuffer().logAction(entry);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Void> broadcastAction(LogEntry entry) {
|
||||
return CompletableFuture.runAsync(() -> plugin.getLogDispatcher().broadcastFromApi((ExtendedLogEntry) entry), plugin.getScheduler().async());
|
||||
public CompletableFuture<Void> broadcastAction(@Nonnull LogEntry entry) {
|
||||
return CompletableFuture.runAsync(() -> this.plugin.getLogDispatcher().broadcastFromApi((ExtendedLogEntry) entry), this.plugin.getScheduler().async());
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,8 @@ import me.lucko.luckperms.common.utils.ImmutableCollectors;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ApiConfiguration implements LPConfiguration {
|
||||
private final LuckPermsConfiguration handle;
|
||||
private final Unsafe unsafe;
|
||||
@ -42,61 +44,66 @@ public class ApiConfiguration implements LPConfiguration {
|
||||
this.unsafe = new UnsafeImpl();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getServer() {
|
||||
return handle.get(ConfigKeys.SERVER);
|
||||
return this.handle.get(ConfigKeys.SERVER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getIncludeGlobalPerms() {
|
||||
return handle.get(ConfigKeys.INCLUDING_GLOBAL_PERMS);
|
||||
return this.handle.get(ConfigKeys.INCLUDING_GLOBAL_PERMS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getIncludeGlobalWorldPerms() {
|
||||
return handle.get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS);
|
||||
return this.handle.get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getApplyGlobalGroups() {
|
||||
return handle.get(ConfigKeys.APPLYING_GLOBAL_GROUPS);
|
||||
return this.handle.get(ConfigKeys.APPLYING_GLOBAL_GROUPS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getApplyGlobalWorldGroups() {
|
||||
return handle.get(ConfigKeys.APPLYING_GLOBAL_WORLD_GROUPS);
|
||||
return this.handle.get(ConfigKeys.APPLYING_GLOBAL_WORLD_GROUPS);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getStorageMethod() {
|
||||
return handle.get(ConfigKeys.STORAGE_METHOD);
|
||||
return this.handle.get(ConfigKeys.STORAGE_METHOD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getSplitStorage() {
|
||||
return handle.get(ConfigKeys.SPLIT_STORAGE);
|
||||
return this.handle.get(ConfigKeys.SPLIT_STORAGE);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Map<String, String> getSplitStorageOptions() {
|
||||
return handle.get(ConfigKeys.SPLIT_STORAGE_OPTIONS).entrySet().stream()
|
||||
return this.handle.get(ConfigKeys.SPLIT_STORAGE_OPTIONS).entrySet().stream()
|
||||
.collect(ImmutableCollectors.toMap(e -> e.getKey().name().toLowerCase(), Map.Entry::getValue));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Unsafe unsafe() {
|
||||
return unsafe;
|
||||
return this.unsafe;
|
||||
}
|
||||
|
||||
private final class UnsafeImpl implements Unsafe {
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Object getObject(String key) {
|
||||
ConfigKey<?> configKey = ConfigKeys.getAllKeys().get(key.toUpperCase());
|
||||
if (configKey == null) {
|
||||
throw new IllegalArgumentException("Unknown key: " + key);
|
||||
}
|
||||
return handle.get(configKey);
|
||||
return ApiConfiguration.this.handle.get(configKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,9 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.api.delegates.misc;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import me.lucko.luckperms.api.metastacking.MetaStackDefinition;
|
||||
@ -38,27 +35,38 @@ import me.lucko.luckperms.common.metastacking.StandardStackElements;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
@AllArgsConstructor
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ApiMetaStackFactory implements MetaStackFactory {
|
||||
public final LuckPermsPlugin plugin;
|
||||
|
||||
@Override
|
||||
public Optional<MetaStackElement> fromString(@NonNull String definition) {
|
||||
return StandardStackElements.parseFromString(plugin, definition);
|
||||
public ApiMetaStackFactory(LuckPermsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public List<MetaStackElement> fromStrings(@NonNull List<String> definitions) {
|
||||
public Optional<MetaStackElement> fromString(@Nonnull String definition) {
|
||||
Objects.requireNonNull(definition, "definition");
|
||||
return StandardStackElements.parseFromString(this.plugin, definition);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public List<MetaStackElement> fromStrings(@Nonnull List<String> definitions) {
|
||||
Objects.requireNonNull(definitions, "definitions");
|
||||
if (definitions.isEmpty()) {
|
||||
return ImmutableList.of();
|
||||
}
|
||||
return StandardStackElements.parseList(plugin, definitions);
|
||||
return StandardStackElements.parseList(this.plugin, definitions);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public MetaStackDefinition createDefinition(List<MetaStackElement> elements, String startSpacer, String middleSpacer, String endSpacer) {
|
||||
public MetaStackDefinition createDefinition(@Nonnull List<MetaStackElement> elements, @Nonnull String startSpacer, @Nonnull String middleSpacer, @Nonnull String endSpacer) {
|
||||
return new SimpleMetaStackDefinition(elements, startSpacer, middleSpacer, endSpacer);
|
||||
}
|
||||
}
|
||||
|
@ -25,14 +25,16 @@
|
||||
|
||||
package me.lucko.luckperms.common.api.delegates.misc;
|
||||
|
||||
import lombok.NonNull;
|
||||
|
||||
import me.lucko.luckperms.api.ChatMetaType;
|
||||
import me.lucko.luckperms.api.Group;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.common.api.delegates.model.ApiGroup;
|
||||
import me.lucko.luckperms.common.node.NodeFactory;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public final class ApiNodeFactory implements me.lucko.luckperms.api.NodeFactory {
|
||||
public static final ApiNodeFactory INSTANCE = new ApiNodeFactory();
|
||||
|
||||
@ -40,43 +42,61 @@ public final class ApiNodeFactory implements me.lucko.luckperms.api.NodeFactory
|
||||
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Node.Builder newBuilder(@NonNull String permission) {
|
||||
public Node.Builder newBuilder(@Nonnull String permission) {
|
||||
Objects.requireNonNull(permission, "permission");
|
||||
return NodeFactory.builder(permission);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Node.Builder newBuilderFromExisting(@NonNull Node other) {
|
||||
public Node.Builder newBuilderFromExisting(@Nonnull Node other) {
|
||||
Objects.requireNonNull(other, "other");
|
||||
return NodeFactory.builder(other);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Node.Builder makeGroupNode(Group group) {
|
||||
public Node.Builder makeGroupNode(@Nonnull Group group) {
|
||||
Objects.requireNonNull(group, "group");
|
||||
return NodeFactory.buildGroupNode(ApiGroup.cast(group));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Node.Builder makeGroupNode(String groupName) {
|
||||
public Node.Builder makeGroupNode(@Nonnull String groupName) {
|
||||
Objects.requireNonNull(groupName, "groupName");
|
||||
return NodeFactory.buildGroupNode(groupName);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Node.Builder makeMetaNode(@NonNull String key, @NonNull String value) {
|
||||
public Node.Builder makeMetaNode(@Nonnull String key, @Nonnull String value) {
|
||||
Objects.requireNonNull(key, "key");
|
||||
Objects.requireNonNull(value, "value");
|
||||
return NodeFactory.buildMetaNode(key, value);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Node.Builder makeChatMetaNode(@NonNull ChatMetaType type, int priority, @NonNull String value) {
|
||||
public Node.Builder makeChatMetaNode(@Nonnull ChatMetaType type, int priority, @Nonnull String value) {
|
||||
Objects.requireNonNull(type, "type");
|
||||
Objects.requireNonNull(value, "value");
|
||||
return NodeFactory.buildChatMetaNode(type, priority, value);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Node.Builder makePrefixNode(int priority, @NonNull String prefix) {
|
||||
public Node.Builder makePrefixNode(int priority, @Nonnull String prefix) {
|
||||
Objects.requireNonNull(prefix, "prefix");
|
||||
return NodeFactory.buildPrefixNode(priority, prefix);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Node.Builder makeSuffixNode(int priority, @NonNull String suffix) {
|
||||
public Node.Builder makeSuffixNode(int priority, @Nonnull String suffix) {
|
||||
Objects.requireNonNull(suffix, "suffix");
|
||||
return NodeFactory.buildSuffixNode(priority, suffix);
|
||||
}
|
||||
}
|
||||
|
@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.api.delegates.misc;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.api.platform.PlatformInfo;
|
||||
import me.lucko.luckperms.api.platform.PlatformType;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
@ -35,13 +33,19 @@ import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ApiPlatformInfo implements PlatformInfo {
|
||||
private final LuckPermsPlugin plugin;
|
||||
|
||||
public ApiPlatformInfo(LuckPermsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return plugin.getVersion();
|
||||
return this.plugin.getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -49,18 +53,20 @@ public class ApiPlatformInfo implements PlatformInfo {
|
||||
return 4.0;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public PlatformType getType() {
|
||||
return plugin.getServerType();
|
||||
return this.plugin.getServerType();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Set<UUID> getUniqueConnections() {
|
||||
return Collections.unmodifiableSet(plugin.getUniqueConnections());
|
||||
return Collections.unmodifiableSet(this.plugin.getUniqueConnections());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getStartTime() {
|
||||
return plugin.getStartTime();
|
||||
return this.plugin.getStartTime();
|
||||
}
|
||||
}
|
||||
|
@ -25,24 +25,31 @@
|
||||
|
||||
package me.lucko.luckperms.common.api.delegates.misc;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
|
||||
import me.lucko.luckperms.api.UuidCache;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
@AllArgsConstructor
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ApiUuidCache implements UuidCache {
|
||||
private final me.lucko.luckperms.common.utils.UuidCache handle;
|
||||
|
||||
@Override
|
||||
public UUID getUUID(@NonNull UUID external) {
|
||||
return handle.getUUID(external);
|
||||
public ApiUuidCache(me.lucko.luckperms.common.utils.UuidCache handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public UUID getExternalUUID(@NonNull UUID internal) {
|
||||
return handle.getExternalUUID(internal);
|
||||
public UUID getUUID(@Nonnull UUID external) {
|
||||
Objects.requireNonNull(external, "external");
|
||||
return this.handle.getUUID(external);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public UUID getExternalUUID(@Nonnull UUID internal) {
|
||||
Objects.requireNonNull(internal, "internal");
|
||||
return this.handle.getExternalUUID(internal);
|
||||
}
|
||||
}
|
||||
|
@ -25,55 +25,63 @@
|
||||
|
||||
package me.lucko.luckperms.common.api.delegates.model;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import me.lucko.luckperms.api.Group;
|
||||
import me.lucko.luckperms.api.caching.GroupData;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public final class ApiGroup extends ApiPermissionHolder implements Group {
|
||||
public static me.lucko.luckperms.common.model.Group cast(Group g) {
|
||||
Preconditions.checkState(g instanceof ApiGroup, "Illegal instance " + g.getClass() + " cannot be handled by this implementation.");
|
||||
return ((ApiGroup) g).getHandle();
|
||||
public static me.lucko.luckperms.common.model.Group cast(Group group) {
|
||||
Objects.requireNonNull(group, "group");
|
||||
Preconditions.checkState(group instanceof ApiGroup, "Illegal instance " + group.getClass() + " cannot be handled by this implementation.");
|
||||
return ((ApiGroup) group).getHandle();
|
||||
}
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private final me.lucko.luckperms.common.model.Group handle;
|
||||
|
||||
public ApiGroup(@NonNull me.lucko.luckperms.common.model.Group handle) {
|
||||
public ApiGroup(me.lucko.luckperms.common.model.Group handle) {
|
||||
super(handle);
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return handle.getName();
|
||||
me.lucko.luckperms.common.model.Group getHandle() {
|
||||
return this.handle;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.handle.getName();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public OptionalInt getWeight() {
|
||||
return handle.getWeight();
|
||||
return this.handle.getWeight();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public GroupData getCachedData() {
|
||||
return this.handle.getCachedData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupData getCachedData() {
|
||||
return handle.getCachedData();
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof ApiGroup)) return false;
|
||||
|
||||
ApiGroup other = (ApiGroup) o;
|
||||
return handle.equals(other.handle);
|
||||
ApiGroup that = (ApiGroup) o;
|
||||
return this.handle.equals(that.handle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return handle.hashCode();
|
||||
return this.handle.hashCode();
|
||||
}
|
||||
}
|
||||
|
@ -25,116 +25,147 @@
|
||||
|
||||
package me.lucko.luckperms.common.api.delegates.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
|
||||
import me.lucko.luckperms.api.Log;
|
||||
import me.lucko.luckperms.api.LogEntry;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.SortedMap;
|
||||
import java.util.SortedSet;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import static me.lucko.luckperms.common.api.ApiUtils.checkName;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@AllArgsConstructor
|
||||
public class ApiLog implements Log {
|
||||
private static final int ENTRIES_PER_PAGE = 5;
|
||||
private final me.lucko.luckperms.common.actionlog.Log handle;
|
||||
|
||||
public ApiLog(me.lucko.luckperms.common.actionlog.Log handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public SortedSet<LogEntry> getContent() {
|
||||
return (SortedSet) handle.getContent();
|
||||
return (SortedSet) this.handle.getContent();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public SortedSet<LogEntry> getRecent() {
|
||||
return (SortedSet) handle.getRecent();
|
||||
return (SortedSet) this.handle.getRecent();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public SortedMap<Integer, LogEntry> getRecent(int pageNo) {
|
||||
return (SortedMap) handle.getRecent(pageNo, ENTRIES_PER_PAGE);
|
||||
return (SortedMap) this.handle.getRecent(pageNo, ENTRIES_PER_PAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRecentMaxPages() {
|
||||
return handle.getRecentMaxPages(ENTRIES_PER_PAGE);
|
||||
return this.handle.getRecentMaxPages(ENTRIES_PER_PAGE);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public SortedSet<LogEntry> getRecent(@Nonnull UUID actor) {
|
||||
Objects.requireNonNull(actor, "actor");
|
||||
return (SortedSet) this.handle.getRecent(actor);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public SortedMap<Integer, LogEntry> getRecent(int pageNo, @Nonnull UUID actor) {
|
||||
Objects.requireNonNull(actor, "actor");
|
||||
return (SortedMap) this.handle.getRecent(pageNo, actor, ENTRIES_PER_PAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedSet<LogEntry> getRecent(@NonNull UUID actor) {
|
||||
return (SortedSet) handle.getRecent(actor);
|
||||
public int getRecentMaxPages(@Nonnull UUID actor) {
|
||||
Objects.requireNonNull(actor, "actor");
|
||||
return this.handle.getRecentMaxPages(actor, ENTRIES_PER_PAGE);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public SortedSet<LogEntry> getUserHistory(@Nonnull UUID uuid) {
|
||||
Objects.requireNonNull(uuid, "uuid");
|
||||
return (SortedSet) this.handle.getUserHistory(uuid);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public SortedMap<Integer, LogEntry> getUserHistory(int pageNo, @Nonnull UUID uuid) {
|
||||
Objects.requireNonNull(uuid, "uuid");
|
||||
return (SortedMap) this.handle.getUserHistory(pageNo, uuid, ENTRIES_PER_PAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedMap<Integer, LogEntry> getRecent(int pageNo, @NonNull UUID actor) {
|
||||
return (SortedMap) handle.getRecent(pageNo, actor, ENTRIES_PER_PAGE);
|
||||
public int getUserHistoryMaxPages(@Nonnull UUID uuid) {
|
||||
Objects.requireNonNull(uuid, "uuid");
|
||||
return this.handle.getUserHistoryMaxPages(uuid, ENTRIES_PER_PAGE);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public SortedSet<LogEntry> getGroupHistory(@Nonnull String name) {
|
||||
Objects.requireNonNull(name, "name");
|
||||
return (SortedSet) this.handle.getGroupHistory(checkName(name));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public SortedMap<Integer, LogEntry> getGroupHistory(int pageNo, @Nonnull String name) {
|
||||
Objects.requireNonNull(name, "name");
|
||||
return (SortedMap) this.handle.getGroupHistory(pageNo, checkName(name), ENTRIES_PER_PAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRecentMaxPages(@NonNull UUID actor) {
|
||||
return handle.getRecentMaxPages(actor, ENTRIES_PER_PAGE);
|
||||
public int getGroupHistoryMaxPages(@Nonnull String name) {
|
||||
Objects.requireNonNull(name, "name");
|
||||
return this.handle.getGroupHistoryMaxPages(checkName(name), ENTRIES_PER_PAGE);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public SortedSet<LogEntry> getTrackHistory(@Nonnull String name) {
|
||||
Objects.requireNonNull(name, "name");
|
||||
return (SortedSet) this.handle.getTrackHistory(checkName(name));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public SortedMap<Integer, LogEntry> getTrackHistory(int pageNo, @Nonnull String name) {
|
||||
Objects.requireNonNull(name, "name");
|
||||
return (SortedMap) this.handle.getTrackHistory(pageNo, checkName(name), ENTRIES_PER_PAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedSet<LogEntry> getUserHistory(@NonNull UUID uuid) {
|
||||
return (SortedSet) handle.getUserHistory(uuid);
|
||||
public int getTrackHistoryMaxPages(@Nonnull String name) {
|
||||
Objects.requireNonNull(name, "name");
|
||||
return this.handle.getTrackHistoryMaxPages(checkName(name), ENTRIES_PER_PAGE);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public SortedSet<LogEntry> getSearch(@Nonnull String query) {
|
||||
Objects.requireNonNull(query, "query");
|
||||
return (SortedSet) this.handle.getSearch(query);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public SortedMap<Integer, LogEntry> getSearch(int pageNo, @Nonnull String query) {
|
||||
Objects.requireNonNull(query, "query");
|
||||
return (SortedMap) this.handle.getSearch(pageNo, query, ENTRIES_PER_PAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedMap<Integer, LogEntry> getUserHistory(int pageNo, @NonNull UUID uuid) {
|
||||
return (SortedMap) handle.getUserHistory(pageNo, uuid, ENTRIES_PER_PAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUserHistoryMaxPages(@NonNull UUID uuid) {
|
||||
return handle.getUserHistoryMaxPages(uuid, ENTRIES_PER_PAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedSet<LogEntry> getGroupHistory(@NonNull String name) {
|
||||
return (SortedSet) handle.getGroupHistory(checkName(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedMap<Integer, LogEntry> getGroupHistory(int pageNo, @NonNull String name) {
|
||||
return (SortedMap) handle.getGroupHistory(pageNo, checkName(name), ENTRIES_PER_PAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGroupHistoryMaxPages(@NonNull String name) {
|
||||
return handle.getGroupHistoryMaxPages(checkName(name), ENTRIES_PER_PAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedSet<LogEntry> getTrackHistory(@NonNull String name) {
|
||||
return (SortedSet) handle.getTrackHistory(checkName(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedMap<Integer, LogEntry> getTrackHistory(int pageNo, @NonNull String name) {
|
||||
return (SortedMap) handle.getTrackHistory(pageNo, checkName(name), ENTRIES_PER_PAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTrackHistoryMaxPages(@NonNull String name) {
|
||||
return handle.getTrackHistoryMaxPages(checkName(name), ENTRIES_PER_PAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedSet<LogEntry> getSearch(@NonNull String query) {
|
||||
return (SortedSet) handle.getSearch(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedMap<Integer, LogEntry> getSearch(int pageNo, @NonNull String query) {
|
||||
return (SortedMap) handle.getSearch(pageNo, query, ENTRIES_PER_PAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSearchMaxPages(@NonNull String query) {
|
||||
return handle.getSearchMaxPages(query, ENTRIES_PER_PAGE);
|
||||
public int getSearchMaxPages(@Nonnull String query) {
|
||||
Objects.requireNonNull(query, "query");
|
||||
return this.handle.getSearchMaxPages(query, ENTRIES_PER_PAGE);
|
||||
}
|
||||
}
|
||||
|
@ -25,9 +25,8 @@
|
||||
|
||||
package me.lucko.luckperms.common.api.delegates.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSetMultimap;
|
||||
import com.google.common.collect.ImmutableSortedSet;
|
||||
@ -44,212 +43,263 @@ import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.common.model.Group;
|
||||
import me.lucko.luckperms.common.model.User;
|
||||
import me.lucko.luckperms.common.node.MetaType;
|
||||
import me.lucko.luckperms.common.utils.ImmutableCollectors;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@AllArgsConstructor
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ApiPermissionHolder implements PermissionHolder {
|
||||
private final me.lucko.luckperms.common.model.PermissionHolder handle;
|
||||
|
||||
@Override
|
||||
public String getObjectName() {
|
||||
return handle.getObjectName();
|
||||
public ApiPermissionHolder(me.lucko.luckperms.common.model.PermissionHolder handle) {
|
||||
this.handle = Objects.requireNonNull(handle, "handle");
|
||||
}
|
||||
|
||||
me.lucko.luckperms.common.model.PermissionHolder getHandle() {
|
||||
return this.handle;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getObjectName() {
|
||||
return this.handle.getObjectName();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getFriendlyName() {
|
||||
if (handle.getType().isGroup()) {
|
||||
if (this.handle.getType().isGroup()) {
|
||||
Group group = (Group) this.handle;
|
||||
return group.getDisplayName().orElse(group.getName());
|
||||
}
|
||||
return handle.getFriendlyName();
|
||||
return this.handle.getFriendlyName();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CachedData getCachedData() {
|
||||
return handle.getCachedData();
|
||||
return this.handle.getCachedData();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Void> refreshCachedData() {
|
||||
return handle.getRefreshBuffer().request();
|
||||
return this.handle.getRefreshBuffer().request();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ImmutableSetMultimap<ImmutableContextSet, Node> getNodes() {
|
||||
return handle.getEnduringNodes();
|
||||
return this.handle.getEnduringNodes();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ImmutableSetMultimap<ImmutableContextSet, Node> getTransientNodes() {
|
||||
return handle.getTransientNodes();
|
||||
return this.handle.getTransientNodes();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public List<Node> getOwnNodes() {
|
||||
return handle.getOwnNodes();
|
||||
return ImmutableList.copyOf(this.handle.getOwnNodes());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public SortedSet<? extends Node> getPermissions() {
|
||||
return ImmutableSortedSet.copyOfSorted(handle.getOwnNodesSorted());
|
||||
return ImmutableSortedSet.copyOfSorted(this.handle.getOwnNodesSorted());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Set<Node> getEnduringPermissions() {
|
||||
return ImmutableSet.copyOf(handle.getEnduringNodes().values());
|
||||
return ImmutableSet.copyOf(this.handle.getEnduringNodes().values());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Set<Node> getTransientPermissions() {
|
||||
return ImmutableSet.copyOf(handle.getTransientNodes().values());
|
||||
return ImmutableSet.copyOf(this.handle.getTransientNodes().values());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public SortedSet<LocalizedNode> getAllNodes(@NonNull Contexts contexts) {
|
||||
return new TreeSet<>(handle.resolveInheritancesAlmostEqual(contexts));
|
||||
public SortedSet<LocalizedNode> getAllNodes(@Nonnull Contexts contexts) {
|
||||
Objects.requireNonNull(contexts, "contexts");
|
||||
return ImmutableSortedSet.copyOfSorted(this.handle.resolveInheritancesAlmostEqual(contexts));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public SortedSet<LocalizedNode> getAllNodes() {
|
||||
return new TreeSet<>(handle.resolveInheritancesAlmostEqual());
|
||||
return ImmutableSortedSet.copyOfSorted(this.handle.resolveInheritancesAlmostEqual());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Set<LocalizedNode> getAllNodesFiltered(@Nonnull Contexts contexts) {
|
||||
Objects.requireNonNull(contexts, "contexts");
|
||||
return ImmutableSet.copyOf(this.handle.getAllNodes(contexts));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Map<String, Boolean> exportNodes(@Nonnull Contexts contexts, boolean lowerCase) {
|
||||
Objects.requireNonNull(contexts, "contexts");
|
||||
return ImmutableMap.copyOf(this.handle.exportNodesAndShorthand(contexts, lowerCase));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Tristate hasPermission(@Nonnull Node node) {
|
||||
Objects.requireNonNull(node, "node");
|
||||
return this.handle.hasPermission(node, false);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Tristate hasTransientPermission(@Nonnull Node node) {
|
||||
Objects.requireNonNull(node, "node");
|
||||
return this.handle.hasPermission(node, true);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Tristate inheritsPermission(@Nonnull Node node) {
|
||||
Objects.requireNonNull(node, "node");
|
||||
return this.handle.inheritsPermission(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<LocalizedNode> getAllNodesFiltered(@NonNull Contexts contexts) {
|
||||
return new HashSet<>(handle.getAllNodes(contexts));
|
||||
public boolean inheritsGroup(@Nonnull me.lucko.luckperms.api.Group group) {
|
||||
Objects.requireNonNull(group, "group");
|
||||
return this.handle.inheritsGroup(ApiGroup.cast(group));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Boolean> exportNodes(Contexts contexts, boolean lowerCase) {
|
||||
return new HashMap<>(handle.exportNodesAndShorthand(contexts, lowerCase));
|
||||
public boolean inheritsGroup(@Nonnull me.lucko.luckperms.api.Group group, @Nonnull ContextSet contextSet) {
|
||||
Objects.requireNonNull(group, "group");
|
||||
Objects.requireNonNull(contextSet, "contextSet");
|
||||
return this.handle.inheritsGroup(ApiGroup.cast(group), contextSet);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public DataMutateResult setPermission(@Nonnull Node node) {
|
||||
Objects.requireNonNull(node, "node");
|
||||
return this.handle.setPermission(node);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public DataMutateResult setTransientPermission(@Nonnull Node node) {
|
||||
Objects.requireNonNull(node, "node");
|
||||
return this.handle.setTransientPermission(node);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public DataMutateResult unsetPermission(@Nonnull Node node) {
|
||||
Objects.requireNonNull(node, "node");
|
||||
return this.handle.unsetPermission(node);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public DataMutateResult unsetTransientPermission(@Nonnull Node node) {
|
||||
Objects.requireNonNull(node, "node");
|
||||
return this.handle.unsetTransientPermission(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tristate hasPermission(@NonNull Node node) {
|
||||
return handle.hasPermission(node, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tristate hasTransientPermission(@NonNull Node node) {
|
||||
return handle.hasPermission(node, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tristate inheritsPermission(@NonNull Node node) {
|
||||
return handle.inheritsPermission(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inheritsGroup(@NonNull me.lucko.luckperms.api.Group group) {
|
||||
return handle.inheritsGroup(ApiGroup.cast(group));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inheritsGroup(@NonNull me.lucko.luckperms.api.Group group, @NonNull ContextSet contextSet) {
|
||||
return handle.inheritsGroup(ApiGroup.cast(group), contextSet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataMutateResult setPermission(@NonNull Node node) {
|
||||
return handle.setPermission(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataMutateResult setTransientPermission(@NonNull Node node) {
|
||||
return handle.setTransientPermission(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataMutateResult unsetPermission(@NonNull Node node) {
|
||||
return handle.unsetPermission(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataMutateResult unsetTransientPermission(@NonNull Node node) {
|
||||
return handle.unsetTransientPermission(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearMatching(@NonNull Predicate<Node> test) {
|
||||
handle.removeIf(test);
|
||||
if (handle.getType().isUser()) {
|
||||
handle.getPlugin().getUserManager().giveDefaultIfNeeded((User) handle, false);
|
||||
public void clearMatching(@Nonnull Predicate<Node> test) {
|
||||
Objects.requireNonNull(test, "test");
|
||||
this.handle.removeIf(test);
|
||||
if (this.handle.getType().isUser()) {
|
||||
this.handle.getPlugin().getUserManager().giveDefaultIfNeeded((User) this.handle, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearMatchingTransient(@NonNull Predicate<Node> test) {
|
||||
handle.removeIfTransient(test);
|
||||
public void clearMatchingTransient(@Nonnull Predicate<Node> test) {
|
||||
Objects.requireNonNull(test, "test");
|
||||
this.handle.removeIfTransient(test);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearNodes() {
|
||||
handle.clearNodes();
|
||||
this.handle.clearNodes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearNodes(@NonNull ContextSet contextSet) {
|
||||
handle.clearNodes(contextSet);
|
||||
public void clearNodes(@Nonnull ContextSet contextSet) {
|
||||
Objects.requireNonNull(contextSet, "contextSet");
|
||||
this.handle.clearNodes(contextSet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearParents() {
|
||||
handle.clearParents(true);
|
||||
this.handle.clearParents(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearParents(@NonNull ContextSet contextSet) {
|
||||
handle.clearParents(contextSet, true);
|
||||
public void clearParents(@Nonnull ContextSet contextSet) {
|
||||
Objects.requireNonNull(contextSet, "contextSet");
|
||||
this.handle.clearParents(contextSet, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearMeta() {
|
||||
handle.clearMeta(MetaType.ANY);
|
||||
this.handle.clearMeta(MetaType.ANY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearMeta(@NonNull ContextSet contextSet) {
|
||||
handle.clearMeta(MetaType.ANY, contextSet);
|
||||
public void clearMeta(@Nonnull ContextSet contextSet) {
|
||||
Objects.requireNonNull(contextSet, "contextSet");
|
||||
this.handle.clearMeta(MetaType.ANY, contextSet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearTransientNodes() {
|
||||
handle.clearTransientNodes();
|
||||
this.handle.clearTransientNodes();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public List<LocalizedNode> resolveInheritances(Contexts contexts) {
|
||||
return handle.resolveInheritances(contexts);
|
||||
Objects.requireNonNull(contexts, "contexts");
|
||||
return ImmutableList.copyOf(this.handle.resolveInheritances(contexts));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public List<LocalizedNode> resolveInheritances() {
|
||||
return handle.resolveInheritances();
|
||||
return ImmutableList.copyOf(this.handle.resolveInheritances());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Set<Node> getPermanentPermissionNodes() {
|
||||
return handle.getOwnNodes().stream().filter(Node::isPermanent).collect(Collectors.toSet());
|
||||
return this.handle.getOwnNodes().stream().filter(Node::isPermanent).collect(ImmutableCollectors.toSet());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Set<Node> getTemporaryPermissionNodes() {
|
||||
return handle.getOwnNodes().stream().filter(Node::isPrefix).collect(Collectors.toSet());
|
||||
return this.handle.getOwnNodes().stream().filter(Node::isPrefix).collect(ImmutableCollectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void auditTemporaryPermissions() {
|
||||
handle.auditTemporaryPermissions();
|
||||
this.handle.auditTemporaryPermissions();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,9 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.api.delegates.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
|
||||
import me.lucko.luckperms.api.Group;
|
||||
import me.lucko.luckperms.api.HeldPermission;
|
||||
import me.lucko.luckperms.api.Log;
|
||||
@ -48,17 +45,24 @@ import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import static me.lucko.luckperms.common.api.ApiUtils.checkName;
|
||||
import static me.lucko.luckperms.common.api.ApiUtils.checkUsername;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class ApiStorage implements Storage {
|
||||
private final LuckPermsPlugin plugin;
|
||||
private final me.lucko.luckperms.common.storage.Storage handle;
|
||||
|
||||
public ApiStorage(LuckPermsPlugin plugin, me.lucko.luckperms.common.storage.Storage handle) {
|
||||
this.plugin = plugin;
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getName() {
|
||||
return handle.getName();
|
||||
return this.handle.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -66,116 +70,155 @@ public class ApiStorage implements Storage {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Executor getSyncExecutor() {
|
||||
return plugin.getScheduler().sync();
|
||||
return this.plugin.getScheduler().sync();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Executor getAsyncExecutor() {
|
||||
return plugin.getScheduler().async();
|
||||
return this.plugin.getScheduler().async();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Boolean> logAction(@NonNull LogEntry entry) {
|
||||
return handle.noBuffer().logAction(entry).thenApply(x -> true);
|
||||
public CompletableFuture<Boolean> logAction(@Nonnull LogEntry entry) {
|
||||
Objects.requireNonNull(entry, "entry");
|
||||
return this.handle.noBuffer().logAction(entry).thenApply(x -> true);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Log> getLog() {
|
||||
return handle.noBuffer().getLog().thenApply(log -> log == null ? null : new ApiLog(log));
|
||||
return this.handle.noBuffer().getLog().thenApply(log -> log == null ? null : new ApiLog(log));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Boolean> loadUser(@NonNull UUID uuid, String username) {
|
||||
return handle.noBuffer().loadUser(uuid, username == null ? null : checkUsername(username)).thenApply(Objects::nonNull);
|
||||
public CompletableFuture<Boolean> loadUser(@Nonnull UUID uuid, String username) {
|
||||
Objects.requireNonNull(uuid, "uuid");
|
||||
return this.handle.noBuffer().loadUser(uuid, username == null ? null : checkUsername(username)).thenApply(Objects::nonNull);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Boolean> saveUser(@NonNull User user) {
|
||||
return handle.noBuffer().saveUser(ApiUser.cast(user)).thenApply(x -> true);
|
||||
public CompletableFuture<Boolean> saveUser(@Nonnull User user) {
|
||||
Objects.requireNonNull(user, "user");
|
||||
return this.handle.noBuffer().saveUser(ApiUser.cast(user)).thenApply(x -> true);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Set<UUID>> getUniqueUsers() {
|
||||
return handle.noBuffer().getUniqueUsers();
|
||||
return this.handle.noBuffer().getUniqueUsers();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<List<HeldPermission<UUID>>> getUsersWithPermission(@NonNull String permission) {
|
||||
return handle.noBuffer().getUsersWithPermission(permission);
|
||||
public CompletableFuture<List<HeldPermission<UUID>>> getUsersWithPermission(@Nonnull String permission) {
|
||||
Objects.requireNonNull(permission, "permission");
|
||||
return this.handle.noBuffer().getUsersWithPermission(permission);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Boolean> createAndLoadGroup(@NonNull String name) {
|
||||
return handle.noBuffer().createAndLoadGroup(checkName(name), CreationCause.API).thenApply(Objects::nonNull);
|
||||
public CompletableFuture<Boolean> createAndLoadGroup(@Nonnull String name) {
|
||||
Objects.requireNonNull(name, "name");
|
||||
return this.handle.noBuffer().createAndLoadGroup(checkName(name), CreationCause.API).thenApply(Objects::nonNull);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Boolean> loadGroup(@NonNull String name) {
|
||||
return handle.noBuffer().loadGroup(checkName(name)).thenApply(Optional::isPresent);
|
||||
public CompletableFuture<Boolean> loadGroup(@Nonnull String name) {
|
||||
Objects.requireNonNull(name, "name");
|
||||
return this.handle.noBuffer().loadGroup(checkName(name)).thenApply(Optional::isPresent);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Boolean> loadAllGroups() {
|
||||
return handle.noBuffer().loadAllGroups().thenApply(x -> true);
|
||||
return this.handle.noBuffer().loadAllGroups().thenApply(x -> true);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Boolean> saveGroup(@NonNull Group group) {
|
||||
return handle.noBuffer().saveGroup(ApiGroup.cast(group)).thenApply(x -> true);
|
||||
public CompletableFuture<Boolean> saveGroup(@Nonnull Group group) {
|
||||
Objects.requireNonNull(group, "group");
|
||||
return this.handle.noBuffer().saveGroup(ApiGroup.cast(group)).thenApply(x -> true);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Boolean> deleteGroup(@NonNull Group group) {
|
||||
if (group.getName().equalsIgnoreCase(plugin.getConfiguration().get(ConfigKeys.DEFAULT_GROUP_NAME))) {
|
||||
public CompletableFuture<Boolean> deleteGroup(@Nonnull Group group) {
|
||||
Objects.requireNonNull(group, "group");
|
||||
if (group.getName().equalsIgnoreCase(this.plugin.getConfiguration().get(ConfigKeys.DEFAULT_GROUP_NAME))) {
|
||||
throw new IllegalArgumentException("Cannot delete the default group.");
|
||||
}
|
||||
return handle.noBuffer().deleteGroup(ApiGroup.cast(group), DeletionCause.API).thenApply(x -> true);
|
||||
return this.handle.noBuffer().deleteGroup(ApiGroup.cast(group), DeletionCause.API).thenApply(x -> true);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<List<HeldPermission<String>>> getGroupsWithPermission(@NonNull String permission) {
|
||||
return handle.noBuffer().getGroupsWithPermission(permission);
|
||||
public CompletableFuture<List<HeldPermission<String>>> getGroupsWithPermission(@Nonnull String permission) {
|
||||
Objects.requireNonNull(permission, "permission");
|
||||
return this.handle.noBuffer().getGroupsWithPermission(permission);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Boolean> createAndLoadTrack(@NonNull String name) {
|
||||
return handle.noBuffer().createAndLoadTrack(checkName(name), CreationCause.API).thenApply(Objects::nonNull);
|
||||
public CompletableFuture<Boolean> createAndLoadTrack(@Nonnull String name) {
|
||||
Objects.requireNonNull(name, "name");
|
||||
return this.handle.noBuffer().createAndLoadTrack(checkName(name), CreationCause.API).thenApply(Objects::nonNull);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Boolean> loadTrack(@NonNull String name) {
|
||||
return handle.noBuffer().loadTrack(checkName(name)).thenApply(Optional::isPresent);
|
||||
public CompletableFuture<Boolean> loadTrack(@Nonnull String name) {
|
||||
Objects.requireNonNull(name, "name");
|
||||
return this.handle.noBuffer().loadTrack(checkName(name)).thenApply(Optional::isPresent);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Boolean> loadAllTracks() {
|
||||
return handle.noBuffer().loadAllTracks().thenApply(x -> true);
|
||||
return this.handle.noBuffer().loadAllTracks().thenApply(x -> true);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Boolean> saveTrack(@NonNull Track track) {
|
||||
return handle.noBuffer().saveTrack(ApiTrack.cast(track)).thenApply(x -> true);
|
||||
public CompletableFuture<Boolean> saveTrack(@Nonnull Track track) {
|
||||
Objects.requireNonNull(track, "track");
|
||||
return this.handle.noBuffer().saveTrack(ApiTrack.cast(track)).thenApply(x -> true);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Boolean> deleteTrack(@NonNull Track track) {
|
||||
return handle.noBuffer().deleteTrack(ApiTrack.cast(track), DeletionCause.API).thenApply(x -> true);
|
||||
public CompletableFuture<Boolean> deleteTrack(@Nonnull Track track) {
|
||||
Objects.requireNonNull(track, "track");
|
||||
return this.handle.noBuffer().deleteTrack(ApiTrack.cast(track), DeletionCause.API).thenApply(x -> true);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Boolean> saveUUIDData(@NonNull String username, @NonNull UUID uuid) {
|
||||
return handle.noBuffer().saveUUIDData(uuid, checkUsername(username)).thenApply(x -> true);
|
||||
public CompletableFuture<Boolean> saveUUIDData(@Nonnull String username, @Nonnull UUID uuid) {
|
||||
Objects.requireNonNull(username, "username");
|
||||
Objects.requireNonNull(uuid, "uuid");
|
||||
return this.handle.noBuffer().saveUUIDData(uuid, checkUsername(username)).thenApply(x -> true);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<UUID> getUUID(@NonNull String username) {
|
||||
return handle.noBuffer().getUUID(checkUsername(username));
|
||||
public CompletableFuture<UUID> getUUID(@Nonnull String username) {
|
||||
Objects.requireNonNull(username, "username");
|
||||
return this.handle.noBuffer().getUUID(checkUsername(username));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<String> getName(@NonNull UUID uuid) {
|
||||
return handle.noBuffer().getName(uuid);
|
||||
public CompletableFuture<String> getName(@Nonnull UUID uuid) {
|
||||
Objects.requireNonNull(uuid, "uuid");
|
||||
return this.handle.noBuffer().getName(uuid);
|
||||
}
|
||||
}
|
||||
|
@ -25,11 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.api.delegates.model;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import me.lucko.luckperms.api.DataMutateResult;
|
||||
@ -37,94 +32,115 @@ import me.lucko.luckperms.api.Group;
|
||||
import me.lucko.luckperms.api.Track;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@AllArgsConstructor
|
||||
public final class ApiTrack implements Track {
|
||||
public static me.lucko.luckperms.common.model.Track cast(Track g) {
|
||||
Preconditions.checkState(g instanceof ApiTrack, "Illegal instance " + g.getClass() + " cannot be handled by this implementation.");
|
||||
return ((ApiTrack) g).getHandle();
|
||||
public static me.lucko.luckperms.common.model.Track cast(Track track) {
|
||||
Objects.requireNonNull(track, "track");
|
||||
Preconditions.checkState(track instanceof ApiTrack, "Illegal instance " + track.getClass() + " cannot be handled by this implementation.");
|
||||
return ((ApiTrack) track).getHandle();
|
||||
}
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private final me.lucko.luckperms.common.model.Track handle;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return handle.getName();
|
||||
public ApiTrack(me.lucko.luckperms.common.model.Track handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
me.lucko.luckperms.common.model.Track getHandle() {
|
||||
return this.handle;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.handle.getName();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public List<String> getGroups() {
|
||||
return handle.getGroups();
|
||||
return this.handle.getGroups();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return handle.getSize();
|
||||
return this.handle.getSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNext(@NonNull Group current) {
|
||||
public String getNext(@Nonnull Group current) {
|
||||
Objects.requireNonNull(current, "current");
|
||||
try {
|
||||
return handle.getNext(ApiGroup.cast(current));
|
||||
return this.handle.getNext(ApiGroup.cast(current));
|
||||
} catch (IllegalArgumentException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrevious(@NonNull Group current) {
|
||||
public String getPrevious(@Nonnull Group current) {
|
||||
Objects.requireNonNull(current, "current");
|
||||
try {
|
||||
return handle.getPrevious(ApiGroup.cast(current));
|
||||
return this.handle.getPrevious(ApiGroup.cast(current));
|
||||
} catch (IllegalArgumentException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataMutateResult appendGroup(@NonNull Group group) {
|
||||
return handle.appendGroup(ApiGroup.cast(group));
|
||||
public DataMutateResult appendGroup(@Nonnull Group group) {
|
||||
Objects.requireNonNull(group, "group");
|
||||
return this.handle.appendGroup(ApiGroup.cast(group));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataMutateResult insertGroup(@NonNull Group group, @NonNull int position) throws IndexOutOfBoundsException {
|
||||
return handle.insertGroup(ApiGroup.cast(group), position);
|
||||
public DataMutateResult insertGroup(@Nonnull Group group, int position) throws IndexOutOfBoundsException {
|
||||
Objects.requireNonNull(group, "group");
|
||||
return this.handle.insertGroup(ApiGroup.cast(group), position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataMutateResult removeGroup(@NonNull Group group) {
|
||||
return handle.removeGroup(ApiGroup.cast(group));
|
||||
public DataMutateResult removeGroup(@Nonnull Group group) {
|
||||
Objects.requireNonNull(group, "group");
|
||||
return this.handle.removeGroup(ApiGroup.cast(group));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataMutateResult removeGroup(@NonNull String group) {
|
||||
return handle.removeGroup(group);
|
||||
public DataMutateResult removeGroup(@Nonnull String group) {
|
||||
Objects.requireNonNull(group, "group");
|
||||
return this.handle.removeGroup(group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsGroup(@NonNull Group group) {
|
||||
return handle.containsGroup(ApiGroup.cast(group));
|
||||
public boolean containsGroup(@Nonnull Group group) {
|
||||
Objects.requireNonNull(group, "group");
|
||||
return this.handle.containsGroup(ApiGroup.cast(group));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsGroup(@NonNull String group) {
|
||||
return handle.containsGroup(group);
|
||||
public boolean containsGroup(@Nonnull String group) {
|
||||
Objects.requireNonNull(group, "group");
|
||||
return this.handle.containsGroup(group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearGroups() {
|
||||
handle.clearGroups();
|
||||
this.handle.clearGroups();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof ApiTrack)) return false;
|
||||
|
||||
ApiTrack other = (ApiTrack) o;
|
||||
return handle.equals(other.handle);
|
||||
ApiTrack that = (ApiTrack) o;
|
||||
return this.handle.equals(that.handle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return handle.hashCode();
|
||||
return this.handle.hashCode();
|
||||
}
|
||||
}
|
||||
|
@ -25,9 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.api.delegates.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import me.lucko.luckperms.api.DataMutateResult;
|
||||
@ -35,77 +32,89 @@ import me.lucko.luckperms.api.User;
|
||||
import me.lucko.luckperms.api.caching.UserData;
|
||||
import me.lucko.luckperms.common.node.NodeFactory;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public final class ApiUser extends ApiPermissionHolder implements User {
|
||||
public static me.lucko.luckperms.common.model.User cast(User u) {
|
||||
Preconditions.checkState(u instanceof ApiUser, "Illegal instance " + u.getClass() + " cannot be handled by this implementation.");
|
||||
return ((ApiUser) u).getHandle();
|
||||
}
|
||||
|
||||
@Getter
|
||||
private final me.lucko.luckperms.common.model.User handle;
|
||||
|
||||
public ApiUser(@NonNull me.lucko.luckperms.common.model.User handle) {
|
||||
@Override
|
||||
me.lucko.luckperms.common.model.User getHandle() {
|
||||
return this.handle;
|
||||
}
|
||||
|
||||
public ApiUser(me.lucko.luckperms.common.model.User handle) {
|
||||
super(handle);
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public UUID getUuid() {
|
||||
return handle.getUuid();
|
||||
return this.handle.getUuid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return handle.getName().orElse(null);
|
||||
return this.handle.getName().orElse(null);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getPrimaryGroup() {
|
||||
return handle.getPrimaryGroup().getValue();
|
||||
return this.handle.getPrimaryGroup().getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataMutateResult setPrimaryGroup(@NonNull String s) {
|
||||
if (getPrimaryGroup().equalsIgnoreCase(s)) {
|
||||
public DataMutateResult setPrimaryGroup(@Nonnull String group) {
|
||||
Objects.requireNonNull(group, "group");
|
||||
if (getPrimaryGroup().equalsIgnoreCase(group)) {
|
||||
return DataMutateResult.ALREADY_HAS;
|
||||
}
|
||||
|
||||
if (!handle.hasPermission(NodeFactory.buildGroupNode(s.toLowerCase()).build()).asBoolean()) {
|
||||
if (!this.handle.hasPermission(NodeFactory.buildGroupNode(group.toLowerCase()).build()).asBoolean()) {
|
||||
return DataMutateResult.FAIL;
|
||||
}
|
||||
|
||||
handle.getPrimaryGroup().setStoredValue(s.toLowerCase());
|
||||
this.handle.getPrimaryGroup().setStoredValue(group.toLowerCase());
|
||||
return DataMutateResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public UserData getCachedData() {
|
||||
return handle.getCachedData();
|
||||
return this.handle.getCachedData();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void refreshPermissions() {
|
||||
handle.getRefreshBuffer().requestDirectly();
|
||||
this.handle.getRefreshBuffer().requestDirectly();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void setupDataCache() {
|
||||
handle.preCalculateData();
|
||||
this.handle.preCalculateData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof ApiUser)) return false;
|
||||
|
||||
ApiUser other = (ApiUser) o;
|
||||
return handle.equals(other.handle);
|
||||
ApiUser that = (ApiUser) o;
|
||||
return this.handle.equals(that.handle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return handle.hashCode();
|
||||
return this.handle.hashCode();
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ public class AssignmentExpression {
|
||||
|
||||
Predicate<Node> checker = node -> holder.hasPermission(node) == tristate;
|
||||
|
||||
String exp = expression.stream().map(t -> t.forExpression(checker)).collect(Collectors.joining())
|
||||
String exp = this.expression.stream().map(t -> t.forExpression(checker)).collect(Collectors.joining())
|
||||
.replace("&", "&&").replace("|", "||");
|
||||
|
||||
try {
|
||||
@ -123,12 +123,12 @@ public class AssignmentExpression {
|
||||
|
||||
@Override
|
||||
public String forExpression(Predicate<Node> checker) {
|
||||
return string;
|
||||
return this.string;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return string;
|
||||
return this.string;
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,12 +143,12 @@ public class AssignmentExpression {
|
||||
|
||||
@Override
|
||||
public String forExpression(Predicate<Node> checker) {
|
||||
return Boolean.toString(checker.test(node));
|
||||
return Boolean.toString(checker.test(this.node));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "<" + permission + ">";
|
||||
return "<" + this.permission + ">";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,9 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.assignments;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.api.Tristate;
|
||||
import me.lucko.luckperms.common.model.User;
|
||||
@ -36,8 +33,6 @@ import me.lucko.luckperms.common.utils.ImmutableCollectors;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@ToString
|
||||
public class AssignmentRule {
|
||||
private final AssignmentExpression hasTrueExpression;
|
||||
private final AssignmentExpression hasFalseExpression;
|
||||
@ -57,9 +52,9 @@ public class AssignmentRule {
|
||||
}
|
||||
|
||||
public boolean apply(User user) {
|
||||
if (hasTrueExpression != null) {
|
||||
if (this.hasTrueExpression != null) {
|
||||
try {
|
||||
boolean b = hasTrueExpression.parse(user, Tristate.TRUE);
|
||||
boolean b = this.hasTrueExpression.parse(user, Tristate.TRUE);
|
||||
if (!b) {
|
||||
// The holder does not meet this requirement
|
||||
return false;
|
||||
@ -71,9 +66,9 @@ public class AssignmentRule {
|
||||
}
|
||||
}
|
||||
|
||||
if (hasFalseExpression != null) {
|
||||
if (this.hasFalseExpression != null) {
|
||||
try {
|
||||
boolean b = hasFalseExpression.parse(user, Tristate.FALSE);
|
||||
boolean b = this.hasFalseExpression.parse(user, Tristate.FALSE);
|
||||
if (!b) {
|
||||
// The holder does not meet this requirement
|
||||
return false;
|
||||
@ -85,9 +80,9 @@ public class AssignmentRule {
|
||||
}
|
||||
}
|
||||
|
||||
if (lacksExpression != null) {
|
||||
if (this.lacksExpression != null) {
|
||||
try {
|
||||
boolean b = lacksExpression.parse(user, Tristate.UNDEFINED);
|
||||
boolean b = this.lacksExpression.parse(user, Tristate.UNDEFINED);
|
||||
if (!b) {
|
||||
// The holder does not meet this requirement
|
||||
return false;
|
||||
@ -100,18 +95,53 @@ public class AssignmentRule {
|
||||
}
|
||||
|
||||
// The holder meets all of the requirements of this rule.
|
||||
for (Node n : toTake) {
|
||||
for (Node n : this.toTake) {
|
||||
user.unsetPermission(n);
|
||||
}
|
||||
|
||||
for (Node n : toGive) {
|
||||
for (Node n : this.toGive) {
|
||||
user.setPermission(n);
|
||||
}
|
||||
|
||||
if (setPrimaryGroup != null) {
|
||||
user.getPrimaryGroup().setStoredValue(setPrimaryGroup);
|
||||
if (this.setPrimaryGroup != null) {
|
||||
user.getPrimaryGroup().setStoredValue(this.setPrimaryGroup);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public AssignmentExpression getHasTrueExpression() {
|
||||
return this.hasTrueExpression;
|
||||
}
|
||||
|
||||
public AssignmentExpression getHasFalseExpression() {
|
||||
return this.hasFalseExpression;
|
||||
}
|
||||
|
||||
public AssignmentExpression getLacksExpression() {
|
||||
return this.lacksExpression;
|
||||
}
|
||||
|
||||
public List<Node> getToGive() {
|
||||
return this.toGive;
|
||||
}
|
||||
|
||||
public List<Node> getToTake() {
|
||||
return this.toTake;
|
||||
}
|
||||
|
||||
public String getSetPrimaryGroup() {
|
||||
return this.setPrimaryGroup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AssignmentRule(" +
|
||||
"hasTrueExpression=" + this.getHasTrueExpression() + ", " +
|
||||
"hasFalseExpression=" + this.getHasFalseExpression() + ", " +
|
||||
"lacksExpression=" + this.getLacksExpression() + ", " +
|
||||
"toGive=" + this.getToGive() + ", " +
|
||||
"toTake=" + this.getToTake() + ", " +
|
||||
"setPrimaryGroup=" + this.getSetPrimaryGroup() + ")";
|
||||
}
|
||||
}
|
||||
|
@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.backup;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import me.lucko.luckperms.api.Tristate;
|
||||
import me.lucko.luckperms.common.commands.CommandManager;
|
||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||
@ -37,7 +35,6 @@ import net.kyori.text.Component;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
public abstract class DummySender implements Sender {
|
||||
private final LuckPermsPlugin platform;
|
||||
|
||||
@ -77,4 +74,18 @@ public abstract class DummySender implements Sender {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LuckPermsPlugin getPlatform() {
|
||||
return this.platform;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUuid() {
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
|
@ -83,29 +83,29 @@ public class Exporter implements Runnable {
|
||||
this.executor = executor;
|
||||
this.filePath = filePath;
|
||||
|
||||
log = new ProgressLogger(null, Message.EXPORT_LOG, Message.EXPORT_LOG_PROGRESS);
|
||||
log.addListener(plugin.getConsoleSender());
|
||||
log.addListener(executor);
|
||||
this.log = new ProgressLogger(null, Message.EXPORT_LOG, Message.EXPORT_LOG_PROGRESS);
|
||||
this.log.addListener(plugin.getConsoleSender());
|
||||
this.log.addListener(executor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(filePath, StandardCharsets.UTF_8)) {
|
||||
log.log("Starting.");
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(this.filePath, StandardCharsets.UTF_8)) {
|
||||
this.log.log("Starting.");
|
||||
|
||||
write(writer, "# LuckPerms Export File");
|
||||
write(writer, "# Generated by " + executor.getNameWithLocation() + " at " + DATE_FORMAT.format(new Date(System.currentTimeMillis())));
|
||||
write(writer, "# Generated by " + this.executor.getNameWithLocation() + " at " + DATE_FORMAT.format(new Date(System.currentTimeMillis())));
|
||||
write(writer, "");
|
||||
|
||||
// Export Groups
|
||||
log.log("Starting group export.");
|
||||
this.log.log("Starting group export.");
|
||||
|
||||
// Create the actual groups first
|
||||
write(writer, "# Create groups");
|
||||
|
||||
AtomicInteger groupCount = new AtomicInteger(0);
|
||||
|
||||
List<? extends Group> groups = plugin.getGroupManager().getAll().values().stream()
|
||||
List<? extends Group> groups = this.plugin.getGroupManager().getAll().values().stream()
|
||||
// export groups in order of weight
|
||||
.sorted((o1, o2) -> {
|
||||
int i = Integer.compare(o2.getWeight().orElse(0), o1.getWeight().orElse(0));
|
||||
@ -128,18 +128,18 @@ public class Exporter implements Runnable {
|
||||
write(writer, "/lp " + NodeFactory.nodeAsCommand(node, group.getName(), HolderType.GROUP, true));
|
||||
}
|
||||
write(writer, "");
|
||||
log.logAllProgress("Exported {} groups so far.", groupCount.incrementAndGet());
|
||||
this.log.logAllProgress("Exported {} groups so far.", groupCount.incrementAndGet());
|
||||
}
|
||||
|
||||
log.log("Exported " + groupCount.get() + " groups.");
|
||||
this.log.log("Exported " + groupCount.get() + " groups.");
|
||||
|
||||
write(writer, "");
|
||||
write(writer, "");
|
||||
|
||||
// Export tracks
|
||||
log.log("Starting track export.");
|
||||
this.log.log("Starting track export.");
|
||||
|
||||
Collection<? extends Track> tracks = plugin.getTrackManager().getAll().values();
|
||||
Collection<? extends Track> tracks = this.plugin.getTrackManager().getAll().values();
|
||||
if (!tracks.isEmpty()) {
|
||||
|
||||
// Create the actual tracks first
|
||||
@ -151,32 +151,32 @@ public class Exporter implements Runnable {
|
||||
write(writer, "");
|
||||
|
||||
AtomicInteger trackCount = new AtomicInteger(0);
|
||||
for (Track track : plugin.getTrackManager().getAll().values()) {
|
||||
for (Track track : this.plugin.getTrackManager().getAll().values()) {
|
||||
write(writer, "# Export track: " + track.getName());
|
||||
for (String group : track.getGroups()) {
|
||||
write(writer, "/lp track " + track.getName() + " append " + group);
|
||||
}
|
||||
write(writer, "");
|
||||
log.logAllProgress("Exported {} tracks so far.", trackCount.incrementAndGet());
|
||||
this.log.logAllProgress("Exported {} tracks so far.", trackCount.incrementAndGet());
|
||||
}
|
||||
|
||||
write(writer, "");
|
||||
write(writer, "");
|
||||
}
|
||||
|
||||
log.log("Exported " + tracks.size() + " tracks.");
|
||||
this.log.log("Exported " + tracks.size() + " tracks.");
|
||||
|
||||
|
||||
// Users are migrated in separate threads.
|
||||
// This is because there are likely to be a lot of them, and because we can.
|
||||
// It's a big speed improvement, since the database/files are split up and can handle concurrent reads.
|
||||
|
||||
log.log("Starting user export. Finding a list of unique users to export.");
|
||||
this.log.log("Starting user export. Finding a list of unique users to export.");
|
||||
|
||||
// Find all of the unique users we need to export
|
||||
Storage ds = plugin.getStorage();
|
||||
Storage ds = this.plugin.getStorage();
|
||||
Set<UUID> users = ds.getUniqueUsers().join();
|
||||
log.log("Found " + users.size() + " unique users to export.");
|
||||
this.log.log("Found " + users.size() + " unique users to export.");
|
||||
|
||||
write(writer, "# Export users");
|
||||
|
||||
@ -186,7 +186,7 @@ public class Exporter implements Runnable {
|
||||
userPools.next().add(uuid);
|
||||
}
|
||||
|
||||
log.log("Split users into " + userPools.getBacking().size() + " threads for export.");
|
||||
this.log.log("Split users into " + userPools.getBacking().size() + " threads for export.");
|
||||
|
||||
// Setup a file writing lock. We don't want multiple threads writing at the same time.
|
||||
// The write function accepts a list of strings, as we want a user's data to be grouped together.
|
||||
@ -220,8 +220,8 @@ public class Exporter implements Runnable {
|
||||
// actually export the user. this output will be fed to the writing function when we have all of the user's data.
|
||||
List<String> output = new ArrayList<>();
|
||||
|
||||
plugin.getStorage().loadUser(uuid, null).join();
|
||||
User user = plugin.getUserManager().getIfLoaded(uuid);
|
||||
this.plugin.getStorage().loadUser(uuid, null).join();
|
||||
User user = this.plugin.getUserManager().getIfLoaded(uuid);
|
||||
output.add("# Export user: " + user.getUuid().toString() + " - " + user.getName().orElse("unknown username"));
|
||||
|
||||
boolean inDefault = false;
|
||||
@ -242,25 +242,25 @@ public class Exporter implements Runnable {
|
||||
output.add("/lp user " + user.getUuid().toString() + " parent remove default");
|
||||
}
|
||||
|
||||
plugin.getUserManager().cleanup(user);
|
||||
this.plugin.getUserManager().cleanup(user);
|
||||
writeFunction.accept(output);
|
||||
|
||||
log.logProgress("Exported {} users so far.", userCount.incrementAndGet());
|
||||
this.log.logProgress("Exported {} users so far.", userCount.incrementAndGet());
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, plugin.getScheduler().async()));
|
||||
}, this.plugin.getScheduler().async()));
|
||||
}
|
||||
|
||||
// all of the threads have been scheduled now and are running. we just need to wait for them all to complete
|
||||
CompletableFuture.allOf(futures.toArray(new CompletableFuture[futures.size()])).join();
|
||||
|
||||
log.log("Exported " + userCount.get() + " users.");
|
||||
this.log.log("Exported " + userCount.get() + " users.");
|
||||
|
||||
writer.flush();
|
||||
log.getListeners().forEach(l -> Message.LOG_EXPORT_SUCCESS.send(l, filePath.toFile().getAbsolutePath()));
|
||||
this.log.getListeners().forEach(l -> Message.LOG_EXPORT_SUCCESS.send(l, this.filePath.toFile().getAbsolutePath()));
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
@ -25,9 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.backup;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
@ -81,13 +78,13 @@ public class Importer implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
long startTime = System.currentTimeMillis();
|
||||
notify.forEach(s -> Message.IMPORT_START.send(s));
|
||||
this.notify.forEach(s -> Message.IMPORT_START.send(s));
|
||||
|
||||
// form instances for all commands, and register them
|
||||
int index = 1;
|
||||
for (String command : commands) {
|
||||
ImportCommand cmd = new ImportCommand(commandManager, index, command);
|
||||
toExecute.add(cmd);
|
||||
for (String command : this.commands) {
|
||||
ImportCommand cmd = new ImportCommand(this.commandManager, index, command);
|
||||
this.toExecute.add(cmd);
|
||||
|
||||
if (cmd.getCommand().startsWith("creategroup ") || cmd.getCommand().startsWith("createtrack ")) {
|
||||
cmd.process(); // process immediately
|
||||
@ -100,7 +97,7 @@ public class Importer implements Runnable {
|
||||
Cycle<List<ImportCommand>> commandPools = new Cycle<>(CommandUtils.nInstances(128, ArrayList::new));
|
||||
|
||||
String lastTarget = null;
|
||||
for (ImportCommand cmd : toExecute) {
|
||||
for (ImportCommand cmd : this.toExecute) {
|
||||
// if the last target isn't the same, skip to a new pool
|
||||
if (lastTarget == null || !lastTarget.equals(cmd.getTarget())) {
|
||||
commandPools.next();
|
||||
@ -126,7 +123,7 @@ public class Importer implements Runnable {
|
||||
cmd.process();
|
||||
processedCount.incrementAndGet();
|
||||
}
|
||||
}, commandManager.getPlugin().getScheduler().async()));
|
||||
}, this.commandManager.getPlugin().getScheduler().async()));
|
||||
}
|
||||
|
||||
// all of the threads have been scheduled now and are running. we just need to wait for them all to complete
|
||||
@ -153,24 +150,24 @@ public class Importer implements Runnable {
|
||||
long endTime = System.currentTimeMillis();
|
||||
double seconds = (endTime - startTime) / 1000;
|
||||
|
||||
int errors = (int) toExecute.stream().filter(v -> !v.getResult().asBoolean()).count();
|
||||
int errors = (int) this.toExecute.stream().filter(v -> !v.getResult().asBoolean()).count();
|
||||
|
||||
switch (errors) {
|
||||
case 0:
|
||||
notify.forEach(s -> Message.IMPORT_END_COMPLETE.send(s, seconds));
|
||||
this.notify.forEach(s -> Message.IMPORT_END_COMPLETE.send(s, seconds));
|
||||
break;
|
||||
case 1:
|
||||
notify.forEach(s -> Message.IMPORT_END_COMPLETE_ERR_SIN.send(s, seconds, errors));
|
||||
this.notify.forEach(s -> Message.IMPORT_END_COMPLETE_ERR_SIN.send(s, seconds, errors));
|
||||
break;
|
||||
default:
|
||||
notify.forEach(s -> Message.IMPORT_END_COMPLETE_ERR.send(s, seconds, errors));
|
||||
this.notify.forEach(s -> Message.IMPORT_END_COMPLETE_ERR.send(s, seconds, errors));
|
||||
break;
|
||||
}
|
||||
|
||||
AtomicInteger errIndex = new AtomicInteger(1);
|
||||
for (ImportCommand e : toExecute) {
|
||||
for (ImportCommand e : this.toExecute) {
|
||||
if (e.getResult() != null && !e.getResult().asBoolean()) {
|
||||
notify.forEach(s -> {
|
||||
this.notify.forEach(s -> {
|
||||
Message.IMPORT_END_ERROR_HEADER.send(s, errIndex.get(), e.getId(), e.getCommand(), e.getResult().toString());
|
||||
for (String out : e.getOutput()) {
|
||||
Message.IMPORT_END_ERROR_CONTENT.send(s, out);
|
||||
@ -184,17 +181,16 @@ public class Importer implements Runnable {
|
||||
}
|
||||
|
||||
private void sendProgress(int processedCount) {
|
||||
int percent = (processedCount * 100) / commands.size();
|
||||
int errors = (int) toExecute.stream().filter(v -> v.isCompleted() && !v.getResult().asBoolean()).count();
|
||||
int percent = (processedCount * 100) / this.commands.size();
|
||||
int errors = (int) this.toExecute.stream().filter(v -> v.isCompleted() && !v.getResult().asBoolean()).count();
|
||||
|
||||
if (errors == 1) {
|
||||
notify.forEach(s -> Message.IMPORT_PROGRESS_SIN.send(s, percent, processedCount, commands.size(), errors));
|
||||
this.notify.forEach(s -> Message.IMPORT_PROGRESS_SIN.send(s, percent, processedCount, this.commands.size(), errors));
|
||||
} else {
|
||||
notify.forEach(s -> Message.IMPORT_PROGRESS.send(s, percent, processedCount, commands.size(), errors));
|
||||
this.notify.forEach(s -> Message.IMPORT_PROGRESS.send(s, percent, processedCount, this.commands.size(), errors));
|
||||
}
|
||||
}
|
||||
|
||||
@Getter
|
||||
private static class ImportCommand extends DummySender {
|
||||
private static final Splitter ARGUMENT_SPLITTER = Splitter.on(CommandManager.COMMAND_SEPARATOR_PATTERN).omitEmptyStrings();
|
||||
private static final Splitter SPACE_SPLITTER = Splitter.on(" ");
|
||||
@ -205,12 +201,10 @@ public class Importer implements Runnable {
|
||||
|
||||
private final String target;
|
||||
|
||||
@Setter
|
||||
private boolean completed = false;
|
||||
|
||||
private final List<String> output = new ArrayList<>();
|
||||
|
||||
@Setter
|
||||
private CommandResult result = CommandResult.FAILURE;
|
||||
|
||||
ImportCommand(CommandManager commandManager, int id, String command) {
|
||||
@ -223,7 +217,7 @@ public class Importer implements Runnable {
|
||||
|
||||
@Override
|
||||
protected void consumeMessage(String s) {
|
||||
output.add(s);
|
||||
this.output.add(s);
|
||||
}
|
||||
|
||||
public void process() {
|
||||
@ -233,7 +227,7 @@ public class Importer implements Runnable {
|
||||
|
||||
try {
|
||||
List<String> args = CommandManager.stripQuotes(ARGUMENT_SPLITTER.splitToList(getCommand()));
|
||||
CommandResult result = commandManager.onCommand(this, "lp", args, Runnable::run).get();
|
||||
CommandResult result = this.commandManager.onCommand(this, "lp", args, Runnable::run).get();
|
||||
setResult(result);
|
||||
} catch (Exception e) {
|
||||
setResult(CommandResult.FAILURE);
|
||||
@ -287,6 +281,37 @@ public class Importer implements Runnable {
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public String getCommand() {
|
||||
return this.command;
|
||||
}
|
||||
|
||||
public String getTarget() {
|
||||
return this.target;
|
||||
}
|
||||
|
||||
public boolean isCompleted() {
|
||||
return this.completed;
|
||||
}
|
||||
|
||||
public List<String> getOutput() {
|
||||
return this.output;
|
||||
}
|
||||
|
||||
public CommandResult getResult() {
|
||||
return this.result;
|
||||
}
|
||||
|
||||
public void setCompleted(boolean completed) {
|
||||
this.completed = completed;
|
||||
}
|
||||
|
||||
public void setResult(CommandResult result) {
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,15 +25,10 @@
|
||||
|
||||
package me.lucko.luckperms.common.buffers;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.function.Function;
|
||||
@ -60,17 +55,19 @@ public class Buffer<T, R> implements Runnable {
|
||||
this.dequeueFunc = dequeueFunc;
|
||||
}
|
||||
|
||||
public CompletableFuture<R> enqueue(@NonNull T t) {
|
||||
lock.lock();
|
||||
public CompletableFuture<R> enqueue(T object) {
|
||||
Objects.requireNonNull(object, "object");
|
||||
|
||||
this.lock.lock();
|
||||
try {
|
||||
ListIterator<BufferedObject<T, R>> it = buffer.listIterator();
|
||||
ListIterator<BufferedObject<T, R>> it = this.buffer.listIterator();
|
||||
|
||||
BufferedObject<T, R> o = null;
|
||||
|
||||
while (it.hasNext()) {
|
||||
BufferedObject<T, R> obj = it.next();
|
||||
|
||||
if (obj.getObject().equals(t)) {
|
||||
if (obj.getObject().equals(object)) {
|
||||
o = obj;
|
||||
it.remove();
|
||||
break;
|
||||
@ -78,28 +75,28 @@ public class Buffer<T, R> implements Runnable {
|
||||
}
|
||||
|
||||
if (o == null) {
|
||||
o = new BufferedObject<>(System.currentTimeMillis(), t, new CompletableFuture<R>());
|
||||
o = new BufferedObject<>(System.currentTimeMillis(), object, new CompletableFuture<R>());
|
||||
} else {
|
||||
o.setBufferTime(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
buffer.add(o);
|
||||
this.buffer.add(o);
|
||||
return o.getFuture();
|
||||
} finally {
|
||||
lock.unlock();
|
||||
this.lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
protected R dequeue(T t) {
|
||||
return dequeueFunc.apply(t);
|
||||
return this.dequeueFunc.apply(t);
|
||||
}
|
||||
|
||||
public void flush(long flushTime) {
|
||||
long time = System.currentTimeMillis();
|
||||
|
||||
lock.lock();
|
||||
this.lock.lock();
|
||||
try {
|
||||
ListIterator<BufferedObject<T, R>> it = buffer.listIterator(buffer.size());
|
||||
ListIterator<BufferedObject<T, R>> it = this.buffer.listIterator(this.buffer.size());
|
||||
|
||||
while (it.hasPrevious()) {
|
||||
BufferedObject<T, R> obj = it.previous();
|
||||
@ -114,7 +111,7 @@ public class Buffer<T, R> implements Runnable {
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
lock.unlock();
|
||||
this.lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@ -123,15 +120,45 @@ public class Buffer<T, R> implements Runnable {
|
||||
flush(DEFAULT_FLUSH_TIME);
|
||||
}
|
||||
|
||||
@Getter
|
||||
@EqualsAndHashCode(of = "object")
|
||||
@AllArgsConstructor
|
||||
private static final class BufferedObject<T, R> {
|
||||
|
||||
@Setter
|
||||
private long bufferTime;
|
||||
private final T object;
|
||||
private final CompletableFuture<R> future;
|
||||
|
||||
public BufferedObject(long bufferTime, T object, CompletableFuture<R> future) {
|
||||
this.bufferTime = bufferTime;
|
||||
this.object = object;
|
||||
this.future = future;
|
||||
}
|
||||
|
||||
public long getBufferTime() {
|
||||
return this.bufferTime;
|
||||
}
|
||||
|
||||
public void setBufferTime(long bufferTime) {
|
||||
this.bufferTime = bufferTime;
|
||||
}
|
||||
|
||||
public T getObject() {
|
||||
return this.object;
|
||||
}
|
||||
|
||||
public CompletableFuture<R> getFuture() {
|
||||
return this.future;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof Buffer.BufferedObject)) return false;
|
||||
final BufferedObject that = (BufferedObject) o;
|
||||
return Objects.equals(this.getObject(), that.getObject());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(this.object);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,9 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.buffers;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
@ -42,7 +39,6 @@ import java.util.function.Supplier;
|
||||
*
|
||||
* @param <T> the return type
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
public abstract class BufferedRequest<T> {
|
||||
private final long bufferTimeMillis;
|
||||
private final long sleepInterval;
|
||||
@ -51,23 +47,29 @@ public abstract class BufferedRequest<T> {
|
||||
private WeakReference<Processor<T>> processor = null;
|
||||
private final ReentrantLock lock = new ReentrantLock();
|
||||
|
||||
public BufferedRequest(long bufferTimeMillis, long sleepInterval, Executor executor) {
|
||||
this.bufferTimeMillis = bufferTimeMillis;
|
||||
this.sleepInterval = sleepInterval;
|
||||
this.executor = executor;
|
||||
}
|
||||
|
||||
public CompletableFuture<T> request() {
|
||||
lock.lock();
|
||||
this.lock.lock();
|
||||
try {
|
||||
if (processor != null) {
|
||||
Processor<T> p = processor.get();
|
||||
if (this.processor != null) {
|
||||
Processor<T> p = this.processor.get();
|
||||
if (p != null && p.isUsable()) {
|
||||
return p.getAndExtend();
|
||||
}
|
||||
}
|
||||
|
||||
Processor<T> p = new Processor<>(bufferTimeMillis, sleepInterval, this::perform);
|
||||
executor.execute(p);
|
||||
processor = new WeakReference<>(p);
|
||||
Processor<T> p = new Processor<>(this.bufferTimeMillis, this.sleepInterval, this::perform);
|
||||
this.executor.execute(p);
|
||||
this.processor = new WeakReference<>(p);
|
||||
return p.get();
|
||||
|
||||
} finally {
|
||||
lock.unlock();
|
||||
this.lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,62 +79,70 @@ public abstract class BufferedRequest<T> {
|
||||
|
||||
protected abstract T perform();
|
||||
|
||||
@RequiredArgsConstructor
|
||||
private static class Processor<R> implements Runnable {
|
||||
private final long delayMillis;
|
||||
private final long sleepMillis;
|
||||
private final Supplier<R> supplier;
|
||||
private final ReentrantLock lock = new ReentrantLock();
|
||||
private final CompletableFuture<R> future = new CompletableFuture<>();
|
||||
@Getter
|
||||
private boolean usable = true;
|
||||
private long executionTime;
|
||||
|
||||
public Processor(long delayMillis, long sleepMillis, Supplier<R> supplier) {
|
||||
this.delayMillis = delayMillis;
|
||||
this.sleepMillis = sleepMillis;
|
||||
this.supplier = supplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
lock.lock();
|
||||
this.lock.lock();
|
||||
try {
|
||||
executionTime = System.currentTimeMillis() + delayMillis;
|
||||
this.executionTime = System.currentTimeMillis() + this.delayMillis;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
this.lock.unlock();
|
||||
}
|
||||
|
||||
while (true) {
|
||||
lock.lock();
|
||||
this.lock.lock();
|
||||
try {
|
||||
if (System.currentTimeMillis() > executionTime) {
|
||||
usable = false;
|
||||
if (System.currentTimeMillis() > this.executionTime) {
|
||||
this.usable = false;
|
||||
break;
|
||||
}
|
||||
|
||||
} finally {
|
||||
lock.unlock();
|
||||
this.lock.unlock();
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(sleepMillis);
|
||||
Thread.sleep(this.sleepMillis);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
R result = supplier.get();
|
||||
future.complete(result);
|
||||
R result = this.supplier.get();
|
||||
this.future.complete(result);
|
||||
}
|
||||
|
||||
public CompletableFuture<R> get() {
|
||||
return future;
|
||||
return this.future;
|
||||
}
|
||||
|
||||
public CompletableFuture<R> getAndExtend() {
|
||||
lock.lock();
|
||||
this.lock.lock();
|
||||
try {
|
||||
executionTime = System.currentTimeMillis() + delayMillis;
|
||||
this.executionTime = System.currentTimeMillis() + this.delayMillis;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
this.lock.unlock();
|
||||
}
|
||||
|
||||
return future;
|
||||
return this.future;
|
||||
}
|
||||
|
||||
public boolean isUsable() {
|
||||
return this.usable;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.buffers;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
@ -35,58 +33,56 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
*
|
||||
* @param <T> the type being stored
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
public abstract class Cache<T> {
|
||||
private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
|
||||
|
||||
private T cached = null;
|
||||
|
||||
protected abstract T supply();
|
||||
|
||||
public final T get() {
|
||||
// try to just read from the cached value
|
||||
lock.readLock().lock();
|
||||
this.lock.readLock().lock();
|
||||
try {
|
||||
if (cached != null) {
|
||||
return cached;
|
||||
if (this.cached != null) {
|
||||
return this.cached;
|
||||
}
|
||||
} finally {
|
||||
// we have to release the read lock, as it is not possible
|
||||
// to acquire the write lock whilst holding a read lock
|
||||
lock.readLock().unlock();
|
||||
this.lock.readLock().unlock();
|
||||
}
|
||||
|
||||
lock.writeLock().lock();
|
||||
this.lock.writeLock().lock();
|
||||
try {
|
||||
// Since the lock was unlocked momentarily, we need
|
||||
// to check again for a cached value
|
||||
if (cached != null) {
|
||||
return cached;
|
||||
if (this.cached != null) {
|
||||
return this.cached;
|
||||
}
|
||||
|
||||
// call the supplier and set the cached value
|
||||
cached = supply();
|
||||
return cached;
|
||||
this.cached = supply();
|
||||
return this.cached;
|
||||
} finally {
|
||||
lock.writeLock().unlock();
|
||||
this.lock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public final Optional<T> getIfPresent() {
|
||||
lock.readLock().lock();
|
||||
this.lock.readLock().lock();
|
||||
try {
|
||||
return Optional.ofNullable(cached);
|
||||
return Optional.ofNullable(this.cached);
|
||||
} finally {
|
||||
lock.readLock().unlock();
|
||||
this.lock.readLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public final void invalidate() {
|
||||
lock.writeLock().lock();
|
||||
this.lock.writeLock().lock();
|
||||
try {
|
||||
cached = null;
|
||||
this.cached = null;
|
||||
} finally {
|
||||
lock.writeLock().unlock();
|
||||
this.lock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public class UpdateTaskBuffer extends BufferedRequest<Void> {
|
||||
|
||||
@Override
|
||||
protected Void perform() {
|
||||
new UpdateTask(plugin, false).run();
|
||||
new UpdateTask(this.plugin, false).run();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -25,26 +25,18 @@
|
||||
|
||||
package me.lucko.luckperms.common.bulkupdate;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
|
||||
import me.lucko.luckperms.common.bulkupdate.action.Action;
|
||||
import me.lucko.luckperms.common.bulkupdate.constraint.Constraint;
|
||||
import me.lucko.luckperms.common.node.NodeModel;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Represents a query to be applied to a set of data.
|
||||
* Queries can either be applied to im-memory sets of data, or converted to SQL syntax to be executed remotely.
|
||||
*/
|
||||
@Getter
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
@AllArgsConstructor
|
||||
public class BulkUpdate {
|
||||
public final class BulkUpdate {
|
||||
|
||||
// the data types which this query should apply to
|
||||
private final DataType dataType;
|
||||
@ -55,6 +47,12 @@ public class BulkUpdate {
|
||||
// a set of constraints which data must match to be acted upon
|
||||
private final List<Constraint> constraints;
|
||||
|
||||
public BulkUpdate(DataType dataType, Action action, List<Constraint> constraints) {
|
||||
this.dataType = dataType;
|
||||
this.action = action;
|
||||
this.constraints = constraints;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if a Node instance satisfies the constrints of this query
|
||||
*
|
||||
@ -62,7 +60,7 @@ public class BulkUpdate {
|
||||
* @return true if satisfied
|
||||
*/
|
||||
public boolean satisfiesConstraints(NodeModel node) {
|
||||
for (Constraint constraint : constraints) {
|
||||
for (Constraint constraint : this.constraints) {
|
||||
if (!constraint.isSatisfiedBy(node)) {
|
||||
return false;
|
||||
}
|
||||
@ -81,7 +79,7 @@ public class BulkUpdate {
|
||||
return from; // make no change
|
||||
}
|
||||
|
||||
return action.apply(from);
|
||||
return this.action.apply(from);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -97,17 +95,17 @@ public class BulkUpdate {
|
||||
|
||||
// add the action
|
||||
// (DELETE FROM or UPDATE)
|
||||
sb.append(action.getAsSql());
|
||||
sb.append(this.action.getAsSql());
|
||||
|
||||
// if there are no constraints, just return without a WHERE clause
|
||||
if (constraints.isEmpty()) {
|
||||
if (this.constraints.isEmpty()) {
|
||||
return sb.append(";").toString();
|
||||
}
|
||||
|
||||
// append constraints
|
||||
sb.append(" WHERE");
|
||||
for (int i = 0; i < constraints.size(); i++) {
|
||||
Constraint constraint = constraints.get(i);
|
||||
for (int i = 0; i < this.constraints.size(); i++) {
|
||||
Constraint constraint = this.constraints.get(i);
|
||||
|
||||
sb.append(" ");
|
||||
if (i != 0) {
|
||||
@ -141,4 +139,39 @@ public class BulkUpdate {
|
||||
return "'" + s + "'";
|
||||
}
|
||||
|
||||
public DataType getDataType() {
|
||||
return this.dataType;
|
||||
}
|
||||
|
||||
public Action getAction() {
|
||||
return this.action;
|
||||
}
|
||||
|
||||
public List<Constraint> getConstraints() {
|
||||
return this.constraints;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof BulkUpdate)) return false;
|
||||
final BulkUpdate that = (BulkUpdate) o;
|
||||
|
||||
return Objects.equals(this.getDataType(), that.getDataType()) &&
|
||||
Objects.equals(this.getAction(), that.getAction()) &&
|
||||
Objects.equals(this.getConstraints(), that.getConstraints());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(getDataType(), getAction(), getConstraints());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BulkUpdate(" +
|
||||
"dataType=" + this.getDataType() + ", " +
|
||||
"action=" + this.getAction() + ", " +
|
||||
"constraints=" + this.getConstraints() + ")";
|
||||
}
|
||||
}
|
||||
|
@ -25,9 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.bulkupdate;
|
||||
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import me.lucko.luckperms.common.bulkupdate.action.Action;
|
||||
@ -39,10 +36,12 @@ import java.util.Set;
|
||||
/**
|
||||
* Responsible for building a {@link BulkUpdate}
|
||||
*/
|
||||
@ToString
|
||||
@NoArgsConstructor(staticName = "create")
|
||||
public class BulkUpdateBuilder {
|
||||
|
||||
public static BulkUpdateBuilder create() {
|
||||
return new BulkUpdateBuilder();
|
||||
}
|
||||
|
||||
// the data type this query should affect
|
||||
private DataType dataType = DataType.ALL;
|
||||
|
||||
@ -52,6 +51,9 @@ public class BulkUpdateBuilder {
|
||||
// a set of constraints which data must match to be acted upon
|
||||
private final Set<Constraint> constraints = new LinkedHashSet<>();
|
||||
|
||||
private BulkUpdateBuilder() {
|
||||
}
|
||||
|
||||
public BulkUpdateBuilder action(Action action) {
|
||||
this.action = action;
|
||||
return this;
|
||||
@ -63,15 +65,23 @@ public class BulkUpdateBuilder {
|
||||
}
|
||||
|
||||
public BulkUpdateBuilder constraint(Constraint constraint) {
|
||||
constraints.add(constraint);
|
||||
this.constraints.add(constraint);
|
||||
return this;
|
||||
}
|
||||
|
||||
public BulkUpdate build() {
|
||||
if (action == null) {
|
||||
if (this.action == null) {
|
||||
throw new IllegalStateException("no action specified");
|
||||
}
|
||||
|
||||
return new BulkUpdate(dataType, action, ImmutableList.copyOf(constraints));
|
||||
return new BulkUpdate(this.dataType, this.action, ImmutableList.copyOf(this.constraints));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BulkUpdateBuilder(" +
|
||||
"dataType=" + this.dataType + ", " +
|
||||
"action=" + this.action + ", " +
|
||||
"constraints=" + this.constraints + ")";
|
||||
}
|
||||
}
|
||||
|
@ -25,14 +25,9 @@
|
||||
|
||||
package me.lucko.luckperms.common.bulkupdate;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Represents the data sets a query should apply to
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum DataType {
|
||||
|
||||
ALL("all", true, true),
|
||||
@ -43,4 +38,21 @@ public enum DataType {
|
||||
private final boolean includingUsers;
|
||||
private final boolean includingGroups;
|
||||
|
||||
DataType(String name, boolean includingUsers, boolean includingGroups) {
|
||||
this.name = name;
|
||||
this.includingUsers = includingUsers;
|
||||
this.includingGroups = includingGroups;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public boolean isIncludingUsers() {
|
||||
return this.includingUsers;
|
||||
}
|
||||
|
||||
public boolean isIncludingGroups() {
|
||||
return this.includingGroups;
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user