mirror of
https://github.com/Zrips/Jobs.git
synced 2024-11-26 04:25:15 +01:00
New command resetquest (playerName) (job)
Lets HashMap everything for quest progresion to avoid duplications
This commit is contained in:
parent
4fdb037fe9
commit
2a1663495c
@ -13,6 +13,7 @@ import com.gamingmesh.jobs.container.JobProgression;
|
|||||||
import com.gamingmesh.jobs.container.JobsPlayer;
|
import com.gamingmesh.jobs.container.JobsPlayer;
|
||||||
import com.gamingmesh.jobs.container.QuestProgression;
|
import com.gamingmesh.jobs.container.QuestProgression;
|
||||||
import com.gamingmesh.jobs.CMILib.RawMessage;
|
import com.gamingmesh.jobs.CMILib.RawMessage;
|
||||||
|
import com.gamingmesh.jobs.stuff.Debug;
|
||||||
import com.gamingmesh.jobs.stuff.TimeManage;
|
import com.gamingmesh.jobs.stuff.TimeManage;
|
||||||
|
|
||||||
public class quests implements Cmd {
|
public class quests implements Cmd {
|
||||||
@ -54,9 +55,11 @@ public class quests implements Cmd {
|
|||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
for (JobProgression jobProg : jPlayer.getJobProgression()) {
|
for (JobProgression jobProg : jPlayer.getJobProgression()) {
|
||||||
List<QuestProgression> list = jPlayer.getQuestProgressions(jobProg.getJob());
|
List<QuestProgression> list = jPlayer.getQuestProgressions(jobProg.getJob());
|
||||||
|
Debug.D("Quest size: " + list.size());
|
||||||
for (QuestProgression q : list) {
|
for (QuestProgression q : list) {
|
||||||
String progressLine = Jobs.getCommandManager().jobProgressMessage(q.getQuest().getAmount(), q.getAmountDone());
|
String progressLine = Jobs.getCommandManager().jobProgressMessage(q.getQuest().getAmount(), q.getAmountDone());
|
||||||
if (q.isComplited())
|
|
||||||
|
if (q.isCompleted())
|
||||||
progressLine = Jobs.getLanguage().getMessage("command.quests.output.completed");
|
progressLine = Jobs.getLanguage().getMessage("command.quests.output.completed");
|
||||||
RawMessage rm = new RawMessage();
|
RawMessage rm = new RawMessage();
|
||||||
String msg = Jobs.getLanguage().getMessage("command.quests.output.questLine", "[progress]",
|
String msg = Jobs.getLanguage().getMessage("command.quests.output.questLine", "[progress]",
|
||||||
|
@ -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<QuestProgression> 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;
|
||||||
|
}
|
||||||
|
}
|
@ -240,6 +240,11 @@ public class LanguageManager {
|
|||||||
c.get("command.resetlimit.help.args", "[playername]");
|
c.get("command.resetlimit.help.args", "[playername]");
|
||||||
c.get("command.resetlimit.output.reseted", "&ePayment limits have been reset for: &2%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.info", "Shows how much points player have.");
|
||||||
c.get("command.points.help.args", "[playername]");
|
c.get("command.points.help.args", "[playername]");
|
||||||
Jobs.getGCManager().commandArgs.put("points", Arrays.asList("[playername]"));
|
Jobs.getGCManager().commandArgs.put("points", Arrays.asList("[playername]"));
|
||||||
|
@ -22,6 +22,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -76,7 +77,7 @@ public class JobsPlayer {
|
|||||||
private HashMap<String, Boolean> permissionsCache = null;
|
private HashMap<String, Boolean> permissionsCache = null;
|
||||||
private Long lastPermissionUpdate = -1L;
|
private Long lastPermissionUpdate = -1L;
|
||||||
|
|
||||||
private HashMap<String, List<QuestProgression>> qProgression = new HashMap<>();
|
private HashMap<String, HashMap<String, QuestProgression>> qProgression = new HashMap<>();
|
||||||
private int doneQuests = 0;
|
private int doneQuests = 0;
|
||||||
|
|
||||||
public JobsPlayer(String userName, OfflinePlayer player) {
|
public JobsPlayer(String userName, OfflinePlayer player) {
|
||||||
@ -827,12 +828,12 @@ public class JobsPlayer {
|
|||||||
|
|
||||||
public boolean inDailyQuest(Job job, String questName) {
|
public boolean inDailyQuest(Job job, String questName) {
|
||||||
|
|
||||||
List<QuestProgression> qpl = this.qProgression.get(job.getName());
|
HashMap<String, QuestProgression> qpl = this.qProgression.get(job.getName());
|
||||||
if (qpl == null)
|
if (qpl == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (QuestProgression one : qpl) {
|
for (Entry<String, QuestProgression> one : qpl.entrySet()) {
|
||||||
if (one.getQuest().getConfigName().equalsIgnoreCase(questName))
|
if (one.getValue().getQuest().getConfigName().equalsIgnoreCase(questName))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -844,15 +845,15 @@ public class JobsPlayer {
|
|||||||
if (!this.isInJob(job))
|
if (!this.isInJob(job))
|
||||||
return ls;
|
return ls;
|
||||||
|
|
||||||
List<QuestProgression> qpl = this.qProgression.get(job.getName());
|
HashMap<String, QuestProgression> qpl = this.qProgression.get(job.getName());
|
||||||
|
|
||||||
if (qpl == null)
|
if (qpl == null)
|
||||||
return ls;
|
return ls;
|
||||||
|
|
||||||
for (QuestProgression one : qpl) {
|
for (Entry<String, QuestProgression> one : qpl.entrySet()) {
|
||||||
|
QuestProgression prog = one.getValue();
|
||||||
if (!one.isEnded() && (type == null || type.name().equals(one.getQuest().getAction().name())))
|
if (!prog.isEnded() && (type == null || type.name().equals(prog.getQuest().getAction().name())))
|
||||||
ls.add(one.getQuest().getConfigName().toLowerCase());
|
ls.add(prog.getQuest().getConfigName().toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
return ls;
|
return ls;
|
||||||
@ -881,23 +882,16 @@ public class JobsPlayer {
|
|||||||
|
|
||||||
public List<QuestProgression> getQuestProgressions(Job job, ActionType type) {
|
public List<QuestProgression> getQuestProgressions(Job job, ActionType type) {
|
||||||
if (!this.isInJob(job))
|
if (!this.isInJob(job))
|
||||||
return null;
|
return new ArrayList<>();
|
||||||
List<QuestProgression> g = new ArrayList<>();
|
HashMap<String, QuestProgression> g = new HashMap<>();
|
||||||
|
|
||||||
if (this.qProgression.get(job.getName()) != null)
|
if (this.qProgression.get(job.getName()) != null)
|
||||||
g = new ArrayList<>(this.qProgression.get(job.getName()));
|
g = new HashMap<>(this.qProgression.get(job.getName()));
|
||||||
|
|
||||||
List<QuestProgression> tmp = new ArrayList<>();
|
HashMap<String, QuestProgression> tmp = new HashMap<>();
|
||||||
|
|
||||||
if (!g.isEmpty()) {
|
for (Entry<String, QuestProgression> one : (new HashMap<String, QuestProgression>(g)).entrySet()) {
|
||||||
if (g.get(0).isEnded()) {
|
QuestProgression qp = one.getValue();
|
||||||
g.clear();
|
|
||||||
this.qProgression.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (QuestProgression one : new ArrayList<QuestProgression>(g)) {
|
|
||||||
QuestProgression qp = one;
|
|
||||||
if (qp == null || !qp.isValid()) {
|
if (qp == null || !qp.isValid()) {
|
||||||
Quest q = job.getNextQuest(getQuestNameList(job, type), this.getJobProgression(job).getLevel());
|
Quest q = job.getNextQuest(getQuestNameList(job, type), this.getJobProgression(job).getLevel());
|
||||||
|
|
||||||
@ -909,11 +903,11 @@ public class JobsPlayer {
|
|||||||
if (g.size() >= job.getMaxDailyQuests())
|
if (g.size() >= job.getMaxDailyQuests())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
g.add(qp);
|
g.put(qp.getQuest().getConfigName(), qp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == null || type.name().equals(qp.getQuest().getAction().name()))
|
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);
|
this.qProgression.put(job.getName(), g);
|
||||||
@ -925,14 +919,21 @@ public class JobsPlayer {
|
|||||||
if (q == null)
|
if (q == null)
|
||||||
continue;
|
continue;
|
||||||
QuestProgression qp = new QuestProgression(q);
|
QuestProgression qp = new QuestProgression(q);
|
||||||
g.add(qp);
|
g.put(qp.getQuest().getConfigName(), qp);
|
||||||
|
|
||||||
if (type == null || type.name().equals(qp.getQuest().getAction().name()))
|
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);
|
this.qProgression.put(job.getName(), g);
|
||||||
return tmp;
|
|
||||||
|
List<QuestProgression> pr = new ArrayList<QuestProgression>();
|
||||||
|
for (Entry<String, QuestProgression> one : tmp.entrySet()) {
|
||||||
|
pr.add(one.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
return pr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDoneQuests() {
|
public int getDoneQuests() {
|
||||||
|
@ -49,7 +49,7 @@ public class QuestProgression {
|
|||||||
return validUntil < System.currentTimeMillis();
|
return validUntil < System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isComplited() {
|
public boolean isCompleted() {
|
||||||
return amountDone >= quest.getAmount();
|
return amountDone >= quest.getAmount();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,10 +61,10 @@ public class QuestProgression {
|
|||||||
if (!quest.getTargetName().equalsIgnoreCase(action.getName()) && !quest.getTargetName().equalsIgnoreCase(action.getNameWithSub()))
|
if (!quest.getTargetName().equalsIgnoreCase(action.getName()) && !quest.getTargetName().equalsIgnoreCase(action.getNameWithSub()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!isComplited())
|
if (!isCompleted())
|
||||||
amountDone++;
|
amountDone++;
|
||||||
|
|
||||||
if (!isComplited())
|
if (!isCompleted())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!jPlayer.isOnline())
|
if (!jPlayer.isOnline())
|
||||||
|
Loading…
Reference in New Issue
Block a user