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).
|
Bugs or issues should be reported using the [GitHub Issues tab](https://github.com/lucko/LuckPerms/issues).
|
||||||
|
|
||||||
### :pencil: Want to contribute code?
|
### :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
|
#### 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!)
|
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.
|
You can find the output jars in the `target` directories.
|
||||||
|
|
||||||
## Contributing
|
## 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
|
#### 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!)
|
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;
|
package me.lucko.luckperms.api;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@ -45,13 +44,13 @@ public enum ChatMetaType {
|
|||||||
PREFIX("prefix") {
|
PREFIX("prefix") {
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(@Nonnull Node node) {
|
public boolean matches(@Nonnull Node node) {
|
||||||
return Preconditions.checkNotNull(node, "node").isPrefix();
|
return Objects.requireNonNull(node, "node").isPrefix();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Map.Entry<Integer, String> getEntry(@Nonnull Node node) {
|
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") {
|
SUFFIX("suffix") {
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(@Nonnull Node node) {
|
public boolean matches(@Nonnull Node node) {
|
||||||
return Preconditions.checkNotNull(node, "node").isSuffix();
|
return Objects.requireNonNull(node, "node").isSuffix();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Map.Entry<Integer, String> getEntry(@Nonnull Node node) {
|
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
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return str;
|
return this.str;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -25,11 +25,11 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.api;
|
package me.lucko.luckperms.api;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
|
|
||||||
import me.lucko.luckperms.api.context.ContextSet;
|
import me.lucko.luckperms.api.context.ContextSet;
|
||||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
@ -89,6 +89,7 @@ public class Contexts {
|
|||||||
return GLOBAL;
|
return GLOBAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
public static Contexts of(@Nonnull ContextSet context, boolean includeGlobal, boolean includeGlobalWorld, boolean applyGroups, boolean applyGlobalGroups, boolean applyGlobalWorldGroups, boolean op) {
|
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);
|
return new Contexts(context, includeGlobal, includeGlobalWorld, applyGroups, applyGlobalGroups, applyGlobalWorldGroups, op);
|
||||||
}
|
}
|
||||||
@ -135,7 +136,7 @@ public class Contexts {
|
|||||||
private final int hashCode;
|
private final int hashCode;
|
||||||
|
|
||||||
public Contexts(@Nonnull ContextSet context, boolean includeGlobal, boolean includeGlobalWorld, boolean applyGroups, boolean applyGlobalGroups, boolean applyGlobalWorldGroups, boolean op) {
|
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.includeGlobal = includeGlobal;
|
||||||
this.includeGlobalWorld = includeGlobalWorld;
|
this.includeGlobalWorld = includeGlobalWorld;
|
||||||
this.applyGroups = applyGroups;
|
this.applyGroups = applyGroups;
|
||||||
@ -211,18 +212,17 @@ public class Contexts {
|
|||||||
return this.applyGlobalWorldGroups;
|
return this.applyGlobalWorldGroups;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Contexts(" +
|
return "Contexts(" +
|
||||||
"context=" + this.getContexts() + ", " +
|
"context=" + this.context + ", " +
|
||||||
"op=" + this.isOp() + ", " +
|
"op=" + this.op + ", " +
|
||||||
"includeGlobal=" + this.isIncludeGlobal() + ", " +
|
"includeGlobal=" + this.includeGlobal + ", " +
|
||||||
"includeGlobalWorld=" + this.isIncludeGlobalWorld() + ", " +
|
"includeGlobalWorld=" + this.includeGlobalWorld + ", " +
|
||||||
"applyGroups=" + this.isApplyGroups() + ", " +
|
"applyGroups=" + this.applyGroups + ", " +
|
||||||
"applyGlobalGroups=" + this.isApplyGlobalGroups() + ", " +
|
"applyGlobalGroups=" + this.applyGlobalGroups + ", " +
|
||||||
"applyGlobalWorldGroups=" + this.isApplyGlobalWorldGroups() +
|
"applyGlobalWorldGroups=" + this.applyGlobalWorldGroups + ")";
|
||||||
")";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -230,33 +230,23 @@ public class Contexts {
|
|||||||
if (o == this) return true;
|
if (o == this) return true;
|
||||||
if (o == allowAll()) return false;
|
if (o == allowAll()) return false;
|
||||||
if (!(o instanceof Contexts)) return false;
|
if (!(o instanceof Contexts)) return false;
|
||||||
|
final Contexts that = (Contexts) o;
|
||||||
|
|
||||||
final Contexts other = (Contexts) o;
|
return this.context.equals(that.context) &&
|
||||||
return this.getContexts().equals(other.getContexts()) &&
|
this.op == that.op &&
|
||||||
this.isOp() == other.isOp() &&
|
this.includeGlobal == that.includeGlobal &&
|
||||||
this.isIncludeGlobal() == other.isIncludeGlobal() &&
|
this.includeGlobalWorld == that.includeGlobalWorld &&
|
||||||
this.isIncludeGlobalWorld() == other.isIncludeGlobalWorld() &&
|
this.applyGroups == that.applyGroups &&
|
||||||
this.isApplyGroups() == other.isApplyGroups() &&
|
this.applyGlobalGroups == that.applyGlobalGroups &&
|
||||||
this.isApplyGlobalGroups() == other.isApplyGlobalGroups() &&
|
this.applyGlobalWorldGroups == that.applyGlobalWorldGroups;
|
||||||
this.isApplyGlobalWorldGroups() == other.isApplyGlobalWorldGroups();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int calculateHashCode() {
|
private int calculateHashCode() {
|
||||||
final int PRIME = 59;
|
return Objects.hash(this.context, this.op, this.includeGlobal, this.includeGlobalWorld, this.applyGroups, this.applyGlobalGroups, this.applyGlobalWorldGroups);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return hashCode;
|
return this.hashCode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ public enum DataMutateResult {
|
|||||||
* @return a boolean representation
|
* @return a boolean representation
|
||||||
*/
|
*/
|
||||||
public boolean asBoolean() {
|
public boolean asBoolean() {
|
||||||
return value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -72,7 +72,7 @@ public enum DataMutateResult {
|
|||||||
* @since 3.4
|
* @since 3.4
|
||||||
*/
|
*/
|
||||||
public boolean wasSuccess() {
|
public boolean wasSuccess() {
|
||||||
return value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -82,7 +82,7 @@ public enum DataMutateResult {
|
|||||||
* @since 3.4
|
* @since 3.4
|
||||||
*/
|
*/
|
||||||
public boolean wasFailure() {
|
public boolean wasFailure() {
|
||||||
return !value;
|
return !this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -96,6 +96,6 @@ public enum Tristate {
|
|||||||
* @return a boolean representation of the Tristate.
|
* @return a boolean representation of the Tristate.
|
||||||
*/
|
*/
|
||||||
public boolean asBoolean() {
|
public boolean asBoolean() {
|
||||||
return booleanValue;
|
return this.booleanValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,11 +25,11 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.api.caching;
|
package me.lucko.luckperms.api.caching;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
|
|
||||||
import me.lucko.luckperms.api.Contexts;
|
import me.lucko.luckperms.api.Contexts;
|
||||||
import me.lucko.luckperms.api.metastacking.MetaStackDefinition;
|
import me.lucko.luckperms.api.metastacking.MetaStackDefinition;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
@ -71,9 +71,9 @@ public final class MetaContexts {
|
|||||||
* @param suffixStackDefinition the suffix stack definition to be used
|
* @param suffixStackDefinition the suffix stack definition to be used
|
||||||
*/
|
*/
|
||||||
public MetaContexts(@Nonnull Contexts contexts, @Nonnull MetaStackDefinition prefixStackDefinition, @Nonnull MetaStackDefinition suffixStackDefinition) {
|
public MetaContexts(@Nonnull Contexts contexts, @Nonnull MetaStackDefinition prefixStackDefinition, @Nonnull MetaStackDefinition suffixStackDefinition) {
|
||||||
this.contexts = Preconditions.checkNotNull(contexts, "contexts");
|
this.contexts = Objects.requireNonNull(contexts, "contexts");
|
||||||
this.prefixStackDefinition = Preconditions.checkNotNull(prefixStackDefinition, "prefixStackDefinition");
|
this.prefixStackDefinition = Objects.requireNonNull(prefixStackDefinition, "prefixStackDefinition");
|
||||||
this.suffixStackDefinition = Preconditions.checkNotNull(suffixStackDefinition, "suffixStackDefinition");
|
this.suffixStackDefinition = Objects.requireNonNull(suffixStackDefinition, "suffixStackDefinition");
|
||||||
this.hashCode = calculateHashCode();
|
this.hashCode = calculateHashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,23 +106,18 @@ public final class MetaContexts {
|
|||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (o == this) return true;
|
if (o == this) return true;
|
||||||
if (!(o instanceof MetaContexts)) return false;
|
if (!(o instanceof MetaContexts)) return false;
|
||||||
final MetaContexts other = (MetaContexts) o;
|
final MetaContexts that = (MetaContexts) o;
|
||||||
return this.getContexts().equals(other.getContexts()) &&
|
return this.contexts.equals(that.contexts) &&
|
||||||
this.getPrefixStackDefinition().equals(other.getPrefixStackDefinition()) &&
|
this.prefixStackDefinition.equals(that.prefixStackDefinition) &&
|
||||||
this.getSuffixStackDefinition().equals(other.getSuffixStackDefinition());
|
this.suffixStackDefinition.equals(that.suffixStackDefinition);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int calculateHashCode() {
|
private int calculateHashCode() {
|
||||||
final int PRIME = 59;
|
return Objects.hash(this.contexts, this.prefixStackDefinition, this.suffixStackDefinition);
|
||||||
int result = 1;
|
|
||||||
result = result * PRIME + this.getContexts().hashCode();
|
|
||||||
result = result * PRIME + this.getPrefixStackDefinition().hashCode();
|
|
||||||
result = result * PRIME + this.getSuffixStackDefinition().hashCode();
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
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.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
|
||||||
|
|
||||||
abstract class AbstractContextSet implements ContextSet {
|
abstract class AbstractContextSet implements ContextSet {
|
||||||
|
|
||||||
protected abstract Multimap<String, String> backing();
|
protected abstract Multimap<String, String> backing();
|
||||||
@ -104,14 +103,14 @@ abstract class AbstractContextSet implements ContextSet {
|
|||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (o == this) return true;
|
if (o == this) return true;
|
||||||
if (!(o instanceof ContextSet)) return false;
|
if (!(o instanceof ContextSet)) return false;
|
||||||
final ContextSet other = (ContextSet) o;
|
final ContextSet that = (ContextSet) o;
|
||||||
|
|
||||||
final Multimap<String, String> otherContexts;
|
final Multimap<String, String> otherContexts;
|
||||||
|
|
||||||
if (other instanceof AbstractContextSet) {
|
if (that instanceof AbstractContextSet) {
|
||||||
otherContexts = ((AbstractContextSet) other).backing();
|
otherContexts = ((AbstractContextSet) that).backing();
|
||||||
} else {
|
} else {
|
||||||
otherContexts = other.toMultimap();
|
otherContexts = that.toMultimap();
|
||||||
}
|
}
|
||||||
|
|
||||||
return backing().equals(otherContexts);
|
return backing().equals(otherContexts);
|
||||||
@ -123,11 +122,11 @@ abstract class AbstractContextSet implements ContextSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static String sanitizeKey(String key) {
|
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) {
|
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
|
* @param calculator the calculator
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
|
||||||
void registerCalculator(@Nonnull ContextCalculator<?> calculator);
|
void registerCalculator(@Nonnull ContextCalculator<?> calculator);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -163,7 +162,6 @@ public interface ContextManager {
|
|||||||
*
|
*
|
||||||
* @param calculator the calculator
|
* @param calculator the calculator
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
|
||||||
void registerStaticCalculator(@Nonnull StaticContextCalculator calculator);
|
void registerStaticCalculator(@Nonnull StaticContextCalculator calculator);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -171,7 +169,6 @@ public interface ContextManager {
|
|||||||
*
|
*
|
||||||
* @param subject the subject
|
* @param subject the subject
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
|
||||||
void invalidateCache(@Nonnull Object subject);
|
void invalidateCache(@Nonnull Object subject);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,10 +25,10 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.api.context;
|
package me.lucko.luckperms.api.context;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@ -302,7 +302,7 @@ public interface ContextSet {
|
|||||||
* @throws NullPointerException if the key or value is null
|
* @throws NullPointerException if the key or value is null
|
||||||
*/
|
*/
|
||||||
default boolean has(@Nonnull Map.Entry<String, String> entry) {
|
default boolean has(@Nonnull Map.Entry<String, String> entry) {
|
||||||
Preconditions.checkNotNull(entry, "entry");
|
Objects.requireNonNull(entry, "entry");
|
||||||
return has(entry.getKey(), entry.getValue());
|
return has(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -317,7 +317,7 @@ public interface ContextSet {
|
|||||||
* @throws NullPointerException if the key or value is null
|
* @throws NullPointerException if the key or value is null
|
||||||
*/
|
*/
|
||||||
default boolean hasIgnoreCase(@Nonnull Map.Entry<String, String> entry) {
|
default boolean hasIgnoreCase(@Nonnull Map.Entry<String, String> entry) {
|
||||||
Preconditions.checkNotNull(entry, "entry");
|
Objects.requireNonNull(entry, "entry");
|
||||||
return hasIgnoreCase(entry.getKey(), entry.getValue());
|
return hasIgnoreCase(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -358,7 +358,7 @@ public interface ContextSet {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Preconditions.checkNotNull(other, "other");
|
Objects.requireNonNull(other, "other");
|
||||||
if (this.isEmpty()) {
|
if (this.isEmpty()) {
|
||||||
// this is empty, so is therefore always satisfied.
|
// this is empty, so is therefore always satisfied.
|
||||||
return true;
|
return true;
|
||||||
|
@ -29,13 +29,12 @@ import com.google.common.collect.ImmutableSetMultimap;
|
|||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An immutable implementation of {@link ContextSet}.
|
* An immutable implementation of {@link ContextSet}.
|
||||||
*
|
*
|
||||||
@ -99,7 +98,7 @@ public final class ImmutableContextSet extends AbstractContextSet implements Con
|
|||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static ImmutableContextSet fromEntries(@Nonnull Iterable<? extends Map.Entry<String, String>> iterable) {
|
public static ImmutableContextSet fromEntries(@Nonnull Iterable<? extends Map.Entry<String, String>> iterable) {
|
||||||
checkNotNull(iterable, "iterable");
|
Objects.requireNonNull(iterable, "iterable");
|
||||||
ImmutableContextSet.Builder builder = builder();
|
ImmutableContextSet.Builder builder = builder();
|
||||||
for (Map.Entry<String, String> entry : iterable) {
|
for (Map.Entry<String, String> entry : iterable) {
|
||||||
builder.add(entry);
|
builder.add(entry);
|
||||||
@ -116,7 +115,7 @@ public final class ImmutableContextSet extends AbstractContextSet implements Con
|
|||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static ImmutableContextSet fromMap(@Nonnull Map<String, String> map) {
|
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
|
@Nonnull
|
||||||
public static ImmutableContextSet fromMultimap(@Nonnull Multimap<String, String> multimap) {
|
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
|
@Nonnull
|
||||||
public static ImmutableContextSet fromSet(@Nonnull ContextSet contextSet) {
|
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) {
|
ImmutableContextSet(ImmutableSetMultimap<String, String> contexts) {
|
||||||
this.map = contexts;
|
this.map = contexts;
|
||||||
this.hashCode = map.hashCode();
|
this.hashCode = this.map.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Multimap<String, String> backing() {
|
protected Multimap<String, String> backing() {
|
||||||
return map;
|
return this.map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -190,18 +189,18 @@ public final class ImmutableContextSet extends AbstractContextSet implements Con
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Set<Map.Entry<String, String>> toSet() {
|
public Set<Map.Entry<String, String>> toSet() {
|
||||||
return map.entries();
|
return this.map.entries();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Multimap<String, String> toMultimap() {
|
public Multimap<String, String> toMultimap() {
|
||||||
return map;
|
return this.map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return hashCode;
|
return this.hashCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -222,10 +221,10 @@ public final class ImmutableContextSet extends AbstractContextSet implements Con
|
|||||||
}
|
}
|
||||||
|
|
||||||
private synchronized ImmutableSetMultimap.Builder<String, String> builder() {
|
private synchronized ImmutableSetMultimap.Builder<String, String> builder() {
|
||||||
if (builder == null) {
|
if (this.builder == null) {
|
||||||
builder = ImmutableSetMultimap.builder();
|
this.builder = ImmutableSetMultimap.builder();
|
||||||
}
|
}
|
||||||
return builder;
|
return this.builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void put(String key, String value) {
|
private void put(String key, String value) {
|
||||||
@ -257,7 +256,7 @@ public final class ImmutableContextSet extends AbstractContextSet implements Con
|
|||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public Builder add(@Nonnull Map.Entry<String, String> entry) {
|
public Builder add(@Nonnull Map.Entry<String, String> entry) {
|
||||||
checkNotNull(entry, "entry");
|
Objects.requireNonNull(entry, "entry");
|
||||||
add(entry.getKey(), entry.getValue());
|
add(entry.getKey(), entry.getValue());
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -272,7 +271,7 @@ public final class ImmutableContextSet extends AbstractContextSet implements Con
|
|||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public Builder addAll(@Nonnull Iterable<? extends Map.Entry<String, String>> iterable) {
|
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);
|
add(e);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
@ -288,7 +287,7 @@ public final class ImmutableContextSet extends AbstractContextSet implements Con
|
|||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public Builder addAll(@Nonnull Map<String, String> map) {
|
public Builder addAll(@Nonnull Map<String, String> map) {
|
||||||
addAll(checkNotNull(map, "map").entrySet());
|
addAll(Objects.requireNonNull(map, "map").entrySet());
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -303,7 +302,7 @@ public final class ImmutableContextSet extends AbstractContextSet implements Con
|
|||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public Builder addAll(@Nonnull Multimap<String, String> multimap) {
|
public Builder addAll(@Nonnull Multimap<String, String> multimap) {
|
||||||
addAll(checkNotNull(multimap, "multimap").entries());
|
addAll(Objects.requireNonNull(multimap, "multimap").entries());
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -317,7 +316,7 @@ public final class ImmutableContextSet extends AbstractContextSet implements Con
|
|||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public Builder addAll(@Nonnull ContextSet contextSet) {
|
public Builder addAll(@Nonnull ContextSet contextSet) {
|
||||||
checkNotNull(contextSet, "contextSet");
|
Objects.requireNonNull(contextSet, "contextSet");
|
||||||
if (contextSet instanceof AbstractContextSet) {
|
if (contextSet instanceof AbstractContextSet) {
|
||||||
AbstractContextSet other = ((AbstractContextSet) contextSet);
|
AbstractContextSet other = ((AbstractContextSet) contextSet);
|
||||||
if (!other.isEmpty()) {
|
if (!other.isEmpty()) {
|
||||||
@ -337,10 +336,10 @@ public final class ImmutableContextSet extends AbstractContextSet implements Con
|
|||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public ImmutableContextSet build() {
|
public ImmutableContextSet build() {
|
||||||
if (builder == null) {
|
if (this.builder == null) {
|
||||||
return empty();
|
return empty();
|
||||||
} else {
|
} else {
|
||||||
return new ImmutableContextSet(builder.build());
|
return new ImmutableContextSet(this.builder.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.api.context;
|
package me.lucko.luckperms.api.context;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
import com.google.common.collect.HashMultimap;
|
import com.google.common.collect.HashMultimap;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.ImmutableSetMultimap;
|
import com.google.common.collect.ImmutableSetMultimap;
|
||||||
@ -35,12 +34,11 @@ import com.google.common.collect.SetMultimap;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A mutable implementation of {@link ContextSet}.
|
* A mutable implementation of {@link ContextSet}.
|
||||||
*
|
*
|
||||||
@ -58,8 +56,8 @@ public final class MutableContextSet extends AbstractContextSet implements Conte
|
|||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static MutableContextSet singleton(@Nonnull String key, @Nonnull String value) {
|
public static MutableContextSet singleton(@Nonnull String key, @Nonnull String value) {
|
||||||
checkNotNull(key, "key");
|
Objects.requireNonNull(key, "key");
|
||||||
checkNotNull(value, "value");
|
Objects.requireNonNull(value, "value");
|
||||||
MutableContextSet set = MutableContextSet.create();
|
MutableContextSet set = MutableContextSet.create();
|
||||||
set.add(key, value);
|
set.add(key, value);
|
||||||
return set;
|
return set;
|
||||||
@ -78,10 +76,10 @@ public final class MutableContextSet extends AbstractContextSet implements Conte
|
|||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static MutableContextSet of(@Nonnull String key1, @Nonnull String value1, @Nonnull String key2, @Nonnull String value2) {
|
public static MutableContextSet of(@Nonnull String key1, @Nonnull String value1, @Nonnull String key2, @Nonnull String value2) {
|
||||||
checkNotNull(key1, "key1");
|
Objects.requireNonNull(key1, "key1");
|
||||||
checkNotNull(value1, "value1");
|
Objects.requireNonNull(value1, "value1");
|
||||||
checkNotNull(key2, "key2");
|
Objects.requireNonNull(key2, "key2");
|
||||||
checkNotNull(value2, "value2");
|
Objects.requireNonNull(value2, "value2");
|
||||||
MutableContextSet set = create();
|
MutableContextSet set = create();
|
||||||
set.add(key1, value1);
|
set.add(key1, value1);
|
||||||
set.add(key2, value2);
|
set.add(key2, value2);
|
||||||
@ -97,7 +95,7 @@ public final class MutableContextSet extends AbstractContextSet implements Conte
|
|||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static MutableContextSet fromEntries(@Nonnull Iterable<? extends Map.Entry<String, String>> iterable) {
|
public static MutableContextSet fromEntries(@Nonnull Iterable<? extends Map.Entry<String, String>> iterable) {
|
||||||
checkNotNull(iterable, "iterable");
|
Objects.requireNonNull(iterable, "iterable");
|
||||||
MutableContextSet set = create();
|
MutableContextSet set = create();
|
||||||
set.addAll(iterable);
|
set.addAll(iterable);
|
||||||
return set;
|
return set;
|
||||||
@ -112,7 +110,7 @@ public final class MutableContextSet extends AbstractContextSet implements Conte
|
|||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static MutableContextSet fromMap(@Nonnull Map<String, String> map) {
|
public static MutableContextSet fromMap(@Nonnull Map<String, String> map) {
|
||||||
checkNotNull(map, "map");
|
Objects.requireNonNull(map, "map");
|
||||||
MutableContextSet set = create();
|
MutableContextSet set = create();
|
||||||
set.addAll(map);
|
set.addAll(map);
|
||||||
return set;
|
return set;
|
||||||
@ -128,7 +126,7 @@ public final class MutableContextSet extends AbstractContextSet implements Conte
|
|||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static MutableContextSet fromMultimap(@Nonnull Multimap<String, String> multimap) {
|
public static MutableContextSet fromMultimap(@Nonnull Multimap<String, String> multimap) {
|
||||||
checkNotNull(multimap, "multimap");
|
Objects.requireNonNull(multimap, "multimap");
|
||||||
MutableContextSet set = create();
|
MutableContextSet set = create();
|
||||||
set.addAll(multimap);
|
set.addAll(multimap);
|
||||||
return set;
|
return set;
|
||||||
@ -145,7 +143,7 @@ public final class MutableContextSet extends AbstractContextSet implements Conte
|
|||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static MutableContextSet fromSet(@Nonnull ContextSet contextSet) {
|
public static MutableContextSet fromSet(@Nonnull ContextSet contextSet) {
|
||||||
Preconditions.checkNotNull(contextSet, "contextSet");
|
Objects.requireNonNull(contextSet, "contextSet");
|
||||||
MutableContextSet set = create();
|
MutableContextSet set = create();
|
||||||
set.addAll(contextSet);
|
set.addAll(contextSet);
|
||||||
return set;
|
return set;
|
||||||
@ -173,7 +171,7 @@ public final class MutableContextSet extends AbstractContextSet implements Conte
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Multimap<String, String> backing() {
|
protected Multimap<String, String> backing() {
|
||||||
return map;
|
return this.map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -185,10 +183,10 @@ public final class MutableContextSet extends AbstractContextSet implements Conte
|
|||||||
@Override
|
@Override
|
||||||
public ImmutableContextSet makeImmutable() {
|
public ImmutableContextSet makeImmutable() {
|
||||||
// if the map is empty, don't create a new instance
|
// if the map is empty, don't create a new instance
|
||||||
if (map.isEmpty()) {
|
if (this.map.isEmpty()) {
|
||||||
return ImmutableContextSet.empty();
|
return ImmutableContextSet.empty();
|
||||||
}
|
}
|
||||||
return new ImmutableContextSet(ImmutableSetMultimap.copyOf(map));
|
return new ImmutableContextSet(ImmutableSetMultimap.copyOf(this.map));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@ -200,13 +198,13 @@ public final class MutableContextSet extends AbstractContextSet implements Conte
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Set<Map.Entry<String, String>> toSet() {
|
public Set<Map.Entry<String, String>> toSet() {
|
||||||
return ImmutableSet.copyOf(map.entries());
|
return ImmutableSet.copyOf(this.map.entries());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Multimap<String, String> toMultimap() {
|
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
|
* @throws NullPointerException if the key or value is null
|
||||||
*/
|
*/
|
||||||
public void add(@Nonnull String key, @Nonnull String value) {
|
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
|
* @throws NullPointerException if the entry is null
|
||||||
*/
|
*/
|
||||||
public void add(@Nonnull Map.Entry<String, String> entry) {
|
public void add(@Nonnull Map.Entry<String, String> entry) {
|
||||||
checkNotNull(entry, "entry");
|
Objects.requireNonNull(entry, "entry");
|
||||||
add(entry.getKey(), entry.getValue());
|
add(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,7 +236,7 @@ public final class MutableContextSet extends AbstractContextSet implements Conte
|
|||||||
* @throws NullPointerException if iterable is null
|
* @throws NullPointerException if iterable is null
|
||||||
*/
|
*/
|
||||||
public void addAll(@Nonnull Iterable<? extends Map.Entry<String, String>> iterable) {
|
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);
|
add(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -250,7 +248,7 @@ public final class MutableContextSet extends AbstractContextSet implements Conte
|
|||||||
* @throws NullPointerException if the map is null
|
* @throws NullPointerException if the map is null
|
||||||
*/
|
*/
|
||||||
public void addAll(@Nonnull Map<String, String> map) {
|
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
|
* @since 3.4
|
||||||
*/
|
*/
|
||||||
public void addAll(@Nonnull Multimap<String, String> multimap) {
|
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
|
* @throws NullPointerException if the contextSet is null
|
||||||
*/
|
*/
|
||||||
public void addAll(@Nonnull ContextSet contextSet) {
|
public void addAll(@Nonnull ContextSet contextSet) {
|
||||||
checkNotNull(contextSet, "contextSet");
|
Objects.requireNonNull(contextSet, "contextSet");
|
||||||
if (contextSet instanceof AbstractContextSet) {
|
if (contextSet instanceof AbstractContextSet) {
|
||||||
AbstractContextSet other = ((AbstractContextSet) contextSet);
|
AbstractContextSet other = ((AbstractContextSet) contextSet);
|
||||||
this.map.putAll(other.backing());
|
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
|
* @throws NullPointerException if the key or value is null
|
||||||
*/
|
*/
|
||||||
public void remove(@Nonnull String key, @Nonnull String value) {
|
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) {
|
public void removeIgnoreCase(@Nonnull String key, @Nonnull String value) {
|
||||||
String v = sanitizeValue(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) {
|
if (strings != null) {
|
||||||
strings.removeIf(e -> e.equalsIgnoreCase(v));
|
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
|
* @throws NullPointerException if the key is null
|
||||||
*/
|
*/
|
||||||
public void removeAll(@Nonnull String key) {
|
public void removeAll(@Nonnull String key) {
|
||||||
map.removeAll(sanitizeKey(key));
|
this.map.removeAll(sanitizeKey(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes all contexts from the set.
|
* Removes all contexts from the set.
|
||||||
*/
|
*/
|
||||||
public void clear() {
|
public void clear() {
|
||||||
map.clear();
|
this.map.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -51,6 +51,6 @@ public enum PlatformType {
|
|||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public String getFriendlyName() {
|
public String getFriendlyName() {
|
||||||
return friendlyName;
|
return this.friendlyName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,11 +92,10 @@
|
|||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- Lombok -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>com.google.code.findbugs</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>jsr305</artifactId>
|
||||||
<version>${lombok.version}</version>
|
<version>3.0.2</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- LilyPad -->
|
<!-- LilyPad -->
|
||||||
@ -166,6 +165,16 @@
|
|||||||
<artifactId>bukkit-permissions</artifactId>
|
<artifactId>bukkit-permissions</artifactId>
|
||||||
<version>2.5</version>
|
<version>2.5</version>
|
||||||
<scope>provided</scope>
|
<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>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
@ -52,7 +52,7 @@ public class BukkitCommandExecutor extends CommandManager implements CommandExec
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
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)));
|
List<String> arguments = stripQuotes(ARGUMENT_SPLITTER.splitToList(ARGUMENT_JOINER.join(args)));
|
||||||
|
|
||||||
onCommand(lpSender, label, arguments);
|
onCommand(lpSender, label, arguments);
|
||||||
@ -61,7 +61,7 @@ public class BukkitCommandExecutor extends CommandManager implements CommandExec
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
|
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)));
|
List<String> arguments = stripQuotes(TAB_COMPLETE_ARGUMENT_SPLITTER.splitToList(ARGUMENT_JOINER.join(args)));
|
||||||
|
|
||||||
return onTabComplete(lpSender, arguments);
|
return onTabComplete(lpSender, arguments);
|
||||||
|
@ -52,38 +52,38 @@ public class BukkitConfigAdapter extends AbstractConfigurationAdapter implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reload() {
|
public void reload() {
|
||||||
configuration = YamlConfiguration.loadConfiguration(file);
|
this.configuration = YamlConfiguration.loadConfiguration(this.file);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean contains(String path) {
|
public boolean contains(String path) {
|
||||||
return configuration.contains(path);
|
return this.configuration.contains(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getString(String path, String def) {
|
public String getString(String path, String def) {
|
||||||
return configuration.getString(path, def);
|
return this.configuration.getString(path, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getInt(String path, int def) {
|
public int getInt(String path, int def) {
|
||||||
return configuration.getInt(path, def);
|
return this.configuration.getInt(path, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean getBoolean(String path, boolean def) {
|
public boolean getBoolean(String path, boolean def) {
|
||||||
return configuration.getBoolean(path, def);
|
return this.configuration.getBoolean(path, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getList(String path, List<String> def) {
|
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;
|
return ret == null ? def : ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getObjectList(String path, List<String> def) {
|
public List<String> getObjectList(String path, List<String> def) {
|
||||||
ConfigurationSection section = configuration.getConfigurationSection(path);
|
ConfigurationSection section = this.configuration.getConfigurationSection(path);
|
||||||
if (section == null) {
|
if (section == null) {
|
||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
@ -95,7 +95,7 @@ public class BukkitConfigAdapter extends AbstractConfigurationAdapter implements
|
|||||||
@Override
|
@Override
|
||||||
public Map<String, String> getMap(String path, Map<String, String> def) {
|
public Map<String, String> getMap(String path, Map<String, String> def) {
|
||||||
Map<String, String> map = new HashMap<>();
|
Map<String, String> map = new HashMap<>();
|
||||||
ConfigurationSection section = configuration.getConfigurationSection(path);
|
ConfigurationSection section = this.configuration.getConfigurationSection(path);
|
||||||
if (section == null) {
|
if (section == null) {
|
||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
|
@ -25,10 +25,6 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.bukkit;
|
package me.lucko.luckperms.bukkit;
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
|
|
||||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||||
|
|
||||||
import me.lucko.luckperms.common.plugin.SchedulerAdapter;
|
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.ThreadPoolExecutor;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
public class BukkitSchedulerAdapter implements SchedulerAdapter {
|
public class BukkitSchedulerAdapter implements SchedulerAdapter {
|
||||||
private final LPBukkitPlugin plugin;
|
private final LPBukkitPlugin plugin;
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Accessors(fluent = true)
|
|
||||||
private final ExecutorService asyncFallback;
|
private final ExecutorService asyncFallback;
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Accessors(fluent = true)
|
|
||||||
private final Executor asyncBukkit;
|
private final Executor asyncBukkit;
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Accessors(fluent = true)
|
|
||||||
private final Executor sync;
|
private final Executor sync;
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Accessors(fluent = true)
|
|
||||||
private final Executor async;
|
private final Executor async;
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
private boolean useFallback = true;
|
private boolean useFallback = true;
|
||||||
|
|
||||||
private final Set<BukkitTask> tasks = ConcurrentHashMap.newKeySet();
|
private final Set<BukkitTask> tasks = ConcurrentHashMap.newKeySet();
|
||||||
@ -89,61 +74,84 @@ public class BukkitSchedulerAdapter implements SchedulerAdapter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void asyncRepeating(Runnable runnable, long intervalTicks) {
|
public void asyncRepeating(Runnable runnable, long intervalTicks) {
|
||||||
BukkitTask task = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, runnable, intervalTicks, intervalTicks);
|
BukkitTask task = this.plugin.getServer().getScheduler().runTaskTimerAsynchronously(this.plugin, runnable, intervalTicks, intervalTicks);
|
||||||
tasks.add(task);
|
this.tasks.add(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void syncRepeating(Runnable runnable, long intervalTicks) {
|
public void syncRepeating(Runnable runnable, long intervalTicks) {
|
||||||
BukkitTask task = plugin.getServer().getScheduler().runTaskTimer(plugin, runnable, intervalTicks, intervalTicks);
|
BukkitTask task = this.plugin.getServer().getScheduler().runTaskTimer(this.plugin, runnable, intervalTicks, intervalTicks);
|
||||||
tasks.add(task);
|
this.tasks.add(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void asyncLater(Runnable runnable, long delayTicks) {
|
public void asyncLater(Runnable runnable, long delayTicks) {
|
||||||
plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, runnable, delayTicks);
|
this.plugin.getServer().getScheduler().runTaskLaterAsynchronously(this.plugin, runnable, delayTicks);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void syncLater(Runnable runnable, long delayTicks) {
|
public void syncLater(Runnable runnable, long delayTicks) {
|
||||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, runnable, delayTicks);
|
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, runnable, delayTicks);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
tasks.forEach(BukkitTask::cancel);
|
this.tasks.forEach(BukkitTask::cancel);
|
||||||
|
|
||||||
// wait for executor
|
// wait for executor
|
||||||
asyncFallback.shutdown();
|
this.asyncFallback.shutdown();
|
||||||
try {
|
try {
|
||||||
asyncFallback.awaitTermination(30, TimeUnit.SECONDS);
|
this.asyncFallback.awaitTermination(30, TimeUnit.SECONDS);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
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 {
|
private final class SyncExecutor implements Executor {
|
||||||
@Override
|
@Override
|
||||||
public void execute(Runnable runnable) {
|
public void execute(@Nonnull Runnable runnable) {
|
||||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, runnable);
|
BukkitSchedulerAdapter.this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(BukkitSchedulerAdapter.this.plugin, runnable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final class AsyncExecutor implements Executor {
|
private final class AsyncExecutor implements Executor {
|
||||||
@Override
|
@Override
|
||||||
public void execute(Runnable runnable) {
|
public void execute(@Nonnull Runnable runnable) {
|
||||||
if (useFallback || !plugin.isEnabled()) {
|
if (BukkitSchedulerAdapter.this.useFallback || !BukkitSchedulerAdapter.this.plugin.isEnabled()) {
|
||||||
asyncFallback.execute(runnable);
|
BukkitSchedulerAdapter.this.asyncFallback.execute(runnable);
|
||||||
} else {
|
} else {
|
||||||
asyncBukkit.execute(runnable);
|
BukkitSchedulerAdapter.this.asyncBukkit.execute(runnable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final class BukkitAsyncExecutor implements Executor {
|
private final class BukkitAsyncExecutor implements Executor {
|
||||||
@Override
|
@Override
|
||||||
public void execute(Runnable runnable) {
|
public void execute(@Nonnull Runnable runnable) {
|
||||||
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, runnable);
|
BukkitSchedulerAdapter.this.plugin.getServer().getScheduler().runTaskAsynchronously(BukkitSchedulerAdapter.this.plugin, runnable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,8 +25,6 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.bukkit;
|
package me.lucko.luckperms.bukkit;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
|
|
||||||
import me.lucko.luckperms.api.Tristate;
|
import me.lucko.luckperms.api.Tristate;
|
||||||
import me.lucko.luckperms.bukkit.compat.BukkitJsonMessageHandler;
|
import me.lucko.luckperms.bukkit.compat.BukkitJsonMessageHandler;
|
||||||
import me.lucko.luckperms.bukkit.compat.ReflectionUtil;
|
import me.lucko.luckperms.bukkit.compat.ReflectionUtil;
|
||||||
@ -51,8 +49,8 @@ public class BukkitSenderFactory extends SenderFactory<CommandSender> {
|
|||||||
|
|
||||||
public BukkitSenderFactory(LuckPermsPlugin plugin) {
|
public BukkitSenderFactory(LuckPermsPlugin plugin) {
|
||||||
super(plugin);
|
super(plugin);
|
||||||
bukkitHandler = new BukkitJsonMessageHandler();
|
this.bukkitHandler = new BukkitJsonMessageHandler();
|
||||||
spigotHandler = isSpigot() ? new SpigotJsonMessageHandler() : null;
|
this.spigotHandler = isSpigot() ? new SpigotJsonMessageHandler() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -89,12 +87,12 @@ public class BukkitSenderFactory extends SenderFactory<CommandSender> {
|
|||||||
String json = ComponentSerializers.JSON.serialize(message);
|
String json = ComponentSerializers.JSON.serialize(message);
|
||||||
|
|
||||||
// Try Bukkit.
|
// Try Bukkit.
|
||||||
if (bukkitHandler.sendJsonMessage(player, json)) {
|
if (this.bukkitHandler.sendJsonMessage(player, json)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try Spigot.
|
// Try Spigot.
|
||||||
if (spigotHandler != null && spigotHandler.sendJsonMessage(player, json)) {
|
if (this.spigotHandler != null && this.spigotHandler.sendJsonMessage(player, json)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -125,14 +123,18 @@ public class BukkitSenderFactory extends SenderFactory<CommandSender> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@AllArgsConstructor
|
|
||||||
private static final class BlockMessengerAgent implements Runnable {
|
private static final class BlockMessengerAgent implements Runnable {
|
||||||
private final BlockCommandSender block;
|
private final BlockCommandSender block;
|
||||||
private final String message;
|
private final String message;
|
||||||
|
|
||||||
|
private BlockMessengerAgent(BlockCommandSender block, String message) {
|
||||||
|
this.block = block;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
block.sendMessage(message);
|
this.block.sendMessage(this.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,8 +25,6 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.bukkit;
|
package me.lucko.luckperms.bukkit;
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import me.lucko.luckperms.api.Contexts;
|
import me.lucko.luckperms.api.Contexts;
|
||||||
import me.lucko.luckperms.api.LuckPermsApi;
|
import me.lucko.luckperms.api.LuckPermsApi;
|
||||||
import me.lucko.luckperms.api.platform.PlatformType;
|
import me.lucko.luckperms.api.platform.PlatformType;
|
||||||
@ -110,7 +108,6 @@ import java.util.stream.Stream;
|
|||||||
/**
|
/**
|
||||||
* LuckPerms implementation for the Bukkit API.
|
* LuckPerms implementation for the Bukkit API.
|
||||||
*/
|
*/
|
||||||
@Getter
|
|
||||||
public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||||
|
|
||||||
private long startTime;
|
private long startTime;
|
||||||
@ -150,13 +147,13 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// setup minimal functionality in order to load initial dependencies
|
// setup minimal functionality in order to load initial dependencies
|
||||||
scheduler = new BukkitSchedulerAdapter(this);
|
this.scheduler = new BukkitSchedulerAdapter(this);
|
||||||
localeManager = new NoopLocaleManager();
|
this.localeManager = new NoopLocaleManager();
|
||||||
senderFactory = new BukkitSenderFactory(this);
|
this.senderFactory = new BukkitSenderFactory(this);
|
||||||
log = new SenderLogger(this, getConsoleSender());
|
this.log = new SenderLogger(this, getConsoleSender());
|
||||||
|
|
||||||
dependencyManager = new DependencyManager(this);
|
this.dependencyManager = new DependencyManager(this);
|
||||||
dependencyManager.loadDependencies(Collections.singleton(Dependency.CAFFEINE));
|
this.dependencyManager.loadDependencies(Collections.singleton(Dependency.CAFFEINE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -178,103 +175,103 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
|||||||
} finally {
|
} finally {
|
||||||
// count down the latch when onEnable has been called
|
// count down the latch when onEnable has been called
|
||||||
// we don't care about the result here
|
// we don't care about the result here
|
||||||
enableLatch.countDown();
|
this.enableLatch.countDown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enable() {
|
private void enable() {
|
||||||
startTime = System.currentTimeMillis();
|
this.startTime = System.currentTimeMillis();
|
||||||
sendStartupBanner(getConsoleSender());
|
sendStartupBanner(getConsoleSender());
|
||||||
verboseHandler = new VerboseHandler(scheduler.asyncBukkit(), getVersion());
|
this.verboseHandler = new VerboseHandler(this.scheduler.asyncBukkit(), getVersion());
|
||||||
permissionVault = new PermissionVault(scheduler.asyncBukkit());
|
this.permissionVault = new PermissionVault(this.scheduler.asyncBukkit());
|
||||||
logDispatcher = new LogDispatcher(this);
|
this.logDispatcher = new LogDispatcher(this);
|
||||||
|
|
||||||
getLog().info("Loading configuration...");
|
getLog().info("Loading configuration...");
|
||||||
configuration = new AbstractConfiguration(this, new BukkitConfigAdapter(this, resolveConfig("config.yml")));
|
this.configuration = new AbstractConfiguration(this, new BukkitConfigAdapter(this, resolveConfig("config.yml")));
|
||||||
configuration.loadAll();
|
this.configuration.loadAll();
|
||||||
|
|
||||||
StorageFactory storageFactory = new StorageFactory(this);
|
StorageFactory storageFactory = new StorageFactory(this);
|
||||||
Set<StorageType> storageTypes = storageFactory.getRequiredTypes(StorageType.H2);
|
Set<StorageType> storageTypes = storageFactory.getRequiredTypes(StorageType.H2);
|
||||||
dependencyManager.loadStorageDependencies(storageTypes);
|
this.dependencyManager.loadStorageDependencies(storageTypes);
|
||||||
|
|
||||||
// setup the Bukkit defaults hook
|
// setup the Bukkit defaults hook
|
||||||
defaultsProvider = new DefaultsProvider();
|
this.defaultsProvider = new DefaultsProvider();
|
||||||
childPermissionProvider = new ChildPermissionProvider();
|
this.childPermissionProvider = new ChildPermissionProvider();
|
||||||
|
|
||||||
// give all plugins a chance to load their permissions, then refresh.
|
// 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
|
// register events
|
||||||
getServer().getPluginManager().registerEvents(new BukkitConnectionListener(this), this);
|
getServer().getPluginManager().registerEvents(new BukkitConnectionListener(this), this);
|
||||||
getServer().getPluginManager().registerEvents(new BukkitPlatformListener(this), this);
|
getServer().getPluginManager().registerEvents(new BukkitPlatformListener(this), this);
|
||||||
|
|
||||||
if (getConfiguration().get(ConfigKeys.WATCH_FILES)) {
|
if (getConfiguration().get(ConfigKeys.WATCH_FILES)) {
|
||||||
fileWatcher = new FileWatcher(this);
|
this.fileWatcher = new FileWatcher(this);
|
||||||
getScheduler().asyncRepeating(fileWatcher, 30L);
|
getScheduler().asyncRepeating(this.fileWatcher, 30L);
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialise datastore
|
// initialise datastore
|
||||||
storage = storageFactory.getInstance(StorageType.H2);
|
this.storage = storageFactory.getInstance(StorageType.H2);
|
||||||
|
|
||||||
// initialise messaging
|
// initialise messaging
|
||||||
messagingService = new BukkitMessagingFactory(this).getInstance();
|
this.messagingService = new BukkitMessagingFactory(this).getInstance();
|
||||||
|
|
||||||
// setup the update task buffer
|
// setup the update task buffer
|
||||||
updateTaskBuffer = new UpdateTaskBuffer(this);
|
this.updateTaskBuffer = new UpdateTaskBuffer(this);
|
||||||
|
|
||||||
// load locale
|
// load locale
|
||||||
localeManager = new SimpleLocaleManager();
|
this.localeManager = new SimpleLocaleManager();
|
||||||
localeManager.tryLoad(this, new File(getDataFolder(), "lang.yml"));
|
this.localeManager.tryLoad(this, new File(getDataFolder(), "lang.yml"));
|
||||||
|
|
||||||
// register commands
|
// register commands
|
||||||
commandManager = new BukkitCommandExecutor(this);
|
this.commandManager = new BukkitCommandExecutor(this);
|
||||||
PluginCommand main = getServer().getPluginCommand("luckperms");
|
PluginCommand main = getServer().getPluginCommand("luckperms");
|
||||||
main.setExecutor(commandManager);
|
main.setExecutor(this.commandManager);
|
||||||
main.setTabCompleter(commandManager);
|
main.setTabCompleter(this.commandManager);
|
||||||
main.setDescription("Manage permissions");
|
main.setDescription("Manage permissions");
|
||||||
main.setAliases(Arrays.asList("lp", "perm", "perms", "permission", "permissions"));
|
main.setAliases(Arrays.asList("lp", "perm", "perms", "permission", "permissions"));
|
||||||
|
|
||||||
// load internal managers
|
// load internal managers
|
||||||
getLog().info("Loading internal permission managers...");
|
getLog().info("Loading internal permission managers...");
|
||||||
uuidCache = new UuidCache(this);
|
this.uuidCache = new UuidCache(this);
|
||||||
userManager = new GenericUserManager(this);
|
this.userManager = new GenericUserManager(this);
|
||||||
groupManager = new GenericGroupManager(this);
|
this.groupManager = new GenericGroupManager(this);
|
||||||
trackManager = new GenericTrackManager(this);
|
this.trackManager = new GenericTrackManager(this);
|
||||||
calculatorFactory = new BukkitCalculatorFactory(this);
|
this.calculatorFactory = new BukkitCalculatorFactory(this);
|
||||||
cachedStateManager = new CachedStateManager();
|
this.cachedStateManager = new CachedStateManager();
|
||||||
|
|
||||||
// setup context manager
|
// setup context manager
|
||||||
contextManager = new BukkitContextManager(this);
|
this.contextManager = new BukkitContextManager(this);
|
||||||
contextManager.registerCalculator(new WorldCalculator(this));
|
this.contextManager.registerCalculator(new WorldCalculator(this));
|
||||||
contextManager.registerStaticCalculator(new LuckPermsCalculator(getConfiguration()));
|
this.contextManager.registerStaticCalculator(new LuckPermsCalculator(getConfiguration()));
|
||||||
|
|
||||||
// inject our own subscription map
|
// inject our own subscription map
|
||||||
new SubscriptionMapInjector(this).run();
|
new SubscriptionMapInjector(this).run();
|
||||||
|
|
||||||
// schedule another injection after all plugins have loaded - the entire pluginmanager instance
|
// schedule another injection after all plugins have loaded - the entire pluginmanager instance
|
||||||
// is replaced by some plugins :(
|
// is replaced by some plugins :(
|
||||||
scheduler.asyncLater(new SubscriptionMapInjector(this), 2L);
|
this.scheduler.asyncLater(new SubscriptionMapInjector(this), 2L);
|
||||||
|
|
||||||
// Provide vault support
|
// Provide vault support
|
||||||
tryVaultHook(false);
|
tryVaultHook(false);
|
||||||
|
|
||||||
// register with the LP API
|
// register with the LP API
|
||||||
apiProvider = new LuckPermsApiProvider(this);
|
this.apiProvider = new LuckPermsApiProvider(this);
|
||||||
|
|
||||||
// setup event factory
|
// setup event factory
|
||||||
eventFactory = new EventFactory(this, apiProvider);
|
this.eventFactory = new EventFactory(this, this.apiProvider);
|
||||||
|
|
||||||
ApiRegistrationUtil.registerProvider(apiProvider);
|
ApiRegistrationUtil.registerProvider(this.apiProvider);
|
||||||
getServer().getServicesManager().register(LuckPermsApi.class, apiProvider, this, ServicePriority.Normal);
|
getServer().getServicesManager().register(LuckPermsApi.class, this.apiProvider, this, ServicePriority.Normal);
|
||||||
|
|
||||||
|
|
||||||
// schedule update tasks
|
// schedule update tasks
|
||||||
int mins = getConfiguration().get(ConfigKeys.SYNC_TIME);
|
int mins = getConfiguration().get(ConfigKeys.SYNC_TIME);
|
||||||
if (mins > 0) {
|
if (mins > 0) {
|
||||||
long ticks = mins * 60 * 20;
|
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.
|
// run an update instantly.
|
||||||
getLog().info("Performing initial data load...");
|
getLog().info("Performing initial data load...");
|
||||||
@ -286,8 +283,8 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
|||||||
|
|
||||||
|
|
||||||
// register tasks
|
// register tasks
|
||||||
scheduler.asyncRepeating(new ExpireTemporaryTask(this), 60L);
|
this.scheduler.asyncRepeating(new ExpireTemporaryTask(this), 60L);
|
||||||
scheduler.asyncRepeating(new CacheHousekeepingTask(this), 2400L);
|
this.scheduler.asyncRepeating(new CacheHousekeepingTask(this), 2400L);
|
||||||
|
|
||||||
// register permissions
|
// register permissions
|
||||||
try {
|
try {
|
||||||
@ -302,20 +299,20 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!getConfiguration().get(ConfigKeys.OPS_ENABLED)) {
|
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
|
// 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)
|
// Load any online users (in the case of a reload)
|
||||||
for (Player player : getServer().getOnlinePlayers()) {
|
for (Player player : getServer().getOnlinePlayers()) {
|
||||||
scheduler.doAsync(() -> {
|
this.scheduler.doAsync(() -> {
|
||||||
try {
|
try {
|
||||||
LoginHelper.loadUser(this, player.getUniqueId(), player.getName(), false);
|
LoginHelper.loadUser(this, player.getUniqueId(), player.getName(), false);
|
||||||
User user = getUserManager().getIfLoaded(getUuidCache().getUUID(player.getUniqueId()));
|
User user = getUserManager().getIfLoaded(getUuidCache().getUUID(player.getUniqueId()));
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
scheduler.doSync(() -> {
|
this.scheduler.doSync(() -> {
|
||||||
try {
|
try {
|
||||||
LPPermissible lpPermissible = new LPPermissible(player, user, this);
|
LPPermissible lpPermissible = new LPPermissible(player, user, this);
|
||||||
PermissibleInjector.inject(player, lpPermissible);
|
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
|
@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
|
// Switch back to the fallback executor, the bukkit one won't allow new tasks
|
||||||
scheduler.setUseFallback(true);
|
this.scheduler.setUseFallback(true);
|
||||||
|
|
||||||
defaultsProvider.close();
|
this.defaultsProvider.close();
|
||||||
permissionVault.shutdown();
|
this.permissionVault.shutdown();
|
||||||
verboseHandler.shutdown();
|
this.verboseHandler.shutdown();
|
||||||
|
|
||||||
// uninject from players
|
// uninject from players
|
||||||
for (Player player : getServer().getOnlinePlayers()) {
|
for (Player player : getServer().getOnlinePlayers()) {
|
||||||
@ -369,26 +366,26 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
|||||||
SubscriptionMapInjector.uninject();
|
SubscriptionMapInjector.uninject();
|
||||||
|
|
||||||
getLog().info("Closing storage...");
|
getLog().info("Closing storage...");
|
||||||
storage.shutdown();
|
this.storage.shutdown();
|
||||||
|
|
||||||
if (fileWatcher != null) {
|
if (this.fileWatcher != null) {
|
||||||
fileWatcher.close();
|
this.fileWatcher.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (messagingService != null) {
|
if (this.messagingService != null) {
|
||||||
getLog().info("Closing messaging service...");
|
getLog().info("Closing messaging service...");
|
||||||
messagingService.close();
|
this.messagingService.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
ApiRegistrationUtil.unregisterProvider();
|
ApiRegistrationUtil.unregisterProvider();
|
||||||
getServer().getServicesManager().unregisterAll(this);
|
getServer().getServicesManager().unregisterAll(this);
|
||||||
|
|
||||||
if (vaultHookManager != null) {
|
if (this.vaultHookManager != null) {
|
||||||
vaultHookManager.unhook(this);
|
this.vaultHookManager.unhook(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
getLog().info("Shutting down internal scheduler...");
|
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.
|
// Bukkit will do this again when #onDisable completes, but we do it early to prevent NPEs elsewhere.
|
||||||
getServer().getScheduler().cancelTasks(this);
|
getServer().getScheduler().cancelTasks(this);
|
||||||
@ -397,18 +394,18 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void tryVaultHook(boolean force) {
|
public void tryVaultHook(boolean force) {
|
||||||
if (vaultHookManager != null) {
|
if (this.vaultHookManager != null) {
|
||||||
return; // already hooked
|
return; // already hooked
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (force || getServer().getPluginManager().isPluginEnabled("Vault")) {
|
if (force || getServer().getPluginManager().isPluginEnabled("Vault")) {
|
||||||
vaultHookManager = new VaultHookManager();
|
this.vaultHookManager = new VaultHookManager();
|
||||||
vaultHookManager.hook(this);
|
this.vaultHookManager.hook(this);
|
||||||
getLog().info("Registered Vault permission & chat hook.");
|
getLog().info("Registered Vault permission & chat hook.");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
vaultHookManager = null;
|
this.vaultHookManager = null;
|
||||||
getLog().severe("Error occurred whilst hooking into Vault.");
|
getLog().severe("Error occurred whilst hooking into Vault.");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -420,7 +417,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (getConfiguration().get(ConfigKeys.AUTO_OP)) {
|
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);
|
boolean op = Optional.ofNullable(backing.get("luckperms.autoop")).orElse(false);
|
||||||
player.setOp(op);
|
player.setOp(op);
|
||||||
}
|
}
|
||||||
@ -439,11 +436,12 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<ExtendedMessagingService> getMessagingService() {
|
public Optional<ExtendedMessagingService> getMessagingService() {
|
||||||
return Optional.ofNullable(messagingService);
|
return Optional.ofNullable(this.messagingService);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Optional<FileWatcher> getFileWatcher() {
|
public Optional<FileWatcher> getFileWatcher() {
|
||||||
return Optional.ofNullable(fileWatcher);
|
return Optional.ofNullable(this.fileWatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -483,7 +481,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Player getPlayer(User user) {
|
public Player getPlayer(User user) {
|
||||||
return getServer().getPlayer(uuidCache.getExternalUUID(user.getUuid()));
|
return getServer().getPlayer(this.uuidCache.getExternalUUID(user.getUuid()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -503,7 +501,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
|||||||
if (player == null) {
|
if (player == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return contextManager.getApplicableContexts(player);
|
return this.contextManager.getApplicableContexts(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -543,9 +541,9 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
|||||||
@Override
|
@Override
|
||||||
public Map<String, Object> getExtraInfo() {
|
public Map<String, Object> getExtraInfo() {
|
||||||
Map<String, Object> map = new LinkedHashMap<>();
|
Map<String, Object> map = new LinkedHashMap<>();
|
||||||
map.put("Vault Enabled", vaultHookManager != null);
|
map.put("Vault Enabled", this.vaultHookManager != null);
|
||||||
map.put("Bukkit Defaults count", defaultsProvider.size());
|
map.put("Bukkit Defaults count", this.defaultsProvider.size());
|
||||||
map.put("Bukkit Child Permissions count", childPermissionProvider.getPermissions().size());
|
map.put("Bukkit Child Permissions count", this.childPermissionProvider.getPermissions().size());
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -557,4 +555,134 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
|||||||
return true;
|
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;
|
package me.lucko.luckperms.bukkit.calculators;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.Contexts;
|
import me.lucko.luckperms.api.Contexts;
|
||||||
@ -45,44 +43,47 @@ import me.lucko.luckperms.common.references.HolderType;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class BukkitCalculatorFactory extends AbstractCalculatorFactory {
|
public class BukkitCalculatorFactory extends AbstractCalculatorFactory {
|
||||||
private final LPBukkitPlugin plugin;
|
private final LPBukkitPlugin plugin;
|
||||||
|
|
||||||
|
public BukkitCalculatorFactory(LPBukkitPlugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PermissionCalculator build(Contexts contexts, PermissionCalculatorMetadata metadata) {
|
public PermissionCalculator build(Contexts contexts, PermissionCalculatorMetadata metadata) {
|
||||||
ImmutableList.Builder<PermissionProcessor> processors = ImmutableList.builder();
|
ImmutableList.Builder<PermissionProcessor> processors = ImmutableList.builder();
|
||||||
|
|
||||||
processors.add(new MapProcessor());
|
processors.add(new MapProcessor());
|
||||||
|
|
||||||
if (plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_CHILD_PERMISSIONS)) {
|
if (this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_CHILD_PERMISSIONS)) {
|
||||||
processors.add(new ChildProcessor(plugin.getChildPermissionProvider()));
|
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());
|
processors.add(new RegexProcessor());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin.getConfiguration().get(ConfigKeys.APPLYING_WILDCARDS)) {
|
if (this.plugin.getConfiguration().get(ConfigKeys.APPLYING_WILDCARDS)) {
|
||||||
processors.add(new WildcardProcessor());
|
processors.add(new WildcardProcessor());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_DEFAULT_PERMISSIONS) && metadata.getHolderType() == HolderType.USER) {
|
if (this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_DEFAULT_PERMISSIONS) && metadata.getHolderType() == HolderType.USER) {
|
||||||
processors.add(new DefaultsProcessor(contexts.isOp(), plugin.getDefaultsProvider()));
|
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
|
@Override
|
||||||
public List<String> getActiveProcessors() {
|
public List<String> getActiveProcessors() {
|
||||||
ImmutableList.Builder<String> ret = ImmutableList.builder();
|
ImmutableList.Builder<String> ret = ImmutableList.builder();
|
||||||
ret.add("Map");
|
ret.add("Map");
|
||||||
if (plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_CHILD_PERMISSIONS)) ret.add("Child");
|
if (this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_CHILD_PERMISSIONS)) ret.add("Child");
|
||||||
if (plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_ATTACHMENT_PERMISSIONS)) ret.add("Attachment");
|
if (this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_ATTACHMENT_PERMISSIONS)) ret.add("Attachment");
|
||||||
if (plugin.getConfiguration().get(ConfigKeys.APPLYING_REGEX)) ret.add("Regex");
|
if (this.plugin.getConfiguration().get(ConfigKeys.APPLYING_REGEX)) ret.add("Regex");
|
||||||
if (plugin.getConfiguration().get(ConfigKeys.APPLYING_WILDCARDS)) ret.add("Wildcard");
|
if (this.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_DEFAULT_PERMISSIONS)) ret.add("Defaults");
|
||||||
return ret.build();
|
return ret.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,12 +25,9 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.bukkit.compat;
|
package me.lucko.luckperms.bukkit.compat;
|
||||||
|
|
||||||
import lombok.experimental.UtilityClass;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
@UtilityClass
|
public final class ReflectionUtil {
|
||||||
public class ReflectionUtil {
|
|
||||||
private static final String SERVER_VERSION = _getServerVersion();
|
private static final String SERVER_VERSION = _getServerVersion();
|
||||||
private static final boolean CHAT_COMPATIBLE = !SERVER_VERSION.startsWith(".v1_7_");
|
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 {
|
public static Class<?> obcClass(String className) throws ClassNotFoundException {
|
||||||
return Class.forName(obc(className));
|
return Class.forName(obc(className));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ReflectionUtil() {}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -42,11 +42,11 @@ public class BukkitContextManager extends AbstractContextManager<Player> {
|
|||||||
public Contexts formContexts(Player subject, ImmutableContextSet contextSet) {
|
public Contexts formContexts(Player subject, ImmutableContextSet contextSet) {
|
||||||
return new Contexts(
|
return new Contexts(
|
||||||
contextSet,
|
contextSet,
|
||||||
plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_PERMS),
|
this.plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_PERMS),
|
||||||
plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS),
|
this.plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS),
|
||||||
true,
|
true,
|
||||||
plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_GROUPS),
|
this.plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_GROUPS),
|
||||||
plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_WORLD_GROUPS),
|
this.plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_WORLD_GROUPS),
|
||||||
subject.isOp()
|
subject.isOp()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,6 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.bukkit.contexts;
|
package me.lucko.luckperms.bukkit.contexts;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
|
|
||||||
import me.lucko.luckperms.api.Contexts;
|
import me.lucko.luckperms.api.Contexts;
|
||||||
import me.lucko.luckperms.api.context.ContextCalculator;
|
import me.lucko.luckperms.api.context.ContextCalculator;
|
||||||
import me.lucko.luckperms.api.context.MutableContextSet;
|
import me.lucko.luckperms.api.context.MutableContextSet;
|
||||||
@ -35,16 +33,22 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
|||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
public class WorldCalculator implements ContextCalculator<Player> {
|
public class WorldCalculator implements ContextCalculator<Player> {
|
||||||
private final LuckPermsPlugin plugin;
|
private final LuckPermsPlugin plugin;
|
||||||
|
|
||||||
|
public WorldCalculator(LuckPermsPlugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public MutableContextSet giveApplicableContext(Player subject, MutableContextSet accumulator) {
|
public MutableContextSet giveApplicableContext(@Nonnull Player subject, @Nonnull MutableContextSet accumulator) {
|
||||||
String world = subject.getWorld().getName().toLowerCase();
|
String world = subject.getWorld().getName().toLowerCase();
|
||||||
while (!accumulator.has(Contexts.WORLD_KEY, world)) {
|
while (!accumulator.has(Contexts.WORLD_KEY, world)) {
|
||||||
accumulator.add(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;
|
return accumulator;
|
||||||
|
@ -25,8 +25,6 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.bukkit.listeners;
|
package me.lucko.luckperms.bukkit.listeners;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
|
|
||||||
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
|
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
|
||||||
import me.lucko.luckperms.bukkit.model.LPPermissible;
|
import me.lucko.luckperms.bukkit.model.LPPermissible;
|
||||||
import me.lucko.luckperms.bukkit.model.PermissibleInjector;
|
import me.lucko.luckperms.bukkit.model.PermissibleInjector;
|
||||||
@ -49,13 +47,16 @@ import java.util.Set;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class BukkitConnectionListener implements Listener {
|
public class BukkitConnectionListener implements Listener {
|
||||||
private final LPBukkitPlugin plugin;
|
private final LPBukkitPlugin plugin;
|
||||||
|
|
||||||
private final Set<UUID> deniedAsyncLogin = Collections.synchronizedSet(new HashSet<>());
|
private final Set<UUID> deniedAsyncLogin = Collections.synchronizedSet(new HashSet<>());
|
||||||
private final Set<UUID> deniedLogin = Collections.synchronizedSet(new HashSet<>());
|
private final Set<UUID> deniedLogin = Collections.synchronizedSet(new HashSet<>());
|
||||||
|
|
||||||
|
public BukkitConnectionListener(LPBukkitPlugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOW)
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
public void onPlayerPreLogin(AsyncPlayerPreLoginEvent e) {
|
public void onPlayerPreLogin(AsyncPlayerPreLoginEvent e) {
|
||||||
/* Called when the player first attempts a connection with the server.
|
/* 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
|
/* wait for the plugin to enable. because these events are fired async, they can be called before
|
||||||
the plugin has enabled. */
|
the plugin has enabled. */
|
||||||
try {
|
try {
|
||||||
plugin.getEnableLatch().await(60, TimeUnit.SECONDS);
|
this.plugin.getEnableLatch().await(60, TimeUnit.SECONDS);
|
||||||
} catch (InterruptedException ex) {
|
} catch (InterruptedException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) {
|
if (this.plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) {
|
||||||
plugin.getLog().info("Processing pre-login for " + e.getUniqueId() + " - " + e.getName());
|
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.
|
/* Actually process the login for the connection.
|
||||||
We do this here to delay the login until the data is ready.
|
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.
|
- creating a user instance in the UserManager for this connection.
|
||||||
- setting up cached data. */
|
- setting up cached data. */
|
||||||
try {
|
try {
|
||||||
User user = LoginHelper.loadUser(plugin, e.getUniqueId(), e.getName(), false);
|
User user = LoginHelper.loadUser(this.plugin, e.getUniqueId(), e.getName(), false);
|
||||||
plugin.getEventFactory().handleUserLoginProcess(e.getUniqueId(), e.getName(), user);
|
this.plugin.getEventFactory().handleUserLoginProcess(e.getUniqueId(), e.getName(), user);
|
||||||
} catch (Exception ex) {
|
} 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();
|
ex.printStackTrace();
|
||||||
|
|
||||||
// deny the connection
|
// deny the connection
|
||||||
deniedAsyncLogin.add(e.getUniqueId());
|
this.deniedAsyncLogin.add(e.getUniqueId());
|
||||||
e.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, Message.LOADING_ERROR.asString(plugin.getLocaleManager()));
|
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. */
|
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.
|
// 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.
|
// 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.
|
// This is a problem, as they were denied at low priority, but are now being allowed.
|
||||||
if (e.getLoginResult() == AsyncPlayerPreLoginEvent.Result.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, "");
|
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
|
// Login event was cancelled by another plugin, but it wasn't cancelled when we handled it at LOW
|
||||||
if (e.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED) {
|
if (e.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED) {
|
||||||
// Schedule cleanup of this user.
|
// 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();
|
final Player player = e.getPlayer();
|
||||||
|
|
||||||
if (plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) {
|
if (this.plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) {
|
||||||
plugin.getLog().info("Processing login for " + player.getUniqueId() + " - " + player.getName());
|
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. */
|
/* User instance is null for whatever reason. Could be that it was unloaded between asyncpre and now. */
|
||||||
if (user == null) {
|
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.");
|
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(plugin.getLocaleManager()));
|
e.disallow(PlayerLoginEvent.Result.KICK_OTHER, Message.LOADING_ERROR.asString(this.plugin.getLocaleManager()));
|
||||||
return;
|
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.
|
// Care should be taken at this stage to ensure that async tasks which manipulate bukkit data check that the player is still online.
|
||||||
try {
|
try {
|
||||||
// Make a new permissible for the user
|
// 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
|
// Inject into the player
|
||||||
PermissibleInjector.inject(player, lpPermissible);
|
PermissibleInjector.inject(player, lpPermissible);
|
||||||
@ -157,7 +158,7 @@ public class BukkitConnectionListener implements Listener {
|
|||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.refreshAutoOp(user, player);
|
this.plugin.refreshAutoOp(user, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@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.
|
// 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;
|
boolean denied = false;
|
||||||
if (deniedLogin.remove(e.getPlayer().getUniqueId())) {
|
if (this.deniedLogin.remove(e.getPlayer().getUniqueId())) {
|
||||||
denied = true;
|
denied = true;
|
||||||
|
|
||||||
// This is a problem, as they were denied at low priority, but are now being allowed.
|
// This is a problem, as they were denied at low priority, but are now being allowed.
|
||||||
if (e.getResult() == PlayerLoginEvent.Result.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, "");
|
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
|
// Login event was cancelled by another plugin since we first loaded their data
|
||||||
if (denied || e.getResult() != PlayerLoginEvent.Result.ALLOWED) {
|
if (denied || e.getResult() != PlayerLoginEvent.Result.ALLOWED) {
|
||||||
// Schedule cleanup of this user.
|
// Schedule cleanup of this user.
|
||||||
plugin.getUserManager().scheduleUnload(e.getPlayer().getUniqueId());
|
this.plugin.getUserManager().scheduleUnload(e.getPlayer().getUniqueId());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// everything is going well. login was processed ok, this is just to refresh auto-op status.
|
// 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
|
// 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
|
// Handle auto op
|
||||||
if (plugin.getConfiguration().get(ConfigKeys.AUTO_OP)) {
|
if (this.plugin.getConfiguration().get(ConfigKeys.AUTO_OP)) {
|
||||||
player.setOp(false);
|
player.setOp(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Request that the users data is unloaded.
|
// 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;
|
package me.lucko.luckperms.bukkit.listeners;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
|
|
||||||
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
|
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
|
||||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||||
import me.lucko.luckperms.common.locale.Message;
|
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.RemoteServerCommandEvent;
|
||||||
import org.bukkit.event.server.ServerCommandEvent;
|
import org.bukkit.event.server.ServerCommandEvent;
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class BukkitPlatformListener implements Listener {
|
public class BukkitPlatformListener implements Listener {
|
||||||
private final LPBukkitPlugin plugin;
|
private final LPBukkitPlugin plugin;
|
||||||
|
|
||||||
|
public BukkitPlatformListener(LPBukkitPlugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerCommand(PlayerCommandPreprocessEvent e) {
|
public void onPlayerCommand(PlayerCommandPreprocessEvent e) {
|
||||||
handleCommand(e.getPlayer(), e.getMessage().toLowerCase(), e);
|
handleCommand(e.getPlayer(), e.getMessage().toLowerCase(), e);
|
||||||
@ -66,7 +67,7 @@ public class BukkitPlatformListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin.getConfiguration().get(ConfigKeys.OPS_ENABLED)) {
|
if (this.plugin.getConfiguration().get(ConfigKeys.OPS_ENABLED)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,21 +81,21 @@ public class BukkitPlatformListener implements Listener {
|
|||||||
|
|
||||||
if (s.equals("op") || s.startsWith("op ") || s.equals("deop") || s.startsWith("deop ")) {
|
if (s.equals("op") || s.startsWith("op ") || s.equals("deop") || s.startsWith("deop ")) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
sender.sendMessage(Message.OP_DISABLED.asString(plugin.getLocaleManager()));
|
sender.sendMessage(Message.OP_DISABLED.asString(this.plugin.getLocaleManager()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPluginEnable(PluginEnableEvent e) {
|
public void onPluginEnable(PluginEnableEvent e) {
|
||||||
if (e.getPlugin().getName().equalsIgnoreCase("Vault")) {
|
if (e.getPlugin().getName().equalsIgnoreCase("Vault")) {
|
||||||
plugin.tryVaultHook(true);
|
this.plugin.tryVaultHook(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onWorldChange(PlayerChangedWorldEvent e) {
|
public void onWorldChange(PlayerChangedWorldEvent e) {
|
||||||
plugin.getContextManager().invalidateCache(e.getPlayer());
|
this.plugin.getContextManager().invalidateCache(e.getPlayer());
|
||||||
plugin.refreshAutoOp(plugin.getUserManager().getIfLoaded(e.getPlayer().getUniqueId()), 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() {
|
public void init() {
|
||||||
plugin.getServer().getMessenger().registerOutgoingPluginChannel(plugin, CHANNEL);
|
this.plugin.getServer().getMessenger().registerOutgoingPluginChannel(this.plugin, CHANNEL);
|
||||||
plugin.getServer().getMessenger().registerIncomingPluginChannel(plugin, CHANNEL, this);
|
this.plugin.getServer().getMessenger().registerIncomingPluginChannel(this.plugin, CHANNEL, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
plugin.getServer().getMessenger().unregisterIncomingPluginChannel(plugin, CHANNEL);
|
this.plugin.getServer().getMessenger().unregisterIncomingPluginChannel(this.plugin, CHANNEL);
|
||||||
plugin.getServer().getMessenger().unregisterOutgoingPluginChannel(plugin, CHANNEL);
|
this.plugin.getServer().getMessenger().unregisterOutgoingPluginChannel(this.plugin, CHANNEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -67,7 +67,7 @@ public class BungeeMessagingService extends AbstractMessagingService implements
|
|||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
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);
|
Player p = Iterables.getFirst(players, null);
|
||||||
if (p == null) {
|
if (p == null) {
|
||||||
return;
|
return;
|
||||||
@ -78,10 +78,10 @@ public class BungeeMessagingService extends AbstractMessagingService implements
|
|||||||
|
|
||||||
byte[] data = out.toByteArray();
|
byte[] data = out.toByteArray();
|
||||||
|
|
||||||
p.sendPluginMessage(plugin, CHANNEL, data);
|
p.sendPluginMessage(BungeeMessagingService.this.plugin, CHANNEL, data);
|
||||||
cancel();
|
cancel();
|
||||||
}
|
}
|
||||||
}.runTaskTimer(plugin, 1L, 100L);
|
}.runTaskTimer(this.plugin, 1L, 100L);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -51,13 +51,13 @@ public class LilyPadMessagingService extends AbstractMessagingService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void init() {
|
public void init() {
|
||||||
connect = plugin.getServer().getServicesManager().getRegistration(Connect.class).getProvider();
|
this.connect = this.plugin.getServer().getServicesManager().getRegistration(Connect.class).getProvider();
|
||||||
connect.registerEvents(this);
|
this.connect.registerEvents(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
connect.unregisterEvents(this);
|
this.connect.unregisterEvents(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -72,7 +72,7 @@ public class LilyPadMessagingService extends AbstractMessagingService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
connect.request(request);
|
this.connect.request(request);
|
||||||
} catch (RequestException e) {
|
} catch (RequestException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -80,7 +80,7 @@ public class LilyPadMessagingService extends AbstractMessagingService {
|
|||||||
|
|
||||||
@EventListener
|
@EventListener
|
||||||
public void onMessage(MessageEvent event) {
|
public void onMessage(MessageEvent event) {
|
||||||
plugin.getScheduler().doAsync(() -> {
|
this.plugin.getScheduler().doAsync(() -> {
|
||||||
try {
|
try {
|
||||||
String channel = event.getChannel();
|
String channel = event.getChannel();
|
||||||
|
|
||||||
|
@ -25,8 +25,6 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.bukkit.migration;
|
package me.lucko.luckperms.bukkit.migration;
|
||||||
|
|
||||||
import lombok.experimental.UtilityClass;
|
|
||||||
|
|
||||||
import me.lucko.luckperms.common.commands.utils.CommandUtils;
|
import me.lucko.luckperms.common.commands.utils.CommandUtils;
|
||||||
import me.lucko.luckperms.common.logging.ProgressLogger;
|
import me.lucko.luckperms.common.logging.ProgressLogger;
|
||||||
|
|
||||||
@ -34,8 +32,7 @@ import org.bukkit.Bukkit;
|
|||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@UtilityClass
|
public final class BukkitMigrationUtils {
|
||||||
public class BukkitMigrationUtils {
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public static UUID lookupUuid(ProgressLogger log, String s) {
|
public static UUID lookupUuid(ProgressLogger log, String s) {
|
||||||
@ -53,4 +50,6 @@ public class BukkitMigrationUtils {
|
|||||||
return uuid;
|
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.ChatMetaType;
|
||||||
import me.lucko.luckperms.api.event.cause.CreationCause;
|
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.CommandResult;
|
||||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||||
import me.lucko.luckperms.common.commands.impl.migration.MigrationUtils;
|
import me.lucko.luckperms.common.commands.impl.migration.MigrationUtils;
|
||||||
@ -77,7 +76,7 @@ public class MigrationBPermissions extends SubCommand<Object> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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");
|
ProgressLogger log = new ProgressLogger("bPermissions");
|
||||||
log.addListener(plugin.getConsoleSender());
|
log.addListener(plugin.getConsoleSender());
|
||||||
log.addListener(sender);
|
log.addListener(sender);
|
||||||
|
@ -28,7 +28,6 @@ package me.lucko.luckperms.bukkit.migration;
|
|||||||
import me.lucko.luckperms.api.ChatMetaType;
|
import me.lucko.luckperms.api.ChatMetaType;
|
||||||
import me.lucko.luckperms.api.Node;
|
import me.lucko.luckperms.api.Node;
|
||||||
import me.lucko.luckperms.api.event.cause.CreationCause;
|
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.CommandPermission;
|
||||||
import me.lucko.luckperms.common.commands.CommandResult;
|
import me.lucko.luckperms.common.commands.CommandResult;
|
||||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||||
@ -65,7 +64,7 @@ public class MigrationGroupManager extends SubCommand<Object> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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");
|
ProgressLogger log = new ProgressLogger("GroupManager");
|
||||||
log.addListener(plugin.getConsoleSender());
|
log.addListener(plugin.getConsoleSender());
|
||||||
log.addListener(sender);
|
log.addListener(sender);
|
||||||
|
@ -28,7 +28,6 @@ package me.lucko.luckperms.bukkit.migration;
|
|||||||
import com.platymuus.bukkit.permissions.PermissionsPlugin;
|
import com.platymuus.bukkit.permissions.PermissionsPlugin;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.event.cause.CreationCause;
|
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.CommandPermission;
|
||||||
import me.lucko.luckperms.common.commands.CommandResult;
|
import me.lucko.luckperms.common.commands.CommandResult;
|
||||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||||
@ -59,7 +58,7 @@ public class MigrationPermissionsBukkit extends SubCommand<Object> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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");
|
ProgressLogger log = new ProgressLogger("PermissionsBukkit");
|
||||||
log.addListener(plugin.getConsoleSender());
|
log.addListener(plugin.getConsoleSender());
|
||||||
log.addListener(sender);
|
log.addListener(sender);
|
||||||
|
@ -26,7 +26,6 @@
|
|||||||
package me.lucko.luckperms.bukkit.migration;
|
package me.lucko.luckperms.bukkit.migration;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.event.cause.CreationCause;
|
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.CommandPermission;
|
||||||
import me.lucko.luckperms.common.commands.CommandResult;
|
import me.lucko.luckperms.common.commands.CommandResult;
|
||||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||||
@ -67,7 +66,7 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
|||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@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");
|
ProgressLogger log = new ProgressLogger("PermissionsEx");
|
||||||
log.addListener(plugin.getConsoleSender());
|
log.addListener(plugin.getConsoleSender());
|
||||||
log.addListener(sender);
|
log.addListener(sender);
|
||||||
|
@ -34,7 +34,6 @@ import com.google.common.collect.ImmutableSet;
|
|||||||
|
|
||||||
import me.lucko.luckperms.api.Node;
|
import me.lucko.luckperms.api.Node;
|
||||||
import me.lucko.luckperms.api.event.cause.CreationCause;
|
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.CommandResult;
|
||||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||||
import me.lucko.luckperms.common.commands.impl.migration.MigrationUtils;
|
import me.lucko.luckperms.common.commands.impl.migration.MigrationUtils;
|
||||||
@ -77,7 +76,7 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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");
|
ProgressLogger log = new ProgressLogger("PowerfulPerms");
|
||||||
log.addListener(plugin.getConsoleSender());
|
log.addListener(plugin.getConsoleSender());
|
||||||
log.addListener(sender);
|
log.addListener(sender);
|
||||||
|
@ -28,7 +28,6 @@ package me.lucko.luckperms.bukkit.migration;
|
|||||||
import me.lucko.luckperms.api.ChatMetaType;
|
import me.lucko.luckperms.api.ChatMetaType;
|
||||||
import me.lucko.luckperms.api.Node;
|
import me.lucko.luckperms.api.Node;
|
||||||
import me.lucko.luckperms.api.event.cause.CreationCause;
|
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.CommandPermission;
|
||||||
import me.lucko.luckperms.common.commands.CommandResult;
|
import me.lucko.luckperms.common.commands.CommandResult;
|
||||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||||
@ -69,7 +68,7 @@ public class MigrationZPermissions extends SubCommand<Object> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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");
|
ProgressLogger log = new ProgressLogger("zPermissions");
|
||||||
log.addListener(plugin.getConsoleSender());
|
log.addListener(plugin.getConsoleSender());
|
||||||
log.addListener(sender);
|
log.addListener(sender);
|
||||||
|
@ -25,8 +25,6 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.bukkit.model;
|
package me.lucko.luckperms.bukkit.model;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
|
|
||||||
import org.bukkit.permissions.Permissible;
|
import org.bukkit.permissions.Permissible;
|
||||||
import org.bukkit.permissions.Permission;
|
import org.bukkit.permissions.Permission;
|
||||||
import org.bukkit.permissions.PermissionAttachment;
|
import org.bukkit.permissions.PermissionAttachment;
|
||||||
@ -36,13 +34,16 @@ import org.bukkit.plugin.Plugin;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class DummyPermissible implements Permissible {
|
public class DummyPermissible implements Permissible {
|
||||||
private final Runnable onRefresh;
|
private final Runnable onRefresh;
|
||||||
|
|
||||||
|
public DummyPermissible(Runnable onRefresh) {
|
||||||
|
this.onRefresh = onRefresh;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void recalculatePermissions() {
|
public void recalculatePermissions() {
|
||||||
onRefresh.run();
|
this.onRefresh.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public Set<PermissionAttachmentInfo> getEffectivePermissions() { return Collections.emptySet(); }
|
@Override public Set<PermissionAttachmentInfo> getEffectivePermissions() { return Collections.emptySet(); }
|
||||||
|
@ -25,10 +25,6 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.bukkit.model;
|
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.Contexts;
|
||||||
import me.lucko.luckperms.api.Tristate;
|
import me.lucko.luckperms.api.Tristate;
|
||||||
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
|
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
|
||||||
@ -46,6 +42,7 @@ import org.bukkit.plugin.Plugin;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
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,
|
* This class is **thread safe**. This means that when LuckPerms is installed on the server,
|
||||||
* is is safe to call Player#hasPermission asynchronously.
|
* is is safe to call Player#hasPermission asynchronously.
|
||||||
*/
|
*/
|
||||||
@Getter
|
|
||||||
public class LPPermissible extends PermissibleBase {
|
public class LPPermissible extends PermissibleBase {
|
||||||
|
|
||||||
// the LuckPerms user this permissible references.
|
// the LuckPerms user this permissible references.
|
||||||
@ -77,7 +73,6 @@ public class LPPermissible extends PermissibleBase {
|
|||||||
private final LPBukkitPlugin plugin;
|
private final LPBukkitPlugin plugin;
|
||||||
|
|
||||||
// the players previous permissible. (the one they had before this one was injected)
|
// the players previous permissible. (the one they had before this one was injected)
|
||||||
@Setter
|
|
||||||
private PermissibleBase oldPermissible = null;
|
private PermissibleBase oldPermissible = null;
|
||||||
|
|
||||||
// if the permissible is currently active.
|
// if the permissible is currently active.
|
||||||
@ -87,27 +82,35 @@ public class LPPermissible extends PermissibleBase {
|
|||||||
// this collection is only modified by the attachments themselves
|
// this collection is only modified by the attachments themselves
|
||||||
final Set<LPPermissionAttachment> attachments = ConcurrentHashMap.newKeySet();
|
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);
|
super(player);
|
||||||
this.user = user;
|
this.user = Objects.requireNonNull(user, "user");
|
||||||
this.player = player;
|
this.player = Objects.requireNonNull(player, "player");
|
||||||
this.plugin = plugin;
|
this.plugin = Objects.requireNonNull(plugin, "plugin");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isPermissionSet(@NonNull String permission) {
|
public boolean isPermissionSet(String permission) {
|
||||||
Tristate ts = user.getCachedData().getPermissionData(calculateContexts()).getPermissionValue(permission, CheckOrigin.PLATFORM_LOOKUP_CHECK);
|
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());
|
return ts != Tristate.UNDEFINED || Permission.DEFAULT_PERMISSION.getValue(isOp());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isPermissionSet(@NonNull Permission permission) {
|
public boolean isPermissionSet(Permission permission) {
|
||||||
Tristate ts = user.getCachedData().getPermissionData(calculateContexts()).getPermissionValue(permission.getName(), CheckOrigin.PLATFORM_LOOKUP_CHECK);
|
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) {
|
if (ts != Tristate.UNDEFINED) {
|
||||||
return true;
|
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());
|
return Permission.DEFAULT_PERMISSION.getValue(isOp());
|
||||||
} else {
|
} else {
|
||||||
return permission.getDefault().getValue(isOp());
|
return permission.getDefault().getValue(isOp());
|
||||||
@ -115,19 +118,27 @@ public class LPPermissible extends PermissibleBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPermission(@NonNull String permission) {
|
public boolean hasPermission(String permission) {
|
||||||
Tristate ts = user.getCachedData().getPermissionData(calculateContexts()).getPermissionValue(permission, CheckOrigin.PLATFORM_PERMISSION_CHECK);
|
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());
|
return ts != Tristate.UNDEFINED ? ts.asBoolean() : Permission.DEFAULT_PERMISSION.getValue(isOp());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPermission(@NonNull Permission permission) {
|
public boolean hasPermission(Permission permission) {
|
||||||
Tristate ts = user.getCachedData().getPermissionData(calculateContexts()).getPermissionValue(permission.getName(), CheckOrigin.PLATFORM_PERMISSION_CHECK);
|
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) {
|
if (ts != Tristate.UNDEFINED) {
|
||||||
return ts.asBoolean();
|
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());
|
return Permission.DEFAULT_PERMISSION.getValue(isOp());
|
||||||
} else {
|
} else {
|
||||||
return permission.getDefault().getValue(isOp());
|
return permission.getDefault().getValue(isOp());
|
||||||
@ -152,21 +163,21 @@ public class LPPermissible extends PermissibleBase {
|
|||||||
* @return the calculated contexts for the player.
|
* @return the calculated contexts for the player.
|
||||||
*/
|
*/
|
||||||
private Contexts calculateContexts() {
|
private Contexts calculateContexts() {
|
||||||
return plugin.getContextManager().getApplicableContexts(player);
|
return this.plugin.getContextManager().getApplicableContexts(this.player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setOp(boolean value) {
|
public void setOp(boolean value) {
|
||||||
player.setOp(value);
|
this.player.setOp(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<PermissionAttachmentInfo> getEffectivePermissions() {
|
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());
|
Set<PermissionAttachmentInfo> ret = new HashSet<>(permissions.size());
|
||||||
|
|
||||||
for (Map.Entry<String, Boolean> entry : permissions) {
|
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;
|
return ret;
|
||||||
@ -174,20 +185,35 @@ public class LPPermissible extends PermissibleBase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LPPermissionAttachment addAttachment(Plugin plugin) {
|
public LPPermissionAttachment addAttachment(Plugin plugin) {
|
||||||
|
if (plugin == null) {
|
||||||
|
throw new NullPointerException("plugin");
|
||||||
|
}
|
||||||
|
|
||||||
LPPermissionAttachment ret = new LPPermissionAttachment(this, plugin);
|
LPPermissionAttachment ret = new LPPermissionAttachment(this, plugin);
|
||||||
ret.hook();
|
ret.hook();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
PermissionAttachment ret = addAttachment(plugin);
|
||||||
ret.setPermission(name, value);
|
ret.setPermission(permission, value);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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()) {
|
if (!plugin.isEnabled()) {
|
||||||
throw new IllegalArgumentException("Plugin " + plugin.getDescription().getFullName() + " is not enabled");
|
throw new IllegalArgumentException("Plugin " + plugin.getDescription().getFullName() + " is not enabled");
|
||||||
}
|
}
|
||||||
@ -195,20 +221,31 @@ public class LPPermissible extends PermissibleBase {
|
|||||||
LPPermissionAttachment ret = addAttachment(plugin);
|
LPPermissionAttachment ret = addAttachment(plugin);
|
||||||
if (getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(plugin, ret::remove, ticks) == -1) {
|
if (getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(plugin, ret::remove, ticks) == -1) {
|
||||||
ret.remove();
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
LPPermissionAttachment ret = addAttachment(plugin, ticks);
|
||||||
ret.setPermission(name, value);
|
ret.setPermission(permission, value);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeAttachment(@NonNull PermissionAttachment attachment) {
|
public void removeAttachment(PermissionAttachment attachment) {
|
||||||
|
if (attachment == null) {
|
||||||
|
throw new NullPointerException("attachment");
|
||||||
|
}
|
||||||
|
|
||||||
if (!(attachment instanceof LPPermissionAttachment)) {
|
if (!(attachment instanceof LPPermissionAttachment)) {
|
||||||
throw new IllegalArgumentException("Given attachment is not a LPPermissionAttachment.");
|
throw new IllegalArgumentException("Given attachment is not a LPPermissionAttachment.");
|
||||||
}
|
}
|
||||||
@ -228,6 +265,30 @@ public class LPPermissible extends PermissibleBase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearPermissions() {
|
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;
|
package me.lucko.luckperms.bukkit.model;
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.Node;
|
import me.lucko.luckperms.api.Node;
|
||||||
@ -45,6 +42,7 @@ import java.util.Collection;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -74,7 +72,6 @@ public class LPPermissionAttachment extends PermissionAttachment {
|
|||||||
/**
|
/**
|
||||||
* The parent LPPermissible
|
* The parent LPPermissible
|
||||||
*/
|
*/
|
||||||
@Getter
|
|
||||||
private final LPPermissible permissible;
|
private final LPPermissible permissible;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -95,8 +92,6 @@ public class LPPermissionAttachment extends PermissionAttachment {
|
|||||||
/**
|
/**
|
||||||
* Callback to run when the attachment is removed
|
* Callback to run when the attachment is removed
|
||||||
*/
|
*/
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
private PermissionRemovedExecutor removalCallback = null;
|
private PermissionRemovedExecutor removalCallback = null;
|
||||||
|
|
||||||
public LPPermissionAttachment(LPPermissible permissible, Plugin owner) {
|
public LPPermissionAttachment(LPPermissible permissible, Plugin owner) {
|
||||||
@ -113,7 +108,7 @@ public class LPPermissionAttachment extends PermissionAttachment {
|
|||||||
this.owner = null;
|
this.owner = null;
|
||||||
|
|
||||||
// copy
|
// copy
|
||||||
perms.putAll(bukkit.getPermissions());
|
this.perms.putAll(bukkit.getPermissions());
|
||||||
|
|
||||||
injectFakeMap();
|
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.
|
* Hooks this attachment with the parent {@link User} instance.
|
||||||
*/
|
*/
|
||||||
public void hook() {
|
public void hook() {
|
||||||
hooked = true;
|
this.hooked = true;
|
||||||
permissible.attachments.add(this);
|
this.permissible.attachments.add(this);
|
||||||
for (Map.Entry<String, Boolean> entry : perms.entrySet()) {
|
for (Map.Entry<String, Boolean> entry : this.perms.entrySet()) {
|
||||||
if (entry.getKey() == null || entry.getKey().isEmpty()) {
|
if (entry.getKey() == null || entry.getKey().isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -153,7 +163,7 @@ public class LPPermissionAttachment extends PermissionAttachment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setPermissionInternal(String name, boolean value) {
|
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;
|
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
|
// we use the servers static context to *try* to ensure that the node will apply
|
||||||
Node node = NodeFactory.builder(name)
|
Node node = NodeFactory.builder(name)
|
||||||
.setValue(value)
|
.setValue(value)
|
||||||
.withExtraContext(permissible.getPlugin().getContextManager().getStaticContext())
|
.withExtraContext(this.permissible.getPlugin().getContextManager().getStaticContext())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// convert the constructed node to a transient node instance to refer back to this attachment
|
// convert the constructed node to a transient node instance to refer back to this attachment
|
||||||
ImmutableTransientNode transientNode = ImmutableTransientNode.of(node, this);
|
ImmutableTransientNode transientNode = ImmutableTransientNode.of(node, this);
|
||||||
|
|
||||||
// set the transient node
|
// set the transient node
|
||||||
User user = permissible.getUser();
|
User user = this.permissible.getUser();
|
||||||
if (user.setTransientPermission(transientNode).asBoolean()) {
|
if (user.setTransientPermission(transientNode).asBoolean()) {
|
||||||
user.reloadCachedData();
|
user.reloadCachedData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void unsetPermissionInternal(String name) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove transient permissions from the holder which were added by this attachment & equal the permission
|
// 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))) {
|
if (user.removeIfTransient(n -> n instanceof ImmutableTransientNode && ((ImmutableTransientNode) n).getOwner() == this && n.getPermission().equals(name))) {
|
||||||
user.reloadCachedData();
|
user.reloadCachedData();
|
||||||
}
|
}
|
||||||
@ -188,7 +198,7 @@ public class LPPermissionAttachment extends PermissionAttachment {
|
|||||||
|
|
||||||
private void clearInternal() {
|
private void clearInternal() {
|
||||||
// remove all transient permissions added by this attachment
|
// 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)) {
|
if (user.removeIfTransient(n -> n instanceof ImmutableTransientNode && ((ImmutableTransientNode) n).getOwner() == this)) {
|
||||||
user.reloadCachedData();
|
user.reloadCachedData();
|
||||||
}
|
}
|
||||||
@ -196,7 +206,7 @@ public class LPPermissionAttachment extends PermissionAttachment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean remove() {
|
public boolean remove() {
|
||||||
if (!hooked) {
|
if (!this.hooked) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,31 +214,31 @@ public class LPPermissionAttachment extends PermissionAttachment {
|
|||||||
clearInternal();
|
clearInternal();
|
||||||
|
|
||||||
// run the callback
|
// run the callback
|
||||||
if (removalCallback != null) {
|
if (this.removalCallback != null) {
|
||||||
removalCallback.attachmentRemoved(this);
|
this.removalCallback.attachmentRemoved(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// unhook from the permissible
|
// unhook from the permissible
|
||||||
hooked = false;
|
this.hooked = false;
|
||||||
permissible.attachments.remove(this);
|
this.permissible.attachments.remove(this);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPermission(String name, boolean value) {
|
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");
|
Preconditions.checkArgument(!name.isEmpty(), "name is empty");
|
||||||
|
|
||||||
String permission = name.toLowerCase();
|
String permission = name.toLowerCase();
|
||||||
|
|
||||||
Boolean previous = perms.put(permission, value);
|
Boolean previous = this.perms.put(permission, value);
|
||||||
if (previous != null && previous == value) {
|
if (previous != null && previous == value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we're not hooked, then don't actually apply the change
|
// if we're not hooked, then don't actually apply the change
|
||||||
// it will get applied on hook - if that ever happens
|
// it will get applied on hook - if that ever happens
|
||||||
if (!hooked) {
|
if (!this.hooked) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,19 +251,19 @@ public class LPPermissionAttachment extends PermissionAttachment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void unsetPermission(String name) {
|
public void unsetPermission(String name) {
|
||||||
Preconditions.checkNotNull(name, "name is null");
|
Objects.requireNonNull(name, "name is null");
|
||||||
Preconditions.checkArgument(!name.isEmpty(), "name is empty");
|
Preconditions.checkArgument(!name.isEmpty(), "name is empty");
|
||||||
|
|
||||||
String permission = name.toLowerCase();
|
String permission = name.toLowerCase();
|
||||||
|
|
||||||
Boolean previous = perms.remove(permission);
|
Boolean previous = this.perms.remove(permission);
|
||||||
if (previous == null) {
|
if (previous == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we're not hooked, then don't actually apply the change
|
// if we're not hooked, then don't actually apply the change
|
||||||
// it will get applied on hook - if that ever happens
|
// it will get applied on hook - if that ever happens
|
||||||
if (!hooked) {
|
if (!this.hooked) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,12 +272,12 @@ public class LPPermissionAttachment extends PermissionAttachment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Boolean> getPermissions() {
|
public Map<String, Boolean> getPermissions() {
|
||||||
return perms;
|
return this.perms;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Plugin getPlugin() {
|
public Plugin getPlugin() {
|
||||||
return owner != null ? owner : permissible.getPlugin();
|
return this.owner != null ? this.owner : this.permissible.getPlugin();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -295,7 +305,7 @@ public class LPPermissionAttachment extends PermissionAttachment {
|
|||||||
@Override
|
@Override
|
||||||
public Boolean put(String key, Boolean value) {
|
public Boolean put(String key, Boolean value) {
|
||||||
// grab the previous result, so we can still satisfy the method signature of Map
|
// 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
|
// proxy the call back through the PermissionAttachment instance
|
||||||
setPermission(key, value);
|
setPermission(key, value);
|
||||||
@ -314,7 +324,7 @@ public class LPPermissionAttachment extends PermissionAttachment {
|
|||||||
String permission = ((String) key);
|
String permission = ((String) key);
|
||||||
|
|
||||||
// grab the previous result, so we can still satisfy the method signature of Map
|
// 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
|
// proxy the call back through the PermissionAttachment instance
|
||||||
unsetPermission(permission);
|
unsetPermission(permission);
|
||||||
@ -333,61 +343,61 @@ public class LPPermissionAttachment extends PermissionAttachment {
|
|||||||
@Override
|
@Override
|
||||||
public void clear() {
|
public void clear() {
|
||||||
// remove the permissions which have already been applied
|
// remove the permissions which have already been applied
|
||||||
if (hooked) {
|
if (LPPermissionAttachment.this.hooked) {
|
||||||
clearInternal();
|
clearInternal();
|
||||||
}
|
}
|
||||||
|
|
||||||
// clear the backing map
|
// clear the backing map
|
||||||
perms.clear();
|
LPPermissionAttachment.this.perms.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int size() {
|
public int size() {
|
||||||
// return the size of the permissions map - probably the most accurate value we have
|
// return the size of the permissions map - probably the most accurate value we have
|
||||||
return perms.size();
|
return LPPermissionAttachment.this.perms.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
// return if the permissions map is empty - again probably the most accurate thing
|
// return if the permissions map is empty - again probably the most accurate thing
|
||||||
// we can return
|
// we can return
|
||||||
return perms.isEmpty();
|
return LPPermissionAttachment.this.perms.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean containsKey(Object key) {
|
public boolean containsKey(Object key) {
|
||||||
// just proxy
|
// just proxy
|
||||||
return perms.containsKey(key);
|
return LPPermissionAttachment.this.perms.containsKey(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean containsValue(Object value) {
|
public boolean containsValue(Object value) {
|
||||||
// just proxy
|
// just proxy
|
||||||
return perms.containsValue(value);
|
return LPPermissionAttachment.this.perms.containsValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean get(Object key) {
|
public Boolean get(Object key) {
|
||||||
// just proxy
|
// just proxy
|
||||||
return perms.get(key);
|
return LPPermissionAttachment.this.perms.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<String> keySet() {
|
public Set<String> keySet() {
|
||||||
// just proxy
|
// just proxy
|
||||||
return perms.keySet();
|
return LPPermissionAttachment.this.perms.keySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<Boolean> values() {
|
public Collection<Boolean> values() {
|
||||||
// just proxy
|
// just proxy
|
||||||
return perms.values();
|
return LPPermissionAttachment.this.perms.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Entry<String, Boolean>> entrySet() {
|
public Set<Entry<String, Boolean>> entrySet() {
|
||||||
// just proxy
|
// 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.WeakHashMap;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A replacement map for the 'permSubs' instance in Bukkit's SimplePluginManager.
|
* 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 the key is a player, check their LPPermissible first
|
||||||
if (isPlayer) {
|
if (isPlayer) {
|
||||||
Permissible p = (Permissible) key;
|
Permissible p = (Permissible) key;
|
||||||
if (p.isPermissionSet(permission)) {
|
if (p.isPermissionSet(this.permission)) {
|
||||||
return p.hasPermission(permission);
|
return p.hasPermission(this.permission);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// then try the map
|
// then try the map
|
||||||
Boolean result = backing.get(key);
|
Boolean result = this.backing.get(key);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -185,8 +187,8 @@ public class LPSubscriptionMap extends HashMap<String, Map<Permissible, Boolean>
|
|||||||
// then try the permissible, if we haven't already
|
// then try the permissible, if we haven't already
|
||||||
if (!isPlayer && key instanceof Permissible) {
|
if (!isPlayer && key instanceof Permissible) {
|
||||||
Permissible p = (Permissible) key;
|
Permissible p = (Permissible) key;
|
||||||
if (p.isPermissionSet(permission)) {
|
if (p.isPermissionSet(this.permission)) {
|
||||||
return p.hasPermission(permission);
|
return p.hasPermission(this.permission);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,17 +202,19 @@ public class LPSubscriptionMap extends HashMap<String, Map<Permissible, Boolean>
|
|||||||
return get(key) != null;
|
return get(key) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Set<Permissible> keySet() {
|
public Set<Permissible> keySet() {
|
||||||
// gather players (LPPermissibles)
|
// gather players (LPPermissibles)
|
||||||
Set<Permissible> players = plugin.getServer().getOnlinePlayers().stream()
|
Set<Permissible> players = LPSubscriptionMap.this.plugin.getServer().getOnlinePlayers().stream()
|
||||||
.filter(player -> player.isPermissionSet(permission))
|
.filter(player -> player.isPermissionSet(this.permission))
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
// then combine the players with the backing map
|
// then combine the players with the backing map
|
||||||
return Sets.union(players, backing.keySet());
|
return Sets.union(players, this.backing.keySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Set<Entry<Permissible, Boolean>> entrySet() {
|
public Set<Entry<Permissible, Boolean>> entrySet() {
|
||||||
return keySet().stream()
|
return keySet().stream()
|
||||||
@ -233,39 +237,40 @@ public class LPSubscriptionMap extends HashMap<String, Map<Permissible, Boolean>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean put(Permissible key, Boolean value) {
|
public Boolean put(Permissible key, Boolean value) {
|
||||||
return backing.put(key, value);
|
return this.backing.put(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean remove(Object key) {
|
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
|
// the following methods are not used in the current impls of PluginManager, but just delegate them for now
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int size() {
|
public int size() {
|
||||||
return backing.size();
|
return this.backing.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean containsValue(Object value) {
|
public boolean containsValue(Object value) {
|
||||||
return backing.containsValue(value);
|
return this.backing.containsValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void putAll(Map<? extends Permissible, ? extends Boolean> m) {
|
public void putAll(@Nonnull Map<? extends Permissible, ? extends Boolean> m) {
|
||||||
backing.putAll(m);
|
this.backing.putAll(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clear() {
|
public void clear() {
|
||||||
backing.clear();
|
this.backing.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Collection<Boolean> values() {
|
public Collection<Boolean> values() {
|
||||||
return backing.values();
|
return this.backing.values();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,6 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.bukkit.model;
|
package me.lucko.luckperms.bukkit.model;
|
||||||
|
|
||||||
import lombok.experimental.UtilityClass;
|
|
||||||
|
|
||||||
import me.lucko.luckperms.bukkit.compat.ReflectionUtil;
|
import me.lucko.luckperms.bukkit.compat.ReflectionUtil;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
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
|
* This allows LuckPerms to directly intercept permission checks and take over all handling of
|
||||||
* checks made by plugins.
|
* checks made by plugins.
|
||||||
*/
|
*/
|
||||||
@UtilityClass
|
public final class PermissibleInjector {
|
||||||
public class PermissibleInjector {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All permission checks made on standard Bukkit objects are effectively proxied to a
|
* 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;
|
package me.lucko.luckperms.bukkit.model;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
|
|
||||||
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
|
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -37,7 +35,6 @@ import org.bukkit.plugin.SimplePluginManager;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class SubscriptionMapInjector implements Runnable {
|
public class SubscriptionMapInjector implements Runnable {
|
||||||
private static final Field PERM_SUBS_FIELD;
|
private static final Field PERM_SUBS_FIELD;
|
||||||
|
|
||||||
@ -54,22 +51,26 @@ public class SubscriptionMapInjector implements Runnable {
|
|||||||
|
|
||||||
private final LPBukkitPlugin plugin;
|
private final LPBukkitPlugin plugin;
|
||||||
|
|
||||||
|
public SubscriptionMapInjector(LPBukkitPlugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
inject();
|
inject();
|
||||||
} catch (Exception e) {
|
} 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();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void inject() throws Exception {
|
private void inject() throws Exception {
|
||||||
PluginManager pluginManager = plugin.getServer().getPluginManager();
|
PluginManager pluginManager = this.plugin.getServer().getPluginManager();
|
||||||
|
|
||||||
if (!(pluginManager instanceof SimplePluginManager)) {
|
if (!(pluginManager instanceof SimplePluginManager)) {
|
||||||
plugin.getLog().severe("PluginManager instance is not a 'SimplePluginManager', instead: " + pluginManager.getClass());
|
this.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("Unable to inject LuckPerms Permission Subscription map.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,7 +83,7 @@ public class SubscriptionMapInjector implements Runnable {
|
|||||||
Map<String, Map<Permissible, Boolean>> castedMap = (Map<String, Map<Permissible, Boolean>>) map;
|
Map<String, Map<Permissible, Boolean>> castedMap = (Map<String, Map<Permissible, Boolean>>) map;
|
||||||
|
|
||||||
// make a new subscription map
|
// make a new subscription map
|
||||||
LPSubscriptionMap newMap = new LPSubscriptionMap(plugin, castedMap);
|
LPSubscriptionMap newMap = new LPSubscriptionMap(this.plugin, castedMap);
|
||||||
|
|
||||||
// inject it
|
// inject it
|
||||||
PERM_SUBS_FIELD.set(pluginManager, newMap);
|
PERM_SUBS_FIELD.set(pluginManager, newMap);
|
||||||
|
@ -25,8 +25,6 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.bukkit.processors;
|
package me.lucko.luckperms.bukkit.processors;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
|
|
||||||
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
|
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -35,21 +33,24 @@ import java.util.Set;
|
|||||||
/**
|
/**
|
||||||
* Performs the initial setup for Bukkit permission processors
|
* Performs the initial setup for Bukkit permission processors
|
||||||
*/
|
*/
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class BukkitProcessorsSetupTask implements Runnable {
|
public class BukkitProcessorsSetupTask implements Runnable {
|
||||||
private final LPBukkitPlugin plugin;
|
private final LPBukkitPlugin plugin;
|
||||||
|
|
||||||
|
public BukkitProcessorsSetupTask(LPBukkitPlugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
plugin.getDefaultsProvider().refresh();
|
this.plugin.getDefaultsProvider().refresh();
|
||||||
plugin.getChildPermissionProvider().setup();
|
this.plugin.getChildPermissionProvider().setup();
|
||||||
|
|
||||||
Set<String> perms = new HashSet<>();
|
Set<String> perms = new HashSet<>();
|
||||||
plugin.getServer().getPluginManager().getPermissions().forEach(p -> {
|
this.plugin.getServer().getPluginManager().getPermissions().forEach(p -> {
|
||||||
perms.add(p.getName());
|
perms.add(p.getName());
|
||||||
perms.addAll(p.getChildren().keySet());
|
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;
|
package me.lucko.luckperms.bukkit.processors;
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
@ -51,7 +49,6 @@ import java.util.Map;
|
|||||||
public class ChildPermissionProvider {
|
public class ChildPermissionProvider {
|
||||||
|
|
||||||
// in the format: permission+value ===> children (a map of child permissions)
|
// in the format: permission+value ===> children (a map of child permissions)
|
||||||
@Getter
|
|
||||||
private ImmutableMap<Map.Entry<String, Boolean>, ImmutableMap<String, Boolean>> permissions = ImmutableMap.of();
|
private ImmutableMap<Map.Entry<String, Boolean>, ImmutableMap<String, Boolean>> permissions = ImmutableMap.of();
|
||||||
|
|
||||||
public void setup() {
|
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;
|
package me.lucko.luckperms.bukkit.processors;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.Tristate;
|
import me.lucko.luckperms.api.Tristate;
|
||||||
@ -38,23 +36,26 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
/**
|
/**
|
||||||
* Permission Processor for Bukkits "child" permission system.
|
* Permission Processor for Bukkits "child" permission system.
|
||||||
*/
|
*/
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class ChildProcessor implements PermissionProcessor {
|
public class ChildProcessor implements PermissionProcessor {
|
||||||
private final ChildPermissionProvider provider;
|
private final ChildPermissionProvider provider;
|
||||||
private final Map<String, Boolean> childPermissions = new ConcurrentHashMap<>();
|
private final Map<String, Boolean> childPermissions = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
public ChildProcessor(ChildPermissionProvider provider) {
|
||||||
|
this.provider = provider;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tristate hasPermission(String permission) {
|
public Tristate hasPermission(String permission) {
|
||||||
return Tristate.fromNullableBoolean(childPermissions.get(permission));
|
return Tristate.fromNullableBoolean(this.childPermissions.get(permission));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateBacking(Map<String, Boolean> map) {
|
public void updateBacking(Map<String, Boolean> map) {
|
||||||
childPermissions.clear();
|
this.childPermissions.clear();
|
||||||
for (Map.Entry<String, Boolean> e : map.entrySet()) {
|
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) {
|
if (children != null) {
|
||||||
childPermissions.putAll(children);
|
this.childPermissions.putAll(children);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,6 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.bukkit.processors;
|
package me.lucko.luckperms.bukkit.processors;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
|
|
||||||
import me.lucko.luckperms.api.Tristate;
|
import me.lucko.luckperms.api.Tristate;
|
||||||
import me.lucko.luckperms.common.processors.PermissionProcessor;
|
import me.lucko.luckperms.common.processors.PermissionProcessor;
|
||||||
|
|
||||||
@ -38,20 +36,24 @@ import java.util.Map;
|
|||||||
/**
|
/**
|
||||||
* Permission Processor for Bukkits "default" permission system.
|
* Permission Processor for Bukkits "default" permission system.
|
||||||
*/
|
*/
|
||||||
@AllArgsConstructor
|
|
||||||
public class DefaultsProcessor implements PermissionProcessor {
|
public class DefaultsProcessor implements PermissionProcessor {
|
||||||
private final boolean isOp;
|
private final boolean isOp;
|
||||||
private final DefaultsProvider defaultsProvider;
|
private final DefaultsProvider defaultsProvider;
|
||||||
|
|
||||||
|
public DefaultsProcessor(boolean isOp, DefaultsProvider defaultsProvider) {
|
||||||
|
this.isOp = isOp;
|
||||||
|
this.defaultsProvider = defaultsProvider;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tristate hasPermission(String permission) {
|
public Tristate hasPermission(String permission) {
|
||||||
Tristate t = defaultsProvider.lookup(permission, isOp);
|
Tristate t = this.defaultsProvider.lookup(permission, this.isOp);
|
||||||
if (t != Tristate.UNDEFINED) {
|
if (t != Tristate.UNDEFINED) {
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
Permission defPerm = Bukkit.getServer().getPluginManager().getPermission(permission);
|
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
|
@Override
|
||||||
|
@ -25,8 +25,6 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.bukkit.processors;
|
package me.lucko.luckperms.bukkit.processors;
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.Tristate;
|
import me.lucko.luckperms.api.Tristate;
|
||||||
@ -54,12 +52,10 @@ import java.util.Set;
|
|||||||
public class DefaultsProvider {
|
public class DefaultsProvider {
|
||||||
|
|
||||||
// defaults for opped players
|
// defaults for opped players
|
||||||
@Getter
|
|
||||||
private Map<String, Boolean> opDefaults = ImmutableMap.of();
|
private Map<String, Boolean> opDefaults = ImmutableMap.of();
|
||||||
private final DummyPermissible opDummy = new DummyPermissible(this::refreshOp);
|
private final DummyPermissible opDummy = new DummyPermissible(this::refreshOp);
|
||||||
|
|
||||||
// defaults for non-opped players
|
// defaults for non-opped players
|
||||||
@Getter
|
|
||||||
private Map<String, Boolean> nonOpDefaults = ImmutableMap.of();
|
private Map<String, Boolean> nonOpDefaults = ImmutableMap.of();
|
||||||
private final DummyPermissible nonOpDummy = new DummyPermissible(this::refreshNonOp);
|
private final DummyPermissible nonOpDummy = new DummyPermissible(this::refreshNonOp);
|
||||||
|
|
||||||
@ -79,7 +75,7 @@ public class DefaultsProvider {
|
|||||||
* @return a tristate result
|
* @return a tristate result
|
||||||
*/
|
*/
|
||||||
public Tristate lookup(String permission, boolean isOp) {
|
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));
|
return Tristate.fromNullableBoolean(map.get(permission));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,39 +85,39 @@ public class DefaultsProvider {
|
|||||||
* @return the number of permissions held
|
* @return the number of permissions held
|
||||||
*/
|
*/
|
||||||
public int size() {
|
public int size() {
|
||||||
return opDefaults.size() + nonOpDefaults.size();
|
return this.opDefaults.size() + this.nonOpDefaults.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Refreshes the op data in this provider.
|
* Refreshes the op data in this provider.
|
||||||
*/
|
*/
|
||||||
private void refreshOp() {
|
private void refreshOp() {
|
||||||
unregisterDefaults(opDefaults, opDummy, true);
|
unregisterDefaults(this.opDefaults, this.opDummy, true);
|
||||||
|
|
||||||
Map<String, Boolean> builder = new HashMap<>();
|
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.
|
* Refreshes the non op data in this provider.
|
||||||
*/
|
*/
|
||||||
private void refreshNonOp() {
|
private void refreshNonOp() {
|
||||||
unregisterDefaults(nonOpDefaults, nonOpDummy, false);
|
unregisterDefaults(this.nonOpDefaults, this.nonOpDummy, false);
|
||||||
|
|
||||||
Map<String, Boolean> builder = new HashMap<>();
|
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.
|
* Unregisters the dummy permissibles with Bukkit.
|
||||||
*/
|
*/
|
||||||
public void close() {
|
public void close() {
|
||||||
unregisterDefaults(opDefaults, opDummy, true);
|
unregisterDefaults(this.opDefaults, this.opDummy, true);
|
||||||
unregisterDefaults(nonOpDefaults, nonOpDummy, false);
|
unregisterDefaults(this.nonOpDefaults, this.nonOpDummy, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PluginManager pm() {
|
private static PluginManager pm() {
|
||||||
|
@ -146,7 +146,7 @@ public abstract class AbstractVaultChat extends Chat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String world(String world) {
|
private String world(String world) {
|
||||||
return worldMappingFunction.apply(world);
|
return this.worldMappingFunction.apply(world);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String world(Player player) {
|
private String world(Player player) {
|
||||||
@ -525,67 +525,67 @@ public abstract class AbstractVaultChat extends Chat {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean playerInGroup(String world, OfflinePlayer player, String group) {
|
public boolean playerInGroup(String world, OfflinePlayer player, String group) {
|
||||||
return permissionApi.playerInGroup(world, player, group);
|
return this.permissionApi.playerInGroup(world, player, group);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean playerInGroup(String world, String player, String group) {
|
public boolean playerInGroup(String world, String player, String group) {
|
||||||
return permissionApi.playerInGroup(world, player, group);
|
return this.permissionApi.playerInGroup(world, player, group);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean playerInGroup(World world, String player, String group) {
|
public boolean playerInGroup(World world, String player, String group) {
|
||||||
return permissionApi.playerInGroup(world, player, group);
|
return this.permissionApi.playerInGroup(world, player, group);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean playerInGroup(Player player, String group) {
|
public boolean playerInGroup(Player player, String group) {
|
||||||
return permissionApi.playerInGroup(player, group);
|
return this.permissionApi.playerInGroup(player, group);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getPlayerGroups(String world, OfflinePlayer player) {
|
public String[] getPlayerGroups(String world, OfflinePlayer player) {
|
||||||
return permissionApi.getPlayerGroups(world, player);
|
return this.permissionApi.getPlayerGroups(world, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getPlayerGroups(String world, String player) {
|
public String[] getPlayerGroups(String world, String player) {
|
||||||
return permissionApi.getPlayerGroups(world, player);
|
return this.permissionApi.getPlayerGroups(world, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getPlayerGroups(World world, String player) {
|
public String[] getPlayerGroups(World world, String player) {
|
||||||
return permissionApi.getPlayerGroups(world, player);
|
return this.permissionApi.getPlayerGroups(world, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getPlayerGroups(Player player) {
|
public String[] getPlayerGroups(Player player) {
|
||||||
return permissionApi.getPlayerGroups(player);
|
return this.permissionApi.getPlayerGroups(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPrimaryGroup(String world, OfflinePlayer player) {
|
public String getPrimaryGroup(String world, OfflinePlayer player) {
|
||||||
return permissionApi.getPrimaryGroup(world, player);
|
return this.permissionApi.getPrimaryGroup(world, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPrimaryGroup(String world, String player) {
|
public String getPrimaryGroup(String world, String player) {
|
||||||
return permissionApi.getPrimaryGroup(world, player);
|
return this.permissionApi.getPrimaryGroup(world, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPrimaryGroup(World world, String player) {
|
public String getPrimaryGroup(World world, String player) {
|
||||||
return permissionApi.getPrimaryGroup(world, player);
|
return this.permissionApi.getPrimaryGroup(world, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPrimaryGroup(Player player) {
|
public String getPrimaryGroup(Player player) {
|
||||||
return permissionApi.getPrimaryGroup(player);
|
return this.permissionApi.getPrimaryGroup(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getGroups() {
|
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) {
|
private String world(String world) {
|
||||||
return worldMappingFunction.apply(world);
|
return this.worldMappingFunction.apply(world);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String world(Player player) {
|
private String world(Player player) {
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.bukkit.vault;
|
package me.lucko.luckperms.bukkit.vault;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.ChatMetaType;
|
import me.lucko.luckperms.api.ChatMetaType;
|
||||||
@ -44,6 +43,7 @@ import me.lucko.luckperms.common.node.NodeFactory;
|
|||||||
|
|
||||||
import net.milkbowl.vault.chat.Chat;
|
import net.milkbowl.vault.chat.Chat;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -78,18 +78,19 @@ public class VaultChatHook extends AbstractVaultChat {
|
|||||||
this.worldMappingFunction = world -> permissionHook.isIgnoreWorld() ? null : world;
|
this.worldMappingFunction = world -> permissionHook.isIgnoreWorld() ? null : world;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "LuckPerms";
|
return "LuckPerms";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPlayerPrefix(String world, UUID uuid) {
|
public String getPlayerPrefix(String world, UUID uuid) {
|
||||||
Preconditions.checkNotNull(uuid, "uuid");
|
Objects.requireNonNull(uuid, "uuid");
|
||||||
User user = getUser(uuid);
|
User user = getUser(uuid);
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Contexts contexts = permissionHook.contextForLookup(user, world);
|
Contexts contexts = this.permissionHook.contextForLookup(user, world);
|
||||||
MetaCache metaData = user.getCachedData().getMetaData(contexts);
|
MetaCache metaData = user.getCachedData().getMetaData(contexts);
|
||||||
String ret = metaData.getPrefix();
|
String ret = metaData.getPrefix();
|
||||||
if (log()) {
|
if (log()) {
|
||||||
@ -100,12 +101,12 @@ public class VaultChatHook extends AbstractVaultChat {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPlayerSuffix(String world, UUID uuid) {
|
public String getPlayerSuffix(String world, UUID uuid) {
|
||||||
Preconditions.checkNotNull(uuid, "uuid");
|
Objects.requireNonNull(uuid, "uuid");
|
||||||
User user = getUser(uuid);
|
User user = getUser(uuid);
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Contexts contexts = permissionHook.contextForLookup(user, world);
|
Contexts contexts = this.permissionHook.contextForLookup(user, world);
|
||||||
MetaCache metaData = user.getCachedData().getMetaData(contexts);
|
MetaCache metaData = user.getCachedData().getMetaData(contexts);
|
||||||
String ret = metaData.getSuffix();
|
String ret = metaData.getSuffix();
|
||||||
if (log()) {
|
if (log()) {
|
||||||
@ -116,7 +117,7 @@ public class VaultChatHook extends AbstractVaultChat {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPlayerPrefix(String world, UUID uuid, String prefix) {
|
public void setPlayerPrefix(String world, UUID uuid, String prefix) {
|
||||||
Preconditions.checkNotNull(uuid, "uuid");
|
Objects.requireNonNull(uuid, "uuid");
|
||||||
User user = getUser(uuid);
|
User user = getUser(uuid);
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
return;
|
return;
|
||||||
@ -126,7 +127,7 @@ public class VaultChatHook extends AbstractVaultChat {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPlayerSuffix(String world, UUID uuid, String suffix) {
|
public void setPlayerSuffix(String world, UUID uuid, String suffix) {
|
||||||
Preconditions.checkNotNull(uuid, "uuid");
|
Objects.requireNonNull(uuid, "uuid");
|
||||||
User user = getUser(uuid);
|
User user = getUser(uuid);
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
return;
|
return;
|
||||||
@ -136,13 +137,13 @@ public class VaultChatHook extends AbstractVaultChat {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPlayerInfo(String world, UUID uuid, String key) {
|
public String getPlayerInfo(String world, UUID uuid, String key) {
|
||||||
Preconditions.checkNotNull(uuid, "uuid");
|
Objects.requireNonNull(uuid, "uuid");
|
||||||
Preconditions.checkNotNull(key, "key");
|
Objects.requireNonNull(key, "key");
|
||||||
User user = getUser(uuid);
|
User user = getUser(uuid);
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Contexts contexts = permissionHook.contextForLookup(user, world);
|
Contexts contexts = this.permissionHook.contextForLookup(user, world);
|
||||||
MetaCache metaData = user.getCachedData().getMetaData(contexts);
|
MetaCache metaData = user.getCachedData().getMetaData(contexts);
|
||||||
String ret = metaData.getMeta().get(key);
|
String ret = metaData.getMeta().get(key);
|
||||||
if (log()) {
|
if (log()) {
|
||||||
@ -153,8 +154,8 @@ public class VaultChatHook extends AbstractVaultChat {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPlayerInfo(String world, UUID uuid, String key, Object value) {
|
public void setPlayerInfo(String world, UUID uuid, String key, Object value) {
|
||||||
Preconditions.checkNotNull(uuid, "uuid");
|
Objects.requireNonNull(uuid, "uuid");
|
||||||
Preconditions.checkNotNull(key, "key");
|
Objects.requireNonNull(key, "key");
|
||||||
User user = getUser(uuid);
|
User user = getUser(uuid);
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
return;
|
return;
|
||||||
@ -164,12 +165,12 @@ public class VaultChatHook extends AbstractVaultChat {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getGroupsPrefix(String world, String name) {
|
public String getGroupsPrefix(String world, String name) {
|
||||||
Preconditions.checkNotNull(name, "name");
|
Objects.requireNonNull(name, "name");
|
||||||
Group group = getGroup(name);
|
Group group = getGroup(name);
|
||||||
if (group == null) {
|
if (group == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Contexts contexts = permissionHook.contextForLookup(null, world);
|
Contexts contexts = this.permissionHook.contextForLookup(null, world);
|
||||||
MetaCache metaData = group.getCachedData().getMetaData(contexts);
|
MetaCache metaData = group.getCachedData().getMetaData(contexts);
|
||||||
String ret = metaData.getPrefix();
|
String ret = metaData.getPrefix();
|
||||||
if (log()) {
|
if (log()) {
|
||||||
@ -180,12 +181,12 @@ public class VaultChatHook extends AbstractVaultChat {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getGroupsSuffix(String world, String name) {
|
public String getGroupsSuffix(String world, String name) {
|
||||||
Preconditions.checkNotNull(name, "name");
|
Objects.requireNonNull(name, "name");
|
||||||
Group group = getGroup(name);
|
Group group = getGroup(name);
|
||||||
if (group == null) {
|
if (group == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Contexts contexts = permissionHook.contextForLookup(null, world);
|
Contexts contexts = this.permissionHook.contextForLookup(null, world);
|
||||||
MetaCache metaData = group.getCachedData().getMetaData(contexts);
|
MetaCache metaData = group.getCachedData().getMetaData(contexts);
|
||||||
String ret = metaData.getSuffix();
|
String ret = metaData.getSuffix();
|
||||||
if (log()) {
|
if (log()) {
|
||||||
@ -196,7 +197,7 @@ public class VaultChatHook extends AbstractVaultChat {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setGroupsPrefix(String world, String name, String prefix) {
|
public void setGroupsPrefix(String world, String name, String prefix) {
|
||||||
Preconditions.checkNotNull(name, "name");
|
Objects.requireNonNull(name, "name");
|
||||||
Group group = getGroup(name);
|
Group group = getGroup(name);
|
||||||
if (group == null) {
|
if (group == null) {
|
||||||
return;
|
return;
|
||||||
@ -206,7 +207,7 @@ public class VaultChatHook extends AbstractVaultChat {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setGroupsSuffix(String world, String name, String suffix) {
|
public void setGroupsSuffix(String world, String name, String suffix) {
|
||||||
Preconditions.checkNotNull(name, "name");
|
Objects.requireNonNull(name, "name");
|
||||||
Group group = getGroup(name);
|
Group group = getGroup(name);
|
||||||
if (group == null) {
|
if (group == null) {
|
||||||
return;
|
return;
|
||||||
@ -216,13 +217,13 @@ public class VaultChatHook extends AbstractVaultChat {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getGroupInfo(String world, String name, String key) {
|
public String getGroupInfo(String world, String name, String key) {
|
||||||
Preconditions.checkNotNull(name, "name");
|
Objects.requireNonNull(name, "name");
|
||||||
Preconditions.checkNotNull(key, "key");
|
Objects.requireNonNull(key, "key");
|
||||||
Group group = getGroup(name);
|
Group group = getGroup(name);
|
||||||
if (group == null) {
|
if (group == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Contexts contexts = permissionHook.contextForLookup(null, world);
|
Contexts contexts = this.permissionHook.contextForLookup(null, world);
|
||||||
MetaCache metaData = group.getCachedData().getMetaData(contexts);
|
MetaCache metaData = group.getCachedData().getMetaData(contexts);
|
||||||
String ret = metaData.getMeta().get(key);
|
String ret = metaData.getMeta().get(key);
|
||||||
if (log()) {
|
if (log()) {
|
||||||
@ -233,8 +234,8 @@ public class VaultChatHook extends AbstractVaultChat {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setGroupInfo(String world, String name, String key, Object value) {
|
public void setGroupInfo(String world, String name, String key, Object value) {
|
||||||
Preconditions.checkNotNull(name, "name");
|
Objects.requireNonNull(name, "name");
|
||||||
Preconditions.checkNotNull(key, "key");
|
Objects.requireNonNull(key, "key");
|
||||||
Group group = getGroup(name);
|
Group group = getGroup(name);
|
||||||
if (group == null) {
|
if (group == null) {
|
||||||
return;
|
return;
|
||||||
@ -245,19 +246,19 @@ public class VaultChatHook extends AbstractVaultChat {
|
|||||||
// utility methods for getting user and group instances
|
// utility methods for getting user and group instances
|
||||||
|
|
||||||
private User getUser(UUID uuid) {
|
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) {
|
private Group getGroup(String name) {
|
||||||
return plugin.getGroupManager().getByDisplayName(name);
|
return this.plugin.getGroupManager().getByDisplayName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// logging
|
// logging
|
||||||
private boolean log() {
|
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) {
|
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.SECTION_CHAR, '$')
|
||||||
.replace(CommandManager.AMPERSAND_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);
|
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
|
// remove all prefixes/suffixes directly set on the user/group
|
||||||
holder.removeIf(type::matches);
|
holder.removeIf(type::matches);
|
||||||
|
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
permissionHook.holderSave(holder);
|
this.permissionHook.holderSave(holder);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -283,11 +284,11 @@ public class VaultChatHook extends AbstractVaultChat {
|
|||||||
.mapToInt(e -> e).max().orElse(0) + 10;
|
.mapToInt(e -> e).max().orElse(0) + 10;
|
||||||
|
|
||||||
Node.Builder chatMetaNode = NodeFactory.buildChatMetaNode(type, priority, value);
|
Node.Builder chatMetaNode = NodeFactory.buildChatMetaNode(type, priority, value);
|
||||||
chatMetaNode.setServer(permissionHook.getVaultServer());
|
chatMetaNode.setServer(this.permissionHook.getVaultServer());
|
||||||
chatMetaNode.setWorld(world);
|
chatMetaNode.setWorld(world);
|
||||||
|
|
||||||
holder.setPermission(chatMetaNode.build());
|
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);
|
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));
|
holder.removeIf(n -> n.isMeta() && n.getMeta().getKey().equals(key));
|
||||||
|
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
permissionHook.holderSave(holder);
|
this.permissionHook.holderSave(holder);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -311,11 +312,11 @@ public class VaultChatHook extends AbstractVaultChat {
|
|||||||
metaNode = NodeFactory.buildMetaNode(key, value.toString());
|
metaNode = NodeFactory.buildMetaNode(key, value.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
metaNode.setServer(permissionHook.getVaultServer());
|
metaNode.setServer(this.permissionHook.getVaultServer());
|
||||||
metaNode.setWorld(world);
|
metaNode.setWorld(world);
|
||||||
|
|
||||||
holder.setPermission(metaNode.build());
|
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")) {
|
if (world != null && !world.equals("") && !world.equalsIgnoreCase("global")) {
|
||||||
context.add(Contexts.WORLD_KEY, world.toLowerCase());
|
context.add(Contexts.WORLD_KEY, world.toLowerCase());
|
||||||
}
|
}
|
||||||
context.add(Contexts.SERVER_KEY, permissionHook.getVaultServer());
|
context.add(Contexts.SERVER_KEY, this.permissionHook.getVaultServer());
|
||||||
return new Contexts(context.build(), permissionHook.isIncludeGlobal(), true, true, true, true, false);
|
return new Contexts(context.build(), this.permissionHook.isIncludeGlobal(), true, true, true, true, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,6 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.bukkit.vault;
|
package me.lucko.luckperms.bukkit.vault;
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
|
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
|
||||||
|
|
||||||
import net.milkbowl.vault.chat.Chat;
|
import net.milkbowl.vault.chat.Chat;
|
||||||
@ -38,7 +36,6 @@ import org.bukkit.plugin.ServicesManager;
|
|||||||
/**
|
/**
|
||||||
* Handles hooking with the Vault API
|
* Handles hooking with the Vault API
|
||||||
*/
|
*/
|
||||||
@Getter
|
|
||||||
public class VaultHookManager {
|
public class VaultHookManager {
|
||||||
private VaultChatHook chatHook = null;
|
private VaultChatHook chatHook = null;
|
||||||
private VaultPermissionHook permissionHook = null;
|
private VaultPermissionHook permissionHook = null;
|
||||||
@ -51,17 +48,17 @@ public class VaultHookManager {
|
|||||||
*/
|
*/
|
||||||
public void hook(LPBukkitPlugin plugin) {
|
public void hook(LPBukkitPlugin plugin) {
|
||||||
try {
|
try {
|
||||||
if (permissionHook == null) {
|
if (this.permissionHook == null) {
|
||||||
permissionHook = new VaultPermissionHook(plugin);
|
this.permissionHook = new VaultPermissionHook(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chatHook == null) {
|
if (this.chatHook == null) {
|
||||||
chatHook = new VaultChatHook(plugin, permissionHook);
|
this.chatHook = new VaultChatHook(plugin, this.permissionHook);
|
||||||
}
|
}
|
||||||
|
|
||||||
final ServicesManager sm = plugin.getServer().getServicesManager();
|
final ServicesManager sm = plugin.getServer().getServicesManager();
|
||||||
sm.register(Permission.class, permissionHook, plugin, ServicePriority.High);
|
sm.register(Permission.class, this.permissionHook, plugin, ServicePriority.High);
|
||||||
sm.register(Chat.class, chatHook, plugin, ServicePriority.High);
|
sm.register(Chat.class, this.chatHook, plugin, ServicePriority.High);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -76,25 +73,16 @@ public class VaultHookManager {
|
|||||||
public void unhook(LPBukkitPlugin plugin) {
|
public void unhook(LPBukkitPlugin plugin) {
|
||||||
final ServicesManager sm = plugin.getServer().getServicesManager();
|
final ServicesManager sm = plugin.getServer().getServicesManager();
|
||||||
|
|
||||||
if (permissionHook != null) {
|
if (this.permissionHook != null) {
|
||||||
sm.unregister(Permission.class, permissionHook);
|
sm.unregister(Permission.class, this.permissionHook);
|
||||||
permissionHook.getExecutor().shutdown();
|
this.permissionHook.getExecutor().shutdown();
|
||||||
permissionHook = null;
|
this.permissionHook = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chatHook != null) {
|
if (this.chatHook != null) {
|
||||||
sm.unregister(Chat.class, chatHook);
|
sm.unregister(Chat.class, this.chatHook);
|
||||||
chatHook = null;
|
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;
|
package me.lucko.luckperms.bukkit.vault;
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.Contexts;
|
import me.lucko.luckperms.api.Contexts;
|
||||||
@ -49,6 +47,7 @@ import net.milkbowl.vault.permission.Permission;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
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
|
* 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.
|
* design. There is nothing I can do about it.
|
||||||
*/
|
*/
|
||||||
@Getter
|
|
||||||
public class VaultPermissionHook extends AbstractVaultPermission {
|
public class VaultPermissionHook extends AbstractVaultPermission {
|
||||||
|
|
||||||
// the plugin instance
|
// the plugin instance
|
||||||
@ -85,6 +83,14 @@ public class VaultPermissionHook extends AbstractVaultPermission {
|
|||||||
this.worldMappingFunction = world -> isIgnoreWorld() ? null : world;
|
this.worldMappingFunction = world -> isIgnoreWorld() ? null : world;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LPBukkitPlugin getPlugin() {
|
||||||
|
return this.plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExecutorService getExecutor() {
|
||||||
|
return this.executor;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "LuckPerms";
|
return "LuckPerms";
|
||||||
@ -104,15 +110,15 @@ public class VaultPermissionHook extends AbstractVaultPermission {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getGroups() {
|
public String[] getGroups() {
|
||||||
return plugin.getGroupManager().getAll().values().stream()
|
return this.plugin.getGroupManager().getAll().values().stream()
|
||||||
.map(g -> g.getDisplayName().orElse(g.getName()))
|
.map(g -> g.getDisplayName().orElse(g.getName()))
|
||||||
.toArray(String[]::new);
|
.toArray(String[]::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPermission(String world, UUID uuid, String permission) {
|
public boolean hasPermission(String world, UUID uuid, String permission) {
|
||||||
Preconditions.checkNotNull(uuid, "uuid");
|
Objects.requireNonNull(uuid, "uuid");
|
||||||
Preconditions.checkNotNull(permission, "permission");
|
Objects.requireNonNull(permission, "permission");
|
||||||
|
|
||||||
User user = getUser(uuid);
|
User user = getUser(uuid);
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
@ -131,8 +137,8 @@ public class VaultPermissionHook extends AbstractVaultPermission {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean playerAddPermission(String world, UUID uuid, String permission) {
|
public boolean playerAddPermission(String world, UUID uuid, String permission) {
|
||||||
Preconditions.checkNotNull(uuid, "uuid");
|
Objects.requireNonNull(uuid, "uuid");
|
||||||
Preconditions.checkNotNull(permission, "permission");
|
Objects.requireNonNull(permission, "permission");
|
||||||
|
|
||||||
User user = getUser(uuid);
|
User user = getUser(uuid);
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
@ -145,8 +151,8 @@ public class VaultPermissionHook extends AbstractVaultPermission {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean playerRemovePermission(String world, UUID uuid, String permission) {
|
public boolean playerRemovePermission(String world, UUID uuid, String permission) {
|
||||||
Preconditions.checkNotNull(uuid, "uuid");
|
Objects.requireNonNull(uuid, "uuid");
|
||||||
Preconditions.checkNotNull(permission, "permission");
|
Objects.requireNonNull(permission, "permission");
|
||||||
|
|
||||||
User user = getUser(uuid);
|
User user = getUser(uuid);
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
@ -159,28 +165,28 @@ public class VaultPermissionHook extends AbstractVaultPermission {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean playerInGroup(String world, UUID uuid, String group) {
|
public boolean playerInGroup(String world, UUID uuid, String group) {
|
||||||
Preconditions.checkNotNull(uuid, "uuid");
|
Objects.requireNonNull(uuid, "uuid");
|
||||||
Preconditions.checkNotNull(group, "group");
|
Objects.requireNonNull(group, "group");
|
||||||
return hasPermission(world, uuid, NodeFactory.groupNode(rewriteGroupName(group)));
|
return hasPermission(world, uuid, NodeFactory.groupNode(rewriteGroupName(group)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean playerAddGroup(String world, UUID uuid, String group) {
|
public boolean playerAddGroup(String world, UUID uuid, String group) {
|
||||||
Preconditions.checkNotNull(uuid, "uuid");
|
Objects.requireNonNull(uuid, "uuid");
|
||||||
Preconditions.checkNotNull(group, "group");
|
Objects.requireNonNull(group, "group");
|
||||||
return checkGroupExists(group) && playerAddPermission(world, uuid, NodeFactory.groupNode(rewriteGroupName(group)));
|
return checkGroupExists(group) && playerAddPermission(world, uuid, NodeFactory.groupNode(rewriteGroupName(group)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean playerRemoveGroup(String world, UUID uuid, String group) {
|
public boolean playerRemoveGroup(String world, UUID uuid, String group) {
|
||||||
Preconditions.checkNotNull(uuid, "uuid");
|
Objects.requireNonNull(uuid, "uuid");
|
||||||
Preconditions.checkNotNull(group, "group");
|
Objects.requireNonNull(group, "group");
|
||||||
return checkGroupExists(group) && playerRemovePermission(world, uuid, NodeFactory.groupNode(rewriteGroupName(group)));
|
return checkGroupExists(group) && playerRemovePermission(world, uuid, NodeFactory.groupNode(rewriteGroupName(group)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] playerGetGroups(String world, UUID uuid) {
|
public String[] playerGetGroups(String world, UUID uuid) {
|
||||||
Preconditions.checkNotNull(uuid, "uuid");
|
Objects.requireNonNull(uuid, "uuid");
|
||||||
|
|
||||||
User user = getUser(uuid);
|
User user = getUser(uuid);
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
@ -193,7 +199,7 @@ public class VaultPermissionHook extends AbstractVaultPermission {
|
|||||||
.filter(Node::isGroupNode)
|
.filter(Node::isGroupNode)
|
||||||
.filter(n -> n.shouldApplyWithContext(contexts))
|
.filter(n -> n.shouldApplyWithContext(contexts))
|
||||||
.map(n -> {
|
.map(n -> {
|
||||||
Group group = plugin.getGroupManager().getIfLoaded(n.getGroupName());
|
Group group = this.plugin.getGroupManager().getIfLoaded(n.getGroupName());
|
||||||
if (group != null) {
|
if (group != null) {
|
||||||
return group.getDisplayName().orElse(group.getName());
|
return group.getDisplayName().orElse(group.getName());
|
||||||
}
|
}
|
||||||
@ -210,7 +216,7 @@ public class VaultPermissionHook extends AbstractVaultPermission {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String playerPrimaryGroup(String world, UUID uuid) {
|
public String playerPrimaryGroup(String world, UUID uuid) {
|
||||||
Preconditions.checkNotNull(uuid, "uuid");
|
Objects.requireNonNull(uuid, "uuid");
|
||||||
|
|
||||||
User user = getUser(uuid);
|
User user = getUser(uuid);
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
@ -232,8 +238,8 @@ public class VaultPermissionHook extends AbstractVaultPermission {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean groupHasPermission(String world, String name, String permission) {
|
public boolean groupHasPermission(String world, String name, String permission) {
|
||||||
Preconditions.checkNotNull(name, "name");
|
Objects.requireNonNull(name, "name");
|
||||||
Preconditions.checkNotNull(permission, "permission");
|
Objects.requireNonNull(permission, "permission");
|
||||||
|
|
||||||
Group group = getGroup(name);
|
Group group = getGroup(name);
|
||||||
if (group == null) {
|
if (group == null) {
|
||||||
@ -252,8 +258,8 @@ public class VaultPermissionHook extends AbstractVaultPermission {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean groupAddPermission(String world, String name, String permission) {
|
public boolean groupAddPermission(String world, String name, String permission) {
|
||||||
Preconditions.checkNotNull(name, "name");
|
Objects.requireNonNull(name, "name");
|
||||||
Preconditions.checkNotNull(permission, "permission");
|
Objects.requireNonNull(permission, "permission");
|
||||||
|
|
||||||
Group group = getGroup(name);
|
Group group = getGroup(name);
|
||||||
if (group == null) {
|
if (group == null) {
|
||||||
@ -266,8 +272,8 @@ public class VaultPermissionHook extends AbstractVaultPermission {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean groupRemovePermission(String world, String name, String permission) {
|
public boolean groupRemovePermission(String world, String name, String permission) {
|
||||||
Preconditions.checkNotNull(name, "name");
|
Objects.requireNonNull(name, "name");
|
||||||
Preconditions.checkNotNull(permission, "permission");
|
Objects.requireNonNull(permission, "permission");
|
||||||
|
|
||||||
Group group = getGroup(name);
|
Group group = getGroup(name);
|
||||||
if (group == null) {
|
if (group == null) {
|
||||||
@ -281,19 +287,19 @@ public class VaultPermissionHook extends AbstractVaultPermission {
|
|||||||
// utility methods for getting user and group instances
|
// utility methods for getting user and group instances
|
||||||
|
|
||||||
private User getUser(UUID uuid) {
|
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) {
|
private Group getGroup(String name) {
|
||||||
return plugin.getGroupManager().getByDisplayName(name);
|
return this.plugin.getGroupManager().getByDisplayName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkGroupExists(String group) {
|
private boolean checkGroupExists(String group) {
|
||||||
return plugin.getGroupManager().getByDisplayName(group) != null;
|
return this.plugin.getGroupManager().getByDisplayName(group) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String rewriteGroupName(String name) {
|
private String rewriteGroupName(String name) {
|
||||||
Group group = plugin.getGroupManager().getByDisplayName(name);
|
Group group = this.plugin.getGroupManager().getByDisplayName(name);
|
||||||
if (group != null) {
|
if (group != null) {
|
||||||
return group.getName();
|
return group.getName();
|
||||||
}
|
}
|
||||||
@ -302,10 +308,10 @@ public class VaultPermissionHook extends AbstractVaultPermission {
|
|||||||
|
|
||||||
// logging
|
// logging
|
||||||
private boolean log() {
|
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) {
|
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.SECTION_CHAR, '$')
|
||||||
.replace(CommandManager.AMPERSAND_CHAR, '$')
|
.replace(CommandManager.AMPERSAND_CHAR, '$')
|
||||||
);
|
);
|
||||||
@ -315,11 +321,11 @@ public class VaultPermissionHook extends AbstractVaultPermission {
|
|||||||
Contexts contextForLookup(User user, String world) {
|
Contexts contextForLookup(User user, String world) {
|
||||||
MutableContextSet context;
|
MutableContextSet context;
|
||||||
|
|
||||||
Player player = user == null ? null : plugin.getPlayer(user);
|
Player player = user == null ? null : this.plugin.getPlayer(user);
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
context = plugin.getContextManager().getApplicableContext(player).mutableCopy();
|
context = this.plugin.getContextManager().getApplicableContext(player).mutableCopy();
|
||||||
} else {
|
} 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
|
// 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
|
// utility methods for modifying the state of PermissionHolders
|
||||||
|
|
||||||
private void holderAddPermission(PermissionHolder holder, String permission, String world) {
|
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");
|
Preconditions.checkArgument(!permission.isEmpty(), "permission is an empty string");
|
||||||
|
|
||||||
if (log()) {
|
if (log()) {
|
||||||
logMsg("#holderAddPermission: %s - %s - %s", holder.getFriendlyName(), permission, world);
|
logMsg("#holderAddPermission: %s - %s - %s", holder.getFriendlyName(), permission, world);
|
||||||
}
|
}
|
||||||
|
|
||||||
executor.execute(() -> {
|
this.executor.execute(() -> {
|
||||||
if (holder.setPermission(NodeFactory.make(permission, true, getVaultServer(), world)).asBoolean()) {
|
if (holder.setPermission(NodeFactory.make(permission, true, getVaultServer(), world)).asBoolean()) {
|
||||||
holderSave(holder);
|
holderSave(holder);
|
||||||
}
|
}
|
||||||
@ -363,14 +369,14 @@ public class VaultPermissionHook extends AbstractVaultPermission {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void holderRemovePermission(PermissionHolder holder, String permission, String world) {
|
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");
|
Preconditions.checkArgument(!permission.isEmpty(), "permission is an empty string");
|
||||||
|
|
||||||
if (log()) {
|
if (log()) {
|
||||||
logMsg("#holderRemovePermission: %s - %s - %s", holder.getFriendlyName(), permission, world);
|
logMsg("#holderRemovePermission: %s - %s - %s", holder.getFriendlyName(), permission, world);
|
||||||
}
|
}
|
||||||
|
|
||||||
executor.execute(() -> {
|
this.executor.execute(() -> {
|
||||||
if (holder.unsetPermission(NodeFactory.make(permission, getVaultServer(), world)).asBoolean()) {
|
if (holder.unsetPermission(NodeFactory.make(permission, getVaultServer(), world)).asBoolean()) {
|
||||||
holderSave(holder);
|
holderSave(holder);
|
||||||
}
|
}
|
||||||
@ -380,33 +386,33 @@ public class VaultPermissionHook extends AbstractVaultPermission {
|
|||||||
void holderSave(PermissionHolder holder) {
|
void holderSave(PermissionHolder holder) {
|
||||||
if (holder.getType().isUser()) {
|
if (holder.getType().isUser()) {
|
||||||
User u = (User) holder;
|
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()) {
|
if (holder.getType().isGroup()) {
|
||||||
Group g = (Group) holder;
|
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.
|
// helper methods to just pull values from the config.
|
||||||
|
|
||||||
String getServer() {
|
String getServer() {
|
||||||
return plugin.getConfiguration().get(ConfigKeys.SERVER);
|
return this.plugin.getConfiguration().get(ConfigKeys.SERVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
String getVaultServer() {
|
String getVaultServer() {
|
||||||
return plugin.getConfiguration().get(ConfigKeys.VAULT_SERVER);
|
return this.plugin.getConfiguration().get(ConfigKeys.VAULT_SERVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isIncludeGlobal() {
|
boolean isIncludeGlobal() {
|
||||||
return plugin.getConfiguration().get(ConfigKeys.VAULT_INCLUDING_GLOBAL);
|
return this.plugin.getConfiguration().get(ConfigKeys.VAULT_INCLUDING_GLOBAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isIgnoreWorld() {
|
boolean isIgnoreWorld() {
|
||||||
return plugin.getConfiguration().get(ConfigKeys.VAULT_IGNORE_WORLD);
|
return this.plugin.getConfiguration().get(ConfigKeys.VAULT_IGNORE_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean useVaultServer() {
|
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>
|
<version>${project.version}</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- Lombok -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>com.google.code.findbugs</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>jsr305</artifactId>
|
||||||
<version>${lombok.version}</version>
|
<version>3.0.2</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- RedisBungee -->
|
<!-- RedisBungee -->
|
||||||
|
@ -53,17 +53,17 @@ public class BungeeCommandExecutor extends Command implements TabExecutor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandSender sender, String[] args) {
|
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)));
|
List<String> arguments = CommandManager.stripQuotes(ARGUMENT_SPLITTER.splitToList(ARGUMENT_JOINER.join(args)));
|
||||||
|
|
||||||
manager.onCommand(lpSender, "lpb", arguments);
|
this.manager.onCommand(lpSender, "lpb", arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<String> onTabComplete(CommandSender sender, String[] args) {
|
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)));
|
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
|
@Override
|
||||||
public void reload() {
|
public void reload() {
|
||||||
try {
|
try {
|
||||||
configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file);
|
this.configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(this.file);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@ -63,32 +63,32 @@ public class BungeeConfigAdapter extends AbstractConfigurationAdapter implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean contains(String path) {
|
public boolean contains(String path) {
|
||||||
return configuration.contains(path);
|
return this.configuration.contains(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getString(String path, String def) {
|
public String getString(String path, String def) {
|
||||||
return configuration.getString(path, def);
|
return this.configuration.getString(path, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getInt(String path, int def) {
|
public int getInt(String path, int def) {
|
||||||
return configuration.getInt(path, def);
|
return this.configuration.getInt(path, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean getBoolean(String path, boolean def) {
|
public boolean getBoolean(String path, boolean def) {
|
||||||
return configuration.getBoolean(path, def);
|
return this.configuration.getBoolean(path, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getList(String path, List<String> def) {
|
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
|
@Override
|
||||||
public List<String> getObjectList(String path, List<String> def) {
|
public List<String> getObjectList(String path, List<String> def) {
|
||||||
Configuration section = configuration.getSection(path);
|
Configuration section = this.configuration.getSection(path);
|
||||||
if (section == null) {
|
if (section == null) {
|
||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
@ -99,7 +99,7 @@ public class BungeeConfigAdapter extends AbstractConfigurationAdapter implements
|
|||||||
@Override
|
@Override
|
||||||
public Map<String, String> getMap(String path, Map<String, String> def) {
|
public Map<String, String> getMap(String path, Map<String, String> def) {
|
||||||
Map<String, String> map = new HashMap<>();
|
Map<String, String> map = new HashMap<>();
|
||||||
Configuration section = configuration.getSection(path);
|
Configuration section = this.configuration.getSection(path);
|
||||||
if (section == null) {
|
if (section == null) {
|
||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
|
@ -47,17 +47,17 @@ public class BungeeSchedulerAdapter implements SchedulerAdapter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Executor async() {
|
public Executor async() {
|
||||||
return asyncExecutor;
|
return this.asyncExecutor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Executor sync() {
|
public Executor sync() {
|
||||||
return asyncExecutor;
|
return this.asyncExecutor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doAsync(Runnable runnable) {
|
public void doAsync(Runnable runnable) {
|
||||||
asyncExecutor.execute(runnable);
|
this.asyncExecutor.execute(runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -68,8 +68,8 @@ public class BungeeSchedulerAdapter implements SchedulerAdapter {
|
|||||||
@Override
|
@Override
|
||||||
public void asyncRepeating(Runnable runnable, long intervalTicks) {
|
public void asyncRepeating(Runnable runnable, long intervalTicks) {
|
||||||
long millis = intervalTicks * 50L; // convert from ticks to milliseconds
|
long millis = intervalTicks * 50L; // convert from ticks to milliseconds
|
||||||
ScheduledTask task = plugin.getProxy().getScheduler().schedule(plugin, runnable, millis, millis, TimeUnit.MILLISECONDS);
|
ScheduledTask task = this.plugin.getProxy().getScheduler().schedule(this.plugin, runnable, millis, millis, TimeUnit.MILLISECONDS);
|
||||||
tasks.add(task);
|
this.tasks.add(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -80,7 +80,7 @@ public class BungeeSchedulerAdapter implements SchedulerAdapter {
|
|||||||
@Override
|
@Override
|
||||||
public void asyncLater(Runnable runnable, long delayTicks) {
|
public void asyncLater(Runnable runnable, long delayTicks) {
|
||||||
long millis = delayTicks * 50L; // convert from ticks to milliseconds
|
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
|
@Override
|
||||||
@ -90,6 +90,6 @@ public class BungeeSchedulerAdapter implements SchedulerAdapter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
tasks.forEach(ScheduledTask::cancel);
|
this.tasks.forEach(ScheduledTask::cancel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,6 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.bungee;
|
package me.lucko.luckperms.bungee;
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import me.lucko.luckperms.api.Contexts;
|
import me.lucko.luckperms.api.Contexts;
|
||||||
import me.lucko.luckperms.api.platform.PlatformType;
|
import me.lucko.luckperms.api.platform.PlatformType;
|
||||||
import me.lucko.luckperms.bungee.calculators.BungeeCalculatorFactory;
|
import me.lucko.luckperms.bungee.calculators.BungeeCalculatorFactory;
|
||||||
@ -97,7 +95,6 @@ import java.util.stream.Stream;
|
|||||||
/**
|
/**
|
||||||
* LuckPerms implementation for the BungeeCord API.
|
* LuckPerms implementation for the BungeeCord API.
|
||||||
*/
|
*/
|
||||||
@Getter
|
|
||||||
public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
||||||
|
|
||||||
private long startTime;
|
private long startTime;
|
||||||
@ -129,93 +126,93 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
|||||||
@Override
|
@Override
|
||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
// setup minimal functionality in order to load initial dependencies
|
// setup minimal functionality in order to load initial dependencies
|
||||||
scheduler = new BungeeSchedulerAdapter(this);
|
this.scheduler = new BungeeSchedulerAdapter(this);
|
||||||
localeManager = new NoopLocaleManager();
|
this.localeManager = new NoopLocaleManager();
|
||||||
senderFactory = new BungeeSenderFactory(this);
|
this.senderFactory = new BungeeSenderFactory(this);
|
||||||
log = new SenderLogger(this, getConsoleSender());
|
this.log = new SenderLogger(this, getConsoleSender());
|
||||||
|
|
||||||
dependencyManager = new DependencyManager(this);
|
this.dependencyManager = new DependencyManager(this);
|
||||||
dependencyManager.loadDependencies(Collections.singleton(Dependency.CAFFEINE));
|
this.dependencyManager.loadDependencies(Collections.singleton(Dependency.CAFFEINE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
startTime = System.currentTimeMillis();
|
this.startTime = System.currentTimeMillis();
|
||||||
sendStartupBanner(getConsoleSender());
|
sendStartupBanner(getConsoleSender());
|
||||||
verboseHandler = new VerboseHandler(scheduler.async(), getVersion());
|
this.verboseHandler = new VerboseHandler(this.scheduler.async(), getVersion());
|
||||||
permissionVault = new PermissionVault(scheduler.async());
|
this.permissionVault = new PermissionVault(this.scheduler.async());
|
||||||
logDispatcher = new LogDispatcher(this);
|
this.logDispatcher = new LogDispatcher(this);
|
||||||
|
|
||||||
getLog().info("Loading configuration...");
|
getLog().info("Loading configuration...");
|
||||||
configuration = new AbstractConfiguration(this, new BungeeConfigAdapter(this, resolveConfig("config.yml")));
|
this.configuration = new AbstractConfiguration(this, new BungeeConfigAdapter(this, resolveConfig("config.yml")));
|
||||||
configuration.loadAll();
|
this.configuration.loadAll();
|
||||||
|
|
||||||
StorageFactory storageFactory = new StorageFactory(this);
|
StorageFactory storageFactory = new StorageFactory(this);
|
||||||
Set<StorageType> storageTypes = storageFactory.getRequiredTypes(StorageType.H2);
|
Set<StorageType> storageTypes = storageFactory.getRequiredTypes(StorageType.H2);
|
||||||
dependencyManager.loadStorageDependencies(storageTypes);
|
this.dependencyManager.loadStorageDependencies(storageTypes);
|
||||||
|
|
||||||
// register events
|
// register events
|
||||||
getProxy().getPluginManager().registerListener(this, new BungeeConnectionListener(this));
|
getProxy().getPluginManager().registerListener(this, new BungeeConnectionListener(this));
|
||||||
getProxy().getPluginManager().registerListener(this, new BungeePermissionCheckListener(this));
|
getProxy().getPluginManager().registerListener(this, new BungeePermissionCheckListener(this));
|
||||||
|
|
||||||
if (getConfiguration().get(ConfigKeys.WATCH_FILES)) {
|
if (getConfiguration().get(ConfigKeys.WATCH_FILES)) {
|
||||||
fileWatcher = new FileWatcher(this);
|
this.fileWatcher = new FileWatcher(this);
|
||||||
getScheduler().asyncRepeating(fileWatcher, 30L);
|
getScheduler().asyncRepeating(this.fileWatcher, 30L);
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialise datastore
|
// initialise datastore
|
||||||
storage = storageFactory.getInstance(StorageType.H2);
|
this.storage = storageFactory.getInstance(StorageType.H2);
|
||||||
|
|
||||||
// initialise messaging
|
// initialise messaging
|
||||||
messagingService = new BungeeMessagingFactory(this).getInstance();
|
this.messagingService = new BungeeMessagingFactory(this).getInstance();
|
||||||
|
|
||||||
// setup the update task buffer
|
// setup the update task buffer
|
||||||
updateTaskBuffer = new UpdateTaskBuffer(this);
|
this.updateTaskBuffer = new UpdateTaskBuffer(this);
|
||||||
|
|
||||||
// load locale
|
// load locale
|
||||||
localeManager = new SimpleLocaleManager();
|
this.localeManager = new SimpleLocaleManager();
|
||||||
localeManager.tryLoad(this, new File(getDataFolder(), "lang.yml"));
|
this.localeManager.tryLoad(this, new File(getDataFolder(), "lang.yml"));
|
||||||
|
|
||||||
// register commands
|
// register commands
|
||||||
commandManager = new CommandManager(this);
|
this.commandManager = new CommandManager(this);
|
||||||
getProxy().getPluginManager().registerCommand(this, new BungeeCommandExecutor(this, commandManager));
|
getProxy().getPluginManager().registerCommand(this, new BungeeCommandExecutor(this, this.commandManager));
|
||||||
|
|
||||||
// disable the default Bungee /perms command so it gets handled by the Bukkit plugin
|
// disable the default Bungee /perms command so it gets handled by the Bukkit plugin
|
||||||
getProxy().getDisabledCommands().add("perms");
|
getProxy().getDisabledCommands().add("perms");
|
||||||
|
|
||||||
// load internal managers
|
// load internal managers
|
||||||
getLog().info("Loading internal permission managers...");
|
getLog().info("Loading internal permission managers...");
|
||||||
uuidCache = new UuidCache(this);
|
this.uuidCache = new UuidCache(this);
|
||||||
userManager = new GenericUserManager(this);
|
this.userManager = new GenericUserManager(this);
|
||||||
groupManager = new GenericGroupManager(this);
|
this.groupManager = new GenericGroupManager(this);
|
||||||
trackManager = new GenericTrackManager(this);
|
this.trackManager = new GenericTrackManager(this);
|
||||||
calculatorFactory = new BungeeCalculatorFactory(this);
|
this.calculatorFactory = new BungeeCalculatorFactory(this);
|
||||||
cachedStateManager = new CachedStateManager();
|
this.cachedStateManager = new CachedStateManager();
|
||||||
|
|
||||||
// setup context manager
|
// setup context manager
|
||||||
contextManager = new BungeeContextManager(this);
|
this.contextManager = new BungeeContextManager(this);
|
||||||
contextManager.registerCalculator(new BackendServerCalculator(this));
|
this.contextManager.registerCalculator(new BackendServerCalculator(this));
|
||||||
contextManager.registerStaticCalculator(new LuckPermsCalculator(getConfiguration()));
|
this.contextManager.registerStaticCalculator(new LuckPermsCalculator(getConfiguration()));
|
||||||
|
|
||||||
if (getProxy().getPluginManager().getPlugin("RedisBungee") != null) {
|
if (getProxy().getPluginManager().getPlugin("RedisBungee") != null) {
|
||||||
contextManager.registerStaticCalculator(new RedisBungeeCalculator());
|
this.contextManager.registerStaticCalculator(new RedisBungeeCalculator());
|
||||||
}
|
}
|
||||||
|
|
||||||
// register with the LP API
|
// register with the LP API
|
||||||
apiProvider = new LuckPermsApiProvider(this);
|
this.apiProvider = new LuckPermsApiProvider(this);
|
||||||
|
|
||||||
// setup event factory
|
// 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
|
// schedule update tasks
|
||||||
int mins = getConfiguration().get(ConfigKeys.SYNC_TIME);
|
int mins = getConfiguration().get(ConfigKeys.SYNC_TIME);
|
||||||
if (mins > 0) {
|
if (mins > 0) {
|
||||||
long ticks = mins * 60 * 20;
|
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.
|
// run an update instantly.
|
||||||
getLog().info("Performing initial data load...");
|
getLog().info("Performing initial data load...");
|
||||||
@ -227,33 +224,33 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
|||||||
|
|
||||||
|
|
||||||
// register tasks
|
// register tasks
|
||||||
scheduler.asyncRepeating(new ExpireTemporaryTask(this), 60L);
|
this.scheduler.asyncRepeating(new ExpireTemporaryTask(this), 60L);
|
||||||
scheduler.asyncRepeating(new CacheHousekeepingTask(this), 2400L);
|
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
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
permissionVault.shutdown();
|
this.permissionVault.shutdown();
|
||||||
verboseHandler.shutdown();
|
this.verboseHandler.shutdown();
|
||||||
|
|
||||||
getLog().info("Closing storage...");
|
getLog().info("Closing storage...");
|
||||||
storage.shutdown();
|
this.storage.shutdown();
|
||||||
|
|
||||||
if (fileWatcher != null) {
|
if (this.fileWatcher != null) {
|
||||||
fileWatcher.close();
|
this.fileWatcher.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (messagingService != null) {
|
if (this.messagingService != null) {
|
||||||
getLog().info("Closing messaging service...");
|
getLog().info("Closing messaging service...");
|
||||||
messagingService.close();
|
this.messagingService.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
ApiRegistrationUtil.unregisterProvider();
|
ApiRegistrationUtil.unregisterProvider();
|
||||||
|
|
||||||
getLog().info("Shutting down internal scheduler...");
|
getLog().info("Shutting down internal scheduler...");
|
||||||
scheduler.shutdown();
|
this.scheduler.shutdown();
|
||||||
|
|
||||||
getProxy().getScheduler().cancel(this);
|
getProxy().getScheduler().cancel(this);
|
||||||
getProxy().getPluginManager().unregisterListeners(this);
|
getProxy().getPluginManager().unregisterListeners(this);
|
||||||
@ -277,11 +274,12 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<ExtendedMessagingService> getMessagingService() {
|
public Optional<ExtendedMessagingService> getMessagingService() {
|
||||||
return Optional.ofNullable(messagingService);
|
return Optional.ofNullable(this.messagingService);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Optional<FileWatcher> getFileWatcher() {
|
public Optional<FileWatcher> getFileWatcher() {
|
||||||
return Optional.ofNullable(fileWatcher);
|
return Optional.ofNullable(this.fileWatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -316,7 +314,7 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ProxiedPlayer getPlayer(User user) {
|
public ProxiedPlayer getPlayer(User user) {
|
||||||
return getProxy().getPlayer(uuidCache.getExternalUUID(user.getUuid()));
|
return getProxy().getPlayer(this.uuidCache.getExternalUUID(user.getUuid()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -338,7 +336,7 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
|||||||
if (player == null) {
|
if (player == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return contextManager.getApplicableContexts(player);
|
return this.contextManager.getApplicableContexts(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -374,4 +372,118 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
|||||||
public Sender getConsoleSender() {
|
public Sender getConsoleSender() {
|
||||||
return getSenderFactory().wrap(getProxy().getConsole());
|
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;
|
package me.lucko.luckperms.bungee.calculators;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.Contexts;
|
import me.lucko.luckperms.api.Contexts;
|
||||||
@ -42,33 +40,36 @@ import me.lucko.luckperms.common.processors.WildcardProcessor;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class BungeeCalculatorFactory extends AbstractCalculatorFactory {
|
public class BungeeCalculatorFactory extends AbstractCalculatorFactory {
|
||||||
private final LPBungeePlugin plugin;
|
private final LPBungeePlugin plugin;
|
||||||
|
|
||||||
|
public BungeeCalculatorFactory(LPBungeePlugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PermissionCalculator build(Contexts contexts, PermissionCalculatorMetadata metadata) {
|
public PermissionCalculator build(Contexts contexts, PermissionCalculatorMetadata metadata) {
|
||||||
ImmutableList.Builder<PermissionProcessor> processors = ImmutableList.builder();
|
ImmutableList.Builder<PermissionProcessor> processors = ImmutableList.builder();
|
||||||
|
|
||||||
processors.add(new MapProcessor());
|
processors.add(new MapProcessor());
|
||||||
|
|
||||||
if (plugin.getConfiguration().get(ConfigKeys.APPLYING_REGEX)) {
|
if (this.plugin.getConfiguration().get(ConfigKeys.APPLYING_REGEX)) {
|
||||||
processors.add(new RegexProcessor());
|
processors.add(new RegexProcessor());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin.getConfiguration().get(ConfigKeys.APPLYING_WILDCARDS)) {
|
if (this.plugin.getConfiguration().get(ConfigKeys.APPLYING_WILDCARDS)) {
|
||||||
processors.add(new WildcardProcessor());
|
processors.add(new WildcardProcessor());
|
||||||
}
|
}
|
||||||
|
|
||||||
return registerCalculator(new PermissionCalculator(plugin, metadata, processors.build()));
|
return registerCalculator(new PermissionCalculator(this.plugin, metadata, processors.build()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getActiveProcessors() {
|
public List<String> getActiveProcessors() {
|
||||||
ImmutableList.Builder<String> ret = ImmutableList.builder();
|
ImmutableList.Builder<String> ret = ImmutableList.builder();
|
||||||
ret.add("Map");
|
ret.add("Map");
|
||||||
if (plugin.getConfiguration().get(ConfigKeys.APPLYING_REGEX)) ret.add("Regex");
|
if (this.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_WILDCARDS)) ret.add("Wildcards");
|
||||||
return ret.build();
|
return ret.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,6 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.bungee.contexts;
|
package me.lucko.luckperms.bungee.contexts;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
|
|
||||||
import me.lucko.luckperms.api.Contexts;
|
import me.lucko.luckperms.api.Contexts;
|
||||||
import me.lucko.luckperms.api.context.ContextCalculator;
|
import me.lucko.luckperms.api.context.ContextCalculator;
|
||||||
import me.lucko.luckperms.api.context.MutableContextSet;
|
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;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
public class BackendServerCalculator implements ContextCalculator<ProxiedPlayer> {
|
public class BackendServerCalculator implements ContextCalculator<ProxiedPlayer> {
|
||||||
|
|
||||||
private static String getServer(ProxiedPlayer player) {
|
private static String getServer(ProxiedPlayer player) {
|
||||||
@ -44,12 +43,17 @@ public class BackendServerCalculator implements ContextCalculator<ProxiedPlayer>
|
|||||||
|
|
||||||
private final LuckPermsPlugin plugin;
|
private final LuckPermsPlugin plugin;
|
||||||
|
|
||||||
|
public BackendServerCalculator(LuckPermsPlugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public MutableContextSet giveApplicableContext(ProxiedPlayer subject, MutableContextSet accumulator) {
|
public MutableContextSet giveApplicableContext(@Nonnull ProxiedPlayer subject, @Nonnull MutableContextSet accumulator) {
|
||||||
String server = getServer(subject);
|
String server = getServer(subject);
|
||||||
while (server != null && !accumulator.has(Contexts.WORLD_KEY, server)) {
|
while (server != null && !accumulator.has(Contexts.WORLD_KEY, server)) {
|
||||||
accumulator.add(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;
|
return accumulator;
|
||||||
|
@ -42,11 +42,11 @@ public class BungeeContextManager extends AbstractContextManager<ProxiedPlayer>
|
|||||||
public Contexts formContexts(ProxiedPlayer subject, ImmutableContextSet contextSet) {
|
public Contexts formContexts(ProxiedPlayer subject, ImmutableContextSet contextSet) {
|
||||||
return new Contexts(
|
return new Contexts(
|
||||||
contextSet,
|
contextSet,
|
||||||
plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_PERMS),
|
this.plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_PERMS),
|
||||||
plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS),
|
this.plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS),
|
||||||
true,
|
true,
|
||||||
plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_GROUPS),
|
this.plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_GROUPS),
|
||||||
plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_WORLD_GROUPS),
|
this.plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_WORLD_GROUPS),
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -31,11 +31,14 @@ import com.imaginarycode.minecraft.redisbungee.RedisBungeeAPI;
|
|||||||
import me.lucko.luckperms.api.context.MutableContextSet;
|
import me.lucko.luckperms.api.context.MutableContextSet;
|
||||||
import me.lucko.luckperms.api.context.StaticContextCalculator;
|
import me.lucko.luckperms.api.context.StaticContextCalculator;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
public class RedisBungeeCalculator implements StaticContextCalculator {
|
public class RedisBungeeCalculator implements StaticContextCalculator {
|
||||||
private static final String PROXY_KEY = "proxy";
|
private static final String PROXY_KEY = "proxy";
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public MutableContextSet giveApplicableContext(MutableContextSet accumulator) {
|
public MutableContextSet giveApplicableContext(@Nonnull MutableContextSet accumulator) {
|
||||||
RedisBungeeAPI redisBungee = RedisBungee.getApi();
|
RedisBungeeAPI redisBungee = RedisBungee.getApi();
|
||||||
if (redisBungee != null) {
|
if (redisBungee != null) {
|
||||||
accumulator.add(PROXY_KEY, redisBungee.getServerId());
|
accumulator.add(PROXY_KEY, redisBungee.getServerId());
|
||||||
|
@ -25,12 +25,6 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.bungee.event;
|
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 me.lucko.luckperms.api.Tristate;
|
||||||
|
|
||||||
import net.md_5.bungee.api.CommandSender;
|
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.
|
* 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 class TristateCheckEvent extends Event {
|
||||||
public static Tristate call(CommandSender sender, String permission) {
|
public static Tristate call(CommandSender sender, String permission) {
|
||||||
return ProxyServer.getInstance().getPluginManager().callEvent(new TristateCheckEvent(sender, permission)).getResult();
|
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 CommandSender sender;
|
||||||
private final String permission;
|
private final String permission;
|
||||||
|
|
||||||
@Setter
|
|
||||||
private Tristate result;
|
private Tristate result;
|
||||||
|
|
||||||
public TristateCheckEvent(CommandSender sender, String permission) {
|
public TristateCheckEvent(CommandSender sender, String permission) {
|
||||||
this(sender, permission, sender.getPermissions().contains(permission) ? Tristate.TRUE : Tristate.UNDEFINED);
|
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;
|
package me.lucko.luckperms.bungee.listeners;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
|
|
||||||
import me.lucko.luckperms.bungee.LPBungeePlugin;
|
import me.lucko.luckperms.bungee.LPBungeePlugin;
|
||||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||||
import me.lucko.luckperms.common.locale.Message;
|
import me.lucko.luckperms.common.locale.Message;
|
||||||
@ -45,10 +43,13 @@ import net.md_5.bungee.event.EventPriority;
|
|||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class BungeeConnectionListener implements Listener {
|
public class BungeeConnectionListener implements Listener {
|
||||||
private final LPBungeePlugin plugin;
|
private final LPBungeePlugin plugin;
|
||||||
|
|
||||||
|
public BungeeConnectionListener(LPBungeePlugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOW)
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
public void onPlayerLogin(LoginEvent e) {
|
public void onPlayerLogin(LoginEvent e) {
|
||||||
/* Called when the player first attempts a connection with the server.
|
/* 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.
|
/* registers the plugins intent to modify this events state going forward.
|
||||||
this will prevent the event from completing until we're finished handling. */
|
this will prevent the event from completing until we're finished handling. */
|
||||||
e.registerIntent(plugin);
|
e.registerIntent(this.plugin);
|
||||||
|
|
||||||
final PendingConnection c = e.getConnection();
|
final PendingConnection c = e.getConnection();
|
||||||
|
|
||||||
if (plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) {
|
if (this.plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) {
|
||||||
plugin.getLog().info("Processing pre-login for " + c.getUniqueId() + " - " + c.getName());
|
this.plugin.getLog().info("Processing pre-login for " + c.getUniqueId() + " - " + c.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.getScheduler().doAsync(() -> {
|
this.plugin.getScheduler().doAsync(() -> {
|
||||||
plugin.getUniqueConnections().add(c.getUniqueId());
|
this.plugin.getUniqueConnections().add(c.getUniqueId());
|
||||||
|
|
||||||
/* Actually process the login for the connection.
|
/* Actually process the login for the connection.
|
||||||
We do this here to delay the login until the data is ready.
|
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.
|
- creating a user instance in the UserManager for this connection.
|
||||||
- setting up cached data. */
|
- setting up cached data. */
|
||||||
try {
|
try {
|
||||||
User user = LoginHelper.loadUser(plugin, c.getUniqueId(), c.getName(), true);
|
User user = LoginHelper.loadUser(this.plugin, c.getUniqueId(), c.getName(), true);
|
||||||
plugin.getEventFactory().handleUserLoginProcess(c.getUniqueId(), c.getName(), user);
|
this.plugin.getEventFactory().handleUserLoginProcess(c.getUniqueId(), c.getName(), user);
|
||||||
} catch (Exception ex) {
|
} 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();
|
ex.printStackTrace();
|
||||||
|
|
||||||
// there was some error loading
|
// 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
|
// 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);
|
e.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// finally, complete our intent to modify state, so the proxy can continue handling the connection.
|
// 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.
|
// schedule a cleanup of the users data in a few seconds.
|
||||||
// this should cover the eventuality that the login fails.
|
// this should cover the eventuality that the login fails.
|
||||||
plugin.getUserManager().scheduleUnload(c.getUniqueId());
|
this.plugin.getUserManager().scheduleUnload(c.getUniqueId());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerPostLogin(PostLoginEvent e) {
|
public void onPlayerPostLogin(PostLoginEvent e) {
|
||||||
final ProxiedPlayer player = e.getPlayer();
|
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)) {
|
if (this.plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) {
|
||||||
plugin.getLog().info("Processing post-login for " + player.getUniqueId() + " - " + player.getName());
|
this.plugin.getLog().info("Processing post-login for " + player.getUniqueId() + " - " + player.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
if (plugin.getConfiguration().get(ConfigKeys.CANCEL_FAILED_LOGINS)) {
|
if (this.plugin.getConfiguration().get(ConfigKeys.CANCEL_FAILED_LOGINS)) {
|
||||||
// disconnect the user
|
// disconnect the user
|
||||||
plugin.getLog().warn("User " + player.getUniqueId() + " - " + player.getName() + " doesn't have data pre-loaded - cancelling login.");
|
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(plugin.getLocaleManager())));
|
e.getPlayer().disconnect(TextComponent.fromLegacyText(Message.LOADING_ERROR.asString(this.plugin.getLocaleManager())));
|
||||||
} else {
|
} else {
|
||||||
// just send a message
|
// just send a message
|
||||||
plugin.getProxy().getScheduler().schedule(plugin, () -> {
|
this.plugin.getProxy().getScheduler().schedule(this.plugin, () -> {
|
||||||
if (!player.isConnected()) {
|
if (!player.isConnected()) {
|
||||||
return;
|
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);
|
}, 1, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -135,7 +136,7 @@ public class BungeeConnectionListener implements Listener {
|
|||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void onPlayerQuit(PlayerDisconnectEvent e) {
|
public void onPlayerQuit(PlayerDisconnectEvent e) {
|
||||||
// Request that the users data is unloaded.
|
// 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;
|
package me.lucko.luckperms.bungee.listeners;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
|
|
||||||
import me.lucko.luckperms.api.Contexts;
|
import me.lucko.luckperms.api.Contexts;
|
||||||
import me.lucko.luckperms.api.Tristate;
|
import me.lucko.luckperms.api.Tristate;
|
||||||
import me.lucko.luckperms.bungee.LPBungeePlugin;
|
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.EventHandler;
|
||||||
import net.md_5.bungee.event.EventPriority;
|
import net.md_5.bungee.event.EventPriority;
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class BungeePermissionCheckListener implements Listener {
|
public class BungeePermissionCheckListener implements Listener {
|
||||||
private final LPBungeePlugin plugin;
|
private final LPBungeePlugin plugin;
|
||||||
|
|
||||||
|
public BungeePermissionCheckListener(LPBungeePlugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onPlayerPermissionCheck(PermissionCheckEvent e) {
|
public void onPlayerPermissionCheck(PermissionCheckEvent e) {
|
||||||
if (!(e.getSender() instanceof ProxiedPlayer)) {
|
if (!(e.getSender() instanceof ProxiedPlayer)) {
|
||||||
@ -53,15 +54,15 @@ public class BungeePermissionCheckListener implements Listener {
|
|||||||
|
|
||||||
ProxiedPlayer player = ((ProxiedPlayer) e.getSender());
|
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) {
|
if (user == null) {
|
||||||
e.setHasPermission(false);
|
e.setHasPermission(false);
|
||||||
return;
|
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);
|
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
|
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());
|
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) {
|
if (user == null) {
|
||||||
e.setResult(Tristate.UNDEFINED);
|
e.setResult(Tristate.UNDEFINED);
|
||||||
return;
|
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);
|
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
|
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() {
|
public void init() {
|
||||||
plugin.getProxy().getPluginManager().registerListener(plugin, this);
|
this.plugin.getProxy().getPluginManager().registerListener(this.plugin, this);
|
||||||
plugin.getProxy().registerChannel(CHANNEL);
|
this.plugin.getProxy().registerChannel(CHANNEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
plugin.getProxy().unregisterChannel(CHANNEL);
|
this.plugin.getProxy().unregisterChannel(CHANNEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -68,7 +68,7 @@ public class BungeeMessagingService extends AbstractMessagingService implements
|
|||||||
|
|
||||||
byte[] data = out.toByteArray();
|
byte[] data = out.toByteArray();
|
||||||
|
|
||||||
for (ServerInfo server : plugin.getProxy().getServers().values()) {
|
for (ServerInfo server : this.plugin.getProxy().getServers().values()) {
|
||||||
server.sendData(CHANNEL, data, true);
|
server.sendData(CHANNEL, data, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -90,7 +90,7 @@ public class BungeeMessagingService extends AbstractMessagingService implements
|
|||||||
|
|
||||||
onMessage(msg, u -> {
|
onMessage(msg, u -> {
|
||||||
// Forward to other servers
|
// 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() {
|
public void init() {
|
||||||
this.redisBungee = RedisBungee.getApi();
|
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
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
redisBungee.unregisterPubSubChannels(CHANNEL);
|
this.redisBungee.unregisterPubSubChannels(CHANNEL);
|
||||||
redisBungee = null;
|
this.redisBungee = null;
|
||||||
|
|
||||||
plugin.getProxy().getPluginManager().unregisterListener(this);
|
this.plugin.getProxy().getPluginManager().unregisterListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void sendMessage(String message) {
|
protected void sendMessage(String message) {
|
||||||
redisBungee.sendChannelMessage(CHANNEL, message);
|
this.redisBungee.sendChannelMessage(CHANNEL, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@ -26,7 +26,6 @@
|
|||||||
package me.lucko.luckperms.bungee.migration;
|
package me.lucko.luckperms.bungee.migration;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.event.cause.CreationCause;
|
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.CommandPermission;
|
||||||
import me.lucko.luckperms.common.commands.CommandResult;
|
import me.lucko.luckperms.common.commands.CommandResult;
|
||||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||||
@ -57,7 +56,7 @@ public class MigrationBungeePerms extends SubCommand<Object> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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");
|
ProgressLogger log = new ProgressLogger("BungeePerms");
|
||||||
log.addListener(plugin.getConsoleSender());
|
log.addListener(plugin.getConsoleSender());
|
||||||
log.addListener(sender);
|
log.addListener(sender);
|
||||||
|
@ -25,15 +25,12 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.bungee.util;
|
package me.lucko.luckperms.bungee.util;
|
||||||
|
|
||||||
import lombok.experimental.UtilityClass;
|
|
||||||
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.RedisBungee;
|
import com.imaginarycode.minecraft.redisbungee.RedisBungee;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@UtilityClass
|
public final class RedisBungeeUtil {
|
||||||
public class RedisBungeeUtil {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Looks up a UUID from username via RedisBungee's uuid cache.
|
* 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)));
|
return Optional.ofNullable(RedisBungee.getApi()).flatMap(a -> Optional.ofNullable(a.getUuidFromName(username, true)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private RedisBungeeUtil() {}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -153,11 +153,10 @@
|
|||||||
<version>2.6.0</version>
|
<version>2.6.0</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- Lombok -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>com.google.code.findbugs</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>jsr305</artifactId>
|
||||||
<version>${lombok.version}</version>
|
<version>3.0.2</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
@ -25,11 +25,6 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.common.actionlog;
|
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.base.Strings;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
@ -50,16 +45,18 @@ import java.util.ArrayList;
|
|||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An implementation of {@link LogEntry} and {@link LogEntry.Builder},
|
* An implementation of {@link LogEntry} and {@link LogEntry.Builder},
|
||||||
* with helper methods for populating and using the entry using internal
|
* with helper methods for populating and using the entry using internal
|
||||||
* LuckPerms classes.
|
* LuckPerms classes.
|
||||||
*/
|
*/
|
||||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
|
||||||
public class ExtendedLogEntry implements LogEntry {
|
public class ExtendedLogEntry implements LogEntry {
|
||||||
|
|
||||||
private static final Comparator<LogEntry> COMPARATOR = Comparator
|
private static final Comparator<LogEntry> COMPARATOR = Comparator
|
||||||
@ -88,68 +85,84 @@ public class ExtendedLogEntry implements LogEntry {
|
|||||||
private final String actedName;
|
private final String actedName;
|
||||||
private final String action;
|
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
|
@Override
|
||||||
public long getTimestamp() {
|
public long getTimestamp() {
|
||||||
return timestamp;
|
return this.timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public UUID getActor() {
|
public UUID getActor() {
|
||||||
return actor;
|
return this.actor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public String getActorName() {
|
public String getActorName() {
|
||||||
return actorName;
|
return this.actorName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getActorFriendlyString() {
|
public String getActorFriendlyString() {
|
||||||
if (Strings.isNullOrEmpty(actorName) || actorName.equals("null")) {
|
if (Strings.isNullOrEmpty(this.actorName) || this.actorName.equals("null")) {
|
||||||
return actor.toString();
|
return this.actor.toString();
|
||||||
}
|
}
|
||||||
return actorName;
|
return this.actorName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Type getType() {
|
public Type getType() {
|
||||||
return type;
|
return this.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Optional<UUID> getActed() {
|
public Optional<UUID> getActed() {
|
||||||
return Optional.ofNullable(acted);
|
return Optional.ofNullable(this.acted);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public String getActedName() {
|
public String getActedName() {
|
||||||
return actedName;
|
return this.actedName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getActedFriendlyString() {
|
public String getActedFriendlyString() {
|
||||||
if (Strings.isNullOrEmpty(actedName) || actedName.equals("null")) {
|
if (Strings.isNullOrEmpty(this.actedName) || this.actedName.equals("null")) {
|
||||||
if (acted != null) {
|
if (this.acted != null) {
|
||||||
return acted.toString();
|
return this.acted.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return String.valueOf(actedName);
|
return String.valueOf(this.actedName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public String getAction() {
|
public String getAction() {
|
||||||
return action;
|
return this.action;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(LogEntry other) {
|
public int compareTo(@Nonnull LogEntry other) {
|
||||||
Preconditions.checkNotNull(other, "other");
|
Objects.requireNonNull(other, "other");
|
||||||
return COMPARATOR.compare(this, other);
|
return COMPARATOR.compare(this, other);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean matchesSearch(String query) {
|
public boolean matchesSearch(String query) {
|
||||||
query = Preconditions.checkNotNull(query, "query").toLowerCase();
|
query = Objects.requireNonNull(query, "query").toLowerCase();
|
||||||
return actorName.toLowerCase().contains(query) ||
|
return this.actorName.toLowerCase().contains(query) ||
|
||||||
actedName.toLowerCase().contains(query) ||
|
this.actedName.toLowerCase().contains(query) ||
|
||||||
action.toLowerCase().contains(query);
|
this.action.toLowerCase().contains(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void submit(LuckPermsPlugin plugin, Sender sender) {
|
public void submit(LuckPermsPlugin plugin, Sender sender) {
|
||||||
@ -172,15 +185,15 @@ public class ExtendedLogEntry implements LogEntry {
|
|||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (o == this) return true;
|
if (o == this) return true;
|
||||||
if (!(o instanceof LogEntry)) return false;
|
if (!(o instanceof LogEntry)) return false;
|
||||||
final LogEntry other = (LogEntry) o;
|
final LogEntry that = (LogEntry) o;
|
||||||
|
|
||||||
return this.getTimestamp() == other.getTimestamp() &&
|
return this.getTimestamp() == that.getTimestamp() &&
|
||||||
this.getActor().equals(other.getActor()) &&
|
this.getActor().equals(that.getActor()) &&
|
||||||
this.getActorName().equals(other.getActorName()) &&
|
this.getActorName().equals(that.getActorName()) &&
|
||||||
this.getType() == other.getType() &&
|
this.getType() == that.getType() &&
|
||||||
this.getActed().equals(other.getActed()) &&
|
this.getActed().equals(that.getActed()) &&
|
||||||
this.getActedName().equals(other.getActedName()) &&
|
this.getActedName().equals(that.getActedName()) &&
|
||||||
this.getAction().equals(other.getAction());
|
this.getAction().equals(that.getAction());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -197,7 +210,6 @@ public class ExtendedLogEntry implements LogEntry {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ToString
|
|
||||||
public static class ExtendedLogEntryBuilder implements LogEntry.Builder {
|
public static class ExtendedLogEntryBuilder implements LogEntry.Builder {
|
||||||
|
|
||||||
private long timestamp = 0L;
|
private long timestamp = 0L;
|
||||||
@ -208,45 +220,52 @@ public class ExtendedLogEntry implements LogEntry {
|
|||||||
private String actedName = null;
|
private String actedName = null;
|
||||||
private String action = null;
|
private String action = null;
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public ExtendedLogEntryBuilder setTimestamp(long timestamp) {
|
public ExtendedLogEntryBuilder setTimestamp(long timestamp) {
|
||||||
this.timestamp = timestamp;
|
this.timestamp = timestamp;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public ExtendedLogEntryBuilder setActor(UUID actor) {
|
public ExtendedLogEntryBuilder setActor(@Nonnull UUID actor) {
|
||||||
this.actor = Preconditions.checkNotNull(actor, "actor");
|
this.actor = Objects.requireNonNull(actor, "actor");
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public ExtendedLogEntryBuilder setActorName(String actorName) {
|
public ExtendedLogEntryBuilder setActorName(@Nonnull String actorName) {
|
||||||
this.actorName = Preconditions.checkNotNull(actorName, "actorName");
|
this.actorName = Objects.requireNonNull(actorName, "actorName");
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public ExtendedLogEntryBuilder setType(Type type) {
|
public ExtendedLogEntryBuilder setType(@Nonnull Type type) {
|
||||||
this.type = Preconditions.checkNotNull(type, "type");
|
this.type = Objects.requireNonNull(type, "type");
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public ExtendedLogEntryBuilder setActed(UUID acted) {
|
public ExtendedLogEntryBuilder setActed(UUID acted) {
|
||||||
this.acted = acted; // nullable
|
this.acted = acted; // nullable
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public ExtendedLogEntryBuilder setActedName(String actedName) {
|
public ExtendedLogEntryBuilder setActedName(@Nonnull String actedName) {
|
||||||
this.actedName = Preconditions.checkNotNull(actedName, "actedName");
|
this.actedName = Objects.requireNonNull(actedName, "actedName");
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public ExtendedLogEntryBuilder setAction(String action) {
|
public ExtendedLogEntryBuilder setAction(@Nonnull String action) {
|
||||||
this.action = Preconditions.checkNotNull(action, "action");
|
this.action = Objects.requireNonNull(action, "action");
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -333,19 +352,32 @@ public class ExtendedLogEntry implements LogEntry {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public ExtendedLogEntry build() {
|
public ExtendedLogEntry build() {
|
||||||
if (timestamp == 0L) {
|
if (this.timestamp == 0L) {
|
||||||
timestamp(DateUtil.unixSecondsNow());
|
timestamp(DateUtil.unixSecondsNow());
|
||||||
}
|
}
|
||||||
|
|
||||||
Preconditions.checkNotNull(actor, "actor");
|
Objects.requireNonNull(this.actor, "actor");
|
||||||
Preconditions.checkNotNull(actorName, "actorName");
|
Objects.requireNonNull(this.actorName, "actorName");
|
||||||
Preconditions.checkNotNull(type, "type");
|
Objects.requireNonNull(this.type, "type");
|
||||||
Preconditions.checkNotNull(actedName, "actedName");
|
Objects.requireNonNull(this.actedName, "actedName");
|
||||||
Preconditions.checkNotNull(action, "action");
|
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;
|
package me.lucko.luckperms.common.actionlog;
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSortedSet;
|
import com.google.common.collect.ImmutableSortedSet;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.LogEntry;
|
import me.lucko.luckperms.api.LogEntry;
|
||||||
@ -77,7 +75,6 @@ public class Log {
|
|||||||
return (int) Math.ceil((double) size / (double) entries);
|
return (int) Math.ceil((double) size / (double) entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Getter
|
|
||||||
private final SortedSet<ExtendedLogEntry> content;
|
private final SortedSet<ExtendedLogEntry> content;
|
||||||
|
|
||||||
public Log(SortedSet<ExtendedLogEntry> content) {
|
public Log(SortedSet<ExtendedLogEntry> content) {
|
||||||
@ -85,19 +82,19 @@ public class Log {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public SortedSet<ExtendedLogEntry> getRecent() {
|
public SortedSet<ExtendedLogEntry> getRecent() {
|
||||||
return content;
|
return this.content;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SortedMap<Integer, ExtendedLogEntry> getRecent(int pageNo, int entriesPerPage) {
|
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) {
|
public int getRecentMaxPages(int entriesPerPage) {
|
||||||
return getMaxPages(content.size(), entriesPerPage);
|
return getMaxPages(this.content.size(), entriesPerPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SortedSet<ExtendedLogEntry> getRecent(UUID actor) {
|
public SortedSet<ExtendedLogEntry> getRecent(UUID actor) {
|
||||||
return content.stream()
|
return this.content.stream()
|
||||||
.filter(e -> e.getActor().equals(actor))
|
.filter(e -> e.getActor().equals(actor))
|
||||||
.collect(Collectors.toCollection(TreeSet::new));
|
.collect(Collectors.toCollection(TreeSet::new));
|
||||||
}
|
}
|
||||||
@ -107,13 +104,13 @@ public class Log {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getRecentMaxPages(UUID actor, int entriesPerPage) {
|
public int getRecentMaxPages(UUID actor, int entriesPerPage) {
|
||||||
return getMaxPages(content.stream()
|
return getMaxPages(this.content.stream()
|
||||||
.filter(e -> e.getActor().equals(actor))
|
.filter(e -> e.getActor().equals(actor))
|
||||||
.mapToInt(x -> 1).sum(), entriesPerPage);
|
.mapToInt(x -> 1).sum(), entriesPerPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SortedSet<ExtendedLogEntry> getUserHistory(UUID uuid) {
|
public SortedSet<ExtendedLogEntry> getUserHistory(UUID uuid) {
|
||||||
return content.stream()
|
return this.content.stream()
|
||||||
.filter(e -> e.getType() == LogEntry.Type.USER)
|
.filter(e -> e.getType() == LogEntry.Type.USER)
|
||||||
.filter(e -> e.getActed().isPresent())
|
.filter(e -> e.getActed().isPresent())
|
||||||
.filter(e -> e.getActed().get().equals(uuid))
|
.filter(e -> e.getActed().get().equals(uuid))
|
||||||
@ -125,7 +122,7 @@ public class Log {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getUserHistoryMaxPages(UUID uuid, int entriesPerPage) {
|
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.getType() == LogEntry.Type.USER)
|
||||||
.filter(e -> e.getActed().isPresent())
|
.filter(e -> e.getActed().isPresent())
|
||||||
.filter(e -> e.getActed().get().equals(uuid))
|
.filter(e -> e.getActed().get().equals(uuid))
|
||||||
@ -133,7 +130,7 @@ public class Log {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public SortedSet<ExtendedLogEntry> getGroupHistory(String name) {
|
public SortedSet<ExtendedLogEntry> getGroupHistory(String name) {
|
||||||
return content.stream()
|
return this.content.stream()
|
||||||
.filter(e -> e.getType() == LogEntry.Type.GROUP)
|
.filter(e -> e.getType() == LogEntry.Type.GROUP)
|
||||||
.filter(e -> e.getActedName().equals(name))
|
.filter(e -> e.getActedName().equals(name))
|
||||||
.collect(Collectors.toCollection(TreeSet::new));
|
.collect(Collectors.toCollection(TreeSet::new));
|
||||||
@ -144,14 +141,14 @@ public class Log {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getGroupHistoryMaxPages(String name, int entriesPerPage) {
|
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.getType() == LogEntry.Type.GROUP)
|
||||||
.filter(e -> e.getActedName().equals(name))
|
.filter(e -> e.getActedName().equals(name))
|
||||||
.mapToInt(x -> 1).sum(), entriesPerPage);
|
.mapToInt(x -> 1).sum(), entriesPerPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SortedSet<ExtendedLogEntry> getTrackHistory(String name) {
|
public SortedSet<ExtendedLogEntry> getTrackHistory(String name) {
|
||||||
return content.stream()
|
return this.content.stream()
|
||||||
.filter(e -> e.getType() == LogEntry.Type.TRACK)
|
.filter(e -> e.getType() == LogEntry.Type.TRACK)
|
||||||
.filter(e -> e.getActedName().equals(name))
|
.filter(e -> e.getActedName().equals(name))
|
||||||
.collect(Collectors.toCollection(TreeSet::new));
|
.collect(Collectors.toCollection(TreeSet::new));
|
||||||
@ -162,14 +159,14 @@ public class Log {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getTrackHistoryMaxPages(String name, int entriesPerPage) {
|
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.getType() == LogEntry.Type.TRACK)
|
||||||
.filter(e -> e.getActedName().equals(name))
|
.filter(e -> e.getActedName().equals(name))
|
||||||
.mapToInt(x -> 1).sum(), entriesPerPage);
|
.mapToInt(x -> 1).sum(), entriesPerPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SortedSet<ExtendedLogEntry> getSearch(String query) {
|
public SortedSet<ExtendedLogEntry> getSearch(String query) {
|
||||||
return content.stream()
|
return this.content.stream()
|
||||||
.filter(e -> e.matchesSearch(query))
|
.filter(e -> e.matchesSearch(query))
|
||||||
.collect(Collectors.toCollection(TreeSet::new));
|
.collect(Collectors.toCollection(TreeSet::new));
|
||||||
}
|
}
|
||||||
@ -179,22 +176,26 @@ public class Log {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getSearchMaxPages(String query, int entriesPerPage) {
|
public int getSearchMaxPages(String query, int entriesPerPage) {
|
||||||
return getMaxPages(content.stream()
|
return getMaxPages(this.content.stream()
|
||||||
.filter(e -> e.matchesSearch(query))
|
.filter(e -> e.matchesSearch(query))
|
||||||
.mapToInt(x -> 1).sum(), entriesPerPage);
|
.mapToInt(x -> 1).sum(), entriesPerPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SortedSet<ExtendedLogEntry> getContent() {
|
||||||
|
return this.content;
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("WeakerAccess")
|
@SuppressWarnings("WeakerAccess")
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
private final SortedSet<ExtendedLogEntry> content = new TreeSet<>();
|
private final SortedSet<ExtendedLogEntry> content = new TreeSet<>();
|
||||||
|
|
||||||
public Builder add(ExtendedLogEntry e) {
|
public Builder add(ExtendedLogEntry e) {
|
||||||
content.add(e);
|
this.content.add(e);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Log build() {
|
public Log build() {
|
||||||
return new Log(content);
|
return new Log(this.content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,8 +25,6 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.common.actionlog;
|
package me.lucko.luckperms.common.actionlog;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
|
|
||||||
import me.lucko.luckperms.api.event.log.LogBroadcastEvent;
|
import me.lucko.luckperms.api.event.log.LogBroadcastEvent;
|
||||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||||
import me.lucko.luckperms.common.commands.impl.log.LogNotify;
|
import me.lucko.luckperms.common.commands.impl.log.LogNotify;
|
||||||
@ -38,16 +36,19 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
|||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class LogDispatcher {
|
public class LogDispatcher {
|
||||||
private final LuckPermsPlugin plugin;
|
private final LuckPermsPlugin plugin;
|
||||||
|
|
||||||
|
public LogDispatcher(LuckPermsPlugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
private void broadcast(ExtendedLogEntry entry, LogBroadcastEvent.Origin origin, Sender sender) {
|
private void broadcast(ExtendedLogEntry entry, LogBroadcastEvent.Origin origin, Sender sender) {
|
||||||
plugin.getOnlineSenders()
|
this.plugin.getOnlineSenders()
|
||||||
.filter(CommandPermission.LOG_NOTIFY::isAuthorized)
|
.filter(CommandPermission.LOG_NOTIFY::isAuthorized)
|
||||||
.filter(s -> {
|
.filter(s -> {
|
||||||
boolean shouldCancel = LogNotify.isIgnoring(plugin, s.getUuid()) || (sender != null && s.getUuid().equals(sender.getUuid()));
|
boolean shouldCancel = LogNotify.isIgnoring(this.plugin, s.getUuid()) || (sender != null && s.getUuid().equals(sender.getUuid()));
|
||||||
return !plugin.getEventFactory().handleLogNotify(shouldCancel, entry, origin, s);
|
return !this.plugin.getEventFactory().handleLogNotify(shouldCancel, entry, origin, s);
|
||||||
})
|
})
|
||||||
.forEach(s -> Message.LOG.send(s,
|
.forEach(s -> Message.LOG.send(s,
|
||||||
entry.getActorFriendlyString(),
|
entry.getActorFriendlyString(),
|
||||||
@ -59,8 +60,8 @@ public class LogDispatcher {
|
|||||||
|
|
||||||
public void dispatch(ExtendedLogEntry entry, Sender sender) {
|
public void dispatch(ExtendedLogEntry entry, Sender sender) {
|
||||||
// set the event to cancelled if the sender is import
|
// set the event to cancelled if the sender is import
|
||||||
if (!plugin.getEventFactory().handleLogPublish(sender.isImport(), entry)) {
|
if (!this.plugin.getEventFactory().handleLogPublish(sender.isImport(), entry)) {
|
||||||
plugin.getStorage().logAction(entry);
|
this.plugin.getStorage().logAction(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
// don't dispatch log entries sent by an import process
|
// don't dispatch log entries sent by an import process
|
||||||
@ -68,21 +69,21 @@ public class LogDispatcher {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<ExtendedMessagingService> messagingService = plugin.getMessagingService();
|
Optional<ExtendedMessagingService> messagingService = this.plugin.getMessagingService();
|
||||||
if (!sender.isImport() && messagingService.isPresent()) {
|
if (!sender.isImport() && messagingService.isPresent()) {
|
||||||
messagingService.get().pushLog(entry);
|
messagingService.get().pushLog(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean shouldCancel = !plugin.getConfiguration().get(ConfigKeys.LOG_NOTIFY);
|
boolean shouldCancel = !this.plugin.getConfiguration().get(ConfigKeys.LOG_NOTIFY);
|
||||||
if (!plugin.getEventFactory().handleLogBroadcast(shouldCancel, entry, LogBroadcastEvent.Origin.LOCAL)) {
|
if (!this.plugin.getEventFactory().handleLogBroadcast(shouldCancel, entry, LogBroadcastEvent.Origin.LOCAL)) {
|
||||||
broadcast(entry, LogBroadcastEvent.Origin.LOCAL, sender);
|
broadcast(entry, LogBroadcastEvent.Origin.LOCAL, sender);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dispatchFromApi(ExtendedLogEntry entry) {
|
public void dispatchFromApi(ExtendedLogEntry entry) {
|
||||||
if (!plugin.getEventFactory().handleLogPublish(false, entry)) {
|
if (!this.plugin.getEventFactory().handleLogPublish(false, entry)) {
|
||||||
try {
|
try {
|
||||||
plugin.getStorage().logAction(entry).get();
|
this.plugin.getStorage().logAction(entry).get();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -92,17 +93,17 @@ public class LogDispatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void broadcastFromApi(ExtendedLogEntry entry) {
|
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);
|
boolean shouldCancel = !this.plugin.getConfiguration().get(ConfigKeys.LOG_NOTIFY);
|
||||||
if (!plugin.getEventFactory().handleLogBroadcast(shouldCancel, entry, LogBroadcastEvent.Origin.LOCAL_API)) {
|
if (!this.plugin.getEventFactory().handleLogBroadcast(shouldCancel, entry, LogBroadcastEvent.Origin.LOCAL_API)) {
|
||||||
broadcast(entry, LogBroadcastEvent.Origin.LOCAL_API, null);
|
broadcast(entry, LogBroadcastEvent.Origin.LOCAL_API, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dispatchFromRemote(ExtendedLogEntry entry) {
|
public void dispatchFromRemote(ExtendedLogEntry entry) {
|
||||||
boolean shouldCancel = !plugin.getConfiguration().get(ConfigKeys.BROADCAST_RECEIVED_LOG_ENTRIES) || !plugin.getConfiguration().get(ConfigKeys.LOG_NOTIFY);
|
boolean shouldCancel = !this.plugin.getConfiguration().get(ConfigKeys.BROADCAST_RECEIVED_LOG_ENTRIES) || !this.plugin.getConfiguration().get(ConfigKeys.LOG_NOTIFY);
|
||||||
if (!plugin.getEventFactory().handleLogBroadcast(shouldCancel, entry, LogBroadcastEvent.Origin.REMOTE)) {
|
if (!this.plugin.getEventFactory().handleLogBroadcast(shouldCancel, entry, LogBroadcastEvent.Origin.REMOTE)) {
|
||||||
broadcast(entry, LogBroadcastEvent.Origin.LOCAL_API, null);
|
broadcast(entry, LogBroadcastEvent.Origin.LOCAL_API, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,14 +25,11 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.common.api;
|
package me.lucko.luckperms.common.api;
|
||||||
|
|
||||||
import lombok.experimental.UtilityClass;
|
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
|
|
||||||
import me.lucko.luckperms.common.storage.DataConstraints;
|
import me.lucko.luckperms.common.storage.DataConstraints;
|
||||||
|
|
||||||
@UtilityClass
|
public final class ApiUtils {
|
||||||
public class ApiUtils {
|
|
||||||
|
|
||||||
public static String checkUsername(String s) {
|
public static String checkUsername(String s) {
|
||||||
Preconditions.checkArgument(
|
Preconditions.checkArgument(
|
||||||
@ -50,4 +47,6 @@ public class ApiUtils {
|
|||||||
return s.toLowerCase();
|
return s.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ApiUtils() {}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,9 +25,6 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.common.api;
|
package me.lucko.luckperms.common.api;
|
||||||
|
|
||||||
import lombok.AccessLevel;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import me.lucko.luckperms.api.ActionLogger;
|
import me.lucko.luckperms.api.ActionLogger;
|
||||||
import me.lucko.luckperms.api.LPConfiguration;
|
import me.lucko.luckperms.api.LPConfiguration;
|
||||||
import me.lucko.luckperms.api.LuckPermsApi;
|
import me.lucko.luckperms.api.LuckPermsApi;
|
||||||
@ -56,12 +53,13 @@ import java.util.Optional;
|
|||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements the LuckPerms API using the plugin instance
|
* Implements the LuckPerms API using the plugin instance
|
||||||
*/
|
*/
|
||||||
public class LuckPermsApiProvider implements LuckPermsApi {
|
public class LuckPermsApiProvider implements LuckPermsApi {
|
||||||
|
|
||||||
@Getter(AccessLevel.NONE)
|
|
||||||
private final LuckPermsPlugin plugin;
|
private final LuckPermsPlugin plugin;
|
||||||
|
|
||||||
private final PlatformInfo platformInfo;
|
private final PlatformInfo platformInfo;
|
||||||
@ -84,74 +82,86 @@ public class LuckPermsApiProvider implements LuckPermsApi {
|
|||||||
this.metaStackFactory = new ApiMetaStackFactory(plugin);
|
this.metaStackFactory = new ApiMetaStackFactory(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public PlatformInfo getPlatformInfo() {
|
public PlatformInfo getPlatformInfo() {
|
||||||
return platformInfo;
|
return this.platformInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public UserManager getUserManager() {
|
public UserManager getUserManager() {
|
||||||
return userManager;
|
return this.userManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public GroupManager getGroupManager() {
|
public GroupManager getGroupManager() {
|
||||||
return groupManager;
|
return this.groupManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public TrackManager getTrackManager() {
|
public TrackManager getTrackManager() {
|
||||||
return trackManager;
|
return this.trackManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Void> runUpdateTask() {
|
public CompletableFuture<Void> runUpdateTask() {
|
||||||
return plugin.getUpdateTaskBuffer().request();
|
return this.plugin.getUpdateTaskBuffer().request();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public EventBus getEventBus() {
|
public EventBus getEventBus() {
|
||||||
return plugin.getEventFactory().getEventBus();
|
return this.plugin.getEventFactory().getEventBus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public LPConfiguration getConfiguration() {
|
public LPConfiguration getConfiguration() {
|
||||||
return plugin.getConfiguration().getDelegate();
|
return this.plugin.getConfiguration().getDelegate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Storage getStorage() {
|
public Storage getStorage() {
|
||||||
return plugin.getStorage().getDelegate();
|
return this.plugin.getStorage().getDelegate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Optional<MessagingService> getMessagingService() {
|
public Optional<MessagingService> getMessagingService() {
|
||||||
return plugin.getMessagingService().map(Function.identity());
|
return this.plugin.getMessagingService().map(Function.identity());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ActionLogger getActionLogger() {
|
public ActionLogger getActionLogger() {
|
||||||
return actionLogger;
|
return this.actionLogger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public UuidCache getUuidCache() {
|
public UuidCache getUuidCache() {
|
||||||
return plugin.getUuidCache().getDelegate();
|
return this.plugin.getUuidCache().getDelegate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ContextManager getContextManager() {
|
public ContextManager getContextManager() {
|
||||||
return contextManager;
|
return this.contextManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public NodeFactory getNodeFactory() {
|
public NodeFactory getNodeFactory() {
|
||||||
return ApiNodeFactory.INSTANCE;
|
return ApiNodeFactory.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public MetaStackFactory getMetaStackFactory() {
|
public MetaStackFactory getMetaStackFactory() {
|
||||||
return metaStackFactory;
|
return this.metaStackFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,9 +25,6 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.common.api.delegates.manager;
|
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.Contexts;
|
||||||
import me.lucko.luckperms.api.User;
|
import me.lucko.luckperms.api.User;
|
||||||
import me.lucko.luckperms.api.context.ContextCalculator;
|
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.api.delegates.model.ApiUser;
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@AllArgsConstructor
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public class ApiContextManager implements ContextManager {
|
public class ApiContextManager implements ContextManager {
|
||||||
private final LuckPermsPlugin plugin;
|
private final LuckPermsPlugin plugin;
|
||||||
private final me.lucko.luckperms.common.contexts.ContextManager handle;
|
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) {
|
private Object checkType(Object subject) {
|
||||||
if (!handle.getSubjectClass().isAssignableFrom(subject.getClass())) {
|
if (!this.handle.getSubjectClass().isAssignableFrom(subject.getClass())) {
|
||||||
throw new IllegalStateException("Subject class " + subject.getClass() + " is not assignable from " + handle.getSubjectClass());
|
throw new IllegalStateException("Subject class " + subject.getClass() + " is not assignable from " + this.handle.getSubjectClass());
|
||||||
}
|
}
|
||||||
return subject;
|
return subject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public ImmutableContextSet getApplicableContext(@NonNull Object subject) {
|
public ImmutableContextSet getApplicableContext(@Nonnull Object subject) {
|
||||||
return handle.getApplicableContext(checkType(subject));
|
Objects.requireNonNull(subject, "subject");
|
||||||
|
return this.handle.getApplicableContext(checkType(subject));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Contexts getApplicableContexts(@NonNull Object subject) {
|
public Contexts getApplicableContexts(@Nonnull Object subject) {
|
||||||
return handle.getApplicableContexts(checkType(subject));
|
Objects.requireNonNull(subject, "subject");
|
||||||
|
return this.handle.getApplicableContexts(checkType(subject));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Optional<ImmutableContextSet> lookupApplicableContext(@NonNull User user) {
|
public Optional<ImmutableContextSet> lookupApplicableContext(@Nonnull User user) {
|
||||||
return Optional.ofNullable(plugin.getContextForUser(ApiUser.cast(user))).map(c -> c.getContexts().makeImmutable());
|
Objects.requireNonNull(user, "user");
|
||||||
|
return Optional.ofNullable(this.plugin.getContextForUser(ApiUser.cast(user))).map(c -> c.getContexts().makeImmutable());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Optional<Contexts> lookupApplicableContexts(@NonNull User user) {
|
public Optional<Contexts> lookupApplicableContexts(@Nonnull User user) {
|
||||||
return Optional.ofNullable(plugin.getContextForUser(ApiUser.cast(user)));
|
Objects.requireNonNull(user, "user");
|
||||||
|
return Optional.ofNullable(this.plugin.getContextForUser(ApiUser.cast(user)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public ImmutableContextSet getStaticContext() {
|
public ImmutableContextSet getStaticContext() {
|
||||||
return handle.getStaticContext();
|
return this.handle.getStaticContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Contexts getStaticContexts() {
|
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
|
@Override
|
||||||
public Contexts formContexts(@NonNull Object subject, @NonNull ImmutableContextSet contextSet) {
|
public void registerCalculator(@Nonnull ContextCalculator<?> calculator) {
|
||||||
return handle.formContexts(checkType(subject), contextSet);
|
Objects.requireNonNull(calculator, "calculator");
|
||||||
|
this.handle.registerCalculator(calculator);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Contexts formContexts(@NonNull ImmutableContextSet contextSet) {
|
public void registerStaticCalculator(@Nonnull StaticContextCalculator calculator) {
|
||||||
return handle.formContexts(contextSet);
|
Objects.requireNonNull(calculator, "calculator");
|
||||||
|
this.handle.registerStaticCalculator(calculator);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerCalculator(@NonNull ContextCalculator<?> calculator) {
|
public void invalidateCache(@Nonnull Object subject) {
|
||||||
handle.registerCalculator(calculator);
|
Objects.requireNonNull(subject, "subject");
|
||||||
}
|
this.handle.invalidateCache(checkType(subject));
|
||||||
|
|
||||||
@Override
|
|
||||||
public void registerStaticCalculator(@NonNull StaticContextCalculator calculator) {
|
|
||||||
handle.registerStaticCalculator(calculator);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void invalidateCache(@NonNull Object subject) {
|
|
||||||
handle.invalidateCache(checkType(subject));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,32 +25,38 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.common.api.delegates.manager;
|
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.Group;
|
||||||
import me.lucko.luckperms.api.manager.GroupManager;
|
import me.lucko.luckperms.api.manager.GroupManager;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@AllArgsConstructor
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
public class ApiGroupManager implements GroupManager {
|
public class ApiGroupManager implements GroupManager {
|
||||||
private final me.lucko.luckperms.common.managers.GroupManager handle;
|
private final me.lucko.luckperms.common.managers.GroupManager handle;
|
||||||
|
|
||||||
|
public ApiGroupManager(me.lucko.luckperms.common.managers.GroupManager handle) {
|
||||||
|
this.handle = handle;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Group getGroup(@NonNull String name) {
|
public Group getGroup(@Nonnull String name) {
|
||||||
me.lucko.luckperms.common.model.Group group = handle.getIfLoaded(name);
|
Objects.requireNonNull(name, "name");
|
||||||
|
me.lucko.luckperms.common.model.Group group = this.handle.getIfLoaded(name);
|
||||||
return group == null ? null : group.getDelegate();
|
return group == null ? null : group.getDelegate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Set<Group> getLoadedGroups() {
|
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
|
@Override
|
||||||
public boolean isLoaded(@NonNull String name) {
|
public boolean isLoaded(@Nonnull String name) {
|
||||||
return handle.isLoaded(name);
|
Objects.requireNonNull(name, "name");
|
||||||
|
return this.handle.isLoaded(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,32 +25,38 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.common.api.delegates.manager;
|
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.Track;
|
||||||
import me.lucko.luckperms.api.manager.TrackManager;
|
import me.lucko.luckperms.api.manager.TrackManager;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@AllArgsConstructor
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
public class ApiTrackManager implements TrackManager {
|
public class ApiTrackManager implements TrackManager {
|
||||||
private final me.lucko.luckperms.common.managers.TrackManager handle;
|
private final me.lucko.luckperms.common.managers.TrackManager handle;
|
||||||
|
|
||||||
|
public ApiTrackManager(me.lucko.luckperms.common.managers.TrackManager handle) {
|
||||||
|
this.handle = handle;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Track getTrack(@NonNull String name) {
|
public Track getTrack(@Nonnull String name) {
|
||||||
me.lucko.luckperms.common.model.Track track = handle.getIfLoaded(name);
|
Objects.requireNonNull(name, "name");
|
||||||
|
me.lucko.luckperms.common.model.Track track = this.handle.getIfLoaded(name);
|
||||||
return track == null ? null : track.getDelegate();
|
return track == null ? null : track.getDelegate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Set<Track> getLoadedTracks() {
|
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
|
@Override
|
||||||
public boolean isLoaded(@NonNull String name) {
|
public boolean isLoaded(@Nonnull String name) {
|
||||||
return handle.isLoaded(name);
|
Objects.requireNonNull(name, "name");
|
||||||
|
return this.handle.isLoaded(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,48 +25,57 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.common.api.delegates.manager;
|
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.User;
|
||||||
import me.lucko.luckperms.api.manager.UserManager;
|
import me.lucko.luckperms.api.manager.UserManager;
|
||||||
import me.lucko.luckperms.common.api.delegates.model.ApiUser;
|
import me.lucko.luckperms.common.api.delegates.model.ApiUser;
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.references.UserIdentifier;
|
import me.lucko.luckperms.common.references.UserIdentifier;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@AllArgsConstructor
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
public class ApiUserManager implements UserManager {
|
public class ApiUserManager implements UserManager {
|
||||||
private final LuckPermsPlugin plugin;
|
private final LuckPermsPlugin plugin;
|
||||||
private final me.lucko.luckperms.common.managers.UserManager handle;
|
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
|
@Override
|
||||||
public User getUser(@NonNull UUID uuid) {
|
public User getUser(@Nonnull UUID uuid) {
|
||||||
me.lucko.luckperms.common.model.User user = handle.getIfLoaded(uuid);
|
Objects.requireNonNull(uuid, "uuid");
|
||||||
|
me.lucko.luckperms.common.model.User user = this.handle.getIfLoaded(uuid);
|
||||||
return user == null ? null : user.getDelegate();
|
return user == null ? null : user.getDelegate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public User getUser(@NonNull String name) {
|
public User getUser(@Nonnull String name) {
|
||||||
me.lucko.luckperms.common.model.User user = handle.getByUsername(name);
|
Objects.requireNonNull(name, "name");
|
||||||
|
me.lucko.luckperms.common.model.User user = this.handle.getByUsername(name);
|
||||||
return user == null ? null : user.getDelegate();
|
return user == null ? null : user.getDelegate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Set<User> getLoadedUsers() {
|
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
|
@Override
|
||||||
public boolean isLoaded(@NonNull UUID uuid) {
|
public boolean isLoaded(@Nonnull UUID uuid) {
|
||||||
return handle.isLoaded(UserIdentifier.of(uuid, null));
|
Objects.requireNonNull(uuid, "uuid");
|
||||||
|
return this.handle.isLoaded(UserIdentifier.of(uuid, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void cleanupUser(@NonNull User user) {
|
public void cleanupUser(@Nonnull User user) {
|
||||||
handle.scheduleUnload(plugin.getUuidCache().getExternalUUID(ApiUser.cast(user).getUuid()));
|
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;
|
package me.lucko.luckperms.common.api.delegates.misc;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
|
|
||||||
import me.lucko.luckperms.api.ActionLogger;
|
import me.lucko.luckperms.api.ActionLogger;
|
||||||
import me.lucko.luckperms.api.Log;
|
import me.lucko.luckperms.api.Log;
|
||||||
import me.lucko.luckperms.api.LogEntry;
|
import me.lucko.luckperms.api.LogEntry;
|
||||||
@ -36,32 +34,42 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
|||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
public class ApiActionLogger implements ActionLogger {
|
public class ApiActionLogger implements ActionLogger {
|
||||||
private final LuckPermsPlugin plugin;
|
private final LuckPermsPlugin plugin;
|
||||||
|
|
||||||
|
public ApiActionLogger(LuckPermsPlugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public LogEntry.Builder newEntryBuilder() {
|
public LogEntry.Builder newEntryBuilder() {
|
||||||
return ExtendedLogEntry.build();
|
return ExtendedLogEntry.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Log> getLog() {
|
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
|
@Override
|
||||||
public CompletableFuture<Void> submit(LogEntry entry) {
|
public CompletableFuture<Void> submit(@Nonnull LogEntry entry) {
|
||||||
return CompletableFuture.runAsync(() -> plugin.getLogDispatcher().dispatchFromApi((ExtendedLogEntry) entry), plugin.getScheduler().async());
|
return CompletableFuture.runAsync(() -> this.plugin.getLogDispatcher().dispatchFromApi((ExtendedLogEntry) entry), this.plugin.getScheduler().async());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Void> submitToStorage(LogEntry entry) {
|
public CompletableFuture<Void> submitToStorage(@Nonnull LogEntry entry) {
|
||||||
return plugin.getStorage().noBuffer().logAction(entry);
|
return this.plugin.getStorage().noBuffer().logAction(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Void> broadcastAction(LogEntry entry) {
|
public CompletableFuture<Void> broadcastAction(@Nonnull LogEntry entry) {
|
||||||
return CompletableFuture.runAsync(() -> plugin.getLogDispatcher().broadcastFromApi((ExtendedLogEntry) entry), plugin.getScheduler().async());
|
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 java.util.Map;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
public class ApiConfiguration implements LPConfiguration {
|
public class ApiConfiguration implements LPConfiguration {
|
||||||
private final LuckPermsConfiguration handle;
|
private final LuckPermsConfiguration handle;
|
||||||
private final Unsafe unsafe;
|
private final Unsafe unsafe;
|
||||||
@ -42,61 +44,66 @@ public class ApiConfiguration implements LPConfiguration {
|
|||||||
this.unsafe = new UnsafeImpl();
|
this.unsafe = new UnsafeImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public String getServer() {
|
public String getServer() {
|
||||||
return handle.get(ConfigKeys.SERVER);
|
return this.handle.get(ConfigKeys.SERVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean getIncludeGlobalPerms() {
|
public boolean getIncludeGlobalPerms() {
|
||||||
return handle.get(ConfigKeys.INCLUDING_GLOBAL_PERMS);
|
return this.handle.get(ConfigKeys.INCLUDING_GLOBAL_PERMS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean getIncludeGlobalWorldPerms() {
|
public boolean getIncludeGlobalWorldPerms() {
|
||||||
return handle.get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS);
|
return this.handle.get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean getApplyGlobalGroups() {
|
public boolean getApplyGlobalGroups() {
|
||||||
return handle.get(ConfigKeys.APPLYING_GLOBAL_GROUPS);
|
return this.handle.get(ConfigKeys.APPLYING_GLOBAL_GROUPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean getApplyGlobalWorldGroups() {
|
public boolean getApplyGlobalWorldGroups() {
|
||||||
return handle.get(ConfigKeys.APPLYING_GLOBAL_WORLD_GROUPS);
|
return this.handle.get(ConfigKeys.APPLYING_GLOBAL_WORLD_GROUPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public String getStorageMethod() {
|
public String getStorageMethod() {
|
||||||
return handle.get(ConfigKeys.STORAGE_METHOD);
|
return this.handle.get(ConfigKeys.STORAGE_METHOD);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean getSplitStorage() {
|
public boolean getSplitStorage() {
|
||||||
return handle.get(ConfigKeys.SPLIT_STORAGE);
|
return this.handle.get(ConfigKeys.SPLIT_STORAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Map<String, String> getSplitStorageOptions() {
|
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));
|
.collect(ImmutableCollectors.toMap(e -> e.getKey().name().toLowerCase(), Map.Entry::getValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Unsafe unsafe() {
|
public Unsafe unsafe() {
|
||||||
return unsafe;
|
return this.unsafe;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final class UnsafeImpl implements Unsafe {
|
private final class UnsafeImpl implements Unsafe {
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Object getObject(String key) {
|
public Object getObject(String key) {
|
||||||
ConfigKey<?> configKey = ConfigKeys.getAllKeys().get(key.toUpperCase());
|
ConfigKey<?> configKey = ConfigKeys.getAllKeys().get(key.toUpperCase());
|
||||||
if (configKey == null) {
|
if (configKey == null) {
|
||||||
throw new IllegalArgumentException("Unknown key: " + key);
|
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;
|
package me.lucko.luckperms.common.api.delegates.misc;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.NonNull;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.metastacking.MetaStackDefinition;
|
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 me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@AllArgsConstructor
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
public class ApiMetaStackFactory implements MetaStackFactory {
|
public class ApiMetaStackFactory implements MetaStackFactory {
|
||||||
public final LuckPermsPlugin plugin;
|
public final LuckPermsPlugin plugin;
|
||||||
|
|
||||||
@Override
|
public ApiMetaStackFactory(LuckPermsPlugin plugin) {
|
||||||
public Optional<MetaStackElement> fromString(@NonNull String definition) {
|
this.plugin = plugin;
|
||||||
return StandardStackElements.parseFromString(plugin, definition);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@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()) {
|
if (definitions.isEmpty()) {
|
||||||
return ImmutableList.of();
|
return ImmutableList.of();
|
||||||
}
|
}
|
||||||
return StandardStackElements.parseList(plugin, definitions);
|
return StandardStackElements.parseList(this.plugin, definitions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@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);
|
return new SimpleMetaStackDefinition(elements, startSpacer, middleSpacer, endSpacer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,14 +25,16 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.common.api.delegates.misc;
|
package me.lucko.luckperms.common.api.delegates.misc;
|
||||||
|
|
||||||
import lombok.NonNull;
|
|
||||||
|
|
||||||
import me.lucko.luckperms.api.ChatMetaType;
|
import me.lucko.luckperms.api.ChatMetaType;
|
||||||
import me.lucko.luckperms.api.Group;
|
import me.lucko.luckperms.api.Group;
|
||||||
import me.lucko.luckperms.api.Node;
|
import me.lucko.luckperms.api.Node;
|
||||||
import me.lucko.luckperms.common.api.delegates.model.ApiGroup;
|
import me.lucko.luckperms.common.api.delegates.model.ApiGroup;
|
||||||
import me.lucko.luckperms.common.node.NodeFactory;
|
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 final class ApiNodeFactory implements me.lucko.luckperms.api.NodeFactory {
|
||||||
public static final ApiNodeFactory INSTANCE = new ApiNodeFactory();
|
public static final ApiNodeFactory INSTANCE = new ApiNodeFactory();
|
||||||
|
|
||||||
@ -40,43 +42,61 @@ public final class ApiNodeFactory implements me.lucko.luckperms.api.NodeFactory
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Node.Builder newBuilder(@NonNull String permission) {
|
public Node.Builder newBuilder(@Nonnull String permission) {
|
||||||
|
Objects.requireNonNull(permission, "permission");
|
||||||
return NodeFactory.builder(permission);
|
return NodeFactory.builder(permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Node.Builder newBuilderFromExisting(@NonNull Node other) {
|
public Node.Builder newBuilderFromExisting(@Nonnull Node other) {
|
||||||
|
Objects.requireNonNull(other, "other");
|
||||||
return NodeFactory.builder(other);
|
return NodeFactory.builder(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Node.Builder makeGroupNode(Group group) {
|
public Node.Builder makeGroupNode(@Nonnull Group group) {
|
||||||
|
Objects.requireNonNull(group, "group");
|
||||||
return NodeFactory.buildGroupNode(ApiGroup.cast(group));
|
return NodeFactory.buildGroupNode(ApiGroup.cast(group));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Node.Builder makeGroupNode(String groupName) {
|
public Node.Builder makeGroupNode(@Nonnull String groupName) {
|
||||||
|
Objects.requireNonNull(groupName, "groupName");
|
||||||
return NodeFactory.buildGroupNode(groupName);
|
return NodeFactory.buildGroupNode(groupName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@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);
|
return NodeFactory.buildMetaNode(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@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);
|
return NodeFactory.buildChatMetaNode(type, priority, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@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);
|
return NodeFactory.buildPrefixNode(priority, prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@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);
|
return NodeFactory.buildSuffixNode(priority, suffix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,6 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.common.api.delegates.misc;
|
package me.lucko.luckperms.common.api.delegates.misc;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
|
|
||||||
import me.lucko.luckperms.api.platform.PlatformInfo;
|
import me.lucko.luckperms.api.platform.PlatformInfo;
|
||||||
import me.lucko.luckperms.api.platform.PlatformType;
|
import me.lucko.luckperms.api.platform.PlatformType;
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
@ -35,13 +33,19 @@ import java.util.Collections;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
public class ApiPlatformInfo implements PlatformInfo {
|
public class ApiPlatformInfo implements PlatformInfo {
|
||||||
private final LuckPermsPlugin plugin;
|
private final LuckPermsPlugin plugin;
|
||||||
|
|
||||||
|
public ApiPlatformInfo(LuckPermsPlugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public String getVersion() {
|
public String getVersion() {
|
||||||
return plugin.getVersion();
|
return this.plugin.getVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -49,18 +53,20 @@ public class ApiPlatformInfo implements PlatformInfo {
|
|||||||
return 4.0;
|
return 4.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public PlatformType getType() {
|
public PlatformType getType() {
|
||||||
return plugin.getServerType();
|
return this.plugin.getServerType();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Set<UUID> getUniqueConnections() {
|
public Set<UUID> getUniqueConnections() {
|
||||||
return Collections.unmodifiableSet(plugin.getUniqueConnections());
|
return Collections.unmodifiableSet(this.plugin.getUniqueConnections());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getStartTime() {
|
public long getStartTime() {
|
||||||
return plugin.getStartTime();
|
return this.plugin.getStartTime();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,24 +25,31 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.common.api.delegates.misc;
|
package me.lucko.luckperms.common.api.delegates.misc;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.NonNull;
|
|
||||||
|
|
||||||
import me.lucko.luckperms.api.UuidCache;
|
import me.lucko.luckperms.api.UuidCache;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@AllArgsConstructor
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
public class ApiUuidCache implements UuidCache {
|
public class ApiUuidCache implements UuidCache {
|
||||||
private final me.lucko.luckperms.common.utils.UuidCache handle;
|
private final me.lucko.luckperms.common.utils.UuidCache handle;
|
||||||
|
|
||||||
@Override
|
public ApiUuidCache(me.lucko.luckperms.common.utils.UuidCache handle) {
|
||||||
public UUID getUUID(@NonNull UUID external) {
|
this.handle = handle;
|
||||||
return handle.getUUID(external);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public UUID getExternalUUID(@NonNull UUID internal) {
|
public UUID getUUID(@Nonnull UUID external) {
|
||||||
return handle.getExternalUUID(internal);
|
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;
|
package me.lucko.luckperms.common.api.delegates.model;
|
||||||
|
|
||||||
import lombok.AccessLevel;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.NonNull;
|
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.Group;
|
import me.lucko.luckperms.api.Group;
|
||||||
import me.lucko.luckperms.api.caching.GroupData;
|
import me.lucko.luckperms.api.caching.GroupData;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.OptionalInt;
|
import java.util.OptionalInt;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
public final class ApiGroup extends ApiPermissionHolder implements Group {
|
public final class ApiGroup extends ApiPermissionHolder implements Group {
|
||||||
public static me.lucko.luckperms.common.model.Group cast(Group g) {
|
public static me.lucko.luckperms.common.model.Group cast(Group group) {
|
||||||
Preconditions.checkState(g instanceof ApiGroup, "Illegal instance " + g.getClass() + " cannot be handled by this implementation.");
|
Objects.requireNonNull(group, "group");
|
||||||
return ((ApiGroup) g).getHandle();
|
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;
|
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);
|
super(handle);
|
||||||
this.handle = handle;
|
this.handle = handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
me.lucko.luckperms.common.model.Group getHandle() {
|
||||||
return handle.getName();
|
return this.handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return this.handle.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public OptionalInt getWeight() {
|
public OptionalInt getWeight() {
|
||||||
return handle.getWeight();
|
return this.handle.getWeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public GroupData getCachedData() {
|
||||||
|
return this.handle.getCachedData();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GroupData getCachedData() {
|
|
||||||
return handle.getCachedData();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (o == this) return true;
|
if (o == this) return true;
|
||||||
if (!(o instanceof ApiGroup)) return false;
|
if (!(o instanceof ApiGroup)) return false;
|
||||||
|
ApiGroup that = (ApiGroup) o;
|
||||||
ApiGroup other = (ApiGroup) o;
|
return this.handle.equals(that.handle);
|
||||||
return handle.equals(other.handle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return handle.hashCode();
|
return this.handle.hashCode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,116 +25,147 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.common.api.delegates.model;
|
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.Log;
|
||||||
import me.lucko.luckperms.api.LogEntry;
|
import me.lucko.luckperms.api.LogEntry;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.SortedMap;
|
import java.util.SortedMap;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
import static me.lucko.luckperms.common.api.ApiUtils.checkName;
|
import static me.lucko.luckperms.common.api.ApiUtils.checkName;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@AllArgsConstructor
|
|
||||||
public class ApiLog implements Log {
|
public class ApiLog implements Log {
|
||||||
private static final int ENTRIES_PER_PAGE = 5;
|
private static final int ENTRIES_PER_PAGE = 5;
|
||||||
private final me.lucko.luckperms.common.actionlog.Log handle;
|
private final me.lucko.luckperms.common.actionlog.Log handle;
|
||||||
|
|
||||||
|
public ApiLog(me.lucko.luckperms.common.actionlog.Log handle) {
|
||||||
|
this.handle = handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public SortedSet<LogEntry> getContent() {
|
public SortedSet<LogEntry> getContent() {
|
||||||
return (SortedSet) handle.getContent();
|
return (SortedSet) this.handle.getContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public SortedSet<LogEntry> getRecent() {
|
public SortedSet<LogEntry> getRecent() {
|
||||||
return (SortedSet) handle.getRecent();
|
return (SortedSet) this.handle.getRecent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public SortedMap<Integer, LogEntry> getRecent(int pageNo) {
|
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
|
@Override
|
||||||
public int getRecentMaxPages() {
|
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
|
@Override
|
||||||
public SortedSet<LogEntry> getRecent(@NonNull UUID actor) {
|
public int getRecentMaxPages(@Nonnull UUID actor) {
|
||||||
return (SortedSet) handle.getRecent(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
|
@Override
|
||||||
public SortedMap<Integer, LogEntry> getRecent(int pageNo, @NonNull UUID actor) {
|
public int getUserHistoryMaxPages(@Nonnull UUID uuid) {
|
||||||
return (SortedMap) handle.getRecent(pageNo, actor, ENTRIES_PER_PAGE);
|
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
|
@Override
|
||||||
public int getRecentMaxPages(@NonNull UUID actor) {
|
public int getGroupHistoryMaxPages(@Nonnull String name) {
|
||||||
return handle.getRecentMaxPages(actor, ENTRIES_PER_PAGE);
|
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
|
@Override
|
||||||
public SortedSet<LogEntry> getUserHistory(@NonNull UUID uuid) {
|
public int getTrackHistoryMaxPages(@Nonnull String name) {
|
||||||
return (SortedSet) handle.getUserHistory(uuid);
|
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
|
@Override
|
||||||
public SortedMap<Integer, LogEntry> getUserHistory(int pageNo, @NonNull UUID uuid) {
|
public int getSearchMaxPages(@Nonnull String query) {
|
||||||
return (SortedMap) handle.getUserHistory(pageNo, uuid, ENTRIES_PER_PAGE);
|
Objects.requireNonNull(query, "query");
|
||||||
}
|
return this.handle.getSearchMaxPages(query, 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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,9 +25,8 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.common.api.delegates.model;
|
package me.lucko.luckperms.common.api.delegates.model;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import com.google.common.collect.ImmutableList;
|
||||||
import lombok.NonNull;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.ImmutableSetMultimap;
|
import com.google.common.collect.ImmutableSetMultimap;
|
||||||
import com.google.common.collect.ImmutableSortedSet;
|
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.Group;
|
||||||
import me.lucko.luckperms.common.model.User;
|
import me.lucko.luckperms.common.model.User;
|
||||||
import me.lucko.luckperms.common.node.MetaType;
|
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.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.TreeSet;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@AllArgsConstructor
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
public class ApiPermissionHolder implements PermissionHolder {
|
public class ApiPermissionHolder implements PermissionHolder {
|
||||||
private final me.lucko.luckperms.common.model.PermissionHolder handle;
|
private final me.lucko.luckperms.common.model.PermissionHolder handle;
|
||||||
|
|
||||||
@Override
|
public ApiPermissionHolder(me.lucko.luckperms.common.model.PermissionHolder handle) {
|
||||||
public String getObjectName() {
|
this.handle = Objects.requireNonNull(handle, "handle");
|
||||||
return handle.getObjectName();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
me.lucko.luckperms.common.model.PermissionHolder getHandle() {
|
||||||
|
return this.handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public String getObjectName() {
|
||||||
|
return this.handle.getObjectName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public String getFriendlyName() {
|
public String getFriendlyName() {
|
||||||
if (handle.getType().isGroup()) {
|
if (this.handle.getType().isGroup()) {
|
||||||
Group group = (Group) this.handle;
|
Group group = (Group) this.handle;
|
||||||
return group.getDisplayName().orElse(group.getName());
|
return group.getDisplayName().orElse(group.getName());
|
||||||
}
|
}
|
||||||
return handle.getFriendlyName();
|
return this.handle.getFriendlyName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public CachedData getCachedData() {
|
public CachedData getCachedData() {
|
||||||
return handle.getCachedData();
|
return this.handle.getCachedData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Void> refreshCachedData() {
|
public CompletableFuture<Void> refreshCachedData() {
|
||||||
return handle.getRefreshBuffer().request();
|
return this.handle.getRefreshBuffer().request();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public ImmutableSetMultimap<ImmutableContextSet, Node> getNodes() {
|
public ImmutableSetMultimap<ImmutableContextSet, Node> getNodes() {
|
||||||
return handle.getEnduringNodes();
|
return this.handle.getEnduringNodes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public ImmutableSetMultimap<ImmutableContextSet, Node> getTransientNodes() {
|
public ImmutableSetMultimap<ImmutableContextSet, Node> getTransientNodes() {
|
||||||
return handle.getTransientNodes();
|
return this.handle.getTransientNodes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public List<Node> getOwnNodes() {
|
public List<Node> getOwnNodes() {
|
||||||
return handle.getOwnNodes();
|
return ImmutableList.copyOf(this.handle.getOwnNodes());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public SortedSet<? extends Node> getPermissions() {
|
public SortedSet<? extends Node> getPermissions() {
|
||||||
return ImmutableSortedSet.copyOfSorted(handle.getOwnNodesSorted());
|
return ImmutableSortedSet.copyOfSorted(this.handle.getOwnNodesSorted());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Set<Node> getEnduringPermissions() {
|
public Set<Node> getEnduringPermissions() {
|
||||||
return ImmutableSet.copyOf(handle.getEnduringNodes().values());
|
return ImmutableSet.copyOf(this.handle.getEnduringNodes().values());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Set<Node> getTransientPermissions() {
|
public Set<Node> getTransientPermissions() {
|
||||||
return ImmutableSet.copyOf(handle.getTransientNodes().values());
|
return ImmutableSet.copyOf(this.handle.getTransientNodes().values());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public SortedSet<LocalizedNode> getAllNodes(@NonNull Contexts contexts) {
|
public SortedSet<LocalizedNode> getAllNodes(@Nonnull Contexts contexts) {
|
||||||
return new TreeSet<>(handle.resolveInheritancesAlmostEqual(contexts));
|
Objects.requireNonNull(contexts, "contexts");
|
||||||
|
return ImmutableSortedSet.copyOfSorted(this.handle.resolveInheritancesAlmostEqual(contexts));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public SortedSet<LocalizedNode> getAllNodes() {
|
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
|
@Override
|
||||||
public Set<LocalizedNode> getAllNodesFiltered(@NonNull Contexts contexts) {
|
public boolean inheritsGroup(@Nonnull me.lucko.luckperms.api.Group group) {
|
||||||
return new HashSet<>(handle.getAllNodes(contexts));
|
Objects.requireNonNull(group, "group");
|
||||||
|
return this.handle.inheritsGroup(ApiGroup.cast(group));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Boolean> exportNodes(Contexts contexts, boolean lowerCase) {
|
public boolean inheritsGroup(@Nonnull me.lucko.luckperms.api.Group group, @Nonnull ContextSet contextSet) {
|
||||||
return new HashMap<>(handle.exportNodesAndShorthand(contexts, lowerCase));
|
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
|
@Override
|
||||||
public Tristate hasPermission(@NonNull Node node) {
|
public void clearMatching(@Nonnull Predicate<Node> test) {
|
||||||
return handle.hasPermission(node, false);
|
Objects.requireNonNull(test, "test");
|
||||||
}
|
this.handle.removeIf(test);
|
||||||
|
if (this.handle.getType().isUser()) {
|
||||||
@Override
|
this.handle.getPlugin().getUserManager().giveDefaultIfNeeded((User) this.handle, false);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearMatchingTransient(@NonNull Predicate<Node> test) {
|
public void clearMatchingTransient(@Nonnull Predicate<Node> test) {
|
||||||
handle.removeIfTransient(test);
|
Objects.requireNonNull(test, "test");
|
||||||
|
this.handle.removeIfTransient(test);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearNodes() {
|
public void clearNodes() {
|
||||||
handle.clearNodes();
|
this.handle.clearNodes();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearNodes(@NonNull ContextSet contextSet) {
|
public void clearNodes(@Nonnull ContextSet contextSet) {
|
||||||
handle.clearNodes(contextSet);
|
Objects.requireNonNull(contextSet, "contextSet");
|
||||||
|
this.handle.clearNodes(contextSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearParents() {
|
public void clearParents() {
|
||||||
handle.clearParents(true);
|
this.handle.clearParents(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearParents(@NonNull ContextSet contextSet) {
|
public void clearParents(@Nonnull ContextSet contextSet) {
|
||||||
handle.clearParents(contextSet, true);
|
Objects.requireNonNull(contextSet, "contextSet");
|
||||||
|
this.handle.clearParents(contextSet, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearMeta() {
|
public void clearMeta() {
|
||||||
handle.clearMeta(MetaType.ANY);
|
this.handle.clearMeta(MetaType.ANY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearMeta(@NonNull ContextSet contextSet) {
|
public void clearMeta(@Nonnull ContextSet contextSet) {
|
||||||
handle.clearMeta(MetaType.ANY, contextSet);
|
Objects.requireNonNull(contextSet, "contextSet");
|
||||||
|
this.handle.clearMeta(MetaType.ANY, contextSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearTransientNodes() {
|
public void clearTransientNodes() {
|
||||||
handle.clearTransientNodes();
|
this.handle.clearTransientNodes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public List<LocalizedNode> resolveInheritances(Contexts contexts) {
|
public List<LocalizedNode> resolveInheritances(Contexts contexts) {
|
||||||
return handle.resolveInheritances(contexts);
|
Objects.requireNonNull(contexts, "contexts");
|
||||||
|
return ImmutableList.copyOf(this.handle.resolveInheritances(contexts));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public List<LocalizedNode> resolveInheritances() {
|
public List<LocalizedNode> resolveInheritances() {
|
||||||
return handle.resolveInheritances();
|
return ImmutableList.copyOf(this.handle.resolveInheritances());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Set<Node> getPermanentPermissionNodes() {
|
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
|
@Override
|
||||||
public Set<Node> getTemporaryPermissionNodes() {
|
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
|
@Override
|
||||||
public void auditTemporaryPermissions() {
|
public void auditTemporaryPermissions() {
|
||||||
handle.auditTemporaryPermissions();
|
this.handle.auditTemporaryPermissions();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,9 +25,6 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.common.api.delegates.model;
|
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.Group;
|
||||||
import me.lucko.luckperms.api.HeldPermission;
|
import me.lucko.luckperms.api.HeldPermission;
|
||||||
import me.lucko.luckperms.api.Log;
|
import me.lucko.luckperms.api.Log;
|
||||||
@ -48,17 +45,24 @@ import java.util.UUID;
|
|||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.Executor;
|
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.checkName;
|
||||||
import static me.lucko.luckperms.common.api.ApiUtils.checkUsername;
|
import static me.lucko.luckperms.common.api.ApiUtils.checkUsername;
|
||||||
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class ApiStorage implements Storage {
|
public class ApiStorage implements Storage {
|
||||||
private final LuckPermsPlugin plugin;
|
private final LuckPermsPlugin plugin;
|
||||||
private final me.lucko.luckperms.common.storage.Storage handle;
|
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
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return handle.getName();
|
return this.handle.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -66,116 +70,155 @@ public class ApiStorage implements Storage {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Executor getSyncExecutor() {
|
public Executor getSyncExecutor() {
|
||||||
return plugin.getScheduler().sync();
|
return this.plugin.getScheduler().sync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Executor getAsyncExecutor() {
|
public Executor getAsyncExecutor() {
|
||||||
return plugin.getScheduler().async();
|
return this.plugin.getScheduler().async();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Boolean> logAction(@NonNull LogEntry entry) {
|
public CompletableFuture<Boolean> logAction(@Nonnull LogEntry entry) {
|
||||||
return handle.noBuffer().logAction(entry).thenApply(x -> true);
|
Objects.requireNonNull(entry, "entry");
|
||||||
|
return this.handle.noBuffer().logAction(entry).thenApply(x -> true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Log> getLog() {
|
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
|
@Override
|
||||||
public CompletableFuture<Boolean> loadUser(@NonNull UUID uuid, String username) {
|
public CompletableFuture<Boolean> loadUser(@Nonnull UUID uuid, String username) {
|
||||||
return handle.noBuffer().loadUser(uuid, username == null ? null : checkUsername(username)).thenApply(Objects::nonNull);
|
Objects.requireNonNull(uuid, "uuid");
|
||||||
|
return this.handle.noBuffer().loadUser(uuid, username == null ? null : checkUsername(username)).thenApply(Objects::nonNull);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Boolean> saveUser(@NonNull User user) {
|
public CompletableFuture<Boolean> saveUser(@Nonnull User user) {
|
||||||
return handle.noBuffer().saveUser(ApiUser.cast(user)).thenApply(x -> true);
|
Objects.requireNonNull(user, "user");
|
||||||
|
return this.handle.noBuffer().saveUser(ApiUser.cast(user)).thenApply(x -> true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Set<UUID>> getUniqueUsers() {
|
public CompletableFuture<Set<UUID>> getUniqueUsers() {
|
||||||
return handle.noBuffer().getUniqueUsers();
|
return this.handle.noBuffer().getUniqueUsers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<List<HeldPermission<UUID>>> getUsersWithPermission(@NonNull String permission) {
|
public CompletableFuture<List<HeldPermission<UUID>>> getUsersWithPermission(@Nonnull String permission) {
|
||||||
return handle.noBuffer().getUsersWithPermission(permission);
|
Objects.requireNonNull(permission, "permission");
|
||||||
|
return this.handle.noBuffer().getUsersWithPermission(permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Boolean> createAndLoadGroup(@NonNull String name) {
|
public CompletableFuture<Boolean> createAndLoadGroup(@Nonnull String name) {
|
||||||
return handle.noBuffer().createAndLoadGroup(checkName(name), CreationCause.API).thenApply(Objects::nonNull);
|
Objects.requireNonNull(name, "name");
|
||||||
|
return this.handle.noBuffer().createAndLoadGroup(checkName(name), CreationCause.API).thenApply(Objects::nonNull);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Boolean> loadGroup(@NonNull String name) {
|
public CompletableFuture<Boolean> loadGroup(@Nonnull String name) {
|
||||||
return handle.noBuffer().loadGroup(checkName(name)).thenApply(Optional::isPresent);
|
Objects.requireNonNull(name, "name");
|
||||||
|
return this.handle.noBuffer().loadGroup(checkName(name)).thenApply(Optional::isPresent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Boolean> loadAllGroups() {
|
public CompletableFuture<Boolean> loadAllGroups() {
|
||||||
return handle.noBuffer().loadAllGroups().thenApply(x -> true);
|
return this.handle.noBuffer().loadAllGroups().thenApply(x -> true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Boolean> saveGroup(@NonNull Group group) {
|
public CompletableFuture<Boolean> saveGroup(@Nonnull Group group) {
|
||||||
return handle.noBuffer().saveGroup(ApiGroup.cast(group)).thenApply(x -> true);
|
Objects.requireNonNull(group, "group");
|
||||||
|
return this.handle.noBuffer().saveGroup(ApiGroup.cast(group)).thenApply(x -> true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Boolean> deleteGroup(@NonNull Group group) {
|
public CompletableFuture<Boolean> deleteGroup(@Nonnull Group group) {
|
||||||
if (group.getName().equalsIgnoreCase(plugin.getConfiguration().get(ConfigKeys.DEFAULT_GROUP_NAME))) {
|
Objects.requireNonNull(group, "group");
|
||||||
|
if (group.getName().equalsIgnoreCase(this.plugin.getConfiguration().get(ConfigKeys.DEFAULT_GROUP_NAME))) {
|
||||||
throw new IllegalArgumentException("Cannot delete the default group.");
|
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
|
@Override
|
||||||
public CompletableFuture<List<HeldPermission<String>>> getGroupsWithPermission(@NonNull String permission) {
|
public CompletableFuture<List<HeldPermission<String>>> getGroupsWithPermission(@Nonnull String permission) {
|
||||||
return handle.noBuffer().getGroupsWithPermission(permission);
|
Objects.requireNonNull(permission, "permission");
|
||||||
|
return this.handle.noBuffer().getGroupsWithPermission(permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Boolean> createAndLoadTrack(@NonNull String name) {
|
public CompletableFuture<Boolean> createAndLoadTrack(@Nonnull String name) {
|
||||||
return handle.noBuffer().createAndLoadTrack(checkName(name), CreationCause.API).thenApply(Objects::nonNull);
|
Objects.requireNonNull(name, "name");
|
||||||
|
return this.handle.noBuffer().createAndLoadTrack(checkName(name), CreationCause.API).thenApply(Objects::nonNull);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Boolean> loadTrack(@NonNull String name) {
|
public CompletableFuture<Boolean> loadTrack(@Nonnull String name) {
|
||||||
return handle.noBuffer().loadTrack(checkName(name)).thenApply(Optional::isPresent);
|
Objects.requireNonNull(name, "name");
|
||||||
|
return this.handle.noBuffer().loadTrack(checkName(name)).thenApply(Optional::isPresent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Boolean> loadAllTracks() {
|
public CompletableFuture<Boolean> loadAllTracks() {
|
||||||
return handle.noBuffer().loadAllTracks().thenApply(x -> true);
|
return this.handle.noBuffer().loadAllTracks().thenApply(x -> true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Boolean> saveTrack(@NonNull Track track) {
|
public CompletableFuture<Boolean> saveTrack(@Nonnull Track track) {
|
||||||
return handle.noBuffer().saveTrack(ApiTrack.cast(track)).thenApply(x -> true);
|
Objects.requireNonNull(track, "track");
|
||||||
|
return this.handle.noBuffer().saveTrack(ApiTrack.cast(track)).thenApply(x -> true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Boolean> deleteTrack(@NonNull Track track) {
|
public CompletableFuture<Boolean> deleteTrack(@Nonnull Track track) {
|
||||||
return handle.noBuffer().deleteTrack(ApiTrack.cast(track), DeletionCause.API).thenApply(x -> true);
|
Objects.requireNonNull(track, "track");
|
||||||
|
return this.handle.noBuffer().deleteTrack(ApiTrack.cast(track), DeletionCause.API).thenApply(x -> true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Boolean> saveUUIDData(@NonNull String username, @NonNull UUID uuid) {
|
public CompletableFuture<Boolean> saveUUIDData(@Nonnull String username, @Nonnull UUID uuid) {
|
||||||
return handle.noBuffer().saveUUIDData(uuid, checkUsername(username)).thenApply(x -> true);
|
Objects.requireNonNull(username, "username");
|
||||||
|
Objects.requireNonNull(uuid, "uuid");
|
||||||
|
return this.handle.noBuffer().saveUUIDData(uuid, checkUsername(username)).thenApply(x -> true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<UUID> getUUID(@NonNull String username) {
|
public CompletableFuture<UUID> getUUID(@Nonnull String username) {
|
||||||
return handle.noBuffer().getUUID(checkUsername(username));
|
Objects.requireNonNull(username, "username");
|
||||||
|
return this.handle.noBuffer().getUUID(checkUsername(username));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<String> getName(@NonNull UUID uuid) {
|
public CompletableFuture<String> getName(@Nonnull UUID uuid) {
|
||||||
return handle.noBuffer().getName(uuid);
|
Objects.requireNonNull(uuid, "uuid");
|
||||||
|
return this.handle.noBuffer().getName(uuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,11 +25,6 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.common.api.delegates.model;
|
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 com.google.common.base.Preconditions;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.DataMutateResult;
|
import me.lucko.luckperms.api.DataMutateResult;
|
||||||
@ -37,94 +32,115 @@ import me.lucko.luckperms.api.Group;
|
|||||||
import me.lucko.luckperms.api.Track;
|
import me.lucko.luckperms.api.Track;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
@AllArgsConstructor
|
|
||||||
public final class ApiTrack implements Track {
|
public final class ApiTrack implements Track {
|
||||||
public static me.lucko.luckperms.common.model.Track cast(Track g) {
|
public static me.lucko.luckperms.common.model.Track cast(Track track) {
|
||||||
Preconditions.checkState(g instanceof ApiTrack, "Illegal instance " + g.getClass() + " cannot be handled by this implementation.");
|
Objects.requireNonNull(track, "track");
|
||||||
return ((ApiTrack) g).getHandle();
|
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;
|
private final me.lucko.luckperms.common.model.Track handle;
|
||||||
|
|
||||||
|
public ApiTrack(me.lucko.luckperms.common.model.Track handle) {
|
||||||
|
this.handle = handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
me.lucko.luckperms.common.model.Track getHandle() {
|
||||||
|
return this.handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return handle.getName();
|
return this.handle.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public List<String> getGroups() {
|
public List<String> getGroups() {
|
||||||
return handle.getGroups();
|
return this.handle.getGroups();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getSize() {
|
public int getSize() {
|
||||||
return handle.getSize();
|
return this.handle.getSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getNext(@NonNull Group current) {
|
public String getNext(@Nonnull Group current) {
|
||||||
|
Objects.requireNonNull(current, "current");
|
||||||
try {
|
try {
|
||||||
return handle.getNext(ApiGroup.cast(current));
|
return this.handle.getNext(ApiGroup.cast(current));
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPrevious(@NonNull Group current) {
|
public String getPrevious(@Nonnull Group current) {
|
||||||
|
Objects.requireNonNull(current, "current");
|
||||||
try {
|
try {
|
||||||
return handle.getPrevious(ApiGroup.cast(current));
|
return this.handle.getPrevious(ApiGroup.cast(current));
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DataMutateResult appendGroup(@NonNull Group group) {
|
public DataMutateResult appendGroup(@Nonnull Group group) {
|
||||||
return handle.appendGroup(ApiGroup.cast(group));
|
Objects.requireNonNull(group, "group");
|
||||||
|
return this.handle.appendGroup(ApiGroup.cast(group));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DataMutateResult insertGroup(@NonNull Group group, @NonNull int position) throws IndexOutOfBoundsException {
|
public DataMutateResult insertGroup(@Nonnull Group group, int position) throws IndexOutOfBoundsException {
|
||||||
return handle.insertGroup(ApiGroup.cast(group), position);
|
Objects.requireNonNull(group, "group");
|
||||||
|
return this.handle.insertGroup(ApiGroup.cast(group), position);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DataMutateResult removeGroup(@NonNull Group group) {
|
public DataMutateResult removeGroup(@Nonnull Group group) {
|
||||||
return handle.removeGroup(ApiGroup.cast(group));
|
Objects.requireNonNull(group, "group");
|
||||||
|
return this.handle.removeGroup(ApiGroup.cast(group));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DataMutateResult removeGroup(@NonNull String group) {
|
public DataMutateResult removeGroup(@Nonnull String group) {
|
||||||
return handle.removeGroup(group);
|
Objects.requireNonNull(group, "group");
|
||||||
|
return this.handle.removeGroup(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean containsGroup(@NonNull Group group) {
|
public boolean containsGroup(@Nonnull Group group) {
|
||||||
return handle.containsGroup(ApiGroup.cast(group));
|
Objects.requireNonNull(group, "group");
|
||||||
|
return this.handle.containsGroup(ApiGroup.cast(group));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean containsGroup(@NonNull String group) {
|
public boolean containsGroup(@Nonnull String group) {
|
||||||
return handle.containsGroup(group);
|
Objects.requireNonNull(group, "group");
|
||||||
|
return this.handle.containsGroup(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearGroups() {
|
public void clearGroups() {
|
||||||
handle.clearGroups();
|
this.handle.clearGroups();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (o == this) return true;
|
if (o == this) return true;
|
||||||
if (!(o instanceof ApiTrack)) return false;
|
if (!(o instanceof ApiTrack)) return false;
|
||||||
|
ApiTrack that = (ApiTrack) o;
|
||||||
ApiTrack other = (ApiTrack) o;
|
return this.handle.equals(that.handle);
|
||||||
return handle.equals(other.handle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return handle.hashCode();
|
return this.handle.hashCode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,9 +25,6 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.common.api.delegates.model;
|
package me.lucko.luckperms.common.api.delegates.model;
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.NonNull;
|
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.DataMutateResult;
|
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.api.caching.UserData;
|
||||||
import me.lucko.luckperms.common.node.NodeFactory;
|
import me.lucko.luckperms.common.node.NodeFactory;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
public final class ApiUser extends ApiPermissionHolder implements User {
|
public final class ApiUser extends ApiPermissionHolder implements User {
|
||||||
public static me.lucko.luckperms.common.model.User cast(User u) {
|
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.");
|
Preconditions.checkState(u instanceof ApiUser, "Illegal instance " + u.getClass() + " cannot be handled by this implementation.");
|
||||||
return ((ApiUser) u).getHandle();
|
return ((ApiUser) u).getHandle();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Getter
|
|
||||||
private final me.lucko.luckperms.common.model.User handle;
|
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);
|
super(handle);
|
||||||
this.handle = handle;
|
this.handle = handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public UUID getUuid() {
|
public UUID getUuid() {
|
||||||
return handle.getUuid();
|
return this.handle.getUuid();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return handle.getName().orElse(null);
|
return this.handle.getName().orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public String getPrimaryGroup() {
|
public String getPrimaryGroup() {
|
||||||
return handle.getPrimaryGroup().getValue();
|
return this.handle.getPrimaryGroup().getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DataMutateResult setPrimaryGroup(@NonNull String s) {
|
public DataMutateResult setPrimaryGroup(@Nonnull String group) {
|
||||||
if (getPrimaryGroup().equalsIgnoreCase(s)) {
|
Objects.requireNonNull(group, "group");
|
||||||
|
if (getPrimaryGroup().equalsIgnoreCase(group)) {
|
||||||
return DataMutateResult.ALREADY_HAS;
|
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;
|
return DataMutateResult.FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
handle.getPrimaryGroup().setStoredValue(s.toLowerCase());
|
this.handle.getPrimaryGroup().setStoredValue(group.toLowerCase());
|
||||||
return DataMutateResult.SUCCESS;
|
return DataMutateResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public UserData getCachedData() {
|
public UserData getCachedData() {
|
||||||
return handle.getCachedData();
|
return this.handle.getCachedData();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public void refreshPermissions() {
|
public void refreshPermissions() {
|
||||||
handle.getRefreshBuffer().requestDirectly();
|
this.handle.getRefreshBuffer().requestDirectly();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public void setupDataCache() {
|
public void setupDataCache() {
|
||||||
handle.preCalculateData();
|
this.handle.preCalculateData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (o == this) return true;
|
if (o == this) return true;
|
||||||
if (!(o instanceof ApiUser)) return false;
|
if (!(o instanceof ApiUser)) return false;
|
||||||
|
ApiUser that = (ApiUser) o;
|
||||||
ApiUser other = (ApiUser) o;
|
return this.handle.equals(that.handle);
|
||||||
return handle.equals(other.handle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int hashCode() {
|
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;
|
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("|", "||");
|
.replace("&", "&&").replace("|", "||");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -123,12 +123,12 @@ public class AssignmentExpression {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String forExpression(Predicate<Node> checker) {
|
public String forExpression(Predicate<Node> checker) {
|
||||||
return string;
|
return this.string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return string;
|
return this.string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,12 +143,12 @@ public class AssignmentExpression {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String forExpression(Predicate<Node> checker) {
|
public String forExpression(Predicate<Node> checker) {
|
||||||
return Boolean.toString(checker.test(node));
|
return Boolean.toString(checker.test(this.node));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "<" + permission + ">";
|
return "<" + this.permission + ">";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,9 +25,6 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.common.assignments;
|
package me.lucko.luckperms.common.assignments;
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.ToString;
|
|
||||||
|
|
||||||
import me.lucko.luckperms.api.Node;
|
import me.lucko.luckperms.api.Node;
|
||||||
import me.lucko.luckperms.api.Tristate;
|
import me.lucko.luckperms.api.Tristate;
|
||||||
import me.lucko.luckperms.common.model.User;
|
import me.lucko.luckperms.common.model.User;
|
||||||
@ -36,8 +33,6 @@ import me.lucko.luckperms.common.utils.ImmutableCollectors;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Getter
|
|
||||||
@ToString
|
|
||||||
public class AssignmentRule {
|
public class AssignmentRule {
|
||||||
private final AssignmentExpression hasTrueExpression;
|
private final AssignmentExpression hasTrueExpression;
|
||||||
private final AssignmentExpression hasFalseExpression;
|
private final AssignmentExpression hasFalseExpression;
|
||||||
@ -57,9 +52,9 @@ public class AssignmentRule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean apply(User user) {
|
public boolean apply(User user) {
|
||||||
if (hasTrueExpression != null) {
|
if (this.hasTrueExpression != null) {
|
||||||
try {
|
try {
|
||||||
boolean b = hasTrueExpression.parse(user, Tristate.TRUE);
|
boolean b = this.hasTrueExpression.parse(user, Tristate.TRUE);
|
||||||
if (!b) {
|
if (!b) {
|
||||||
// The holder does not meet this requirement
|
// The holder does not meet this requirement
|
||||||
return false;
|
return false;
|
||||||
@ -71,9 +66,9 @@ public class AssignmentRule {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasFalseExpression != null) {
|
if (this.hasFalseExpression != null) {
|
||||||
try {
|
try {
|
||||||
boolean b = hasFalseExpression.parse(user, Tristate.FALSE);
|
boolean b = this.hasFalseExpression.parse(user, Tristate.FALSE);
|
||||||
if (!b) {
|
if (!b) {
|
||||||
// The holder does not meet this requirement
|
// The holder does not meet this requirement
|
||||||
return false;
|
return false;
|
||||||
@ -85,9 +80,9 @@ public class AssignmentRule {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lacksExpression != null) {
|
if (this.lacksExpression != null) {
|
||||||
try {
|
try {
|
||||||
boolean b = lacksExpression.parse(user, Tristate.UNDEFINED);
|
boolean b = this.lacksExpression.parse(user, Tristate.UNDEFINED);
|
||||||
if (!b) {
|
if (!b) {
|
||||||
// The holder does not meet this requirement
|
// The holder does not meet this requirement
|
||||||
return false;
|
return false;
|
||||||
@ -100,18 +95,53 @@ public class AssignmentRule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The holder meets all of the requirements of this rule.
|
// The holder meets all of the requirements of this rule.
|
||||||
for (Node n : toTake) {
|
for (Node n : this.toTake) {
|
||||||
user.unsetPermission(n);
|
user.unsetPermission(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Node n : toGive) {
|
for (Node n : this.toGive) {
|
||||||
user.setPermission(n);
|
user.setPermission(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setPrimaryGroup != null) {
|
if (this.setPrimaryGroup != null) {
|
||||||
user.getPrimaryGroup().setStoredValue(setPrimaryGroup);
|
user.getPrimaryGroup().setStoredValue(this.setPrimaryGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
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;
|
package me.lucko.luckperms.common.backup;
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import me.lucko.luckperms.api.Tristate;
|
import me.lucko.luckperms.api.Tristate;
|
||||||
import me.lucko.luckperms.common.commands.CommandManager;
|
import me.lucko.luckperms.common.commands.CommandManager;
|
||||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||||
@ -37,7 +35,6 @@ import net.kyori.text.Component;
|
|||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@Getter
|
|
||||||
public abstract class DummySender implements Sender {
|
public abstract class DummySender implements Sender {
|
||||||
private final LuckPermsPlugin platform;
|
private final LuckPermsPlugin platform;
|
||||||
|
|
||||||
@ -77,4 +74,18 @@ public abstract class DummySender implements Sender {
|
|||||||
return true;
|
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.executor = executor;
|
||||||
this.filePath = filePath;
|
this.filePath = filePath;
|
||||||
|
|
||||||
log = new ProgressLogger(null, Message.EXPORT_LOG, Message.EXPORT_LOG_PROGRESS);
|
this.log = new ProgressLogger(null, Message.EXPORT_LOG, Message.EXPORT_LOG_PROGRESS);
|
||||||
log.addListener(plugin.getConsoleSender());
|
this.log.addListener(plugin.getConsoleSender());
|
||||||
log.addListener(executor);
|
this.log.addListener(executor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try (BufferedWriter writer = Files.newBufferedWriter(filePath, StandardCharsets.UTF_8)) {
|
try (BufferedWriter writer = Files.newBufferedWriter(this.filePath, StandardCharsets.UTF_8)) {
|
||||||
log.log("Starting.");
|
this.log.log("Starting.");
|
||||||
|
|
||||||
write(writer, "# LuckPerms Export File");
|
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, "");
|
write(writer, "");
|
||||||
|
|
||||||
// Export Groups
|
// Export Groups
|
||||||
log.log("Starting group export.");
|
this.log.log("Starting group export.");
|
||||||
|
|
||||||
// Create the actual groups first
|
// Create the actual groups first
|
||||||
write(writer, "# Create groups");
|
write(writer, "# Create groups");
|
||||||
|
|
||||||
AtomicInteger groupCount = new AtomicInteger(0);
|
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
|
// export groups in order of weight
|
||||||
.sorted((o1, o2) -> {
|
.sorted((o1, o2) -> {
|
||||||
int i = Integer.compare(o2.getWeight().orElse(0), o1.getWeight().orElse(0));
|
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, "/lp " + NodeFactory.nodeAsCommand(node, group.getName(), HolderType.GROUP, true));
|
||||||
}
|
}
|
||||||
write(writer, "");
|
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, "");
|
||||||
write(writer, "");
|
write(writer, "");
|
||||||
|
|
||||||
// Export tracks
|
// 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()) {
|
if (!tracks.isEmpty()) {
|
||||||
|
|
||||||
// Create the actual tracks first
|
// Create the actual tracks first
|
||||||
@ -151,32 +151,32 @@ public class Exporter implements Runnable {
|
|||||||
write(writer, "");
|
write(writer, "");
|
||||||
|
|
||||||
AtomicInteger trackCount = new AtomicInteger(0);
|
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());
|
write(writer, "# Export track: " + track.getName());
|
||||||
for (String group : track.getGroups()) {
|
for (String group : track.getGroups()) {
|
||||||
write(writer, "/lp track " + track.getName() + " append " + group);
|
write(writer, "/lp track " + track.getName() + " append " + group);
|
||||||
}
|
}
|
||||||
write(writer, "");
|
write(writer, "");
|
||||||
log.logAllProgress("Exported {} tracks so far.", trackCount.incrementAndGet());
|
this.log.logAllProgress("Exported {} tracks so far.", trackCount.incrementAndGet());
|
||||||
}
|
}
|
||||||
|
|
||||||
write(writer, "");
|
write(writer, "");
|
||||||
write(writer, "");
|
write(writer, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
log.log("Exported " + tracks.size() + " tracks.");
|
this.log.log("Exported " + tracks.size() + " tracks.");
|
||||||
|
|
||||||
|
|
||||||
// Users are migrated in separate threads.
|
// Users are migrated in separate threads.
|
||||||
// This is because there are likely to be a lot of them, and because we can.
|
// 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.
|
// 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
|
// 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();
|
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");
|
write(writer, "# Export users");
|
||||||
|
|
||||||
@ -186,7 +186,7 @@ public class Exporter implements Runnable {
|
|||||||
userPools.next().add(uuid);
|
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.
|
// 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.
|
// 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.
|
// 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<>();
|
List<String> output = new ArrayList<>();
|
||||||
|
|
||||||
plugin.getStorage().loadUser(uuid, null).join();
|
this.plugin.getStorage().loadUser(uuid, null).join();
|
||||||
User user = plugin.getUserManager().getIfLoaded(uuid);
|
User user = this.plugin.getUserManager().getIfLoaded(uuid);
|
||||||
output.add("# Export user: " + user.getUuid().toString() + " - " + user.getName().orElse("unknown username"));
|
output.add("# Export user: " + user.getUuid().toString() + " - " + user.getName().orElse("unknown username"));
|
||||||
|
|
||||||
boolean inDefault = false;
|
boolean inDefault = false;
|
||||||
@ -242,25 +242,25 @@ public class Exporter implements Runnable {
|
|||||||
output.add("/lp user " + user.getUuid().toString() + " parent remove default");
|
output.add("/lp user " + user.getUuid().toString() + " parent remove default");
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.getUserManager().cleanup(user);
|
this.plugin.getUserManager().cleanup(user);
|
||||||
writeFunction.accept(output);
|
writeFunction.accept(output);
|
||||||
|
|
||||||
log.logProgress("Exported {} users so far.", userCount.incrementAndGet());
|
this.log.logProgress("Exported {} users so far.", userCount.incrementAndGet());
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
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
|
// 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();
|
CompletableFuture.allOf(futures.toArray(new CompletableFuture[futures.size()])).join();
|
||||||
|
|
||||||
log.log("Exported " + userCount.get() + " users.");
|
this.log.log("Exported " + userCount.get() + " users.");
|
||||||
|
|
||||||
writer.flush();
|
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) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -25,9 +25,6 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.common.backup;
|
package me.lucko.luckperms.common.backup;
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
@ -81,13 +78,13 @@ public class Importer implements Runnable {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
long startTime = System.currentTimeMillis();
|
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
|
// form instances for all commands, and register them
|
||||||
int index = 1;
|
int index = 1;
|
||||||
for (String command : commands) {
|
for (String command : this.commands) {
|
||||||
ImportCommand cmd = new ImportCommand(commandManager, index, command);
|
ImportCommand cmd = new ImportCommand(this.commandManager, index, command);
|
||||||
toExecute.add(cmd);
|
this.toExecute.add(cmd);
|
||||||
|
|
||||||
if (cmd.getCommand().startsWith("creategroup ") || cmd.getCommand().startsWith("createtrack ")) {
|
if (cmd.getCommand().startsWith("creategroup ") || cmd.getCommand().startsWith("createtrack ")) {
|
||||||
cmd.process(); // process immediately
|
cmd.process(); // process immediately
|
||||||
@ -100,7 +97,7 @@ public class Importer implements Runnable {
|
|||||||
Cycle<List<ImportCommand>> commandPools = new Cycle<>(CommandUtils.nInstances(128, ArrayList::new));
|
Cycle<List<ImportCommand>> commandPools = new Cycle<>(CommandUtils.nInstances(128, ArrayList::new));
|
||||||
|
|
||||||
String lastTarget = null;
|
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 the last target isn't the same, skip to a new pool
|
||||||
if (lastTarget == null || !lastTarget.equals(cmd.getTarget())) {
|
if (lastTarget == null || !lastTarget.equals(cmd.getTarget())) {
|
||||||
commandPools.next();
|
commandPools.next();
|
||||||
@ -126,7 +123,7 @@ public class Importer implements Runnable {
|
|||||||
cmd.process();
|
cmd.process();
|
||||||
processedCount.incrementAndGet();
|
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
|
// 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();
|
long endTime = System.currentTimeMillis();
|
||||||
double seconds = (endTime - startTime) / 1000;
|
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) {
|
switch (errors) {
|
||||||
case 0:
|
case 0:
|
||||||
notify.forEach(s -> Message.IMPORT_END_COMPLETE.send(s, seconds));
|
this.notify.forEach(s -> Message.IMPORT_END_COMPLETE.send(s, seconds));
|
||||||
break;
|
break;
|
||||||
case 1:
|
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;
|
break;
|
||||||
default:
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
AtomicInteger errIndex = new AtomicInteger(1);
|
AtomicInteger errIndex = new AtomicInteger(1);
|
||||||
for (ImportCommand e : toExecute) {
|
for (ImportCommand e : this.toExecute) {
|
||||||
if (e.getResult() != null && !e.getResult().asBoolean()) {
|
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());
|
Message.IMPORT_END_ERROR_HEADER.send(s, errIndex.get(), e.getId(), e.getCommand(), e.getResult().toString());
|
||||||
for (String out : e.getOutput()) {
|
for (String out : e.getOutput()) {
|
||||||
Message.IMPORT_END_ERROR_CONTENT.send(s, out);
|
Message.IMPORT_END_ERROR_CONTENT.send(s, out);
|
||||||
@ -184,17 +181,16 @@ public class Importer implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void sendProgress(int processedCount) {
|
private void sendProgress(int processedCount) {
|
||||||
int percent = (processedCount * 100) / commands.size();
|
int percent = (processedCount * 100) / this.commands.size();
|
||||||
int errors = (int) toExecute.stream().filter(v -> v.isCompleted() && !v.getResult().asBoolean()).count();
|
int errors = (int) this.toExecute.stream().filter(v -> v.isCompleted() && !v.getResult().asBoolean()).count();
|
||||||
|
|
||||||
if (errors == 1) {
|
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 {
|
} 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 class ImportCommand extends DummySender {
|
||||||
private static final Splitter ARGUMENT_SPLITTER = Splitter.on(CommandManager.COMMAND_SEPARATOR_PATTERN).omitEmptyStrings();
|
private static final Splitter ARGUMENT_SPLITTER = Splitter.on(CommandManager.COMMAND_SEPARATOR_PATTERN).omitEmptyStrings();
|
||||||
private static final Splitter SPACE_SPLITTER = Splitter.on(" ");
|
private static final Splitter SPACE_SPLITTER = Splitter.on(" ");
|
||||||
@ -205,12 +201,10 @@ public class Importer implements Runnable {
|
|||||||
|
|
||||||
private final String target;
|
private final String target;
|
||||||
|
|
||||||
@Setter
|
|
||||||
private boolean completed = false;
|
private boolean completed = false;
|
||||||
|
|
||||||
private final List<String> output = new ArrayList<>();
|
private final List<String> output = new ArrayList<>();
|
||||||
|
|
||||||
@Setter
|
|
||||||
private CommandResult result = CommandResult.FAILURE;
|
private CommandResult result = CommandResult.FAILURE;
|
||||||
|
|
||||||
ImportCommand(CommandManager commandManager, int id, String command) {
|
ImportCommand(CommandManager commandManager, int id, String command) {
|
||||||
@ -223,7 +217,7 @@ public class Importer implements Runnable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void consumeMessage(String s) {
|
protected void consumeMessage(String s) {
|
||||||
output.add(s);
|
this.output.add(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void process() {
|
public void process() {
|
||||||
@ -233,7 +227,7 @@ public class Importer implements Runnable {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
List<String> args = CommandManager.stripQuotes(ARGUMENT_SPLITTER.splitToList(getCommand()));
|
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);
|
setResult(result);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
setResult(CommandResult.FAILURE);
|
setResult(CommandResult.FAILURE);
|
||||||
@ -287,6 +281,37 @@ public class Importer implements Runnable {
|
|||||||
return null;
|
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;
|
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.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ListIterator;
|
import java.util.ListIterator;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
@ -60,17 +55,19 @@ public class Buffer<T, R> implements Runnable {
|
|||||||
this.dequeueFunc = dequeueFunc;
|
this.dequeueFunc = dequeueFunc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompletableFuture<R> enqueue(@NonNull T t) {
|
public CompletableFuture<R> enqueue(T object) {
|
||||||
lock.lock();
|
Objects.requireNonNull(object, "object");
|
||||||
|
|
||||||
|
this.lock.lock();
|
||||||
try {
|
try {
|
||||||
ListIterator<BufferedObject<T, R>> it = buffer.listIterator();
|
ListIterator<BufferedObject<T, R>> it = this.buffer.listIterator();
|
||||||
|
|
||||||
BufferedObject<T, R> o = null;
|
BufferedObject<T, R> o = null;
|
||||||
|
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
BufferedObject<T, R> obj = it.next();
|
BufferedObject<T, R> obj = it.next();
|
||||||
|
|
||||||
if (obj.getObject().equals(t)) {
|
if (obj.getObject().equals(object)) {
|
||||||
o = obj;
|
o = obj;
|
||||||
it.remove();
|
it.remove();
|
||||||
break;
|
break;
|
||||||
@ -78,28 +75,28 @@ public class Buffer<T, R> implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (o == null) {
|
if (o == null) {
|
||||||
o = new BufferedObject<>(System.currentTimeMillis(), t, new CompletableFuture<R>());
|
o = new BufferedObject<>(System.currentTimeMillis(), object, new CompletableFuture<R>());
|
||||||
} else {
|
} else {
|
||||||
o.setBufferTime(System.currentTimeMillis());
|
o.setBufferTime(System.currentTimeMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer.add(o);
|
this.buffer.add(o);
|
||||||
return o.getFuture();
|
return o.getFuture();
|
||||||
} finally {
|
} finally {
|
||||||
lock.unlock();
|
this.lock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected R dequeue(T t) {
|
protected R dequeue(T t) {
|
||||||
return dequeueFunc.apply(t);
|
return this.dequeueFunc.apply(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void flush(long flushTime) {
|
public void flush(long flushTime) {
|
||||||
long time = System.currentTimeMillis();
|
long time = System.currentTimeMillis();
|
||||||
|
|
||||||
lock.lock();
|
this.lock.lock();
|
||||||
try {
|
try {
|
||||||
ListIterator<BufferedObject<T, R>> it = buffer.listIterator(buffer.size());
|
ListIterator<BufferedObject<T, R>> it = this.buffer.listIterator(this.buffer.size());
|
||||||
|
|
||||||
while (it.hasPrevious()) {
|
while (it.hasPrevious()) {
|
||||||
BufferedObject<T, R> obj = it.previous();
|
BufferedObject<T, R> obj = it.previous();
|
||||||
@ -114,7 +111,7 @@ public class Buffer<T, R> implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
lock.unlock();
|
this.lock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,15 +120,45 @@ public class Buffer<T, R> implements Runnable {
|
|||||||
flush(DEFAULT_FLUSH_TIME);
|
flush(DEFAULT_FLUSH_TIME);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Getter
|
|
||||||
@EqualsAndHashCode(of = "object")
|
|
||||||
@AllArgsConstructor
|
|
||||||
private static final class BufferedObject<T, R> {
|
private static final class BufferedObject<T, R> {
|
||||||
|
|
||||||
@Setter
|
|
||||||
private long bufferTime;
|
private long bufferTime;
|
||||||
private final T object;
|
private final T object;
|
||||||
private final CompletableFuture<R> future;
|
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;
|
package me.lucko.luckperms.common.buffers;
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
@ -42,7 +39,6 @@ import java.util.function.Supplier;
|
|||||||
*
|
*
|
||||||
* @param <T> the return type
|
* @param <T> the return type
|
||||||
*/
|
*/
|
||||||
@RequiredArgsConstructor
|
|
||||||
public abstract class BufferedRequest<T> {
|
public abstract class BufferedRequest<T> {
|
||||||
private final long bufferTimeMillis;
|
private final long bufferTimeMillis;
|
||||||
private final long sleepInterval;
|
private final long sleepInterval;
|
||||||
@ -51,23 +47,29 @@ public abstract class BufferedRequest<T> {
|
|||||||
private WeakReference<Processor<T>> processor = null;
|
private WeakReference<Processor<T>> processor = null;
|
||||||
private final ReentrantLock lock = new ReentrantLock();
|
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() {
|
public CompletableFuture<T> request() {
|
||||||
lock.lock();
|
this.lock.lock();
|
||||||
try {
|
try {
|
||||||
if (processor != null) {
|
if (this.processor != null) {
|
||||||
Processor<T> p = processor.get();
|
Processor<T> p = this.processor.get();
|
||||||
if (p != null && p.isUsable()) {
|
if (p != null && p.isUsable()) {
|
||||||
return p.getAndExtend();
|
return p.getAndExtend();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Processor<T> p = new Processor<>(bufferTimeMillis, sleepInterval, this::perform);
|
Processor<T> p = new Processor<>(this.bufferTimeMillis, this.sleepInterval, this::perform);
|
||||||
executor.execute(p);
|
this.executor.execute(p);
|
||||||
processor = new WeakReference<>(p);
|
this.processor = new WeakReference<>(p);
|
||||||
return p.get();
|
return p.get();
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
lock.unlock();
|
this.lock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,62 +79,70 @@ public abstract class BufferedRequest<T> {
|
|||||||
|
|
||||||
protected abstract T perform();
|
protected abstract T perform();
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
private static class Processor<R> implements Runnable {
|
private static class Processor<R> implements Runnable {
|
||||||
private final long delayMillis;
|
private final long delayMillis;
|
||||||
private final long sleepMillis;
|
private final long sleepMillis;
|
||||||
private final Supplier<R> supplier;
|
private final Supplier<R> supplier;
|
||||||
private final ReentrantLock lock = new ReentrantLock();
|
private final ReentrantLock lock = new ReentrantLock();
|
||||||
private final CompletableFuture<R> future = new CompletableFuture<>();
|
private final CompletableFuture<R> future = new CompletableFuture<>();
|
||||||
@Getter
|
|
||||||
private boolean usable = true;
|
private boolean usable = true;
|
||||||
private long executionTime;
|
private long executionTime;
|
||||||
|
|
||||||
|
public Processor(long delayMillis, long sleepMillis, Supplier<R> supplier) {
|
||||||
|
this.delayMillis = delayMillis;
|
||||||
|
this.sleepMillis = sleepMillis;
|
||||||
|
this.supplier = supplier;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
lock.lock();
|
this.lock.lock();
|
||||||
try {
|
try {
|
||||||
executionTime = System.currentTimeMillis() + delayMillis;
|
this.executionTime = System.currentTimeMillis() + this.delayMillis;
|
||||||
} finally {
|
} finally {
|
||||||
lock.unlock();
|
this.lock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
lock.lock();
|
this.lock.lock();
|
||||||
try {
|
try {
|
||||||
if (System.currentTimeMillis() > executionTime) {
|
if (System.currentTimeMillis() > this.executionTime) {
|
||||||
usable = false;
|
this.usable = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
lock.unlock();
|
this.lock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Thread.sleep(sleepMillis);
|
Thread.sleep(this.sleepMillis);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
R result = supplier.get();
|
R result = this.supplier.get();
|
||||||
future.complete(result);
|
this.future.complete(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompletableFuture<R> get() {
|
public CompletableFuture<R> get() {
|
||||||
return future;
|
return this.future;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompletableFuture<R> getAndExtend() {
|
public CompletableFuture<R> getAndExtend() {
|
||||||
lock.lock();
|
this.lock.lock();
|
||||||
try {
|
try {
|
||||||
executionTime = System.currentTimeMillis() + delayMillis;
|
this.executionTime = System.currentTimeMillis() + this.delayMillis;
|
||||||
} finally {
|
} 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;
|
package me.lucko.luckperms.common.buffers;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||||
|
|
||||||
@ -35,58 +33,56 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
|
|||||||
*
|
*
|
||||||
* @param <T> the type being stored
|
* @param <T> the type being stored
|
||||||
*/
|
*/
|
||||||
@RequiredArgsConstructor
|
|
||||||
public abstract class Cache<T> {
|
public abstract class Cache<T> {
|
||||||
private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
|
private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
|
||||||
|
|
||||||
private T cached = null;
|
private T cached = null;
|
||||||
|
|
||||||
protected abstract T supply();
|
protected abstract T supply();
|
||||||
|
|
||||||
public final T get() {
|
public final T get() {
|
||||||
// try to just read from the cached value
|
// try to just read from the cached value
|
||||||
lock.readLock().lock();
|
this.lock.readLock().lock();
|
||||||
try {
|
try {
|
||||||
if (cached != null) {
|
if (this.cached != null) {
|
||||||
return cached;
|
return this.cached;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
// we have to release the read lock, as it is not possible
|
// we have to release the read lock, as it is not possible
|
||||||
// to acquire the write lock whilst holding a read lock
|
// 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 {
|
try {
|
||||||
// Since the lock was unlocked momentarily, we need
|
// Since the lock was unlocked momentarily, we need
|
||||||
// to check again for a cached value
|
// to check again for a cached value
|
||||||
if (cached != null) {
|
if (this.cached != null) {
|
||||||
return cached;
|
return this.cached;
|
||||||
}
|
}
|
||||||
|
|
||||||
// call the supplier and set the cached value
|
// call the supplier and set the cached value
|
||||||
cached = supply();
|
this.cached = supply();
|
||||||
return cached;
|
return this.cached;
|
||||||
} finally {
|
} finally {
|
||||||
lock.writeLock().unlock();
|
this.lock.writeLock().unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final Optional<T> getIfPresent() {
|
public final Optional<T> getIfPresent() {
|
||||||
lock.readLock().lock();
|
this.lock.readLock().lock();
|
||||||
try {
|
try {
|
||||||
return Optional.ofNullable(cached);
|
return Optional.ofNullable(this.cached);
|
||||||
} finally {
|
} finally {
|
||||||
lock.readLock().unlock();
|
this.lock.readLock().unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void invalidate() {
|
public final void invalidate() {
|
||||||
lock.writeLock().lock();
|
this.lock.writeLock().lock();
|
||||||
try {
|
try {
|
||||||
cached = null;
|
this.cached = null;
|
||||||
} finally {
|
} finally {
|
||||||
lock.writeLock().unlock();
|
this.lock.writeLock().unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ public class UpdateTaskBuffer extends BufferedRequest<Void> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Void perform() {
|
protected Void perform() {
|
||||||
new UpdateTask(plugin, false).run();
|
new UpdateTask(this.plugin, false).run();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,26 +25,18 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.common.bulkupdate;
|
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.action.Action;
|
||||||
import me.lucko.luckperms.common.bulkupdate.constraint.Constraint;
|
import me.lucko.luckperms.common.bulkupdate.constraint.Constraint;
|
||||||
import me.lucko.luckperms.common.node.NodeModel;
|
import me.lucko.luckperms.common.node.NodeModel;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a query to be applied to a set of data.
|
* 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.
|
* Queries can either be applied to im-memory sets of data, or converted to SQL syntax to be executed remotely.
|
||||||
*/
|
*/
|
||||||
@Getter
|
public final class BulkUpdate {
|
||||||
@ToString
|
|
||||||
@EqualsAndHashCode
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class BulkUpdate {
|
|
||||||
|
|
||||||
// the data types which this query should apply to
|
// the data types which this query should apply to
|
||||||
private final DataType dataType;
|
private final DataType dataType;
|
||||||
@ -55,6 +47,12 @@ public class BulkUpdate {
|
|||||||
// a set of constraints which data must match to be acted upon
|
// a set of constraints which data must match to be acted upon
|
||||||
private final List<Constraint> constraints;
|
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
|
* Check to see if a Node instance satisfies the constrints of this query
|
||||||
*
|
*
|
||||||
@ -62,7 +60,7 @@ public class BulkUpdate {
|
|||||||
* @return true if satisfied
|
* @return true if satisfied
|
||||||
*/
|
*/
|
||||||
public boolean satisfiesConstraints(NodeModel node) {
|
public boolean satisfiesConstraints(NodeModel node) {
|
||||||
for (Constraint constraint : constraints) {
|
for (Constraint constraint : this.constraints) {
|
||||||
if (!constraint.isSatisfiedBy(node)) {
|
if (!constraint.isSatisfiedBy(node)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -81,7 +79,7 @@ public class BulkUpdate {
|
|||||||
return from; // make no change
|
return from; // make no change
|
||||||
}
|
}
|
||||||
|
|
||||||
return action.apply(from);
|
return this.action.apply(from);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -97,17 +95,17 @@ public class BulkUpdate {
|
|||||||
|
|
||||||
// add the action
|
// add the action
|
||||||
// (DELETE FROM or UPDATE)
|
// (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 there are no constraints, just return without a WHERE clause
|
||||||
if (constraints.isEmpty()) {
|
if (this.constraints.isEmpty()) {
|
||||||
return sb.append(";").toString();
|
return sb.append(";").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
// append constraints
|
// append constraints
|
||||||
sb.append(" WHERE");
|
sb.append(" WHERE");
|
||||||
for (int i = 0; i < constraints.size(); i++) {
|
for (int i = 0; i < this.constraints.size(); i++) {
|
||||||
Constraint constraint = constraints.get(i);
|
Constraint constraint = this.constraints.get(i);
|
||||||
|
|
||||||
sb.append(" ");
|
sb.append(" ");
|
||||||
if (i != 0) {
|
if (i != 0) {
|
||||||
@ -141,4 +139,39 @@ public class BulkUpdate {
|
|||||||
return "'" + s + "'";
|
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;
|
package me.lucko.luckperms.common.bulkupdate;
|
||||||
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.ToString;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
import me.lucko.luckperms.common.bulkupdate.action.Action;
|
import me.lucko.luckperms.common.bulkupdate.action.Action;
|
||||||
@ -39,10 +36,12 @@ import java.util.Set;
|
|||||||
/**
|
/**
|
||||||
* Responsible for building a {@link BulkUpdate}
|
* Responsible for building a {@link BulkUpdate}
|
||||||
*/
|
*/
|
||||||
@ToString
|
|
||||||
@NoArgsConstructor(staticName = "create")
|
|
||||||
public class BulkUpdateBuilder {
|
public class BulkUpdateBuilder {
|
||||||
|
|
||||||
|
public static BulkUpdateBuilder create() {
|
||||||
|
return new BulkUpdateBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
// the data type this query should affect
|
// the data type this query should affect
|
||||||
private DataType dataType = DataType.ALL;
|
private DataType dataType = DataType.ALL;
|
||||||
|
|
||||||
@ -52,6 +51,9 @@ public class BulkUpdateBuilder {
|
|||||||
// a set of constraints which data must match to be acted upon
|
// a set of constraints which data must match to be acted upon
|
||||||
private final Set<Constraint> constraints = new LinkedHashSet<>();
|
private final Set<Constraint> constraints = new LinkedHashSet<>();
|
||||||
|
|
||||||
|
private BulkUpdateBuilder() {
|
||||||
|
}
|
||||||
|
|
||||||
public BulkUpdateBuilder action(Action action) {
|
public BulkUpdateBuilder action(Action action) {
|
||||||
this.action = action;
|
this.action = action;
|
||||||
return this;
|
return this;
|
||||||
@ -63,15 +65,23 @@ public class BulkUpdateBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public BulkUpdateBuilder constraint(Constraint constraint) {
|
public BulkUpdateBuilder constraint(Constraint constraint) {
|
||||||
constraints.add(constraint);
|
this.constraints.add(constraint);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BulkUpdate build() {
|
public BulkUpdate build() {
|
||||||
if (action == null) {
|
if (this.action == null) {
|
||||||
throw new IllegalStateException("no action specified");
|
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;
|
package me.lucko.luckperms.common.bulkupdate;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the data sets a query should apply to
|
* Represents the data sets a query should apply to
|
||||||
*/
|
*/
|
||||||
@Getter
|
|
||||||
@AllArgsConstructor
|
|
||||||
public enum DataType {
|
public enum DataType {
|
||||||
|
|
||||||
ALL("all", true, true),
|
ALL("all", true, true),
|
||||||
@ -43,4 +38,21 @@ public enum DataType {
|
|||||||
private final boolean includingUsers;
|
private final boolean includingUsers;
|
||||||
private final boolean includingGroups;
|
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