Advertisement
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 FileConfiguration configFile;
- SpoutFlight plugin;
- public Config(SpoutFlight plugin) {
- this.plugin = plugin;
- init();
- }
- public void init() {
- if (!new File(plugin.getDataFolder(), "config.yml").exists()) {
- plugin.saveDefaultConfig();
- }
- configFile = plugin.getConfig();
- load();
- loadMaps();
- }
- public void load() {
- getDefaultSpeed();
- getDefaultGravity();
- useOps();
- stopDrifting();
- getMaxSpeed();
- getMaxGravity();
- sendNotifications();
- useOldPermissions();
- }
- public int getDefaultSpeed() {
- int speed = configFile.getInt("default_speed", 5);
- if (speed < 1) {
- speed = 1;
- } else if (speed > getMaxSpeed()) {
- speed = getMaxSpeed();
- }
- return speed;
- }
- public double getDefaultGravity() {
- double gravity = configFile.getDouble("default_gravity", 1);
- if (gravity < 0) {
- gravity = 0.1D;
- } else if (gravity > getMaxGravity()) {
- gravity = getMaxGravity();
- }
- return gravity;
- }
- public boolean useOps() {
- return configFile.getBoolean("useOps", true);
- }
- public boolean useOldPermissions() {
- return configFile.getBoolean("useOldPermissions", false);
- }
- public boolean stopDrifting() {
- return configFile.getBoolean("stopDrifting", true);
- }
- public int getMaxSpeed() {
- return configFile.getInt("maxSpeed", 10);
- }
- public double getMaxGravity() {
- return configFile.getDouble("maxGravity", 2);
- }
- public boolean sendNotifications() {
- return configFile.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
Advertisement