More workarounds to support MassiveCore's modification of attachment permissions via reflection

This commit is contained in:
Luck 2018-05-31 00:51:33 +01:00
parent 644c53a074
commit f4e4f727dd
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
4 changed files with 34 additions and 14 deletions

View File

@ -53,12 +53,12 @@ public class DummyPermissibleBase extends PermissibleBase {
public static void nullFields(PermissibleBase permissibleBase) {
try {
ATTACHMENTS_FIELD.set(permissibleBase, null);
ATTACHMENTS_FIELD.set(permissibleBase, Collections.emptyList());
} catch (Exception e) {
// ignore
}
try {
PERMISSIONS_FIELD.set(permissibleBase, null);
PERMISSIONS_FIELD.set(permissibleBase, Collections.emptyMap());
} catch (Exception e) {
// ignore
}

View File

@ -110,7 +110,7 @@ public class LPPermissionAttachment extends PermissionAttachment {
public LPPermissionAttachment(LPPermissible permissible, PermissionAttachment source) {
super(DummyPlugin.INSTANCE, null);
this.permissible = permissible;
this.owner = null;
this.owner = source.getPlugin();
// copy
this.perms.putAll(source.getPermissions());
@ -389,19 +389,29 @@ public class LPPermissionAttachment extends PermissionAttachment {
@Override
public Set<String> keySet() {
// just proxy
return LPPermissionAttachment.this.perms.keySet();
return Collections.unmodifiableSet(LPPermissionAttachment.this.perms.keySet());
}
@Override
public Collection<Boolean> values() {
// just proxy
return LPPermissionAttachment.this.perms.values();
return Collections.unmodifiableCollection(LPPermissionAttachment.this.perms.values());
}
@Override
public Set<Entry<String, Boolean>> entrySet() {
// just proxy
return LPPermissionAttachment.this.perms.entrySet();
return Collections.unmodifiableSet(LPPermissionAttachment.this.perms.entrySet());
}
@Override
public boolean equals(Object obj) {
return obj instanceof Map<?, ?> && LPPermissionAttachment.this.perms.equals(obj);
}
@Override
public int hashCode() {
return LPPermissionAttachment.this.perms.hashCode();
}
}
}

View File

@ -53,12 +53,12 @@ public class DummyPermissibleBase extends PermissibleBase {
public static void nullFields(PermissibleBase permissibleBase) {
try {
ATTACHMENTS_FIELD.set(permissibleBase, null);
ATTACHMENTS_FIELD.set(permissibleBase, Collections.emptyList());
} catch (Exception e) {
// ignore
}
try {
PERMISSIONS_FIELD.set(permissibleBase, null);
PERMISSIONS_FIELD.set(permissibleBase, Collections.emptyMap());
} catch (Exception e) {
// ignore
}

View File

@ -109,13 +109,13 @@ public class LPPermissionAttachment extends PermissionAttachment {
injectFakeMap();
}
public LPPermissionAttachment(LPPermissible permissible, PermissionAttachment nukkit) {
public LPPermissionAttachment(LPPermissible permissible, PermissionAttachment source) {
super(DummyPlugin.INSTANCE, null);
this.permissible = permissible;
this.owner = null;
this.owner = source.getPlugin();
// copy
this.perms.putAll(nukkit.getPermissions());
this.perms.putAll(source.getPermissions());
this.source = source;
injectFakeMap();
@ -419,19 +419,29 @@ public class LPPermissionAttachment extends PermissionAttachment {
@Override
public Set<String> keySet() {
// just proxy
return LPPermissionAttachment.this.perms.keySet();
return Collections.unmodifiableSet(LPPermissionAttachment.this.perms.keySet());
}
@Override
public Collection<Boolean> values() {
// just proxy
return LPPermissionAttachment.this.perms.values();
return Collections.unmodifiableCollection(LPPermissionAttachment.this.perms.values());
}
@Override
public Set<Entry<String, Boolean>> entrySet() {
// just proxy
return LPPermissionAttachment.this.perms.entrySet();
return Collections.unmodifiableSet(LPPermissionAttachment.this.perms.entrySet());
}
@Override
public boolean equals(Object obj) {
return obj instanceof Map<?, ?> && LPPermissionAttachment.this.perms.equals(obj);
}
@Override
public int hashCode() {
return LPPermissionAttachment.this.perms.hashCode();
}
}
}