Advertisement
kman2010

TDSettings.java

May 5th, 2011
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.02 KB | None | 0 0
  1. package me.kman2010.TD;
  2.  
  3. import java.io.BufferedWriter;
  4. import java.io.File;
  5. import java.io.FileWriter;
  6. import java.io.IOException;
  7. import java.util.Scanner;
  8.  
  9. import org.bukkit.util.config.Configuration;
  10.  
  11. public class TDSettings
  12. {
  13.  
  14.     /**
  15.      * Settings
  16.      */
  17.     public static boolean ban = true;
  18.     public static boolean kick = true;
  19.  
  20.     /**
  21.      * Bukkit config class
  22.      */
  23.     public static Configuration config = null;
  24.  
  25.     /**
  26.      * Load and parse the YAML config file
  27.      */
  28.     public static void load()
  29.     {
  30.         File dataDirectory = new File("plugins/TD");
  31.  
  32.         dataDirectory.mkdirs();
  33.  
  34.         File file = new File("plugins/TD", "config.yml");
  35.  
  36.         if (file.exists())
  37.         {
  38.             config = new Configuration(file);
  39.             config.load();
  40.             setSettings();
  41.             {
  42.             }
  43.         }
  44.         else
  45.         {
  46.             writeFile(file);
  47.             config = new Configuration(file);
  48.             config.load();
  49.         }
  50.         config.load();
  51.         setSettings();
  52.     }
  53.  
  54.     private static void writeFile(File file)
  55.     {
  56.         File temp = new File("plugins/TD", "Temp.yml");
  57.         BufferedWriter bw;
  58.         try
  59.         {
  60.             Configuration tempConfig;
  61.             tempConfig = new Configuration(temp);
  62.             tempConfig.load();
  63.             tempConfig.setProperty("ban", ban);
  64.             tempConfig.setProperty("kick", kick);
  65.  
  66.             tempConfig.save();
  67.  
  68.             Scanner sc = new Scanner(temp);
  69.  
  70.             bw = new BufferedWriter(new FileWriter(file));
  71.             bw.write("#ban controles wheather or not a user is banned when placing tnt. Defaults to " + ban);
  72.             bw.newLine();
  73.             bw.write("#ban controles wheather or not a user is kicked when placing tnt. Defaults to " + kick);
  74.             bw.newLine();
  75.             while (sc.hasNextLine())
  76.             {
  77.                 // String l=sc.nextLine();
  78.                 // System.out.println(l);
  79.                 bw.write(sc.nextLine());
  80.                 bw.newLine();
  81.             }
  82.             bw.close();
  83.             temp.delete();
  84.         }
  85.         catch (IOException e)
  86.         {
  87.             // TODO Auto-generated catch block
  88.             e.printStackTrace();
  89.         }
  90.     }
  91.  
  92.     /**
  93.      * Sets the internal variables
  94.      */
  95.     private static void setSettings()
  96.     {
  97.         ban = config.getBoolean("strike.enabled", ban);
  98.         kick = config.getBoolean("storm.enabled", kick);
  99.     }
  100.  
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement