mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2025-01-15 21:01:34 +01:00
Fix NPEs caused in LPPermissionMap (#794)
This commit is contained in:
parent
6704ac4b46
commit
aa4833ed74
@ -40,10 +40,12 @@ import org.bukkit.plugin.PluginManager;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import javax.annotation.CheckForNull;
|
import javax.annotation.CheckForNull;
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A replacement map for the 'permissions' instance in Bukkit's SimplePluginManager.
|
* A replacement map for the 'permissions' instance in Bukkit's SimplePluginManager.
|
||||||
@ -94,6 +96,9 @@ public final class LPPermissionMap extends ForwardingMap<String, Permission> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Permission put(@Nonnull String key, @Nonnull Permission value) {
|
public Permission put(@Nonnull String key, @Nonnull Permission value) {
|
||||||
|
Objects.requireNonNull(key, "key");
|
||||||
|
Objects.requireNonNull(value, "value");
|
||||||
|
|
||||||
this.plugin.getPermissionVault().offer(key);
|
this.plugin.getPermissionVault().offer(key);
|
||||||
Permission ret = super.put(key, value);
|
Permission ret = super.put(key, value);
|
||||||
update();
|
update();
|
||||||
@ -109,12 +114,48 @@ public final class LPPermissionMap extends ForwardingMap<String, Permission> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Permission putIfAbsent(String key, Permission value) {
|
public Permission putIfAbsent(String key, Permission value) {
|
||||||
|
Objects.requireNonNull(key, "key");
|
||||||
|
Objects.requireNonNull(value, "value");
|
||||||
|
|
||||||
this.plugin.getPermissionVault().offer(key);
|
this.plugin.getPermissionVault().offer(key);
|
||||||
Permission ret = super.putIfAbsent(key, value);
|
Permission ret = super.putIfAbsent(key, value);
|
||||||
update();
|
update();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// null-safe - the plugin manager uses hashmap
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Permission remove(@Nullable Object object) {
|
||||||
|
if (object == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return super.remove(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean remove(Object key, Object value) {
|
||||||
|
return key != null && value != null && super.remove(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean containsKey(@Nullable Object key) {
|
||||||
|
return key != null && super.containsKey(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean containsValue(@Nullable Object value) {
|
||||||
|
return value != null && super.containsValue(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Permission get(@Nullable Object key) {
|
||||||
|
if (key == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return super.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
private final class ChildPermissionResolver implements CacheLoader<String, Map<String, Boolean>> {
|
private final class ChildPermissionResolver implements CacheLoader<String, Map<String, Boolean>> {
|
||||||
private final boolean value;
|
private final boolean value;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user