ge plugin: add grand exchange total value

Co-authored-by: Adam <Adam@sigterm.info>
This commit is contained in:
Daniel Serpa
2019-06-26 18:58:01 -04:00
committed by Adam
parent 23197077a6
commit 692609480f
4 changed files with 168 additions and 0 deletions

View File

@@ -74,4 +74,26 @@ public interface GrandExchangeConfig extends Config
{
return true;
}
@ConfigItem(
position = 5,
keyName = "showTotal",
name = "Show grand exchange total",
description = "Show grand exchange total"
)
default boolean showTotal()
{
return true;
}
@ConfigItem(
position = 6,
keyName = "showExact",
name = "Show exact total value",
description = "Show exact total value"
)
default boolean showExact()
{
return false;
}
}

View File

@@ -60,6 +60,7 @@ import net.runelite.api.events.MenuEntryAdded;
import net.runelite.client.events.SessionClose;
import net.runelite.client.events.SessionOpen;
import net.runelite.api.events.WidgetLoaded;
import net.runelite.api.events.ScriptCallbackEvent;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetID;
import net.runelite.api.widgets.WidgetInfo;
@@ -428,6 +429,49 @@ public class GrandExchangePlugin extends Plugin
}
}
@Subscribe
public void onScriptCallbackEvent(ScriptCallbackEvent event)
{
if (!event.getEventName().equals("setGETitle") || !config.showTotal())
{
return;
}
long total = 0;
GrandExchangeOffer[] offers = client.getGrandExchangeOffers();
for (GrandExchangeOffer offer : offers)
{
if (offer != null)
{
total += offer.getPrice() * offer.getTotalQuantity();
}
}
if (total == 0L)
{
return;
}
StringBuilder titleBuilder = new StringBuilder(" (");
if (config.showExact())
{
titleBuilder.append(StackFormatter.formatNumber(total));
}
else
{
titleBuilder.append(StackFormatter.quantityToStackSize(total));
}
titleBuilder.append(')');
// Append to title
String[] stringStack = client.getStringStack();
int stringStackSize = client.getStringStackSize();
stringStack[stringStackSize - 1] += titleBuilder.toString();
}
@Subscribe
public void onGameTick(GameTick event)
{