public void saveSettings() { try { Gson gson = new GsonBuilder().setPrettyPrinting().create(); String data = gson.toJson(this); OutputStream os = new FileOutputStream(new File(plugin.getDataFolder() + File.separator + menuFile)); os.write(data.getBytes()); os.close(); } catch (Exception e) { plugin.getServer().getLogger().warning("Error while saving settings!"); e.printStackTrace(); } }
public void refreshSubServersGUI(boolean clear) { if (subServersInventory == null) subServersInventory = plugin.getServer().createInventory(null, InventoryType.CHEST); if (clear) subServersInventory.clear(); for (MenuItem srv : subServers) { ItemStack is = getItemStackByMenuItem(srv); subServersInventory.setItem(srv.getSlot(), is); } }
public static Settings loadSettings(ServerMenu _plugin) { plugin = _plugin; Settings settings; Gson gson = new Gson(); try (FileReader reader = new FileReader(new File(plugin.getDataFolder() + File.separator + menuFile))) { settings = gson.fromJson(reader, Settings.class); reader.close(); return settings; } catch (Exception e) { settings = new Settings(); settings.resetSettingsToDefault(); settings.saveSettings(); return settings; } }