1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-12-01 15:03:36 +01:00

Lets use ConfigReader

Lets properly transition to new mysql setup format by keeping old
entries
Better checks for existing mysql tables
This commit is contained in:
Zrips 2019-01-30 15:28:17 +02:00
parent c341d43892
commit 95f922e151
8 changed files with 294 additions and 367 deletions

View File

@ -313,6 +313,11 @@ public class ConfigReader extends YamlConfiguration {
return config.getInt(path); return config.getInt(path);
} }
public int get(String path, Integer boo) {
path = process(path, boo);
return config.getInt(path);
}
public List<Integer> getIntList(String path, List<Integer> list) { public List<Integer> getIntList(String path, List<Integer> list) {
path = process(path, list); path = process(path, list);
return config.getIntegerList(path); return config.getIntegerList(path);

View File

@ -18,8 +18,6 @@
package com.gamingmesh.jobs.config; package com.gamingmesh.jobs.config;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
@ -28,19 +26,18 @@ import java.util.Locale;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.CMILib.ConfigReader;
import com.gamingmesh.jobs.CMILib.ItemManager.CMIMaterial; import com.gamingmesh.jobs.CMILib.ItemManager.CMIMaterial;
import com.gamingmesh.jobs.resources.jfep.Parser; import com.gamingmesh.jobs.CMILib.VersionChecker.Version;
import com.gamingmesh.jobs.container.CurrencyLimit; import com.gamingmesh.jobs.container.CurrencyLimit;
import com.gamingmesh.jobs.container.CurrencyType; import com.gamingmesh.jobs.container.CurrencyType;
import com.gamingmesh.jobs.container.LocaleReader;
import com.gamingmesh.jobs.container.Schedule; import com.gamingmesh.jobs.container.Schedule;
import com.gamingmesh.jobs.CMILib.VersionChecker.Version; import com.gamingmesh.jobs.resources.jfep.Parser;
public class GeneralConfigManager { public class GeneralConfigManager {
private Jobs plugin; private Jobs plugin;
@ -74,6 +71,7 @@ public class GeneralConfigManager {
private int ResetTimeHour; private int ResetTimeHour;
private int ResetTimeMinute; private int ResetTimeMinute;
private ConfigReader c = null;
// Limits // Limits
private HashMap<CurrencyType, CurrencyLimit> currencyLimitUse = new HashMap<>(); private HashMap<CurrencyType, CurrencyLimit> currencyLimitUse = new HashMap<>();
@ -374,30 +372,23 @@ public class GeneralConfigManager {
* loads from Jobs/generalConfig.yml * loads from Jobs/generalConfig.yml
*/ */
private synchronized void loadGeneralSettings() { private synchronized void loadGeneralSettings() {
File f = new File(Jobs.getFolder(), "generalConfig.yml"); try {
YamlConfiguration conf = YamlConfiguration.loadConfiguration(f); c = new ConfigReader("generalConfig.yml");
CommentedYamlConfiguration write = new CommentedYamlConfiguration(); } catch (Exception e1) {
LocaleReader c = new LocaleReader(conf, write); e1.printStackTrace();
}
if (c == null){
return;
}
c.header(Arrays.asList("General configuration.",
" The general configuration for the jobs plugin mostly includes how often the plugin",
" saves user data (when the user is in the game), the storage method, whether",
" to broadcast a message to the server when a user goes up a skill level.",
" It also allows admins to set the maximum number of jobs a player can have at",
" any one time."));
c.copyDefaults(true);
c.addComment("locale-language", "Default language.", "Example: en, ru", "File in locale folder with same name should exist. Example: messages_ru.yml");
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"));
c.getC().options().copyDefaults(true);
c.getW().options().header(header.toString());
c.getW().addComment("locale-language", "Default language.", "Example: en, ru", "File in locale folder with same name should exist. Example: messages_ru.yml");
localeString = c.get("locale-language", "en"); localeString = c.get("locale-language", "en");
try { try {
int i = localeString.indexOf('_'); int i = localeString.indexOf('_');
@ -411,7 +402,7 @@ public class GeneralConfigManager {
Jobs.getPluginLogger().warning("Invalid locale \"" + localeString + "\" defaulting to " + locale.getLanguage()); Jobs.getPluginLogger().warning("Invalid locale \"" + localeString + "\" defaulting to " + locale.getLanguage());
} }
Jobs.getDBManager().start(c); Jobs.getDBManager().start();
// c.getW().addComment("storage-method", "storage method, can be MySQL, sqlite"); // c.getW().addComment("storage-method", "storage method, can be MySQL, sqlite");
// storageMethod = c.get("storage-method", "sqlite"); // storageMethod = c.get("storage-method", "sqlite");
@ -432,149 +423,149 @@ public class GeneralConfigManager {
// c.get("mysql-database", "minecraft"); // c.get("mysql-database", "minecraft");
// c.get("mysql-table-prefix", "jobs_"); // c.get("mysql-table-prefix", "jobs_");
c.getW().addComment("save-period", "How often in minutes you want it to save. This must be a non-zero number"); c.addComment("save-period", "How often in minutes you want it to save. This must be a non-zero number");
c.get("save-period", 10); c.get("save-period", 10);
if (c.getW().getInt("save-period") <= 0) { if (c.getInt("save-period") <= 0) {
Jobs.getPluginLogger().severe("Save period must be greater than 0! Defaulting to 10 minutes!"); Jobs.getPluginLogger().severe("Save period must be greater than 0! Defaulting to 10 minutes!");
c.getW().set("save-period", 10); c.set("save-period", 10);
} }
savePeriod = c.getW().getInt("save-period"); savePeriod = c.getInt("save-period");
c.getW().addComment("save-on-disconnect", "Should player data be saved on disconnect?", c.addComment("save-on-disconnect", "Should player data be saved on disconnect?",
"Player data is always periodically auto-saved and autosaved during a clean shutdown.", "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."); "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.");
saveOnDisconnect = c.get("save-on-disconnect", false); saveOnDisconnect = c.get("save-on-disconnect", false);
c.getW().addComment("selectionTool", "Tool used when selecting bounds for restricted area"); c.addComment("selectionTool", "Tool used when selecting bounds for restricted area");
if (CMIMaterial.get(getSelectionTooldID) == null) if (CMIMaterial.get(getSelectionTooldID) == null)
getSelectionTooldID = 294; getSelectionTooldID = 294;
else else
getSelectionTooldID = c.get("selectionTool", 294); getSelectionTooldID = c.get("selectionTool", 294);
c.getW().addComment("MultiServerCompatability", "Enable if you are using one data base for multiple servers across bungee network", c.addComment("MultiServerCompatability", "Enable if you are using one data base for multiple servers across bungee network",
"This will force to load players data every time he is logging in to have most up to date data instead of having preloaded data", "This will force to load players data every time he is logging in to have most up to date data instead of having preloaded data",
"This will enable automatically save-on-disconnect feature"); "This will enable automatically save-on-disconnect feature");
MultiServerCompatability = c.get("MultiServerCompatability", false); MultiServerCompatability = c.get("MultiServerCompatability", false);
if (MultiServerCompatability) if (MultiServerCompatability)
saveOnDisconnect = true; saveOnDisconnect = true;
c.getW().addComment("Optimizations.NewVersion", c.addComment("Optimizations.NewVersion",
"When set to true staff will be informed about new Jobs plugin version", "You need to have jobs.versioncheck permission node"); "When set to true staff will be informed about new Jobs plugin version", "You need to have jobs.versioncheck permission node");
ShowNewVersion = c.get("Optimizations.NewVersion", true); ShowNewVersion = c.get("Optimizations.NewVersion", true);
c.getW().addComment("Optimizations.DecimalPlaces.Money", c.addComment("Optimizations.DecimalPlaces.Money",
"Decimal places to be shown"); "Decimal places to be shown");
DecimalPlacesMoney = "%." + c.get("Optimizations.DecimalPlaces.Money", 2) + "f"; DecimalPlacesMoney = "%." + c.get("Optimizations.DecimalPlaces.Money", 2) + "f";
DecimalPlacesExp = "%." + c.get("Optimizations.DecimalPlaces.Exp", 2) + "f"; DecimalPlacesExp = "%." + c.get("Optimizations.DecimalPlaces.Exp", 2) + "f";
DecimalPlacesPoints = "%." + c.get("Optimizations.DecimalPlaces.Points", 2) + "f"; DecimalPlacesPoints = "%." + c.get("Optimizations.DecimalPlaces.Points", 2) + "f";
c.getW().addComment("Optimizations.DBCleaning.Jobs.Use", c.addComment("Optimizations.DBCleaning.Jobs.Use",
"Warning!!! before enabling this feature, please make data base backup, just in case there will be some issues with data base cleaning", "Warning!!! before enabling this feature, please make data base backup, just in case there will be some issues with data base cleaning",
"When set to true, jobs data base will be cleaned on each startup to avoid having not used jobs", "When set to true, jobs data base will be cleaned on each startup to avoid having not used jobs",
"keep in mind that this will only clean actual jobs, but not recorded players"); "keep in mind that this will only clean actual jobs, but not recorded players");
DBCleaningJobsUse = c.get("Optimizations.DBCleaning.Jobs.Use", false); DBCleaningJobsUse = c.get("Optimizations.DBCleaning.Jobs.Use", false);
c.getW().addComment("Optimizations.DBCleaning.Jobs.Level", "Any one who has jobs level equal or less then set, hies job will be removed from data base"); c.addComment("Optimizations.DBCleaning.Jobs.Level", "Any one who has jobs level equal or less then set, hies job will be removed from data base");
DBCleaningJobsLvl = c.get("Optimizations.DBCleaning.Jobs.Level", 1); DBCleaningJobsLvl = c.get("Optimizations.DBCleaning.Jobs.Level", 1);
c.getW().addComment("Optimizations.DBCleaning.Users.Use", c.addComment("Optimizations.DBCleaning.Users.Use",
"Warning!!! before enabling this feature, please make data base backup, just in case there will be some issues with data base cleaning", "Warning!!! before enabling this feature, please make data base backup, just in case there will be some issues with data base cleaning",
"When set to true, data base will be cleaned on each startup from user data to avoid having old player data"); "When set to true, data base will be cleaned on each startup from user data to avoid having old player data");
DBCleaningUsersUse = c.get("Optimizations.DBCleaning.Users.Use", false); DBCleaningUsersUse = c.get("Optimizations.DBCleaning.Users.Use", false);
c.getW().addComment("Optimizations.DBCleaning.Users.Days", "Any one who not played for defined amount of days, will be removed from data base"); c.addComment("Optimizations.DBCleaning.Users.Days", "Any one who not played for defined amount of days, will be removed from data base");
DBCleaningUsersDays = c.get("Optimizations.DBCleaning.Users.Days", 60); DBCleaningUsersDays = c.get("Optimizations.DBCleaning.Users.Days", 60);
c.getW().addComment("Optimizations.AutoJobJoin.Use", "Use or not auto join jobs feature", c.addComment("Optimizations.AutoJobJoin.Use", "Use or not auto join jobs feature",
"If you are not using auto join feature, keep it disabled"); "If you are not using auto join feature, keep it disabled");
AutoJobJoinUse = c.get("Optimizations.AutoJobJoin.Use", false); AutoJobJoinUse = c.get("Optimizations.AutoJobJoin.Use", false);
c.getW().addComment("Optimizations.AutoJobJoin.Delay", "Delay in seconds to perform auto join job if used after player joins server", c.addComment("Optimizations.AutoJobJoin.Delay", "Delay in seconds to perform auto join job if used after player joins server",
"If you using offline server, try to keep it slightly more than your login plugin gives time to enter password", "If you using offline server, try to keep it slightly more than your login plugin gives time to enter password",
"For player to auto join job add permission node jobs.autojoin.[jobname]", "For player to auto join job add permission node jobs.autojoin.[jobname]",
"Op players are ignored"); "Op players are ignored");
AutoJobJoinDelay = c.get("Optimizations.AutoJobJoin.Delay", 15); AutoJobJoinDelay = c.get("Optimizations.AutoJobJoin.Delay", 15);
c.getW().addComment("Optimizations.AllowDelevel", "When set to true players who gets negative experience can delevel job up to level 1", c.addComment("Optimizations.AllowDelevel", "When set to true players who gets negative experience can delevel job up to level 1",
"ATTENTION! Set it to true only if you certain that commands performed on level up will not cause issues if player start level and delevel in a row."); "ATTENTION! Set it to true only if you certain that commands performed on level up will not cause issues if player start level and delevel in a row.");
AllowDelevel = c.get("Optimizations.AllowDelevel", false); AllowDelevel = c.get("Optimizations.AllowDelevel", false);
// c.getW().addComment("Optimizations.UseLocalOfflinePlayersData", "With this set to true, offline player data will be taken from local player data files", // c.addComment("Optimizations.UseLocalOfflinePlayersData", "With this set to true, offline player data will be taken from local player data files",
// "This will eliminate small lag spikes when request is being send to mojangs servers for offline players data", // "This will eliminate small lag spikes when request is being send to mojangs servers for offline players data",
// "Theroticali this should work without issues, but if you havving some, just disable", // "Theroticali this should work without issues, but if you havving some, just disable",
// "But then you can feal some small (100-200ms) lag spikes while performings some jobs commands"); // "But then you can feal some small (100-200ms) lag spikes while performings some jobs commands");
// LocalOfflinePlayersData = c.get("Optimizations.UseLocalOfflinePlayersData", true); // LocalOfflinePlayersData = c.get("Optimizations.UseLocalOfflinePlayersData", true);
c.getW().addComment("Optimizations.DisabledWorlds.Use", "By setting this to true, Jobs plugin will be disabled in given worlds", c.addComment("Optimizations.DisabledWorlds.Use", "By setting this to true, Jobs plugin will be disabled in given worlds",
"Only commands can be performed from disabled worlds with jobs.disabledworld.commands permission node"); "Only commands can be performed from disabled worlds with jobs.disabledworld.commands permission node");
DisabledWorldsUse = c.get("Optimizations.DisabledWorlds.Use", false); DisabledWorldsUse = c.get("Optimizations.DisabledWorlds.Use", false);
DisabledWorldsList = c.getStringList("Optimizations.DisabledWorlds.List", Arrays.asList(Bukkit.getWorlds().get(0).getName())); DisabledWorldsList = c.get("Optimizations.DisabledWorlds.List", Arrays.asList(Bukkit.getWorlds().get(0).getName()));
// c.getW().addComment("Optimizations.Purge.Use", "By setting this to true, Jobs plugin will clean data base on startup from all jobs with level 1 and at 0 exp"); // c.addComment("Optimizations.Purge.Use", "By setting this to true, Jobs plugin will clean data base on startup from all jobs with level 1 and at 0 exp");
// PurgeUse = c.get("Optimizations.Purge.Use", false); // PurgeUse = c.get("Optimizations.Purge.Use", false);
c.getW().addComment("Logging.Use", "With this set to true all players jobs actions will be logged to database for easy to see statistics", c.addComment("Logging.Use", "With this set to true all players jobs actions will be logged to database for easy to see statistics",
"This is still in development and in feature it will expand"); "This is still in development and in feature it will expand");
LoggingUse = c.get("Logging.Use", false); LoggingUse = c.get("Logging.Use", false);
c.getW().addComment("broadcast.on-skill-up.use", "Do all players get a message when someone goes up a skill level?"); c.addComment("broadcast.on-skill-up.use", "Do all players get a message when someone goes up a skill level?");
isBroadcastingSkillups = c.get("broadcast.on-skill-up.use", false); isBroadcastingSkillups = c.get("broadcast.on-skill-up.use", false);
c.getW().addComment("broadcast.on-level-up.use", "Do all players get a message when someone goes up a level?"); c.addComment("broadcast.on-level-up.use", "Do all players get a message when someone goes up a level?");
isBroadcastingLevelups = c.get("broadcast.on-level-up.use", false); isBroadcastingLevelups = c.get("broadcast.on-level-up.use", false);
c.getW().addComment("broadcast.on-level-up.levels", "For what levels you want to broadcast message? Keep it at 0 if you want for all of them"); c.addComment("broadcast.on-level-up.levels", "For what levels you want to broadcast message? Keep it at 0 if you want for all of them");
BroadcastingLevelUpLevels = c.getIntList("broadcast.on-level-up.levels", Arrays.asList(0)); BroadcastingLevelUpLevels = c.getIntList("broadcast.on-level-up.levels", Arrays.asList(0));
c.getW().addComment("DailyQuests.ResetTime", "Defines time in 24hour format when we want to give out new daily quests", c.addComment("DailyQuests.ResetTime", "Defines time in 24hour format when we want to give out new daily quests",
"Any daily quests given before reset will be invalid and new ones will be given out"); "Any daily quests given before reset will be invalid and new ones will be given out");
ResetTimeHour = c.get("DailyQuests.ResetTime.Hour", 4); ResetTimeHour = c.get("DailyQuests.ResetTime.Hour", 4);
ResetTimeMinute = c.get("DailyQuests.ResetTime.Minute", 0); ResetTimeMinute = c.get("DailyQuests.ResetTime.Minute", 0);
c.getW().addComment("max-jobs", "Maximum number of jobs a player can join.", "Use 0 for no maximum", "Keep in mind that jobs.max.[amount] will bypass this setting"); c.addComment("max-jobs", "Maximum number of jobs a player can join.", "Use 0 for no maximum", "Keep in mind that jobs.max.[amount] will bypass this setting");
maxJobs = c.get("max-jobs", 3); maxJobs = c.get("max-jobs", 3);
c.getW().addComment("hide-jobs-without-permission", "Hide jobs from player if they lack the permission to join the job"); c.addComment("hide-jobs-without-permission", "Hide jobs from player if they lack the permission to join the job");
hideJobsWithoutPermission = c.get("hide-jobs-without-permission", false); hideJobsWithoutPermission = c.get("hide-jobs-without-permission", false);
c.getW().addComment("hide-jobsinfo-without-permission", "Hide jobs info from player if they lack the permission to join the job"); c.addComment("hide-jobsinfo-without-permission", "Hide jobs info from player if they lack the permission to join the job");
hideJobsInfoWithoutPermission = c.get("hide-jobsinfo-without-permission", false); hideJobsInfoWithoutPermission = c.get("hide-jobsinfo-without-permission", false);
c.getW().addComment("enable-pay-near-spawner", c.addComment("enable-pay-near-spawner",
"Option to allow payment to be made when killing mobs from a spawner.", "Option to allow payment to be made when killing mobs from a spawner.",
"Use jobs.nearspawner.[amount] to define multiplayer. Example jobs.nearspawner.-0.5 will pay half of payment, jobs.nearspawner.-1 will not pay at all"); "Use jobs.nearspawner.[amount] to define multiplayer. Example jobs.nearspawner.-0.5 will pay half of payment, jobs.nearspawner.-1 will not pay at all");
payNearSpawner = c.get("enable-pay-near-spawner", false); payNearSpawner = c.get("enable-pay-near-spawner", false);
c.getW().addComment("enable-pay-creative", "Option to allow payment to be made in creative mode. This ignoring when a group has 'jobs.paycreative' permission."); c.addComment("enable-pay-creative", "Option to allow payment to be made in creative mode. This ignoring when a group has 'jobs.paycreative' permission.");
payInCreative = c.get("enable-pay-creative", false); payInCreative = c.get("enable-pay-creative", false);
c.getW().addComment("enable-pay-for-exploring-when-flying", "Option to allow payment to be made for exploring when player flies"); c.addComment("enable-pay-for-exploring-when-flying", "Option to allow payment to be made for exploring when player flies");
payExploringWhenFlying = c.get("enable-pay-for-exploring-when-flying", false); payExploringWhenFlying = c.get("enable-pay-for-exploring-when-flying", false);
c.getW().addComment("add-xp-player", "Adds the Jobs xp received to the player's Minecraft XP bar"); c.addComment("add-xp-player", "Adds the Jobs xp received to the player's Minecraft XP bar");
addXpPlayer = c.get("add-xp-player", false); addXpPlayer = c.get("add-xp-player", false);
c.getW().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."); c.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.");
modifyChat = c.get("modify-chat.use", true); modifyChat = c.get("modify-chat.use", true);
modifyChatPrefix = c.get("modify-chat.prefix", "&c[", true); modifyChatPrefix = c.get("modify-chat.prefix", "&c[");
modifyChatSuffix = c.get("modify-chat.suffix", "&c]&r ", true); modifyChatSuffix = c.get("modify-chat.suffix", "&c]&r ");
modifyChatSeparator = c.get("modify-chat.separator", " ", true); modifyChatSeparator = c.get("modify-chat.separator", " ");
c.getW().addComment("UseCustomNames", "Do you want to use custom item/block/mob/enchant/color names?", c.addComment("UseCustomNames", "Do you want to use custom item/block/mob/enchant/color names?",
"With this set to true names like Stone:1 will be translated to Granite", "Name list is in TranslatableWords.yml file"); "With this set to true names like Stone:1 will be translated to Granite", "Name list is in TranslatableWords.yml file");
UseCustomNames = c.get("UseCustomNames", true); UseCustomNames = c.get("UseCustomNames", true);
c.getW().addComment("economy-batch-delay", "Changes how often, in seconds, players are paid out. Default is 5 seconds.", c.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)"); "Setting this too low may cause tick lag. Increase this to improve economy performance (at the cost of delays in payment)");
economyBatchDelay = c.get("economy-batch-delay", 5); economyBatchDelay = c.get("economy-batch-delay", 5);
c.getW().addComment("economy-async", "Enable async economy calls.", "Disable this if you have issues with payments or your plugin is not thread safe."); c.addComment("economy-async", "Enable async economy calls.", "Disable this if you have issues with payments or your plugin is not thread safe.");
economyAsync = c.get("economy-async", true); economyAsync = c.get("economy-async", true);
c.getW().addComment("Economy.PaymentMethods", c.addComment("Economy.PaymentMethods",
"By disabling one of these, players no longer will get particular payment.", "By disabling one of these, players no longer will get particular payment.",
"Useful for removing particular payment method without editing whole jobConfig file"); "Useful for removing particular payment method without editing whole jobConfig file");
PaymentMethodsMoney = c.get("Economy.PaymentMethods.Money", true); PaymentMethodsMoney = c.get("Economy.PaymentMethods.Money", true);
PaymentMethodsPoints = c.get("Economy.PaymentMethods.Points", true); PaymentMethodsPoints = c.get("Economy.PaymentMethods.Points", true);
PaymentMethodsExp = c.get("Economy.PaymentMethods.Exp", true); PaymentMethodsExp = c.get("Economy.PaymentMethods.Exp", true);
c.getW().addComment("Economy.GeneralMulti", c.addComment("Economy.GeneralMulti",
"Can be used to change payment amounts for all jobs and all actions if you want to readjust them", "Can be used to change payment amounts for all jobs and all actions if you want to readjust them",
"Amounts are in percentage, above 0 will increase payments", "Amounts are in percentage, above 0 will increase payments",
"Amount belove 0 will decrease payments", "Amount belove 0 will decrease payments",
@ -586,18 +577,18 @@ public class GeneralConfigManager {
generalMulti.put(one, c.get("Economy.GeneralMulti." + one.name(), 0D) / 100D); generalMulti.put(one, c.get("Economy.GeneralMulti." + one.name(), 0D) / 100D);
} }
c.getW().addComment("Economy.MinimumOveralPayment.use", c.addComment("Economy.MinimumOveralPayment.use",
"Determines minimum payment. In example if player uses McMMO treefeller and earns only 20%, but at same time he gets 25% penalty from dynamic payment. He can 'get' negative amount of money", "Determines minimum payment. In example if player uses McMMO treefeller and earns only 20%, but at same time he gets 25% penalty from dynamic payment. He can 'get' negative amount of money",
"This will limit it to particular percentage", "Works only when original payment is above 0"); "This will limit it to particular percentage", "Works only when original payment is above 0");
useMinimumOveralPayment = c.get("Economy.MinimumOveralPayment.use", true); useMinimumOveralPayment = c.get("Economy.MinimumOveralPayment.use", true);
MinimumOveralPaymentLimit = c.get("Economy.MinimumOveralPayment.limit", 0.1); MinimumOveralPaymentLimit = c.get("Economy.MinimumOveralPayment.limit", 0.1);
c.getW().addComment("Economy.MinimumOveralPoints.use", c.addComment("Economy.MinimumOveralPoints.use",
"Determines minimum payment. In example if player uses McMMO treefeller and earns only 20%, but at same time he gets 25% penalty from dynamic payment. He can 'get' negative amount of money", "Determines minimum payment. In example if player uses McMMO treefeller and earns only 20%, but at same time he gets 25% penalty from dynamic payment. He can 'get' negative amount of money",
"This will limit it to particular percentage", "Works only when original payment is above 0"); "This will limit it to particular percentage", "Works only when original payment is above 0");
useMinimumOveralPoints = c.get("Economy.MinimumOveralPoints.use", true); useMinimumOveralPoints = c.get("Economy.MinimumOveralPoints.use", true);
MinimumOveralPointsLimit = c.get("Economy.MinimumOveralPoints.limit", 0.1); MinimumOveralPointsLimit = c.get("Economy.MinimumOveralPoints.limit", 0.1);
c.getW().addComment("Economy.DynamicPayment.use", "Do you want to use dynamic payment dependent on how many players already working for jobs?", c.addComment("Economy.DynamicPayment.use", "Do you want to use dynamic payment dependent on how many players already working for jobs?",
"This can help automatically lift up payments for not so popular jobs and lower for most popular ones"); "This can help automatically lift up payments for not so popular jobs and lower for most popular ones");
useDynamicPayment = c.get("Economy.DynamicPayment.use", false); useDynamicPayment = c.get("Economy.DynamicPayment.use", false);
@ -616,43 +607,43 @@ public class GeneralConfigManager {
DynamicPaymentMaxPenalty = c.get("Economy.DynamicPayment.MaxPenalty", 25.0); DynamicPaymentMaxPenalty = c.get("Economy.DynamicPayment.MaxPenalty", 25.0);
DynamicPaymentMaxBonus = c.get("Economy.DynamicPayment.MaxBonus", 100.0); DynamicPaymentMaxBonus = c.get("Economy.DynamicPayment.MaxBonus", 100.0);
c.getW().addComment("Economy.MaxPayment.curve.use", "Enabling this feature will mean players will still earn once they reach cap but " + c.addComment("Economy.MaxPayment.curve.use", "Enabling this feature will mean players will still earn once they reach cap but " +
"will loose a percentage the higher over cap they go. Controlled by a factor. math is ```100/((1/factor*percentOver^2)+1)```"); "will loose a percentage the higher over cap they go. Controlled by a factor. math is ```100/((1/factor*percentOver^2)+1)```");
useMaxPaymentCurve = c.get("Economy.MaxPayment.curve.use", false); useMaxPaymentCurve = c.get("Economy.MaxPayment.curve.use", false);
int temp = c.get("Economy.MaxPayment.curve.factor", 10); int temp = c.get("Economy.MaxPayment.curve.factor", 10);
maxPaymentCurveFactor = ((float) temp) / 1000; maxPaymentCurveFactor = ((float) temp) / 1000;
c.getW().addComment("Economy.UseServerAccount", "Server economy account", "With this enabled, players will get money from defined user (server account)", c.addComment("Economy.UseServerAccount", "Server economy account", "With this enabled, players will get money from defined user (server account)",
"If this account don't have enough money to pay for players for, player will get message"); "If this account don't have enough money to pay for players for, player will get message");
UseServerAccount = c.get("Economy.UseServerAccount", false); UseServerAccount = c.get("Economy.UseServerAccount", false);
c.getW().addComment("Economy.AccountName", "Username should be with Correct capitalization"); c.addComment("Economy.AccountName", "Username should be with Correct capitalization");
ServerAccountName = c.get("Economy.AccountName", "Server"); ServerAccountName = c.get("Economy.AccountName", "Server");
c.getW().addComment("Economy.Taxes.use", "Do you want to use taxes feature for jobs payment?"); c.addComment("Economy.Taxes.use", "Do you want to use taxes feature for jobs payment?");
UseTaxes = c.get("Economy.Taxes.use", false); UseTaxes = c.get("Economy.Taxes.use", false);
c.getW().addComment("Economy.Taxes.AccountName", "Username should be with Correct capitalization, it can be same as setup in server account before"); c.addComment("Economy.Taxes.AccountName", "Username should be with Correct capitalization, it can be same as setup in server account before");
ServertaxesAccountName = c.get("Economy.Taxes.AccountName", "Server"); ServertaxesAccountName = c.get("Economy.Taxes.AccountName", "Server");
c.getW().addComment("Economy.Taxes.Amount", "Amount in percentage"); c.addComment("Economy.Taxes.Amount", "Amount in percentage");
TaxesAmount = c.get("Economy.Taxes.Amount", 15.0); TaxesAmount = c.get("Economy.Taxes.Amount", 15.0);
c.getW().addComment("Economy.Taxes.TransferToServerAccount", "Do you want to transfer taxes to server account?"); c.addComment("Economy.Taxes.TransferToServerAccount", "Do you want to transfer taxes to server account?");
TransferToServerAccount = c.get("Economy.Taxes.TransferToServerAccount", true); TransferToServerAccount = c.get("Economy.Taxes.TransferToServerAccount", true);
c.getW().addComment("Economy.Taxes.TakeFromPlayersPayment", c.addComment("Economy.Taxes.TakeFromPlayersPayment",
"With this true, taxes will be taken from players payment and he will get less money than its shown in jobs info", "With this true, taxes will be taken from players payment and he will get less money than its shown in jobs info",
"When its false player will get full payment and server account will get taxes amount to hes account"); "When its false player will get full payment and server account will get taxes amount to hes account");
TakeFromPlayersPayment = c.get("Economy.Taxes.TakeFromPlayersPayment", false); TakeFromPlayersPayment = c.get("Economy.Taxes.TakeFromPlayersPayment", false);
// Money limit // Money limit
CurrencyLimit limit = new CurrencyLimit(); CurrencyLimit limit = new CurrencyLimit();
c.getW().addComment("Economy.Limit.Money", "Money gain limit", "With this enabled, players will be limited how much they can make in defined time", c.addComment("Economy.Limit.Money", "Money gain limit", "With this enabled, players will be limited how much they can make in defined time",
"Time in seconds: 60 = 1 min, 3600 = 1 hour, 86400 = 24 hours"); "Time in seconds: 60 = 1 min, 3600 = 1 hour, 86400 = 24 hours");
limit.setEnabled(c.get("Economy.Limit.Money.Use", false)); limit.setEnabled(c.get("Economy.Limit.Money.Use", false));
List<CurrencyType> list = new ArrayList<>(); List<CurrencyType> list = new ArrayList<>();
c.getW().addComment("Economy.Limit.Money.StopWithExp", "Do you want to stop money gain when exp limit reached?"); c.addComment("Economy.Limit.Money.StopWithExp", "Do you want to stop money gain when exp limit reached?");
if (c.get("Economy.Limit.Money.StopWithExp", false)) if (c.get("Economy.Limit.Money.StopWithExp", false))
list.add(CurrencyType.EXP); list.add(CurrencyType.EXP);
c.getW().addComment("Economy.Limit.Money.StopWithPoint", "Do you want to stop money gain when point limit reached?"); c.addComment("Economy.Limit.Money.StopWithPoint", "Do you want to stop money gain when point limit reached?");
if (c.get("Economy.Limit.Money.StopWithPoint", false)) if (c.get("Economy.Limit.Money.StopWithPoint", false))
list.add(CurrencyType.POINTS); list.add(CurrencyType.POINTS);
limit.setStopWith(list); limit.setStopWith(list);
c.getW().addComment("Economy.Limit.Money.MoneyLimit", c.addComment("Economy.Limit.Money.MoneyLimit",
"Equation to calculate max limit. Option to use total level to include players total amount levels of current jobs", "Equation to calculate max limit. Option to use total level to include players total amount levels of current jobs",
"You can always use simple number to set money limit", "You can always use simple number to set money limit",
"Default equation is: 500+500*(totallevel/100), this will add 1% from 500 for each level player have", "Default equation is: 500+500*(totallevel/100), this will add 1% from 500 for each level player have",
@ -667,9 +658,9 @@ public class GeneralConfigManager {
Jobs.getPluginLogger().warning("MoneyLimit has an invalid value. Disabling money limit!"); Jobs.getPluginLogger().warning("MoneyLimit has an invalid value. Disabling money limit!");
limit.setEnabled(false); limit.setEnabled(false);
} }
c.getW().addComment("Economy.Limit.Money.TimeLimit", "Time in seconds: 60 = 1 min, 3600 = 1 hour, 86400 = 24 hours"); c.addComment("Economy.Limit.Money.TimeLimit", "Time in seconds: 60 = 1 min, 3600 = 1 hour, 86400 = 24 hours");
limit.setTimeLimit(c.get("Economy.Limit.Money.TimeLimit", 3600)); limit.setTimeLimit(c.get("Economy.Limit.Money.TimeLimit", 3600));
c.getW().addComment("Economy.Limit.Money.AnnouncementDelay", "Delay between announcements about reached money limit", c.addComment("Economy.Limit.Money.AnnouncementDelay", "Delay between announcements about reached money limit",
"Keep this from 30 to 5 min (300), as players can get annoyed of constant message displaying"); "Keep this from 30 to 5 min (300), as players can get annoyed of constant message displaying");
limit.setAnnouncementDelay(c.get("Economy.Limit.Money.AnnouncementDelay", 30)); limit.setAnnouncementDelay(c.get("Economy.Limit.Money.AnnouncementDelay", 30));
currencyLimitUse.put(CurrencyType.MONEY, limit); currencyLimitUse.put(CurrencyType.MONEY, limit);
@ -677,16 +668,16 @@ public class GeneralConfigManager {
// Point limit // Point limit
limit = new CurrencyLimit(); limit = new CurrencyLimit();
list = new ArrayList<>(); list = new ArrayList<>();
c.getW().addComment("Economy.Limit.Point", "Point gain limit", "With this enabled, players will be limited how much they can make in defined time"); c.addComment("Economy.Limit.Point", "Point gain limit", "With this enabled, players will be limited how much they can make in defined time");
limit.setEnabled(c.get("Economy.Limit.Point.Use", false)); limit.setEnabled(c.get("Economy.Limit.Point.Use", false));
c.getW().addComment("Economy.Limit.Point.StopWithExp", "Do you want to stop Point gain when exp limit reached?"); c.addComment("Economy.Limit.Point.StopWithExp", "Do you want to stop Point gain when exp limit reached?");
if (c.get("Economy.Limit.Point.StopWithExp", false)) if (c.get("Economy.Limit.Point.StopWithExp", false))
list.add(CurrencyType.EXP); list.add(CurrencyType.EXP);
c.getW().addComment("Economy.Limit.Point.StopWithMoney", "Do you want to stop Point gain when money limit reached?"); c.addComment("Economy.Limit.Point.StopWithMoney", "Do you want to stop Point gain when money limit reached?");
if (c.get("Economy.Limit.Point.StopWithMoney", false)) if (c.get("Economy.Limit.Point.StopWithMoney", false))
list.add(CurrencyType.MONEY); list.add(CurrencyType.MONEY);
limit.setStopWith(list); limit.setStopWith(list);
c.getW().addComment("Economy.Limit.Point.Limit", c.addComment("Economy.Limit.Point.Limit",
"Equation to calculate max limit. Option to use total level to include players total amount levels of current jobs", "Equation to calculate max limit. Option to use total level to include players total amount levels of current jobs",
"You can always use simple number to set limit", "You can always use simple number to set limit",
"Default equation is: 500+500*(totallevel/100), this will add 1% from 500 for each level player have", "Default equation is: 500+500*(totallevel/100), this will add 1% from 500 for each level player have",
@ -701,9 +692,9 @@ public class GeneralConfigManager {
Jobs.getPluginLogger().warning("PointLimit has an invalid value. Disabling money limit!"); Jobs.getPluginLogger().warning("PointLimit has an invalid value. Disabling money limit!");
limit.setEnabled(false); limit.setEnabled(false);
} }
c.getW().addComment("Economy.Limit.Point.TimeLimit", "Time in seconds: 60 = 1 min, 3600 = 1 hour, 86400 = 24 hours"); c.addComment("Economy.Limit.Point.TimeLimit", "Time in seconds: 60 = 1 min, 3600 = 1 hour, 86400 = 24 hours");
limit.setTimeLimit(c.get("Economy.Limit.Point.TimeLimit", 3600)); limit.setTimeLimit(c.get("Economy.Limit.Point.TimeLimit", 3600));
c.getW().addComment("Economy.Limit.Point.AnnouncementDelay", "Delay between announcements about reached limit", c.addComment("Economy.Limit.Point.AnnouncementDelay", "Delay between announcements about reached limit",
"Keep this from 30 to 5 min (300), as players can get annoyed of constant message displaying"); "Keep this from 30 to 5 min (300), as players can get annoyed of constant message displaying");
limit.setAnnouncementDelay(c.get("Economy.Limit.Point.AnnouncementDelay", 30)); limit.setAnnouncementDelay(c.get("Economy.Limit.Point.AnnouncementDelay", 30));
currencyLimitUse.put(CurrencyType.POINTS, limit); currencyLimitUse.put(CurrencyType.POINTS, limit);
@ -711,17 +702,17 @@ public class GeneralConfigManager {
// Exp limit // Exp limit
limit = new CurrencyLimit(); limit = new CurrencyLimit();
list = new ArrayList<>(); list = new ArrayList<>();
c.getW().addComment("Economy.Limit.Exp", "Exp gain limit", "With this enabled, players will be limited how much they can get in defined time", c.addComment("Economy.Limit.Exp", "Exp gain limit", "With this enabled, players will be limited how much they can get in defined time",
"Time in seconds: 60 = 1 min, 3600 = 1 hour, 86400 = 24 hours"); "Time in seconds: 60 = 1 min, 3600 = 1 hour, 86400 = 24 hours");
limit.setEnabled(c.get("Economy.Limit.Exp.Use", false)); limit.setEnabled(c.get("Economy.Limit.Exp.Use", false));
c.getW().addComment("Economy.Limit.Exp.StopWithMoney", "Do you want to stop exp gain when money limit reached?"); c.addComment("Economy.Limit.Exp.StopWithMoney", "Do you want to stop exp gain when money limit reached?");
if (c.get("Economy.Limit.Exp.StopWithMoney", false)) if (c.get("Economy.Limit.Exp.StopWithMoney", false))
list.add(CurrencyType.MONEY); list.add(CurrencyType.MONEY);
c.getW().addComment("Economy.Limit.Exp.StopWithPoint", "Do you want to stop exp gain when point limit reached?"); c.addComment("Economy.Limit.Exp.StopWithPoint", "Do you want to stop exp gain when point limit reached?");
if (c.get("Economy.Limit.Exp.StopWithPoint", false)) if (c.get("Economy.Limit.Exp.StopWithPoint", false))
list.add(CurrencyType.POINTS); list.add(CurrencyType.POINTS);
limit.setStopWith(list); limit.setStopWith(list);
c.getW().addComment("Economy.Limit.Exp.Limit", "Equation to calculate max money limit. Option to use total level to include players total amount of current jobs", c.addComment("Economy.Limit.Exp.Limit", "Equation to calculate max money limit. Option to use total level to include players total amount of current jobs",
"You can always use simple number to set exp limit", "You can always use simple number to set exp limit",
"Default equation is: 5000+5000*(totallevel/100), this will add 1% from 5000 for each level player have", "Default equation is: 5000+5000*(totallevel/100), this will add 1% from 5000 for each level player have",
"So player with 2 jobs with level 15 and 22 will have 6850 limit"); "So player with 2 jobs with level 15 and 22 will have 6850 limit");
@ -735,148 +726,148 @@ public class GeneralConfigManager {
Jobs.getPluginLogger().warning("ExpLimit has an invalid value. Disabling money limit!"); Jobs.getPluginLogger().warning("ExpLimit has an invalid value. Disabling money limit!");
limit.setEnabled(false); limit.setEnabled(false);
} }
c.getW().addComment("Economy.Limit.Exp.TimeLimit", "Time in seconds: 60 = 1 min, 3600 = 1 hour, 86400 = 24 hours"); c.addComment("Economy.Limit.Exp.TimeLimit", "Time in seconds: 60 = 1 min, 3600 = 1 hour, 86400 = 24 hours");
limit.setTimeLimit(c.get("Economy.Limit.Exp.TimeLimit", 3600)); limit.setTimeLimit(c.get("Economy.Limit.Exp.TimeLimit", 3600));
c.getW().addComment("Economy.Limit.Exp.AnnouncementDelay", "Delay between announcements about reached Exp limit", c.addComment("Economy.Limit.Exp.AnnouncementDelay", "Delay between announcements about reached Exp limit",
"Keep this from 30 to 5 min (300), as players can get annoyed of constant message displaying"); "Keep this from 30 to 5 min (300), as players can get annoyed of constant message displaying");
limit.setAnnouncementDelay(c.get("Economy.Limit.Exp.AnnouncementDelay", 30)); limit.setAnnouncementDelay(c.get("Economy.Limit.Exp.AnnouncementDelay", 30));
currencyLimitUse.put(CurrencyType.EXP, limit); currencyLimitUse.put(CurrencyType.EXP, limit);
c.getW().addComment("Economy.Repair.PayForRenaming", "Do you want to give money for only renaming items in anvil?", c.addComment("Economy.Repair.PayForRenaming", "Do you want to give money for only renaming items in anvil?",
"Players will get full pay as they would for remaining two items when they only rename one", "Players will get full pay as they would for remaining two items when they only rename one",
"This is not a big issue, but if you want to disable it, you can"); "This is not a big issue, but if you want to disable it, you can");
PayForRenaming = c.get("Economy.Repair.PayForRenaming", true); PayForRenaming = c.get("Economy.Repair.PayForRenaming", true);
c.getW().addComment("Economy.Crafting.PayForEachCraft", c.addComment("Economy.Crafting.PayForEachCraft",
"With this true, player will get money for all crafted items instead of each crafting action (like with old payment mechanic)", "With this true, player will get money for all crafted items instead of each crafting action (like with old payment mechanic)",
"By default its false, as you can make ALOT of money if prices kept from old payment mechanics"); "By default its false, as you can make ALOT of money if prices kept from old payment mechanics");
PayForEachCraft = c.get("Economy.Crafting.PayForEachCraft", false); PayForEachCraft = c.get("Economy.Crafting.PayForEachCraft", false);
c.getW().addComment("Economy.MilkingCow.CancelMilking", "With this true, when timer is still going, cow milking event will be canceled", c.addComment("Economy.MilkingCow.CancelMilking", "With this true, when timer is still going, cow milking event will be canceled",
"With this false, player will get bucket of milk, but still no payment"); "With this false, player will get bucket of milk, but still no payment");
CancelCowMilking = c.get("Economy.MilkingCow.CancelMilking", false); CancelCowMilking = c.get("Economy.MilkingCow.CancelMilking", false);
c.getW().addComment("Economy.MilkingCow.Timer", c.addComment("Economy.MilkingCow.Timer",
"How ofter player can milk cows in seconds. Keep in mind that by default player can milk cow indefinitely and as often as he wants", "How ofter player can milk cows in seconds. Keep in mind that by default player can milk cow indefinitely and as often as he wants",
"Set to 0 if you want to disable timer"); "Set to 0 if you want to disable timer");
CowMilkingTimer = c.get("Economy.MilkingCow.Timer", 30) * 1000; CowMilkingTimer = c.get("Economy.MilkingCow.Timer", 30) * 1000;
c.getW().addComment("ExploitProtections.Furnaces.Reassign", c.addComment("ExploitProtections.Furnaces.Reassign",
"When enabled, players interacted furnaces will be saved into a file and will be reassigned after restart to keep giving out money", "When enabled, players interacted furnaces will be saved into a file and will be reassigned after restart to keep giving out money",
"Players will no longer need to click on furnace to get paid from it after server restart"); "Players will no longer need to click on furnace to get paid from it after server restart");
FurnacesReassign = c.get("ExploitProtections.Furnaces.Reassign", true); FurnacesReassign = c.get("ExploitProtections.Furnaces.Reassign", true);
c.getW().addComment("ExploitProtections.Furnaces.MaxDefaultAvailable", c.addComment("ExploitProtections.Furnaces.MaxDefaultAvailable",
"Defines max available furnaces each player can have to get paid from", "Defines max available furnaces each player can have to get paid from",
"This can be overridden with jobs.maxfurnaces.[amount] permission node"); "This can be overridden with jobs.maxfurnaces.[amount] permission node");
FurnacesMaxDefault = c.get("ExploitProtections.Furnaces.MaxDefaultAvailable", 20); FurnacesMaxDefault = c.get("ExploitProtections.Furnaces.MaxDefaultAvailable", 20);
c.getW().addComment("ExploitProtections.BrewingStands.Reassign", c.addComment("ExploitProtections.BrewingStands.Reassign",
"When enabled, players interacted brewing stands will be saved into file and will be reassigned after restart to keep giving out money", "When enabled, players interacted brewing stands will be saved into file and will be reassigned after restart to keep giving out money",
"Players will no longer need to click on brewing stand to get paid from it after server restart"); "Players will no longer need to click on brewing stand to get paid from it after server restart");
BrewingStandsReassign = c.get("ExploitProtections.BrewingStands.Reassign", true); BrewingStandsReassign = c.get("ExploitProtections.BrewingStands.Reassign", true);
c.getW().addComment("ExploitProtections.BrewingStands.MaxDefaultAvailable", c.addComment("ExploitProtections.BrewingStands.MaxDefaultAvailable",
"Defines max available brewing stands each player can have to get paid from", "Defines max available brewing stands each player can have to get paid from",
"Set to 0 if you want to disable this limitation", "Set to 0 if you want to disable this limitation",
"This can be overridden with jobs.maxbrewingstands.[amount] permission node"); "This can be overridden with jobs.maxbrewingstands.[amount] permission node");
BrewingStandsMaxDefault = c.get("ExploitProtections.BrewingStands.MaxDefaultAvailable", 20); BrewingStandsMaxDefault = c.get("ExploitProtections.BrewingStands.MaxDefaultAvailable", 20);
c.getW().addComment("ExploitProtections.General.PlaceAndBreakProtection", c.addComment("ExploitProtections.General.PlaceAndBreakProtection",
"Enable blocks protection, like ore, from exploiting by placing and destroying same block again and again.", "Enable blocks protection, like ore, from exploiting by placing and destroying same block again and again.",
"Modify restrictedBlocks.yml for blocks you want to protect"); "Modify restrictedBlocks.yml for blocks you want to protect");
useBlockProtection = c.get("ExploitProtections.General.PlaceAndBreakProtection", true); useBlockProtection = c.get("ExploitProtections.General.PlaceAndBreakProtection", true);
c.getW().addComment("ExploitProtections.General.KeepDataFor", c.addComment("ExploitProtections.General.KeepDataFor",
"For how long in days to keep block protection data in data base", "This will clean block data which ones have -1 as cooldown value", "For how long in days to keep block protection data in data base", "This will clean block data which ones have -1 as cooldown value",
"Data base cleanup will be performed on each server startup"); "Data base cleanup will be performed on each server startup");
BlockProtectionDays = c.get("ExploitProtections.General.KeepDataFor", 14); BlockProtectionDays = c.get("ExploitProtections.General.KeepDataFor", 14);
c.getW().addComment("ExploitProtections.General.GlobalBlockTimer", "All blocks will be protected X sec after player places it on ground."); c.addComment("ExploitProtections.General.GlobalBlockTimer", "All blocks will be protected X sec after player places it on ground.");
useGlobalTimer = c.get("ExploitProtections.General.GlobalBlockTimer.use", true); useGlobalTimer = c.get("ExploitProtections.General.GlobalBlockTimer.use", true);
globalblocktimer = c.get("ExploitProtections.General.GlobalBlockTimer.timer", 3); globalblocktimer = c.get("ExploitProtections.General.GlobalBlockTimer.timer", 3);
c.getW().addComment("ExploitProtections.General.SilkTouchProtection", "Enable silk touch protection.", c.addComment("ExploitProtections.General.SilkTouchProtection", "Enable silk touch protection.",
"With this enabled players wont get paid for broken blocks from restrictedblocks list with silk touch tool."); "With this enabled players wont get paid for broken blocks from restrictedblocks list with silk touch tool.");
useSilkTouchProtection = c.get("ExploitProtections.General.SilkTouchProtection", false); useSilkTouchProtection = c.get("ExploitProtections.General.SilkTouchProtection", false);
c.getW().addComment("ExploitProtections.General.MonsterDamage.Use", "This section controls how much damage player should do to monster for player to get paid", c.addComment("ExploitProtections.General.MonsterDamage.Use", "This section controls how much damage player should do to monster for player to get paid",
"This prevents from killing monsters in one hit when they suffer in example fall damage"); "This prevents from killing monsters in one hit when they suffer in example fall damage");
MonsterDamageUse = c.get("ExploitProtections.General.MonsterDamage.Use", false); MonsterDamageUse = c.get("ExploitProtections.General.MonsterDamage.Use", false);
MonsterDamagePercentage = c.get("ExploitProtections.General.MonsterDamage.Percentage", 60); MonsterDamagePercentage = c.get("ExploitProtections.General.MonsterDamage.Percentage", 60);
c.getW().addComment("ExploitProtections.McMMO", "McMMO abilities"); c.addComment("ExploitProtections.McMMO", "McMMO abilities");
c.getW().addComment("ExploitProtections.McMMO.TreeFellerMultiplier", "Players will get part of money from cutting trees with treefeller ability enabled.", c.addComment("ExploitProtections.McMMO.TreeFellerMultiplier", "Players will get part of money from cutting trees with treefeller ability enabled.",
"0.2 means 20% of original price"); "0.2 means 20% of original price");
TreeFellerMultiplier = c.get("ExploitProtections.McMMO.TreeFellerMultiplier", 0.2); TreeFellerMultiplier = c.get("ExploitProtections.McMMO.TreeFellerMultiplier", 0.2);
c.getW().addComment("ExploitProtections.McMMO.gigaDrillMultiplier", "Players will get part of money from braking blocks with gigaDrill ability enabled.", c.addComment("ExploitProtections.McMMO.gigaDrillMultiplier", "Players will get part of money from braking blocks with gigaDrill ability enabled.",
"0.2 means 20% of original price"); "0.2 means 20% of original price");
gigaDrillMultiplier = c.get("ExploitProtections.McMMO.gigaDrillMultiplier", 0.2); gigaDrillMultiplier = c.get("ExploitProtections.McMMO.gigaDrillMultiplier", 0.2);
c.getW().addComment("ExploitProtections.McMMO.superBreakerMultiplier", "Players will get part of money from braking blocks with super breaker ability enabled.", c.addComment("ExploitProtections.McMMO.superBreakerMultiplier", "Players will get part of money from braking blocks with super breaker ability enabled.",
"0.2 means 20% of original price"); "0.2 means 20% of original price");
superBreakerMultiplier = c.get("ExploitProtections.McMMO.superBreakerMultiplier", 0.2); superBreakerMultiplier = c.get("ExploitProtections.McMMO.superBreakerMultiplier", 0.2);
c.getW().addComment("ExploitProtections.MythicMobs", "MythicMobs plugin support", "Disable if you having issues with it or using old version"); c.addComment("ExploitProtections.MythicMobs", "MythicMobs plugin support", "Disable if you having issues with it or using old version");
MythicMobsEnabled = c.get("ExploitProtections.MythicMobs.enabled", true); MythicMobsEnabled = c.get("ExploitProtections.MythicMobs.enabled", true);
c.getW().addComment("ExploitProtections.Spawner.PreventSlimeSplit", "Prevent slime splitting when they are from spawner", c.addComment("ExploitProtections.Spawner.PreventSlimeSplit", "Prevent slime splitting when they are from spawner",
"Protects agains exploiting as new splited slimes is treated as naturally spawned and not from spawner"); "Protects agains exploiting as new splited slimes is treated as naturally spawned and not from spawner");
PreventSlimeSplit = c.get("ExploitProtections.Spawner.PreventSlimeSplit", true); PreventSlimeSplit = c.get("ExploitProtections.Spawner.PreventSlimeSplit", true);
c.getW().addComment("ExploitProtections.Spawner.PreventMagmaCubeSplit", "Prevent magmacube splitting when they are from spawner"); c.addComment("ExploitProtections.Spawner.PreventMagmaCubeSplit", "Prevent magmacube splitting when they are from spawner");
PreventMagmaCubeSplit = c.get("ExploitProtections.Spawner.PreventMagmaCubeSplit", true); PreventMagmaCubeSplit = c.get("ExploitProtections.Spawner.PreventMagmaCubeSplit", true);
c.getW().addComment("ExploitProtections.Smelt.PreventHopperFillUps", "Prevent payments when hoppers moving items into furnace", "Player will not get paid, but items will be smelted"); c.addComment("ExploitProtections.Smelt.PreventHopperFillUps", "Prevent payments when hoppers moving items into furnace", "Player will not get paid, but items will be smelted");
PreventHopperFillUps = c.get("ExploitProtections.Smelt.PreventHopperFillUps", true); PreventHopperFillUps = c.get("ExploitProtections.Smelt.PreventHopperFillUps", true);
c.getW().addComment("ExploitProtections.Smelt.PreventMagmaCubeSplit", "Prevent payments when hoppers moving items into brewing stands", c.addComment("ExploitProtections.Smelt.PreventMagmaCubeSplit", "Prevent payments when hoppers moving items into brewing stands",
"Player will not get paid, but items will be brewd as they supose too"); "Player will not get paid, but items will be brewd as they supose too");
PreventBrewingStandFillUps = c.get("ExploitProtections.Brew.PreventBrewingStandFillUps", true); PreventBrewingStandFillUps = c.get("ExploitProtections.Brew.PreventBrewingStandFillUps", true);
c.getW().addComment("use-breeder-finder", "Breeder finder.", c.addComment("use-breeder-finder", "Breeder finder.",
"If you are not using breeding payment, you can disable this to save little resources. Really little."); "If you are not using breeding payment, you can disable this to save little resources. Really little.");
useBreederFinder = c.get("use-breeder-finder", true); useBreederFinder = c.get("use-breeder-finder", true);
c.getW().addComment("old-job", c.addComment("old-job",
"Old job save", "Players can leave job and return later with some level loss during that", "Old job save", "Players can leave job and return later with some level loss during that",
"You can fix players level if his job level is at max level"); "You can fix players level if his job level is at max level");
levelLossPercentage = c.get("old-job.level-loss-percentage", 30); levelLossPercentage = c.get("old-job.level-loss-percentage", 30);
fixAtMaxLevel = c.get("old-job.fix-at-max-level", true); fixAtMaxLevel = c.get("old-job.fix-at-max-level", true);
c.getW().addComment("old-job.level-loss-from-max-level", c.addComment("old-job.level-loss-from-max-level",
"Percentage to loose when leaving job at max level", "Percentage to loose when leaving job at max level",
"Only works when fix-at-max-level is set to false"); "Only works when fix-at-max-level is set to false");
levelLossPercentageFromMax = c.get("old-job.level-loss-from-max-level", levelLossPercentage); levelLossPercentageFromMax = c.get("old-job.level-loss-from-max-level", levelLossPercentage);
c.getW().addComment("ActionBars.Messages.EnabledByDefault", "When this set to true player will see action bar messages by default"); c.addComment("ActionBars.Messages.EnabledByDefault", "When this set to true player will see action bar messages by default");
ActionBarsMessageByDefault = c.get("ActionBars.Messages.EnabledByDefault", true); ActionBarsMessageByDefault = c.get("ActionBars.Messages.EnabledByDefault", true);
c.getW().addComment("BossBar.Enabled", "Enables BossBar feature", "Works only from 1.9 mc version"); c.addComment("BossBar.Enabled", "Enables BossBar feature", "Works only from 1.9 mc version");
BossBarEnabled = c.get("BossBar.Enabled", true); BossBarEnabled = c.get("BossBar.Enabled", true);
if (BossBarEnabled == true) { if (BossBarEnabled == true) {
if (Jobs.getVersionCheckManager().getVersion().isLower(Version.v1_9_R1)) { if (Jobs.getVersionCheckManager().getVersion().isLower(Version.v1_9_R1)) {
Jobs.consoleMsg("&c[Jobs] Your server version don't support BossBar. This feature will be disabled."); Jobs.consoleMsg("&c[Jobs] Your server version don't support BossBar. This feature will be disabled.");
c.getW().set("BossBar.Enabled", false); c.set("BossBar.Enabled", false);
BossBarEnabled = false; BossBarEnabled = false;
} }
} }
c.getW().addComment("BossBar.Messages.EnabledByDefault", "When this set to true player will see Bossbar messages by default"); c.addComment("BossBar.Messages.EnabledByDefault", "When this set to true player will see Bossbar messages by default");
BossBarsMessageByDefault = c.get("BossBar.Messages.EnabledByDefault", true); BossBarsMessageByDefault = c.get("BossBar.Messages.EnabledByDefault", true);
c.getW().addComment("BossBar.ShowOnEachAction", "If enabled boss bar will update after each action", c.addComment("BossBar.ShowOnEachAction", "If enabled boss bar will update after each action",
"If disabled, BossBar will update only on each payment. This can save some server resources"); "If disabled, BossBar will update only on each payment. This can save some server resources");
BossBarShowOnEachAction = c.get("BossBar.ShowOnEachAction", false); BossBarShowOnEachAction = c.get("BossBar.ShowOnEachAction", false);
c.getW().addComment("BossBar.Timer", "How long in sec to show BossBar for player", c.addComment("BossBar.Timer", "How long in sec to show BossBar for player",
"If you have disabled ShowOnEachAction, then keep this number higher than payment interval for better experience"); "If you have disabled ShowOnEachAction, then keep this number higher than payment interval for better experience");
BossBarTimer = c.get("BossBar.Timer", economyBatchDelay + 1); BossBarTimer = c.get("BossBar.Timer", economyBatchDelay + 1);
c.getW().addComment("ShowActionBars", "You can enable/disable message shown for players in action bar"); c.addComment("ShowActionBars", "You can enable/disable message shown for players in action bar");
TitleChangeActionBar = c.get("ShowActionBars.OnTitleChange", true); TitleChangeActionBar = c.get("ShowActionBars.OnTitleChange", true);
LevelChangeActionBar = c.get("ShowActionBars.OnLevelChange", true); LevelChangeActionBar = c.get("ShowActionBars.OnLevelChange", true);
EmptyServerAccountActionBar = c.get("ShowActionBars.OnEmptyServerAccount", true); EmptyServerAccountActionBar = c.get("ShowActionBars.OnEmptyServerAccount", true);
c.getW().addComment("ShowChatMessage", "Chat messages", "You can enable/disable message shown for players in chat"); c.addComment("ShowChatMessage", "Chat messages", "You can enable/disable message shown for players in chat");
TitleChangeChat = c.get("ShowChatMessage.OnTitleChange", true); TitleChangeChat = c.get("ShowChatMessage.OnTitleChange", true);
LevelChangeChat = c.get("ShowChatMessage.OnLevelChange", true); LevelChangeChat = c.get("ShowChatMessage.OnLevelChange", true);
EmptyServerAccountChat = c.get("ShowChatMessage.OnEmptyServerAccount", true); EmptyServerAccountChat = c.get("ShowChatMessage.OnEmptyServerAccount", true);
c.getW().addComment("Sounds", "Sounds", "Extra sounds on some events", c.addComment("Sounds", "Sounds", "Extra sounds on some events",
"All sounds can be found in https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Sound.html"); "All sounds can be found in https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Sound.html");
SoundLevelupUse = c.get("Sounds.LevelUp.use", true); SoundLevelupUse = c.get("Sounds.LevelUp.use", true);
SoundLevelupSound = c.get("Sounds.LevelUp.sound", "ENTITY_PLAYER_LEVELUP"); SoundLevelupSound = c.get("Sounds.LevelUp.sound", "ENTITY_PLAYER_LEVELUP");
@ -887,50 +878,50 @@ public class GeneralConfigManager {
SoundTitleChangeVolume = c.get("Sounds.TitleChange.volume", 1); SoundTitleChangeVolume = c.get("Sounds.TitleChange.volume", 1);
SoundTitleChangePitch = c.get("Sounds.TitleChange.pitch", 3); SoundTitleChangePitch = c.get("Sounds.TitleChange.pitch", 3);
c.getW().addComment("Signs", "You can disable this to save SMALL amount of server resources"); c.addComment("Signs", "You can disable this to save SMALL amount of server resources");
SignsEnabled = c.get("Signs.Enable", true); SignsEnabled = c.get("Signs.Enable", true);
SignsColorizeJobName = c.get("Signs.Colors.ColorizeJobName", true); SignsColorizeJobName = c.get("Signs.Colors.ColorizeJobName", true);
c.getW().addComment("Signs.InfoUpdateInterval", c.addComment("Signs.InfoUpdateInterval",
"This is interval in sec in which signs will be updated. This is not continues update, signs are updated only on levelup, job leave, job join or similar action."); "This is interval in sec in which signs will be updated. This is not continues update, signs are updated only on levelup, job leave, job join or similar action.");
c.getW().addComment("Signs.InfoUpdateInterval", c.addComment("Signs.InfoUpdateInterval",
"This is update for same job signs, to avoid huge lag if you have bunch of same type signs. Keep it from 1 to as many sec you want"); "This is update for same job signs, to avoid huge lag if you have bunch of same type signs. Keep it from 1 to as many sec you want");
InfoUpdateInterval = c.get("Signs.InfoUpdateInterval", 5); InfoUpdateInterval = c.get("Signs.InfoUpdateInterval", 5);
c.getW().addComment("Scoreboard.ShowToplist", "This will enable to show top list in scoreboard instead of chat"); c.addComment("Scoreboard.ShowToplist", "This will enable to show top list in scoreboard instead of chat");
ShowToplistInScoreboard = c.get("Scoreboard.ShowToplist", true); ShowToplistInScoreboard = c.get("Scoreboard.ShowToplist", true);
c.getW().addComment("Scoreboard.interval", "For how long to show scoreboard"); c.addComment("Scoreboard.interval", "For how long to show scoreboard");
ToplistInScoreboardInterval = c.get("Scoreboard.interval", 10); ToplistInScoreboardInterval = c.get("Scoreboard.interval", 10);
c.getW().addComment("JobsBrowse.ShowTotalWorkers", "Do you want to show total amount of workers for job in jobs browse window?"); c.addComment("JobsBrowse.ShowTotalWorkers", "Do you want to show total amount of workers for job in jobs browse window?");
ShowTotalWorkers = c.get("JobsBrowse.ShowTotalWorkers", true); ShowTotalWorkers = c.get("JobsBrowse.ShowTotalWorkers", true);
c.getW().addComment("JobsBrowse.ShowPenaltyBonus", "Do you want to show penalty and bonus in jobs browse window? Only works if this feature is enabled"); c.addComment("JobsBrowse.ShowPenaltyBonus", "Do you want to show penalty and bonus in jobs browse window? Only works if this feature is enabled");
ShowPenaltyBonus = c.get("JobsBrowse.ShowPenaltyBonus", true); ShowPenaltyBonus = c.get("JobsBrowse.ShowPenaltyBonus", true);
c.getW().addComment("JobsBrowse.UseNewLook", "Defines if you want to use new /jobs browse look or old one"); c.addComment("JobsBrowse.UseNewLook", "Defines if you want to use new /jobs browse look or old one");
BrowseUseNewLook = c.get("JobsBrowse.UseNewLook", true); BrowseUseNewLook = c.get("JobsBrowse.UseNewLook", true);
c.getW().addComment("JobsBrowse.AmountToShow", "Defines amount of jobs to be shown in one page for /jobs browse"); c.addComment("JobsBrowse.AmountToShow", "Defines amount of jobs to be shown in one page for /jobs browse");
BrowseAmountToShow = c.get("JobsBrowse.AmountToShow", 5); BrowseAmountToShow = c.get("JobsBrowse.AmountToShow", 5);
c.getW().addComment("JobsGUI.OpenOnBrowse", "Do you want to show GUI when performing /jobs browse command?"); c.addComment("JobsGUI.OpenOnBrowse", "Do you want to show GUI when performing /jobs browse command?");
JobsGUIOpenOnBrowse = c.get("JobsGUI.OpenOnBrowse", true); JobsGUIOpenOnBrowse = c.get("JobsGUI.OpenOnBrowse", true);
c.getW().addComment("JobsGUI.ShowChatBrowse", "Do you want to show chat information when performing /jobs browse command?"); c.addComment("JobsGUI.ShowChatBrowse", "Do you want to show chat information when performing /jobs browse command?");
JobsGUIShowChatBrowse = c.get("JobsGUI.ShowChatBrowse", true); JobsGUIShowChatBrowse = c.get("JobsGUI.ShowChatBrowse", true);
c.getW().addComment("JobsGUI.SwitcheButtons", "With true left mouse button will join job and right will show more info", c.addComment("JobsGUI.SwitcheButtons", "With true left mouse button will join job and right will show more info",
"With false left mouse button will show more info, right will join job", "Don't forget to adjust locale file"); "With false left mouse button will show more info, right will join job", "Don't forget to adjust locale file");
JobsGUISwitcheButtons = c.get("JobsGUI.SwitcheButtons", false); JobsGUISwitcheButtons = c.get("JobsGUI.SwitcheButtons", false);
c.getW().addComment("JobsGUI.Rows", "Defines size in rows of GUI"); c.addComment("JobsGUI.Rows", "Defines size in rows of GUI");
JobsGUIRows = c.get("JobsGUI.Rows", 5); JobsGUIRows = c.get("JobsGUI.Rows", 5);
c.getW().addComment("JobsGUI.BackButtonSlot", "Defines back button slot in GUI"); c.addComment("JobsGUI.BackButtonSlot", "Defines back button slot in GUI");
JobsGUIBackButton = c.get("JobsGUI.BackButtonSlot", 37); JobsGUIBackButton = c.get("JobsGUI.BackButtonSlot", 37);
c.getW().addComment("JobsGUI.StartPosition", "Defines start position in gui from which job icons will be shown"); c.addComment("JobsGUI.StartPosition", "Defines start position in gui from which job icons will be shown");
JobsGUIStartPosition = c.get("JobsGUI.StartPosition", 11); JobsGUIStartPosition = c.get("JobsGUI.StartPosition", 11);
c.getW().addComment("JobsGUI.GroupAmount", "Defines by how many jobs we need to group up"); c.addComment("JobsGUI.GroupAmount", "Defines by how many jobs we need to group up");
JobsGUIGroupAmount = c.get("JobsGUI.GroupAmount", 7); JobsGUIGroupAmount = c.get("JobsGUI.GroupAmount", 7);
c.getW().addComment("JobsGUI.SkipAmount", "Defines by how many slots we need to skip after group"); c.addComment("JobsGUI.SkipAmount", "Defines by how many slots we need to skip after group");
JobsGUISkipAmount = c.get("JobsGUI.SkipAmount", 2); JobsGUISkipAmount = c.get("JobsGUI.SkipAmount", 2);
c.getW().addComment("JobsTop.AmountToShow", "Defines amount of players to be shown in one page for /jobs top & /jobs gtop"); c.addComment("JobsTop.AmountToShow", "Defines amount of players to be shown in one page for /jobs top & /jobs gtop");
JobsTopAmount = c.get("JobsTop.AmountToShow", 15); JobsTopAmount = c.get("JobsTop.AmountToShow", 15);
CMIMaterial tmat = null; CMIMaterial tmat = null;
@ -940,14 +931,10 @@ public class GeneralConfigManager {
tmat = CMIMaterial.get(c.get("JobsGUI.Filler.Material", "STAINED_GLASS_PANE")); tmat = CMIMaterial.get(c.get("JobsGUI.Filler.Material", "STAINED_GLASS_PANE"));
guiFiller = tmat == null ? CMIMaterial.GREEN_STAINED_GLASS_PANE.newItemStack() : tmat.newItemStack(); guiFiller = tmat == null ? CMIMaterial.GREEN_STAINED_GLASS_PANE.newItemStack() : tmat.newItemStack();
// c.getW().addComment("Schedule.Boost.Enable", "Do you want to enable scheduler for global boost?"); // c.addComment("Schedule.Boost.Enable", "Do you want to enable scheduler for global boost?");
// useGlobalBoostScheduler = c.get("Schedule.Boost.Enable", false); // useGlobalBoostScheduler = c.get("Schedule.Boost.Enable", false);
try { c.save();
c.getW().save(f);
} catch (IOException e) {
e.printStackTrace();
}
} }
public int getSelectionTooldID() { public int getSelectionTooldID() {
@ -1038,4 +1025,8 @@ public class GeneralConfigManager {
return generalMulti.get(type); return generalMulti.get(type);
} }
public ConfigReader getConfig() {
return c;
}
} }

View File

@ -1,7 +1,6 @@
package com.gamingmesh.jobs.config; package com.gamingmesh.jobs.config;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
@ -13,10 +12,8 @@ import java.util.List;
import java.util.jar.JarEntry; import java.util.jar.JarEntry;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import org.bukkit.configuration.file.YamlConfiguration;
import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.container.LocaleReader; import com.gamingmesh.jobs.CMILib.ConfigReader;
public class LanguageManager { public class LanguageManager {
@ -116,12 +113,15 @@ public class LanguageManager {
f = new File(Jobs.getFolder(), "locale" + File.separator + "messages_" + lang + ".yml"); f = new File(Jobs.getFolder(), "locale" + File.separator + "messages_" + lang + ".yml");
} }
YamlConfiguration config = YamlConfiguration.loadConfiguration(f); ConfigReader c = null;
CommentedYamlConfiguration writer = new CommentedYamlConfiguration(); try {
c = new ConfigReader(f);
LocaleReader c = new LocaleReader(config, writer); } catch (Exception e) {
e.printStackTrace();
c.getC().options().copyDefaults(true); }
if (c == null)
continue;
c.copyDefaults(true);
Jobs.getGCManager().commandArgs.clear(); Jobs.getGCManager().commandArgs.clear();
@ -310,7 +310,6 @@ public class LanguageManager {
c.get("command.placeholders.output.outputResult", " &eresult: &7[result]"); c.get("command.placeholders.output.outputResult", " &eresult: &7[result]");
c.get("command.placeholders.output.parse", "&6[placeholder] &7by [source] &6result &8|&f[result]&8|"); c.get("command.placeholders.output.parse", "&6[placeholder] &7by [source] &6result &8|&f[result]&8|");
c.get("command.entitylist.help.info", "Shows all possible entities that can be used with the plugin."); c.get("command.entitylist.help.info", "Shows all possible entities that can be used with the plugin.");
c.get("command.entitylist.help.args", ""); c.get("command.entitylist.help.args", "");
@ -677,11 +676,7 @@ public class LanguageManager {
Jobs.getGCManager().keys = new ArrayList<>(c.getC().getConfigurationSection("signs.secondline").getKeys(false)); Jobs.getGCManager().keys = new ArrayList<>(c.getC().getConfigurationSection("signs.secondline").getKeys(false));
// Write back config // Write back config
try { c.save();
c.getW().save(f);
} catch (IOException e) {
e.printStackTrace();
}
} }
} }
} }

View File

@ -10,10 +10,10 @@ import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.CMILib.ConfigReader;
import com.gamingmesh.jobs.CMILib.ItemManager.CMIEntityType; import com.gamingmesh.jobs.CMILib.ItemManager.CMIEntityType;
import com.gamingmesh.jobs.CMILib.ItemManager.CMIMaterial; import com.gamingmesh.jobs.CMILib.ItemManager.CMIMaterial;
import com.gamingmesh.jobs.container.JobInfo; import com.gamingmesh.jobs.container.JobInfo;
import com.gamingmesh.jobs.container.LocaleReader;
import com.gamingmesh.jobs.container.NameList; import com.gamingmesh.jobs.container.NameList;
public class NameTranslatorManager { public class NameTranslatorManager {
@ -256,13 +256,16 @@ public class NameTranslatorManager {
f.delete(); f.delete();
f = new File(Jobs.getFolder(), "TranslatableWords" + File.separator + "Words_" + lang + ".yml"); f = new File(Jobs.getFolder(), "TranslatableWords" + File.separator + "Words_" + lang + ".yml");
} }
ConfigReader c = null;
try {
c = new ConfigReader(f);
} catch (Exception e) {
e.printStackTrace();
}
if (c == null)
continue;
YamlConfiguration config = YamlConfiguration.loadConfiguration(f); c.copyDefaults(true);
CommentedYamlConfiguration writer = new CommentedYamlConfiguration();
LocaleReader c = new LocaleReader(config, writer);
c.getC().options().copyDefaults(true);
for (CMIMaterial one : CMIMaterial.values()) { for (CMIMaterial one : CMIMaterial.values()) {
if (one.getMaterial() == null) if (one.getMaterial() == null)
@ -499,11 +502,7 @@ public class NameTranslatorManager {
c.get("PotionNamesList." + one.getLegacyData() + "-" + one.toString(), name); c.get("PotionNamesList." + one.getLegacyData() + "-" + one.toString(), name);
} }
try { c.save();
c.getW().save(f);
} catch (IOException e) {
e.printStackTrace();
}
} }
readFile(); readFile();
} }

View File

@ -3,13 +3,14 @@ package com.gamingmesh.jobs.config;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.container.LocaleReader; import com.gamingmesh.jobs.CMILib.ConfigReader;
import com.gamingmesh.jobs.container.Title; import com.gamingmesh.jobs.container.Title;
import com.gamingmesh.jobs.stuff.ChatColor; import com.gamingmesh.jobs.stuff.ChatColor;
@ -49,35 +50,26 @@ public class TitleManager {
synchronized void load() { synchronized void load() {
this.titles.clear(); this.titles.clear();
File f = new File(Jobs.getFolder(), "titleConfig.yml"); ConfigReader c = null;
YamlConfiguration config = YamlConfiguration.loadConfiguration(f); try {
CommentedYamlConfiguration writer = new CommentedYamlConfiguration(); c = new ConfigReader("titleConfig.yml");
} catch (Exception e) {
e.printStackTrace();
}
if (c == null)
return;
c.copyDefaults(true);
LocaleReader c = new LocaleReader(config, writer); c.header(Arrays.asList(
"Title configuration",
StringBuilder header = new StringBuilder() "Stores the titles people gain at certain levels.",
.append("Title configuration") "Each title requres to have a name, short name (used when the player has more than",
.append(System.getProperty("line.separator")) "1 job) the colour of the title and the level requrirement to attain the title.",
.append(System.getProperty("line.separator")) "It is recommended but not required to have a title at level 0.",
.append("Stores the titles people gain at certain levels.") "Titles are completely optional.",
.append(System.getProperty("line.separator")) "Posible variable are {level} to add current jobs level.",
.append("Each title requres to have a name, short name (used when the player has more than") "Optionaly you can set different titles based by job.",
.append(System.getProperty("line.separator")) " JobName: Miner"));
.append("1 job) the colour of the title and the level requrirement to attain the title.")
.append(System.getProperty("line.separator"))
.append(System.getProperty("line.separator"))
.append("It is recommended but not required to have a title at level 0.")
.append(System.getProperty("line.separator"))
.append(System.getProperty("line.separator"))
.append("Titles are completely optional.")
.append(System.getProperty("line.separator"))
.append("Posible variable are {level} to add current jobs level.")
.append(System.getProperty("line.separator"))
.append("Optionaly you can set different titles based by job.")
.append(System.getProperty("line.separator"))
.append(" JobName: Miner");
c.getC().options().header(header.toString());
c.getC().options().copyDefaults(true);
ConfigurationSection titleSection = c.getC().getConfigurationSection("Titles"); ConfigurationSection titleSection = c.getC().getConfigurationSection("Titles");
if (titleSection == null) { if (titleSection == null) {
@ -138,11 +130,7 @@ public class TitleManager {
ChatColor.matchColor(c.get("Titles.Legendary.ChatColour", "BLACK")), ChatColor.matchColor(c.get("Titles.Legendary.ChatColour", "BLACK")),
c.get("Titles.Legendary.levelReq", 200), c.get("Titles.Legendary.levelReq", 200),
null)); null));
try { c.save();
c.getC().save(f);
} catch (IOException e) {
e.printStackTrace();
}
} else } else
for (String titleKey : titleSection.getKeys(false)) { for (String titleKey : titleSection.getKeys(false)) {
String jobName = null; String jobName = null;

View File

@ -1,80 +0,0 @@
package com.gamingmesh.jobs.container;
import java.util.List;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.ChatColor;
import com.gamingmesh.jobs.config.CommentedYamlConfiguration;
public class LocaleReader {
private YamlConfiguration config;
private CommentedYamlConfiguration writer;
public LocaleReader(YamlConfiguration config, CommentedYamlConfiguration writer) {
this.config = config;
this.writer = writer;
}
public CommentedYamlConfiguration getW() {
return writer;
}
public YamlConfiguration getC() {
return config;
}
public Boolean get(String path, Boolean boo) {
config.addDefault(path, boo);
copySetting(path);
return config.getBoolean(path);
}
public int get(String path, int boo) {
config.addDefault(path, boo);
copySetting(path);
return config.getInt(path);
}
public List<Integer> getIntList(String path, List<Integer> list) {
config.addDefault(path, list);
copySetting(path);
return config.getIntegerList(path);
}
public List<String> getStringList(String path, List<String> list) {
config.addDefault(path, list);
copySetting(path);
return config.getStringList(path);
}
public List<String> get(String path, List<String> list) {
config.addDefault(path, list);
copySetting(path);
return config.getStringList(path);
}
public String get(String path, String boo) {
config.addDefault(path, boo);
copySetting(path);
return get(path, boo, true);
}
public String get(String path, String boo, boolean colorize) {
config.addDefault(path, boo);
copySetting(path);
if (colorize)
return ChatColor.translateAlternateColorCodes('&', config.getString(path));
return config.getString(path);
}
public Double get(String path, Double boo) {
config.addDefault(path, boo);
copySetting(path);
return config.getDouble(path);
}
public synchronized void copySetting(String path) {
writer.set(path, config.get(path));
}
}

View File

@ -6,7 +6,7 @@ import java.io.IOException;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.container.LocaleReader; import com.gamingmesh.jobs.CMILib.ConfigReader;
public class JobsManager { public class JobsManager {
private JobsDAO dao; private JobsDAO dao;
@ -54,18 +54,29 @@ public class JobsManager {
Jobs.setDAO(dao); Jobs.setDAO(dao);
} }
public void start(LocaleReader c) { String username = "root";
c.getW().addComment("storage.method", "storage method, can be MySQL or sqlite"); String password = "";
String hostname = "localhost:3306";
String database = "minecraft";
String prefix = "jobs_";
boolean certificate = false;
boolean ssl = false;
boolean autoReconnect = false;
public void start() {
ConfigReader c = Jobs.getGCManager().getConfig();
c.addComment("storage.method", "storage method, can be MySQL or sqlite");
String storageMethod = c.get("storage.method", "sqlite"); String storageMethod = c.get("storage.method", "sqlite");
c.getW().addComment("mysql", "Requires Mysql."); c.addComment("mysql", "Requires Mysql.");
c.get("mysql.username", "root");
c.get("mysql.password", ""); username = c.get("mysql.username", c.getC().getString("mysql-username", "root"));
c.get("mysql.hostname", "localhost:3306"); password = c.get("mysql.password", c.getC().getString("mysql-password", ""));
c.get("mysql.database", "minecraft"); hostname = c.get("mysql.hostname", c.getC().getString("mysql-hostname", "localhost:3306"));
c.get("mysql.table-prefix", "jobs_"); database = c.get("mysql.database", c.getC().getString("mysql-database", "minecraft"));
c.get("mysql.verify-server-certificate", false); prefix = c.get("mysql.table-prefix", c.getC().getString("mysql-table-prefix", "jobs_"));
c.get("mysql.use-ssl", false); certificate = c.get("mysql.verify-server-certificate", c.getC().getBoolean("verify-server-certificate", false));
c.get("mysql.auto-reconnect", false); ssl = c.get("mysql.use-ssl", c.getC().getBoolean("use-ssl", false));
autoReconnect = c.get("mysql.auto-reconnect", c.getC().getBoolean("auto-reconnect", true));
if (storageMethod.equalsIgnoreCase("mysql")) { if (storageMethod.equalsIgnoreCase("mysql")) {
DbType = DataBaseType.MySQL; DbType = DataBaseType.MySQL;
@ -75,7 +86,7 @@ public class JobsManager {
dao = startSqlite(); dao = startSqlite();
} else { } else {
Jobs.consoleMsg("&cInvalid storage method! Changing method to sqlite!"); Jobs.consoleMsg("&cInvalid storage method! Changing method to sqlite!");
c.getC().set("storage.method", "sqlite"); c.set("storage.method", "sqlite");
DbType = DataBaseType.SqLite; DbType = DataBaseType.SqLite;
dao = startSqlite(); dao = startSqlite();
} }
@ -83,32 +94,26 @@ public class JobsManager {
} }
private synchronized JobsMySQL startMysql() { private synchronized JobsMySQL startMysql() {
File f = new File(Jobs.getFolder(), "generalConfig.yml");
YamlConfiguration config = YamlConfiguration.loadConfiguration(f); ConfigReader c = Jobs.getGCManager().getConfig();
String legacyUrl = config.getString("mysql.url");
String legacyUrl = c.getC().getString("mysql.url");
if (legacyUrl != null) { if (legacyUrl != null) {
String jdbcString = "jdbc:mysql://"; String jdbcString = "jdbc:mysql://";
if (legacyUrl.toLowerCase().startsWith(jdbcString)) { if (legacyUrl.toLowerCase().startsWith(jdbcString)) {
legacyUrl = legacyUrl.substring(jdbcString.length()); legacyUrl = legacyUrl.substring(jdbcString.length());
String[] parts = legacyUrl.split("/"); String[] parts = legacyUrl.split("/");
if (parts.length >= 2) { if (parts.length >= 2) {
config.set("mysql.hostname", parts[0]); hostname = c.get("mysql.hostname", parts[0]);
config.set("mysql.database", parts[1]); database = c.get("mysql.database", parts[1]);
} }
} }
} }
String username = config.getString("mysql.username");
if (username == null) { if (username == null) {
Jobs.getPluginLogger().severe("mysql username property invalid or missing"); 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");
boolean certificate = config.getBoolean("mysql.verify-server-certificate", false);
boolean ssl = config.getBoolean("mysql.use-ssl", false);
boolean autoReconnect = config.getBoolean("mysql.auto-reconnect");
if (plugin.isEnabled()) { if (plugin.isEnabled()) {
JobsMySQL data = new JobsMySQL(plugin, hostname, database, username, password, prefix, certificate, ssl, autoReconnect); JobsMySQL data = new JobsMySQL(plugin, hostname, database, username, password, prefix, certificate, ssl, autoReconnect);
data.initialize(); data.initialize();

View File

@ -122,17 +122,19 @@ public class JobsMySQL extends JobsDAO {
Jobs.consoleMsg("&cCould not create table: query is empty or null."); Jobs.consoleMsg("&cCould not create table: query is empty or null.");
return false; return false;
} }
JobsConnection conn = getConnection();
if (conn == null)
return false;
try { try {
statement = getConnection().createStatement(); statement = conn.createStatement();
statement.execute(query); statement.execute(query);
statement.close(); statement.close();
} catch (SQLException e) { } catch (SQLException e) {
Jobs.consoleMsg("&cCould not create table, SQLException: " + e.getMessage()); Jobs.consoleMsg("&cCould not create table, SQLException: " + e.getMessage());
close(statement); this.close(statement);
return false; return false;
} finally { } finally {
close(statement); this.close(statement);
} }
return true; return true;
} }
@ -140,19 +142,41 @@ public class JobsMySQL extends JobsDAO {
@Override @Override
public boolean isTable(String table) { public boolean isTable(String table) {
Statement statement; Statement statement;
JobsConnection conn = getConnection();
if (conn == null)
return false;
try { try {
statement = getConnection().createStatement(); statement = conn.createStatement();
} catch (SQLException e) { } catch (SQLException e) {
Jobs.consoleMsg("&cCould not check if its table, SQLException: " + e.getMessage()); Jobs.consoleMsg("&cCould not check if its table, SQLException: " + e.getMessage());
return false; return false;
} }
try { try {
statement.executeQuery("SELECT * FROM `" + table+"`;"); ResultSet tables = conn.getMetaData().getTables(null, null, table, null);
statement.close(); if (tables.next()) {
tables.close();
return true; return true;
}
tables.close();
return false;
} catch (SQLException e) { } catch (SQLException e) {
// Jobs.consoleMsg("Not a table |" + "SELECT * FROM " + table + "|"); Jobs.consoleMsg("Not a table |" + "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME ='" + table + "';" + "|");
close(statement); }
try {
PreparedStatement insert = conn.prepareStatement("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME ='" + table + "';");
ResultSet res = insert.executeQuery();
if (res.next()) {
res.close();
insert.close();
return true;
}
res.close();
insert.close();
return false;
} catch (SQLException e) {
Jobs.consoleMsg("Not a table |" + "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME ='" + table + "';" + "|");
JobsDAO.close(statement);
return false; return false;
} }
} }