mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2025-02-05 15:11:56 +01:00
Reuse the same InheritanceOrigin object where possible
This commit is contained in:
parent
4de7448394
commit
a53c9fad00
@ -83,7 +83,7 @@ public class ParentAddTemp extends GenericChildCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
if (group.getName().equalsIgnoreCase(target.getObjectName())) {
|
||||
if (group.getName().equalsIgnoreCase(target.getIdentifier().getName())) {
|
||||
Message.ALREADY_TEMP_INHERITS.send(sender, target, group, context);
|
||||
return;
|
||||
}
|
||||
|
@ -1671,7 +1671,7 @@ public interface Message {
|
||||
.append(space())
|
||||
.append(formatContextSetBracketed(node.getContexts(), empty()))
|
||||
.apply(builder -> {
|
||||
String holderName = holder.getType() == HolderType.GROUP ? holder.getObjectName() : holder.getPlainDisplayName();
|
||||
String holderName = holder.getType() == HolderType.GROUP ? holder.getIdentifier().getName() : holder.getPlainDisplayName();
|
||||
boolean explicitGlobalContext = !holder.getPlugin().getConfiguration().getContextsFile().getDefaultContexts().isEmpty();
|
||||
|
||||
Component hover = join(newline(),
|
||||
@ -1701,7 +1701,7 @@ public interface Message {
|
||||
.append(space())
|
||||
.append(formatContextSetBracketed(node.getContexts(), empty()))
|
||||
.apply(builder -> {
|
||||
String holderName = holder.getType() == HolderType.GROUP ? holder.getObjectName() : holder.getPlainDisplayName();
|
||||
String holderName = holder.getType() == HolderType.GROUP ? holder.getIdentifier().getName() : holder.getPlainDisplayName();
|
||||
boolean explicitGlobalContext = !holder.getPlugin().getConfiguration().getContextsFile().getDefaultContexts().isEmpty();
|
||||
|
||||
Component hover = join(newline(),
|
||||
@ -1771,7 +1771,7 @@ public interface Message {
|
||||
.content(node.getGroupName())
|
||||
.color(GREEN)
|
||||
.apply(builder -> {
|
||||
String holderName = holder.getType() == HolderType.GROUP ? holder.getObjectName() : holder.getPlainDisplayName();
|
||||
String holderName = holder.getType() == HolderType.GROUP ? holder.getIdentifier().getName() : holder.getPlainDisplayName();
|
||||
boolean explicitGlobalContext = !holder.getPlugin().getConfiguration().getContextsFile().getDefaultContexts().isEmpty();
|
||||
|
||||
Component hover = join(newline(),
|
||||
@ -1804,7 +1804,7 @@ public interface Message {
|
||||
.content(node.getGroupName())
|
||||
.color(GREEN)
|
||||
.apply(builder -> {
|
||||
String holderName = holder.getType() == HolderType.GROUP ? holder.getObjectName() : holder.getPlainDisplayName();
|
||||
String holderName = holder.getType() == HolderType.GROUP ? holder.getIdentifier().getName() : holder.getPlainDisplayName();
|
||||
boolean explicitGlobalContext = !holder.getPlugin().getConfiguration().getContextsFile().getDefaultContexts().isEmpty();
|
||||
|
||||
Component hover = join(newline(),
|
||||
|
@ -68,8 +68,8 @@ public class Group extends PermissionHolder {
|
||||
private final GroupCachedDataManager cachedData;
|
||||
|
||||
public Group(String name, LuckPermsPlugin plugin) {
|
||||
super(plugin);
|
||||
this.name = name.toLowerCase(Locale.ROOT);
|
||||
super(plugin, name.toLowerCase(Locale.ROOT));
|
||||
this.name = getIdentifier().getName();
|
||||
|
||||
this.cachedData = new GroupCachedDataManager(this);
|
||||
getPlugin().getEventDispatcher().dispatchGroupCacheLoad(this, this.cachedData);
|
||||
@ -89,11 +89,6 @@ public class Group extends PermissionHolder {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getObjectName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public ApiGroup getApiProxy() {
|
||||
return this.apiProxy;
|
||||
}
|
||||
|
@ -25,28 +25,47 @@
|
||||
|
||||
package me.lucko.luckperms.common.model;
|
||||
|
||||
import net.luckperms.api.model.PermissionHolder;
|
||||
import net.luckperms.api.model.data.DataType;
|
||||
import net.luckperms.api.node.metadata.types.InheritanceOriginMetadata;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class InheritanceOrigin implements InheritanceOriginMetadata {
|
||||
private final PermissionHolder.Identifier location;
|
||||
private final PermissionHolderIdentifier origin;
|
||||
private final DataType dataType;
|
||||
|
||||
public InheritanceOrigin(PermissionHolder.Identifier location, DataType dataType) {
|
||||
this.location = location;
|
||||
public InheritanceOrigin(PermissionHolderIdentifier origin, DataType dataType) {
|
||||
this.origin = origin;
|
||||
this.dataType = dataType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionHolder.@NonNull Identifier getOrigin() {
|
||||
return this.location;
|
||||
public @NonNull PermissionHolderIdentifier getOrigin() {
|
||||
return this.origin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull DataType getDataType() {
|
||||
return this.dataType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof InheritanceOriginMetadata)) return false;
|
||||
InheritanceOriginMetadata that = (InheritanceOriginMetadata) o;
|
||||
return this.origin.equals(that.getOrigin()) && this.dataType == that.getDataType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.origin, getDataType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.origin + " (" + this.dataType + ")";
|
||||
}
|
||||
}
|
||||
|
@ -53,7 +53,6 @@ import net.luckperms.api.query.Flag;
|
||||
import net.luckperms.api.query.QueryOptions;
|
||||
import net.luckperms.api.util.Tristate;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
@ -102,7 +101,7 @@ public abstract class PermissionHolder {
|
||||
/**
|
||||
* The holders identifier
|
||||
*/
|
||||
private @MonotonicNonNull PermissionHolderIdentifier identifier;
|
||||
private final PermissionHolderIdentifier identifier;
|
||||
|
||||
/**
|
||||
* The holders persistent nodes.
|
||||
@ -135,8 +134,9 @@ public abstract class PermissionHolder {
|
||||
*
|
||||
* @param plugin the plugin instance
|
||||
*/
|
||||
protected PermissionHolder(LuckPermsPlugin plugin) {
|
||||
protected PermissionHolder(LuckPermsPlugin plugin, String objectName) {
|
||||
this.plugin = plugin;
|
||||
this.identifier = new PermissionHolderIdentifier(getType(), objectName);
|
||||
}
|
||||
|
||||
// getters
|
||||
@ -169,22 +169,9 @@ public abstract class PermissionHolder {
|
||||
}
|
||||
|
||||
public PermissionHolderIdentifier getIdentifier() {
|
||||
if (this.identifier == null) {
|
||||
this.identifier = new PermissionHolderIdentifier(getType(), getObjectName());
|
||||
}
|
||||
return this.identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the unique name of this holder object.
|
||||
*
|
||||
* <p>Used as a base for identifying permission holding objects. Also acts
|
||||
* as a method for preventing circular inheritance issues.</p>
|
||||
*
|
||||
* @return the object name
|
||||
*/
|
||||
public abstract String getObjectName();
|
||||
|
||||
/**
|
||||
* Gets the formatted display name of this permission holder
|
||||
* (for use in commands, etc)
|
||||
@ -439,7 +426,7 @@ public abstract class PermissionHolder {
|
||||
}
|
||||
|
||||
public Tristate hasNode(DataType type, Node node, NodeEqualityPredicate equalityPredicate) {
|
||||
if (this.getType() == HolderType.GROUP && node instanceof InheritanceNode && ((InheritanceNode) node).getGroupName().equalsIgnoreCase(getObjectName())) {
|
||||
if (this.getType() == HolderType.GROUP && node instanceof InheritanceNode && ((InheritanceNode) node).getGroupName().equalsIgnoreCase(getIdentifier().getName())) {
|
||||
return Tristate.TRUE;
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,9 @@ public final class PermissionHolderIdentifier implements Identifier {
|
||||
private final String name;
|
||||
|
||||
public PermissionHolderIdentifier(HolderType type, String name) {
|
||||
this.type = type == HolderType.USER ? Identifier.USER_TYPE : Identifier.GROUP_TYPE;
|
||||
this.type = type == HolderType.USER
|
||||
? Identifier.USER_TYPE
|
||||
: Identifier.GROUP_TYPE;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@ -46,13 +48,13 @@ public final class PermissionHolderIdentifier implements Identifier {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull String getName() {
|
||||
return this.name;
|
||||
public @NonNull String getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull String getType() {
|
||||
return this.type;
|
||||
public @NonNull String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -60,12 +62,16 @@ public final class PermissionHolderIdentifier implements Identifier {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof Identifier)) return false;
|
||||
Identifier that = (Identifier) o;
|
||||
return getType().equals(that.getType()) &&
|
||||
getName().equals(that.getName());
|
||||
return this.type.equals(that.getType()) && this.name.equals(that.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(getType(), getName());
|
||||
return Objects.hash(this.type, this.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.type + '/' + this.name;
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ public class User extends PermissionHolder {
|
||||
private final UserCachedDataManager cachedData;
|
||||
|
||||
public User(UUID uniqueId, LuckPermsPlugin plugin) {
|
||||
super(plugin);
|
||||
super(plugin, uniqueId.toString());
|
||||
this.uniqueId = uniqueId;
|
||||
this.primaryGroup = plugin.getConfiguration().get(ConfigKeys.PRIMARY_GROUP_CALCULATION).apply(this);
|
||||
this.cachedData = new UserCachedDataManager(this);
|
||||
@ -77,11 +77,6 @@ public class User extends PermissionHolder {
|
||||
return Optional.ofNullable(this.username);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getObjectName() {
|
||||
return this.uniqueId.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getFormattedDisplayName() {
|
||||
return Component.text(getPlainDisplayName());
|
||||
|
@ -63,7 +63,7 @@ public class WeightCache extends Cache<OptionalInt> {
|
||||
|
||||
if (!seen) {
|
||||
Map<String, Integer> configWeights = this.group.getPlugin().getConfiguration().get(ConfigKeys.GROUP_WEIGHTS);
|
||||
Integer value = configWeights.get(this.group.getObjectName().toLowerCase(Locale.ROOT));
|
||||
Integer value = configWeights.get(this.group.getIdentifier().getName().toLowerCase(Locale.ROOT));
|
||||
if (value != null) {
|
||||
seen = true;
|
||||
weight = value;
|
||||
|
@ -90,11 +90,11 @@ public class NodeMapMutable extends NodeMapBase {
|
||||
private final Lock lock = new ReentrantLock();
|
||||
|
||||
protected final PermissionHolder holder;
|
||||
private final DataType type;
|
||||
private final InheritanceOrigin inheritanceOrigin;
|
||||
|
||||
public NodeMapMutable(PermissionHolder holder, DataType type) {
|
||||
this.holder = holder;
|
||||
this.type = type;
|
||||
this.inheritanceOrigin = new InheritanceOrigin(holder.getIdentifier(), type);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -113,12 +113,12 @@ public class NodeMapMutable extends NodeMapBase {
|
||||
}
|
||||
|
||||
private Node addInheritanceOrigin(Node node) {
|
||||
Optional<InheritanceOriginMetadata> metadata = node.getMetadata(InheritanceOriginMetadata.KEY);
|
||||
if (metadata.isPresent() && metadata.get().getOrigin().equals(this.holder.getIdentifier())) {
|
||||
Optional<InheritanceOriginMetadata> existing = node.getMetadata(InheritanceOriginMetadata.KEY);
|
||||
if (existing.isPresent() && existing.get().equals(this.inheritanceOrigin)) {
|
||||
return node;
|
||||
}
|
||||
|
||||
return node.toBuilder().withMetadata(InheritanceOriginMetadata.KEY, new InheritanceOrigin(this.holder.getIdentifier(), this.type)).build();
|
||||
return node.toBuilder().withMetadata(InheritanceOriginMetadata.KEY, this.inheritanceOrigin).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -139,7 +139,7 @@ public class WebEditorRequest {
|
||||
private static JObject formPermissionHolder(PermissionHolder holder) {
|
||||
return new JObject()
|
||||
.add("type", holder.getType().toString())
|
||||
.add("id", holder.getObjectName())
|
||||
.add("id", holder.getIdentifier().getName())
|
||||
.add("displayName", holder.getPlainDisplayName())
|
||||
.add("nodes", NodeJsonSerializer.serializeNodes(holder.normalData().asList()));
|
||||
}
|
||||
|
@ -27,8 +27,9 @@ package me.lucko.luckperms.sponge.service.model;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import me.lucko.luckperms.common.model.PermissionHolderIdentifier;
|
||||
|
||||
import net.luckperms.api.context.ImmutableContextSet;
|
||||
import net.luckperms.api.model.PermissionHolder;
|
||||
import net.luckperms.api.query.QueryOptions;
|
||||
import net.luckperms.api.util.Tristate;
|
||||
|
||||
@ -46,7 +47,7 @@ public interface LPSubject {
|
||||
|
||||
LPPermissionService getService();
|
||||
|
||||
PermissionHolder.Identifier getIdentifier();
|
||||
PermissionHolderIdentifier getIdentifier();
|
||||
|
||||
default LPSubjectReference toReference() {
|
||||
return getService().getReferenceFactory().obtain(this);
|
||||
|
@ -70,6 +70,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
public class CalculatedSubjectData implements LPSubjectData {
|
||||
private final LPSubject parentSubject;
|
||||
private final DataType type;
|
||||
private final InheritanceOrigin inheritanceOrigin;
|
||||
private final LPPermissionService service;
|
||||
|
||||
private final Map<ImmutableContextSet, Map<String, Boolean>> permissions = new ConcurrentHashMap<>();
|
||||
@ -79,6 +80,7 @@ public class CalculatedSubjectData implements LPSubjectData {
|
||||
public CalculatedSubjectData(LPSubject parentSubject, DataType type, LPPermissionService service) {
|
||||
this.parentSubject = parentSubject;
|
||||
this.type = type;
|
||||
this.inheritanceOrigin = new InheritanceOrigin(this.parentSubject.getIdentifier(), this.type);
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
@ -155,7 +157,7 @@ public class CalculatedSubjectData implements LPSubjectData {
|
||||
.permission(key)
|
||||
.value(value)
|
||||
.context(entry.getKey())
|
||||
.withMetadata(InheritanceOriginMetadata.KEY, new InheritanceOrigin(this.parentSubject.getIdentifier(), this.type))
|
||||
.withMetadata(InheritanceOriginMetadata.KEY, this.inheritanceOrigin)
|
||||
.build();
|
||||
nodeMap.put(key, node);
|
||||
});
|
||||
@ -320,7 +322,7 @@ public class CalculatedSubjectData implements LPSubjectData {
|
||||
.key(key)
|
||||
.value(value)
|
||||
.context(entry.getKey())
|
||||
.withMetadata(InheritanceOriginMetadata.KEY, new InheritanceOrigin(this.parentSubject.getIdentifier(), this.type))
|
||||
.withMetadata(InheritanceOriginMetadata.KEY, this.inheritanceOrigin)
|
||||
.build();
|
||||
nodeMap.put(key, node);
|
||||
});
|
||||
|
@ -25,13 +25,12 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.service.model.permissionholder;
|
||||
|
||||
import me.lucko.luckperms.common.model.PermissionHolderIdentifier;
|
||||
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
||||
import me.lucko.luckperms.sponge.model.SpongeGroup;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
|
||||
|
||||
import net.luckperms.api.model.PermissionHolder;
|
||||
|
||||
import org.spongepowered.api.command.CommandSource;
|
||||
|
||||
import java.util.Optional;
|
||||
@ -45,7 +44,7 @@ public class GroupSubject extends PermissionHolderSubject<SpongeGroup> implement
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionHolder.Identifier getIdentifier() {
|
||||
public PermissionHolderIdentifier getIdentifier() {
|
||||
return this.parent.getIdentifier();
|
||||
}
|
||||
|
||||
|
@ -25,13 +25,12 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.service.model.permissionholder;
|
||||
|
||||
import me.lucko.luckperms.common.model.PermissionHolderIdentifier;
|
||||
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
||||
import me.lucko.luckperms.sponge.model.SpongeUser;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
|
||||
|
||||
import net.luckperms.api.model.PermissionHolder;
|
||||
|
||||
import org.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.command.CommandSource;
|
||||
|
||||
@ -48,7 +47,7 @@ public final class UserSubject extends PermissionHolderSubject<SpongeUser> imple
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionHolder.Identifier getIdentifier() {
|
||||
public PermissionHolderIdentifier getIdentifier() {
|
||||
return this.parent.getIdentifier();
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,6 @@ import me.lucko.luckperms.sponge.service.model.calculated.CalculatedSubject;
|
||||
import me.lucko.luckperms.sponge.service.model.calculated.CalculatedSubjectData;
|
||||
import me.lucko.luckperms.sponge.service.model.calculated.MonitoredSubjectData;
|
||||
|
||||
import net.luckperms.api.model.PermissionHolder;
|
||||
import net.luckperms.api.model.data.DataType;
|
||||
|
||||
import org.spongepowered.api.command.CommandSource;
|
||||
@ -158,7 +157,7 @@ public class PersistedSubject extends CalculatedSubject implements LPSubject {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionHolder.Identifier getIdentifier() {
|
||||
public PermissionHolderIdentifier getIdentifier() {
|
||||
return this.identifier;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user