From 8dc1bf80da8914a86bd563f448621b6c4b4b4249 Mon Sep 17 00:00:00 2001 From: montlikadani Date: Sat, 15 May 2021 19:36:12 +0200 Subject: [PATCH] Improved displaying player's quests in console --- src/main/java/com/gamingmesh/jobs/Jobs.java | 5 +-- .../com/gamingmesh/jobs/PlayerManager.java | 2 +- .../gamingmesh/jobs/commands/list/area.java | 2 +- .../gamingmesh/jobs/commands/list/quests.java | 35 ++++++++++++------- .../jobs/config/RestrictedAreaManager.java | 11 ++++++ .../jobs/container/ExploreChunk.java | 8 +++-- .../jobs/container/JobLimitedItems.java | 3 -- .../gamingmesh/jobs/container/JobsPlayer.java | 4 +-- .../com/gamingmesh/jobs/container/Quest.java | 13 ++++--- .../jobs/container/QuestProgression.java | 10 +++--- 10 files changed, 62 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/Jobs.java b/src/main/java/com/gamingmesh/jobs/Jobs.java index 252a0d4a..81aa299b 100644 --- a/src/main/java/com/gamingmesh/jobs/Jobs.java +++ b/src/main/java/com/gamingmesh/jobs/Jobs.java @@ -445,8 +445,9 @@ public class Jobs extends JavaPlugin { } /** - * Retrieves the list of active jobs - * @return list of jobs + * Returns the list of available jobs. + * + * @return an unmodifiable list of jobs */ public static List getJobs() { return Collections.unmodifiableList(jobs); diff --git a/src/main/java/com/gamingmesh/jobs/PlayerManager.java b/src/main/java/com/gamingmesh/jobs/PlayerManager.java index ecd0dad1..fd552a6b 100644 --- a/src/main/java/com/gamingmesh/jobs/PlayerManager.java +++ b/src/main/java/com/gamingmesh/jobs/PlayerManager.java @@ -1102,7 +1102,7 @@ public class PlayerManager { boost.add(BoostOf.Item, getItemBoostNBT(pl, prog)); } - if (!Jobs.getRestrictedAreaManager().getRestrictedAres().isEmpty()) + if (!Jobs.getRestrictedAreaManager().getRestrictedAreas().isEmpty()) boost.add(BoostOf.Area, new BoostMultiplier().add(Jobs.getRestrictedAreaManager().getRestrictedMultiplier(pl))); return boost; diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/area.java b/src/main/java/com/gamingmesh/jobs/commands/list/area.java index 904d1789..c88116c9 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/area.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/area.java @@ -117,7 +117,7 @@ public class area implements Cmd { if (args.length == 1 && args[0].equalsIgnoreCase("list")) { - java.util.Map areas = Jobs.getRestrictedAreaManager().getRestrictedAres(); + java.util.Map areas = Jobs.getRestrictedAreaManager().getRestrictedAreas(); if (areas.isEmpty()) { sender.sendMessage(Jobs.getLanguage().getMessage("command.area.output.noAreas")); return true; 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 00356919..259d80c9 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/quests.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/quests.java @@ -11,6 +11,7 @@ import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.container.JobProgression; import com.gamingmesh.jobs.container.JobsPlayer; +import com.gamingmesh.jobs.container.Quest; import com.gamingmesh.jobs.container.QuestObjective; import com.gamingmesh.jobs.container.QuestProgression; import com.gamingmesh.jobs.stuff.TimeManage; @@ -75,37 +76,47 @@ public class quests implements Cmd { sender.sendMessage(Jobs.getLanguage().getMessage("command.quests.toplineseparator", "[playerName]", jPlayer.getName(), "[questsDone]", jPlayer.getDoneQuests())); - if (!isPlayer) { - return true; - } - for (JobProgression jobProg : jPlayer.progression) { List list = jPlayer.getQuestProgressions(jobProg.getJob()); for (QuestProgression q : list) { - String progressLine = Jobs.getCommandManager().jobProgressMessage(q.getTotalAmountNeeded(), q.getTotalAmountDone()); + int totalAmountNeeded = q.getTotalAmountNeeded(); + int totalAmountDone = q.getTotalAmountDone(); - if (q.isCompleted()) + String progressLine = Jobs.getCommandManager().jobProgressMessage(totalAmountNeeded, totalAmountDone); + + boolean completed = q.isCompleted(); + + if (completed) progressLine = Jobs.getLanguage().getMessage("command.quests.output.completed"); - RawMessage rm = new RawMessage(); + Quest quest = q.getQuest(); + String msg = Jobs.getLanguage().getMessage("command.quests.output.questLine", "[progress]", - progressLine, "[questName]", q.getQuest().getQuestName(), "[done]", q.getTotalAmountDone(), "[required]", q.getTotalAmountNeeded()); + progressLine, "[questName]", quest.getQuestName(), "[done]", totalAmountDone, "[required]", totalAmountNeeded); + + if (!isPlayer) { + sender.sendMessage(msg); + continue; + } + + RawMessage rm = new RawMessage(); 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]")) { - hoverList.addAll(q.getQuest().getDescription()); + hoverList.addAll(quest.getDescription()); } else { hoverList.add(current); } } - for (java.util.Map oneAction : q.getQuest().getObjectives().values()) { + for (java.util.Map oneAction : quest.getObjectives().values()) { for (Entry oneObjective : oneAction.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() @@ -123,12 +134,12 @@ public class quests implements Cmd { hover += one; } - if (list.size() < jobProg.getJob().getQuests().size() && Jobs.getGCManager().getDailyQuestsSkips() > jPlayer.getSkippedQuests() && !q.isCompleted()) { + if (list.size() < jobProg.getJob().getQuests().size() && Jobs.getGCManager().getDailyQuestsSkips() > jPlayer.getSkippedQuests() && !completed) { 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.addText(msg).addHover(hover).addCommand("jobs skipquest " + jobProg.getJob().getName() + " " + q.getQuest().getConfigName() + " " + jPlayer.getName()); + rm.addText(msg).addHover(hover).addCommand("jobs skipquest " + jobProg.getJob().getName() + " " + quest.getConfigName() + " " + jPlayer.getName()); } else rm.addText(msg).addHover(hover); diff --git a/src/main/java/com/gamingmesh/jobs/config/RestrictedAreaManager.java b/src/main/java/com/gamingmesh/jobs/config/RestrictedAreaManager.java index fba19e1e..84443f84 100644 --- a/src/main/java/com/gamingmesh/jobs/config/RestrictedAreaManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/RestrictedAreaManager.java @@ -66,10 +66,21 @@ public class RestrictedAreaManager { } } + /** + * Retrieves the restricted areas map. + * + * @deprecated badly named + * @return the cached map of restricted areas + */ + @Deprecated public Map getRestrictedAres() { return restrictedAreas; } + public Map getRestrictedAreas() { + return restrictedAreas; + } + private void save() { File f = new File(Jobs.getFolder(), "restrictedAreas.yml"); YamlConfiguration conf = YamlConfiguration.loadConfiguration(f); diff --git a/src/main/java/com/gamingmesh/jobs/container/ExploreChunk.java b/src/main/java/com/gamingmesh/jobs/container/ExploreChunk.java index f7561242..37b18eec 100644 --- a/src/main/java/com/gamingmesh/jobs/container/ExploreChunk.java +++ b/src/main/java/com/gamingmesh/jobs/container/ExploreChunk.java @@ -52,8 +52,9 @@ public class ExploreChunk { StringBuilder s = new StringBuilder(); for (Integer one : playerIds) { - if (!s.toString().isEmpty()) + if (s.length() != 0) s.append(';'); + s.append(one); } return s.toString(); @@ -73,11 +74,13 @@ public class ExploreChunk { try { int id = Integer.parseInt(one); PlayerInfo info = Jobs.getPlayerManager().getPlayerInfo(id); + if (info != null) playerIds.add(id); - } catch (Exception e) { + } catch (NumberFormatException e) { updated = true; JobsPlayer jp = Jobs.getPlayerManager().getJobsPlayer(one); + if (jp != null) playerIds.add(jp.getUserId()); } @@ -85,6 +88,7 @@ public class ExploreChunk { if (playerIds.size() >= Jobs.getExplore().getPlayerAmount() && Jobs.getGCManager().ExploreCompact) { playerIds = null; + if (!names.isEmpty()) updated = true; } diff --git a/src/main/java/com/gamingmesh/jobs/container/JobLimitedItems.java b/src/main/java/com/gamingmesh/jobs/container/JobLimitedItems.java index 610ee6f5..e5afe90c 100644 --- a/src/main/java/com/gamingmesh/jobs/container/JobLimitedItems.java +++ b/src/main/java/com/gamingmesh/jobs/container/JobLimitedItems.java @@ -28,7 +28,6 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.CMILib.CMIChatColor; import com.gamingmesh.jobs.CMILib.CMIMaterial; @@ -65,8 +64,6 @@ public class JobLimitedItems { return item; } - Jobs plugin = org.bukkit.plugin.java.JavaPlugin.getPlugin(Jobs.class); - if (name != null) meta.setDisplayName(CMIChatColor.translate(name)); diff --git a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java index eed49a85..1ca704b4 100644 --- a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java +++ b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java @@ -406,9 +406,9 @@ public class JobsPlayer { * Reloads limit for this player. */ public void reload(CurrencyType type) { - int totalLevel = getTotalLevels(); Parser eq = Jobs.getGCManager().getLimit(type).getMaxEquation(); - eq.setVariable("totallevel", totalLevel); + eq.setVariable("totallevel", getTotalLevels()); + maxJobsEquation = Jobs.getPlayerManager().getMaxJobs(this); limits.put(type, (int) eq.getValue()); setSaved(false); diff --git a/src/main/java/com/gamingmesh/jobs/container/Quest.java b/src/main/java/com/gamingmesh/jobs/container/Quest.java index 3fae9ee1..efda9b53 100644 --- a/src/main/java/com/gamingmesh/jobs/container/Quest.java +++ b/src/main/java/com/gamingmesh/jobs/container/Quest.java @@ -15,7 +15,7 @@ public class Quest { private String configName = ""; private String questName = ""; private Job job; - private Long validUntil = 0L; + private long validUntil = 0L; private int chance = 100, minLvl = 0; private Integer maxLvl; @@ -76,30 +76,35 @@ public class Quest { } } - public Long getValidUntil() { + public long getValidUntil() { if (validUntil < System.currentTimeMillis()) { int hour = Jobs.getGCManager().getResetTimeHour(); int minute = Jobs.getGCManager().getResetTimeMinute(); Calendar c = Calendar.getInstance(); + c.add(Calendar.DAY_OF_MONTH, 1); + c.set(Calendar.HOUR_OF_DAY, hour); c.set(Calendar.MINUTE, minute); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); + if (c.getTimeInMillis() - System.currentTimeMillis() > 86400000) { c = Calendar.getInstance(); + c.set(Calendar.HOUR_OF_DAY, hour); c.set(Calendar.MINUTE, minute); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); } + validUntil = c.getTimeInMillis(); } return validUntil; } - public void setValidUntil(Long validUntil) { + public void setValidUntil(long validUntil) { this.validUntil = validUntil; } @@ -184,7 +189,7 @@ public class Quest { public void setObjectives(Map> objectives) { if (objectives == null) { - objectives = new HashMap<>(); + return; } this.objectives = objectives; diff --git a/src/main/java/com/gamingmesh/jobs/container/QuestProgression.java b/src/main/java/com/gamingmesh/jobs/container/QuestProgression.java index ae407f64..00c70c68 100644 --- a/src/main/java/com/gamingmesh/jobs/container/QuestProgression.java +++ b/src/main/java/com/gamingmesh/jobs/container/QuestProgression.java @@ -65,16 +65,16 @@ public class QuestProgression { } } - public Long getValidUntil() { + public long getValidUntil() { return validUntil; } - public void setValidUntil(Long validUntil) { + public void setValidUntil(long validUntil) { this.validUntil = validUntil; } public boolean isValid() { - return validUntil == getValidUntil(); + return !isEnded(); } public boolean isEnded() { @@ -103,7 +103,7 @@ public class QuestProgression { org.bukkit.entity.Player player = jPlayer.getPlayer(); for (String area : quest.getRestrictedAreas()) { - for (Entry a : Jobs.getRestrictedAreaManager().getRestrictedAres().entrySet()) { + for (Entry a : Jobs.getRestrictedAreaManager().getRestrictedAreas().entrySet()) { if (a.getKey().equalsIgnoreCase(area) && a.getValue().inRestrictedArea(player.getLocation())) { return; } @@ -120,8 +120,10 @@ public class QuestProgression { if (!isCompleted()) { QuestObjective objective = null; + if (byAction != null) { objective = byAction.get(action.getName()); + if (objective == null) objective = byAction.get(action.getNameWithSub()); }