@Override public void onEnable() { plugin = this; directory = plugin.getDataFolder(); pdfFile = plugin.getDescription(); checkEbean(); setupDatabase(); setupFiles(); setupPermissions(); // Smickles thinks this is what we're supposed to do for permissions via // vault setupEconomy(); // Smickles thinks this is what we're supposed to do for economy via vault logger.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " enabled"); }
/** use this in the case that we need to update from the old way of storing data in config.yml */ @SuppressWarnings("deprecation") private void switchToDatabase() { logger.info("[" + pdfFile.getName() + "] Converting flatfile to database..."); // load old config file org.bukkit.configuration.Configuration items = plugin.getConfig(); // populate the database with existing values logger.info("[" + plugin.getDescription().getName() + "] Populating database ..."); for (String item : items.getKeys(false)) { Commodities commodity = plugin .getDatabase() .find(Commodities.class) .where() .ieq("name", item) .ieq("number", items.getString(item + ".number")) .findUnique(); if (commodity == null) { commodity = new Commodities(); commodity.setName(item); for (String key : items.getConfigurationSection(item).getKeys(false)) { String value = items.getString(item + "." + key); if (key.equalsIgnoreCase("value")) commodity.setValue(Double.valueOf(value)); if (key.equalsIgnoreCase("number")) commodity.setNumber(Integer.valueOf(value)); if (key.equalsIgnoreCase("minValue")) commodity.setMinValue(Double.valueOf(value)); if (key.equalsIgnoreCase("maxValue")) commodity.setMaxValue(Double.valueOf(value)); if (key.equalsIgnoreCase("changeRate")) commodity.setChangeRate(Double.valueOf(value)); if (key.equalsIgnoreCase("data")) commodity.setData(Integer.valueOf(value)); if (key.equalsIgnoreCase("spread")) commodity.setSpread(Double.valueOf(value)); } } else { logger.warning( "[" + pdfFile.getName() + "] Duplicate commodity found, that can't be good. You may want to restore the config.yml backup, delete Dynamark.db (or equivilant), then check the file for commodities with the same \"number\", correct the issue, and then restart your server to try again."); continue; } plugin.getDatabase().save(commodity); commodity = null; } // mv config.yml to config.yml.bak logger.info("[" + plugin.getDescription().getName() + "] backing up config.yml..."); File configFlatFile = new File(directory + File.separator + "config.yml"); File backupName = new File(directory + File.separator + "config.yml.bak"); configFlatFile.renameTo(backupName); // rm config.yml.example File toDelete = new File(directory + File.separator + "config.yml.EXAMPLE"); toDelete.delete(); logger.info( "[" + plugin.getDescription().getName() + "] Successfully converted flatfile to database"); }