1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-01-04 23:37:49 +01:00

Fix Jobs database truncation on updating job ids

This commit is contained in:
montlikadani 2021-03-21 17:02:42 +01:00
parent 0d138d6664
commit 24968f2218
12 changed files with 112 additions and 142 deletions

View File

@ -1,17 +1,18 @@
--- ---
name: Bug report name: Bug report
about: Create a report to help us improve about: Create a report to help us improve our project
title: '' title: ''
labels: Bug Report labels: Bug Report
assignees: '' assignees: ''
--- ---
***Description of issue:** ***Detailed description of the issue:**
--- ---
**ERROR (DELETE IF YOU HAVE NO ERROR):** **ERROR (DELETE IF YOU HAVE NO ERROR):**
<-- Try to use pastebin.com server if you have long error. -->
``` ```
#################### ####################
## PASTE ERROR HERE ## ## PASTE ERROR HERE ##
@ -27,7 +28,9 @@ assignees: ''
--- ---
**Server Type (Spigot/Paperspigot/etc):** **Jobs version:**
**Server Type (Spigot/Paper/etc):**
**Server Version (using `/ver`):** **Server Version (using `/ver`):**

View File

@ -9,6 +9,6 @@ assignees: ''
**Description of new idea or improvement on existing one** **Description of new idea or improvement on existing one**
**Detailed information what should do**
<-- Maybe a config example if related -->
**Detailed information what should do what and when**

View File

@ -108,9 +108,10 @@ public class GuiManager {
} else } else
lore.addAll(Arrays.asList(job.getDescription().split("/n|\\n"))); lore.addAll(Arrays.asList(job.getDescription().split("/n|\\n")));
if (job.getMaxSlots() != null) if (job.getMaxSlots() != null) {
lore.add(Jobs.getLanguage().getMessage("command.info.gui.leftSlots") + ((job.getMaxSlots() - Jobs.getUsedSlots(job)) > 0 ? (job.getMaxSlots() - Jobs int usedSlots = Jobs.getUsedSlots(job);
.getUsedSlots(job)) : 0)); lore.add(Jobs.getLanguage().getMessage("command.info.gui.leftSlots") + ((job.getMaxSlots() - usedSlots) > 0 ? (job.getMaxSlots() - usedSlots) : 0));
}
if (Jobs.getGCManager().ShowActionNames) { if (Jobs.getGCManager().ShowActionNames) {
lore.add(""); lore.add("");

View File

@ -399,8 +399,7 @@ public class Jobs extends JavaPlugin {
public static File getFolder() { public static File getFolder() {
File folder = instance.getDataFolder(); File folder = instance.getDataFolder();
if (!folder.exists()) folder.mkdirs();
folder.mkdirs();
return folder; return folder;
} }

View File

@ -5,6 +5,7 @@ import java.text.NumberFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
@ -24,6 +25,7 @@ import com.gamingmesh.jobs.container.Quest;
import com.gamingmesh.jobs.container.QuestProgression; import com.gamingmesh.jobs.container.QuestProgression;
import com.gamingmesh.jobs.container.Title; import com.gamingmesh.jobs.container.Title;
import com.gamingmesh.jobs.container.TopList; import com.gamingmesh.jobs.container.TopList;
import com.gamingmesh.jobs.container.blockOwnerShip.BlockOwnerShip;
import com.gamingmesh.jobs.container.blockOwnerShip.BlockTypes; import com.gamingmesh.jobs.container.blockOwnerShip.BlockTypes;
import com.gamingmesh.jobs.stuff.TimeManage; import com.gamingmesh.jobs.stuff.TimeManage;
@ -103,7 +105,7 @@ public class Placeholder {
private String[] vars; private String[] vars;
private List<Integer> groups = new ArrayList<>(); private List<Integer> groups = new ArrayList<>();
private ChatFilterRule rule = null; private ChatFilterRule rule;
private boolean hidden = false; private boolean hidden = false;
JobsPlaceHolders(String... vars) { JobsPlaceHolders(String... vars) {
@ -234,7 +236,7 @@ public class Placeholder {
if (!isComplex()) if (!isComplex())
return lsInLs; return lsInLs;
Matcher matcher = getRule().getMatcher(text); Matcher matcher = rule.getMatcher(text);
if (matcher == null) if (matcher == null)
return lsInLs; return lsInLs;
@ -250,7 +252,7 @@ public class Placeholder {
if (!isComplex() || text == null) if (!isComplex() || text == null)
return lsInLs; return lsInLs;
Matcher matcher = getRule().getMatcher(text); Matcher matcher = rule.getMatcher(text);
if (matcher != null && matcher.find()) { if (matcher != null && matcher.find()) {
try { try {
for (Integer oneG : groups) { for (Integer oneG : groups) {
@ -429,13 +431,13 @@ public class Placeholder {
case user_maxfurncount: case user_maxfurncount:
return Integer.toString(user.getMaxOwnerShipAllowed(BlockTypes.FURNACE)); return Integer.toString(user.getMaxOwnerShipAllowed(BlockTypes.FURNACE));
case user_smokercount: case user_smokercount:
return !plugin.getBlockOwnerShip(BlockTypes.SMOKER).isPresent() ? "0" Optional<BlockOwnerShip> blastSmoker = plugin.getBlockOwnerShip(BlockTypes.SMOKER);
: Integer.toString(plugin.getBlockOwnerShip(BlockTypes.SMOKER).get().getTotal(uuid)); return !blastSmoker.isPresent() ? "0" : Integer.toString(blastSmoker.get().getTotal(uuid));
case user_maxsmokercount: case user_maxsmokercount:
return Integer.toString(user.getMaxOwnerShipAllowed(BlockTypes.SMOKER)); return Integer.toString(user.getMaxOwnerShipAllowed(BlockTypes.SMOKER));
case user_blastcount: case user_blastcount:
return !plugin.getBlockOwnerShip(BlockTypes.BLAST_FURNACE).isPresent() ? "0" Optional<BlockOwnerShip> blastShip = plugin.getBlockOwnerShip(BlockTypes.BLAST_FURNACE);
: Integer.toString(plugin.getBlockOwnerShip(BlockTypes.BLAST_FURNACE).get().getTotal(uuid)); return !blastShip.isPresent() ? "0" : Integer.toString(blastShip.get().getTotal(uuid));
case user_maxblastcount: case user_maxblastcount:
return Integer.toString(user.getMaxOwnerShipAllowed(BlockTypes.BLAST_FURNACE)); return Integer.toString(user.getMaxOwnerShipAllowed(BlockTypes.BLAST_FURNACE));
case user_doneq: case user_doneq:
@ -498,14 +500,11 @@ public class Placeholder {
switch (placeHolder) { switch (placeHolder) {
case limit_$1: case limit_$1:
CurrencyType t = CurrencyType.getByName(vals.get(0)); return Integer.toString(user.getLimit(CurrencyType.getByName(vals.get(0))));
return Integer.toString(user.getLimit(t));
case plimit_$1: case plimit_$1:
t = CurrencyType.getByName(vals.get(0)); return Double.toString(user.getPaymentLimit().getAmount(CurrencyType.getByName(vals.get(0))));
return Double.toString(user.getPaymentLimit().getAmount(t));
case plimit_tleft_$1: case plimit_tleft_$1:
t = CurrencyType.getByName(vals.get(0)); return TimeManage.to24hourShort(user.getPaymentLimit().getLeftTime(CurrencyType.getByName(vals.get(0))));
return TimeManage.to24hourShort(user.getPaymentLimit().getLeftTime(t));
case user_jlevel_$1: case user_jlevel_$1:
return j == null ? "0" : Integer.toString(j.getLevel()); return j == null ? "0" : Integer.toString(j.getLevel());
case user_jexp_$1: case user_jexp_$1:
@ -521,10 +520,9 @@ public class Placeholder {
case user_jmaxlvl_$1: case user_jmaxlvl_$1:
return j == null ? "0" : Integer.toString(j.getJob().getMaxLevel(user)); return j == null ? "0" : Integer.toString(j.getJob().getMaxLevel(user));
case user_boost_$1_$2: case user_boost_$1_$2:
return vals.size() < 2 || j == null ? "" : simplifyDouble(user.getBoost(j.getJob().getName(), return (vals.size() < 2 || j == null) ? "" : simplifyDouble(user.getBoost(j.getJob().getName(),
CurrencyType.getByName(vals.get(1)))); CurrencyType.getByName(vals.get(1))));
case user_jtoplvl_$1_$2: case user_jtoplvl_$1_$2:
vals = placeHolder.getComplexValues(value);
if (vals.size() < 2 || job == null) if (vals.size() < 2 || job == null)
return ""; return "";
@ -545,10 +543,6 @@ public class Placeholder {
return ""; return "";
}).join(); }).join();
case user_isin_$1: case user_isin_$1:
vals = placeHolder.getComplexValues(value);
if (vals.isEmpty())
return "";
return job == null ? "no" : convert(user.isInJob(job)); return job == null ? "no" : convert(user.isInJob(job));
case user_job_$1: case user_job_$1:
return j == null ? "" : j.getJob().getName(); return j == null ? "" : j.getJob().getName();
@ -589,21 +583,16 @@ public class Placeholder {
if (job == null) if (job == null)
return ""; return "";
if (!Jobs.getCommandManager().hasJobPermission(player, job)) if (!Jobs.getCommandManager().hasJobPermission(player, job) || user.isInJob(job))
return convert(false);
if (user.isInJob(job))
return convert(false); return convert(false);
if (job.getMaxSlots() != null && Jobs.getUsedSlots(job) >= job.getMaxSlots()) if (job.getMaxSlots() != null && Jobs.getUsedSlots(job) >= job.getMaxSlots())
return convert(false); return convert(false);
int confMaxJobs = Jobs.getGCManager().getMaxJobs(); int confMaxJobs = Jobs.getGCManager().getMaxJobs();
short PlayerMaxJobs = (short) user.getJobProgression().size(); short playerMaxJobs = (short) user.getJobProgression().size();
if (confMaxJobs > 0 && PlayerMaxJobs >= confMaxJobs && !Jobs.getPlayerManager().getJobsLimit(user, PlayerMaxJobs)) return convert(confMaxJobs > 0 && playerMaxJobs >= confMaxJobs
return convert(false); && !Jobs.getPlayerManager().getJobsLimit(user, playerMaxJobs));
return convert(true);
case maxjobs: case maxjobs:
return Integer.toString(Jobs.getPlayerManager().getMaxJobs(user)); return Integer.toString(Jobs.getPlayerManager().getMaxJobs(user));

View File

@ -313,8 +313,10 @@ public class ConfigManager {
public void changeJobsSettings(String jobName, String path, Object value) { public void changeJobsSettings(String jobName, String path, Object value) {
path = path.replace('/', '.'); path = path.replace('/', '.');
jobName = jobName.toLowerCase();
for (YmlMaker yml : jobFiles) { for (YmlMaker yml : jobFiles) {
if (yml.getConfigFile().getName().contains(jobName.toLowerCase())) { if (yml.getConfigFile().getName().contains(jobName)) {
yml.getConfig().set(path, value); yml.getConfig().set(path, value);
yml.saveConfig(); yml.saveConfig();
break; break;
@ -370,14 +372,14 @@ public class ConfigManager {
if (myKey.contains("-")) { if (myKey.contains("-")) {
// uses subType // uses subType
String[] split = myKey.split("-"); String[] split = myKey.split("-", 2);
if (split.length >= 2) { if (split.length >= 2) {
subType = ":" + split[1]; subType = ":" + split[1];
meta = split[1]; meta = split[1];
myKey = split[0]; myKey = split[0];
} }
} else if (myKey.contains(":")) { // when we uses tipped arrow effect types } else if (myKey.contains(":")) { // when we uses tipped arrow effect types
String[] split = myKey.split(":"); String[] split = myKey.split(":", 2);
meta = split.length > 1 ? split[1] : myKey; meta = split.length > 1 ? split[1] : myKey;
subType = ":all"; subType = ":all";
myKey = split[0]; myKey = split[0];
@ -445,7 +447,7 @@ public class ConfigManager {
} }
if (Version.isCurrentLower(Version.v1_13_R1) && meta.isEmpty()) if (Version.isCurrentLower(Version.v1_13_R1) && meta.isEmpty())
meta = String.valueOf(material.getData()); meta = Integer.toString(material.getData());
c: if (material != CMIMaterial.NONE && material.getMaterial() != null && !material.isAir()) { c: if (material != CMIMaterial.NONE && material.getMaterial() != null && !material.isAir()) {
// Need to include those ones and count as regular blocks // Need to include those ones and count as regular blocks
@ -596,14 +598,14 @@ public class ConfigManager {
} }
if (myKey.contains(":")) { if (myKey.contains(":")) {
subType = myKey.split(":")[1]; subType = myKey.split(":", 2)[1];
} }
} else if (actionType == ActionType.SHEAR && !myKey.startsWith("color")) { } else if (actionType == ActionType.SHEAR && !myKey.startsWith("color")) {
type = myKey; type = myKey;
} }
if (finalMyKey.endsWith("-all") || finalMyKey.endsWith(":all")) { if (finalMyKey.endsWith("-all") || finalMyKey.endsWith(":all")) {
type = finalMyKey.split(":|-")[0]; type = finalMyKey.split(":|-", 2)[0];
} }
if (type == null) { if (type == null) {
@ -635,9 +637,7 @@ public class ConfigManager {
private boolean migrateJobs() { private boolean migrateJobs() {
YamlConfiguration oldConf = getJobConfig(); YamlConfiguration oldConf = getJobConfig();
if (oldConf == null) { if (oldConf == null) {
if (!jobsPathFolder.exists()) { jobsPathFolder.mkdirs();
jobsPathFolder.mkdirs();
}
if (jobsPathFolder.isDirectory() && jobsPathFolder.listFiles().length == 0) if (jobsPathFolder.isDirectory() && jobsPathFolder.listFiles().length == 0)
try { try {
@ -762,19 +762,19 @@ public class ConfigManager {
// Translating unicode // Translating unicode
jobFullName = StringEscapeUtils.unescapeJava(jobFullName); jobFullName = StringEscapeUtils.unescapeJava(jobFullName);
int maxLevel = jobSection.getInt("max-level", 0); int maxLevel = jobSection.getInt("max-level");
if (maxLevel < 0) if (maxLevel < 0)
maxLevel = 0; maxLevel = 0;
int vipmaxLevel = jobSection.getInt("vip-max-level", 0); int vipmaxLevel = jobSection.getInt("vip-max-level");
if (vipmaxLevel < 0) if (vipmaxLevel < 0)
vipmaxLevel = 0; vipmaxLevel = 0;
Integer maxSlots = jobSection.getInt("slots", 0); Integer maxSlots = jobSection.getInt("slots");
if (maxSlots.intValue() <= 0) if (maxSlots.intValue() <= 0)
maxSlots = null; maxSlots = null;
Long rejoinCd = jobSection.getLong("rejoinCooldown", 0L); Long rejoinCd = jobSection.getLong("rejoinCooldown");
if (rejoinCd < 0L) { if (rejoinCd < 0L) {
rejoinCd = 0L; rejoinCd = 0L;
} else { } else {
@ -899,10 +899,10 @@ public class ConfigManager {
if (item.contains("-")) { if (item.contains("-")) {
// uses subType // uses subType
subType = ":" + item.split("-")[1]; subType = ":" + item.split("-", 2)[1];
item = item.split("-")[0]; item = item.split("-")[0];
} else if (item.contains(":")) { // when we uses tipped arrow effect types } else if (item.contains(":")) { // when we uses tipped arrow effect types
item = item.split(":")[0]; item = item.split(":", 2)[0];
} }
CMIMaterial material = CMIMaterial.get(item + (subType)); CMIMaterial material = CMIMaterial.get(item + (subType));
@ -952,7 +952,7 @@ public class ConfigManager {
} }
// Permissions // Permissions
ArrayList<JobPermission> jobPermissions = new ArrayList<>(); List<JobPermission> jobPermissions = new ArrayList<>();
ConfigurationSection permissionsSection = jobSection.getConfigurationSection("permissions"); ConfigurationSection permissionsSection = jobSection.getConfigurationSection("permissions");
if (permissionsSection != null) { if (permissionsSection != null) {
for (String permissionKey : permissionsSection.getKeys(false)) { for (String permissionKey : permissionsSection.getKeys(false)) {
@ -964,35 +964,35 @@ public class ConfigManager {
String node = permissionSection.getString("permission"); String node = permissionSection.getString("permission");
boolean value = permissionSection.getBoolean("value", true); boolean value = permissionSection.getBoolean("value", true);
int levelRequirement = permissionSection.getInt("level", 0); int levelRequirement = permissionSection.getInt("level");
jobPermissions.add(new JobPermission(node, value, levelRequirement)); jobPermissions.add(new JobPermission(node, value, levelRequirement));
} }
} }
// Conditions // Conditions
ArrayList<JobConditions> jobConditions = new ArrayList<>(); List<JobConditions> jobConditions = new ArrayList<>();
ConfigurationSection conditionsSection = jobSection.getConfigurationSection("conditions"); ConfigurationSection conditionsSection = jobSection.getConfigurationSection("conditions");
if (conditionsSection != null) { if (conditionsSection != null) {
for (String ConditionKey : conditionsSection.getKeys(false)) { for (String conditionKey : conditionsSection.getKeys(false)) {
ConfigurationSection permissionSection = conditionsSection.getConfigurationSection(ConditionKey); ConfigurationSection permissionSection = conditionsSection.getConfigurationSection(conditionKey);
if (permissionSection == null) { if (permissionSection == null) {
log.warning("Job " + jobKey + " has an invalid condition key " + ConditionKey + "!"); log.warning("Job " + jobKey + " has an invalid condition key " + conditionKey + "!");
continue; continue;
} }
if (!permissionSection.contains("requires") || !permissionSection.contains("perform")) { if (!permissionSection.contains("requires") || !permissionSection.contains("perform")) {
log.warning("Job " + jobKey + " has an invalid condition requirement " + ConditionKey + "!"); log.warning("Job " + jobKey + " has an invalid condition requirement " + conditionKey + "!");
continue; continue;
} }
List<String> requires = permissionSection.getStringList("requires"), List<String> requires = permissionSection.getStringList("requires"),
perform = permissionSection.getStringList("perform"); perform = permissionSection.getStringList("perform");
jobConditions.add(new JobConditions(ConditionKey.toLowerCase(), requires, perform)); jobConditions.add(new JobConditions(conditionKey.toLowerCase(), requires, perform));
} }
} }
// Commands // Commands
ArrayList<JobCommands> jobCommand = new ArrayList<>(); List<JobCommands> jobCommand = new ArrayList<>();
ConfigurationSection commandsSection = jobSection.getConfigurationSection("commands"); ConfigurationSection commandsSection = jobSection.getConfigurationSection("commands");
if (commandsSection != null) { if (commandsSection != null) {
for (String commandKey : commandsSection.getKeys(false)) { for (String commandKey : commandsSection.getKeys(false)) {
@ -1073,7 +1073,7 @@ public class ConfigManager {
} }
// Limited Items // Limited Items
HashMap<String, JobLimitedItems> jobLimitedItems = new HashMap<>(); Map<String, JobLimitedItems> jobLimitedItems = new HashMap<>();
ConfigurationSection limitedItemsSection = jobSection.getConfigurationSection("limitedItems"); ConfigurationSection limitedItemsSection = jobSection.getConfigurationSection("limitedItems");
if (limitedItemsSection != null) { if (limitedItemsSection != null) {
for (String itemKey : limitedItemsSection.getKeys(false)) { for (String itemKey : limitedItemsSection.getKeys(false)) {
@ -1093,10 +1093,11 @@ public class ConfigManager {
if (!eachLine.contains("=")) if (!eachLine.contains("="))
continue; continue;
Enchantment ench = CMIEnchantment.getEnchantment(eachLine.split("=")[0]); String[] split = eachLine.split("=", 2);
Enchantment ench = CMIEnchantment.getEnchantment(split[0]);
Integer level = -1; Integer level = -1;
try { try {
level = Integer.parseInt(eachLine.split("=")[1]); level = Integer.parseInt(split[1]);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
continue; continue;
} }
@ -1120,6 +1121,8 @@ public class ConfigManager {
job.setMoneyEquation(incomeEquation); job.setMoneyEquation(incomeEquation);
job.setXpEquation(expEquation); job.setXpEquation(expEquation);
job.setPointsEquation(pointsEquation); job.setPointsEquation(pointsEquation);
job.setBossbar(bossbar);
job.setRejoinCd(rejoinCd);
if (jobSection.isConfigurationSection("Quests")) { if (jobSection.isConfigurationSection("Quests")) {
List<Quest> quests = new ArrayList<>(); List<Quest> quests = new ArrayList<>();
@ -1148,7 +1151,7 @@ public class ConfigManager {
if (sqsection.isList("Objectives")) { if (sqsection.isList("Objectives")) {
List<String> list = sqsection.getStringList("Objectives"); List<String> list = sqsection.getStringList("Objectives");
for (String oneObjective : list) { for (String oneObjective : list) {
String[] split = oneObjective.split(";"); String[] split = oneObjective.split(";", 3);
if (split.length < 2) { if (split.length < 2) {
log.warning("Job " + jobKey + " has incorrect quest objective (" + oneObjective + ")!"); log.warning("Job " + jobKey + " has incorrect quest objective (" + oneObjective + ")!");
continue; continue;
@ -1183,7 +1186,7 @@ public class ConfigManager {
quest.addObjective(objective); quest.addObjective(objective);
} }
} }
} catch (Throwable e) { } catch (Exception e) {
log.warning("Job " + jobKey + " has incorrect quest objective (" + oneObjective + ")!"); log.warning("Job " + jobKey + " has incorrect quest objective (" + oneObjective + ")!");
} }
} }
@ -1206,7 +1209,7 @@ public class ConfigManager {
quest.setDescription(desc); quest.setDescription(desc);
quest.setRestrictedArea(areas); quest.setRestrictedArea(areas);
quests.add(quest); quests.add(quest);
} catch (Throwable e) { } catch (Exception e) {
Jobs.consoleMsg("&c[Jobs] Can't load " + one + " quest for " + jobFullName); Jobs.consoleMsg("&c[Jobs] Can't load " + one + " quest for " + jobFullName);
e.printStackTrace(); e.printStackTrace();
} }
@ -1238,7 +1241,7 @@ public class ConfigManager {
} }
KeyValues keyValue = null; KeyValues keyValue = null;
String[] sep = mat.split(";"); String[] sep = mat.split(";", 4);
if (sep.length >= 1) { if (sep.length >= 1) {
keyValue = getKeyValue(sep[0], actionType, jobKey); keyValue = getKeyValue(sep[0], actionType, jobKey);
} }

View File

@ -39,18 +39,12 @@ import com.gamingmesh.jobs.CMILib.ConfigReader;
import com.gamingmesh.jobs.CMILib.Version; import com.gamingmesh.jobs.CMILib.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.Schedule;
import com.gamingmesh.jobs.resources.jfep.Parser; import com.gamingmesh.jobs.resources.jfep.Parser;
public class GeneralConfigManager { public class GeneralConfigManager {
public List<Integer> BroadcastingLevelUpLevels = new ArrayList<>(); public List<Integer> BroadcastingLevelUpLevels = new ArrayList<>();
public List<String> FwColors = new ArrayList<>(), DisabledWorldsList = new ArrayList<>(); public List<String> FwColors = new ArrayList<>(), DisabledWorldsList = new ArrayList<>();
/**
* @deprecated use {@link ScheduleManager}
*/
@Deprecated
public List<Schedule> BoostSchedule = new ArrayList<>();
public final Map<CMIMaterial, Map<Enchantment, Integer>> whiteListedItems = new HashMap<>(); public final Map<CMIMaterial, Map<Enchantment, Integer>> whiteListedItems = new HashMap<>();
private final Map<CurrencyType, CurrencyLimit> currencyLimitUse = new HashMap<>(); private final Map<CurrencyType, CurrencyLimit> currencyLimitUse = new HashMap<>();
@ -484,12 +478,12 @@ public class GeneralConfigManager {
String ench = null; String ench = null;
if (one.contains("=")) { if (one.contains("=")) {
String[] split = one.split("="); String[] split = one.split("=", 2);
mName = split[0]; mName = split[0];
ench = split[1]; ench = split[1];
} }
String value = ench != null && ench.contains("-") ? ench.split("-")[1] : null; String value = ench != null && ench.contains("-") ? ench.split("-", 2)[1] : null;
if (value != null && ench != null) { if (value != null && ench != null) {
ench = ench.substring(0, ench.length() - (value.length() + 1)); ench = ench.substring(0, ench.length() - (value.length() + 1));
} }

View File

@ -195,7 +195,7 @@ public class RestrictedAreaManager {
ConfigurationSection areaSection = conf.getConfigurationSection("restrictedareas"); ConfigurationSection areaSection = conf.getConfigurationSection("restrictedareas");
if (areaSection != null) { if (areaSection != null) {
for (String areaKey : areaSection.getKeys(false)) { for (String areaKey : areaSection.getKeys(false)) {
double multiplier = conf.getDouble("restrictedareas." + areaKey + ".multiplier", 0d); double multiplier = conf.getDouble("restrictedareas." + areaKey + ".multiplier");
if (conf.isBoolean("restrictedareas." + areaKey + ".WG")) { if (conf.isBoolean("restrictedareas." + areaKey + ".WG")) {
addNew(new RestrictedArea(areaKey, areaKey, multiplier)); addNew(new RestrictedArea(areaKey, areaKey, multiplier));
@ -204,11 +204,11 @@ public class RestrictedAreaManager {
World world = Bukkit.getServer().getWorld(conf.getString("restrictedareas." + areaKey + ".world", "")); World world = Bukkit.getServer().getWorld(conf.getString("restrictedareas." + areaKey + ".world", ""));
if (world == null) if (world == null)
continue; continue;
Location point1 = new Location(world, conf.getDouble("restrictedareas." + areaKey + ".point1.x", 0d), conf.getDouble("restrictedareas." + areaKey Location point1 = new Location(world, conf.getDouble("restrictedareas." + areaKey + ".point1.x"), conf.getDouble("restrictedareas." + areaKey
+ ".point1.y", 0d), conf.getDouble("restrictedareas." + areaKey + ".point1.z", 0d)); + ".point1.y"), conf.getDouble("restrictedareas." + areaKey + ".point1.z"));
Location point2 = new Location(world, conf.getDouble("restrictedareas." + areaKey + ".point2.x", 0d), conf.getDouble("restrictedareas." + areaKey Location point2 = new Location(world, conf.getDouble("restrictedareas." + areaKey + ".point2.x"), conf.getDouble("restrictedareas." + areaKey
+ ".point2.y", 0d), conf.getDouble("restrictedareas." + areaKey + ".point2.z", 0d)); + ".point2.y"), conf.getDouble("restrictedareas." + areaKey + ".point2.z"));
addNew(new RestrictedArea(areaKey, new CuboidArea(point1, point2), multiplier)); addNew(new RestrictedArea(areaKey, new CuboidArea(point1, point2), multiplier));
} }
} }

View File

@ -1,6 +1,5 @@
package com.gamingmesh.jobs.config; package com.gamingmesh.jobs.config;
import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
@ -54,11 +53,10 @@ public class ScheduleManager {
if (BOOSTSCHEDULE.isEmpty()) if (BOOSTSCHEDULE.isEmpty())
return false; return false;
DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); String currentTime = new SimpleDateFormat("HH:mm:ss").format(new Date());
String currenttime = dateFormat.format(new Date());
String currentDayName = getWeekDay(); String currentDayName = getWeekDay();
int current = Integer.parseInt(currenttime.replace(":", "")); int current = Integer.parseInt(currentTime.replace(":", ""));
for (Schedule one : BOOSTSCHEDULE) { for (Schedule one : BOOSTSCHEDULE) {

View File

@ -49,8 +49,8 @@ public class Job {
private List<JobCommands> jobCommands; private List<JobCommands> jobCommands;
private List<JobConditions> jobConditions; private List<JobConditions> jobConditions;
private HashMap<String, JobItems> jobItems; private Map<String, JobItems> jobItems;
private HashMap<String, JobLimitedItems> jobLimitedItems; private Map<String, JobLimitedItems> jobLimitedItems;
private String jobName = "N/A"; private String jobName = "N/A";
private String fullName = "N/A"; private String fullName = "N/A";
@ -93,18 +93,19 @@ public class Job {
@Deprecated @Deprecated
public Job(String jobName, String fullName, String jobShortName, String description, CMIChatColor jobColour, Parser maxExpEquation, DisplayMethod displayMethod, int maxLevel, public Job(String jobName, String fullName, String jobShortName, String description, CMIChatColor jobColour, Parser maxExpEquation, DisplayMethod displayMethod, int maxLevel,
int vipmaxLevel, Integer maxSlots, List<JobPermission> jobPermissions, List<JobCommands> jobCommands, List<JobConditions> jobConditions, HashMap<String, JobItems> jobItems, int vipmaxLevel, Integer maxSlots, List<JobPermission> jobPermissions, List<JobCommands> jobCommands, List<JobConditions> jobConditions, Map<String, JobItems> jobItems,
HashMap<String, JobLimitedItems> jobLimitedItems, List<String> cmdOnJoin, List<String> cmdOnLeave, ItemStack guiItem, int guiSlot, String bossbar, Long rejoinCD, List<String> worldBlacklist) { Map<String, JobLimitedItems> jobLimitedItems, List<String> cmdOnJoin, List<String> cmdOnLeave, ItemStack guiItem, int guiSlot, String bossbar, Long rejoinCD, List<String> worldBlacklist) {
this(jobName, fullName, jobShortName, jobColour, maxExpEquation, displayMethod, maxLevel, this(jobName, fullName, jobShortName, jobColour, maxExpEquation, displayMethod, maxLevel,
vipmaxLevel, maxSlots, jobPermissions, jobCommands, jobConditions, jobItems, vipmaxLevel, maxSlots, jobPermissions, jobCommands, jobConditions,
jobLimitedItems, cmdOnJoin, cmdOnLeave, guiItem, guiSlot, bossbar, rejoinCD, worldBlacklist); jobLimitedItems, cmdOnJoin, cmdOnLeave, guiItem, guiSlot, worldBlacklist);
this.jobItems = jobItems;
this.description = description; this.description = description;
} }
public Job(String jobName, String fullName, String jobShortName, CMIChatColor jobColour, Parser maxExpEquation, DisplayMethod displayMethod, int maxLevel, public Job(String jobName, String fullName, String jobShortName, CMIChatColor jobColour, Parser maxExpEquation, DisplayMethod displayMethod, int maxLevel,
int vipmaxLevel, Integer maxSlots, List<JobPermission> jobPermissions, List<JobCommands> jobCommands, List<JobConditions> jobConditions, HashMap<String, JobItems> jobItems, int vipmaxLevel, Integer maxSlots, List<JobPermission> jobPermissions, List<JobCommands> jobCommands, List<JobConditions> jobConditions,
HashMap<String, JobLimitedItems> jobLimitedItems, List<String> cmdOnJoin, List<String> cmdOnLeave, ItemStack guiItem, int guiSlot, String bossbar, Long rejoinCD, List<String> worldBlacklist) { Map<String, JobLimitedItems> jobLimitedItems, List<String> cmdOnJoin, List<String> cmdOnLeave, ItemStack guiItem, int guiSlot, List<String> worldBlacklist) {
this.jobName = jobName == null ? "" : jobName; this.jobName = jobName == null ? "" : jobName;
this.fullName = fullName == null ? "" : fullName; this.fullName = fullName == null ? "" : fullName;
this.jobShortName = jobShortName; this.jobShortName = jobShortName;
@ -117,14 +118,11 @@ public class Job {
this.jobPermissions = jobPermissions; this.jobPermissions = jobPermissions;
this.jobCommands = jobCommands; this.jobCommands = jobCommands;
this.jobConditions = jobConditions; this.jobConditions = jobConditions;
this.jobItems = jobItems;
this.jobLimitedItems = jobLimitedItems; this.jobLimitedItems = jobLimitedItems;
this.cmdOnJoin = cmdOnJoin; this.cmdOnJoin = cmdOnJoin;
this.cmdOnLeave = cmdOnLeave; this.cmdOnLeave = cmdOnLeave;
this.guiItem = guiItem; this.guiItem = guiItem;
this.guiSlot = guiSlot; this.guiSlot = guiSlot;
this.bossbar = bossbar;
this.rejoinCd = rejoinCD;
if (worldBlacklist != null) { if (worldBlacklist != null) {
this.worldBlacklist = worldBlacklist; this.worldBlacklist = worldBlacklist;
@ -169,7 +167,7 @@ public class Job {
} }
public boolean isSame(Job job) { public boolean isSame(Job job) {
return job != null && (getName().equalsIgnoreCase(job.getName()) || id == job.getId()); return job != null && (fullName.equalsIgnoreCase(job.getName()) || id == job.getId());
} }
public int getTotalPlayers() { public int getTotalPlayers() {
@ -436,7 +434,7 @@ public class Job {
* @return Items for this job * @return Items for this job
*/ */
@Deprecated @Deprecated
public HashMap<String, JobItems> getItemBonus() { public Map<String, JobItems> getItemBonus() {
if (jobItems == null) if (jobItems == null)
jobItems = new HashMap<String, JobItems>(); jobItems = new HashMap<String, JobItems>();
return jobItems; return jobItems;
@ -451,7 +449,7 @@ public class Job {
* Get the limited item nodes for this job * Get the limited item nodes for this job
* @return Limited items for this job * @return Limited items for this job
*/ */
public HashMap<String, JobLimitedItems> getLimitedItems() { public Map<String, JobLimitedItems> getLimitedItems() {
return jobLimitedItems; return jobLimitedItems;
} }

View File

@ -1214,7 +1214,7 @@ public abstract class JobsDAO {
job.setId(jobId + 1); job.setId(jobId + 1);
prestt = conn.prepareStatement("UPDATE `" + getJobsTableName() + "` SET `" + JobsTableFields.jobid.getCollumn() + "` = ? WHERE `" + JobsTableFields.job.getCollumn() + "` = ?;"); prestt = conn.prepareStatement("UPDATE `" + getJobsTableName() + "` SET `" + JobsTableFields.job.getCollumn() + "` = ? WHERE `" + JobsTableFields.jobid.getCollumn() + "` = ?;");
prestt.setString(1, job.getName()); prestt.setString(1, job.getName());
prestt.setInt(2, job.getId()); prestt.setInt(2, job.getId());
prestt.execute(); prestt.execute();
@ -1308,8 +1308,7 @@ public abstract class JobsDAO {
* @return list of all of the names of the jobs the players are part of. * @return list of all of the names of the jobs the players are part of.
*/ */
public synchronized List<JobsDAOData> getAllJobsOffline(String userName) { public synchronized List<JobsDAOData> getAllJobsOffline(String userName) {
List<JobsDAOData> jobs = new ArrayList<>();
ArrayList<JobsDAOData> jobs = new ArrayList<>();
PlayerInfo info = Jobs.getPlayerManager().getPlayerInfo(userName); PlayerInfo info = Jobs.getPlayerManager().getPlayerInfo(userName);
if (info == null) if (info == null)
@ -1478,14 +1477,12 @@ public abstract class JobsDAO {
return; return;
PreparedStatement prest = null; PreparedStatement prest = null;
try { try {
int level = job.getLevel();
Double exp = job.getExperience();
prest = conn.prepareStatement("INSERT INTO `" + getJobsTableName() + "` (`" + JobsTableFields.userid.getCollumn() + "`, `" + JobsTableFields.jobid.getCollumn() prest = conn.prepareStatement("INSERT INTO `" + getJobsTableName() + "` (`" + JobsTableFields.userid.getCollumn() + "`, `" + JobsTableFields.jobid.getCollumn()
+ "`, `" + JobsTableFields.level.getCollumn() + "`, `" + JobsTableFields.experience.getCollumn() + "`, `" + JobsTableFields.job.getCollumn() + "`) VALUES (?, ?, ?, ?, ?);"); + "`, `" + JobsTableFields.level.getCollumn() + "`, `" + JobsTableFields.experience.getCollumn() + "`, `" + JobsTableFields.job.getCollumn() + "`) VALUES (?, ?, ?, ?, ?);");
prest.setInt(1, jPlayer.getUserId()); prest.setInt(1, jPlayer.getUserId());
prest.setInt(2, job.getJob().getId()); prest.setInt(2, job.getJob().getId());
prest.setInt(3, level); prest.setInt(3, job.getLevel());
prest.setDouble(4, exp); prest.setDouble(4, job.getExperience());
prest.setString(5, job.getJob().getName()); prest.setString(5, job.getJob().getName());
prest.execute(); prest.execute();
} catch (SQLException e) { } catch (SQLException e) {
@ -1659,7 +1656,6 @@ public abstract class JobsDAO {
return; return;
PreparedStatement prest = null; PreparedStatement prest = null;
try { try {
int level = jp.getLevel();
Double exp = jp.getExperience(); Double exp = jp.getExperience();
prest = conn.prepareStatement("INSERT INTO `" + DBTables.ArchiveTable.getTableName() + "` (`" + ArchiveTableFields.userid.getCollumn() prest = conn.prepareStatement("INSERT INTO `" + DBTables.ArchiveTable.getTableName() + "` (`" + ArchiveTableFields.userid.getCollumn()
+ "`, `" + ArchiveTableFields.jobid.getCollumn() + "`, `" + ArchiveTableFields.jobid.getCollumn()
@ -1670,7 +1666,7 @@ public abstract class JobsDAO {
+ "`) VALUES (?, ?, ?, ?, ?, ?);"); + "`) VALUES (?, ?, ?, ?, ?, ?);");
prest.setInt(1, jPlayer.getUserId()); prest.setInt(1, jPlayer.getUserId());
prest.setInt(2, job.getId()); prest.setInt(2, job.getId());
prest.setInt(3, level); prest.setInt(3, jp.getLevel());
prest.setInt(4, exp.intValue()); prest.setInt(4, exp.intValue());
prest.setLong(5, System.currentTimeMillis()); prest.setLong(5, System.currentTimeMillis());
prest.setString(6, job.getName()); prest.setString(6, job.getName());
@ -1715,8 +1711,7 @@ public abstract class JobsDAO {
if (info == null) if (info == null)
continue; continue;
TopList top = new TopList(info, res.getInt("totallvl"), 0); names.add(new TopList(info, res.getInt("totallvl"), 0));
names.add(top);
if (names.size() >= Jobs.getGCManager().JobsTopAmount * 2) if (names.size() >= Jobs.getGCManager().JobsTopAmount * 2)
break; break;
@ -1760,8 +1755,7 @@ public abstract class JobsDAO {
if (info == null) if (info == null)
continue; continue;
TopList top = new TopList(info, res.getInt(UserTableFields.donequests.getCollumn()), 0); names.add(new TopList(info, res.getInt(UserTableFields.donequests.getCollumn()), 0));
names.add(top);
if (names.size() >= Jobs.getGCManager().JobsTopAmount) if (names.size() >= Jobs.getGCManager().JobsTopAmount)
break; break;
@ -2322,10 +2316,10 @@ public abstract class JobsDAO {
PreparedStatement prestDel = null; PreparedStatement prestDel = null;
ResultSet res = null; ResultSet res = null;
Long timer = System.currentTimeMillis(); long timer = System.currentTimeMillis();
try { try {
Long mark = System.currentTimeMillis() - (Jobs.getGCManager().BlockProtectionDays * 24L * 60L * 60L * 1000L); long mark = System.currentTimeMillis() - (Jobs.getGCManager().BlockProtectionDays * 24L * 60L * 60L * 1000L);
prestDel = conn.prepareStatement("DELETE FROM `" + DBTables.BlocksTable.getTableName() + "` WHERE `" + BlockTableFields.recorded.getCollumn() + "` < ? OR `" + prestDel = conn.prepareStatement("DELETE FROM `" + DBTables.BlocksTable.getTableName() + "` WHERE `" + BlockTableFields.recorded.getCollumn() + "` < ? OR `" +
BlockTableFields.resets.getCollumn() + "` < ? AND `" + BlockTableFields.resets.getCollumn() + "` > 0;"); BlockTableFields.resets.getCollumn() + "` < ? AND `" + BlockTableFields.resets.getCollumn() + "` > 0;");
prestDel.setLong(1, mark); prestDel.setLong(1, mark);
@ -2371,9 +2365,8 @@ public abstract class JobsDAO {
bp.setRecorded(res.getLong(BlockTableFields.recorded.getCollumn())); bp.setRecorded(res.getLong(BlockTableFields.recorded.getCollumn()));
bp.setAction(DBAction.NONE); bp.setAction(DBAction.NONE);
i++; i++;
ii++;
if (ii >= 100000) { if (ii++ >= 100000) {
Jobs.consoleMsg("&6[Jobs] Loading (" + i + ") BP"); Jobs.consoleMsg("&6[Jobs] Loading (" + i + ") BP");
ii = 0; ii = 0;
} }
@ -2442,7 +2435,6 @@ public abstract class JobsDAO {
if (i > 0) if (i > 0)
Jobs.consoleMsg("&e[Jobs] Saved " + i + " new explorer entries."); Jobs.consoleMsg("&e[Jobs] Saved " + i + " new explorer entries.");
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
@ -2473,10 +2465,9 @@ public abstract class JobsDAO {
for (ExploreRegion worlds : temp.values()) { for (ExploreRegion worlds : temp.values()) {
for (ExploreChunk oneChunk : worlds.getChunks().values()) { for (ExploreChunk oneChunk : worlds.getChunks().values()) {
if (oneChunk.getDbId() == -1) if (oneChunk.getDbId() == -1 || !oneChunk.isUpdated())
continue;
if (!oneChunk.isUpdated())
continue; continue;
prest.setString(1, oneChunk.serializeNames()); prest.setString(1, oneChunk.serializeNames());
prest.setInt(2, oneChunk.getDbId()); prest.setInt(2, oneChunk.getDbId());
prest.addBatch(); prest.addBatch();
@ -2541,7 +2532,6 @@ public abstract class JobsDAO {
} finally { } finally {
close(prest2); close(prest2);
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
@ -2590,7 +2580,7 @@ public abstract class JobsDAO {
* @param toplist - toplist by jobs name * @param toplist - toplist by jobs name
* @return * @return
*/ */
public ArrayList<TopList> toplist(String jobsname) { public List<TopList> toplist(String jobsname) {
return toplist(jobsname, 0); return toplist(jobsname, 0);
} }
@ -2599,8 +2589,8 @@ public abstract class JobsDAO {
* @param toplist - toplist by jobs name * @param toplist - toplist by jobs name
* @return * @return
*/ */
public ArrayList<TopList> toplist(String jobsname, int limit) { public List<TopList> toplist(String jobsname, int limit) {
ArrayList<TopList> jobs = new ArrayList<>(); List<TopList> jobs = new ArrayList<>();
JobsConnection conn = getConnection(); JobsConnection conn = getConnection();
if (conn == null) if (conn == null)
return jobs; return jobs;

View File

@ -1,7 +1,6 @@
package com.gamingmesh.jobs.stuff; package com.gamingmesh.jobs.stuff;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -9,7 +8,6 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter; import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
import com.gamingmesh.jobs.ItemBoostManager; import com.gamingmesh.jobs.ItemBoostManager;
import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Jobs;
@ -25,23 +23,19 @@ public class TabComplete implements TabCompleter {
@Override @Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) { public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
List<String> completionList = new ArrayList<>();
if (args.length == 1) { if (args.length == 1) {
List<String> temp = new ArrayList<>(); return new ArrayList<>(Jobs.getCommandManager().getCommands(sender));
temp.addAll(Jobs.getCommandManager().getCommands(sender));
StringUtil.copyPartialMatches(args[0], temp, completionList);
} }
if (args.length > 1)
for (int i = 1; i <= args.length; i++)
if (args.length == i + 1) {
String partOfCommand = args[i];
if (!Jobs.getGCManager().getCommandArgs().containsKey(args[0].toLowerCase())) if (args.length > 1) {
String first = args[0].toLowerCase();
for (int i = 1; i <= args.length; i++) {
if (args.length == i + 1) {
if (!Jobs.getGCManager().getCommandArgs().containsKey(first))
break; break;
List<String> argsList = Jobs.getGCManager().getCommandArgs().get(args[0].toLowerCase()); List<String> argsList = Jobs.getGCManager().getCommandArgs().get(first);
if (argsList.size() < i) if (argsList.size() < i)
continue; continue;
@ -133,10 +127,11 @@ public class TabComplete implements TabCompleter {
} }
} }
StringUtil.copyPartialMatches(partOfCommand, temp, completionList); return temp;
} }
}
}
Collections.sort(completionList); return null;
return completionList;
} }
} }