ge plugin: add buy limit reset timer
Co-authored-by: renfc <renfc145@gmail.com>
This commit is contained in:
@@ -28,9 +28,11 @@ import net.runelite.client.config.Config;
|
|||||||
import net.runelite.client.config.ConfigGroup;
|
import net.runelite.client.config.ConfigGroup;
|
||||||
import net.runelite.client.config.ConfigItem;
|
import net.runelite.client.config.ConfigItem;
|
||||||
|
|
||||||
@ConfigGroup("grandexchange")
|
@ConfigGroup(GrandExchangeConfig.CONFIG_GROUP)
|
||||||
public interface GrandExchangeConfig extends Config
|
public interface GrandExchangeConfig extends Config
|
||||||
{
|
{
|
||||||
|
String CONFIG_GROUP = "grandexchange";
|
||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
position = 1,
|
position = 1,
|
||||||
keyName = "quickLookup",
|
keyName = "quickLookup",
|
||||||
@@ -77,6 +79,18 @@ public interface GrandExchangeConfig extends Config
|
|||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
position = 5,
|
position = 5,
|
||||||
|
keyName = "enableGELimitReset",
|
||||||
|
name = "Enable GE Limit Reset Timer",
|
||||||
|
description = "Shows when GE Trade limits reset (H:MM)"
|
||||||
|
)
|
||||||
|
|
||||||
|
default boolean enableGELimitReset()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ConfigItem(
|
||||||
|
position = 6,
|
||||||
keyName = "showTotal",
|
keyName = "showTotal",
|
||||||
name = "Show grand exchange total",
|
name = "Show grand exchange total",
|
||||||
description = "Show grand exchange total"
|
description = "Show grand exchange total"
|
||||||
@@ -87,7 +101,7 @@ public interface GrandExchangeConfig extends Config
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
position = 6,
|
position = 7,
|
||||||
keyName = "showExact",
|
keyName = "showExact",
|
||||||
name = "Show exact total value",
|
name = "Show exact total value",
|
||||||
description = "Show exact total value"
|
description = "Show exact total value"
|
||||||
@@ -98,7 +112,7 @@ public interface GrandExchangeConfig extends Config
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
position = 7,
|
position = 8,
|
||||||
keyName = "highlightSearchMatch",
|
keyName = "highlightSearchMatch",
|
||||||
name = "Highlight Search Match",
|
name = "Highlight Search Match",
|
||||||
description = "Highlights the search match with an underline"
|
description = "Highlights the search match with an underline"
|
||||||
@@ -109,7 +123,7 @@ public interface GrandExchangeConfig extends Config
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
position = 8,
|
position = 9,
|
||||||
keyName = "geSearchMode",
|
keyName = "geSearchMode",
|
||||||
name = "Search Mode",
|
name = "Search Mode",
|
||||||
description = "The search mode to use for the GE<br>"
|
description = "The search mode to use for the GE<br>"
|
||||||
|
|||||||
@@ -30,18 +30,18 @@ package net.runelite.client.plugins.grandexchange;
|
|||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.primitives.Shorts;
|
import com.google.common.primitives.Shorts;
|
||||||
import com.google.common.reflect.TypeToken;
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.Instant;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.function.ToIntFunction;
|
import java.util.function.ToIntFunction;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -98,6 +98,7 @@ import net.runelite.http.api.ge.GrandExchangeTrade;
|
|||||||
import net.runelite.http.api.item.ItemStats;
|
import net.runelite.http.api.item.ItemStats;
|
||||||
import net.runelite.http.api.osbuddy.OSBGrandExchangeClient;
|
import net.runelite.http.api.osbuddy.OSBGrandExchangeClient;
|
||||||
import net.runelite.http.api.osbuddy.OSBGrandExchangeResult;
|
import net.runelite.http.api.osbuddy.OSBGrandExchangeResult;
|
||||||
|
import org.apache.commons.lang3.time.DurationFormatUtils;
|
||||||
import org.apache.commons.text.similarity.FuzzyScore;
|
import org.apache.commons.text.similarity.FuzzyScore;
|
||||||
|
|
||||||
@PluginDescriptor(
|
@PluginDescriptor(
|
||||||
@@ -114,10 +115,9 @@ public class GrandExchangePlugin extends Plugin
|
|||||||
private static final String OSB_GE_TEXT = "<br>OSBuddy Actively traded price: ";
|
private static final String OSB_GE_TEXT = "<br>OSBuddy Actively traded price: ";
|
||||||
|
|
||||||
private static final String BUY_LIMIT_GE_TEXT = "<br>Buy limit: ";
|
private static final String BUY_LIMIT_GE_TEXT = "<br>Buy limit: ";
|
||||||
|
private static final String BUY_LIMIT_KEY = "buylimit_";
|
||||||
private static final Gson GSON = new Gson();
|
private static final Gson GSON = new Gson();
|
||||||
private static final TypeToken<Map<Integer, Integer>> BUY_LIMIT_TOKEN = new TypeToken<Map<Integer, Integer>>()
|
private static final Duration BUY_LIMIT_RESET = Duration.ofHours(4);
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
static final String SEARCH_GRAND_EXCHANGE = "Search Grand Exchange";
|
static final String SEARCH_GRAND_EXCHANGE = "Search Grand Exchange";
|
||||||
|
|
||||||
@@ -315,7 +315,7 @@ public class GrandExchangePlugin extends Plugin
|
|||||||
@Subscribe
|
@Subscribe
|
||||||
public void onConfigChanged(ConfigChanged event)
|
public void onConfigChanged(ConfigChanged event)
|
||||||
{
|
{
|
||||||
if (event.getGroup().equals("grandexchange"))
|
if (event.getGroup().equals(GrandExchangeConfig.CONFIG_GROUP))
|
||||||
{
|
{
|
||||||
if (event.getKey().equals("quickLookup"))
|
if (event.getKey().equals("quickLookup"))
|
||||||
{
|
{
|
||||||
@@ -403,6 +403,8 @@ public class GrandExchangePlugin extends Plugin
|
|||||||
savedOffer.setSpent(offer.getSpent());
|
savedOffer.setSpent(offer.getSpent());
|
||||||
savedOffer.setState(offer.getState());
|
savedOffer.setState(offer.getState());
|
||||||
setOffer(slot, savedOffer);
|
setOffer(slot, savedOffer);
|
||||||
|
|
||||||
|
updateLimitTimer(offer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -679,6 +681,46 @@ public class GrandExchangePlugin extends Plugin
|
|||||||
stringStack[stringStackSize - 1] += titleBuilder.toString();
|
stringStack[stringStackSize - 1] += titleBuilder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setLimitResetTime(int itemId)
|
||||||
|
{
|
||||||
|
Instant lastDateTime = configManager.getConfiguration(GrandExchangeConfig.CONFIG_GROUP,
|
||||||
|
BUY_LIMIT_KEY + client.getUsername().toLowerCase() + "." + itemId, Instant.class);
|
||||||
|
if (lastDateTime == null || lastDateTime.isBefore(Instant.now()))
|
||||||
|
{
|
||||||
|
configManager.setConfiguration(GrandExchangeConfig.CONFIG_GROUP,
|
||||||
|
BUY_LIMIT_KEY + client.getUsername().toLowerCase() + "." + itemId,
|
||||||
|
Instant.now().plus(BUY_LIMIT_RESET));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Instant getLimitResetTime(int itemId)
|
||||||
|
{
|
||||||
|
Instant lastDateTime = configManager.getConfiguration(GrandExchangeConfig.CONFIG_GROUP,
|
||||||
|
BUY_LIMIT_KEY + client.getUsername().toLowerCase() + "." + itemId, Instant.class);
|
||||||
|
if (lastDateTime == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lastDateTime.isBefore(Instant.now()))
|
||||||
|
{
|
||||||
|
configManager.unsetConfiguration(GrandExchangeConfig.CONFIG_GROUP, BUY_LIMIT_KEY + client.getUsername().toLowerCase() + "." + itemId);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return lastDateTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateLimitTimer(GrandExchangeOffer offer)
|
||||||
|
{
|
||||||
|
if (offer.getState() == GrandExchangeOfferState.BOUGHT ||
|
||||||
|
(offer.getQuantitySold() > 0 &&
|
||||||
|
offer.getState() == GrandExchangeOfferState.BUYING))
|
||||||
|
{
|
||||||
|
setLimitResetTime(offer.getItemId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void rebuildGeText()
|
private void rebuildGeText()
|
||||||
{
|
{
|
||||||
if (grandExchangeText == null || grandExchangeItem == null || grandExchangeItem.isHidden())
|
if (grandExchangeText == null || grandExchangeItem == null || grandExchangeItem.isHidden())
|
||||||
@@ -709,6 +751,16 @@ public class GrandExchangePlugin extends Plugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (config.enableGELimitReset())
|
||||||
|
{
|
||||||
|
Instant resetTime = getLimitResetTime(itemId);
|
||||||
|
if (resetTime != null)
|
||||||
|
{
|
||||||
|
Duration remaining = Duration.between(Instant.now(), resetTime);
|
||||||
|
text += " (" + DurationFormatUtils.formatDuration(remaining.toMillis(), "H:mm") + ")";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
geText.setText(text);
|
geText.setText(text);
|
||||||
|
|
||||||
if (!config.enableOsbPrices())
|
if (!config.enableOsbPrices())
|
||||||
|
|||||||
Reference in New Issue
Block a user