-
-
Save TigerReborn/e132eb7cfc43549867c1 to your computer and use it in GitHub Desktop.
Singleton example - With example usage for accessing a JavaPlugin/Plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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