Created
August 13, 2016 22:39
-
-
Save franga2000/258a8a3a2359beaf1de22fd905d38576 to your computer and use it in GitHub Desktop.
Some old config class I wrote that actually works quite nicely
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.franga2000.capturetheflag.config; | |
import java.io.File; | |
import java.io.IOException; | |
import org.bukkit.configuration.InvalidConfigurationException; | |
import org.bukkit.configuration.file.YamlConfiguration; | |
import com.franga2000.capturetheflag.Main; | |
import com.franga2000.capturetheflag.Util; | |
public class Config extends YamlConfiguration { | |
File file; | |
public Config(String filename) { | |
this(new File(Main.instance.getDataFolder(), filename)); | |
} | |
public Config(File file) { | |
this.file = file; | |
try { | |
reload(); | |
} catch (IOException e) { | |
Util.logToConsole("&cThere was an error reading from the configuration file &e" + file.getName() + "&c!"); | |
e.printStackTrace(); | |
} catch (InvalidConfigurationException e) { | |
Util.logToConsole("&cThere was an error in the configuration file &e" + file.getName() + "&c!"); | |
e.printStackTrace(); | |
} | |
} | |
public void reload() throws IOException, InvalidConfigurationException { | |
if (!file.exists()) { | |
file.getParentFile().mkdirs(); | |
Main.instance.saveResource(file.getName(), false); | |
} | |
this.load(file); | |
} | |
public void save() { | |
try { | |
save(file); | |
} catch (IOException e) { | |
Util.logToConsole("&cThere was an error saving the configuration file &e" + file.getName() + "&c!"); | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.franga2000.capturetheflag.config; | |
import org.bukkit.configuration.serialization.ConfigurationSerialization; | |
import com.franga2000.capturetheflag.arena.Arena; | |
public class ConfigManager { | |
public static Config ARENAS; | |
public static Config KITS; | |
public static Config CONFIG; | |
public static Config SIGNS; | |
public static void init() { | |
ConfigurationSerialization.registerClass(SerializableLocation.class, "CTF_Location"); | |
ConfigurationSerialization.registerClass(Arena.class, "CTF_Arena"); | |
ConfigurationSerialization.registerClass(Arena.class, "CTF_Kit"); | |
ConfigurationSerialization.registerClass(ArenaSign.class, "CTF_ArenaSign"); | |
ARENAS = new Config("arenas.yml"); | |
CONFIG = new Config("config.yml"); | |
KITS = new Config("kits.yml"); | |
SIGNS = new Config("signs.yml"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment