Language Updater: Put new lines at the end

This commit is contained in:
Sn0wStorm 2019-12-02 15:56:30 +01:00
parent 4f0b56e2dc
commit 55200608c1
7 changed files with 33 additions and 22 deletions

View File

@ -3,8 +3,8 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.dre</groupId> <groupId>com.dre</groupId>
<artifactId>brewery</artifactId> <artifactId>Brewery</artifactId>
<version>1.8.2</version> <version>1.8.3</version>
<name>Brewery</name> <name>Brewery</name>
<properties> <properties>

View File

@ -1,5 +1,5 @@
name: Brewery name: Brewery
version: 1.8.2 version: 1.8.3
main: com.dre.brewery.P main: com.dre.brewery.P
softdepend: [LWC, LogBlock, WorldGuard, GriefPrevention, Vault, Citadel] softdepend: [LWC, LogBlock, WorldGuard, GriefPrevention, Vault, Citadel]
authors: [Milan Albrecht, Frank Baumann, ProgrammerDan, Daniel Saukel] authors: [Milan Albrecht, Frank Baumann, ProgrammerDan, Daniel Saukel]

View File

@ -37,7 +37,7 @@ import java.util.Map;
public class Barrel implements InventoryHolder { public class Barrel implements InventoryHolder {
public static List<Barrel> barrels = new ArrayList<>(); public static List<Barrel> barrels = new ArrayList<>();
private static int check = 0; private static int check = 0; // Which Barrel was last checked
private final Block spigot; private final Block spigot;
private final BarrelBody body; // The Blocks that make up a Barrel in the World private final BarrelBody body; // The Blocks that make up a Barrel in the World

View File

@ -137,7 +137,6 @@ public class Brew implements Cloneable {
item.setItemMeta(meta); item.setItemMeta(meta);
} else if (brew != null && brew.needsSave) { } else if (brew != null && brew.needsSave) {
// Brew needs saving from a previous format // Brew needs saving from a previous format
P.p.debugLog("Brew needs saving from previous format");
if (P.useNBT) { if (P.useNBT) {
new BrewLore(brew, (PotionMeta) meta).removeLoreData(); new BrewLore(brew, (PotionMeta) meta).removeLoreData();
P.p.debugLog("removed Data from Lore"); P.p.debugLog("removed Data from Lore");
@ -823,13 +822,16 @@ public class Brew implements Cloneable {
XORUnscrambleStream.SuccessType successType = unscrambler.getSuccessType(); XORUnscrambleStream.SuccessType successType = unscrambler.getSuccessType();
if (successType == XORUnscrambleStream.SuccessType.PREV_SEED) { if (successType == XORUnscrambleStream.SuccessType.PREV_SEED) {
P.p.debugLog("Converting Brew from previous Seed");
brew.setNeedsSave(true); brew.setNeedsSave(true);
} else if (BConfig.enableEncode != (successType == XORUnscrambleStream.SuccessType.MAIN_SEED)) { } else if (BConfig.enableEncode != (successType == XORUnscrambleStream.SuccessType.MAIN_SEED)) {
// We have either enabled encode and the data was not encoded or the other way round // We have either enabled encode and the data was not encoded or the other way round
P.p.debugLog("Converting Brew to new encode setting");
brew.setNeedsSave(true); brew.setNeedsSave(true);
} else if (P.useNBT && itemLoadStream instanceof Base91DecoderStream) { } else if (P.useNBT && itemLoadStream instanceof Base91DecoderStream) {
// We are on a version that supports nbt but the data is still in the lore of the item // We are on a version that supports nbt but the data is still in the lore of the item
// Just save it again so that it gets saved to nbt // Just save it again so that it gets saved to nbt
P.p.debugLog("Converting Brew to NBT");
brew.setNeedsSave(true); brew.setNeedsSave(true);
} }
return brew; return brew;

View File

@ -13,6 +13,7 @@ import com.dre.brewery.recipe.BRecipe;
import com.dre.brewery.utility.BUtil; import com.dre.brewery.utility.BUtil;
import com.dre.brewery.utility.LegacyUtil; import com.dre.brewery.utility.LegacyUtil;
import org.apache.commons.lang.math.NumberUtils; import org.apache.commons.lang.math.NumberUtils;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
@ -22,6 +23,9 @@ import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import java.util.HashMap;
import java.util.Map;
public class P extends JavaPlugin { public class P extends JavaPlugin {
public static P p; public static P p;
public static boolean debug; public static boolean debug;
@ -220,7 +224,7 @@ public class P extends JavaPlugin {
} }
private void setupMetrics() { private void setupMetrics() {
/*try { try {
Metrics metrics = new Metrics(this); Metrics metrics = new Metrics(this);
metrics.addCustomChart(new Metrics.SingleLineChart("drunk_players", BPlayer::numDrunkPlayers)); metrics.addCustomChart(new Metrics.SingleLineChart("drunk_players", BPlayer::numDrunkPlayers));
metrics.addCustomChart(new Metrics.SingleLineChart("brews_in_existence", () -> brewsCreated)); metrics.addCustomChart(new Metrics.SingleLineChart("brews_in_existence", () -> brewsCreated));
@ -321,7 +325,7 @@ public class P extends JavaPlugin {
})); }));
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();
}*/ }
} }
public void metricsForCreate(boolean byCmd) { public void metricsForCreate(boolean byCmd) {

View File

@ -1297,9 +1297,11 @@ public class ConfigUpdater {
"enableEncode: false", "enableEncode: false",
"encodeKey: 0"); "encodeKey: 0");
addLinesAt(new String[] {"autosave:", "version:"}, 1, "", if (indexOfStart("debug:") == -1) {
"# Debug Nachrichten im Log anzeigen [false]", addLinesAt(new String[]{"autosave:", "version:"}, 1, "",
"debug: false"); "# Debug Nachrichten im Log anzeigen [false]",
"debug: false");
}
index = indexOfStart("oldMat:") + 1; index = indexOfStart("oldMat:") + 1;
if (index == 0) { if (index == 0) {
@ -1396,9 +1398,11 @@ public class ConfigUpdater {
"enableEncode: false", "enableEncode: false",
"encodeKey: 0"); "encodeKey: 0");
addLinesAt(new String[] {"autosave:", "version:"}, 1, "", if (indexOfStart("debug:") == -1) {
"# Show debug messages in log [false]", addLinesAt(new String[]{"autosave:", "version:"}, 1, "",
"debug: false"); "# Show debug messages in log [false]",
"debug: false");
}
index = indexOfStart("oldMat:") + 1; index = indexOfStart("oldMat:") + 1;
if (index == 0) { if (index == 0) {
@ -1495,9 +1499,11 @@ public class ConfigUpdater {
"enableEncode: false", "enableEncode: false",
"encodeKey: 0"); "encodeKey: 0");
addLinesAt(new String[] {"autosave:", "version:"}, 1, "", if (indexOfStart("debug:") == -1) {
"# Show debug messages in log [false]", addLinesAt(new String[]{"autosave:", "version:"}, 1, "",
"debug: false"); "# Show debug messages in log [false]",
"debug: false");
}
index = indexOfStart("oldMat:") + 1; index = indexOfStart("oldMat:") + 1;
if (index == 0) { if (index == 0) {

View File

@ -38,7 +38,6 @@ public class LanguageReader {
private void check(String defaultPath) { private void check(String defaultPath) {
FileConfiguration defaults = null; FileConfiguration defaults = null;
ConfigUpdater updater = null; ConfigUpdater updater = null;
int i = 0;
String line; String line;
InputStream resource = P.p.getResource(defaultPath); InputStream resource = P.p.getResource(defaultPath);
if (resource == null) return; if (resource == null) return;
@ -46,18 +45,18 @@ public class LanguageReader {
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
int index = line.indexOf(':'); int index = line.indexOf(':');
if (index != -1) { if (index != -1) {
line = line.substring(0, index); String key = line.substring(0, index);
if (!entries.containsKey(line)) { if (!entries.containsKey(key)) {
if (defaults == null) { if (defaults == null) {
defaults = new YamlConfiguration(); defaults = new YamlConfiguration();
defaults.load(new BufferedReader(new InputStreamReader(Objects.requireNonNull(P.p.getResource(defaultPath))))); defaults.load(new BufferedReader(new InputStreamReader(Objects.requireNonNull(P.p.getResource(defaultPath)))));
updater = new ConfigUpdater(file); updater = new ConfigUpdater(file);
updater.appendLines("", "# Updated");
} }
entries.put(line, defaults.getString(line)); entries.put(key, defaults.getString(key));
updater.addLines(i, line + ": '" + entries.get(line) + "'"); updater.appendLines(line);
} }
} }
i++;
} }
if (updater != null) { if (updater != null) {
createBackup(); createBackup();