From 2679c922a0a51128fb8ee81533e09c7f914dcabf Mon Sep 17 00:00:00 2001 From: Grafe Date: Fri, 3 May 2013 13:47:04 +0200 Subject: [PATCH] Added the mainconfig Signed-off-by: Grafe --- config.yml | 1 + src/com/dre/managerxl/Config.java | 41 +++++++++++++++++++ src/com/dre/managerxl/P.java | 18 ++++---- .../dre/managerxl/commands/managing/MotD.java | 2 +- .../managerxl/commands/managing/MotDSet.java | 3 +- .../managerxl/listeners/ServerListener.java | 5 ++- 6 files changed, 56 insertions(+), 14 deletions(-) create mode 100644 config.yml create mode 100644 src/com/dre/managerxl/Config.java diff --git a/config.yml b/config.yml new file mode 100644 index 0000000..a7e82f6 --- /dev/null +++ b/config.yml @@ -0,0 +1 @@ +MotD: Standard MotD of ManagerXL \ No newline at end of file diff --git a/src/com/dre/managerxl/Config.java b/src/com/dre/managerxl/Config.java new file mode 100644 index 0000000..0bdf23c --- /dev/null +++ b/src/com/dre/managerxl/Config.java @@ -0,0 +1,41 @@ +package com.dre.managerxl; + +import java.io.File; +import java.io.IOException; + +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; + +public class Config { + + //File + private File file; + + //MotD + private String motd; + public String getMotD() { return this.motd; } + public void setMotD(String motd) { this.motd = motd; } + + public Config(File file){ + if(!file.exists()){ + P.p.saveDefaultConfig(); + } + + this.file = file; + FileConfiguration ymlFile = YamlConfiguration.loadConfiguration(this.file); + + this.motd = ymlFile.getString("MotD"); + } + + public void saveSingleConfig(String path, Object object){ + FileConfiguration ymlFile = YamlConfiguration.loadConfiguration(this.file); + + ymlFile.set(path, object); + + try { + ymlFile.save(this.file); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/com/dre/managerxl/P.java b/src/com/dre/managerxl/P.java index d22a972..c98ab04 100644 --- a/src/com/dre/managerxl/P.java +++ b/src/com/dre/managerxl/P.java @@ -24,23 +24,24 @@ public class P extends JavaPlugin{ /* Other Plugins */ public DynmapCommonAPI dynmap; + /* Config */ + public Config config; + /* Language Reader */ private LanguageReader languageReader; public LanguageReader getLanguageReader(){ return languageReader; } - /* MotD */ - private String motd = ""; - public String getMotD() { return this.motd; } - public void setMotD(String motd) { this.motd = motd; } - @Override public void onEnable(){ p = this; + //Load Config + this.config = new Config(new File(this.getDataFolder(),"config.yml")); + //Load LanguageReader - languageReader = new LanguageReader(new File(p.getDataFolder(), "languages/default.yml")); + this.languageReader = new LanguageReader(new File(p.getDataFolder(), "languages/default.yml")); //Setup Permissions setupPermissions(); @@ -58,7 +59,7 @@ public void onEnable(){ //Check Dynmap Plugin dynmapPlugin = Bukkit.getPluginManager().getPlugin("dynmap"); if(dynmapPlugin != null){ - dynmap = ((DynmapCommonAPI) dynmapPlugin); + this.dynmap = ((DynmapCommonAPI) dynmapPlugin); } } @@ -85,9 +86,6 @@ public void LoadAll(){ } else { P.p.log(Level.WARNING, getLanguageReader().get("Log_Error_PlayersLoaded")); } - - //MotD - motd = Bukkit.getMotd(); } //Msg diff --git a/src/com/dre/managerxl/commands/managing/MotD.java b/src/com/dre/managerxl/commands/managing/MotD.java index d2644aa..16c500e 100644 --- a/src/com/dre/managerxl/commands/managing/MotD.java +++ b/src/com/dre/managerxl/commands/managing/MotD.java @@ -21,6 +21,6 @@ public MotD(){ @Override public void onExecute(String[] args, CommandSender sender) { - P.p.msg(sender, P.p.getMotD()); + P.p.msg(sender, P.p.config.getMotD()); } } diff --git a/src/com/dre/managerxl/commands/managing/MotDSet.java b/src/com/dre/managerxl/commands/managing/MotDSet.java index df287f4..cf185f0 100644 --- a/src/com/dre/managerxl/commands/managing/MotDSet.java +++ b/src/com/dre/managerxl/commands/managing/MotDSet.java @@ -21,7 +21,8 @@ public MotDSet(){ @Override public void onExecute(String[] args, CommandSender sender) { - P.p.setMotD(P.p.replaceColors(MUtility.parseMessage(args, 0))); + P.p.config.setMotD(MUtility.parseMessage(args, 0)); + P.p.config.saveSingleConfig("MotD", P.p.config.getMotD()); P.p.msg(sender, P.p.getLanguageReader().get("Cmd_MotDSet_Success")); } } diff --git a/src/com/dre/managerxl/listeners/ServerListener.java b/src/com/dre/managerxl/listeners/ServerListener.java index 69837d9..22a8cef 100644 --- a/src/com/dre/managerxl/listeners/ServerListener.java +++ b/src/com/dre/managerxl/listeners/ServerListener.java @@ -10,7 +10,8 @@ public class ServerListener implements Listener{ @EventHandler() public void onServerListPing(ServerListPingEvent event){ - /* Set MotD */ - event.setMotd(P.p.getMotD()); + if(P.p.config.getMotD()!=""){ + event.setMotd(P.p.replaceColors(P.p.config.getMotD())); + } } }