Example

If shading MilkGUI, be sure to register your plugin during onEnable:

@Override
public void onEnable() {
    MilkGUI.INSTANCE.register(this);
}

Saving any type of GUI is easy! Here's an example of saving to a Bukkit YAML file:

Plugin plugin; // Instantiate your plugin

public void saveGuiData(final BasicGUI gui, final String fileName) throws Exception {
    final FileConfiguration data = new YamlConfiguration();
    data.options().header("File must stay in UTF-8 encoding!");
    data.set(plugin.getName(), gui);
       
    final File file = new File(plugin.getDataFolder() 
            + File.separator + "gui", fileName);
    try {
        if (file != null) {
            data.save(file);
        }
    } catch (final Exception e) {
        e.printStackTrace();
    }
}

Loading from the same file is a walk in the park:

Plugin plugin; // Instantiate your plugin

public BasicGUI loadGuiData(final String fileName) throws Exception {
    final File file = new File(plugin.getDataFolder() 
            + File.separator + "gui", fileName);
    if (!file.exists()) {
        return null;
    }
    final FileConfiguration data 
            = YamlConfiguration.loadConfiguration(new InputStreamReader(
            new FileInputStream(file), "UTF-8"));
    if (data == null) {
        plugin.getLogger().severe("Data was null for file " + fileName);
        return null;
    }
    return (BasicGUI) data.get(plugin.getName());
}

Last updated