Fix error when group flag existed for non-existent flag.

Probably caused by bad API usage /shrug.
This commit is contained in:
wizjany 2019-05-21 16:31:42 -04:00
parent 2b854f0d72
commit f516999087

View File

@ -24,6 +24,8 @@
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.sk89q.worldguard.protection.flags.Flag; import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.Flags; import com.sk89q.worldguard.protection.flags.Flags;
import com.sk89q.worldguard.protection.flags.RegionGroup;
import com.sk89q.worldguard.protection.flags.RegionGroupFlag;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Collection; import java.util.Collection;
@ -149,11 +151,19 @@ public Map<Flag<?>, Object> unmarshal(Map<String, Object> rawValues, boolean cre
} }
} }
} }
RegionGroupFlag groupUnmarshaller = new RegionGroupFlag("unmarshaldummy", RegionGroup.NONE);
for (Entry<String, Object> entry : regionFlags.entrySet()) { for (Entry<String, Object> entry : regionFlags.entrySet()) {
String parentName = entry.getKey().replaceAll("-group", ""); String parentName = entry.getKey().replaceAll("-group", "");
Flag<?> parent = get(parentName); Flag<?> parent = get(parentName);
if (parent == null || parent instanceof UnknownFlag) { if (parent == null || parent instanceof UnknownFlag) {
if (createUnknown) forceRegister(new UnknownFlag(entry.getKey())); if (createUnknown && get(entry.getKey()) == null) {
final UnknownFlag unknownFlag = new UnknownFlag(entry.getKey());
forceRegister(unknownFlag);
}
Flag<?> unk = get(entry.getKey());
if (unk != null) {
values.put(unk, groupUnmarshaller.unmarshal(entry.getValue()));
}
} else { } else {
values.put(parent.getRegionGroupFlag(), parent.getRegionGroupFlag().unmarshal(entry.getValue())); values.put(parent.getRegionGroupFlag(), parent.getRegionGroupFlag().unmarshal(entry.getValue()));
} }