Skip to content

Commit

Permalink
Merge branch 'LuckPerms:master' into feat/minestom
Browse files Browse the repository at this point in the history
  • Loading branch information
LooFifteen authored Dec 25, 2024
2 parents c919670 + 0fef481 commit 91d7f75
Show file tree
Hide file tree
Showing 46 changed files with 1,358 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public interface DataTypeFilterFunction {

/**
* Creates a {@link DataTypeFilterFunction} that always returns the given
* {@code predicate}.
* {@code predicate} (commonly one of the values in {@link DataTypeFilter}).
*
* @param predicate the predicate
* @return the data type filter function
Expand Down
2 changes: 1 addition & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.1'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.9.1'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.9.1'
testImplementation "org.testcontainers:junit-jupiter:1.19.8"
testImplementation 'org.testcontainers:junit-jupiter:1.20.4'
testImplementation 'org.mockito:mockito-core:5.11.0'
testImplementation 'org.mockito:mockito-junit-jupiter:5.11.0'
testImplementation 'com.h2database:h2:2.1.214'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
package me.lucko.luckperms.common.api.implementation;

import com.google.common.collect.ImmutableList;
import me.lucko.luckperms.common.metastacking.SimpleMetaStackDefinition;
import me.lucko.luckperms.common.metastacking.StandardStackElements;
import me.lucko.luckperms.common.cacheddata.metastack.SimpleMetaStackDefinition;
import me.lucko.luckperms.common.cacheddata.metastack.StandardStackElements;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import net.luckperms.api.metastacking.DuplicateRemovalFunction;
import net.luckperms.api.metastacking.MetaStackDefinition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public AbstractContainer(Function<QueryOptions, C> cacheLoader) {
}

public void cleanup() {
this.cache.values().removeIf(value -> ((UsageTracked) value).usedSince(TimeUnit.MINUTES.toMillis(2)));
this.cache.values().removeIf(value -> !((UsageTracked) value).usedInTheLast(2, TimeUnit.MINUTES));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,20 @@

package me.lucko.luckperms.common.cacheddata;

import com.google.common.annotations.VisibleForTesting;

import java.util.concurrent.TimeUnit;

public abstract class UsageTracked {
private long lastUsed = System.currentTimeMillis();

@VisibleForTesting
protected long lastUsed = System.currentTimeMillis();

public void recordUsage() {
this.lastUsed = System.currentTimeMillis();
}

public boolean usedSince(long duration) {
return this.lastUsed > System.currentTimeMillis() - duration;
public boolean usedInTheLast(long duration, TimeUnit unit) {
return this.lastUsed > System.currentTimeMillis() - unit.toMillis(duration);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* SOFTWARE.
*/

package me.lucko.luckperms.common.metastacking;
package me.lucko.luckperms.common.cacheddata.metastack;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* SOFTWARE.
*/

package me.lucko.luckperms.common.metastacking;
package me.lucko.luckperms.common.cacheddata.metastack;

import com.google.common.collect.ImmutableList;
import net.luckperms.api.metastacking.DuplicateRemovalFunction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* SOFTWARE.
*/

package me.lucko.luckperms.common.metastacking;
package me.lucko.luckperms.common.cacheddata.metastack;

import me.lucko.luckperms.common.model.Track;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
Expand Down Expand Up @@ -220,8 +220,11 @@ private static final class FromGroupOnTrackCheck implements MetaStackElement {
@Override
public boolean shouldAccumulate(@NonNull ChatMetaType type, @NonNull ChatMetaNode<?, ?> node, @Nullable ChatMetaNode<?, ?> current) {
Track track = this.plugin.getTrackManager().getIfLoaded(this.trackName);
if (track == null) {
return false;
}
PermissionHolder.Identifier origin = node.metadata(InheritanceOriginMetadata.KEY).getOrigin();
return track != null && origin.getType().equals(PermissionHolder.Identifier.GROUP_TYPE) && track.containsGroup(origin.getName());
return origin.getType().equals(PermissionHolder.Identifier.GROUP_TYPE) && track.containsGroup(origin.getName());
}

@Override
Expand Down Expand Up @@ -250,8 +253,11 @@ private static final class NotFromGroupOnTrackCheck implements MetaStackElement
@Override
public boolean shouldAccumulate(@NonNull ChatMetaType type, @NonNull ChatMetaNode<?, ?> node, @Nullable ChatMetaNode<?, ?> current) {
Track track = this.plugin.getTrackManager().getIfLoaded(this.trackName);
if (track == null) {
return false;
}
PermissionHolder.Identifier origin = node.metadata(InheritanceOriginMetadata.KEY).getOrigin();
return track != null && !track.containsGroup(origin.getName());
return !(origin.getType().equals(PermissionHolder.Identifier.GROUP_TYPE) && track.containsGroup(origin.getName()));
}

@Override
Expand Down Expand Up @@ -305,7 +311,7 @@ private static final class NotFromGroupCheck implements MetaStackElement {
@Override
public boolean shouldAccumulate(@NonNull ChatMetaType type, @NonNull ChatMetaNode<?, ?> node, @Nullable ChatMetaNode<?, ?> current) {
PermissionHolder.Identifier origin = node.metadata(InheritanceOriginMetadata.KEY).getOrigin();
return !this.groupName.equals(origin.getName());
return !(origin.getType().equals(PermissionHolder.Identifier.GROUP_TYPE) && this.groupName.equals(origin.getName()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* This file is part of LuckPerms, licensed under the MIT License.
*
* Copyright (c) lucko (Luck) <luck@lucko.me>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package me.lucko.luckperms.common.cacheddata.result;

import net.luckperms.api.cacheddata.Result;
import net.luckperms.api.node.Node;
import org.checkerframework.checker.nullness.qual.Nullable;

public abstract class AbstractResult<T, N extends Node, S extends AbstractResult<T, N, S>> implements Result<T, N> {

/** The node that caused the result */
protected final N node;
/** A reference to another result that this one overrides */
protected S overriddenResult;

public AbstractResult(N node, S overriddenResult) {
this.node = node;
this.overriddenResult = overriddenResult;
}

@Override
public final @Nullable N node() {
return this.node;
}

public final @Nullable S overriddenResult() {
return this.overriddenResult;
}

public final void setOverriddenResult(S overriddenResult) {
this.overriddenResult = overriddenResult;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,23 @@

package me.lucko.luckperms.common.cacheddata.result;

import net.luckperms.api.cacheddata.Result;
import net.luckperms.api.node.Node;
import net.luckperms.api.node.types.WeightNode;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
* Represents the result of an integer meta lookup
*
* @param <N> the node type
*/
public final class IntegerResult<N extends Node> implements Result<Integer, N> {
public final class IntegerResult<N extends Node> extends AbstractResult<Integer, N, IntegerResult<N>> {

/** The result */
private final int result;
/** The node that caused the result */
private final N node;
/** A reference to another result that this one overrides */
private IntegerResult<N> overriddenResult;

public IntegerResult(int result, N node, IntegerResult<N> overriddenResult) {
super(node, overriddenResult);
this.result = result;
this.node = node;
this.overriddenResult = overriddenResult;
}

@Override
Expand All @@ -73,19 +66,6 @@ public StringResult<N> asStringResult() {
}
}

@Override
public @Nullable N node() {
return this.node;
}

public @Nullable IntegerResult<N> overriddenResult() {
return this.overriddenResult;
}

public void setOverriddenResult(IntegerResult<N> overriddenResult) {
this.overriddenResult = overriddenResult;
}

public boolean isNull() {
return this == NULL_RESULT;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

package me.lucko.luckperms.common.cacheddata.result;

import net.luckperms.api.cacheddata.Result;
import net.luckperms.api.node.Node;
import net.luckperms.api.node.types.ChatMetaNode;
import net.luckperms.api.node.types.MetaNode;
Expand All @@ -36,39 +35,21 @@
*
* @param <N> the node type
*/
public final class StringResult<N extends Node> implements Result<String, N> {
public final class StringResult<N extends Node> extends AbstractResult<String, N, StringResult<N>> {

/** The result, nullable */
private final String result;
/** The node that caused the result */
private final N node;
/** A reference to another result that this one overrides */
private StringResult<N> overriddenResult;

public StringResult(String result, N node, StringResult<N> overriddenResult) {
super(node, overriddenResult);
this.result = result;
this.node = node;
this.overriddenResult = overriddenResult;
}

@Override
public @Nullable String result() {
return this.result;
}

@Override
public @Nullable N node() {
return this.node;
}

public @Nullable StringResult<N> overriddenResult() {
return this.overriddenResult;
}

public void setOverriddenResult(StringResult<N> overriddenResult) {
this.overriddenResult = overriddenResult;
}

public StringResult<N> copy() {
return new StringResult<>(this.result, this.node, this.overriddenResult);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

import me.lucko.luckperms.common.calculator.PermissionCalculator;
import me.lucko.luckperms.common.calculator.processor.PermissionProcessor;
import net.luckperms.api.cacheddata.Result;
import net.luckperms.api.node.Node;
import net.luckperms.api.util.Tristate;
import org.checkerframework.checker.nullness.qual.NonNull;
Expand All @@ -36,20 +35,16 @@
/**
* Represents the result of a {@link PermissionCalculator} lookup.
*/
public final class TristateResult implements Result<Tristate, Node> {
public final class TristateResult extends AbstractResult<Tristate, Node, TristateResult> {

/** The result */
private final Tristate result;
/** The node that caused the result */
private final Node node;
/** The permission processor that provided the result */
private final Class<? extends PermissionProcessor> processorClass;
/** A reference to another result that this one overrides */
private TristateResult overriddenResult;

private TristateResult(Tristate result, Node node, Class<? extends PermissionProcessor> processorClass) {
super(node, null);
this.result = result;
this.node = node;
this.processorClass = processorClass;
}

Expand All @@ -58,11 +53,6 @@ private TristateResult(Tristate result, Node node, Class<? extends PermissionPro
return this.result;
}

@Override
public @Nullable Node node() {
return this.node;
}

public @Nullable Class<? extends PermissionProcessor> processorClass() {
return this.processorClass;
}
Expand All @@ -79,14 +69,6 @@ private TristateResult(Tristate result, Node node, Class<? extends PermissionPro
}
}

public @Nullable TristateResult overriddenResult() {
return this.overriddenResult;
}

public void setOverriddenResult(TristateResult overriddenResult) {
this.overriddenResult = overriddenResult;
}

@Override
public String toString() {
return "TristateResult(" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.sender.Sender;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.JoinConfiguration;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.NamedTextColor;

Expand Down Expand Up @@ -66,7 +67,7 @@ public void sendUsage(Sender sender, String label) {
.collect(Collectors.toList());

builder.append(Component.text(" - ", NamedTextColor.DARK_AQUA))
.append(Component.join(Component.space(), argUsages))
.append(Component.join(JoinConfiguration.separator(Component.space()), argUsages))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.JoinConfiguration;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.NamedTextColor;

Expand Down Expand Up @@ -114,7 +115,7 @@ public void sendUsage(Sender sender) {
.collect(Collectors.toList());

builder.append(Component.text(" - ", NamedTextColor.DARK_AQUA))
.append(Component.join(Component.space(), argUsages))
.append(Component.join(JoinConfiguration.separator(Component.space()), argUsages))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.JoinConfiguration;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.NamedTextColor;

Expand Down Expand Up @@ -70,7 +71,7 @@ public void sendUsage(Sender sender, String label) {
.collect(Collectors.toList());

builder.append(Component.text(" - ", NamedTextColor.DARK_AQUA))
.append(Component.join(Component.space(), argUsages))
.append(Component.join(JoinConfiguration.separator(Component.space()), argUsages))
.build();
}

Expand Down
Loading

0 comments on commit 91d7f75

Please sign in to comment.