mirror of
https://github.com/Zrips/Jobs.git
synced 2024-11-26 04:25:15 +01:00
parent
580ce6d555
commit
ef4927c23f
@ -60,7 +60,6 @@ import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@ -672,13 +671,10 @@ public class Jobs extends JavaPlugin {
|
||||
placeholderAPIEnabled = setupPlaceHolderAPI();
|
||||
|
||||
try {
|
||||
YmlMaker jobConfig = new YmlMaker(this, "jobConfig.yml");
|
||||
jobConfig.saveDefaultConfig();
|
||||
|
||||
YmlMaker jobShopItems = new YmlMaker(this, "shopItems.yml");
|
||||
YmlMaker jobShopItems = new YmlMaker(getFolder(), "shopItems.yml");
|
||||
jobShopItems.saveDefaultConfig();
|
||||
|
||||
YmlMaker restrictedBlocks = new YmlMaker(this, "restrictedBlocks.yml");
|
||||
YmlMaker restrictedBlocks = new YmlMaker(getFolder(), "restrictedBlocks.yml");
|
||||
restrictedBlocks.saveDefaultConfig();
|
||||
|
||||
bbManager = new BossBarManager(this);
|
||||
@ -691,7 +687,7 @@ public class Jobs extends JavaPlugin {
|
||||
startup();
|
||||
|
||||
if (getGCManager().SignsEnabled) {
|
||||
YmlMaker jobSigns = new YmlMaker(this, "Signs.yml");
|
||||
YmlMaker jobSigns = new YmlMaker(getFolder(), "Signs.yml");
|
||||
jobSigns.saveDefaultConfig();
|
||||
}
|
||||
|
||||
|
@ -251,7 +251,7 @@ public class editjobs implements Cmd {
|
||||
break;
|
||||
}
|
||||
|
||||
Jobs.getConfigManager().changeJobsSettings(jInfo.getConfigPath() + "/" + sType, value);
|
||||
Jobs.getConfigManager().changeJobsSettings(args[1], jInfo.getConfigPath() + "/" + sType, value);
|
||||
player.performCommand("jobs editjobs list " + job.getName() + " " + actionT.getName() + " " + jInfo.getName());
|
||||
Util.getJobsEditorMap().remove(player.getUniqueId());
|
||||
return true;
|
||||
@ -287,7 +287,7 @@ public class editjobs implements Cmd {
|
||||
}
|
||||
|
||||
action.remove(jInfo);
|
||||
Jobs.getConfigManager().changeJobsSettings(jInfo.getConfigPath(), null);
|
||||
Jobs.getConfigManager().changeJobsSettings(args[1], jInfo.getConfigPath(), null);
|
||||
player.performCommand("jobs editjobs list " + job.getName() + " " + actionT.getName() + " 1");
|
||||
Util.getJobsEditorMap().remove(player.getUniqueId());
|
||||
return true;
|
||||
@ -383,9 +383,9 @@ public class editjobs implements Cmd {
|
||||
action.add(jInfo);
|
||||
player.performCommand("jobs editjobs list " + job.getName() + " " + actionT.getName() + " " + jInfo.getName());
|
||||
|
||||
Jobs.getConfigManager().changeJobsSettings(jInfo.getConfigPath() + "/income", 0);
|
||||
Jobs.getConfigManager().changeJobsSettings(jInfo.getConfigPath() + "/points", 0);
|
||||
Jobs.getConfigManager().changeJobsSettings(jInfo.getConfigPath() + "/experience", 0);
|
||||
Jobs.getConfigManager().changeJobsSettings(args[1], jInfo.getConfigPath() + "/income", 0);
|
||||
Jobs.getConfigManager().changeJobsSettings(args[1], jInfo.getConfigPath() + "/points", 0);
|
||||
Jobs.getConfigManager().changeJobsSettings(args[1], jInfo.getConfigPath() + "/experience", 0);
|
||||
|
||||
Util.getJobsEditorMap().remove(player.getUniqueId());
|
||||
return true;
|
||||
|
@ -222,8 +222,8 @@ public class editquests implements Cmd {
|
||||
String j = "Jobs." + job.getJobKeyName() + ".Quests." + q.getConfigName() + ".";
|
||||
|
||||
if (file.isString(j + "Target")) {
|
||||
Jobs.getConfigManager().changeJobsSettings(file.getString(j + "Target"), target);
|
||||
Jobs.getConfigManager().changeJobsSettings(file.getString(j + "Action"), actionT.getName());
|
||||
Jobs.getConfigManager().changeJobsSettings(args[1], file.getString(j + "Target"), target);
|
||||
Jobs.getConfigManager().changeJobsSettings(args[1], file.getString(j + "Action"), actionT.getName());
|
||||
} else if (file.isList(j + "Objectives")) {
|
||||
List<String> list = file.getStringList(j + "Objectives");
|
||||
for (String s : list) {
|
||||
@ -561,8 +561,8 @@ public class editquests implements Cmd {
|
||||
String j = "Jobs." + job.getJobKeyName() + ".Quests." + q.getConfigName() + ".";
|
||||
|
||||
if (file.isString(j + "Target")) {
|
||||
Jobs.getConfigManager().changeJobsSettings(file.getString(j + "Target"), (type + subType).toLowerCase());
|
||||
Jobs.getConfigManager().changeJobsSettings(file.getString(j + "Action"), actionT.getName());
|
||||
Jobs.getConfigManager().changeJobsSettings(args[1], file.getString(j + "Target"), (type + subType).toLowerCase());
|
||||
Jobs.getConfigManager().changeJobsSettings(args[1], file.getString(j + "Action"), actionT.getName());
|
||||
} else if (file.isList(j + "Objectives")) {
|
||||
List<String> list = file.getStringList(j + "Objectives");
|
||||
list.add(actionT.getName() + ";" + (type + subType).toLowerCase() + ";" + amount);
|
||||
|
@ -22,321 +22,72 @@ import com.gamingmesh.jobs.CMILib.CMIChatColor;
|
||||
import com.gamingmesh.jobs.CMILib.CMIEnchantment;
|
||||
import com.gamingmesh.jobs.CMILib.CMIEntityType;
|
||||
import com.gamingmesh.jobs.CMILib.CMIMaterial;
|
||||
import com.gamingmesh.jobs.CMILib.ConfigReader;
|
||||
import com.gamingmesh.jobs.CMILib.Version;
|
||||
import com.gamingmesh.jobs.ItemBoostManager;
|
||||
import com.gamingmesh.jobs.Jobs;
|
||||
import com.gamingmesh.jobs.container.*;
|
||||
import com.gamingmesh.jobs.resources.jfep.ParseError;
|
||||
import com.gamingmesh.jobs.resources.jfep.Parser;
|
||||
import com.gamingmesh.jobs.stuff.Util;
|
||||
|
||||
import org.apache.commons.lang.StringEscapeUtils;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class ConfigManager {
|
||||
|
||||
@Deprecated
|
||||
private File jobFile;
|
||||
private File jobsPathFolder;
|
||||
|
||||
private final Set<YmlMaker> jobFiles = new HashSet<>();
|
||||
|
||||
public ConfigManager() {
|
||||
this.jobFile = new File(Jobs.getFolder(), "jobConfig.yml");
|
||||
updateFile();
|
||||
this.jobsPathFolder = new File(Jobs.getFolder(), "jobs");
|
||||
|
||||
migrateJobs();
|
||||
}
|
||||
|
||||
private void updateFile() {
|
||||
ConfigReader cfg = new ConfigReader(jobFile);
|
||||
|
||||
cfg.header(Arrays.asList("Jobs configuration.", "", "Edited by roracle to include 1.13 items and item names, prepping for 1.14 as well.",
|
||||
"",
|
||||
"Stores information about each job.",
|
||||
"",
|
||||
"NOTE: When having multiple jobs, both jobs will give the income payout to the player",
|
||||
"even if they give the pay for one action (make the configurations with this in mind)",
|
||||
"and each job will get the respective experience.",
|
||||
"",
|
||||
"e.g If player has 2 jobs where job1 gives 10 income and experience for killing a player ",
|
||||
"and job2 gives 5 income and experience for killing a player. When the user kills a player",
|
||||
"they will get 15 income and job1 will gain 10 experience and job2 will gain 5 experience."));
|
||||
|
||||
if (!cfg.contains("Jobs")) {
|
||||
cfg.set("Jobs", cfg.getC().get("Jobs"));
|
||||
}
|
||||
|
||||
String pt = "Jobs.exampleJob";
|
||||
cfg.addComment(pt, "Must be one word",
|
||||
"This job will be ignored as this is just example of all possible actions.");
|
||||
cfg.addComment(pt + ".fullname", "full name of the job (displayed when browsing a job, used when joining and leaving",
|
||||
"also can be used as a prefix for the user's name if the option is enabled.",
|
||||
"Shown as a prefix only when the user has 1 job.",
|
||||
"",
|
||||
"NOTE: Must be 1 word");
|
||||
cfg.get(pt + ".fullname", "Woodcutter");
|
||||
|
||||
cfg.addComment(pt + ".shortname", "Shortened version of the name of the job. Used as a prefix when the user has more than 1 job.");
|
||||
cfg.get(pt + ".shortname", "W");
|
||||
cfg.get(pt + ".description", "Earns money felling and planting trees");
|
||||
|
||||
cfg.addComment(pt + ".FullDescription", "Full description of job to be shown in job browse command");
|
||||
cfg.get(pt + ".FullDescription", Arrays.asList("&2Get money for:", " &7Planting trees", " &7Cutting down trees", " &7Killing players"));
|
||||
|
||||
cfg.addComment(pt + ".ChatColour",
|
||||
"The colour of the name, for a full list of supported colours, go to the message config. Hex color codes are supported as of 1.16 minecraft version. Example: {#6600cc} or {#Brown}");
|
||||
cfg.get(pt + ".ChatColour", "GREEN");
|
||||
|
||||
cfg.addComment(pt + ".BossBarColour", "[OPTIONAL] The colour of the boss bar: GREEN, BLUE, RED, WHITE, YELLOW, PINK, PURPLE.");
|
||||
cfg.get(pt + ".BossBarColour", "WHITE");
|
||||
|
||||
cfg.addComment(pt + ".chat-display", "Option to let you choose what kind of prefix this job adds to your name.", "options are: full, title, job, shortfull, shorttitle, shortjob and none");
|
||||
cfg.get(pt + ".chat-display", "full");
|
||||
|
||||
cfg.addComment(pt + ".max-level", "[OPTIONAL] - the maximum level of this class");
|
||||
cfg.get(pt + ".max-level", 10);
|
||||
|
||||
cfg.addComment(pt + ".vip-max-level", "[OPTIONAL] - the maximum level of this class with specific permission",
|
||||
"use jobs.[jobsname].vipmaxlevel, in this case it will be jobs.exampleJob.vipmaxlevel");
|
||||
cfg.get(pt + ".vip-max-level", 20);
|
||||
|
||||
cfg.addComment(pt + ".slots", "[OPTIONAL] - the maximum number of users on the server that can have this job at any one time (includes offline players).");
|
||||
cfg.get(pt + ".slots", 1);
|
||||
|
||||
cfg.addComment(pt + ".softIncomeLimit", "[OPTIONAL] Soft limits will allow to stop income/exp/point payment increase at some particular level but allow further general leveling.",
|
||||
"In example if player is level 70, he will get paid as he would be at level 50, exp gain will be as he would be at lvl 40 and point gain will be as at level 60",
|
||||
"This only applies after players level is higher than provided particular limit.");
|
||||
|
||||
cfg.get(pt + ".softIncomeLimit", 50);
|
||||
cfg.get(pt + ".softExpLimit", 40);
|
||||
cfg.get(pt + ".softPointsLimit", 60);
|
||||
|
||||
cfg.addComment(pt + ".leveling-progression-equation", "Equation used for calculating how much experience is needed to go to the next level.",
|
||||
"Available parameters:",
|
||||
" numjobs - the number of jobs the player has",
|
||||
" maxjobs - the number of jobs the player have max",
|
||||
" joblevel - the level the player has attained in the job.",
|
||||
" NOTE: Please take care of the brackets when modifying this equation.");
|
||||
cfg.get(pt + ".leveling-progression-equation", "10*(joblevel)+(joblevel*joblevel*4)");
|
||||
|
||||
cfg.addComment(pt + ".income-progression-equation", "Equation used for calculating how much income is given per action for the job level.",
|
||||
"Available parameters:",
|
||||
" numjobs - the number of jobs the player has",
|
||||
" maxjobs - the number of jobs the player have max",
|
||||
" baseincome - the income for the action at level 1 (as set in the configuration).",
|
||||
" joblevel - the level the player has attained in the job.",
|
||||
"NOTE: Please take care of the brackets when modifying this equation.");
|
||||
cfg.get(pt + ".income-progression-equation", "baseincome+(baseincome*(joblevel-1)*0.01)-((baseincome+(joblevel-1)*0.01) * ((numjobs-1)*0.05))");
|
||||
|
||||
cfg.addComment(pt + ".points-progression-equation", "Equation used for calculating how much points is given per action for the job level.",
|
||||
"Available parameters:",
|
||||
" numjobs - the number of jobs the player has",
|
||||
" maxjobs - the number of jobs the player have max",
|
||||
" basepoints - the points for the action at level 1 (as set in the configuration).",
|
||||
" joblevel - the level the player has attained in the job.",
|
||||
"NOTE: Please take care of the brackets when modifying this equation.");
|
||||
cfg.get(pt + ".points-progression-equation", "basepoints+(basepoints*(joblevel-1)*0.01)-((basepoints+(joblevel-1)*0.01) * ((numjobs-1)*0.05))");
|
||||
|
||||
cfg.addComment(pt + ".experience-progression-equation", "Equation used for calculating how much experience is given per action for the job level.",
|
||||
"Available parameters:",
|
||||
" numjobs - the number of jobs the player has",
|
||||
" maxjobs - the number of jobs the player have max",
|
||||
" baseexperience - the experience for the action at level 1 (as set in the configuration).",
|
||||
" joblevel - the level the player has attained in the job.",
|
||||
"NOTE: Please take care of the brackets when modifying this equation.");
|
||||
cfg.get(pt + ".experience-progression-equation", "basepoints+(basepoints*(joblevel-1)*0.01)-((basepoints+(joblevel-1)*0.01) * ((numjobs-1)*0.05))");
|
||||
|
||||
cfg.addComment(pt + ".rejoinCooldown", "Defines how often in seconds player can rejoin this job. Can be bypassed with jobs.rejoinbypass");
|
||||
cfg.get(pt + ".rejoinCooldown", 10);
|
||||
|
||||
cfg.addComment(pt + ".Gui", "GUI icon information when using GUI function");
|
||||
cfg.addComment(pt + ".Gui.Item", "You can use the custom player head:",
|
||||
"Item: player_head",
|
||||
" CustomSkull: Notch",
|
||||
"",
|
||||
"Name of the material");
|
||||
cfg.get(pt + ".Gui.Item", "LOG:2");
|
||||
cfg.addComment(pt + ".Gui.slot", "Slot number to show the item in the specified row");
|
||||
cfg.get(pt + ".Gui.slot", 5);
|
||||
cfg.addComment(pt + ".Gui.Enchantments", "Enchants of the item");
|
||||
cfg.get(pt + ".Gui.Enchantments", Arrays.asList("DURABILITY:1"));
|
||||
|
||||
cfg.addComment(pt + ".maxDailyQuests",
|
||||
"Defines maximum amount of daily quests player can have from THIS job",
|
||||
"This will not have effect on overall quest amount player will have");
|
||||
cfg.get(pt + ".maxDailyQuests", 3);
|
||||
|
||||
cfg.addComment(pt + ".Quests", "Daily quests",
|
||||
"Each job can have as many daily quests as you want",
|
||||
"Players will have access to quests from jobs he is currently working at");
|
||||
|
||||
String questPt = pt + ".Quests.first";
|
||||
cfg.addComment(questPt, "Quest identification. Can be any ONE word or number or both of them. This doesn't have any real meaning but it can't repeat.");
|
||||
cfg.addComment(questPt + ".Name", "Quest name used for quests list, don't forget to enclose it with \" \"");
|
||||
cfg.get(questPt + ".Name", "Break Oak wood");
|
||||
cfg.addComment(questPt + ".Objectives", "This should be in a format as [actionType];[actionTarget];[amount]",
|
||||
"[actionType] can be any valid job action. Look lower for all possible action types",
|
||||
"[actionTarget] can be material name, block type, entity name and so on. This is defined in same way as any generic payable job action",
|
||||
"[amount] is how many times player should perform this action to complete quest");
|
||||
cfg.get(questPt + ".Objectives", "Break;oak_log;300");
|
||||
|
||||
cfg.addComment(questPt + ".RewardCommands", "Command list to be performed after quest is finished.",
|
||||
"Use [playerName] to insert players name who finished that quest");
|
||||
cfg.get(questPt + ".RewardCommands", Arrays.asList("money give [playerName] 500", "msg [playerName] Completed quest!"));
|
||||
|
||||
cfg.addComment(questPt + ".RewardDesc", "Quest description to be used to explain quest requirements or rewards for player");
|
||||
cfg.get(questPt + ".RewardDesc", Arrays.asList("Break 300 Oak wood", "Get 500 bucks for this"));
|
||||
|
||||
cfg.addComment(questPt + ".RestrictedAreas", "Restricted areas where player cant progress his quest");
|
||||
cfg.get(questPt + ".RestrictedAreas", Arrays.asList("Arenas", "myarena"));
|
||||
|
||||
cfg.addComment(questPt + ".Chance", "Defines chance in getting this quest.",
|
||||
"If you have set 10 quests and player can have only 2, then quests with biggest chance will be picked most likely",
|
||||
"This will allow to have some rare quests with legendary rewards");
|
||||
cfg.get(questPt + ".Chance", 40);
|
||||
|
||||
cfg.addComment(questPt + ".fromLevel", "Defines from which level you want to give option to get this quest",
|
||||
"You can use both limitations to have limited quests for particular job level ranges");
|
||||
cfg.get(questPt + ".fromLevel", 3);
|
||||
|
||||
cfg.addComment(questPt + ".toLevel", "Defines to which job level you want to give out this quest.",
|
||||
"Keep in mind that player will keep quest even if he is over level limit if he got new one while being under",
|
||||
"In example: player with level 2 takes quests and levels up to level 5, he still can finish this quest and after next quest reset (check general config file)",
|
||||
"he will no longer have option to get this quest");
|
||||
cfg.get(questPt + ".toLevel", 5);
|
||||
|
||||
cfg.addComment(pt + ".Break",
|
||||
"########################################################################",
|
||||
"Section used to configure what items the job gets paid for, how much",
|
||||
"they get paid and how much experience they gain.",
|
||||
"",
|
||||
"For break and place, the block material name is used.",
|
||||
"e.g ACACIA_LOG, DARK_OAK_FENCE, BIRCH_DOOR",
|
||||
"",
|
||||
"To get a list of all available block types, check the",
|
||||
"bukkit JavaDocs for a complete list of block types",
|
||||
"https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html",
|
||||
"",
|
||||
"For kill tags (Kill and custom-kill), the name is the name of the mob.",
|
||||
"To get a list of all available entity types, check the",
|
||||
"bukkit JavaDocs for a complete list of entity types",
|
||||
"https://hub.spigotmc.org/javadocs/spigot/org/bukkit/entity/EntityType.html",
|
||||
"",
|
||||
"For custom-kill, it is the name of the job (case sensitive).",
|
||||
"",
|
||||
"NOTE: If a job has both the pay for killing a player and for killing a specific class, they will get both payments.",
|
||||
"#######################################################################",
|
||||
"payment for breaking a block");
|
||||
|
||||
cfg.addComment(pt + ".Break.oak_log", "block name/id (with optional sub-type)");
|
||||
cfg.addComment(pt + ".Break.oak_log.income", "base income, can be not used if using point system");
|
||||
cfg.get(pt + ".Break.oak_log.income", 5D);
|
||||
cfg.addComment(pt + ".Break.oak_log.points", "base points, can be not used if using income system");
|
||||
cfg.get(pt + ".Break.oak_log.points", 5D);
|
||||
cfg.addComment(pt + ".Break.oak_log.experience", "base experience");
|
||||
cfg.get(pt + ".Break.oak_log.experience", 5D);
|
||||
cfg.addComment(pt + ".Break.oak_log.from-level", "(OPTIONAL) from which level of this job player can get money for this action",
|
||||
"if not given, then player will always get money for this action",
|
||||
"this can be used for any action");
|
||||
cfg.get(pt + ".Break.oak_log.from-level", 1);
|
||||
cfg.addComment(pt + ".Break.oak_log.until-level", "(OPTIONAL) until which level player can get money for this action.",
|
||||
"if not given, then there is no limit",
|
||||
"this can be used for any action");
|
||||
cfg.get(pt + ".Break.oak_log.until-level", 30);
|
||||
cfg.addComment(pt + ".Break.oak_log.softIncomeLimit", "(OPTIONAL) Soft limits will allow to stop income/exp/point payment increase at some particular level but allow further general leveling.",
|
||||
"In example if player is level 70, he will get paid as he would be at level 50, exp gain will be as he would be at lvl 40 and point gain will be as at level 60",
|
||||
"This only applies after players level is higher than provided particular limit.");
|
||||
cfg.get(pt + ".Break.oak_log.softIncomeLimit", 50);
|
||||
cfg.get(pt + ".Break.oak_log.softExpLimit", 40);
|
||||
cfg.get(pt + ".Break.oak_log.softPointsLimit", 60);
|
||||
|
||||
cfg.addComment(pt + ".Break.gravel.income", "you can use minuses to take away money if the player break this block");
|
||||
cfg.get(pt + ".Break.gravel.income", -1D);
|
||||
|
||||
cfg.addComment(pt + ".permissions.firstNode.permission", "The permission node");
|
||||
cfg.get(pt + ".permissions.firstNode.permission", "aaaaaatest.node");
|
||||
|
||||
cfg.save();
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
// job settings
|
||||
try {
|
||||
loadJobSettings();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
/**
|
||||
* Returns all of existing jobs files in Jobs/jobs folder
|
||||
*
|
||||
* @return {@link HashSet}
|
||||
*/
|
||||
public Set<YmlMaker> getJobFiles() {
|
||||
return jobFiles;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public YamlConfiguration getJobConfig() {
|
||||
if (!jobFile.exists()) {
|
||||
Jobs.getPluginLogger().severe("Unable to load jobConfig.yml!");
|
||||
return null;
|
||||
}
|
||||
|
||||
return YamlConfiguration.loadConfiguration(jobFile);
|
||||
return !jobFile.exists() ? null : YamlConfiguration.loadConfiguration(jobFile);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public File getJobFile() {
|
||||
return jobFile;
|
||||
}
|
||||
|
||||
public void changeJobsSettings(String path, Object value) {
|
||||
InputStreamReader s = null;
|
||||
try {
|
||||
s = new InputStreamReader(new FileInputStream(jobFile), StandardCharsets.UTF_8);
|
||||
} catch (FileNotFoundException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
if (!jobFile.exists()) {
|
||||
try {
|
||||
jobFile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
Jobs.getPluginLogger().severe("Unable to create jobConfig.yml! No jobs were loaded!");
|
||||
try {
|
||||
if (s != null)
|
||||
s.close();
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
return;
|
||||
public void changeJobsSettings(String jobName, String path, Object value) {
|
||||
for (YmlMaker yml : jobFiles) {
|
||||
if (yml.getConfigFile().getName().contains(jobName.toLowerCase())) {
|
||||
yml.getConfig().set(path, value);
|
||||
yml.saveConfig();
|
||||
break;
|
||||
}
|
||||
}
|
||||
YamlConfiguration conf = new YamlConfiguration();
|
||||
conf.options().pathSeparator('/');
|
||||
try {
|
||||
conf.load(s);
|
||||
} catch (Exception e) {
|
||||
Jobs.getPluginLogger().severe("==================== Jobs ====================");
|
||||
Jobs.getPluginLogger().severe("Unable to load jobConfig.yml!");
|
||||
Jobs.getPluginLogger().severe("Check your config for formatting issues!");
|
||||
Jobs.getPluginLogger().severe("No jobs were loaded!");
|
||||
Jobs.getPluginLogger().severe("Error: " + e.getMessage());
|
||||
Jobs.getPluginLogger().severe("==============================================");
|
||||
return;
|
||||
} finally {
|
||||
if (s != null)
|
||||
try {
|
||||
s.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
conf.set(path, value);
|
||||
|
||||
try {
|
||||
conf.save(jobFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public class KeyValues {
|
||||
@ -643,76 +394,129 @@ public class ConfigManager {
|
||||
return kv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to load the jobs configuration
|
||||
*
|
||||
* loads from Jobs/jobConfig.yml
|
||||
* @throws IOException
|
||||
*/
|
||||
private void loadJobSettings() throws IOException {
|
||||
if (!jobFile.exists()) {
|
||||
YmlMaker jobConfig = new YmlMaker(Jobs.getInstance(), "jobConfig.yml");
|
||||
jobConfig.saveDefaultConfig();
|
||||
private boolean migrateJobs() {
|
||||
YamlConfiguration oldConf = getJobConfig();
|
||||
if (oldConf == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
InputStreamReader s = new InputStreamReader(new FileInputStream(jobFile), StandardCharsets.UTF_8);
|
||||
java.util.logging.Logger log = Jobs.getPluginLogger();
|
||||
|
||||
if (!jobFile.exists()) {
|
||||
if (!jobsPathFolder.exists()) {
|
||||
oldConf.set("migratedToNewFile", false);
|
||||
try {
|
||||
jobFile.createNewFile();
|
||||
oldConf.save(jobFile);
|
||||
} catch (IOException e) {
|
||||
log.severe("Unable to create jobConfig.yml! No jobs were loaded!");
|
||||
s.close();
|
||||
return;
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
jobsPathFolder.mkdirs();
|
||||
}
|
||||
|
||||
if (oldConf.getBoolean("migratedToNewFile")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
ConfigurationSection jobsSection = oldConf.getConfigurationSection("Jobs");
|
||||
if (jobsSection == null || jobsSection.getKeys(false).isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
jobFiles.clear();
|
||||
|
||||
Jobs.getPluginLogger().warning("Your jobConfig.yml file is not works anymore and can cause issues!");
|
||||
Jobs.getPluginLogger().warning("We've starting migrating your jobConfig file data into separate files to avoid any loss.");
|
||||
Jobs.getPluginLogger().warning("The jobConfig file will get removed in future releases!");
|
||||
|
||||
Jobs.getPluginLogger().info("Started migrating jobConfig to /jobs folder...");
|
||||
|
||||
for (String jobKey : jobsSection.getKeys(false)) {
|
||||
// Ignore example job
|
||||
if (jobKey.equalsIgnoreCase("exampleJob"))
|
||||
continue;
|
||||
|
||||
YmlMaker newJobFile = new YmlMaker(jobsPathFolder, jobKey.toLowerCase() + ".yml");
|
||||
if (!newJobFile.exists()) {
|
||||
newJobFile.createNewFile();
|
||||
}
|
||||
|
||||
FileConfiguration conf = newJobFile.getConfig();
|
||||
conf.options().pathSeparator('/');
|
||||
|
||||
for (Map.Entry<String, Object> m : jobsSection.getValues(true).entrySet()) {
|
||||
if (m.getKey().equalsIgnoreCase(jobKey)) {
|
||||
conf.set(m.getKey(), m.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
newJobFile.saveConfig();
|
||||
jobFiles.add(newJobFile);
|
||||
}
|
||||
|
||||
if (!jobFiles.isEmpty()) {
|
||||
Jobs.getPluginLogger().info("Done. Migrated jobs amount: " + jobFiles.size());
|
||||
|
||||
oldConf.set("migratedToNewFile", true);
|
||||
try {
|
||||
oldConf.save(jobFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
YamlConfiguration conf = new YamlConfiguration();
|
||||
conf.options().pathSeparator('/');
|
||||
try {
|
||||
conf.load(s);
|
||||
} catch (Exception e) {
|
||||
log.severe("==================== Jobs ====================");
|
||||
log.severe("Unable to load jobConfig.yml!");
|
||||
log.severe("Check your config for formatting issues!");
|
||||
log.severe("No jobs were loaded!");
|
||||
log.severe("Error: " + e.getMessage());
|
||||
log.severe("==============================================");
|
||||
return;
|
||||
} finally {
|
||||
s.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
migrateJobs();
|
||||
|
||||
if (jobFiles.isEmpty()) {
|
||||
for (File file : jobsPathFolder.listFiles((dir, name) -> name.toLowerCase().endsWith(".yml"))) {
|
||||
jobFiles.add(new YmlMaker(jobsPathFolder, file));
|
||||
}
|
||||
}
|
||||
|
||||
ConfigurationSection jobsSection = conf.getConfigurationSection("Jobs");
|
||||
if (jobsSection == null) {
|
||||
log.severe("==================== Jobs ====================");
|
||||
log.severe("Jobs section not found in jobConfig file!");
|
||||
log.severe("Check the config for fix the issue.");
|
||||
log.severe("==============================================");
|
||||
if (jobFiles.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayList<Job> jobs = new ArrayList<>();
|
||||
List<Job> jobs = new ArrayList<>();
|
||||
for (YmlMaker conf : jobFiles) {
|
||||
Job job = loadJobs(conf.getConfig().getConfigurationSection(""));
|
||||
if (job != null) {
|
||||
jobs.add(job);
|
||||
}
|
||||
}
|
||||
|
||||
Jobs.setJobs(jobs);
|
||||
|
||||
if (!jobs.isEmpty()) {
|
||||
Jobs.consoleMsg("&e[Jobs] Loaded " + jobs.size() + " jobs!");
|
||||
}
|
||||
|
||||
ItemBoostManager.load();
|
||||
}
|
||||
|
||||
private Job loadJobs(ConfigurationSection jobsSection) {
|
||||
java.util.logging.Logger log = Jobs.getPluginLogger();
|
||||
|
||||
for (String jobKey : jobsSection.getKeys(false)) {
|
||||
// Ignoring example job
|
||||
if (jobKey.equalsIgnoreCase("exampleJob"))
|
||||
// Ignore example job
|
||||
if (jobKey.equalsIgnoreCase("exampleJob")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Translating unicode
|
||||
jobKey = StringEscapeUtils.unescapeJava(jobKey);
|
||||
|
||||
ConfigurationSection jobSection = jobsSection.getConfigurationSection(jobKey);
|
||||
String jobFullName = jobSection.getString("fullname", null);
|
||||
|
||||
// Translating unicode
|
||||
jobFullName = StringEscapeUtils.unescapeJava(jobFullName);
|
||||
if (jobFullName == null) {
|
||||
log.warning("Job " + jobKey + " has an invalid fullname property. Skipping job!");
|
||||
continue;
|
||||
}
|
||||
|
||||
// Translating unicode
|
||||
jobFullName = StringEscapeUtils.unescapeJava(jobFullName);
|
||||
|
||||
int maxLevel = jobSection.getInt("max-level", 0);
|
||||
if (maxLevel < 0)
|
||||
maxLevel = 0;
|
||||
@ -726,9 +530,11 @@ public class ConfigManager {
|
||||
maxSlots = null;
|
||||
|
||||
Long rejoinCd = jobSection.getLong("rejoinCooldown", 0L);
|
||||
if (rejoinCd < 0L)
|
||||
if (rejoinCd < 0L) {
|
||||
rejoinCd = 0L;
|
||||
rejoinCd *= 1000L;
|
||||
} else {
|
||||
rejoinCd *= 1000L;
|
||||
}
|
||||
|
||||
String jobShortName = jobSection.getString("shortname", null);
|
||||
if (jobShortName == null) {
|
||||
@ -786,7 +592,7 @@ public class ConfigManager {
|
||||
maxExpEquation.setVariable("numjobs", 1);
|
||||
maxExpEquation.setVariable("maxjobs", 2);
|
||||
maxExpEquation.setVariable("joblevel", 1);
|
||||
} catch (Throwable e) {
|
||||
} catch (ParseError e) {
|
||||
log.warning("Job " + jobKey + " has an invalid leveling-progression-equation property. Skipping job!");
|
||||
continue;
|
||||
}
|
||||
@ -801,7 +607,7 @@ public class ConfigManager {
|
||||
incomeEquation.setVariable("maxjobs", 2);
|
||||
incomeEquation.setVariable("joblevel", 1);
|
||||
incomeEquation.setVariable("baseincome", 1);
|
||||
} catch (Throwable e) {
|
||||
} catch (ParseError e) {
|
||||
log.warning("Job " + jobKey + " has an invalid income-progression-equation property. Skipping job!");
|
||||
continue;
|
||||
}
|
||||
@ -816,7 +622,7 @@ public class ConfigManager {
|
||||
expEquation.setVariable("maxjobs", 2);
|
||||
expEquation.setVariable("joblevel", 1);
|
||||
expEquation.setVariable("baseexperience", 1);
|
||||
} catch (Throwable e) {
|
||||
} catch (ParseError e) {
|
||||
log.warning("Job " + jobKey + " has an invalid experience-progression-equation property. Skipping job!");
|
||||
continue;
|
||||
}
|
||||
@ -831,7 +637,7 @@ public class ConfigManager {
|
||||
pointsEquation.setVariable("maxjobs", 2);
|
||||
pointsEquation.setVariable("joblevel", 1);
|
||||
pointsEquation.setVariable("basepoints", 1);
|
||||
} catch (Throwable e) {
|
||||
} catch (ParseError e) {
|
||||
log.warning("Job " + jobKey + " has an invalid points-progression-equation property. Skipping job!");
|
||||
continue;
|
||||
}
|
||||
@ -1304,20 +1110,12 @@ public class ConfigManager {
|
||||
|
||||
if (jobKey.equalsIgnoreCase("none"))
|
||||
Jobs.setNoneJob(job);
|
||||
else
|
||||
jobs.add(job);
|
||||
else if (getJobConfig().getBoolean("migratedToNewFile")) {
|
||||
return job;
|
||||
}
|
||||
}
|
||||
|
||||
Jobs.setJobs(jobs);
|
||||
|
||||
Jobs.consoleMsg("&e[Jobs] Loaded " + jobs.size() + " jobs!");
|
||||
if (!Jobs.getExplore().isExploreEnabled())
|
||||
Jobs.consoleMsg("&6[Jobs] Explorer jobs manager are not enabled!");
|
||||
else
|
||||
Jobs.consoleMsg("&e[Jobs] Explorer job manager registered!");
|
||||
|
||||
// Lets load item boosts
|
||||
ItemBoostManager.load();
|
||||
return null;
|
||||
}
|
||||
|
||||
private double updateValue(CurrencyType type, double amount) {
|
||||
|
@ -33,7 +33,7 @@ public class LanguageManager {
|
||||
}
|
||||
for (Iterator<String> e1 = this.languages.iterator(); e1.hasNext();) {
|
||||
String lang = e1.next();
|
||||
YmlMaker langFile = new YmlMaker(Jobs.getInstance(), "locale" + File.separator + "messages_" + lang + ".yml");
|
||||
YmlMaker langFile = new YmlMaker(Jobs.getFolder(), "locale" + File.separator + "messages_" + lang + ".yml");
|
||||
langFile.saveDefaultConfig();
|
||||
}
|
||||
//Up to here.
|
||||
|
@ -158,7 +158,7 @@ public class NameTranslatorManager {
|
||||
}
|
||||
|
||||
public void readFile() {
|
||||
YmlMaker ItemFile = new YmlMaker(Jobs.getInstance(), "TranslatableWords" + File.separator + "Words_"
|
||||
YmlMaker ItemFile = new YmlMaker(Jobs.getFolder(), "TranslatableWords" + File.separator + "Words_"
|
||||
+ Jobs.getGCManager().localeString + ".yml");
|
||||
if (!ItemFile.getConfigFile().getName().equalsIgnoreCase("en")) {
|
||||
ItemFile.saveDefaultConfig();
|
||||
@ -268,7 +268,7 @@ public class NameTranslatorManager {
|
||||
}
|
||||
for (Iterator<String> e1 = languages.iterator(); e1.hasNext();) {
|
||||
String lang = e1.next();
|
||||
YmlMaker langFile = new YmlMaker(Jobs.getInstance(), "TranslatableWords" + File.separator + "Words_" + lang + ".yml");
|
||||
YmlMaker langFile = new YmlMaker(Jobs.getFolder(), "TranslatableWords" + File.separator + "Words_" + lang + ".yml");
|
||||
langFile.saveDefaultConfig();
|
||||
}
|
||||
//Up to here.
|
||||
|
@ -153,7 +153,7 @@ public class ScheduleManager {
|
||||
public void load() {
|
||||
BOOSTSCHEDULE.clear();
|
||||
|
||||
jobSchedule = new YmlMaker(plugin, "schedule.yml");
|
||||
jobSchedule = new YmlMaker(Jobs.getFolder(), "schedule.yml");
|
||||
jobSchedule.saveDefaultConfig();
|
||||
|
||||
YamlConfiguration conf = YamlConfiguration.loadConfiguration(jobSchedule.getConfigFile());
|
||||
|
@ -10,73 +10,81 @@ import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.gamingmesh.jobs.Jobs;
|
||||
|
||||
public class YmlMaker {
|
||||
public String fileName;
|
||||
private JavaPlugin plugin;
|
||||
private File ConfigFile;
|
||||
private FileConfiguration Configuration;
|
||||
|
||||
public YmlMaker(JavaPlugin plugin, String fileName) {
|
||||
if (plugin == null) {
|
||||
throw new IllegalArgumentException("plugin cannot be null");
|
||||
}
|
||||
this.plugin = plugin;
|
||||
public String fileName;
|
||||
|
||||
private File path;
|
||||
private File configFile;
|
||||
private FileConfiguration configuration;
|
||||
|
||||
public YmlMaker(File path, File parent) {
|
||||
this(path, parent.getName());
|
||||
|
||||
configFile = parent;
|
||||
}
|
||||
|
||||
public YmlMaker(File path, String fileName) {
|
||||
this.path = path;
|
||||
this.fileName = fileName;
|
||||
|
||||
ConfigFile = new File(Jobs.getFolder(), fileName);
|
||||
configFile = new File(path, fileName);
|
||||
}
|
||||
|
||||
public void reloadConfig() {
|
||||
InputStreamReader f = null;
|
||||
try {
|
||||
f = new InputStreamReader(new FileInputStream(ConfigFile), StandardCharsets.UTF_8);
|
||||
f = new InputStreamReader(new FileInputStream(configFile), StandardCharsets.UTF_8);
|
||||
} catch (FileNotFoundException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
Configuration = YamlConfiguration.loadConfiguration(f);
|
||||
if (f != null)
|
||||
try {
|
||||
f.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (f == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
configuration = YamlConfiguration.loadConfiguration(f);
|
||||
|
||||
try {
|
||||
f.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public FileConfiguration getConfig() {
|
||||
if (Configuration == null)
|
||||
if (configuration == null)
|
||||
reloadConfig();
|
||||
return Configuration;
|
||||
return configuration;
|
||||
}
|
||||
|
||||
public File getConfigFile() {
|
||||
if (ConfigFile == null)
|
||||
ConfigFile = new File(Jobs.getFolder(), fileName);
|
||||
return ConfigFile;
|
||||
if (configFile == null)
|
||||
configFile = new File(path, fileName);
|
||||
return configFile;
|
||||
}
|
||||
|
||||
public void saveConfig() {
|
||||
if ((Configuration == null) || (ConfigFile == null))
|
||||
if (configuration == null || configFile == null)
|
||||
return;
|
||||
try {
|
||||
getConfig().save(ConfigFile);
|
||||
getConfig().save(configFile);
|
||||
} catch (IOException ex) {
|
||||
plugin.getLogger().log(Level.SEVERE, "Could not save config to " + ConfigFile, ex);
|
||||
Jobs.getInstance().getLogger().log(Level.SEVERE, "Could not save config to " + configFile.getName(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean exists() {
|
||||
return ConfigFile != null && ConfigFile.exists();
|
||||
return configFile != null && configFile.exists();
|
||||
}
|
||||
|
||||
public void createNewFile() {
|
||||
if (ConfigFile != null && !ConfigFile.exists()) {
|
||||
if (configFile != null && !configFile.exists()) {
|
||||
try {
|
||||
ConfigFile.createNewFile();
|
||||
configFile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -84,7 +92,7 @@ public class YmlMaker {
|
||||
}
|
||||
|
||||
public void saveDefaultConfig() {
|
||||
if (ConfigFile != null && !ConfigFile.exists())
|
||||
plugin.saveResource(fileName, false);
|
||||
if (configFile != null && !configFile.exists())
|
||||
Jobs.getInstance().saveResource(fileName, false);
|
||||
}
|
||||
}
|
||||
|
@ -171,8 +171,8 @@ public class BlockOwnerShip {
|
||||
}
|
||||
|
||||
public void load() {
|
||||
YmlMaker f = new YmlMaker(Jobs.getInstance(), "furnaceBrewingStands.yml");
|
||||
YmlMaker f2 = new YmlMaker(Jobs.getInstance(), "blockOwnerShips.yml");
|
||||
YmlMaker f = new YmlMaker(Jobs.getFolder(), "furnaceBrewingStands.yml");
|
||||
YmlMaker f2 = new YmlMaker(Jobs.getFolder(), "blockOwnerShips.yml");
|
||||
if (!f.exists() && !f2.exists())
|
||||
return;
|
||||
|
||||
@ -231,12 +231,12 @@ public class BlockOwnerShip {
|
||||
}
|
||||
|
||||
public void save() {
|
||||
YmlMaker f = new YmlMaker(Jobs.getInstance(), "furnaceBrewingStands.yml");
|
||||
YmlMaker f = new YmlMaker(Jobs.getFolder(), "furnaceBrewingStands.yml");
|
||||
if (f.exists()) {
|
||||
f.getConfigFile().renameTo(new File(Jobs.getFolder(), "blockOwnerShips.yml"));
|
||||
}
|
||||
|
||||
f = new YmlMaker(Jobs.getInstance(), "blockOwnerShips.yml");
|
||||
f = new YmlMaker(Jobs.getFolder(), "blockOwnerShips.yml");
|
||||
if (!f.exists())
|
||||
f.createNewFile();
|
||||
|
||||
|
@ -45,8 +45,8 @@ public class Language {
|
||||
*/
|
||||
public void reload() {
|
||||
String ls = Jobs.getGCManager().localeString.toLowerCase();
|
||||
customlocale = new YmlMaker(plugin, "locale/messages_" + ls + ".yml").getConfig();
|
||||
enlocale = new YmlMaker(plugin, "locale/messages_en.yml").getConfig();
|
||||
customlocale = new YmlMaker(Jobs.getFolder(), "locale/messages_" + ls + ".yml").getConfig();
|
||||
enlocale = new YmlMaker(Jobs.getFolder(), "locale/messages_en.yml").getConfig();
|
||||
if (customlocale == null)
|
||||
customlocale = enlocale;
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ public class FurnaceBrewingHandling {
|
||||
static HashMap<UUID, List<blockLoc>> brewingMap = new HashMap<>();
|
||||
|
||||
public static void load() {
|
||||
YmlMaker f = new YmlMaker(Jobs.getInstance(), "furnaceBrewingStands.yml");
|
||||
YmlMaker f = new YmlMaker(Jobs.getFolder(), "furnaceBrewingStands.yml");
|
||||
if (!f.exists())
|
||||
return;
|
||||
|
||||
@ -120,7 +120,7 @@ public class FurnaceBrewingHandling {
|
||||
}
|
||||
|
||||
public static void save() {
|
||||
YmlMaker f = new YmlMaker(Jobs.getInstance(), "furnaceBrewingStands.yml");
|
||||
YmlMaker f = new YmlMaker(Jobs.getFolder(), "furnaceBrewingStands.yml");
|
||||
if (!f.exists())
|
||||
f.createNewFile();
|
||||
|
||||
|
@ -16,7 +16,7 @@ public class ToggleBarHandling {
|
||||
static Map<String, Boolean> bossBarToggle = new HashMap<>();
|
||||
|
||||
public static void load() {
|
||||
YmlMaker f = new YmlMaker(Jobs.getInstance(), "actionBarBossbar.yml");
|
||||
YmlMaker f = new YmlMaker(Jobs.getFolder(), "actionBarBossbar.yml");
|
||||
if (!f.exists())
|
||||
return;
|
||||
|
||||
@ -48,7 +48,7 @@ public class ToggleBarHandling {
|
||||
}
|
||||
|
||||
public static void save() {
|
||||
YmlMaker f = new YmlMaker(Jobs.getInstance(), "actionBarBossbar.yml");
|
||||
YmlMaker f = new YmlMaker(Jobs.getFolder(), "actionBarBossbar.yml");
|
||||
if (!f.exists())
|
||||
f.createNewFile();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user