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 a8c6c34e..c74494f0 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/quests.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/quests.java @@ -13,6 +13,7 @@ import com.gamingmesh.jobs.container.JobProgression; import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.container.QuestProgression; import com.gamingmesh.jobs.CMILib.RawMessage; +import com.gamingmesh.jobs.stuff.Debug; import com.gamingmesh.jobs.stuff.TimeManage; public class quests implements Cmd { @@ -54,9 +55,11 @@ public class quests implements Cmd { if (sender instanceof Player) { for (JobProgression jobProg : jPlayer.getJobProgression()) { List list = jPlayer.getQuestProgressions(jobProg.getJob()); + Debug.D("Quest size: " + list.size()); for (QuestProgression q : list) { String progressLine = Jobs.getCommandManager().jobProgressMessage(q.getQuest().getAmount(), q.getAmountDone()); - if (q.isComplited()) + + if (q.isCompleted()) progressLine = Jobs.getLanguage().getMessage("command.quests.output.completed"); RawMessage rm = new RawMessage(); String msg = Jobs.getLanguage().getMessage("command.quests.output.questLine", "[progress]", diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/resetquest.java b/src/main/java/com/gamingmesh/jobs/commands/list/resetquest.java new file mode 100644 index 00000000..5da5ddcd --- /dev/null +++ b/src/main/java/com/gamingmesh/jobs/commands/list/resetquest.java @@ -0,0 +1,63 @@ +package com.gamingmesh.jobs.commands.list; + +import java.util.List; + +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import com.gamingmesh.jobs.Jobs; +import com.gamingmesh.jobs.commands.Cmd; +import com.gamingmesh.jobs.commands.JobCommand; +import com.gamingmesh.jobs.container.Job; +import com.gamingmesh.jobs.container.JobsPlayer; +import com.gamingmesh.jobs.container.QuestProgression; + +public class resetquest implements Cmd { + + @Override + @JobCommand(700) + public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { + if (args.length != 0 && args.length != 1 && args.length != 2) { + Jobs.getCommandManager().sendUsage(sender, "resetquest"); + return true; + } + + JobsPlayer jPlayer = null; + Job job = null; + + for (String one : args) { + if (job == null) { + job = Jobs.getJob(one); + if (job != null) + continue; + } + jPlayer = Jobs.getPlayerManager().getJobsPlayer(one); + } + + if (jPlayer == null && sender instanceof Player) + jPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender); + + if (jPlayer == null) { + sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfoByPlayer", "%playername%", args.length > 0 ? args[0] : "")); + return true; + } + + List quests = jPlayer.getQuestProgressions(); + + if (job != null) + quests = jPlayer.getQuestProgressions(job); + + if (quests == null || quests.isEmpty()) { + sender.sendMessage(Jobs.getLanguage().getMessage("command.resetquest.output.noQuests")); + return true; + } + + for (QuestProgression one : quests) { + one.setValidUntil(System.currentTimeMillis()); + } + + sender.sendMessage(Jobs.getLanguage().getMessage("command.resetquest.output.reseted", "%playername%", jPlayer.getUserName())); + + return true; + } +} diff --git a/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java b/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java index 705bed3b..50361d46 100644 --- a/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java @@ -240,6 +240,11 @@ public class LanguageManager { c.get("command.resetlimit.help.args", "[playername]"); c.get("command.resetlimit.output.reseted", "&ePayment limits have been reset for: &2%playername%"); + c.get("command.resetquest.help.info", "Resets players quest"); + c.get("command.resetquest.help.args", "[playername] (job)"); + c.get("command.resetquest.output.reseted", "&eQuest have been reset for: &2%playername%"); + c.get("command.resetquest.output.noQuests", "&eCan't find any quests"); + c.get("command.points.help.info", "Shows how much points player have."); c.get("command.points.help.args", "[playername]"); Jobs.getGCManager().commandArgs.put("points", Arrays.asList("[playername]")); diff --git a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java index 15885702..80da23b5 100644 --- a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java +++ b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; +import java.util.Map.Entry; import java.util.UUID; import org.bukkit.Bukkit; @@ -76,7 +77,7 @@ public class JobsPlayer { private HashMap permissionsCache = null; private Long lastPermissionUpdate = -1L; - private HashMap> qProgression = new HashMap<>(); + private HashMap> qProgression = new HashMap<>(); private int doneQuests = 0; public JobsPlayer(String userName, OfflinePlayer player) { @@ -827,12 +828,12 @@ public class JobsPlayer { public boolean inDailyQuest(Job job, String questName) { - List qpl = this.qProgression.get(job.getName()); + HashMap qpl = this.qProgression.get(job.getName()); if (qpl == null) return false; - for (QuestProgression one : qpl) { - if (one.getQuest().getConfigName().equalsIgnoreCase(questName)) + for (Entry one : qpl.entrySet()) { + if (one.getValue().getQuest().getConfigName().equalsIgnoreCase(questName)) return true; } @@ -844,15 +845,15 @@ public class JobsPlayer { if (!this.isInJob(job)) return ls; - List qpl = this.qProgression.get(job.getName()); + HashMap qpl = this.qProgression.get(job.getName()); if (qpl == null) return ls; - for (QuestProgression one : qpl) { - - if (!one.isEnded() && (type == null || type.name().equals(one.getQuest().getAction().name()))) - ls.add(one.getQuest().getConfigName().toLowerCase()); + for (Entry one : qpl.entrySet()) { + QuestProgression prog = one.getValue(); + if (!prog.isEnded() && (type == null || type.name().equals(prog.getQuest().getAction().name()))) + ls.add(prog.getQuest().getConfigName().toLowerCase()); } return ls; @@ -881,23 +882,16 @@ public class JobsPlayer { public List getQuestProgressions(Job job, ActionType type) { if (!this.isInJob(job)) - return null; - List g = new ArrayList<>(); + return new ArrayList<>(); + HashMap g = new HashMap<>(); if (this.qProgression.get(job.getName()) != null) - g = new ArrayList<>(this.qProgression.get(job.getName())); + g = new HashMap<>(this.qProgression.get(job.getName())); - List tmp = new ArrayList<>(); + HashMap tmp = new HashMap<>(); - if (!g.isEmpty()) { - if (g.get(0).isEnded()) { - g.clear(); - this.qProgression.clear(); - } - } - - for (QuestProgression one : new ArrayList(g)) { - QuestProgression qp = one; + for (Entry one : (new HashMap(g)).entrySet()) { + QuestProgression qp = one.getValue(); if (qp == null || !qp.isValid()) { Quest q = job.getNextQuest(getQuestNameList(job, type), this.getJobProgression(job).getLevel()); @@ -909,11 +903,11 @@ public class JobsPlayer { if (g.size() >= job.getMaxDailyQuests()) continue; - g.add(qp); + g.put(qp.getQuest().getConfigName(), qp); } if (type == null || type.name().equals(qp.getQuest().getAction().name())) - tmp.add(qp); + tmp.put(qp.getQuest().getConfigName(), qp); } this.qProgression.put(job.getName(), g); @@ -925,14 +919,21 @@ public class JobsPlayer { if (q == null) continue; QuestProgression qp = new QuestProgression(q); - g.add(qp); + g.put(qp.getQuest().getConfigName(), qp); if (type == null || type.name().equals(qp.getQuest().getAction().name())) - tmp.add(qp); + tmp.put(qp.getQuest().getConfigName(), qp); } } + this.qProgression.put(job.getName(), g); - return tmp; + + List pr = new ArrayList(); + for (Entry one : tmp.entrySet()) { + pr.add(one.getValue()); + } + + return pr; } public int getDoneQuests() { diff --git a/src/main/java/com/gamingmesh/jobs/container/QuestProgression.java b/src/main/java/com/gamingmesh/jobs/container/QuestProgression.java index 2dbe12c5..71d07d23 100644 --- a/src/main/java/com/gamingmesh/jobs/container/QuestProgression.java +++ b/src/main/java/com/gamingmesh/jobs/container/QuestProgression.java @@ -49,7 +49,7 @@ public class QuestProgression { return validUntil < System.currentTimeMillis(); } - public boolean isComplited() { + public boolean isCompleted() { return amountDone >= quest.getAmount(); } @@ -61,10 +61,10 @@ public class QuestProgression { if (!quest.getTargetName().equalsIgnoreCase(action.getName()) && !quest.getTargetName().equalsIgnoreCase(action.getNameWithSub())) return; - if (!isComplited()) + if (!isCompleted()) amountDone++; - if (!isComplited()) + if (!isCompleted()) return; if (!jPlayer.isOnline())