Skip to content

Instantly share code, notes, and snippets.

@TigerReborn
Created May 28, 2014 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TigerReborn/e132eb7cfc43549867c1 to your computer and use it in GitHub Desktop.
Save TigerReborn/e132eb7cfc43549867c1 to your computer and use it in GitHub Desktop.
Singleton example - With example usage for accessing a JavaPlugin/Plugin
import java.io.File;
import java.io.IOException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
public class LivesManager {
private LivesManager(){}
private static LivesManager instance = new LivesManager();
public static LivesManager getInstance() { return instance; }
private File livesFile;
private FileConfiguration lives;
public void init(Plugin p){
livesFile = new File(p.getDataFolder() + File.separator + "lives.yml");
if(!p.getDataFolder().exists()){
p.getDataFolder().mkdirs();
}
if(!livesFile.exists())
try {
livesFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
lives = YamlConfiguration.loadConfiguration(livesFile);
}
public FileConfiguration getLivesConfig(){
return this.lives;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment