From 97ee33e46ee46e7246801b19f02176e06345064b Mon Sep 17 00:00:00 2001 From: montlikadani Date: Thu, 16 Apr 2020 19:47:44 +0200 Subject: [PATCH] Added sub-command to start or stop the quests for player --- .../gamingmesh/jobs/commands/list/quests.java | 150 ++++++++++-------- .../jobs/config/LanguageManager.java | 3 + .../com/gamingmesh/jobs/container/Quest.java | 10 ++ .../jobs/container/QuestProgression.java | 4 + 4 files changed, 105 insertions(+), 62 deletions(-) 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 91b3644b..b4804d32 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/quests.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/quests.java @@ -26,11 +26,11 @@ public class quests implements Cmd { public boolean perform(Jobs plugin, final CommandSender sender, String[] args) { JobsPlayer jPlayer = null; - if (args.length >= 1 && args[0].equals("next")) { + if (args.length >= 1 && args[0].equals("next") && (!(args[0].equalsIgnoreCase("stop") || args[0].equalsIgnoreCase("start")))) { jPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender); jPlayer.resetQuests(); } else { - if (args.length >= 1) { + if (args.length >= 1 && (!(args[0].equalsIgnoreCase("stop") || args[0].equalsIgnoreCase("start")))) { if (!Jobs.hasPermission(sender, "jobs.command.admin.quests", true)) return true; @@ -52,68 +52,94 @@ public class quests implements Cmd { return true; } - sender.sendMessage(Jobs.getLanguage().getMessage("command.quests.toplineseparator", "[playerName]", jPlayer.getName(), "[questsDone]", jPlayer.getDoneQuests())); - if (sender instanceof Player) { - for (JobProgression jobProg : jPlayer.getJobProgression()) { - List list = jPlayer.getQuestProgressions(jobProg.getJob()); - - for (QuestProgression q : list) { - String progressLine = Jobs.getCommandManager().jobProgressMessage(q.getTotalAmountNeeded(), q.getTotalAmountDone()); - - 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]", - progressLine, "[questName]", q.getQuest().getQuestName(), "[done]", q.getTotalAmountDone(), "[required]", q.getTotalAmountNeeded()); - - String hoverMsg = Jobs.getLanguage().getMessage("command.quests.output.hover"); - List hoverList = new ArrayList<>(); - for (String current : hoverMsg.split("\n")) { - current = current.replace("[jobName]", jobProg.getJob().getName()) - .replace("[time]", TimeManage.to24hourShort(q.getValidUntil() - System.currentTimeMillis())); - - if (current.contains("[desc]")) { - for (String one : q.getQuest().getDescription()) { - hoverList.add(one); - } - } else { - hoverList.add(current); - } - } - - for (Entry> oneAction : q.getQuest().getObjectives().entrySet()) { - for (Entry oneObjective : oneAction.getValue().entrySet()) { - hoverList.add(Jobs.getLanguage().getMessage("command.info.output." + oneObjective.getValue().getAction().toString().toLowerCase() + ".info") + " " + - Jobs.getNameTranslatorManager().Translate(oneObjective.getKey(), oneObjective.getValue().getAction(), oneObjective.getValue().getTargetId(), oneObjective.getValue() - .getTargetMeta(), oneObjective.getValue().getTargetName()) - + " " + q.getAmountDone(oneObjective.getValue()) + "/" - + oneObjective.getValue().getAmount()); - } - } - - String hover = ""; - for (String one : hoverList) { - if (!hover.isEmpty()) - hover += "\n"; - hover += one; - } - - if (list.size() < jobProg.getJob().getQuests().size() && Jobs.getGCManager().getDailyQuestsSkips() > jPlayer.getSkippedQuests()) { - 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())); - } - rm.add(msg, hover, "jobs skipquest " + jobProg.getJob().getName() + " " + q.getQuest().getConfigName() + " " + jPlayer.getName()); - } else - rm.add(msg, hover); - rm.show(sender); - } + if (args.length >= 1) { + Boolean stopped = null; + String cmd = args.length == 1 ? args[0] : args[1]; + if (cmd.equalsIgnoreCase("stop")) { + stopped = true; + } else if (cmd.equalsIgnoreCase("start")) { + stopped = false; } - } else - return true; - sender.sendMessage(Jobs.getLanguage().getMessage("general.info.separator")); + if (stopped != null) { + for (JobProgression jobProg : jPlayer.getJobProgression()) { + List list = jPlayer.getQuestProgressions(jobProg.getJob()); + for (QuestProgression q : list) { + q.getQuest().setStopped(stopped); + } + } + + sender.sendMessage(Jobs.getLanguage().getMessage("command.quests.status.changed", "%status%", + stopped ? Jobs.getLanguage().getMessage("command.quests.status.stopped") : + Jobs.getLanguage().getMessage("command.quests.status.started"))); + return true; + } + } + + sender.sendMessage(Jobs.getLanguage().getMessage("command.quests.toplineseparator", "[playerName]", jPlayer.getName(), "[questsDone]", jPlayer.getDoneQuests())); + if (!(sender instanceof Player)) { + return true; + } + + for (JobProgression jobProg : jPlayer.getJobProgression()) { + List list = jPlayer.getQuestProgressions(jobProg.getJob()); + + for (QuestProgression q : list) { + String progressLine = Jobs.getCommandManager().jobProgressMessage(q.getTotalAmountNeeded(), q.getTotalAmountDone()); + + 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]", + progressLine, "[questName]", q.getQuest().getQuestName(), "[done]", q.getTotalAmountDone(), "[required]", q.getTotalAmountNeeded()); + + String hoverMsg = Jobs.getLanguage().getMessage("command.quests.output.hover"); + List hoverList = new ArrayList<>(); + for (String current : hoverMsg.split("\n")) { + current = current.replace("[jobName]", jobProg.getJob().getName()) + .replace("[time]", TimeManage.to24hourShort(q.getValidUntil() - System.currentTimeMillis())); + + if (current.contains("[desc]")) { + for (String one : q.getQuest().getDescription()) { + hoverList.add(one); + } + } else { + hoverList.add(current); + } + } + + for (Entry> oneAction : q.getQuest().getObjectives().entrySet()) { + for (Entry oneObjective : oneAction.getValue().entrySet()) { + hoverList.add(Jobs.getLanguage().getMessage("command.info.output." + oneObjective.getValue().getAction().toString().toLowerCase() + ".info") + " " + + Jobs.getNameTranslatorManager().Translate(oneObjective.getKey(), oneObjective.getValue().getAction(), oneObjective.getValue().getTargetId(), oneObjective.getValue() + .getTargetMeta(), oneObjective.getValue().getTargetName()) + + " " + q.getAmountDone(oneObjective.getValue()) + "/" + + oneObjective.getValue().getAmount()); + } + } + + String hover = ""; + for (String one : hoverList) { + if (!hover.isEmpty()) + hover += "\n"; + + hover += one; + } + + if (list.size() < jobProg.getJob().getQuests().size() && Jobs.getGCManager().getDailyQuestsSkips() > jPlayer.getSkippedQuests()) { + 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())); + } + rm.add(msg, hover, "jobs skipquest " + jobProg.getJob().getName() + " " + q.getQuest().getConfigName() + " " + jPlayer.getName()); + } else + rm.add(msg, hover); + rm.show(sender); + } + } + + sender.sendMessage(Jobs.getLanguage().getMessage("general.info.separator")); 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 22a03e11..44b5a410 100644 --- a/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java @@ -474,6 +474,9 @@ public class LanguageManager { Jobs.getGCManager().getCommandArgs().put("quests", Arrays.asList("[playername]")); c.get("command.quests.error.noquests", "&cThere are no quests"); c.get("command.quests.toplineseparator", "&7*********************** &6[playerName] &2(&f[questsDone]&2) &7***********************"); + c.get("command.quests.status.changed", "&2The quests status has been changed to&r %status%"); + c.get("command.quests.status.started", "&aStarted"); + c.get("command.quests.status.stopped", "&cStopped"); c.get("command.quests.output.completed", "&2 !Completed!&r "); c.get("command.quests.output.questLine", "[progress] &7[questName] &f[done]&7/&8[required]"); c.get("command.quests.output.skip", "&7Click to skip this quest"); diff --git a/src/main/java/com/gamingmesh/jobs/container/Quest.java b/src/main/java/com/gamingmesh/jobs/container/Quest.java index 1c41fd9f..f34d4d49 100644 --- a/src/main/java/com/gamingmesh/jobs/container/Quest.java +++ b/src/main/java/com/gamingmesh/jobs/container/Quest.java @@ -25,6 +25,8 @@ public class Quest { private List rewards = new ArrayList<>(); private List area = new ArrayList<>(); + private boolean stopped = false; + private HashMap> objectives = new HashMap<>(); private Set actions = new HashSet<>(); @@ -33,6 +35,14 @@ public class Quest { this.job = job; } + public boolean isStopped() { + return stopped; + } + + public void setStopped(boolean stopped) { + this.stopped = stopped; + } + public List getRewardCmds() { return rewardCmds; } diff --git a/src/main/java/com/gamingmesh/jobs/container/QuestProgression.java b/src/main/java/com/gamingmesh/jobs/container/QuestProgression.java index b05f2f20..a79efcbc 100644 --- a/src/main/java/com/gamingmesh/jobs/container/QuestProgression.java +++ b/src/main/java/com/gamingmesh/jobs/container/QuestProgression.java @@ -88,6 +88,10 @@ public class QuestProgression { } public void processQuest(JobsPlayer jPlayer, ActionInfo action) { + if (quest.isStopped()) { + return; + } + if (!quest.hasAction(action.getType())) return;