1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-01-20 07:01:22 +01:00

Fix commands was not loaded for jobs shop

Fixes #1183
This commit is contained in:
montlikadani 2021-05-15 18:11:21 +02:00
parent beac6c059c
commit f61bfab4c4
10 changed files with 87 additions and 45 deletions

View File

@ -105,11 +105,14 @@ public class GuiManager {
if (Jobs.getGCManager().ShowTotalWorkers) if (Jobs.getGCManager().ShowTotalWorkers)
lore.add(Jobs.getLanguage().getMessage("command.browse.output.totalWorkers", "[amount]", job.getTotalPlayers())); lore.add(Jobs.getLanguage().getMessage("command.browse.output.totalWorkers", "[amount]", job.getTotalPlayers()));
if (Jobs.getGCManager().useDynamicPayment && Jobs.getGCManager().ShowPenaltyBonus) if (Jobs.getGCManager().useDynamicPayment && Jobs.getGCManager().ShowPenaltyBonus) {
if (job.getBonus() < 0) double bonus = job.getBonus();
lore.add(Jobs.getLanguage().getMessage("command.browse.output.penalty", "[amount]", (int) (job.getBonus() * 100) * -1));
if (bonus < 0)
lore.add(Jobs.getLanguage().getMessage("command.browse.output.penalty", "[amount]", (int) (bonus * 100) * -1));
else else
lore.add(Jobs.getLanguage().getMessage("command.browse.output.bonus", "[amount]", (int) (job.getBonus() * 100))); lore.add(Jobs.getLanguage().getMessage("command.browse.output.bonus", "[amount]", (int) (bonus * 100)));
}
if (job.getDescription().isEmpty()) { if (job.getDescription().isEmpty()) {
lore.addAll(job.getFullDescription()); lore.addAll(job.getFullDescription());
@ -127,6 +130,7 @@ public class GuiManager {
for (ActionType actionType : ActionType.values()) { for (ActionType actionType : ActionType.values()) {
List<JobInfo> info = job.getJobInfo(actionType); List<JobInfo> info = job.getJobInfo(actionType);
if (info != null && !info.isEmpty()) { if (info != null && !info.isEmpty()) {
lore.add(Jobs.getLanguage().getMessage("command.info.output." + actionType.getName().toLowerCase() + ".info")); lore.add(Jobs.getLanguage().getMessage("command.info.output." + actionType.getName().toLowerCase() + ".info"));
} }
@ -210,7 +214,7 @@ public class GuiManager {
ItemStack guiItem = job.getGuiItem(); ItemStack guiItem = job.getGuiItem();
int level = prog != null ? prog.getLevel() : 1, int level = prog != null ? prog.getLevel() : 1,
numjobs = jPlayer.getJobProgression().size(), numjobs = jPlayer.progression.size(),
nextButton = Jobs.getGCManager().getJobsGUINextButton(), nextButton = Jobs.getGCManager().getJobsGUINextButton(),
backButton = Jobs.getGCManager().getJobsGUIBackButton(); backButton = Jobs.getGCManager().getJobsGUIBackButton();
@ -363,7 +367,7 @@ public class GuiManager {
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player); JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
Boost boost = Jobs.getPlayerManager().getFinalBonus(jPlayer, job); Boost boost = Jobs.getPlayerManager().getFinalBonus(jPlayer, job);
int numjobs = jPlayer.getJobProgression().size(); int numjobs = jPlayer.progression.size();
int level = jPlayer.getJobProgression(job) != null ? jPlayer.getJobProgression(job).getLevel() : 1; int level = jPlayer.getJobProgression(job) != null ? jPlayer.getJobProgression(job).getLevel() : 1;
ItemStack guiItem = job.getGuiItem(); ItemStack guiItem = job.getGuiItem();

View File

@ -935,9 +935,8 @@ public class ConfigManager {
for (String jobKey : jobsSection.getKeys(false)) { for (String jobKey : jobsSection.getKeys(false)) {
// Ignore example job // Ignore example job
if (jobKey.equalsIgnoreCase(EXAMPLEJOBINTERNALNAME)) { if (jobKey.equalsIgnoreCase(EXAMPLEJOBINTERNALNAME))
continue; continue;
}
// Translating unicode // Translating unicode
jobKey = StringEscapeUtils.unescapeJava(jobKey); jobKey = StringEscapeUtils.unescapeJava(jobKey);
@ -1020,8 +1019,10 @@ public class ConfigManager {
displayMethod = DisplayMethod.NONE; displayMethod = DisplayMethod.NONE;
} }
boolean isNoneJob = jobKey.equalsIgnoreCase("none");
Parser maxExpEquation; Parser maxExpEquation;
String maxExpEquationInput = jobKey.equalsIgnoreCase("None") ? "0" : jobSection.getString("leveling-progression-equation", "0"); String maxExpEquationInput = isNoneJob ? "0" : jobSection.getString("leveling-progression-equation", "0");
try { try {
maxExpEquation = new Parser(maxExpEquationInput); maxExpEquation = new Parser(maxExpEquationInput);
// test equation // test equation
@ -1050,7 +1051,7 @@ public class ConfigManager {
} }
Parser expEquation; Parser expEquation;
String expEquationInput = jobKey.equalsIgnoreCase("None") ? "0" : jobSection.getString("experience-progression-equation", "0"); String expEquationInput = isNoneJob ? "0" : jobSection.getString("experience-progression-equation", "0");
try { try {
expEquation = new Parser(expEquationInput); expEquation = new Parser(expEquationInput);
// test equation // test equation
@ -1565,7 +1566,7 @@ public class ConfigManager {
job.setJobInfo(actionType, jobInfo); job.setJobInfo(actionType, jobInfo);
} }
if (jobKey.equalsIgnoreCase("none")) if (isNoneJob)
Jobs.setNoneJob(job); Jobs.setNoneJob(job);
else { else {
return job; return job;
@ -1576,8 +1577,6 @@ public class ConfigManager {
} }
private double updateValue(CurrencyType type, double amount) { private double updateValue(CurrencyType type, double amount) {
Double mult = Jobs.getGCManager().getGeneralMulti(type); return amount += (amount * Jobs.getGCManager().getGeneralMulti(type));
amount += (amount * mult);
return amount;
} }
} }

View File

@ -1113,8 +1113,8 @@ public class GeneralConfigManager {
return JobsGUISkipAmount; return JobsGUISkipAmount;
} }
public Double getGeneralMulti(CurrencyType type) { public double getGeneralMulti(CurrencyType type) {
return generalMulti.get(type); return generalMulti.getOrDefault(type, 0D);
} }
public ConfigReader getConfig() { public ConfigReader getConfig() {

View File

@ -46,10 +46,6 @@ public class NameTranslatorManager {
case BREW: case BREW:
case FISH: case FISH:
case STRIPLOGS: case STRIPLOGS:
String fallbackMaterialName = Arrays.stream(materialName.split("\\s|:"))
.map(word -> word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase())
.collect(Collectors.joining(" ")); // returns capitalized word (from this -> To This)
materialName = materialName.replace(" ", ""); materialName = materialName.replace(" ", "");
CMIMaterial mat = CMIMaterial.get(materialName); CMIMaterial mat = CMIMaterial.get(materialName);
@ -75,15 +71,21 @@ public class NameTranslatorManager {
if (meta != null && !meta.isEmpty()) { if (meta != null && !meta.isEmpty()) {
mat = CMIMaterial.get(materialName + ":" + meta); mat = CMIMaterial.get(materialName + ":" + meta);
nameLs = listOfNames.get(mat); nameLs = listOfNames.get(mat);
if (nameLs == null) { if (nameLs == null) {
mat = CMIMaterial.get(materialName.replace(" ", "")); mat = CMIMaterial.get(materialName.replace(" ", ""));
nameLs = listOfNames.get(mat); nameLs = listOfNames.get(mat);
NameList nameMeta = listOfNames.get(CMIMaterial.get(meta.replace(" ", ""))); NameList nameMeta = listOfNames.get(CMIMaterial.get(meta.replace(" ", "")));
if (nameLs != null && nameMeta != null) { if (nameLs != null && nameMeta != null) {
return nameLs + ":" + nameMeta; return nameLs + ":" + nameMeta;
} }
if (mat == CMIMaterial.NONE) { if (mat == CMIMaterial.NONE) {
String fallbackMaterialName = Arrays.stream(materialName.split("\\s|:"))
.map(word -> word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase())
.collect(Collectors.joining(" ")); // returns capitalized word (from this -> To This)
return fallbackMaterialName; return fallbackMaterialName;
} }
@ -94,6 +96,7 @@ public class NameTranslatorManager {
if (id > 0 && meta != null && !meta.isEmpty()) { if (id > 0 && meta != null && !meta.isEmpty()) {
mat = CMIMaterial.get(id + ":" + meta); mat = CMIMaterial.get(id + ":" + meta);
nameLs = listOfNames.get(mat); nameLs = listOfNames.get(mat);
if (nameLs == null) { if (nameLs == null) {
return mat.getName(); return mat.getName();
} }
@ -106,14 +109,19 @@ public class NameTranslatorManager {
case TAME: case TAME:
for (NameList one : listOfEntities) { for (NameList one : listOfEntities) {
String ids = one.getId() + ":" + one.getMeta(); String ids = one.getId() + ":" + one.getMeta();
if (!one.getMeta().isEmpty() && ids.equalsIgnoreCase(id + ":" + meta) && !one.getId().equals("0")) {
if (!one.getMeta().isEmpty() && !one.getId().equals("0") && ids.equalsIgnoreCase(id + ":" + meta)) {
return one.getName(); return one.getName();
} }
ids = one.getId(); ids = one.getId();
if (ids.equalsIgnoreCase(Integer.toString(id)) && !one.getId().equals("0")) {
if (!one.getId().equals("0") && ids.equalsIgnoreCase(Integer.toString(id))) {
return one.getName(); return one.getName();
} }
ids = one.getMinecraftName(); ids = one.getMinecraftName();
if (ids.equalsIgnoreCase(name)) { if (ids.equalsIgnoreCase(name)) {
return one.getName(); return one.getName();
} }
@ -122,15 +130,18 @@ public class NameTranslatorManager {
case ENCHANT: case ENCHANT:
String mName = materialName; String mName = materialName;
String level = ""; String level = "";
if (mName.contains(":")) { if (mName.contains(":")) {
String[] split = materialName.split(":", 2); String[] split = materialName.split(":", 2);
mName = split[0]; mName = split[0];
level = ":" + split[1]; level = ":" + split[1];
} }
NameList nameInfo = listOfEnchants.get(mName.toLowerCase().replace("_", "")); NameList nameInfo = listOfEnchants.get(mName.toLowerCase().replace("_", ""));
if (nameInfo != null) { if (nameInfo != null) {
return nameInfo.getMinecraftName() + level; return nameInfo.getMinecraftName() + level;
} }
break; break;
case SHEAR: case SHEAR:
for (NameList one : listOfColors) { for (NameList one : listOfColors) {
@ -145,8 +156,10 @@ public class NameTranslatorManager {
return fallbackColorName; return fallbackColorName;
case MMKILL: case MMKILL:
NameList got = listOfMMEntities.get(materialName.toLowerCase()); NameList got = listOfMMEntities.get(materialName.toLowerCase());
if (got != null && got.getName() != null) if (got != null && got.getName() != null)
return got.getName(); return got.getName();
return HookManager.getMythicManager() == null ? materialName : HookManager.getMythicManager().getDisplayName(materialName); return HookManager.getMythicManager() == null ? materialName : HookManager.getMythicManager().getDisplayName(materialName);
default: default:
break; break;

View File

@ -384,6 +384,7 @@ public class ShopManager {
for (int k = 0; k < performCommands.size(); k++) { for (int k = 0; k < performCommands.size(); k++) {
performCommands.set(k, CMIChatColor.translate(performCommands.get(k))); performCommands.set(k, CMIChatColor.translate(performCommands.get(k)));
} }
sItem.setCommands(performCommands);
ConfigurationSection itemsSection = nameSection.getConfigurationSection("GiveItems"); ConfigurationSection itemsSection = nameSection.getConfigurationSection("GiveItems");
if (itemsSection != null) { if (itemsSection != null) {
@ -449,7 +450,7 @@ public class ShopManager {
} }
items.add(new JobItems(oneItemName.toLowerCase(), id == null ? CMIMaterial.STONE : CMIMaterial.get(id), amount, name, giveLore, items.add(new JobItems(oneItemName.toLowerCase(), id == null ? CMIMaterial.STONE : CMIMaterial.get(id), amount, name, giveLore,
enchants, new BoostMultiplier(), new ArrayList<Job>(), potionData, null)); enchants, new BoostMultiplier(), new ArrayList<>(), potionData, null));
} }
sItem.setitems(items); sItem.setitems(items);
} }

View File

@ -34,7 +34,7 @@ public class BoostMultiplier implements Cloneable {
} }
public BoostMultiplier add(double amount) { public BoostMultiplier add(double amount) {
if (amount > 0) { if (amount != 0) {
for (CurrencyType one : CurrencyType.values()) { for (CurrencyType one : CurrencyType.values()) {
map.put(one, amount); map.put(one, amount);
} }

View File

@ -984,7 +984,9 @@ public class JobsPlayer {
return false; return false;
for (QuestProgression one : qpl.values()) { for (QuestProgression one : qpl.values()) {
if (one.getQuest() != null && one.getQuest().getConfigName().equalsIgnoreCase(questName)) Quest quest = one.getQuest();
if (quest != null && quest.getConfigName().equalsIgnoreCase(questName))
return true; return true;
} }
@ -1001,13 +1003,17 @@ public class JobsPlayer {
return ls; return ls;
for (QuestProgression prog : qpl.values()) { for (QuestProgression prog : qpl.values()) {
if (prog.isEnded() || prog.getQuest() == null) if (prog.isEnded())
continue; continue;
for (Map<String, QuestObjective> oneAction : prog.getQuest().getObjectives().values()) { Quest quest = prog.getQuest();
if (quest == null)
continue;
for (Map<String, QuestObjective> oneAction : quest.getObjectives().values()) {
for (QuestObjective oneObjective : oneAction.values()) { for (QuestObjective oneObjective : oneAction.values()) {
if (type == null || type.name().equals(oneObjective.getAction().name())) { if (type == null || type.name().equals(oneObjective.getAction().name())) {
ls.add(prog.getQuest().getConfigName().toLowerCase()); ls.add(quest.getConfigName().toLowerCase());
break; break;
} }
} }
@ -1023,8 +1029,10 @@ public class JobsPlayer {
public void resetQuests(List<QuestProgression> quests) { public void resetQuests(List<QuestProgression> quests) {
for (QuestProgression oneQ : quests) { for (QuestProgression oneQ : quests) {
if (oneQ.getQuest() != null) { Quest quest = oneQ.getQuest();
Map<String, QuestProgression> map = qProgression.remove(oneQ.getQuest().getJob().getName());
if (quest != null) {
Map<String, QuestProgression> map = qProgression.remove(quest.getJob().getName());
if (map != null) { if (map != null) {
map.clear(); map.clear();
@ -1044,17 +1052,23 @@ public class JobsPlayer {
} }
public void getNewQuests(Job job) { public void getNewQuests(Job job) {
java.util.Optional.ofNullable(qProgression.get(job.getName())).ifPresent(Map::clear); Map<String, QuestProgression> prog = qProgression.get(job.getName());
if (prog != null) {
prog.clear();
qProgression.put(job.getName(), prog);
}
} }
public void replaceQuest(Quest quest) { public void replaceQuest(Quest quest) {
Map<String, QuestProgression> orProg = qProgression.get(quest.getJob().getName()); Job job = quest.getJob();
Map<String, QuestProgression> orProg = qProgression.get(job.getName());
Quest q = quest.getJob().getNextQuest(getQuestNameList(quest.getJob(), null), getJobProgression(quest.getJob()).getLevel()); Quest q = job.getNextQuest(getQuestNameList(job, null), getJobProgression(job).getLevel());
if (q == null) { if (q == null) {
for (JobProgression one : progression) { for (JobProgression one : progression) {
if (one.getJob().isSame(quest.getJob())) if (one.getJob().isSame(job))
continue; continue;
q = one.getJob().getNextQuest(getQuestNameList(one.getJob(), null), getJobProgression(one.getJob()).getLevel()); q = one.getJob().getNextQuest(getQuestNameList(one.getJob(), null), getJobProgression(one.getJob()).getLevel());
if (q != null) if (q != null)
break; break;
@ -1064,10 +1078,12 @@ public class JobsPlayer {
if (q == null) if (q == null)
return; return;
Map<String, QuestProgression> prog = qProgression.get(q.getJob().getName()); Job qJob = q.getJob();
Map<String, QuestProgression> prog = qProgression.get(qJob.getName());
if (prog == null) { if (prog == null) {
prog = new HashMap<>(); prog = new HashMap<>();
qProgression.put(q.getJob().getName(), prog); qProgression.put(qJob.getName(), prog);
} }
if (q.getConfigName().equals(quest.getConfigName())) if (q.getConfigName().equals(quest.getConfigName()))
@ -1078,7 +1094,7 @@ public class JobsPlayer {
if (prog.containsKey(confName)) if (prog.containsKey(confName))
return; return;
if (q.getJob() != quest.getJob() && prog.size() >= q.getJob().getMaxDailyQuests()) if (!qJob.isSame(job) && prog.size() >= qJob.getMaxDailyQuests())
return; return;
if (orProg != null) { if (orProg != null) {
@ -1130,8 +1146,9 @@ public class JobsPlayer {
continue; continue;
QuestProgression qp = new QuestProgression(q); QuestProgression qp = new QuestProgression(q);
if (qp.getQuest() != null) Quest quest = qp.getQuest();
g.put(qp.getQuest().getConfigName().toLowerCase(), qp); if (quest != null)
g.put(quest.getConfigName().toLowerCase(), qp);
if (g.size() >= job.getMaxDailyQuests()) if (g.size() >= job.getMaxDailyQuests())
break; break;
@ -1277,8 +1294,8 @@ public class JobsPlayer {
private Integer questSignUpdateShed; private Integer questSignUpdateShed;
public void addDoneQuest(final Job job) { public void addDoneQuest(final Job job) {
this.doneQuests++; doneQuests++;
this.setSaved(false); setSaved(false);
if (questSignUpdateShed == null) { if (questSignUpdateShed == null) {
questSignUpdateShed = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> { questSignUpdateShed = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> {

View File

@ -25,7 +25,11 @@ public class QuestProgression {
} }
public Quest getQuest() { public Quest getQuest() {
return (quest == null || quest.getJob() == null) ? null : quest.getJob().getQuest(quest.getConfigName()); if (quest == null)
return null;
Job job = quest.getJob();
return job == null ? null : job.getQuest(quest.getConfigName());
} }
public void setQuest(Quest quest) { public void setQuest(Quest quest) {

View File

@ -34,7 +34,7 @@ public class JobsConnectionPool {
return connection; return connection;
} }
public synchronized void closeConnection() { public void closeConnection() {
if (connection != null) { if (connection != null) {
try { try {
connection.closeConnection(); connection.closeConnection();

View File

@ -505,8 +505,12 @@ public abstract class JobsDAO {
public abstract boolean drop(String table); public abstract boolean drop(String table);
public boolean isConnected() { public boolean isConnected() {
if (pool == null)
return false;
try { try {
return pool != null && pool.getConnection() != null && !pool.getConnection().isClosed(); JobsConnection conn = pool.getConnection();
return conn != null && !conn.isClosed();
} catch (SQLException e) { } catch (SQLException e) {
return false; return false;
} }
@ -2657,7 +2661,7 @@ public abstract class JobsDAO {
/** /**
* Close all active database handles * Close all active database handles
*/ */
public synchronized void closeConnections() { public void closeConnections() {
pool.closeConnection(); pool.closeConnection();
} }