Do not check for invalid materials in the config before upgrading them

This commit is contained in:
Brokkonaut
2018-07-29 15:31:59 +02:00
parent 0bdbce59b8
commit 9f1fc3fe7b
2 changed files with 13 additions and 5 deletions

View File

@ -1,6 +1,8 @@
package de.diddiz.LogBlock.config; package de.diddiz.LogBlock.config;
import de.diddiz.LogBlock.*; import de.diddiz.LogBlock.*;
import de.diddiz.util.ComparableVersion;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
@ -136,6 +138,10 @@ public class Config {
} }
} }
logblock.saveConfig(); logblock.saveConfig();
ComparableVersion configVersion = new ComparableVersion(config.getString("version"));
boolean oldConfig = configVersion.compareTo(new ComparableVersion(logblock.getDescription().getVersion().replace(" (manually compiled)", ""))) < 0;
url = "jdbc:mysql://" + config.getString("mysql.host") + ":" + config.getInt("mysql.port") + "/" + getStringIncludingInts(config, "mysql.database"); url = "jdbc:mysql://" + config.getString("mysql.host") + ":" + config.getInt("mysql.port") + "/" + getStringIncludingInts(config, "mysql.database");
user = getStringIncludingInts(config, "mysql.user"); user = getStringIncludingInts(config, "mysql.user");
password = getStringIncludingInts(config, "mysql.password"); password = getStringIncludingInts(config, "mysql.password");
@ -166,7 +172,7 @@ public class Config {
final Material mat = Material.matchMaterial(blocktype); final Material mat = Material.matchMaterial(blocktype);
if (mat != null) { if (mat != null) {
hiddenBlocks.add(mat); hiddenBlocks.add(mat);
} else { } else if (!oldConfig) {
throw new DataFormatException("Not a valid material in hiddenBlocks: '" + blocktype + "'"); throw new DataFormatException("Not a valid material in hiddenBlocks: '" + blocktype + "'");
} }
} }
@ -179,7 +185,7 @@ public class Config {
Material mat = Material.matchMaterial(e); Material mat = Material.matchMaterial(e);
if (mat != null) { if (mat != null) {
dontRollback.add(mat); dontRollback.add(mat);
} else { } else if (!oldConfig) {
throw new DataFormatException("Not a valid material in dontRollback: '" + e + "'"); throw new DataFormatException("Not a valid material in dontRollback: '" + e + "'");
} }
} }
@ -188,7 +194,7 @@ public class Config {
Material mat = Material.matchMaterial(e); Material mat = Material.matchMaterial(e);
if (mat != null) { if (mat != null) {
replaceAnyway.add(mat); replaceAnyway.add(mat);
} else { } else if (!oldConfig) {
throw new DataFormatException("Not a valid material in replaceAnyway: '" + e + "'"); throw new DataFormatException("Not a valid material in replaceAnyway: '" + e + "'");
} }
} }
@ -242,7 +248,7 @@ public class Config {
throw new DataFormatException("No worlds configured"); throw new DataFormatException("No worlds configured");
} }
for (final String world : loggedWorlds) { for (final String world : loggedWorlds) {
worldConfigs.put(world, new WorldConfig(new File(logblock.getDataFolder(), friendlyWorldname(world) + ".yml"))); worldConfigs.put(world, new WorldConfig(world, new File(logblock.getDataFolder(), friendlyWorldname(world) + ".yml")));
} }
superWorldConfig = new LoggingEnabledMapping(); superWorldConfig = new LoggingEnabledMapping();
for (final WorldConfig wcfg : worldConfigs.values()) { for (final WorldConfig wcfg : worldConfigs.values()) {

View File

@ -10,9 +10,11 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
public class WorldConfig extends LoggingEnabledMapping { public class WorldConfig extends LoggingEnabledMapping {
public final String world;
public final String table; public final String table;
public WorldConfig(File file) throws IOException { public WorldConfig(String world, File file) throws IOException {
this.world = world;
final Map<String, Object> def = new HashMap<String, Object>(); final Map<String, Object> def = new HashMap<String, Object>();
// "Before MySQL 5.1.6, database and table names cannot contain "/", "\", ".", or characters that are not permitted in file names" - MySQL manual // "Before MySQL 5.1.6, database and table names cannot contain "/", "\", ".", or characters that are not permitted in file names" - MySQL manual
// They _can_ contain spaces, but replace them as well // They _can_ contain spaces, but replace them as well