mirror of
https://github.com/JEFF-Media-GbR/ChestSort.git
synced 2024-06-26 06:35:04 +02:00
fixed automatic config update for disabled-worlds and hotkey settings
This commit is contained in:
parent
8d369c8bd5
commit
8e0827a006
3
CHANGELOG.md
Normal file
3
CHANGELOG.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Changelog
|
||||
## 6.2
|
||||
Automatic config update now correctly updates EVERY config setting, including disabled-worlds and the individual hotkey settings.
|
2
pom.xml
2
pom.xml
|
@ -6,7 +6,7 @@
|
|||
|
||||
<groupId>de.jeffclan</groupId>
|
||||
<artifactId>JeffChestSort</artifactId>
|
||||
<version>6.1</version>
|
||||
<version>6.2</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>JeffChestSort</name>
|
||||
|
|
|
@ -28,9 +28,11 @@ public class JeffChestSortConfigUpdater {
|
|||
|
||||
void updateConfig() {
|
||||
|
||||
if(plugin.debug) plugin.getLogger().info("rename config.yml -> config.old.yml");
|
||||
if (plugin.debug)
|
||||
plugin.getLogger().info("rename config.yml -> config.old.yml");
|
||||
Utils.renameFileInPluginDir(plugin, "config.yml", "config.old.yml");
|
||||
if(plugin.debug) plugin.getLogger().info("saving new config.yml");
|
||||
if (plugin.debug)
|
||||
plugin.getLogger().info("saving new config.yml");
|
||||
plugin.saveDefaultConfig();
|
||||
|
||||
File oldConfigFile = new File(plugin.getDataFolder().getAbsolutePath() + File.separator + "config.old.yml");
|
||||
|
@ -61,7 +63,25 @@ public class JeffChestSortConfigUpdater {
|
|||
ArrayList<String> newLines = new ArrayList<String>();
|
||||
for (String line : linesInDefaultConfig) {
|
||||
String newline = line;
|
||||
if (!line.startsWith("config-version:")) { // dont replace config-version
|
||||
if (line.startsWith("config-version:")) {
|
||||
// dont replace config-version
|
||||
} else if (line.startsWith("disabled-worlds:")) {
|
||||
newline = null;
|
||||
newLines.add("disabled-worlds:");
|
||||
if (plugin.disabledWorlds != null) {
|
||||
for (String disabledWorld : plugin.disabledWorlds) {
|
||||
newLines.add("- " + disabledWorld);
|
||||
}
|
||||
}
|
||||
} else if (line.startsWith("hotkeys:")) {
|
||||
// dont replace hotkeys root part
|
||||
} else if (line.startsWith(" middle-click:")) {
|
||||
newline = " middle-click: " + plugin.getConfig().getBoolean("hotkeys.middle-click");
|
||||
} else if (line.startsWith(" shift-click:")) {
|
||||
newline = " shift-click: " + plugin.getConfig().getBoolean("hotkeys.shift-click");
|
||||
} else if (line.startsWith(" double-click:")) {
|
||||
newline = " double-click: " + plugin.getConfig().getBoolean("hotkeys.double-click");
|
||||
} else {
|
||||
for (String node : oldValues.keySet()) {
|
||||
if (line.startsWith(node + ":")) {
|
||||
|
||||
|
@ -73,12 +93,14 @@ public class JeffChestSortConfigUpdater {
|
|||
quotes = "\"";
|
||||
|
||||
newline = node + ": " + quotes + oldValues.get(node).toString() + quotes;
|
||||
if(plugin.debug) plugin.getLogger().info("Updating config node " + newline);
|
||||
if (plugin.debug)
|
||||
plugin.getLogger().info("Updating config node " + newline);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
newLines.add(newline);
|
||||
if (newline != null)
|
||||
newLines.add(newline);
|
||||
}
|
||||
|
||||
FileWriter fw;
|
||||
|
|
|
@ -61,7 +61,7 @@ public class JeffChestSortPlugin extends JavaPlugin {
|
|||
JeffChestSortListener listener;
|
||||
String sortingMethod;
|
||||
ArrayList<String> disabledWorlds;
|
||||
int currentConfigVersion = 14;
|
||||
int currentConfigVersion = 12;
|
||||
boolean usingMatchingConfig = true;
|
||||
boolean debug = false;
|
||||
boolean verbose = true;
|
||||
|
@ -95,6 +95,17 @@ public class JeffChestSortPlugin extends JavaPlugin {
|
|||
// This saves the config.yml included in the .jar file, but it will not
|
||||
// overwrite an existing config.yml
|
||||
this.saveDefaultConfig();
|
||||
|
||||
// Load disabled-worlds. If it does not exist in the config, it returns null.
|
||||
// That's no problem
|
||||
disabledWorlds = (ArrayList<String>) getConfig().getStringList("disabled-worlds");
|
||||
|
||||
// DEBUG
|
||||
if(disabledWorlds != null ) {
|
||||
for(String disabledWorld : disabledWorlds) {
|
||||
System.out.println("Disabled world: "+disabledWorld);
|
||||
}
|
||||
}
|
||||
|
||||
// Config version prior to 5? Then it must have been generated by ChestSort 1.x
|
||||
if (getConfig().getInt("config-version", 0) < 5) {
|
||||
|
@ -108,16 +119,13 @@ public class JeffChestSortPlugin extends JavaPlugin {
|
|||
configUpdater.updateConfig();
|
||||
configUpdater = null;
|
||||
usingMatchingConfig = true;
|
||||
// createConfig();
|
||||
//createConfig();
|
||||
}
|
||||
|
||||
createDirectories();
|
||||
|
||||
setDefaultConfigValues();
|
||||
|
||||
// Load disabled-worlds. If it does not exist in the config, it returns null.
|
||||
// That's no problem
|
||||
disabledWorlds = (ArrayList<String>) getConfig().getStringList("disabled-worlds");
|
||||
}
|
||||
|
||||
private void setDefaultConfigValues() {
|
||||
|
@ -134,10 +142,7 @@ public class JeffChestSortPlugin extends JavaPlugin {
|
|||
getConfig().addDefault("check-for-updates", "true");
|
||||
getConfig().addDefault("auto-generate-category-files", true);
|
||||
getConfig().addDefault("sort-time", "close");
|
||||
getConfig().addDefault("allow-hotkeys", true);
|
||||
getConfig().addDefault("hotkeys.middle-click", true);
|
||||
getConfig().addDefault("hotkeys.shift-click", true);
|
||||
getConfig().addDefault("hotkeys.double-click", true);
|
||||
getConfig().addDefault("allow-shortcut", true);
|
||||
getConfig().addDefault("verbose", true); // Prints some information in onEnable()
|
||||
}
|
||||
|
||||
|
@ -255,12 +260,7 @@ public class JeffChestSortPlugin extends JavaPlugin {
|
|||
getLogger().info("Sorting enabled by default: " + getConfig().getBoolean("sorting-enabled-by-default"));
|
||||
getLogger().info("Auto generate category files: " + getConfig().getBoolean("auto-generate-category-files"));
|
||||
getLogger().info("Sort time: " + getConfig().getString("sort-time"));
|
||||
getLogger().info("Allow hotkeys " + getConfig().getBoolean("allow-hotkeys"));
|
||||
if (getConfig().getBoolean("allow-hotkeys")) {
|
||||
getLogger().info("|- Middle-Click: " + getConfig().getBoolean("hotkeys.middle-click"));
|
||||
getLogger().info("|- Shift-Click: " + getConfig().getBoolean("hotkeys.shift-click"));
|
||||
getLogger().info("|- Double-Click: " + getConfig().getBoolean("hotkeys.double-click"));
|
||||
}
|
||||
getLogger().info("Allow shortcut: " + getConfig().getString("allow-shortcut"));
|
||||
getLogger().info("Check for updates: " + getConfig().getString("check-for-updates"));
|
||||
getLogger().info("Categories: " + getCategoryList());
|
||||
}
|
||||
|
@ -288,16 +288,15 @@ public class JeffChestSortPlugin extends JavaPlugin {
|
|||
|
||||
private String getCategoryList() {
|
||||
String list = "";
|
||||
JeffChestSortCategory[] categories = organizer.categories
|
||||
.toArray(new JeffChestSortCategory[organizer.categories.size()]);
|
||||
JeffChestSortCategory[] categories = organizer.categories.toArray(new JeffChestSortCategory[organizer.categories.size()]);
|
||||
Arrays.sort(categories);
|
||||
for (JeffChestSortCategory category : categories) {
|
||||
for(JeffChestSortCategory category : categories) {
|
||||
list = list + category.name + " (";
|
||||
list = list + category.typeMatches.length + "), ";
|
||||
}
|
||||
list = list.substring(0, list.length() - 2);
|
||||
list = list.substring(0, list.length()-2);
|
||||
return list;
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void registerMetrics() {
|
||||
|
@ -321,14 +320,6 @@ public class JeffChestSortPlugin extends JavaPlugin {
|
|||
metrics.addCustomChart(new Metrics.SimplePie("sort_time", () -> getConfig().getString("sort-time")));
|
||||
metrics.addCustomChart(new Metrics.SimplePie("auto_generate_category_files",
|
||||
() -> Boolean.toString(getConfig().getBoolean("auto-generate-category-files"))));
|
||||
metrics.addCustomChart(new Metrics.SimplePie("allow_hotkeys",
|
||||
() -> Boolean.toString(getConfig().getBoolean("allow-hotkeys"))));
|
||||
metrics.addCustomChart(new Metrics.SimplePie("hotkey_middle_click",
|
||||
() -> Boolean.toString(getConfig().getBoolean("hotkeys.middle-click"))));
|
||||
metrics.addCustomChart(new Metrics.SimplePie("hotkey_shift_click",
|
||||
() -> Boolean.toString(getConfig().getBoolean("hotkeys.shift-click"))));
|
||||
metrics.addCustomChart(new Metrics.SimplePie("hotkey_double_click",
|
||||
() -> Boolean.toString(getConfig().getBoolean("hotkeys.double-click"))));
|
||||
}
|
||||
|
||||
// Saves default category files, when enabled in the config
|
||||
|
@ -340,9 +331,8 @@ public class JeffChestSortPlugin extends JavaPlugin {
|
|||
}
|
||||
|
||||
// Isn't there a smarter way to find all the 9** files in the .jar?
|
||||
String[] defaultCategories = { "900-weapons", "905-common-tools", "907-other-tools", "909-food",
|
||||
"910-valuables", "920-armor-and-arrows", "930-brewing", "950-redstone", "960-wood", "970-stone",
|
||||
"980-plants", "981-corals", "_ReadMe - Category files" };
|
||||
String[] defaultCategories = { "900-weapons", "905-common-tools", "907-other-tools", "909-food", "910-valuables", "920-armor-and-arrows", "930-brewing",
|
||||
"950-redstone", "960-wood", "970-stone", "980-plants", "981-corals","_ReadMe - Category files" };
|
||||
|
||||
// Delete all files starting with 9..
|
||||
for (File file : new File(getDataFolder().getAbsolutePath() + File.separator + "categories" + File.separator)
|
||||
|
@ -352,7 +342,7 @@ public class JeffChestSortPlugin extends JavaPlugin {
|
|||
return false;
|
||||
}
|
||||
if (fileName.matches("(?i)9\\d\\d.*\\.txt$")) // Category between 900 and 999-... are default
|
||||
// categories
|
||||
// categories
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -363,7 +353,7 @@ public class JeffChestSortPlugin extends JavaPlugin {
|
|||
boolean delete = true;
|
||||
|
||||
for (String name : defaultCategories) {
|
||||
name = name + ".txt";
|
||||
name=name+".txt";
|
||||
if (name.equalsIgnoreCase(file.getName())) {
|
||||
delete = false;
|
||||
break;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
main: de.jeffclan.JeffChestSort.JeffChestSortPlugin
|
||||
name: ChestSort
|
||||
version: 6.1
|
||||
version: 6.2
|
||||
api-version: 1.13
|
||||
description: Allows automatic chest sorting
|
||||
author: mfnalex
|
||||
|
|
Loading…
Reference in New Issue
Block a user