diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/kingdomofmiscellania/KingdomConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/kingdomofmiscellania/KingdomConfig.java new file mode 100644 index 0000000000..d1e8ea9747 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/kingdomofmiscellania/KingdomConfig.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2019, Parker + * 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 net.runelite.client.plugins.kingdomofmiscellania; + +import net.runelite.client.config.Config; +import net.runelite.client.config.ConfigGroup; +import net.runelite.client.config.ConfigItem; + +@ConfigGroup("kingdomofmiscellania") +public interface KingdomConfig extends Config +{ + @ConfigItem( + keyName = "showInfoboxAnywhere", + name = "Show kingdom infobox anywhere", + description = "Show the infobox containing your favor/coffer amount even when outside Miscellania", + position = 0 + ) + default boolean showInfoboxAnywhere() + { + return false; + } + + @ConfigItem( + keyName = "notifyFavorThreshold", + name = "Notify chat favor", + description = "Sends a message to your chatbox when your kingdom favor percentage is below the threshold. Leave at 0 to disable.", + position = 1 + + ) + default int notifyFavorThreshold() + { + return 0; + } + + @ConfigItem( + keyName = "notifyCofferThreshold", + name = "Notify chat coffer value", + description = "Sends a message to your chatbox when your kingdom's coffer is below the threshold. Leave at 0 to disable.", + position = 2 + ) + default int notifyCofferThreshold() + { + return 0; + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/kingdomofmiscellania/KingdomCounter.java b/runelite-client/src/main/java/net/runelite/client/plugins/kingdomofmiscellania/KingdomCounter.java index b48a0af346..cdf5dfe093 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/kingdomofmiscellania/KingdomCounter.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/kingdomofmiscellania/KingdomCounter.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2018, Infinitay + * Copyright (c) 2019, Parker * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -49,7 +50,12 @@ class KingdomCounter extends Counter @Override public String getTooltip() { - return "Favor: " + plugin.getFavor() + "/127" + "
" - + "Coffer: " + StackFormatter.quantityToRSStackSize(plugin.getCoffer()); + return new StringBuilder("Favor: ") + .append(plugin.getFavor()) + .append("/127") + .append("
") + .append("Coffer: ") + .append(StackFormatter.quantityToRSStackSize(plugin.getCoffer())) + .toString(); } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/kingdomofmiscellania/KingdomPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/kingdomofmiscellania/KingdomPlugin.java index 39e99d8a7f..71f2f59151 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/kingdomofmiscellania/KingdomPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/kingdomofmiscellania/KingdomPlugin.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2018, Infinitay + * Copyright (c) 2019, Parker * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -25,18 +26,28 @@ package net.runelite.client.plugins.kingdomofmiscellania; import com.google.common.collect.ImmutableSet; +import java.text.NumberFormat; import javax.inject.Inject; import javax.inject.Singleton; +import com.google.inject.Provides; import lombok.AccessLevel; import lombok.Getter; import lombok.extern.slf4j.Slf4j; +import net.runelite.api.ChatMessageType; import net.runelite.api.Client; import net.runelite.api.GameState; import static net.runelite.api.ItemID.TEAK_CHEST; import net.runelite.api.VarPlayer; import net.runelite.api.Varbits; +import net.runelite.api.events.ConfigChanged; import net.runelite.api.events.GameStateChanged; import net.runelite.api.events.VarbitChanged; +import net.runelite.client.callback.ClientThread; +import net.runelite.client.chat.ChatColorType; +import net.runelite.client.chat.ChatMessageBuilder; +import net.runelite.client.chat.ChatMessageManager; +import net.runelite.client.chat.QueuedMessage; +import net.runelite.client.config.ConfigManager; import net.runelite.client.eventbus.EventBus; import net.runelite.client.game.ItemManager; import net.runelite.client.plugins.Plugin; @@ -45,8 +56,8 @@ import net.runelite.client.ui.overlay.infobox.InfoBoxManager; @PluginDescriptor( name = "Kingdom of Miscellania", - description = "Show amount of favor when inside Miscellania", - tags = {"favor", "favour", "managing", "overlay"}, + description = "Show various informations about your Kingdom of Miscellania", + tags = {"favor", "favour", "managing", "overlay", "indication", "notification"}, enabledByDefault = false ) @Slf4j @@ -58,6 +69,15 @@ public class KingdomPlugin extends Plugin @Inject private Client client; + @Inject + private KingdomConfig config; + + @Inject + private ClientThread clientThread; + + @Inject + private ChatMessageManager chatMessageManager; + @Inject private InfoBoxManager infoBoxManager; @@ -71,10 +91,20 @@ public class KingdomPlugin extends Plugin private int favor = 0, coffer = 0; private KingdomCounter counter; + private boolean showInfoboxAnywhere; + private int notifyFavorThreshold; + private int notifyCofferThreshold; + + @Provides + KingdomConfig provideConfig(ConfigManager configManager) + { + return configManager.getConfig(KingdomConfig.class); + } @Override protected void startUp() throws Exception { + updateConfig(); addSubscriptions(); } @@ -90,29 +120,44 @@ public class KingdomPlugin extends Plugin { eventBus.subscribe(VarbitChanged.class, this, this::onVarbitChanged); eventBus.subscribe(GameStateChanged.class, this, this::onGameStateChanged); + eventBus.subscribe(ConfigChanged.class, this, this::onConfigChanged); } private void onVarbitChanged(VarbitChanged event) { - if (isInKingdom()) - { - favor = client.getVar(Varbits.KINGDOM_FAVOR); - coffer = client.getVar(Varbits.KINGDOM_COFFER); - processInfobox(); - } + updateKingdomVarbits(); + processInfobox(); } public void onGameStateChanged(GameStateChanged event) { + if (event.getGameState() == GameState.LOGGED_IN) { - processInfobox(); + clientThread.invokeLater(() -> + { + updateKingdomVarbits(); + processInfobox(); + notifyFavor(); + notifyCoffer(); + }); } } + private void onConfigChanged(ConfigChanged event) + { + if (!event.getGroup().equals("kingdomofmiscellania")) + { + return; + } + + updateConfig(); + processInfobox(); + } + private void processInfobox() { - if (client.getGameState() == GameState.LOGGED_IN && hasCompletedQuest() && isInKingdom()) + if (client.getGameState() == GameState.LOGGED_IN && hasCompletedQuest() && (isInKingdom() || this.showInfoboxAnywhere)) { addKingdomInfobox(); } @@ -123,13 +168,23 @@ public class KingdomPlugin extends Plugin } + private void updateKingdomVarbits() + { + if (!hasCompletedQuest()) + { + return; + } + + this.favor = client.getVar(Varbits.KINGDOM_FAVOR); + this.coffer = client.getVar(Varbits.KINGDOM_COFFER); + } + private void addKingdomInfobox() { if (counter == null) { counter = new KingdomCounter(itemManager.getImage(TEAK_CHEST), this); infoBoxManager.addInfoBox(counter); - log.debug("Added Kingdom Infobox"); } } @@ -139,7 +194,6 @@ public class KingdomPlugin extends Plugin { infoBoxManager.removeInfoBox(counter); counter = null; - log.debug("Removed Kingdom Infobox"); } } @@ -159,4 +213,40 @@ public class KingdomPlugin extends Plugin return (favor * 100) / 127; } + private void notifyFavor() + { + if (hasCompletedQuest() && getFavorPercent(favor) < this.notifyFavorThreshold) + { + sendChatMessage("Your favor with your kingdom is below " + this.notifyFavorThreshold + "%."); + } + } + + private void notifyCoffer() + { + if (hasCompletedQuest() && coffer < this.notifyCofferThreshold) + { + sendChatMessage("Your kingdom's coffer has less than " + NumberFormat.getIntegerInstance().format(this.notifyCofferThreshold) + " coins in it."); + } + } + + private void sendChatMessage(String chatMessage) + { + final String message = new ChatMessageBuilder() + .append(ChatColorType.HIGHLIGHT) + .append(chatMessage) + .build(); + + chatMessageManager.queue( + QueuedMessage.builder() + .type(ChatMessageType.CONSOLE) + .runeLiteFormattedMessage(message) + .build()); + } + + private void updateConfig() + { + this.showInfoboxAnywhere = config.showInfoboxAnywhere(); + this.notifyFavorThreshold = config.notifyFavorThreshold(); + this.notifyCofferThreshold = config.notifyCofferThreshold(); + } }