feat: add config system

This commit is contained in:
Simon Giesel 2020-05-03 20:50:15 +02:00
parent 0bc20e79ad
commit d4f37b6ddf

View file

@ -1,25 +1,48 @@
package de.cliffbreak.varo; package de.cliffbreak.varo;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import org.bukkit.Difficulty; import org.bukkit.Difficulty;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.World.Environment; import org.bukkit.World.Environment;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.configuration.file.YamlConfiguration;
import de.cliffbreak.varo.commands.TestCommand; import de.cliffbreak.varo.commands.TestCommand;
import de.cliffbreak.varo.commands.VaroCommand;
import de.cliffbreak.varo.listeners.ChatListener; import de.cliffbreak.varo.listeners.ChatListener;
import de.cliffbreak.varo.listeners.EntityRegainHealthListener; import de.cliffbreak.varo.listeners.EntityRegainHealthListener;
import de.cliffbreak.varo.listeners.PlayerDeathListener;
import de.cliffbreak.varo.listeners.PlayerJoinQuitListener; import de.cliffbreak.varo.listeners.PlayerJoinQuitListener;
import de.cliffbreak.varo.listeners.PlayerPreLoginListener;
public class Varo extends JavaPlugin { public class Varo extends JavaPlugin {
public File configurationFile = new File("plugins/CliffbreakVaro", "config.yml");
public FileConfiguration config = YamlConfiguration.loadConfiguration(this.configurationFile);
@Override @Override
public void onEnable() { public void onEnable() {
getLogger().info("CliffbreakVaro is starting..."); getLogger().info("CliffbreakVaro is starting...");
getServer().getPluginManager().registerEvents(new ChatListener(), this); // this.config.addDefault("Varo.Start", "TODO: StartDate");
getServer().getPluginManager().registerEvents(new PlayerJoinQuitListener(), this); this.config.addDefault("Varo.Bans", new ArrayList<String>());
getServer().getPluginManager().registerEvents(new EntityRegainHealthListener(), this); this.config.options().copyDefaults(true);
this.saveConfiguration();
// this.config.getStringList(path)
getServer().getPluginManager().registerEvents(new PlayerPreLoginListener(this), this);
getServer().getPluginManager().registerEvents(new PlayerJoinQuitListener(this), this);
getServer().getPluginManager().registerEvents(new ChatListener(), this);
getServer().getPluginManager().registerEvents(new EntityRegainHealthListener(), this);
getServer().getPluginManager().registerEvents(new PlayerDeathListener(this), this);
getCommand("varo").setExecutor(new VaroCommand(this));
getCommand("test").setExecutor(new TestCommand()); getCommand("test").setExecutor(new TestCommand());
for (World world : getServer().getWorlds()) { for (World world : getServer().getWorlds()) {
@ -34,4 +57,13 @@ public class Varo extends JavaPlugin {
public void onDisable() { public void onDisable() {
getLogger().info("Stopping CliffbreakVaro!"); getLogger().info("Stopping CliffbreakVaro!");
} }
public void saveConfiguration() {
try {
getLogger().info("Saving Config...");
this.config.save(this.configurationFile);
} catch (IOException e) {
e.printStackTrace();
}
}
} }