-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dc5a34b
commit 4594607
Showing
3 changed files
with
106 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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
105 changes: 99 additions & 6 deletions
105
src/main/java/dansplugins/activitytracker/managers/ConfigManager.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,107 @@ | ||
package dansplugins.activitytracker.managers; | ||
|
||
import dansplugins.activitytracker.ActivityTracker; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.configuration.file.FileConfiguration; | ||
|
||
/* | ||
To add a new config option, the following methods must be altered: | ||
- saveMissingConfigDefaultsIfNotPresent | ||
- setConfigOption() | ||
- sendConfigList() | ||
*/ | ||
|
||
public class ConfigManager { | ||
|
||
private static ConfigManager instance; | ||
private boolean altered = false; | ||
|
||
private ConfigManager() { | ||
|
||
} | ||
|
||
public static ConfigManager getInstance() { | ||
// TODO: implement | ||
return null; | ||
if (instance == null) { | ||
instance = new ConfigManager(); | ||
} | ||
return instance; | ||
} | ||
|
||
public void saveMissingConfigDefaultsIfNotPresent() { | ||
// set version | ||
if (!getConfig().isString("version")) { | ||
getConfig().addDefault("version", ActivityTracker.getInstance().getVersion()); | ||
} | ||
else { | ||
getConfig().set("version", ActivityTracker.getInstance().getVersion()); | ||
} | ||
|
||
// save config options | ||
if (!getConfig().isSet("debugMode")) { | ||
getConfig().set("debugMode", false); | ||
} | ||
getConfig().options().copyDefaults(true); | ||
ActivityTracker.getInstance().saveConfig(); | ||
} | ||
|
||
public void setConfigOption(String option, String value, CommandSender sender) { | ||
|
||
if (getConfig().isSet(option)) { | ||
|
||
if (option.equalsIgnoreCase("version")) { | ||
sender.sendMessage(ChatColor.RED + "Cannot set version."); | ||
return; | ||
} else if (option.equalsIgnoreCase("")) { // no integers yet | ||
getConfig().set(option, Integer.parseInt(value)); | ||
sender.sendMessage(ChatColor.GREEN + "Integer set."); | ||
} else if (option.equalsIgnoreCase("debugMode")) { | ||
getConfig().set(option, Boolean.parseBoolean(value)); | ||
sender.sendMessage(ChatColor.GREEN + "Boolean set."); | ||
} else if (option.equalsIgnoreCase("")) { // no doubles yet | ||
getConfig().set(option, Double.parseDouble(value)); | ||
sender.sendMessage(ChatColor.GREEN + "Double set."); | ||
} else { | ||
getConfig().set(option, value); | ||
sender.sendMessage(ChatColor.GREEN + "String set."); | ||
} | ||
|
||
// save | ||
ActivityTracker.getInstance().saveConfig(); | ||
altered = true; | ||
} else { | ||
sender.sendMessage(ChatColor.RED + "That config option wasn't found."); | ||
} | ||
} | ||
|
||
public boolean getBoolean(String debugMode) { | ||
// TODO: implement | ||
return true; | ||
public void sendConfigList(CommandSender sender) { | ||
sender.sendMessage(ChatColor.AQUA + "=== Config List ==="); | ||
sender.sendMessage(ChatColor.AQUA + "version: " + getConfig().getString("version") | ||
+ ", debugMode: " + getString("debugMode")); | ||
} | ||
} | ||
|
||
public boolean hasBeenAltered() { | ||
return altered; | ||
} | ||
|
||
public FileConfiguration getConfig() { | ||
return ActivityTracker.getInstance().getConfig(); | ||
} | ||
|
||
public int getInt(String option) { | ||
return getConfig().getInt(option); | ||
} | ||
|
||
public boolean getBoolean(String option) { | ||
return getConfig().getBoolean(option); | ||
} | ||
|
||
public double getDouble(String option) { | ||
return getConfig().getDouble(option); | ||
} | ||
|
||
public String getString(String option) { | ||
return getConfig().getString(option); | ||
} | ||
|
||
} |
This file contains 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