mirror of
https://github.com/exituser/Brewery.git
synced 2026-09-17 08:59:01 +00:00
Config Updater to update Material names
Updater will only update materials on 1.13 Updated configs as well
This commit is contained in:
@@ -289,13 +289,9 @@ public class Barrel implements InventoryHolder {
|
||||
public boolean hasBlock(Block block) {
|
||||
if (block != null) {
|
||||
if (LegacyUtil.isWoodPlanks(block.getType())) {
|
||||
if (hasWoodBlock(block)) {
|
||||
return true;
|
||||
}
|
||||
return hasWoodBlock(block);
|
||||
} else if (LegacyUtil.isWoodStairs(block.getType())) {
|
||||
if (hasStairsBlock(block)) {
|
||||
return true;
|
||||
}
|
||||
return hasStairsBlock(block);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@@ -748,7 +744,7 @@ public class Barrel implements InventoryHolder {
|
||||
x = startX;
|
||||
y++;
|
||||
}
|
||||
stairsloc = ArrayUtils.toPrimitive(stairs.toArray(new Integer[stairs.size()]));
|
||||
stairsloc = ArrayUtils.toPrimitive(stairs.toArray(new Integer[0]));
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -839,8 +835,8 @@ public class Barrel implements InventoryHolder {
|
||||
x = startX;
|
||||
y++;
|
||||
}
|
||||
stairsloc = ArrayUtils.toPrimitive(stairs.toArray(new Integer[stairs.size()]));
|
||||
woodsloc = ArrayUtils.toPrimitive(woods.toArray(new Integer[woods.size()]));
|
||||
stairsloc = ArrayUtils.toPrimitive(stairs.toArray(new Integer[0]));
|
||||
woodsloc = ArrayUtils.toPrimitive(woods.toArray(new Integer[0]));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class P extends JavaPlugin {
|
||||
public static P p;
|
||||
public static final String configVersion = "1.6";
|
||||
public static final String configVersion = "1.7";
|
||||
public static boolean debug;
|
||||
public static boolean useUUID;
|
||||
public static boolean use1_9;
|
||||
@@ -249,12 +249,15 @@ public class P extends JavaPlugin {
|
||||
// Load LanguageReader
|
||||
languageReader = new LanguageReader(new File(p.getDataFolder(), "languages/" + language + ".yml"));
|
||||
|
||||
// Has to config still got old materials
|
||||
boolean oldMat = config.getBoolean("oldMat", false);
|
||||
|
||||
// Check if config is the newest version
|
||||
String version = config.getString("version", null);
|
||||
if (version != null) {
|
||||
if (!version.equals(configVersion)) {
|
||||
if (!version.equals(configVersion) || (oldMat && use1_13)) {
|
||||
copyDefaultConfigs(true);
|
||||
new ConfigUpdater(file).update(version, language);
|
||||
new ConfigUpdater(file).update(version, oldMat, language);
|
||||
P.p.log("Config Updated to version: " + configVersion);
|
||||
config = YamlConfiguration.loadConfiguration(file);
|
||||
}
|
||||
@@ -707,7 +710,7 @@ public class P extends JavaPlugin {
|
||||
BCauldron.remove(block);
|
||||
return true;
|
||||
|
||||
} else if (LegacyUtil.isFence(type)) {
|
||||
} else if (LegacyUtil.isFence(type)) {
|
||||
// remove barrel and throw potions on the ground
|
||||
Barrel barrel = Barrel.getBySpigot(block);
|
||||
if (barrel != null) {
|
||||
@@ -720,7 +723,7 @@ public class P extends JavaPlugin {
|
||||
}
|
||||
return true;
|
||||
|
||||
} else if (LegacyUtil.isSign(type)) {
|
||||
} else if (LegacyUtil.isSign(type)) {
|
||||
// remove small Barrels
|
||||
Barrel barrel2 = Barrel.getBySpigot(block);
|
||||
if (barrel2 != null) {
|
||||
@@ -737,7 +740,7 @@ public class P extends JavaPlugin {
|
||||
}
|
||||
return true;
|
||||
|
||||
} else if (LegacyUtil.isWoodPlanks(type) || LegacyUtil.isWoodStairs(type)){
|
||||
} else if (LegacyUtil.isWoodPlanks(type) || LegacyUtil.isWoodStairs(type)){
|
||||
Barrel barrel3 = Barrel.getByWood(block);
|
||||
if (barrel3 != null) {
|
||||
if (barrel3.hasPermsDestroy(player)) {
|
||||
@@ -746,7 +749,7 @@ public class P extends JavaPlugin {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package com.dre.brewery.filedata;
|
||||
|
||||
import com.dre.brewery.LegacyUtil;
|
||||
import com.dre.brewery.P;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
@@ -9,8 +13,6 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.dre.brewery.P;
|
||||
|
||||
public class ConfigUpdater {
|
||||
|
||||
private ArrayList<String> config = new ArrayList<>();
|
||||
@@ -47,7 +49,7 @@ public class ConfigUpdater {
|
||||
}
|
||||
|
||||
public void saveConfig() {
|
||||
StringBuilder stringBuilder = new StringBuilder("");
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (String line : config) {
|
||||
stringBuilder.append(line).append("\n");
|
||||
}
|
||||
@@ -82,7 +84,7 @@ public class ConfigUpdater {
|
||||
// ---- Updating to newer Versions ----
|
||||
|
||||
// Update from a specified Config version and language to the newest version
|
||||
public void update(String fromVersion, String lang) {
|
||||
public void update(String fromVersion, boolean oldMat, String lang) {
|
||||
if (fromVersion.equals("0.5")) {
|
||||
// Version 0.5 was only released for de, but with en as setting, so default to de
|
||||
if (!lang.equals("de")) {
|
||||
@@ -144,11 +146,17 @@ public class ConfigUpdater {
|
||||
fromVersion = "1.5";
|
||||
}
|
||||
|
||||
if (fromVersion.equals("1.5")) {
|
||||
fromVersion = "1.6";
|
||||
if (fromVersion.equals("1.5") || fromVersion.equals("1.6")) {
|
||||
update15(P.use1_13, de);
|
||||
fromVersion = "1.7";
|
||||
oldMat = false;
|
||||
}
|
||||
|
||||
if (!fromVersion.equals("1.6")) {
|
||||
if (P.use1_13 && oldMat) {
|
||||
updateMaterials(true);
|
||||
}
|
||||
|
||||
if (!fromVersion.equals("1.7")) {
|
||||
P.p.log(P.p.languageReader.get("Error_ConfigUpdate", fromVersion));
|
||||
return;
|
||||
}
|
||||
@@ -1058,4 +1066,153 @@ public class ConfigUpdater {
|
||||
}
|
||||
|
||||
|
||||
//update from 1.5 to 1.7/mc 1.13
|
||||
private void update15(boolean mc113, boolean langDE) {
|
||||
updateVersion("1.7");
|
||||
updateMaterials(mc113);
|
||||
|
||||
if (langDE) {
|
||||
|
||||
int index = indexOfStart("# ingredients: Auflistung von 'Material oder ID");
|
||||
if (index != -1) {
|
||||
setLine(index, "# ingredients: Auflistung von 'Material,Data/Anzahl'");
|
||||
}
|
||||
|
||||
index = indexOfStart("# (Item-ids anstatt Material");
|
||||
if (index != -1) {
|
||||
setLine(index, "# (Item-ids anstatt Material können in Bukkit nicht mehr benutzt werden)");
|
||||
}
|
||||
|
||||
index = indexOfStart("# [Beispiel] MATERIAL_oder_id: Name");
|
||||
if (index != -1) {
|
||||
setLine(index, "# [Beispiel] MATERIAL: Name nach Gähren");
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
int index = indexOfStart("# ingredients: List of 'material or id");
|
||||
if (index != -1) {
|
||||
setLine(index, "# ingredients: List of 'material,data/amount'");
|
||||
}
|
||||
|
||||
index = indexOfStart("# (Item-ids instead of material are deprecated");
|
||||
if (index != -1) {
|
||||
setLine(index, "# (Item-ids instead of material are not supported by bukkit anymore and will not work)");
|
||||
}
|
||||
|
||||
index = indexOfStart("# [Example] MATERIAL_or_id: Name");
|
||||
if (index != -1) {
|
||||
setLine(index, "# [Example] MATERIAL: Name after cooking");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Update all Materials to Minecraft 1.13
|
||||
private void updateMaterials(boolean toMC113) {
|
||||
int index;
|
||||
if (toMC113) {
|
||||
index = indexOfStart("oldMat:");
|
||||
if (index != -1) {
|
||||
config.remove(index);
|
||||
}
|
||||
} else {
|
||||
index = indexOfStart("version:");
|
||||
if (index != -1) {
|
||||
addLines(index + 1, "oldMat: true");
|
||||
}
|
||||
}
|
||||
|
||||
index = indexOfStart("pukeItem: ");
|
||||
String line;
|
||||
if (index != -1) {
|
||||
line = config.get(index);
|
||||
if (line.length() > 10) {
|
||||
setLine(index, convertMaterial(line, "pukeItem: ", "", toMC113));
|
||||
}
|
||||
}
|
||||
|
||||
index = indexOfStart("drainItems:");
|
||||
if (index != -1) {
|
||||
index++;
|
||||
while (config.get(index).startsWith("-")) {
|
||||
setLine(index, convertMaterial(config.get(index), "- ", "(,.*|)/.*", toMC113));
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
index = indexOfStart("recipes:");
|
||||
if (index != -1) {
|
||||
index++;
|
||||
int endIndex = indexOfStart("useWorldGuard:");
|
||||
if (endIndex < index) {
|
||||
endIndex = indexOfStart("enableChatDistortion:");
|
||||
}
|
||||
if (endIndex < index) {
|
||||
endIndex = indexOfStart("words:");
|
||||
}
|
||||
if (endIndex < index) {
|
||||
endIndex = config.size();
|
||||
}
|
||||
while (index < endIndex) {
|
||||
if (config.get(index).matches("^\\s+ingredients:.*")) {
|
||||
index++;
|
||||
while (config.get(index).matches("^\\s+- .+")) {
|
||||
line = config.get(index);
|
||||
setLine(index, convertMaterial(line, "^\\s+- ", "(,.*|)/.*", toMC113));
|
||||
index++;
|
||||
}
|
||||
} else if (config.get(index).startsWith("cooked:")) {
|
||||
index++;
|
||||
while (config.get(index).matches("^\\s\\s+.+")) {
|
||||
line = config.get(index);
|
||||
setLine(index, convertMaterial(line, "^\\s\\s+", ":.*", toMC113));
|
||||
index++;
|
||||
}
|
||||
}
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String convertMaterial(String line, String regexPrefix, String regexPostfix, boolean toMC113) {
|
||||
if (!toMC113) {
|
||||
return convertIdtoMaterial(line, regexPrefix, regexPostfix);
|
||||
}
|
||||
String mat = line.replaceFirst(regexPrefix, "").replaceFirst(regexPostfix, "");
|
||||
Material material;
|
||||
if (mat.equalsIgnoreCase("LONG_GRASS")) {
|
||||
material = Material.GRASS;
|
||||
} else {
|
||||
material = Material.matchMaterial(mat, true);
|
||||
}
|
||||
|
||||
if (material == null) {
|
||||
return line;
|
||||
}
|
||||
String matnew = material.name();
|
||||
if (!mat.equalsIgnoreCase(matnew)) {
|
||||
return line.replaceAll(mat, matnew);
|
||||
} else {
|
||||
return line;
|
||||
}
|
||||
}
|
||||
|
||||
private String convertIdtoMaterial(String line, String regexPrefix, String regexPostfix) {
|
||||
String idString = line.replaceFirst(regexPrefix, "").replaceFirst(regexPostfix, "");
|
||||
int id = P.p.parseInt(idString);
|
||||
if (id > 0) {
|
||||
Material material = LegacyUtil.getMaterial(id);
|
||||
if (material == null) {
|
||||
P.p.errorLog("Could not find Material with id: " + line);
|
||||
return line;
|
||||
} else {
|
||||
return line.replaceAll(idString, material.name());
|
||||
}
|
||||
} else {
|
||||
return line;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -67,6 +67,7 @@ public class PlayerListener implements Listener {
|
||||
// reset cauldron when refilling to prevent unlimited source of potions
|
||||
} else if (materialInHand == Material.WATER_BUCKET) {
|
||||
if (!P.use1_9) {
|
||||
// We catch >=1.9 cases in the Cauldron Listener
|
||||
if (LegacyUtil.getFillLevel(clickedBlock) == 1) {
|
||||
// will only remove when existing
|
||||
BCauldron.remove(clickedBlock);
|
||||
|
||||
Reference in New Issue
Block a user