Fix startup on Nukkit (#2290)

This commit is contained in:
Luck 2020-05-16 11:52:51 +01:00
parent 918ea7503a
commit c120fa6a4d
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
3 changed files with 28 additions and 3 deletions

View File

@ -71,7 +71,7 @@ public class DummyPermissibleBase extends PermissibleBase {
try {
ATTACHMENTS_FIELD.set(this, EmptyCollections.list());
PERMISSIONS_FIELD.set(this, EmptyCollections.map());
} catch (ReflectiveOperationException e) {
} catch (Exception e) {
e.printStackTrace();
}
}

View File

@ -27,7 +27,9 @@ package me.lucko.luckperms.common.util;
import java.util.AbstractList;
import java.util.AbstractMap;
import java.util.AbstractSet;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -39,6 +41,7 @@ public final class EmptyCollections {
private EmptyCollections() {}
private static final EmptyList<?> LIST = new EmptyList<>();
private static final EmptySet<?> SET = new EmptySet<>();
private static final EmptyMap<?, ?> MAP = new EmptyMap<>();
@SuppressWarnings("unchecked")
@ -46,6 +49,11 @@ public final class EmptyCollections {
return (List<E>) LIST;
}
@SuppressWarnings("unchecked")
public static <E> Set<E> set() {
return (Set<E>) SET;
}
@SuppressWarnings("unchecked")
public static <K, V> Map<K, V> map() {
return (Map<K, V>) MAP;
@ -78,6 +86,23 @@ public final class EmptyCollections {
}
}
private static final class EmptySet<E> extends AbstractSet<E> {
@Override
public Iterator<E> iterator() {
return Collections.emptyIterator();
}
@Override
public int size() {
return 0;
}
@Override
public boolean add(E e) {
return true;
}
}
private static final class EmptyMap<K, V> extends AbstractMap<K, V> {
@Override
public Set<Entry<K, V>> entrySet() {

View File

@ -68,9 +68,9 @@ public class DummyPermissibleBase extends PermissibleBase {
super(null);
try {
ATTACHMENTS_FIELD.set(this, EmptyCollections.list());
ATTACHMENTS_FIELD.set(this, EmptyCollections.set());
PERMISSIONS_FIELD.set(this, EmptyCollections.map());
} catch (ReflectiveOperationException e) {
} catch (Exception e) {
e.printStackTrace();
}
}