*
* loads from Jobs/generalConfig.yml
*/
private synchronized void loadGeneralSettings(){
File f = new File(plugin.getDataFolder(), "generalConfig.yml");
YamlConfiguration config = YamlConfiguration.loadConfiguration(f);
CommentedYamlConfiguration writer = new CommentedYamlConfiguration();
StringBuilder header = new StringBuilder();
header.append("General configuration.");
header.append(System.getProperty("line.separator"));
header.append(" The general configuration for the jobs plugin mostly includes how often the plugin");
header.append(System.getProperty("line.separator"));
header.append("saves user data (when the user is in the game), the storage method, whether");
header.append(System.getProperty("line.separator"));
header.append("to broadcast a message to the server when a user goes up a skill level.");
header.append(System.getProperty("line.separator"));
header.append(" It also allows admins to set the maximum number of jobs a player can have at");
header.append(System.getProperty("line.separator"));
header.append("any one time.");
header.append(System.getProperty("line.separator"));
config.options().copyDefaults(true);
writer.options().header(header.toString());
writer.addComment("locale-language", "Default language. Use your languages two digit ISO 639-1 code, and optionally followed by the ISO-3166-1 country code.",
"Example: en, en_US");
config.addDefault("locale-language", Locale.getDefault().getLanguage());
writer.addComment("storage-method", "storage method, can be MySQL, sqlite");
config.addDefault("storage-method", "sqlite");
writer.addComment("mysql-username", "Requires Mysql.");
config.addDefault("mysql-username", "root");
config.addDefault("mysql-password", "");
config.addDefault("mysql-hostname", "localhost:3306");
config.addDefault("mysql-database", "minecraft");
config.addDefault("mysql-table-prefix", "jobs_");
writer.addComment("save-period", "How often in minutes you want it to save. This must be a non-zero number");
config.addDefault("save-period", 10);
writer.addComment("save-on-disconnect",
"Should player data be saved on disconnect?",
"Player data is always periodically auto-saved and autosaved during a clean shutdown.",
"Only enable this if you have a multi-server setup, or have a really good reason for enabling this.",
"Turning this on will decrease database performance.");
config.addDefault("save-on-disconnect", false);
writer.addComment("broadcast-on-skill-up", "Do all players get a message when somone goes up a skill level?");
config.addDefault("broadcast-on-skill-up", false);
writer.addComment("broadcast-on-level-up", "Do all players get a message when somone goes up a level?");
config.addDefault("broadcast-on-level-up", false);
writer.addComment("max-jobs",
"Maximum number of jobs a player can join.",
"Use 0 for no maximum"
);
config.addDefault("max-jobs", 3);
writer.addComment("hide-jobs-without-permission", "Hide jobs from player if they lack the permission to join the job");
config.addDefault("hide-jobs-without-permission", false);
writer.addComment("enable-pay-near-spawner", "option to allow payment to be made when killing mobs from a spawner");
config.addDefault("enable-pay-near-spawner", false);
writer.addComment("enable-pay-creative", "option to allow payment to be made in creative mode");
config.addDefault("enable-pay-creative", false);
writer.addComment("add-xp-player", "Adds the Jobs xp recieved to the player's Minecraft XP bar");
config.addDefault("add-xp-player", false);
writer.addComment("modify-chat", "Modifys chat to add chat titles. If you're using a chat manager, you may add the tag {jobs} to your chat format and disable this.");
config.addDefault("modify-chat", true);
writer.addComment("economy-batch-delay", "Changes how often, in seconds, players are paid out. Default is 5 seconds.",
"Setting this too low may cause tick lag. Increase this to improve economy performance (at the cost of delays in payment)");
config.addDefault("economy-batch-delay", 5);
writer.addComment("economy-async", "Enable async economy calls.",
"Only enable if your economy plugin is thread safe, use with EXTREME caution.");
config.addDefault("economy-async", false);
String storageMethod = config.getString("storage-method");
if(storageMethod.equalsIgnoreCase("mysql")) {
String legacyUrl = config.getString("mysql-url");
if (legacyUrl != null) {
String jdbcString = "jdbc:mysql://";
if (legacyUrl.toLowerCase().startsWith(jdbcString)) {
legacyUrl = legacyUrl.substring(jdbcString.length());
String[] parts = legacyUrl.split("/");
if (parts.length >= 2) {
config.set("mysql-hostname", parts[0]);
config.set("mysql-database", parts[1]);
}
}
}
String username = config.getString("mysql-username");
if(username == null) {
Jobs.getPluginLogger().severe("mysql-username property invalid or missing");
}
String password = config.getString("mysql-password");
String hostname = config.getString("mysql-hostname");
String database = config.getString("mysql-database");
String prefix = config.getString("mysql-table-prefix");
if (plugin.isEnabled())
Jobs.setDAO(JobsDAOMySQL.initialize(hostname, database, username, password, prefix));
} else if(storageMethod.equalsIgnoreCase("h2")) {
File h2jar = new File(plugin.getDataFolder(), "h2.jar");
Jobs.getPluginLogger().warning("H2 database no longer supported! Converting to SQLite.");
if (!h2jar.exists()) {
Jobs.getPluginLogger().info("H2 library not found, downloading...");
try {
FileDownloader.downloadFile(new URL("http://dev.bukkit.org/media/files/692/88/h2-1.3.171.jar"), h2jar);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
Jobs.getPluginLogger().severe("Could not download database library!");
}
}
if (plugin.isEnabled()) {
try {
Jobs.getJobsClassloader().addFile(h2jar);
} catch (IOException e) {
Jobs.getPluginLogger().severe("Could not load database library!");
}
if (plugin.isEnabled()) {
try {
JobsDAOH2.convertToSQLite();
Jobs.setDAO(JobsDAOSQLite.initialize());
config.set("storage-method", "sqlite");
} catch (SQLException e) {
Jobs.getPluginLogger().severe("Error when converting from H2 to SQLite!");
e.printStackTrace();
}
}
}
} else if(storageMethod.equalsIgnoreCase("sqlite")) {
Jobs.setDAO(JobsDAOSQLite.initialize());
} else {
Jobs.getPluginLogger().warning("Invalid storage method! Changing method to sqlite!");
config.set("storage-method", "sqlite");
Jobs.setDAO(JobsDAOSQLite.initialize());
}
if (config.getInt("save-period") <= 0) {
Jobs.getPluginLogger().severe("Save period must be greater than 0! Defaulting to 10 minutes!");
config.set("save-period", 10);
}
String localeString = config.getString("locale-language");
try {
int i = localeString.indexOf('_');
if (i == -1) {
locale = new Locale(localeString);
} else {
locale = new Locale(localeString.substring(0, i), localeString.substring(i+1));
}
} catch (IllegalArgumentException e) {
locale = Locale.getDefault();
Jobs.getPluginLogger().warning("Invalid locale \""+localeString+"\" defaulting to "+locale.getLanguage());
}
savePeriod = config.getInt("save-period");
economyAsync = config.getBoolean("economy-async");
isBroadcastingSkillups = config.getBoolean("broadcast-on-skill-up");
isBroadcastingLevelups = config.getBoolean("broadcast-on-level-up");
payInCreative = config.getBoolean("enable-pay-creative");
addXpPlayer = config.getBoolean("add-xp-player");
hideJobsWithoutPermission = config.getBoolean("hide-jobs-without-permission");
maxJobs = config.getInt("max-jobs");
payNearSpawner = config.getBoolean("enable-pay-near-spawner");
modifyChat = config.getBoolean("modify-chat");
economyBatchDelay = config.getInt("economy-batch-delay");
saveOnDisconnect = config.getBoolean("save-on-disconnect");
// Make sure we're only copying settings we care about
copySetting(config, writer, "locale-language");
copySetting(config, writer, "storage-method");
copySetting(config, writer, "mysql-username");