From 173ac185024c85aeec67edafa78392c095723dfe Mon Sep 17 00:00:00 2001 From: Zoinkwiz Date: Sun, 24 Nov 2024 20:02:54 +0000 Subject: [PATCH 1/5] feat: add initial attempt at importable JSON quest helpers --- .../com/questhelper/QuestHelperPlugin.java | 24 +- .../QuestHelperSharingManager.java | 115 +++++++++ .../questhelper/managers/QuestManager.java | 2 +- .../com/questhelper/panel/PanelDetails.java | 1 + .../questhelper/panel/QuestOverviewPanel.java | 4 +- .../questhelper/questhelpers/QuestHelper.java | 4 + .../questimport/JsonQuestHelper.java | 114 +++++++++ .../questhelper/questimport/JsonToQuest.java | 219 ++++++++++++++++++ .../questhelper/questimport/QuestData.java | 34 +++ .../questimport/RequirementData.java | 35 +++ .../com/questhelper/questimport/StepData.java | 40 ++++ .../java/com/questhelper/steps/QuestStep.java | 2 +- .../questhelper/QuestHelperPluginTest.java | 2 +- 13 files changed, 585 insertions(+), 11 deletions(-) create mode 100644 src/main/java/com/questhelper/QuestHelperSharingManager.java create mode 100644 src/main/java/com/questhelper/questimport/JsonQuestHelper.java create mode 100644 src/main/java/com/questhelper/questimport/JsonToQuest.java create mode 100644 src/main/java/com/questhelper/questimport/QuestData.java create mode 100644 src/main/java/com/questhelper/questimport/RequirementData.java create mode 100644 src/main/java/com/questhelper/questimport/StepData.java diff --git a/src/main/java/com/questhelper/QuestHelperPlugin.java b/src/main/java/com/questhelper/QuestHelperPlugin.java index ff19fc6697..e6e0ebb4cf 100644 --- a/src/main/java/com/questhelper/QuestHelperPlugin.java +++ b/src/main/java/com/questhelper/QuestHelperPlugin.java @@ -157,6 +157,9 @@ public class QuestHelperPlugin extends Plugin @Inject public SkillIconManager skillIconManager; + @Inject + public QuestHelperSharingManager questHelperSharingManager; + private QuestHelperPanel panel; private NavigationButton navButton; @@ -331,7 +334,7 @@ public void onConfigChanged(ConfigChanged event) return; } - if (event.getKey().equals("showRuneliteObjects") && client.getGameState() == GameState.LOGGED_IN) + if (event.getKey().equals("showRuneliteObjects") && client.getGameState() == GameState.LOGGED_IN) { clientThread.invokeLater(() -> { if (config.showRuneliteObjects()) @@ -406,6 +409,10 @@ else if (developerMode && commandExecuted.getCommand().equals("qh-inv")) } System.out.println(inv); } + else if (commandExecuted.getCommand().equals("import-quest")) + { + questHelperSharingManager.promptForImport(); + } } @Subscribe(priority = 100) @@ -506,10 +513,8 @@ private void scanAndInstantiate() } } - private void instantiate(QuestHelperQuest quest) + void instantiate(QuestHelper questHelper, String name) { - QuestHelper questHelper = quest.getQuestHelper(); - Module questModule = (Binder binder) -> { binder.bind(QuestHelper.class).toInstance(questHelper); @@ -518,10 +523,17 @@ private void instantiate(QuestHelperQuest quest) Injector questInjector = RuneLite.getInjector().createChildInjector(questModule); injector.injectMembers(questHelper); questHelper.setInjector(questInjector); - questHelper.setQuest(quest); questHelper.setConfig(config); questHelper.setQuestHelperPlugin(this); + questHelper.setName(name); + + log.debug("Loaded quest helper {}", name); + } - log.debug("Loaded quest helper {}", quest.name()); + private void instantiate(QuestHelperQuest quest) + { + QuestHelper questHelper = quest.getQuestHelper(); + instantiate(questHelper, quest.name()); + questHelper.setQuest(quest); } } diff --git a/src/main/java/com/questhelper/QuestHelperSharingManager.java b/src/main/java/com/questhelper/QuestHelperSharingManager.java new file mode 100644 index 0000000000..0eb9ff851e --- /dev/null +++ b/src/main/java/com/questhelper/QuestHelperSharingManager.java @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2021, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.questhelper; + +import com.google.common.base.Strings; +import com.google.gson.Gson; +import com.google.gson.JsonSyntaxException; +import com.questhelper.questimport.JsonToQuest; +import com.questhelper.managers.QuestManager; +import com.questhelper.questhelpers.QuestHelper; +import lombok.extern.slf4j.Slf4j; +import net.runelite.api.ChatMessageType; +import net.runelite.client.callback.ClientThread; +import net.runelite.client.chat.ChatMessageManager; +import net.runelite.client.chat.QueuedMessage; +import net.runelite.client.game.ItemManager; +import java.awt.Toolkit; +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.UnsupportedFlavorException; +import java.io.IOException; +import javax.inject.Inject; + +@Slf4j +public class QuestHelperSharingManager +{ + private final QuestHelperPlugin plugin; + private final QuestManager questManager; + private final ChatMessageManager chatMessageManager; + private final ClientThread clientThread; + private final ItemManager itemManager; + private final Gson gson; + + @Inject + private QuestHelperSharingManager(QuestHelperPlugin plugin, ClientThread clientThread, QuestManager questManager, ChatMessageManager chatMessageManager, + ItemManager itemManager, Gson gson) + { + this.plugin = plugin; + this.clientThread = clientThread; + this.questManager = questManager; + this.chatMessageManager = chatMessageManager; + this.itemManager = itemManager; + this.gson = gson; + } + + public void promptForImport() + { + final String clipboardText; + try + { + clipboardText = Toolkit.getDefaultToolkit() + .getSystemClipboard() + .getData(DataFlavor.stringFlavor) + .toString(); + } + catch (IOException | UnsupportedFlavorException ex) + { + sendChatMessage("Unable to read system clipboard."); + log.warn("error reading clipboard", ex); + return; + } + + log.debug("Clipboard contents: {}", clipboardText); + if (Strings.isNullOrEmpty(clipboardText)) + { + sendChatMessage("You do not have any quest helper helpers copied in your clipboard."); + return; + } + + try + { + JsonToQuest jsonToQuest = new JsonToQuest(itemManager); + QuestHelper questHelper = jsonToQuest.importQuestFromJson(gson, clipboardText); + clientThread.invokeLater(() -> { + plugin.instantiate(questHelper, "Imported Helper"); + questManager.startUpQuest(questHelper); + }); + + } + catch (JsonSyntaxException e) + { + log.debug("Malformed JSON for clipboard import", e); + sendChatMessage("Invalid helper copied in your clipboard."); + } + } + + private void sendChatMessage(final String message) + { + chatMessageManager.queue(QueuedMessage.builder() + .type(ChatMessageType.CONSOLE) + .runeLiteFormattedMessage(message) + .build()); + } +} diff --git a/src/main/java/com/questhelper/managers/QuestManager.java b/src/main/java/com/questhelper/managers/QuestManager.java index fe0be56992..f4272be14d 100644 --- a/src/main/java/com/questhelper/managers/QuestManager.java +++ b/src/main/java/com/questhelper/managers/QuestManager.java @@ -408,7 +408,7 @@ public void startUpBackgroundQuest(String questHelperName) return; } - if (selectedQuest != null && selectedQuest.getQuest().getName().equals(questHelperName)) + if (selectedQuest != null && selectedQuest.getQuest() != null && selectedQuest.getQuest().getName().equals(questHelperName)) { return; } diff --git a/src/main/java/com/questhelper/panel/PanelDetails.java b/src/main/java/com/questhelper/panel/PanelDetails.java index ab3d3795df..0b0262d649 100644 --- a/src/main/java/com/questhelper/panel/PanelDetails.java +++ b/src/main/java/com/questhelper/panel/PanelDetails.java @@ -53,6 +53,7 @@ public class PanelDetails private Requirement hideCondition; @Getter + @Setter private List requirements; @Getter diff --git a/src/main/java/com/questhelper/panel/QuestOverviewPanel.java b/src/main/java/com/questhelper/panel/QuestOverviewPanel.java index 93b107d1e4..4c95caa232 100644 --- a/src/main/java/com/questhelper/panel/QuestOverviewPanel.java +++ b/src/main/java/com/questhelper/panel/QuestOverviewPanel.java @@ -269,7 +269,7 @@ public void addQuest(QuestHelper quest, boolean isActive) if (quest.getCurrentStep() != null) { - questNameLabel.setText(quest.getQuest().getName()); + questNameLabel.setText(quest.getName()); actionsContainer.setVisible(true); if (quest.getConfigs() != null) @@ -571,7 +571,7 @@ private void updateExternalResourcesPanel(QuestHelper quest) externalResourcesList = Collections.singletonList(ExternalQuestResources.valueOf(quest.getQuest().name().toUpperCase()).getWikiURL()); } catch (Exception e) { - externalResourcesList = Collections.singletonList("https://oldschool.runescape.wiki/w/" + StringUtils.lowerCase(URLEncoder.encode(quest.getQuest().name(), StandardCharsets.UTF_8))); + externalResourcesList = Collections.singletonList("https://oldschool.runescape.wiki/w/" + StringUtils.lowerCase(URLEncoder.encode(quest.getName(), StandardCharsets.UTF_8))); } JButton wikiBtn = new JButton(); diff --git a/src/main/java/com/questhelper/questhelpers/QuestHelper.java b/src/main/java/com/questhelper/questhelpers/QuestHelper.java index e15344df92..a000d39aa4 100644 --- a/src/main/java/com/questhelper/questhelpers/QuestHelper.java +++ b/src/main/java/com/questhelper/questhelpers/QuestHelper.java @@ -101,6 +101,10 @@ public abstract class QuestHelper implements Module, QuestDebugRenderer private boolean hasInitialized; + @Setter + @Getter + private String name; + @Override public void configure(Binder binder) { diff --git a/src/main/java/com/questhelper/questimport/JsonQuestHelper.java b/src/main/java/com/questhelper/questimport/JsonQuestHelper.java new file mode 100644 index 0000000000..a71e4c09e0 --- /dev/null +++ b/src/main/java/com/questhelper/questimport/JsonQuestHelper.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2024, Zoinkwiz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.questhelper.questimport; + +import com.questhelper.panel.PanelDetails; +import com.questhelper.questhelpers.ComplexStateQuestHelper; +import com.questhelper.steps.ConditionalStep; +import com.questhelper.steps.DetailedQuestStep; +import com.questhelper.steps.QuestStep; +import java.util.ArrayList; +import java.util.List; + +public class JsonQuestHelper extends ComplexStateQuestHelper +{ + ConditionalStep steps; + + public void setSteps(ConditionalStep conditionalStep) + { + this.steps = conditionalStep; + } + + @Override + public QuestStep loadStep() + { + return steps; + } + + @Override + protected void setupRequirements() + { + + } + + @Override + public List getPanels() + { + List allSteps = new ArrayList<>(); + + int i = 0; + QuestStep defaultStep = null; + for (var questStep : steps.getSteps()) + { + if (i == 0) + { + defaultStep = questStep; + i++; + continue; + } + + PanelDetails details = makePanelDetail(questStep, String.valueOf(i)); + if (details == null) continue; + allSteps.add(details); + i++; + } + if (defaultStep != null) + { + PanelDetails details = makePanelDetail(defaultStep, "default"); + if (details != null) allSteps.add(details); + } + + return allSteps; + } + + private PanelDetails makePanelDetail(QuestStep questStep, String panelText) + { + if (questStep == null) return null; + if (questStep.getText().get(0).equals("Default step.")) return null; + PanelDetails details = new PanelDetails("Step " + panelText); + if (questStep instanceof DetailedQuestStep) + { + var reqs = ((DetailedQuestStep) questStep).getRequirements(); + if (reqs != null) details.setRequirements(reqs); + } + questStep.setLockable(true); + details.addSteps(questStep); + details.setLockingStep(questStep); + + return details; + } + + @Override + public boolean isCompleted() + { + return false; + } + + @Override + public int getVar() + { + return 0; + } +} diff --git a/src/main/java/com/questhelper/questimport/JsonToQuest.java b/src/main/java/com/questhelper/questimport/JsonToQuest.java new file mode 100644 index 0000000000..8abde75158 --- /dev/null +++ b/src/main/java/com/questhelper/questimport/JsonToQuest.java @@ -0,0 +1,219 @@ +/* + * Copyright (c) 2024, Zoinkwiz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.questhelper.questimport; + +import com.google.gson.Gson; +import com.questhelper.requirements.Requirement; +import com.questhelper.requirements.conditional.Conditions; +import com.questhelper.requirements.item.ItemRequirement; +import com.questhelper.requirements.player.SkillRequirement; +import com.questhelper.requirements.util.LogicType; +import com.questhelper.steps.ConditionalStep; +import com.questhelper.steps.DetailedQuestStep; +import com.questhelper.steps.NpcStep; +import com.questhelper.steps.ObjectStep; +import com.questhelper.steps.QuestStep; +import net.runelite.api.Skill; +import net.runelite.api.coords.WorldPoint; +import net.runelite.client.game.ItemManager; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class JsonToQuest +{ + ItemManager itemManager; + + public JsonToQuest(ItemManager itemManager) + { + this.itemManager = itemManager; + } + public JsonQuestHelper importQuestFromJson(Gson gson, String jsonContent) + { + JsonQuestHelper newHelper = new JsonQuestHelper(); + QuestData questData = gson.fromJson(jsonContent, QuestData.class); + + // Map requirements + Map requirementMap = getRequirementMap(questData.getRequirements()); + + // Map steps and create ConditionalSteps + ConditionalStep steps = new ConditionalStep(newHelper, new DetailedQuestStep(newHelper, "Default step.")); + for (StepData stepData : questData.getSteps()) + { + QuestStep questStep = parseQuestStep(newHelper, stepData, requirementMap); + LogicType logicType = getLogicType(stepData.getLogicType()); + if (stepData.isDefault()) + { + steps.addStep(null, questStep); + } + else + { + Requirement[] reqs = getRequirements(stepData.getConditionalRequirements(), requirementMap); + if (reqs == null) + { + System.out.println(questStep.getText()); + } + Conditions conditions = new Conditions(logicType, reqs); + steps.addStep(conditions, questStep); + } + } + + newHelper.setSteps(steps); + return newHelper; + } + + private Requirement parseRequirement(RequirementData reqData) + { + Requirement requirement = null; + + switch (reqData.getType()) + { + case "SkillRequirement": + String skillName = (String) reqData.getParameters().get("skill"); + int level = ((Number) reqData.getParameters().get("level")).intValue(); + boolean boostable = (Boolean) reqData.getParameters().getOrDefault("boostable", true); + Skill skill = Skill.valueOf(skillName.toUpperCase()); + requirement = new SkillRequirement(skill, level, boostable); + break; + + case "ItemRequirement": + int itemId = ((Number) reqData.getParameters().get("itemId")).intValue(); + int quantity = ((Number) reqData.getParameters().getOrDefault("quantity", 1)).intValue(); + boolean equipped = (Boolean) reqData.getParameters().getOrDefault("equipped", false); + String name = itemManager.getItemComposition(itemId).getName(); + requirement = new ItemRequirement(name, itemId, quantity, equipped); + break; + + default: + // Handle unknown requirement types + System.err.println("Unknown requirement type: " + reqData.getType()); + break; + } + + return requirement; + } + + private QuestStep parseQuestStep(JsonQuestHelper newHelper, StepData stepData, Map requirementMap) + { + Map params = stepData.getParameters(); + + String text; + WorldPoint wp; + List reqIds; + Requirement[] reqs; + switch (stepData.getType()) + { + case "DetailedQuestStep": + text = (String) params.get("text"); + wp = getWorldPoint(params); + reqIds = stepData.getStepRequirements(); + reqs = getRequirements(reqIds, requirementMap); + DetailedQuestStep detailedQuestStep = new DetailedQuestStep(newHelper, text); + if (wp != null) detailedQuestStep.setWorldPoint(wp); + if (reqs != null) detailedQuestStep.setRequirements(List.of(reqs)); + return detailedQuestStep; + case "NpcStep": + var npcId = ((Number) params.get("npcId")).intValue(); + text = (String) params.get("text"); + wp = getWorldPoint(params); + reqIds = stepData.getStepRequirements(); + reqs = getRequirements(reqIds, requirementMap); + NpcStep npcStep = new NpcStep(newHelper, npcId, text); + if (wp != null) npcStep.setWorldPoint(wp); + if (reqs != null) npcStep.setRequirements(List.of(reqs)); + return npcStep; + case "ObjectStep": + var objectId = ((Number) params.get("objectId")).intValue(); + text = (String) params.get("text"); + wp = getWorldPoint(params); + reqIds = stepData.getStepRequirements(); + reqs = getRequirements(reqIds, requirementMap); + ObjectStep objectStep = new ObjectStep(newHelper, objectId, text); + if (wp != null) objectStep.setWorldPoint(wp); + if (reqs != null) objectStep.setRequirements(List.of(reqs)); + return objectStep; + default: + // Handle unknown step types + System.err.println("Unknown step type: " + stepData.getType()); + break; + } + + return new DetailedQuestStep(newHelper, "Unable to create step"); + } + + private Map getRequirementMap(List requirementData) + { + Map requirementMap = new HashMap<>(); + for (RequirementData reqData : requirementData) + { + Requirement requirement = parseRequirement(reqData); + if (requirement != null) + { + requirementMap.put(reqData.getId(), requirement); + } + } + + return requirementMap; + } + + private Requirement[] getRequirements(List reqs, Map requirementMap) + { + if (reqs == null) return null; + Requirement[] requirements = new Requirement[reqs.size()]; + for (int i=0; i params) + { + var x = ((Number) params.getOrDefault("wpX", -1)).intValue(); + var y = ((Number) params.getOrDefault("wpY", -1)).intValue(); + var z = ((Number) params.getOrDefault("wpZ", -1)).intValue(); + if (x == -1 || y == -1 || z == -1) return null; + return new WorldPoint(x, y, z); + } + + private LogicType getLogicType(String logicType) + { + if (logicType == null) return LogicType.AND; + + switch (logicType.toLowerCase()) + { + case "or": + return LogicType.OR; + case "nor": + return LogicType.NOR; + case "nand": + return LogicType.NAND; + default: + return LogicType.AND; + } + } +} diff --git a/src/main/java/com/questhelper/questimport/QuestData.java b/src/main/java/com/questhelper/questimport/QuestData.java new file mode 100644 index 0000000000..ed1d3097c5 --- /dev/null +++ b/src/main/java/com/questhelper/questimport/QuestData.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024, Zoinkwiz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.questhelper.questimport; + +import lombok.Data; +import java.util.List; + +@Data +public class QuestData { + private List requirements; + private List steps; +} diff --git a/src/main/java/com/questhelper/questimport/RequirementData.java b/src/main/java/com/questhelper/questimport/RequirementData.java new file mode 100644 index 0000000000..238b7a23c9 --- /dev/null +++ b/src/main/java/com/questhelper/questimport/RequirementData.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024, Zoinkwiz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.questhelper.questimport; + +import lombok.Data; +import java.util.Map; + +@Data +public class RequirementData { + private String id; + private String type; + private Map parameters; +} diff --git a/src/main/java/com/questhelper/questimport/StepData.java b/src/main/java/com/questhelper/questimport/StepData.java new file mode 100644 index 0000000000..be091db0f5 --- /dev/null +++ b/src/main/java/com/questhelper/questimport/StepData.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024, Zoinkwiz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.questhelper.questimport; + +import lombok.Data; +import java.util.List; +import java.util.Map; + +@Data +public class StepData { + private String type; + private boolean isDefault; + private Map parameters; + private List stepRequirements; + private String logicType; + private List conditionalRequirements; +} + diff --git a/src/main/java/com/questhelper/steps/QuestStep.java b/src/main/java/com/questhelper/steps/QuestStep.java index 74ae932c5f..ece1c790aa 100644 --- a/src/main/java/com/questhelper/steps/QuestStep.java +++ b/src/main/java/com/questhelper/steps/QuestStep.java @@ -463,7 +463,7 @@ else if (text != null) private void addTitleToPanel(PanelComponent panelComponent) { panelComponent.getChildren().add(LineComponent.builder() - .left(questHelper.getQuest().getName()) + .left(questHelper.getName()) .build()); } diff --git a/src/test/java/com/questhelper/QuestHelperPluginTest.java b/src/test/java/com/questhelper/QuestHelperPluginTest.java index bd9f293b4e..79bc6fe27c 100644 --- a/src/test/java/com/questhelper/QuestHelperPluginTest.java +++ b/src/test/java/com/questhelper/QuestHelperPluginTest.java @@ -10,4 +10,4 @@ public static void main(String[] args) throws Exception ExternalPluginManager.loadBuiltin(QuestHelperPlugin.class); RuneLite.main(args); } -} \ No newline at end of file +} From a4f24891395d056dcb670beaa9c6fa4f73eb7cac Mon Sep 17 00:00:00 2001 From: Zoinkwiz Date: Sun, 24 Nov 2024 20:03:15 +0000 Subject: [PATCH 2/5] feat: add example quest.json --- src/main/resources/quest.json | 73 +++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/main/resources/quest.json diff --git a/src/main/resources/quest.json b/src/main/resources/quest.json new file mode 100644 index 0000000000..a273ad8e7c --- /dev/null +++ b/src/main/resources/quest.json @@ -0,0 +1,73 @@ +{ + "requirements": [ + { + "id": "attack50", + "type": "SkillRequirement", + "parameters": { + "skill": "ATTACK", + "level": 50, + "boostable": true + } + }, + { + "id": "bucket", + "type": "ItemRequirement", + "parameters": { + "itemId": 1925, + "quantity": 1 + } + }, + { + "id": "bucketofwater", + "type": "ItemRequirement", + "parameters": { + "itemId": 1929, + "quantity": 1 + } + }, + { + "id": "uncutSapphire", + "type": "ItemRequirement", + "parameters": { + "itemId": 1623, + "quantity": 1 + } + } + ], + "steps": [ + { + "type": "NpcStep", + "parameters": { + "npcId": 3105, + "text": "Talk to Hans, and get an uncut sapphire.", + "wpX": 3223, + "wpY": 3218, + "wpZ": 0 + }, + "logicType": "nand", + "stepRequirements": ["uncutSapphire"], + "stepRequirements": ["uncutSapphire"], + "conditionalRequirements": ["uncutSapphire"] + }, + { + "type": "ObjectStep", + "parameters": { + "objectId": 9101, + "text": "Use a bucket on the fountain in Lumbridge Castle.", + "wpX": 3221, + "wpY": 3226, + "wpZ": 0 + }, + "logicType": "nand", + "stepRequirements": ["bucket", "attack50"], + "conditionalRequirements": ["bucketofwater"] + }, + { + "type": "DetailedQuestStep", + "parameters": { + "text": "You did it!" + }, + "isDefault": true + } + ] +} From bcd8f46a3cb912f9bbe80e48cb7e216da2bfd7a5 Mon Sep 17 00:00:00 2001 From: Zoinkwiz Date: Sun, 24 Nov 2024 20:15:10 +0000 Subject: [PATCH 3/5] fix: Add missing copyright append --- src/main/java/com/questhelper/QuestHelperSharingManager.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/questhelper/QuestHelperSharingManager.java b/src/main/java/com/questhelper/QuestHelperSharingManager.java index 0eb9ff851e..1d1ee25b00 100644 --- a/src/main/java/com/questhelper/QuestHelperSharingManager.java +++ b/src/main/java/com/questhelper/QuestHelperSharingManager.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2024, Zoinkwiz * All rights reserved. * From 556fbeaac87eac326773c861a9408d27ce690052 Mon Sep 17 00:00:00 2001 From: Zoinkwiz Date: Sun, 24 Nov 2024 20:15:55 +0000 Subject: [PATCH 4/5] fix: Remove duplicate requirement in quest.json --- src/main/resources/quest.json | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/resources/quest.json b/src/main/resources/quest.json index a273ad8e7c..6af701ebc9 100644 --- a/src/main/resources/quest.json +++ b/src/main/resources/quest.json @@ -46,7 +46,6 @@ }, "logicType": "nand", "stepRequirements": ["uncutSapphire"], - "stepRequirements": ["uncutSapphire"], "conditionalRequirements": ["uncutSapphire"] }, { From fd75cd8f75f8b67679cdd00b0da2fd3f5728a5c9 Mon Sep 17 00:00:00 2001 From: Zoinkwiz Date: Sun, 24 Nov 2024 20:24:18 +0000 Subject: [PATCH 5/5] fix: formatting fixes --- src/main/java/com/questhelper/QuestHelperPlugin.java | 2 +- src/main/java/com/questhelper/questimport/JsonToQuest.java | 5 +++-- src/main/java/com/questhelper/questimport/QuestData.java | 3 ++- .../java/com/questhelper/questimport/RequirementData.java | 3 ++- src/main/java/com/questhelper/questimport/StepData.java | 4 ++-- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/questhelper/QuestHelperPlugin.java b/src/main/java/com/questhelper/QuestHelperPlugin.java index e6e0ebb4cf..4c45c454c3 100644 --- a/src/main/java/com/questhelper/QuestHelperPlugin.java +++ b/src/main/java/com/questhelper/QuestHelperPlugin.java @@ -334,7 +334,7 @@ public void onConfigChanged(ConfigChanged event) return; } - if (event.getKey().equals("showRuneliteObjects") && client.getGameState() == GameState.LOGGED_IN) + if (event.getKey().equals("showRuneliteObjects") && client.getGameState() == GameState.LOGGED_IN) { clientThread.invokeLater(() -> { if (config.showRuneliteObjects()) diff --git a/src/main/java/com/questhelper/questimport/JsonToQuest.java b/src/main/java/com/questhelper/questimport/JsonToQuest.java index 8abde75158..528450fb8a 100644 --- a/src/main/java/com/questhelper/questimport/JsonToQuest.java +++ b/src/main/java/com/questhelper/questimport/JsonToQuest.java @@ -50,6 +50,7 @@ public JsonToQuest(ItemManager itemManager) { this.itemManager = itemManager; } + public JsonQuestHelper importQuestFromJson(Gson gson, String jsonContent) { JsonQuestHelper newHelper = new JsonQuestHelper(); @@ -182,7 +183,7 @@ private Requirement[] getRequirements(List reqs, Map requirements; private List steps; } diff --git a/src/main/java/com/questhelper/questimport/RequirementData.java b/src/main/java/com/questhelper/questimport/RequirementData.java index 238b7a23c9..182fb70d13 100644 --- a/src/main/java/com/questhelper/questimport/RequirementData.java +++ b/src/main/java/com/questhelper/questimport/RequirementData.java @@ -28,7 +28,8 @@ import java.util.Map; @Data -public class RequirementData { +public class RequirementData +{ private String id; private String type; private Map parameters; diff --git a/src/main/java/com/questhelper/questimport/StepData.java b/src/main/java/com/questhelper/questimport/StepData.java index be091db0f5..abe5b63f00 100644 --- a/src/main/java/com/questhelper/questimport/StepData.java +++ b/src/main/java/com/questhelper/questimport/StepData.java @@ -29,7 +29,8 @@ import java.util.Map; @Data -public class StepData { +public class StepData +{ private String type; private boolean isDefault; private Map parameters; @@ -37,4 +38,3 @@ public class StepData { private String logicType; private List conditionalRequirements; } -