mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-24 11:38:40 +01:00
Make the dummy attachment a bit more compatible
still MassiveCore lol
This commit is contained in:
parent
f4e4f727dd
commit
07b003c77a
@ -32,8 +32,12 @@ import cn.nukkit.permission.PermissionAttachmentInfo;
|
||||
import cn.nukkit.plugin.Plugin;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.AbstractList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.RandomAccess;
|
||||
|
||||
public class DummyPermissibleBase extends PermissibleBase {
|
||||
private static final Field ATTACHMENTS_FIELD;
|
||||
@ -53,7 +57,7 @@ public class DummyPermissibleBase extends PermissibleBase {
|
||||
|
||||
public static void nullFields(PermissibleBase permissibleBase) {
|
||||
try {
|
||||
ATTACHMENTS_FIELD.set(permissibleBase, Collections.emptyList());
|
||||
ATTACHMENTS_FIELD.set(permissibleBase, EMPTY_LIST);
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
@ -98,4 +102,31 @@ public class DummyPermissibleBase extends PermissibleBase {
|
||||
@Override public void clearPermissions() {}
|
||||
@Override public Map<String, PermissionAttachmentInfo> getEffectivePermissions() { return Collections.emptyMap(); }
|
||||
|
||||
// empty list impl that doesn't throw an exception on calls to #add
|
||||
private static final List EMPTY_LIST = new EmptyList<>();
|
||||
private static class EmptyList<E> extends AbstractList<E> implements RandomAccess {
|
||||
|
||||
@Override
|
||||
public boolean add(E e) {
|
||||
// do nothing, but don't throw an exception
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(Collection<? extends E> c) {
|
||||
// do nothing
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public E get(int index) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user