Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.olloth.plugins.flight;
- import java.io.File;
- import java.util.Map;
- //import org.bukkit.util.config.Configuration;
- import org.bukkit.configuration.file.FileConfiguration;
- public class Config {
- private File enableMap;
- private File gravityMap;
- private File directory;
- private File configFile;
- //private Configuration config;
- SpoutFlight plugin;
- public Config(SpoutFlight plugin) {
- this.plugin = plugin;
- init();
- }
- public void init() {
- if (!new File(getDataFolder(), "config.yml").exists()) {
- saveDefaultConfig();
- }
- configFile = getConfig();
- /* directory = plugin.getDataFolder();
- configFile = new File(directory, "config.yml");
- if (!directory.exists())
- directory.mkdir();
- if (!configFile.exists()) {
- try {
- configFile.createNewFile();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- */
- load();
- loadMaps();
- }
- public void load() {
- // config = new Configuration(configFile);
- // config.load();
- getDefaultSpeed();
- getDefaultGravity();
- useOps();
- stopDrifting();
- getMaxSpeed();
- getMaxGravity();
- sendNotifications();
- useOldPermissions();
- // config.save();
- }
- public int getDefaultSpeed() {
- // int speed = config.getInt("default_speed", 5);
- if (speed < 1) {
- speed = 1;
- } else if (speed > getMaxSpeed()) {
- speed = getMaxSpeed();
- }
- return speed;
- }
- public double getDefaultGravity() {
- double gravity = getConfig().getDouble("default_gravity", 1);
- if (gravity < 0) {
- gravity = 0.1D;
- } else if (gravity > getMaxGravity()) {
- gravity = getMaxGravity();
- }
- return gravity;
- }
- public boolean useOps() {
- return config.getBoolean("useOps", true);
- }
- public boolean useOldPermissions() {
- return config.getBoolean("useOldPermissions", false);
- }
- public boolean stopDrifting() {
- return config.getBoolean("stopDrifting", true);
- }
- public int getMaxSpeed() {
- return config.getInt("maxSpeed", 10);
- }
- public double getMaxGravity() {
- return config.getDouble("maxGravity", 2);
- }
- public boolean sendNotifications() {
- return config.getBoolean("sendNotifications", true);
- }
- @SuppressWarnings("unchecked")
- public void loadMaps() {
- enableMap = new File(directory, "flying.bin");
- gravityMap = new File(directory, "gravity.bin");
- if (!enableMap.exists()) {
- saveMap(plugin.getEnabledMap(), enableMap.getPath());
- } else {
- plugin.setEnabledMap((Map<String, Boolean>) HMapSL.load(enableMap.getPath()));
- }
- if (!gravityMap.exists()) {
- saveMap(plugin.getGravityMap(), gravityMap.getPath());
- } else {
- plugin.setGravityMap((Map<String, Double>) HMapSL.load(gravityMap.getPath()));
- }
- }
- public void saveMap(Map<String, ?> map, String path) {
- HMapSL.save(map, path);
- }
- public void saveMaps() {
- saveMap(plugin.getEnabledMap(), enableMap.getPath());
- saveMap(plugin.getGravityMap(), gravityMap.getPath());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment