Fix NPE from permission holder initialisation order (#3263)

This commit is contained in:
Luck 2022-01-02 16:58:15 +00:00
parent a53c9fad00
commit f61d9ff9f0
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
3 changed files with 12 additions and 9 deletions

View File

@ -37,8 +37,8 @@ public class InheritanceOrigin implements InheritanceOriginMetadata {
private final DataType dataType; private final DataType dataType;
public InheritanceOrigin(PermissionHolderIdentifier origin, DataType dataType) { public InheritanceOrigin(PermissionHolderIdentifier origin, DataType dataType) {
this.origin = origin; this.origin = Objects.requireNonNull(origin, "origin");
this.dataType = dataType; this.dataType = Objects.requireNonNull(dataType, "dataType");
} }
@Override @Override

View File

@ -110,7 +110,7 @@ public abstract class PermissionHolder {
* *
* @see #normalData() * @see #normalData()
*/ */
private final RecordedNodeMap normalNodes = new RecordedNodeMap(new NodeMapMutable(this, DataType.NORMAL)); private final RecordedNodeMap normalNodes;
/** /**
* The holders transient nodes. * The holders transient nodes.
@ -122,12 +122,12 @@ public abstract class PermissionHolder {
* *
* @see #transientData() * @see #transientData()
*/ */
private final NodeMap transientNodes = new NodeMapMutable(this, DataType.TRANSIENT); private final NodeMap transientNodes;
/** /**
* Comparator used to ordering groups when calculating inheritance * Comparator used to ordering groups when calculating inheritance
*/ */
private final Comparator<? super PermissionHolder> inheritanceComparator = InheritanceComparator.getFor(this); private final Comparator<? super PermissionHolder> inheritanceComparator;
/** /**
* Creates a new instance * Creates a new instance
@ -137,6 +137,9 @@ public abstract class PermissionHolder {
protected PermissionHolder(LuckPermsPlugin plugin, String objectName) { protected PermissionHolder(LuckPermsPlugin plugin, String objectName) {
this.plugin = plugin; this.plugin = plugin;
this.identifier = new PermissionHolderIdentifier(getType(), objectName); this.identifier = new PermissionHolderIdentifier(getType(), objectName);
this.normalNodes = new RecordedNodeMap(new NodeMapMutable(this, DataType.NORMAL));
this.transientNodes = new NodeMapMutable(this, DataType.TRANSIENT);
this.inheritanceComparator = InheritanceComparator.getFor(this);
} }
// getters // getters

View File

@ -36,15 +36,15 @@ public final class PermissionHolderIdentifier implements Identifier {
private final String name; private final String name;
public PermissionHolderIdentifier(HolderType type, String name) { public PermissionHolderIdentifier(HolderType type, String name) {
this.type = type == HolderType.USER this.type = Objects.requireNonNull(type, "type") == HolderType.USER
? Identifier.USER_TYPE ? Identifier.USER_TYPE
: Identifier.GROUP_TYPE; : Identifier.GROUP_TYPE;
this.name = name; this.name = Objects.requireNonNull(name, "name");
} }
public PermissionHolderIdentifier(String type, String name) { public PermissionHolderIdentifier(String type, String name) {
this.type = type; this.type = Objects.requireNonNull(type, "type");
this.name = name; this.name = Objects.requireNonNull(name, "name");
} }
@Override @Override