No null in Collection/MapGameRule; resolves #993

This commit is contained in:
Tim Daniel Saukel 2021-04-07 23:53:23 +02:00
parent 3be40cc20a
commit c956344176
2 changed files with 10 additions and 2 deletions

View File

@ -72,7 +72,7 @@ public class CollectionGameRule<T, V extends Collection<T>> extends GameRule<V>
Object value = config.get(getKey());
if (reader != null) {
V v = reader.read(api, value);
container.setState(this, v);
setStateWithoutNull(container, v);
return v;
}
@ -82,10 +82,17 @@ public class CollectionGameRule<T, V extends Collection<T>> extends GameRule<V>
} catch (ClassCastException exception) {
return null;
}
container.setState(this, v);
setStateWithoutNull(container, v);
return v;
}
private void setStateWithoutNull(GameRuleContainer container, V v) {
while (v != null && v.contains(null)) {
v.remove(null);
}
container.setState(this, v);
}
@Override
public void merge(GameRuleContainer overriding, GameRuleContainer subsidiary, GameRuleContainer writeTo) {
V writeToState = writeTo.getState(this);

View File

@ -68,6 +68,7 @@ public class MapGameRule<TK, TV, V extends Map<TK, TV>> extends GameRule<V> {
if (v == null) {
return null;
}
v.remove(null); // Do not allow null values
container.setState(this, v);
return v;
}