Skip to content

Commit

Permalink
Added the mainconfig
Browse files Browse the repository at this point in the history
Signed-off-by: Grafe <[email protected]>
  • Loading branch information
Grafe committed May 3, 2013
1 parent 7212ba1 commit 2679c92
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 14 deletions.
1 change: 1 addition & 0 deletions config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MotD: Standard MotD of ManagerXL
41 changes: 41 additions & 0 deletions src/com/dre/managerxl/Config.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
18 changes: 8 additions & 10 deletions src/com/dre/managerxl/P.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
}

Expand All @@ -85,9 +86,6 @@ public void LoadAll(){
} else {
P.p.log(Level.WARNING, getLanguageReader().get("Log_Error_PlayersLoaded"));
}

//MotD
motd = Bukkit.getMotd();
}

//Msg
Expand Down
2 changes: 1 addition & 1 deletion src/com/dre/managerxl/commands/managing/MotD.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
3 changes: 2 additions & 1 deletion src/com/dre/managerxl/commands/managing/MotDSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
}
5 changes: 3 additions & 2 deletions src/com/dre/managerxl/listeners/ServerListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}
}

0 comments on commit 2679c92

Please sign in to comment.