Merge branch 'upstream-master' into runelite

This commit is contained in:
zeruth
2021-01-22 20:19:52 -05:00
7 changed files with 89 additions and 50 deletions

View File

@@ -25,9 +25,11 @@
package net.runelite.client.externalplugins; package net.runelite.client.externalplugins;
import com.google.common.reflect.TypeToken; import com.google.common.reflect.TypeToken;
import com.google.gson.JsonSyntaxException;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
@@ -37,6 +39,7 @@ import java.security.cert.Certificate;
import java.security.cert.CertificateException; import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory; import java.security.cert.CertificateFactory;
import java.util.List; import java.util.List;
import java.util.Map;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import javax.inject.Inject; import javax.inject.Inject;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@@ -172,4 +175,27 @@ public class ExternalPluginClient
} }
}); });
} }
public Map<String, Integer> getPluginCounts() throws IOException
{
HttpUrl url = RuneLiteAPI.getApiBase()
.newBuilder()
.addPathSegments("pluginhub")
.build();
try (Response res = okHttpClient.newCall(new Request.Builder().url(url).build()).execute())
{
if (res.code() != 200)
{
throw new IOException("Non-OK response code: " + res.code());
}
// CHECKSTYLE:OFF
return RuneLiteAPI.GSON.fromJson(new InputStreamReader(res.body().byteStream()), new TypeToken<Map<String, Integer>>(){}.getType());
// CHECKSTYLE:ON
}
catch (JsonSyntaxException ex)
{
throw new IOException(ex);
}
}
} }

View File

@@ -125,10 +125,13 @@ class PluginHubPanel extends PluginPanel
@Getter @Getter
private final List<String> keywords = new ArrayList<>(); private final List<String> keywords = new ArrayList<>();
@Getter
private final int userCount;
@Getter @Getter
private final boolean installed; private final boolean installed;
PluginItem(ExternalPluginManifest newManifest, Collection<Plugin> loadedPlugins, boolean installed) PluginItem(ExternalPluginManifest newManifest, Collection<Plugin> loadedPlugins, int userCount, boolean installed)
{ {
ExternalPluginManifest loaded = null; ExternalPluginManifest loaded = null;
if (!loadedPlugins.isEmpty()) if (!loadedPlugins.isEmpty())
@@ -137,6 +140,7 @@ class PluginHubPanel extends PluginPanel
} }
manifest = newManifest == null ? loaded : newManifest; manifest = newManifest == null ? loaded : newManifest;
this.userCount = userCount;
this.installed = installed; this.installed = installed;
if (manifest != null) if (manifest != null)
@@ -194,10 +198,7 @@ class PluginHubPanel extends PluginPanel
{ {
BufferedImage img = externalPluginClient.downloadIcon(manifest); BufferedImage img = externalPluginClient.downloadIcon(manifest);
SwingUtilities.invokeLater(() -> SwingUtilities.invokeLater(() -> icon.setIcon(new ImageIcon(img)));
{
icon.setIcon(new ImageIcon(img));
});
} }
catch (IOException e) catch (IOException e)
{ {
@@ -521,11 +522,21 @@ class PluginHubPanel extends PluginPanel
return; return;
} }
reloadPluginList(manifest); Map<String, Integer> pluginCounts = Collections.emptyMap();
try
{
pluginCounts = externalPluginClient.getPluginCounts();
}
catch (IOException e)
{
log.warn("unable to download plugin counts", e);
}
reloadPluginList(manifest, pluginCounts);
}); });
} }
private void reloadPluginList(List<ExternalPluginManifest> manifest) private void reloadPluginList(List<ExternalPluginManifest> manifest, Map<String, Integer> pluginCounts)
{ {
Map<String, ExternalPluginManifest> manifests = manifest.stream() Map<String, ExternalPluginManifest> manifests = manifest.stream()
.collect(ImmutableMap.toImmutableMap(ExternalPluginManifest::getInternalName, Function.identity())); .collect(ImmutableMap.toImmutableMap(ExternalPluginManifest::getInternalName, Function.identity()));
@@ -547,7 +558,8 @@ class PluginHubPanel extends PluginPanel
{ {
plugins = Sets.union(manifests.keySet(), loadedPlugins.keySet()) plugins = Sets.union(manifests.keySet(), loadedPlugins.keySet())
.stream() .stream()
.map(id -> new PluginItem(manifests.get(id), loadedPlugins.get(id), installed.contains(id))) .map(id -> new PluginItem(manifests.get(id), loadedPlugins.get(id),
pluginCounts.getOrDefault(id, -1), installed.contains(id)))
.collect(Collectors.toList()); .collect(Collectors.toList());
refreshing.setVisible(false); refreshing.setVisible(false);
@@ -575,7 +587,11 @@ class PluginHubPanel extends PluginPanel
else else
{ {
stream stream
.sorted(Comparator.comparing(PluginItem::isInstalled).thenComparing(p -> p.manifest.getDisplayName())) .sorted(Comparator.comparing(PluginItem::isInstalled)
.thenComparingInt(PluginItem::getUserCount)
.reversed()
.thenComparing(p -> p.manifest.getDisplayName())
)
.forEach(mainPanel::add); .forEach(mainPanel::add);
} }
@@ -594,6 +610,13 @@ class PluginHubPanel extends PluginPanel
@Subscribe @Subscribe
private void onExternalPluginsChanged(ExternalPluginsChanged ev) private void onExternalPluginsChanged(ExternalPluginsChanged ev)
{ {
SwingUtilities.invokeLater(() -> reloadPluginList(ev.getLoadedManifest())); Map<String, Integer> pluginCounts = Collections.emptyMap();
if (plugins != null)
{
pluginCounts = plugins.stream()
.collect(Collectors.toMap(pi -> pi.manifest.getInternalName(), PluginItem::getUserCount));
}
reloadPluginList(ev.getLoadedManifest(), pluginCounts);
} }
} }

View File

@@ -32,7 +32,6 @@ 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.concurrent.ScheduledExecutorService;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import javax.inject.Inject; import javax.inject.Inject;
@@ -108,7 +107,6 @@ class PluginListPanel extends PluginPanel
ConfigManager configManager, ConfigManager configManager,
PluginManager pluginManager, PluginManager pluginManager,
ExternalPluginManager externalPluginManager, ExternalPluginManager externalPluginManager,
ScheduledExecutorService executorService,
EventBus eventBus, EventBus eventBus,
Provider<ConfigPanel> configPanelProvider, Provider<ConfigPanel> configPanelProvider,
Provider<PluginHubPanel> pluginHubPanelProvider) Provider<PluginHubPanel> pluginHubPanelProvider)

View File

@@ -124,9 +124,9 @@ public class CookingPlugin extends Plugin
} }
Duration statTimeout = Duration.ofMinutes(config.statTimeout()); Duration statTimeout = Duration.ofMinutes(config.statTimeout());
Duration sinceCut = Duration.between(session.getLastCookingAction(), Instant.now()); Duration sinceCooked = Duration.between(session.getLastCookingAction(), Instant.now());
if (sinceCut.compareTo(statTimeout) >= 0) if (sinceCooked.compareTo(statTimeout) >= 0)
{ {
session = null; session = null;
} }

View File

@@ -58,7 +58,6 @@ import net.runelite.client.ui.overlay.components.BackgroundComponent;
import net.runelite.client.ui.overlay.components.ProgressPieComponent; import net.runelite.client.ui.overlay.components.ProgressPieComponent;
import net.runelite.client.ui.overlay.components.TextComponent; import net.runelite.client.ui.overlay.components.TextComponent;
import net.runelite.client.util.QuantityFormatter; import net.runelite.client.util.QuantityFormatter;
import org.apache.commons.lang3.ArrayUtils;
public class GroundItemsOverlay extends Overlay public class GroundItemsOverlay extends Overlay
{ {
@@ -78,6 +77,10 @@ public class GroundItemsOverlay extends Overlay
private static final Duration DESPAWN_TIME_DROP = Duration.ofMinutes(3); private static final Duration DESPAWN_TIME_DROP = Duration.ofMinutes(3);
private static final int KRAKEN_REGION = 9116; private static final int KRAKEN_REGION = 9116;
private static final int KBD_NMZ_REGION = 9033; private static final int KBD_NMZ_REGION = 9033;
private static final int ZILYANA_REGION = 11602;
private static final int GRAARDOR_REGION = 11347;
private static final int KRIL_TSUTSAROTH_REGION = 11603;
private static final int KREEARRA_REGION = 11346;
private final Client client; private final Client client;
private final GroundItemsPlugin plugin; private final GroundItemsPlugin plugin;
@@ -410,35 +413,31 @@ public class GroundItemsOverlay extends Overlay
return null; return null;
} }
Instant despawnTime; final Instant despawnTime;
Instant now = Instant.now(); Instant now = Instant.now();
if (client.isInInstancedRegion()) if (client.isInInstancedRegion())
{ {
// Items in the Kraken instance appear to never despawn? final int playerRegionID = WorldPoint.fromLocalInstance(client, client.getLocalPlayer().getLocalLocation()).getRegionID();
if (isInKraken()) if (playerRegionID == KRAKEN_REGION)
{ {
// Items in the Kraken instance never despawn
return null; return null;
} }
else if (isInKBDorNMZ()) else if (playerRegionID == KBD_NMZ_REGION)
{ {
// NMZ and the KBD lair uses the same region ID but NMZ uses planes 1-3 and KBD uses plane 0 // NMZ and the KBD lair uses the same region ID but NMZ uses planes 1-3 and KBD uses plane 0
if (client.getLocalPlayer().getWorldLocation().getPlane() == 0) if (client.getLocalPlayer().getWorldLocation().getPlane() == 0)
{ {
// Items in the KBD instance use the standard despawn timer // Items in the KBD instance use the standard despawn timer
if (groundItem.getLootType() == LootType.DROPPED) despawnTime = spawnTime.plus(groundItem.getLootType() == LootType.DROPPED
{ ? DESPAWN_TIME_DROP
despawnTime = spawnTime.plus(DESPAWN_TIME_DROP); : DESPAWN_TIME_LOOT);
}
else
{
despawnTime = spawnTime.plus(DESPAWN_TIME_LOOT);
}
} }
else else
{ {
// Dropped items in the NMZ instance appear to never despawn?
if (groundItem.getLootType() == LootType.DROPPED) if (groundItem.getLootType() == LootType.DROPPED)
{ {
// Dropped items in the NMZ instance never despawn
return null; return null;
} }
else else
@@ -447,6 +446,14 @@ public class GroundItemsOverlay extends Overlay
} }
} }
} }
else if (playerRegionID == ZILYANA_REGION || playerRegionID == GRAARDOR_REGION ||
playerRegionID == KRIL_TSUTSAROTH_REGION || playerRegionID == KREEARRA_REGION)
{
// GWD instances use the normal despawn timers
despawnTime = spawnTime.plus(groundItem.getLootType() == LootType.DROPPED
? DESPAWN_TIME_DROP
: DESPAWN_TIME_LOOT);
}
else else
{ {
despawnTime = spawnTime.plus(DESPAWN_TIME_INSTANCE); despawnTime = spawnTime.plus(DESPAWN_TIME_INSTANCE);
@@ -454,14 +461,9 @@ public class GroundItemsOverlay extends Overlay
} }
else else
{ {
if (groundItem.getLootType() == LootType.DROPPED) despawnTime = spawnTime.plus(groundItem.getLootType() == LootType.DROPPED
{ ? DESPAWN_TIME_DROP
despawnTime = spawnTime.plus(DESPAWN_TIME_DROP); : DESPAWN_TIME_LOOT);
}
else
{
despawnTime = spawnTime.plus(DESPAWN_TIME_LOOT);
}
} }
if (now.isBefore(spawnTime) || now.isAfter(despawnTime)) if (now.isBefore(spawnTime) || now.isAfter(despawnTime))
@@ -561,14 +563,4 @@ public class GroundItemsOverlay extends Overlay
} }
} }
private boolean isInKraken()
{
return ArrayUtils.contains(client.getMapRegions(), KRAKEN_REGION);
}
private boolean isInKBDorNMZ()
{
return ArrayUtils.contains(client.getMapRegions(), KBD_NMZ_REGION);
}
} }

View File

@@ -71,9 +71,9 @@ public class MotherlodeGemOverlay extends OverlayPanel
} }
Duration statTimeout = Duration.ofMinutes(config.statTimeout()); Duration statTimeout = Duration.ofMinutes(config.statTimeout());
Duration sinceCut = Duration.between(session.getLastGemFound(), Instant.now()); Duration sinceLastGem = Duration.between(session.getLastGemFound(), Instant.now());
if (sinceCut.compareTo(statTimeout) >= 0) if (sinceLastGem.compareTo(statTimeout) >= 0)
{ {
return null; return null;
} }

View File

@@ -86,9 +86,9 @@ class MotherlodeOverlay extends OverlayPanel
} }
Duration statTimeout = Duration.ofMinutes(config.statTimeout()); Duration statTimeout = Duration.ofMinutes(config.statTimeout());
Duration sinceCut = Duration.between(session.getLastPayDirtMined(), Instant.now()); Duration sinceLastPayDirt = Duration.between(session.getLastPayDirtMined(), Instant.now());
if (sinceCut.compareTo(statTimeout) >= 0) if (sinceLastPayDirt.compareTo(statTimeout) >= 0)
{ {
return null; return null;
} }