kingdomofmiscellania: add login chat notification for favor and coffer amount - fix whitespaces (#1324)
This commit is contained in:
@@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2019, Parker <https://github.com/Judaxx>
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018, Infinitay <https://github.com/Infinitay>
|
* Copyright (c) 2018, Infinitay <https://github.com/Infinitay>
|
||||||
|
* Copyright (c) 2019, Parker <https://github.com/Judaxx>
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -49,7 +50,12 @@ class KingdomCounter extends Counter
|
|||||||
@Override
|
@Override
|
||||||
public String getTooltip()
|
public String getTooltip()
|
||||||
{
|
{
|
||||||
return "Favor: " + plugin.getFavor() + "/127" + "</br>"
|
return new StringBuilder("Favor: ")
|
||||||
+ "Coffer: " + StackFormatter.quantityToRSStackSize(plugin.getCoffer());
|
.append(plugin.getFavor())
|
||||||
|
.append("/127")
|
||||||
|
.append("</br>")
|
||||||
|
.append("Coffer: ")
|
||||||
|
.append(StackFormatter.quantityToRSStackSize(plugin.getCoffer()))
|
||||||
|
.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018, Infinitay <https://github.com/Infinitay>
|
* Copyright (c) 2018, Infinitay <https://github.com/Infinitay>
|
||||||
|
* Copyright (c) 2019, Parker <https://github.com/Judaxx>
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -25,18 +26,28 @@
|
|||||||
package net.runelite.client.plugins.kingdomofmiscellania;
|
package net.runelite.client.plugins.kingdomofmiscellania;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import java.text.NumberFormat;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
import com.google.inject.Provides;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import net.runelite.api.ChatMessageType;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.api.GameState;
|
import net.runelite.api.GameState;
|
||||||
import static net.runelite.api.ItemID.TEAK_CHEST;
|
import static net.runelite.api.ItemID.TEAK_CHEST;
|
||||||
import net.runelite.api.VarPlayer;
|
import net.runelite.api.VarPlayer;
|
||||||
import net.runelite.api.Varbits;
|
import net.runelite.api.Varbits;
|
||||||
|
import net.runelite.api.events.ConfigChanged;
|
||||||
import net.runelite.api.events.GameStateChanged;
|
import net.runelite.api.events.GameStateChanged;
|
||||||
import net.runelite.api.events.VarbitChanged;
|
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.eventbus.EventBus;
|
||||||
import net.runelite.client.game.ItemManager;
|
import net.runelite.client.game.ItemManager;
|
||||||
import net.runelite.client.plugins.Plugin;
|
import net.runelite.client.plugins.Plugin;
|
||||||
@@ -45,8 +56,8 @@ import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
|
|||||||
|
|
||||||
@PluginDescriptor(
|
@PluginDescriptor(
|
||||||
name = "Kingdom of Miscellania",
|
name = "Kingdom of Miscellania",
|
||||||
description = "Show amount of favor when inside Miscellania",
|
description = "Show various informations about your Kingdom of Miscellania",
|
||||||
tags = {"favor", "favour", "managing", "overlay"},
|
tags = {"favor", "favour", "managing", "overlay", "indication", "notification"},
|
||||||
enabledByDefault = false
|
enabledByDefault = false
|
||||||
)
|
)
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -58,6 +69,15 @@ public class KingdomPlugin extends Plugin
|
|||||||
@Inject
|
@Inject
|
||||||
private Client client;
|
private Client client;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private KingdomConfig config;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private ClientThread clientThread;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private ChatMessageManager chatMessageManager;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private InfoBoxManager infoBoxManager;
|
private InfoBoxManager infoBoxManager;
|
||||||
|
|
||||||
@@ -71,10 +91,20 @@ public class KingdomPlugin extends Plugin
|
|||||||
private int favor = 0, coffer = 0;
|
private int favor = 0, coffer = 0;
|
||||||
|
|
||||||
private KingdomCounter counter;
|
private KingdomCounter counter;
|
||||||
|
private boolean showInfoboxAnywhere;
|
||||||
|
private int notifyFavorThreshold;
|
||||||
|
private int notifyCofferThreshold;
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
KingdomConfig provideConfig(ConfigManager configManager)
|
||||||
|
{
|
||||||
|
return configManager.getConfig(KingdomConfig.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void startUp() throws Exception
|
protected void startUp() throws Exception
|
||||||
{
|
{
|
||||||
|
updateConfig();
|
||||||
addSubscriptions();
|
addSubscriptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,29 +120,44 @@ public class KingdomPlugin extends Plugin
|
|||||||
{
|
{
|
||||||
eventBus.subscribe(VarbitChanged.class, this, this::onVarbitChanged);
|
eventBus.subscribe(VarbitChanged.class, this, this::onVarbitChanged);
|
||||||
eventBus.subscribe(GameStateChanged.class, this, this::onGameStateChanged);
|
eventBus.subscribe(GameStateChanged.class, this, this::onGameStateChanged);
|
||||||
|
eventBus.subscribe(ConfigChanged.class, this, this::onConfigChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onVarbitChanged(VarbitChanged event)
|
private void onVarbitChanged(VarbitChanged event)
|
||||||
{
|
{
|
||||||
if (isInKingdom())
|
updateKingdomVarbits();
|
||||||
{
|
processInfobox();
|
||||||
favor = client.getVar(Varbits.KINGDOM_FAVOR);
|
|
||||||
coffer = client.getVar(Varbits.KINGDOM_COFFER);
|
|
||||||
processInfobox();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onGameStateChanged(GameStateChanged event)
|
public void onGameStateChanged(GameStateChanged event)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (event.getGameState() == GameState.LOGGED_IN)
|
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()
|
private void processInfobox()
|
||||||
{
|
{
|
||||||
if (client.getGameState() == GameState.LOGGED_IN && hasCompletedQuest() && isInKingdom())
|
if (client.getGameState() == GameState.LOGGED_IN && hasCompletedQuest() && (isInKingdom() || this.showInfoboxAnywhere))
|
||||||
{
|
{
|
||||||
addKingdomInfobox();
|
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()
|
private void addKingdomInfobox()
|
||||||
{
|
{
|
||||||
if (counter == null)
|
if (counter == null)
|
||||||
{
|
{
|
||||||
counter = new KingdomCounter(itemManager.getImage(TEAK_CHEST), this);
|
counter = new KingdomCounter(itemManager.getImage(TEAK_CHEST), this);
|
||||||
infoBoxManager.addInfoBox(counter);
|
infoBoxManager.addInfoBox(counter);
|
||||||
log.debug("Added Kingdom Infobox");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,7 +194,6 @@ public class KingdomPlugin extends Plugin
|
|||||||
{
|
{
|
||||||
infoBoxManager.removeInfoBox(counter);
|
infoBoxManager.removeInfoBox(counter);
|
||||||
counter = null;
|
counter = null;
|
||||||
log.debug("Removed Kingdom Infobox");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,4 +213,40 @@ public class KingdomPlugin extends Plugin
|
|||||||
return (favor * 100) / 127;
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user