mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-02 17:00:19 +01:00
Fix game rule merging
This commit is contained in:
parent
767a5eddaf
commit
f8ea5eff69
@ -83,8 +83,24 @@ public class CollectionGameRule<T, V extends Collection<T>> extends GameRule<V>
|
||||
@Override
|
||||
public void merge(GameRuleContainer overriding, GameRuleContainer subsidiary, GameRuleContainer writeTo) {
|
||||
V write = writeTo.getState(this);
|
||||
write.addAll(subsidiary.getState(this));
|
||||
write.addAll(overriding.getState(this));
|
||||
|
||||
V subsidiaryState = subsidiary.getState(this);
|
||||
if (subsidiaryState != null) {
|
||||
if (write == null) {
|
||||
write = subsidiaryState;
|
||||
} else {
|
||||
write.addAll(subsidiaryState);
|
||||
}
|
||||
}
|
||||
|
||||
V overridingState = overriding.getState(this);
|
||||
if (overridingState != null) {
|
||||
if (write == null) {
|
||||
write = overridingState;
|
||||
} else {
|
||||
write.addAll(overridingState);
|
||||
}
|
||||
}
|
||||
writeTo.setState(this, write);
|
||||
}
|
||||
|
||||
|
@ -36,10 +36,13 @@ public class GameRuleContainer {
|
||||
}
|
||||
}
|
||||
|
||||
private Map<GameRule<?>, Object> rules;
|
||||
|
||||
/**
|
||||
* Initializes an emtpy GameRuleContainer.
|
||||
*/
|
||||
public GameRuleContainer() {
|
||||
rules = new HashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -51,8 +54,6 @@ public class GameRuleContainer {
|
||||
rules = new HashMap<>(container.rules);
|
||||
}
|
||||
|
||||
private Map<GameRule<?>, Object> rules = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Returns the state of the GameRule or UNDEFINED_STATE if it is not defined
|
||||
*
|
||||
@ -86,7 +87,7 @@ public class GameRuleContainer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the rule from the map sothat a subsidiary provider can set it.
|
||||
* Removes the rule from the map sothat a subsidiary container can set it.
|
||||
*
|
||||
* @param rule the GameRule to unset
|
||||
*/
|
||||
@ -100,7 +101,7 @@ public class GameRuleContainer {
|
||||
* @param subsidiary the GameRules that override the values that are null.
|
||||
*/
|
||||
public void merge(GameRuleContainer subsidiary) {
|
||||
rules.entrySet().forEach(e -> e.getKey().merge(this, subsidiary, this));
|
||||
subsidiary.rules.entrySet().forEach(e -> e.getKey().merge(this, subsidiary, this));
|
||||
|
||||
// If we are using the last subsidiary rules (the default rules) and if blocks may be broken...
|
||||
if (subsidiary != DEFAULT_VALUES || !getState(GameRule.BREAK_BLOCKS)) {
|
||||
|
@ -71,8 +71,24 @@ public class MapGameRule<TK, TV, V extends Map<TK, TV>> extends GameRule<V> {
|
||||
@Override
|
||||
public void merge(GameRuleContainer overriding, GameRuleContainer subsidiary, GameRuleContainer writeTo) {
|
||||
V write = writeTo.getState(this);
|
||||
write.putAll(subsidiary.getState(this));
|
||||
write.putAll(overriding.getState(this));
|
||||
|
||||
V subsidiaryState = subsidiary.getState(this);
|
||||
if (subsidiaryState != null) {
|
||||
if (write == null) {
|
||||
write = subsidiaryState;
|
||||
} else {
|
||||
write.putAll(subsidiaryState);
|
||||
}
|
||||
}
|
||||
|
||||
V overridingState = overriding.getState(this);
|
||||
if (overridingState != null) {
|
||||
if (write == null) {
|
||||
write = overridingState;
|
||||
} else {
|
||||
write.putAll(overridingState);
|
||||
}
|
||||
}
|
||||
writeTo.setState(this, write);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user