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
if (OpenInv.this.inventories.containsKey(key)) {
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();
}
}
@ -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<HumanEntity> 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

View file

@ -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() {

View file

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