First load should not "update" nonexistent config, just use a default

This commit is contained in:
Jikoo 2018-02-07 18:17:33 -05:00
parent a802769265
commit 9e66885690
3 changed files with 15 additions and 9 deletions

View file

@ -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 // Check if inventory is stored, and if it is, remove it and eject all viewers
if (OpenInv.this.inventories.containsKey(key)) { if (OpenInv.this.inventories.containsKey(key)) {
Inventory inv = OpenInv.this.inventories.remove(key).getBukkitInventory(); Inventory inv = OpenInv.this.inventories.remove(key).getBukkitInventory();
for (HumanEntity entity : inv.getViewers()) { List<HumanEntity> viewers = inv.getViewers();
for (HumanEntity entity : viewers.toArray(new HumanEntity[viewers.size()])) {
entity.closeInventory(); 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 // Check if ender chest is stored, and if it is, remove it and eject all viewers
if (OpenInv.this.enderChests.containsKey(key)) { if (OpenInv.this.enderChests.containsKey(key)) {
Inventory inv = OpenInv.this.enderChests.remove(key).getBukkitInventory(); Inventory inv = OpenInv.this.enderChests.remove(key).getBukkitInventory();
for (HumanEntity entity : inv.getViewers()) { List<HumanEntity> viewers = inv.getViewers();
for (HumanEntity entity : viewers.toArray(new HumanEntity[viewers.size()])) {
entity.closeInventory(); entity.closeInventory();
} }
} }
@ -517,6 +519,7 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
return; return;
} }
this.saveDefaultConfig();
new ConfigUpdater(this).checkForUpdates(); new ConfigUpdater(this).checkForUpdates();
// Register listeners // Register listeners

View file

@ -31,8 +31,6 @@ import org.bukkit.scheduler.BukkitRunnable;
public class ConfigUpdater { public class ConfigUpdater {
private static final int CONFIG_VERSION = 3;
private final OpenInv plugin; private final OpenInv plugin;
public ConfigUpdater(OpenInv plugin) { public ConfigUpdater(OpenInv plugin) {
@ -41,7 +39,7 @@ public class ConfigUpdater {
public void checkForUpdates() { public void checkForUpdates() {
final int version = plugin.getConfig().getInt("config-version", 1); final int version = plugin.getConfig().getInt("config-version", 1);
if (version >= CONFIG_VERSION) { if (version >= plugin.getConfig().getDefaults().getInt("config-version")) {
return; return;
} }
@ -58,12 +56,11 @@ public class ConfigUpdater {
new BukkitRunnable() { new BukkitRunnable() {
@Override @Override
public void run() { public void run() {
switch (version) { if (version < 2) {
case 1:
updateConfig1To2(); updateConfig1To2();
case 2: }
if (version < 3) {
updateConfig2To3(); updateConfig2To3();
break;
} }
new BukkitRunnable() { new BukkitRunnable() {

View file

@ -0,0 +1,6 @@
config-version: 3
notify:
any-chest: true
silent-chest: true
settings:
disable-saving: false