1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-01-04 23:37:49 +01:00

Added sub-command to start or stop the quests for player

This commit is contained in:
montlikadani 2020-04-16 19:47:44 +02:00
parent 3fc2487bfd
commit 97ee33e46e
4 changed files with 105 additions and 62 deletions

View File

@ -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<QuestProgression> 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<String> 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<ActionType, HashMap<String, QuestObjective>> oneAction : q.getQuest().getObjectives().entrySet()) {
for (Entry<String, QuestObjective> 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<QuestProgression> 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<QuestProgression> 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<String> 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<ActionType, HashMap<String, QuestObjective>> oneAction : q.getQuest().getObjectives().entrySet()) {
for (Entry<String, QuestObjective> 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;
}
}

View File

@ -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");

View File

@ -25,6 +25,8 @@ public class Quest {
private List<String> rewards = new ArrayList<>();
private List<String> area = new ArrayList<>();
private boolean stopped = false;
private HashMap<ActionType, HashMap<String, QuestObjective>> objectives = new HashMap<>();
private Set<ActionType> 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<String> getRewardCmds() {
return rewardCmds;
}

View File

@ -88,6 +88,10 @@ public class QuestProgression {
}
public void processQuest(JobsPlayer jPlayer, ActionInfo action) {
if (quest.isStopped()) {
return;
}
if (!quest.hasAction(action.getType()))
return;