Advertisement
Guest User

SettingsManager.java

a guest
Jul 7th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.40 KB | None | 0 0
  1. package me.greenadine.worldspawns;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5.  
  6. import org.bukkit.Bukkit;
  7. import org.bukkit.ChatColor;
  8. import org.bukkit.configuration.file.FileConfiguration;
  9. import org.bukkit.configuration.file.YamlConfiguration;
  10. import org.bukkit.plugin.Plugin;
  11. import org.bukkit.plugin.PluginDescriptionFile;
  12.  
  13. public class SettingsManager {
  14.  
  15.     private SettingsManager() {
  16.     }
  17.  
  18.     static SettingsManager instance = new SettingsManager();
  19.  
  20.     public static SettingsManager getInstance() {
  21.         return instance;
  22.     }
  23.  
  24.     Plugin p;
  25.    
  26.     FileConfiguration spawns;
  27.     File sfile;
  28.  
  29.     public void setup(Plugin p) {
  30.  
  31.         sfile = new File(p.getDataFolder() + File.separator + "data", "worldspawns.yml");
  32.  
  33.         if (!sfile.exists()) {
  34.             try {
  35.                 sfile.createNewFile();
  36.             } catch (IOException e) {
  37.                 Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could not create worldspawns.yml!");
  38.             }
  39.         }
  40.        
  41.         spawns = YamlConfiguration.loadConfiguration(sfile);
  42.     }
  43.  
  44.     public FileConfiguration getSpawns() {
  45.         return spawns;
  46.     }
  47.  
  48.     public void saveSpawns() {
  49.         try {
  50.             spawns.save(sfile);
  51.         } catch (IOException e) {
  52.             Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could not save worldspawns.yml!");
  53.         }
  54.     }
  55.  
  56.     public void reloadSpawns() {
  57.         spawns = YamlConfiguration.loadConfiguration(sfile);
  58.     }
  59.  
  60.     public PluginDescriptionFile getDesc() {
  61.         return p.getDescription();
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement