package fr.lightmute;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
public class ConfigTaxi {
private final Plugin plugin;
private YamlConfiguration config;
private File configFile;
private File configFolder;
private final String fileName;
private final String path;
public ConfigTaxi(String file, Plugin plugin) {
this(file, new String("plugins" + File.separator + plugin.getDescription().getName()), plugin);
}
public ConfigTaxi(String file, String path) {
this(file, path, null);
}
public ConfigTaxi(String file, String path, Plugin plugin) {
this.plugin = plugin;
mkdir(path);
mkFile(file);
loadConfig();
this.fileName = file;
this.path = path;
}
public final void mkdir(String path) {
this.configFolder = new File(path);
if (!this.configFolder.exists())
this.configFolder.mkdirs();
}
public final void mkFile(String file) {
this.configFile = new File(this.configFolder, file);
if (!this.configFile.exists())
if (this.plugin != null && this.plugin.getResource(file) != null && !this.configFile.exists()) {
try {
Exception exception2, exception1 = null;
} catch (IOException e) {
e.printStackTrace();
}
} else {
try {
this.configFile.createNewFile();
} catch (IOException iOException) {}
}
}
public final void reload() {
mkdir(this.path);
mkFile(this.fileName);
loadConfig();
}
public final void loadConfig() {
this.config = YamlConfiguration.loadConfiguration(this.configFile);
}
public final void saveConfig() {
try {
this.config.save(this.configFile);
} catch (IOException e) {
System.out.println("La config n'a pas pu sauvegarder correctement");
}
}
public final void reloadConfig() {
loadConfig();
}
public final void set(String path, Object value) {
try {
this.config.set(path, value);
} catch (Exception exception) {}
}
public final void setSave(String path, Object value) {
set(path, value);
saveConfig();
}
public final boolean contains(String path) {
if (this.config.contains(path))
return true;
return false;
}
public final boolean isBoolean(String path) {
try {
Boolean.parseBoolean(this.config.getString(path));
return true;
} catch (Exception e) {
return false;
}
}
public final boolean isInt(String path) {
try {
Integer.parseInt(this.config.getString(path));
return true;
} catch (Exception e) {
return false;
}
}
public final boolean isDouble(String path) {
try {
Double.parseDouble(this.config.getString(path));
return true;
} catch (Exception e) {
return false;
}
}
public final boolean isLong(String path) {
try {
Long.parseLong(this.config.getString(path));
return true;
} catch (Exception e) {
return false;
}
}
public final boolean isFloat(String path) {
try {
Float.parseFloat(this.config.getString(path));
return true;
} catch (Exception e) {
return false;
}
}
public final boolean isList(String path) {
return this.config.isList(path);
}
public final boolean isString(String path) {
try {
String output = this.config.getString(path);
return !(output == null);
} catch (NullPointerException e) {
return false;
}
}
public final boolean getBoolean(String path) {
if (!isBoolean(path))
throw new IllegalArgumentException("The specified path is not a boolean");
return Boolean.valueOf(this.config.getString(path)).booleanValue();
}
public final int getInt(String path) {
if (!isInt(path))
throw new IllegalArgumentException("The specified path is not a integer");
return Integer.valueOf(this.config.getString(path)).intValue();
}
public final Double getDouble(String path) {
if (!isDouble(path))
throw new IllegalArgumentException("The specified path is not a double");
return Double.valueOf(this.config.getString(path));
}
public final long getLong(String path) {
if (!isLong(path))
throw new IllegalArgumentException("The specified path is not a long");
return Long.valueOf(this.config.getString(path)).longValue();
}
public final float getFloat(String path) {
if (!isFloat(path))
throw new IllegalArgumentException("The specified path is not a float");
return Float.valueOf(this.config.getString(path)).floatValue();
}
public final List<String> getStringList(String path) {
if (!isList(path))
throw new IllegalArgumentException("The specified path is not a String list");
return this.config.getStringList(path);
}
public final List<?> getList(String path) {
if (!isList(path))
throw new IllegalArgumentException("The specified path is not a List");
return this.config.getList(path);
}
public String getString(String path) {
if (!isString(path))
throw new IllegalArgumentException("The specified path is not a String");
return String.valueOf(this.config.getString(path));
}
public final Object get(String path) {
return this.config.get(path);
}
public final boolean isNull(String path) {
if (isString(path) && !this.config.getString(path).equalsIgnoreCase(""))
return false;
return true;
}
public final YamlConfiguration toConfigurationSection() {
return this.config;
}
public final String getName() {
return this.fileName;
}
}