ge plugin: add buy limit reset timer

Co-authored-by: renfc <renfc145@gmail.com>
This commit is contained in:
Adam
2020-05-11 16:19:29 -04:00
parent aae994cbf1
commit aea258fb5c
2 changed files with 76 additions and 10 deletions

View File

@@ -28,9 +28,11 @@ import net.runelite.client.config.Config;
import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem;
@ConfigGroup("grandexchange")
@ConfigGroup(GrandExchangeConfig.CONFIG_GROUP)
public interface GrandExchangeConfig extends Config
{
String CONFIG_GROUP = "grandexchange";
@ConfigItem(
position = 1,
keyName = "quickLookup",
@@ -77,6 +79,18 @@ public interface GrandExchangeConfig extends Config
@ConfigItem(
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",
name = "Show grand exchange total",
description = "Show grand exchange total"
@@ -87,7 +101,7 @@ public interface GrandExchangeConfig extends Config
}
@ConfigItem(
position = 6,
position = 7,
keyName = "showExact",
name = "Show exact total value",
description = "Show exact total value"
@@ -98,7 +112,7 @@ public interface GrandExchangeConfig extends Config
}
@ConfigItem(
position = 7,
position = 8,
keyName = "highlightSearchMatch",
name = "Highlight Search Match",
description = "Highlights the search match with an underline"
@@ -109,7 +123,7 @@ public interface GrandExchangeConfig extends Config
}
@ConfigItem(
position = 8,
position = 9,
keyName = "geSearchMode",
name = "Search Mode",
description = "The search mode to use for the GE<br>"

View File

@@ -30,18 +30,18 @@ package net.runelite.client.plugins.grandexchange;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.primitives.Shorts;
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.google.inject.Provides;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ScheduledExecutorService;
import java.util.function.ToIntFunction;
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.osbuddy.OSBGrandExchangeClient;
import net.runelite.http.api.osbuddy.OSBGrandExchangeResult;
import org.apache.commons.lang3.time.DurationFormatUtils;
import org.apache.commons.text.similarity.FuzzyScore;
@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 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 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";
@@ -315,7 +315,7 @@ public class GrandExchangePlugin extends Plugin
@Subscribe
public void onConfigChanged(ConfigChanged event)
{
if (event.getGroup().equals("grandexchange"))
if (event.getGroup().equals(GrandExchangeConfig.CONFIG_GROUP))
{
if (event.getKey().equals("quickLookup"))
{
@@ -403,6 +403,8 @@ public class GrandExchangePlugin extends Plugin
savedOffer.setSpent(offer.getSpent());
savedOffer.setState(offer.getState());
setOffer(slot, savedOffer);
updateLimitTimer(offer);
}
}
@@ -679,6 +681,46 @@ public class GrandExchangePlugin extends Plugin
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()
{
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);
if (!config.enableOsbPrices())