From 958329778a275cad46dabc7e0fdfa41b2e741471 Mon Sep 17 00:00:00 2001 From: montlikadani Date: Sun, 23 Aug 2020 20:34:53 +0200 Subject: [PATCH] Fix when the completed quests can be skipped Fixes #863 - Added tab complete for skipquest --- .../jobs/Placeholders/Placeholder.java | 2 +- .../gamingmesh/jobs/commands/list/quests.java | 2 +- .../jobs/commands/list/skipquest.java | 7 ++++ .../jobs/config/LanguageManager.java | 1 + .../gamingmesh/jobs/container/JobsPlayer.java | 41 +++++++++---------- .../jobs/economy/BufferedEconomy.java | 2 +- .../jobs/economy/BufferedPayment.java | 7 ++-- .../gamingmesh/jobs/stuff/TabComplete.java | 11 +++++ 8 files changed, 44 insertions(+), 29 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/Placeholders/Placeholder.java b/src/main/java/com/gamingmesh/jobs/Placeholders/Placeholder.java index 4f33a7bf..daf535e4 100644 --- a/src/main/java/com/gamingmesh/jobs/Placeholders/Placeholder.java +++ b/src/main/java/com/gamingmesh/jobs/Placeholders/Placeholder.java @@ -522,7 +522,7 @@ public class Placeholder { case maxjobs: Double max = Jobs.getPermissionManager().getMaxPermission(user, "jobs.max"); - max = max == null ? Jobs.getGCManager().getMaxJobs() : max; + max = max == 0D ? Jobs.getGCManager().getMaxJobs() : max; return Double.toString(max); default: break; diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/quests.java b/src/main/java/com/gamingmesh/jobs/commands/list/quests.java index 14043a8c..2a1f0456 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/quests.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/quests.java @@ -126,7 +126,7 @@ public class quests implements Cmd { hover += one; } - if (list.size() < jobProg.getJob().getQuests().size() && Jobs.getGCManager().getDailyQuestsSkips() > jPlayer.getSkippedQuests()) { + if (list.size() < jobProg.getJob().getQuests().size() && Jobs.getGCManager().getDailyQuestsSkips() > jPlayer.getSkippedQuests() && !q.isCompleted()) { if (Jobs.getGCManager().getDailyQuestsSkips() > 0) { hover += "\n" + Jobs.getLanguage().getMessage("command.quests.output.skip"); hover += "\n" + Jobs.getLanguage().getMessage("command.quests.output.skips", "[skips]", (Jobs.getGCManager().getDailyQuestsSkips() - jPlayer.getSkippedQuests())); diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/skipquest.java b/src/main/java/com/gamingmesh/jobs/commands/list/skipquest.java index 581ab324..27c7d749 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/skipquest.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/skipquest.java @@ -75,6 +75,13 @@ public class skipquest implements Cmd { return false; } + // Do not skip the completed quests + for (QuestProgression q : quests) { + if (q.getQuest().getQuestName().equals(old.getQuestName()) && q.isCompleted()) { + return false; + } + } + if (Jobs.getGCManager().getDailyQuestsSkips() <= jPlayer.getSkippedQuests()) return false; diff --git a/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java b/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java index 7cf534ab..53dc31ec 100644 --- a/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java @@ -464,6 +464,7 @@ public class LanguageManager { c.get("command.skipquest.help.info", "Skip defined quest and get new one"); c.get("command.skipquest.help.args", "[jobname] [questname] (playerName)"); c.get("command.skipquest.output.questSkipForCost", "&2You skipped the quest and paid:&e %amount%$"); + Jobs.getGCManager().getCommandArgs().put("skipquest", Arrays.asList("[jobname]", "[questname]", "[playername]")); c.get("command.quests.help.info", "List available quests"); c.get("command.quests.help.args", "[playername]"); diff --git a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java index 82a300b4..c0abe1cf 100644 --- a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java +++ b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java @@ -879,8 +879,8 @@ public class JobsPlayer { if (qpl == null) return false; - for (Entry one : qpl.entrySet()) { - if (one.getValue().getQuest() != null && one.getValue().getQuest().getConfigName().equalsIgnoreCase(questName)) + for (QuestProgression one : qpl.values()) { + if (one.getQuest() != null && one.getQuest().getConfigName().equalsIgnoreCase(questName)) return true; } @@ -896,14 +896,13 @@ public class JobsPlayer { if (qpl == null) return ls; - for (Entry one : qpl.entrySet()) { - QuestProgression prog = one.getValue(); + for (QuestProgression prog : qpl.values()) { if (prog.isEnded() || prog.getQuest() == null) continue; - for (Entry> oneAction : prog.getQuest().getObjectives().entrySet()) { - for (Entry oneObjective : oneAction.getValue().entrySet()) { - if (type == null || type.name().equals(oneObjective.getValue().getAction().name())) { + for (HashMap oneAction : prog.getQuest().getObjectives().values()) { + for (QuestObjective oneObjective : oneAction.values()) { + if (type == null || type.name().equals(oneObjective.getAction().name())) { ls.add(prog.getQuest().getConfigName().toLowerCase()); break; } @@ -921,9 +920,9 @@ public class JobsPlayer { } oneQ.setValidUntil(System.currentTimeMillis()); - for (Entry> base : oneQ.getQuest().getObjectives().entrySet()) { - for (Entry obj : base.getValue().entrySet()) { - oneQ.setAmountDone(obj.getValue(), 0); + for (HashMap base : oneQ.getQuest().getObjectives().values()) { + for (QuestObjective obj : base.values()) { + oneQ.setAmountDone(obj, 0); } } } @@ -1038,7 +1037,7 @@ public class JobsPlayer { while (i > 0) { --i; - g.remove(g.entrySet().iterator().next().getKey()); + g.remove(g.keySet().iterator().next()); if (g.size() <= job.getMaxDailyQuests()) break; @@ -1047,31 +1046,29 @@ public class JobsPlayer { qProgression.put(job.getName(), g); - for (Entry oneJ : g.entrySet()) { - Quest q = oneJ.getValue().getQuest(); + for (QuestProgression oneJ : g.values()) { + Quest q = oneJ.getQuest(); if (q == null) { continue; } if (type == null) { - tmp.put(q.getConfigName().toLowerCase(), oneJ.getValue()); + tmp.put(q.getConfigName().toLowerCase(), oneJ); continue; } HashMap old = q.getObjectives().get(type); if (old != null) - for (Entry one : old.entrySet()) { - if (type.name().equals(one.getValue().getAction().name())) { - tmp.put(q.getConfigName().toLowerCase(), oneJ.getValue()); + for (QuestObjective one : old.values()) { + if (type.name().equals(one.getAction().name())) { + tmp.put(q.getConfigName().toLowerCase(), oneJ); break; } } } List pr = new ArrayList<>(); - for (Entry one : tmp.entrySet()) { - pr.add(one.getValue()); - } + tmp.values().forEach(pr::add); return pr; } @@ -1089,8 +1086,8 @@ public class JobsPlayer { prog += q.getJob().getName() + ":" + q.getConfigName() + ":" + one.getValidUntil() + ":"; - for (Entry> oneA : q.getObjectives().entrySet()) { - for (Entry oneO : oneA.getValue().entrySet()) { + for (HashMap oneA : q.getObjectives().values()) { + for (Entry oneO : oneA.entrySet()) { prog += oneO.getValue().getAction().toString() + ";" + oneO.getKey() + ";" + one.getAmountDone(oneO.getValue()) + ":;:"; } } diff --git a/src/main/java/com/gamingmesh/jobs/economy/BufferedEconomy.java b/src/main/java/com/gamingmesh/jobs/economy/BufferedEconomy.java index 4d5d3c41..d2cdffd3 100644 --- a/src/main/java/com/gamingmesh/jobs/economy/BufferedEconomy.java +++ b/src/main/java/com/gamingmesh/jobs/economy/BufferedEconomy.java @@ -39,7 +39,7 @@ import java.util.concurrent.LinkedBlockingQueue; public class BufferedEconomy { private Jobs plugin; private Economy economy; - private LinkedBlockingQueue payments = new LinkedBlockingQueue<>(); + private final LinkedBlockingQueue payments = new LinkedBlockingQueue<>(); private final Map paymentCache = Collections.synchronizedMap(new HashMap()); private OfflinePlayer ServerTaxesAccount = null; diff --git a/src/main/java/com/gamingmesh/jobs/economy/BufferedPayment.java b/src/main/java/com/gamingmesh/jobs/economy/BufferedPayment.java index b169703f..177e8314 100644 --- a/src/main/java/com/gamingmesh/jobs/economy/BufferedPayment.java +++ b/src/main/java/com/gamingmesh/jobs/economy/BufferedPayment.java @@ -19,7 +19,6 @@ package com.gamingmesh.jobs.economy; import java.util.HashMap; -import java.util.Map.Entry; import org.bukkit.OfflinePlayer; @@ -27,7 +26,7 @@ import com.gamingmesh.jobs.container.CurrencyType; public class BufferedPayment { private OfflinePlayer offlinePlayer; - private HashMap payments = new HashMap(); + private final HashMap payments = new HashMap<>(); @Deprecated public BufferedPayment(OfflinePlayer offlinePlayer, double amount, double points, double exp) { @@ -89,8 +88,8 @@ public class BufferedPayment { } public boolean containsPayment() { - for (Entry one : payments.entrySet()) { - if (one.getValue() != 0D) + for (Double one : payments.values()) { + if (one != 0D) return true; } return false; diff --git a/src/main/java/com/gamingmesh/jobs/stuff/TabComplete.java b/src/main/java/com/gamingmesh/jobs/stuff/TabComplete.java index b4ccf654..0c30f567 100644 --- a/src/main/java/com/gamingmesh/jobs/stuff/TabComplete.java +++ b/src/main/java/com/gamingmesh/jobs/stuff/TabComplete.java @@ -20,6 +20,7 @@ import com.gamingmesh.jobs.container.JobItems; import com.gamingmesh.jobs.container.JobLimitedItems; import com.gamingmesh.jobs.container.JobProgression; import com.gamingmesh.jobs.container.JobsPlayer; +import com.gamingmesh.jobs.container.QuestProgression; public class TabComplete implements TabCompleter { @@ -63,6 +64,16 @@ public class TabComplete implements TabCompleter { List temp = new ArrayList<>(); for (String ar : t2) { switch (ar) { + case "[questname]": + case "[quest]": + JobsPlayer playerJob = Jobs.getPlayerManager().getJobsPlayer(args[i - 1]); + if (playerJob != null) { + for (QuestProgression prog : playerJob.getQuestProgressions()) { + if (prog.getQuest() != null) + temp.add(prog.getQuest().getQuestName()); + } + } + break; case "[jobname]": case "[newjob]": for (Job one : Jobs.getJobs()) {