Advertisement
lipe123

Untitled

Feb 2nd, 2012
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.60 KB | None | 0 0
  1. package me.olloth.plugins.flight;
  2.  
  3. import java.io.File;
  4. import java.util.Map;
  5.  
  6. //import org.bukkit.util.config.Configuration;
  7. import org.bukkit.configuration.file.FileConfiguration;
  8.  
  9. public class Config {
  10.     private File enableMap;
  11.     private File gravityMap;
  12.     private File directory;
  13.     private FileConfiguration configFile;
  14.        
  15.     SpoutFlight plugin;
  16.  
  17.     public Config(SpoutFlight plugin) {
  18.         this.plugin = plugin;
  19.         init();
  20.     }
  21.    
  22.     public void init() {
  23.         if (!new File(plugin.getDataFolder(), "config.yml").exists()) {
  24.            plugin.saveDefaultConfig();
  25.         }
  26.         configFile = plugin.getConfig();
  27.        
  28.         load();
  29.  
  30.         loadMaps();
  31.     }
  32.  
  33.     public void load() {
  34.  
  35.         getDefaultSpeed();
  36.         getDefaultGravity();
  37.         useOps();
  38.         stopDrifting();
  39.         getMaxSpeed();
  40.         getMaxGravity();
  41.         sendNotifications();
  42.         useOldPermissions();
  43.  
  44.     }
  45.  
  46.     public int getDefaultSpeed() {
  47.         int speed  = configFile.getInt("default_speed", 5);
  48.         if (speed < 1) {
  49.             speed = 1;
  50.         } else if (speed > getMaxSpeed()) {
  51.             speed = getMaxSpeed();
  52.         }
  53.  
  54.         return speed;
  55.     }
  56.  
  57.     public double getDefaultGravity() {
  58.         double gravity = configFile.getDouble("default_gravity", 1);
  59.         if (gravity < 0) {
  60.             gravity = 0.1D;
  61.         } else if (gravity > getMaxGravity()) {
  62.             gravity = getMaxGravity();
  63.         }
  64.  
  65.         return gravity;
  66.     }
  67.  
  68.     public boolean useOps() {
  69.         return configFile.getBoolean("useOps", true);
  70.     }
  71.  
  72.     public boolean useOldPermissions() {
  73.         return configFile.getBoolean("useOldPermissions", false);
  74.     }
  75.  
  76.     public boolean stopDrifting() {
  77.         return configFile.getBoolean("stopDrifting", true);
  78.     }
  79.  
  80.     public int getMaxSpeed() {
  81.         return configFile.getInt("maxSpeed", 10);
  82.     }
  83.  
  84.     public double getMaxGravity() {
  85.         return configFile.getDouble("maxGravity", 2);
  86.     }
  87.  
  88.     public boolean sendNotifications() {
  89.         return configFile.getBoolean("sendNotifications", true);
  90.     }
  91.  
  92.     @SuppressWarnings("unchecked")
  93.     public void loadMaps() {
  94.         enableMap = new File(directory, "flying.bin");
  95.  
  96.         gravityMap = new File(directory, "gravity.bin");
  97.         if (!enableMap.exists()) {
  98.             saveMap(plugin.getEnabledMap(), enableMap.getPath());
  99.         } else {
  100.             plugin.setEnabledMap((Map<String, Boolean>) HMapSL.load(enableMap.getPath()));
  101.         }
  102.  
  103.         if (!gravityMap.exists()) {
  104.             saveMap(plugin.getGravityMap(), gravityMap.getPath());
  105.         } else {
  106.             plugin.setGravityMap((Map<String, Double>) HMapSL.load(gravityMap.getPath()));
  107.         }
  108.     }
  109.  
  110.     public void saveMap(Map<String, ?> map, String path) {
  111.         HMapSL.save(map, path);
  112.     }
  113.  
  114.     public void saveMaps() {
  115.         saveMap(plugin.getEnabledMap(), enableMap.getPath());
  116.         saveMap(plugin.getGravityMap(), gravityMap.getPath());
  117.     }
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement