Skip to content

Commit

Permalink
Added safeguard in for building configuration maps. This will solve a…
Browse files Browse the repository at this point in the history
…ny issues such as invalid enchantments trying to be saved.
  • Loading branch information
dumptruckman committed Jan 4, 2013
1 parent 5928f6f commit 0713948
Showing 1 changed file with 16 additions and 11 deletions.
@@ -1,5 +1,6 @@
package com.onarandombox.multiverseinventories.util;

import com.dumptruckman.minecraft.util.Logging;
import net.minidev.json.parser.JSONParser;
import net.minidev.json.parser.ParseException;
import org.apache.commons.lang.Validate;
Expand Down Expand Up @@ -37,18 +38,22 @@ public String saveToString() {

private Map<String, Object> buildMap(final Map<String, Object> map) {
final Map<String, Object> result = new LinkedHashMap<String, Object>();
for (final Map.Entry<String, Object> entry : map.entrySet()) {
if (entry.getValue() instanceof ConfigurationSection) {
result.put(entry.getKey(), buildMap(((ConfigurationSection) entry.getValue()).getValues(false)));
} else if (entry.getValue() instanceof ConfigurationSerializable) {
ConfigurationSerializable serializable = (ConfigurationSerializable) entry.getValue();
Map<String, Object> values = new LinkedHashMap<String, Object>();
values.put(ConfigurationSerialization.SERIALIZED_TYPE_KEY, ConfigurationSerialization.getAlias(serializable.getClass()));
values.putAll(serializable.serialize());
result.put(entry.getKey(), buildMap(values));
} else {
result.put(entry.getKey(), entry.getValue());
try {
for (final Map.Entry<String, Object> entry : map.entrySet()) {
if (entry.getValue() instanceof ConfigurationSection) {
result.put(entry.getKey(), buildMap(((ConfigurationSection) entry.getValue()).getValues(false)));
} else if (entry.getValue() instanceof ConfigurationSerializable) {
ConfigurationSerializable serializable = (ConfigurationSerializable) entry.getValue();
Map<String, Object> values = new LinkedHashMap<String, Object>();
values.put(ConfigurationSerialization.SERIALIZED_TYPE_KEY, ConfigurationSerialization.getAlias(serializable.getClass()));
values.putAll(serializable.serialize());
result.put(entry.getKey(), buildMap(values));
} else {
result.put(entry.getKey(), entry.getValue());
}
}
} catch (Exception e) {
Logging.getLogger().log(Level.WARNING, "Error while building configuration map.", e);
}
return result;
}
Expand Down

0 comments on commit 0713948

Please sign in to comment.