public final class ChestSell extends JavaPlugin { private static File file; private final List layoutLore = new ArrayList<>(); public Economy economy = null; private HashMap prices = new HashMap<>(); private HashMap> signs = new HashMap<>(); public void onEnable() { saveDefaultConfig(); this.saveResource("prices.yml", true); try { createOutBin(); } catch (IOException e) { e.printStackTrace(); } setupEconomy(); try { signs = Serializer.readFromFile(file); } catch (ClassNotFoundException | IOException e) { getLogger().log(Level.SEVERE, "No File was found to load data from"); } parseConfigFile("prices"); getServer().getPluginManager().registerEvents(new ChestInteractEvent(this), this); getCommand("chestsell").setExecutor(new ChestSellCommands(this)); } public void onDisable() { getLogger().log(Level.WARNING, "Saving data!"); try { Serializer.writeToFile(signs, file); } catch (IOException e) { e.printStackTrace(); } getLogger().log(Level.WARNING, "Data saved!"); } private void createOutBin() throws IOException { file = new File(getDataFolder(), "signs.bin"); file.createNewFile(); } private boolean setupEconomy() { if (getServer().getPluginManager().getPlugin("Vault") == null) { return false; } RegisteredServiceProvider rsp = getServer().getServicesManager().getRegistration(Economy.class); if (rsp == null) { return false; } economy = rsp.getProvider(); return true; } public void parseConfigFile(String rootKey) { final FileConfiguration config = YamlConfiguration.loadConfiguration(new File(getDataFolder() + "/prices.yml")); config.getConfigurationSection(rootKey).getKeys(false).forEach(sKey -> { String itemReformat = sKey; final double price = config.getDouble(rootKey + "." + sKey); itemReformat = getString(itemReformat, price); this.prices.put(itemReformat, price); }); System.out.println("[ChestSellV2] A total of " + this.prices.size() + " items have been registered."); } @NotNull private String getString(String item, double price) { boolean isItemId = false; try { Integer.parseInt(item); isItemId = true; } catch (NumberFormatException ignored) { } if (isItemId) { try { item = Material.getMaterial(item).toString(); } catch (NullPointerException ignored) { } } item = item.replace("_", "").toLowerCase(); System.out.println("[ChestSellV2] Item " + item + " registered for $" + price); return item; } public HashMap getPrices() { return prices; } public List getLayoutLore() { return layoutLore; } public Economy getEconomy() { return economy; } public HashMap> getSigns() { return signs; } }