From 9e66885690721d655ba44eb65a09f6e75bea0e9a Mon Sep 17 00:00:00 2001 From: Jikoo Date: Wed, 7 Feb 2018 18:17:33 -0500 Subject: [PATCH] First load should not "update" nonexistent config, just use a default --- .../src/main/java/com/lishid/openinv/OpenInv.java | 7 +++++-- .../java/com/lishid/openinv/util/ConfigUpdater.java | 11 ++++------- plugin/plugin-core/src/main/resources/config.yml | 6 ++++++ 3 files changed, 15 insertions(+), 9 deletions(-) create mode 100644 plugin/plugin-core/src/main/resources/config.yml diff --git a/plugin/plugin-core/src/main/java/com/lishid/openinv/OpenInv.java b/plugin/plugin-core/src/main/java/com/lishid/openinv/OpenInv.java index c3ee807..6c1975d 100644 --- a/plugin/plugin-core/src/main/java/com/lishid/openinv/OpenInv.java +++ b/plugin/plugin-core/src/main/java/com/lishid/openinv/OpenInv.java @@ -95,7 +95,8 @@ public class OpenInv extends JavaPlugin implements IOpenInv { // Check if inventory is stored, and if it is, remove it and eject all viewers if (OpenInv.this.inventories.containsKey(key)) { Inventory inv = OpenInv.this.inventories.remove(key).getBukkitInventory(); - for (HumanEntity entity : inv.getViewers()) { + List viewers = inv.getViewers(); + for (HumanEntity entity : viewers.toArray(new HumanEntity[viewers.size()])) { entity.closeInventory(); } } @@ -103,7 +104,8 @@ public class OpenInv extends JavaPlugin implements IOpenInv { // Check if ender chest is stored, and if it is, remove it and eject all viewers if (OpenInv.this.enderChests.containsKey(key)) { Inventory inv = OpenInv.this.enderChests.remove(key).getBukkitInventory(); - for (HumanEntity entity : inv.getViewers()) { + List viewers = inv.getViewers(); + for (HumanEntity entity : viewers.toArray(new HumanEntity[viewers.size()])) { entity.closeInventory(); } } @@ -517,6 +519,7 @@ public class OpenInv extends JavaPlugin implements IOpenInv { return; } + this.saveDefaultConfig(); new ConfigUpdater(this).checkForUpdates(); // Register listeners diff --git a/plugin/plugin-core/src/main/java/com/lishid/openinv/util/ConfigUpdater.java b/plugin/plugin-core/src/main/java/com/lishid/openinv/util/ConfigUpdater.java index 45aff2b..f917699 100644 --- a/plugin/plugin-core/src/main/java/com/lishid/openinv/util/ConfigUpdater.java +++ b/plugin/plugin-core/src/main/java/com/lishid/openinv/util/ConfigUpdater.java @@ -31,8 +31,6 @@ import org.bukkit.scheduler.BukkitRunnable; public class ConfigUpdater { - private static final int CONFIG_VERSION = 3; - private final OpenInv plugin; public ConfigUpdater(OpenInv plugin) { @@ -41,7 +39,7 @@ public class ConfigUpdater { public void checkForUpdates() { final int version = plugin.getConfig().getInt("config-version", 1); - if (version >= CONFIG_VERSION) { + if (version >= plugin.getConfig().getDefaults().getInt("config-version")) { return; } @@ -58,12 +56,11 @@ public class ConfigUpdater { new BukkitRunnable() { @Override public void run() { - switch (version) { - case 1: + if (version < 2) { updateConfig1To2(); - case 2: + } + if (version < 3) { updateConfig2To3(); - break; } new BukkitRunnable() { diff --git a/plugin/plugin-core/src/main/resources/config.yml b/plugin/plugin-core/src/main/resources/config.yml new file mode 100644 index 0000000..35f924c --- /dev/null +++ b/plugin/plugin-core/src/main/resources/config.yml @@ -0,0 +1,6 @@ +config-version: 3 +notify: + any-chest: true + silent-chest: true +settings: + disable-saving: false