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 fc96e935..a8e49c1d 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/quests.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/quests.java @@ -16,6 +16,10 @@ import com.gamingmesh.jobs.container.QuestObjective; import com.gamingmesh.jobs.container.QuestProgression; import com.gamingmesh.jobs.i18n.Language; +import net.Zrips.CMILib.GUI.CMIGui; +import net.Zrips.CMILib.GUI.CMIGuiButton; +import net.Zrips.CMILib.GUI.GUIManager.GUIClickType; +import net.Zrips.CMILib.GUI.GUIManager.InvType; import net.Zrips.CMILib.Locale.LC; import net.Zrips.CMILib.Messages.CMIMessages; import net.Zrips.CMILib.RawMessages.RawMessage; @@ -78,13 +82,18 @@ public class quests implements Cmd { } } + if (isPlayer && Jobs.getGeneralConfigManager().isDailyQuestsUseGUI()) { + openGui((Player) sender, jPlayer); + return true; + } + Language.sendMessage(sender, "command.quests.toplineseparator", "[playerName]", jPlayer.getName(), "[questsDone]", jPlayer.getDoneQuests()); for (JobProgression jobProg : jPlayer.progression) { List list = jPlayer.getQuestProgressions(jobProg.getJob()); for (QuestProgression q : list) { - + int totalAmountNeeded = q.getTotalAmountNeeded(); int totalAmountDone = q.getTotalAmountDone(); @@ -111,7 +120,7 @@ public class quests implements Cmd { List hoverList = new ArrayList<>(); for (String current : hoverMsg.split("\n")) { - current = current.replace("[jobName]", jobProg.getJob().getName()) + current = current.replace("[jobName]", jobProg.getJob().getDisplayName()) .replace("[time]", CMITimeManager.to24hourShort(q.getValidUntil() - System.currentTimeMillis())); if (current.contains("[desc]")) { @@ -135,7 +144,6 @@ public class quests implements Cmd { for (String one : hoverList) { if (!hover.isEmpty()) hover += "\n"; - hover += one; } @@ -155,4 +163,95 @@ public class quests implements Cmd { sender.sendMessage(Jobs.getLanguage().getMessage("general.info.separator")); return true; } + + private static void openGui(Player player, JobsPlayer jPlayer) { + + CMIGui gui = new CMIGui(player); + gui.setTitle(jPlayer.getDisplayName()); + gui.addLock(InvType.Gui); + gui.addLock(InvType.Main); + + for (JobProgression jobProg : jPlayer.progression) { + List list = jPlayer.getQuestProgressions(jobProg.getJob()); + + for (QuestProgression q : list) { + + int totalAmountNeeded = q.getTotalAmountNeeded(); + int totalAmountDone = q.getTotalAmountDone(); + + String progressLine = Jobs.getCommandManager().jobProgressMessage(totalAmountNeeded, totalAmountDone); + + boolean completed = q.isCompleted(); + + if (completed) + progressLine = Jobs.getLanguage().getMessage("command.quests.output.completed"); + + Quest quest = q.getQuest(); + + 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]", CMITimeManager.to24hourShort(q.getValidUntil() - System.currentTimeMillis())); + + if (current.contains("[desc]")) { + hoverList.addAll(quest.getDescription()); + } else { + hoverList.add(current); + } + } + + 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() + .getTargetMeta(), oneObjective.getValue().getTargetName()) + + " " + q.getAmountDone(oneObjective.getValue()) + "/" + + oneObjective.getValue().getAmount()); + } + } + + String title = Jobs.getLanguage().getMessage("command.quests.output.questLine", "[progress]", progressLine, "[questName]", quest.getQuestName(), "[done]", totalAmountDone, "[required]", + totalAmountNeeded); + + String hover = ""; + + for (String one : hoverList) { + if (!hover.isEmpty()) + hover += "\n"; + hover += "&r&f" + one; + } + + 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())); + } + + CMIGuiButton button = new CMIGuiButton(jobProg.getJob().getGuiItem()) { + @Override + public void click(GUIClickType type) { + player.performCommand("jobs skipquest " + jobProg.getJob().getName() + " " + quest.getConfigName() + " " + jPlayer.getName()); + } + }; + + button.setName(title); + button.addLore(hover); + button.hideItemFlags(); + gui.addButton(button); + } else { + CMIGuiButton button = new CMIGuiButton(jobProg.getJob().getGuiItem()); + button.setName(title); + button.addLore(hover); + button.hideItemFlags(); + gui.addButton(button); + } + + } + } + gui.fillEmptyButtons(); + gui.open(); + + } } diff --git a/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java b/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java index fb8382be..981ff700 100644 --- a/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java @@ -88,7 +88,7 @@ public class GeneralConfigManager { public float maxPaymentCurveFactor; private boolean FurnacesReassign, BrewingStandsReassign, useTnTFinder = false, ShowNewVersion; - private boolean InformDuplicates; + private boolean InformDuplicates, DailyQuestsUseGUI; private FireworkEffect fireworkEffect; @@ -446,6 +446,8 @@ public class GeneralConfigManager { "Any daily quests given before reset will be invalid and new ones will be given out"); ResetTimeHour = c.get("DailyQuests.ResetTime.Hour", 4); ResetTimeMinute = c.get("DailyQuests.ResetTime.Minute", 0); + c.addComment("DailyQuests.useGUI", "Defines amount of skips player can do on a quest", "This allows player to abandon current quest and get new one"); + DailyQuestsUseGUI = c.get("DailyQuests.useGUI", true); c.addComment("DailyQuests.Skips", "Defines amount of skips player can do on a quest", "This allows player to abandon current quest and get new one"); DailyQuestsSkips = c.get("DailyQuests.Skips", 1); c.addComment("DailyQuests.SkipQuestCost", "The cost of the quest skip (money).", "Default 0, disabling cost of skipping quest."); @@ -1107,15 +1109,15 @@ public class GeneralConfigManager { CMIItemStack item = CMILib.getInstance().getItemManager().getItem(c.get("JobsGUI.InfoButton.Material", "head:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMjcwNWZkOTRhMGM0MzE5MjdmYjRlNjM5YjBmY2ZiNDk3MTdlNDEyMjg1YTAyYjQzOWUwMTEyZGEyMmIyZTJlYyJ9fX0=")); guiInfoButton = item.getCMIType() == CMIMaterial.NONE ? CMIMaterial.ARROW.newItemStack() : item.getItemStack(); - + item = CMIItemStack.deserialize(c.get("JobsGUI.JoinButton.Material", - "head:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZmZlYzNkMjVhZTBkMTQ3YzM0MmM0NTM3MGUwZTQzMzAwYTRlNDhhNWI0M2Y5YmI4NThiYWJmZjc1NjE0NGRhYyJ9fX0=")); + "head:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZmZlYzNkMjVhZTBkMTQ3YzM0MmM0NTM3MGUwZTQzMzAwYTRlNDhhNWI0M2Y5YmI4NThiYWJmZjc1NjE0NGRhYyJ9fX0=")); guiJoinButton = item == null || item.getCMIType() == CMIMaterial.NONE ? CMIMaterial.GREEN_STAINED_GLASS_PANE.newItemStack() : item.getItemStack(); - + item = CMIItemStack.deserialize(c.get("JobsGUI.LeaveButton.Material", - "head:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzY1ZjNiYWUwZDIwM2JhMTZmZTFkYzNkMTMwN2E4NmE2MzhiZTkyNDQ3MWYyM2U4MmFiZDlkNzhmOGEzZmNhIn19fQ==")); + "head:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzY1ZjNiYWUwZDIwM2JhMTZmZTFkYzNkMTMwN2E4NmE2MzhiZTkyNDQ3MWYyM2U4MmFiZDlkNzhmOGEzZmNhIn19fQ==")); guiLeaveButton = item == null || item.getCMIType() == CMIMaterial.NONE ? CMIMaterial.RED_STAINED_GLASS_PANE.newItemStack() : item.getItemStack(); - + c.addComment("JobsGUI.InfoButton.Commands", "closeinv! can be used to close players inventory when you click this icon"); InfoButtonCommands = c.get("JobsGUI.InfoButton.Commands", Arrays.asList("closeinv!")); @@ -1277,4 +1279,8 @@ public class GeneralConfigManager { public boolean isBossBarAsync() { return bossBarAsync; } + + public boolean isDailyQuestsUseGUI() { + return DailyQuestsUseGUI; + } }