forked from LogBlock/LogBlock
Improve compatibility when running 1.13 and 1.14 servers on the same logblock database
Old materials are no longer renamed, instead new materials are added and the old entries are modified
This commit is contained in:
@ -88,7 +88,6 @@ public class LogBlock extends JavaPlugin {
|
|||||||
conn.close();
|
conn.close();
|
||||||
Updater updater = new Updater(this);
|
Updater updater = new Updater(this);
|
||||||
updater.checkTables();
|
updater.checkTables();
|
||||||
updater.updateMaterialsPost1_13();
|
|
||||||
MaterialConverter.initializeMaterials(getConnection());
|
MaterialConverter.initializeMaterials(getConnection());
|
||||||
MaterialConverter.getOrAddMaterialId(Material.AIR.getKey()); // AIR must be the first entry
|
MaterialConverter.getOrAddMaterialId(Material.AIR.getKey()); // AIR must be the first entry
|
||||||
EntityTypeConverter.initializeEntityTypes(getConnection());
|
EntityTypeConverter.initializeEntityTypes(getConnection());
|
||||||
|
@ -756,6 +756,8 @@ class Updater {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateMaterialsPost1_13();
|
||||||
|
|
||||||
logblock.saveConfig();
|
logblock.saveConfig();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -838,7 +840,7 @@ class Updater {
|
|||||||
/**
|
/**
|
||||||
* Update materials that were renamed
|
* Update materials that were renamed
|
||||||
*/
|
*/
|
||||||
public void updateMaterialsPost1_13() {
|
private void updateMaterialsPost1_13() {
|
||||||
final ConfigurationSection config = logblock.getConfig();
|
final ConfigurationSection config = logblock.getConfig();
|
||||||
String previousMinecraftVersion = config.getString("previousMinecraftVersion");
|
String previousMinecraftVersion = config.getString("previousMinecraftVersion");
|
||||||
if (previousMinecraftVersion == null) {
|
if (previousMinecraftVersion == null) {
|
||||||
@ -858,56 +860,43 @@ class Updater {
|
|||||||
|
|
||||||
if (comparablePreviousMinecraftVersion.compareTo("1.14") < 0 && comparableCurrentMinecraftVersion.compareTo("1.14") >= 0) {
|
if (comparablePreviousMinecraftVersion.compareTo("1.14") < 0 && comparableCurrentMinecraftVersion.compareTo("1.14") >= 0) {
|
||||||
logblock.getLogger().info("[Updater] Upgrading Materials to 1.14");
|
logblock.getLogger().info("[Updater] Upgrading Materials to 1.14");
|
||||||
renameMaterial("minecraft:sign", "minecraft:oak_sign", true);
|
renameMaterial("minecraft:sign", "minecraft:oak_sign");
|
||||||
renameMaterial("minecraft:wall_sign", "minecraft:oak_wall_sign", true);
|
renameMaterial("minecraft:wall_sign", "minecraft:oak_wall_sign");
|
||||||
renameMaterial("minecraft:stone_slab", "minecraft:smooth_stone_slab", false);
|
renameMaterial("minecraft:stone_slab", "minecraft:smooth_stone_slab");
|
||||||
renameMaterial("minecraft:rose_red", "minecraft:red_dye", true);
|
renameMaterial("minecraft:rose_red", "minecraft:red_dye");
|
||||||
renameMaterial("minecraft:dandelion_yellow", "minecraft:yellow_dye", true);
|
renameMaterial("minecraft:dandelion_yellow", "minecraft:yellow_dye");
|
||||||
renameMaterial("minecraft:cactus_green", "minecraft:green_dye", true);
|
renameMaterial("minecraft:cactus_green", "minecraft:green_dye");
|
||||||
}
|
}
|
||||||
|
|
||||||
config.set("previousMinecraftVersion", currentMinecraftVersion);
|
config.set("previousMinecraftVersion", currentMinecraftVersion);
|
||||||
logblock.saveConfig();
|
logblock.saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renameMaterial(String oldName, String newName, boolean mergeOnCollision) {
|
private void renameMaterial(String oldName, String newName) {
|
||||||
logblock.getLogger().info("[Updater] Renaming " + oldName + " to " + newName);
|
|
||||||
final Connection conn = logblock.getConnection();
|
final Connection conn = logblock.getConnection();
|
||||||
try {
|
try {
|
||||||
conn.setAutoCommit(false);
|
conn.setAutoCommit(false);
|
||||||
PreparedStatement stSelectMaterial = conn.prepareStatement("SELECT id FROM `lb-materials` WHERE name = ?");
|
PreparedStatement stSelectMaterial = conn.prepareStatement("SELECT id FROM `lb-materials` WHERE name = ?");
|
||||||
stSelectMaterial.setString(1, oldName);
|
stSelectMaterial.setString(1, oldName);
|
||||||
ResultSet rs = stSelectMaterial.executeQuery();
|
ResultSet rs = stSelectMaterial.executeQuery();
|
||||||
if (!rs.next()) {
|
if (rs.next()) {
|
||||||
logblock.getLogger().info("[Updater] Skipped because " + oldName + " does not exist..");
|
logblock.getLogger().info("[Updater] Updating " + oldName + " to " + newName);
|
||||||
} else {
|
|
||||||
int oldId = rs.getInt(1);
|
int oldId = rs.getInt(1);
|
||||||
stSelectMaterial.setString(1, newName);
|
int newId = MaterialConverter.getOrAddMaterialId(newName);
|
||||||
rs = stSelectMaterial.executeQuery();
|
|
||||||
if (rs.next()) {
|
Statement st = conn.createStatement();
|
||||||
int newId = rs.getInt(1);
|
int rows = 0;
|
||||||
if (!mergeOnCollision) {
|
for (final WorldConfig wcfg : getLoggedWorlds()) {
|
||||||
logblock.getLogger().info("[Updater] Skipped because " + newName + " already exists..");
|
rows += st.executeUpdate("UPDATE `" + wcfg.table + "-blocks` SET replaced = " + newId + " WHERE replaced = " + oldId);
|
||||||
} else {
|
rows += st.executeUpdate("UPDATE `" + wcfg.table + "-blocks` SET type = " + newId + " WHERE type = " + oldId);
|
||||||
Statement st = conn.createStatement();
|
rows += st.executeUpdate("UPDATE `" + wcfg.table + "-chestdata` SET itemtype = " + newId + " WHERE itemtype = " + oldId);
|
||||||
int rows = 0;
|
if (wcfg.isLogging(Logging.KILL)) {
|
||||||
for (final WorldConfig wcfg : getLoggedWorlds()) {
|
rows += st.executeUpdate("UPDATE `" + wcfg.table + "-kills` SET weapon = " + newId + " WHERE weapon = " + oldId);
|
||||||
rows += st.executeUpdate("UPDATE `" + wcfg.table + "-blocks` SET replaced = " + newId + " WHERE replaced = " + oldId);
|
|
||||||
rows += st.executeUpdate("UPDATE `" + wcfg.table + "-blocks` SET type = " + newId + " WHERE type = " + oldId);
|
|
||||||
rows += st.executeUpdate("UPDATE `" + wcfg.table + "-chestdata` SET itemtype = " + newId + " WHERE itemtype = " + oldId);
|
|
||||||
}
|
|
||||||
st.execute("DELETE FROM `lb-materials` WHERE id = " + oldId);
|
|
||||||
st.close();
|
|
||||||
logblock.getLogger().info("[Updater] Successfully merged " + rows + " entries..");
|
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
PreparedStatement stRenameMaterial = conn.prepareStatement("UPDATE `lb-materials` SET name = ? WHERE id = ?");
|
st.close();
|
||||||
stRenameMaterial.setString(1, newName);
|
if (rows > 0) {
|
||||||
stRenameMaterial.setInt(2, oldId);
|
logblock.getLogger().info("[Updater] Successfully updated " + rows + " entries..");
|
||||||
if (stRenameMaterial.executeUpdate() > 0) {
|
|
||||||
logblock.getLogger().info("[Updater] Successfully renamed..");
|
|
||||||
}
|
|
||||||
stRenameMaterial.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stSelectMaterial.close();
|
stSelectMaterial.close();
|
||||||
|
Reference in New Issue
Block a user