From 283525e853cd439afa66c642053df11f8f6063a4 Mon Sep 17 00:00:00 2001 From: montlikadani Date: Mon, 24 Aug 2020 08:00:13 +0200 Subject: [PATCH] Trying to fix resetquest - Fix for quest tabcomplete --- .../gamingmesh/jobs/commands/list/browse.java | 38 +++++-------------- .../jobs/commands/list/resetquest.java | 15 +------- .../gamingmesh/jobs/container/JobsPlayer.java | 17 ++++++--- .../com/gamingmesh/jobs/container/Quest.java | 6 ++- .../gamingmesh/jobs/stuff/TabComplete.java | 11 +++--- 5 files changed, 32 insertions(+), 55 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/browse.java b/src/main/java/com/gamingmesh/jobs/commands/list/browse.java index 6a198514..2f2b3608 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/browse.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/browse.java @@ -22,25 +22,19 @@ public class browse implements Cmd { if (Jobs.getGCManager().BrowseUseNewLook) { List jobList = new ArrayList<>(Jobs.getJobs()); - if (jobList.isEmpty()) { sender.sendMessage(Jobs.getLanguage().getMessage("command.browse.error.nojobs")); return true; } if (sender instanceof Player && Jobs.getGCManager().JobsGUIOpenOnBrowse) { -// Inventory inv = null; try { Jobs.getGUIManager().openJobsBrowseGUI((Player) sender); } catch (Throwable e) { ((Player) sender).closeInventory(); -// Jobs.getGUIManager().GuiList.remove(((Player) sender).getUniqueId()); return true; } -// if (inv == null) -// return true; -// if (Jobs.getGUIManager().isInGui((Player) sender)) -// ((Player) sender).openInventory(inv); + return true; } @@ -52,18 +46,15 @@ public class browse implements Cmd { try { page = Integer.parseInt(one.substring("-p:".length())); continue; - } catch (Throwable e) { + } catch (Exception e) { } } } } for (String one : args) { if (one.startsWith("-j:")) { - try { - j = Jobs.getJob(one.substring("-j:".length())); - continue; - } catch (Throwable e) { - } + j = Jobs.getJob(one.substring("-j:".length())); + continue; } } @@ -82,7 +73,7 @@ public class browse implements Cmd { String hoverMsg = ""; if (!one.getDescription().isEmpty()) - hoverMsg += Jobs.getLanguage().getMessage("command.browse.output.description", "[description]", one.getDescription().replace("/n", "")); + hoverMsg += Jobs.getLanguage().getMessage("command.browse.output.description", "[description]", one.getDescription().replaceAll("/n|\n", "")); if (one.getMaxLevel(sender) > 0) { if (!hoverMsg.isEmpty()) @@ -152,11 +143,10 @@ public class browse implements Cmd { if (j == null) { sender.sendMessage(Jobs.getLanguage().getMessage("command.browse.output.console.newHeader", "[amount]", jobList.size(), "\\n", "\n")); for (Job one : jobList) { - String msg = ""; if (!one.getDescription().isEmpty()) - msg += Jobs.getLanguage().getMessage("command.browse.output.console.description", "[description]", one.getDescription().replace("/n", "")); + msg += Jobs.getLanguage().getMessage("command.browse.output.console.description", "[description]", one.getDescription().replaceAll("/n|\n", "")); if (one.getMaxLevel(sender) > 0) msg += Jobs.getLanguage().getMessage("command.browse.output.console.newMax", "[max]", one.getMaxLevel(sender)); @@ -176,7 +166,6 @@ public class browse implements Cmd { sender.sendMessage(msg); } } else { - sender.sendMessage(Jobs.getLanguage().getMessage("command.browse.output.jobHeader", "[jobname]", j.getName())); if (j.getMaxLevel(sender) > 0) @@ -199,15 +188,14 @@ public class browse implements Cmd { } } } - } else { - ArrayList lines = new ArrayList<>(); for (Job job : Jobs.getJobs()) { if (Jobs.getGCManager().getHideJobsWithoutPermission()) { if (!Jobs.getCommandManager().hasJobPermission(sender, job)) continue; } + StringBuilder builder = new StringBuilder(); builder.append(" "); builder.append(job.getChatColor().toString()); @@ -229,7 +217,7 @@ public class browse implements Cmd { lines.add(builder.toString()); if (!job.getDescription().isEmpty()) - lines.add(" - " + job.getDescription().replace("/n", "")); + lines.add(" - " + job.getDescription().replaceAll("/n|\n", "")); } if (lines.isEmpty()) { @@ -238,27 +226,19 @@ public class browse implements Cmd { } if (sender instanceof Player && Jobs.getGCManager().JobsGUIOpenOnBrowse) { - try { Jobs.getGUIManager().openJobsBrowseGUI((Player) sender); } catch (Throwable e) { ((Player) sender).closeInventory(); -// Jobs.getGUIManager().GuiList.remove(((Player) sender).getUniqueId()); return true; } -// if (inv == null) -// return true; -// if (Jobs.getGUIManager().isInGui((Player) sender)) -// ((Player) sender).openInventory(inv); return true; } if (Jobs.getGCManager().JobsGUIShowChatBrowse) { sender.sendMessage(Jobs.getLanguage().getMessage("command.browse.output.header")); - for (String line : lines) { - sender.sendMessage(line); - } + lines.forEach(sender::sendMessage); sender.sendMessage(Jobs.getLanguage().getMessage("command.browse.output.footer")); } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/resetquest.java b/src/main/java/com/gamingmesh/jobs/commands/list/resetquest.java index 4e82ceb0..a3a1bd22 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/resetquest.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/resetquest.java @@ -1,6 +1,5 @@ package com.gamingmesh.jobs.commands.list; -import java.util.HashMap; import java.util.List; import org.bukkit.command.CommandSender; @@ -11,7 +10,6 @@ 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.QuestObjective; import com.gamingmesh.jobs.container.QuestProgression; public class resetquest implements Cmd { @@ -49,21 +47,12 @@ public class resetquest implements Cmd { if (job != null) quests = jPlayer.getQuestProgressions(job); - if (quests == null || quests.isEmpty()) { + if (quests.isEmpty()) { sender.sendMessage(Jobs.getLanguage().getMessage("command.resetquest.output.noQuests")); return true; } - for (QuestProgression one : quests) { - one.setValidUntil(System.currentTimeMillis()); - for (HashMap actions : one.getQuest().getObjectives().values()) { - for (QuestObjective obj : actions.values()) { - one.setAmountDone(obj, 0); - } - } - } - - jPlayer.resetQuests(); + jPlayer.resetQuests(quests); sender.sendMessage(Jobs.getLanguage().getMessage("command.resetquest.output.reseted", "%playername%", jPlayer.getName())); return true; } diff --git a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java index c0abe1cf..73d9061c 100644 --- a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java +++ b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java @@ -914,17 +914,22 @@ public class JobsPlayer { } public void resetQuests(Job job) { - for (QuestProgression oneQ : getQuestProgressions(job)) { + resetQuests(getQuestProgressions(job)); + } + + public void resetQuests(List quests) { + for (QuestProgression oneQ : quests) { if (oneQ.getQuest() == null) { continue; } - oneQ.setValidUntil(System.currentTimeMillis()); - for (HashMap base : oneQ.getQuest().getObjectives().values()) { - for (QuestObjective obj : base.values()) { - oneQ.setAmountDone(obj, 0); - } + Job job = oneQ.getQuest().getJob(); + getNewQuests(job); + if (qProgression.containsKey(job.getName())) { + qProgression.remove(job.getName()); } + + oneQ.getQuest().setObjectives(null); } } diff --git a/src/main/java/com/gamingmesh/jobs/container/Quest.java b/src/main/java/com/gamingmesh/jobs/container/Quest.java index 113c3b33..e1ff7c1e 100644 --- a/src/main/java/com/gamingmesh/jobs/container/Quest.java +++ b/src/main/java/com/gamingmesh/jobs/container/Quest.java @@ -176,6 +176,10 @@ public class Quest { } public void setObjectives(HashMap> objectives) { + if (objectives == null) { + objectives = new HashMap<>(); + } + this.objectives = objectives; objectives.keySet().forEach(actions::add); } @@ -192,6 +196,6 @@ public class Quest { } public boolean hasAction(ActionType action) { - return this.actions.contains(action); + return actions.contains(action); } } diff --git a/src/main/java/com/gamingmesh/jobs/stuff/TabComplete.java b/src/main/java/com/gamingmesh/jobs/stuff/TabComplete.java index 0c30f567..552408a2 100644 --- a/src/main/java/com/gamingmesh/jobs/stuff/TabComplete.java +++ b/src/main/java/com/gamingmesh/jobs/stuff/TabComplete.java @@ -20,7 +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; +import com.gamingmesh.jobs.container.Quest; public class TabComplete implements TabCompleter { @@ -66,11 +66,10 @@ public class TabComplete implements TabCompleter { 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()); + Job job = Jobs.getJob(args[i - 1]); + if (job != null) { + for (Quest q : job.getQuests()) { + temp.add(q.getQuestName()); } } break;