hiscore: use correct endpoint when looking up self with shortcut
Co-authored-by: Hydrox6 <ikada@protonmail.ch>
This commit is contained in:
@@ -38,7 +38,6 @@ import java.awt.event.KeyListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -53,7 +52,6 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.Experience;
|
||||
import net.runelite.api.Player;
|
||||
import net.runelite.api.WorldType;
|
||||
import net.runelite.client.ui.ColorScheme;
|
||||
import net.runelite.client.ui.FontManager;
|
||||
import net.runelite.client.ui.PluginPanel;
|
||||
@@ -118,7 +116,7 @@ public class HiscorePanel extends PluginPanel
|
||||
HiscoreEndpoint.NORMAL, HiscoreEndpoint.IRONMAN, HiscoreEndpoint.HARDCORE_IRONMAN, HiscoreEndpoint.ULTIMATE_IRONMAN, HiscoreEndpoint.DEADMAN, HiscoreEndpoint.LEAGUE
|
||||
};
|
||||
|
||||
private final Client client;
|
||||
private final HiscorePlugin plugin;
|
||||
private final HiscoreConfig config;
|
||||
private final NameAutocompleter nameAutocompleter;
|
||||
private final HiscoreClient hiscoreClient;
|
||||
@@ -138,10 +136,10 @@ public class HiscorePanel extends PluginPanel
|
||||
private boolean loading = false;
|
||||
|
||||
@Inject
|
||||
public HiscorePanel(@Nullable Client client,
|
||||
HiscoreConfig config, NameAutocompleter nameAutocompleter, OkHttpClient okHttpClient)
|
||||
public HiscorePanel(@Nullable Client client, HiscorePlugin plugin, HiscoreConfig config,
|
||||
NameAutocompleter nameAutocompleter, OkHttpClient okHttpClient)
|
||||
{
|
||||
this.client = client;
|
||||
this.plugin = plugin;
|
||||
this.config = config;
|
||||
this.nameAutocompleter = nameAutocompleter;
|
||||
this.hiscoreClient = new HiscoreClient(okHttpClient);
|
||||
@@ -187,7 +185,7 @@ public class HiscorePanel extends PluginPanel
|
||||
|
||||
if (localPlayer != null)
|
||||
{
|
||||
lookup(localPlayer.getName());
|
||||
lookup(localPlayer.getName(), plugin.getLocalHiscoreEndpoint());
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -360,10 +358,10 @@ public class HiscorePanel extends PluginPanel
|
||||
return skillPanel;
|
||||
}
|
||||
|
||||
public void lookup(String username)
|
||||
public void lookup(String username, HiscoreEndpoint endpoint)
|
||||
{
|
||||
searchBar.setText(username);
|
||||
resetEndpoints();
|
||||
tabGroup.select(tabGroup.getTab(ArrayUtils.indexOf(ENDPOINTS, endpoint)));
|
||||
lookup();
|
||||
}
|
||||
|
||||
@@ -720,33 +718,11 @@ public class HiscorePanel extends PluginPanel
|
||||
private void resetEndpoints()
|
||||
{
|
||||
// Select the correct tab based on the world type.
|
||||
HiscoreEndpoint endpoint = selectWorldEndpoint();
|
||||
HiscoreEndpoint endpoint = plugin.getWorldEndpoint();
|
||||
int idx = ArrayUtils.indexOf(ENDPOINTS, endpoint);
|
||||
tabGroup.select(tabGroup.getTab(idx));
|
||||
}
|
||||
|
||||
private HiscoreEndpoint selectWorldEndpoint()
|
||||
{
|
||||
if (client != null)
|
||||
{
|
||||
EnumSet<WorldType> wTypes = client.getWorldType();
|
||||
|
||||
if (wTypes.contains(WorldType.DEADMAN_TOURNAMENT))
|
||||
{
|
||||
return HiscoreEndpoint.TOURNAMENT;
|
||||
}
|
||||
else if (wTypes.contains(WorldType.DEADMAN))
|
||||
{
|
||||
return HiscoreEndpoint.DEADMAN;
|
||||
}
|
||||
else if (wTypes.contains(WorldType.LEAGUE))
|
||||
{
|
||||
return HiscoreEndpoint.LEAGUE;
|
||||
}
|
||||
}
|
||||
return HiscoreEndpoint.NORMAL;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static String formatLevel(int level)
|
||||
{
|
||||
|
||||
@@ -28,20 +28,25 @@ import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ObjectArrays;
|
||||
import com.google.inject.Provides;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.EnumSet;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Provider;
|
||||
import javax.swing.SwingUtilities;
|
||||
import lombok.Getter;
|
||||
import net.runelite.api.ChatMessageType;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.IconID;
|
||||
import net.runelite.api.MenuAction;
|
||||
import net.runelite.api.MenuEntry;
|
||||
import net.runelite.api.Player;
|
||||
import net.runelite.api.WorldType;
|
||||
import net.runelite.api.events.ChatMessage;
|
||||
import net.runelite.api.events.MenuEntryAdded;
|
||||
import net.runelite.api.events.MenuOptionClicked;
|
||||
import net.runelite.api.events.VarbitChanged;
|
||||
import net.runelite.api.widgets.WidgetInfo;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.eventbus.Subscribe;
|
||||
@@ -53,6 +58,7 @@ import net.runelite.client.ui.ClientToolbar;
|
||||
import net.runelite.client.ui.NavigationButton;
|
||||
import net.runelite.client.util.ImageUtil;
|
||||
import net.runelite.client.util.Text;
|
||||
import net.runelite.http.api.hiscore.HiscoreEndpoint;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
@PluginDescriptor(
|
||||
@@ -84,6 +90,9 @@ public class HiscorePlugin extends Plugin
|
||||
private NavigationButton navButton;
|
||||
private HiscorePanel hiscorePanel;
|
||||
|
||||
@Getter
|
||||
private HiscoreEndpoint localHiscoreEndpoint;
|
||||
|
||||
@Provides
|
||||
HiscoreConfig provideConfig(ConfigManager configManager)
|
||||
{
|
||||
@@ -198,7 +207,7 @@ public class HiscorePlugin extends Plugin
|
||||
target = Text.removeTags(event.getMenuTarget());
|
||||
}
|
||||
|
||||
lookupPlayer(target);
|
||||
lookupPlayer(target, HiscoreEndpoint.NORMAL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,10 +223,16 @@ public class HiscorePlugin extends Plugin
|
||||
Matcher m = BOUNTY_PATTERN.matcher(message);
|
||||
if (m.matches())
|
||||
{
|
||||
lookupPlayer(m.group(1));
|
||||
lookupPlayer(m.group(1), HiscoreEndpoint.NORMAL);
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onVarbitChanged(VarbitChanged event)
|
||||
{
|
||||
localHiscoreEndpoint = findHiscoreEndpointFromLocalPlayer();
|
||||
}
|
||||
|
||||
private void insertMenuEntry(MenuEntry newEntry, MenuEntry[] entries)
|
||||
{
|
||||
MenuEntry[] newMenu = ObjectArrays.concat(entries, newEntry);
|
||||
@@ -226,7 +241,7 @@ public class HiscorePlugin extends Plugin
|
||||
client.setMenuEntries(newMenu);
|
||||
}
|
||||
|
||||
private void lookupPlayer(String playerName)
|
||||
private void lookupPlayer(String playerName, HiscoreEndpoint endpoint)
|
||||
{
|
||||
SwingUtilities.invokeLater(() ->
|
||||
{
|
||||
@@ -234,7 +249,52 @@ public class HiscorePlugin extends Plugin
|
||||
{
|
||||
navButton.getOnSelect().run();
|
||||
}
|
||||
hiscorePanel.lookup(playerName);
|
||||
hiscorePanel.lookup(playerName, endpoint);
|
||||
});
|
||||
}
|
||||
|
||||
HiscoreEndpoint getWorldEndpoint()
|
||||
{
|
||||
if (client != null)
|
||||
{
|
||||
EnumSet<WorldType> wTypes = client.getWorldType();
|
||||
|
||||
if (wTypes.contains(WorldType.DEADMAN_TOURNAMENT))
|
||||
{
|
||||
return HiscoreEndpoint.TOURNAMENT;
|
||||
}
|
||||
else if (wTypes.contains(WorldType.DEADMAN))
|
||||
{
|
||||
return HiscoreEndpoint.DEADMAN;
|
||||
}
|
||||
else if (wTypes.contains(WorldType.LEAGUE))
|
||||
{
|
||||
return HiscoreEndpoint.LEAGUE;
|
||||
}
|
||||
}
|
||||
return HiscoreEndpoint.NORMAL;
|
||||
}
|
||||
|
||||
private HiscoreEndpoint findHiscoreEndpointFromLocalPlayer()
|
||||
{
|
||||
final HiscoreEndpoint profile = getWorldEndpoint();
|
||||
if (profile != HiscoreEndpoint.NORMAL)
|
||||
{
|
||||
return profile;
|
||||
}
|
||||
|
||||
if (client != null)
|
||||
{
|
||||
switch (client.getAccountType())
|
||||
{
|
||||
case IRONMAN:
|
||||
return HiscoreEndpoint.IRONMAN;
|
||||
case ULTIMATE_IRONMAN:
|
||||
return HiscoreEndpoint.ULTIMATE_IRONMAN;
|
||||
case HARDCORE_IRONMAN:
|
||||
return HiscoreEndpoint.HARDCORE_IRONMAN;
|
||||
}
|
||||
}
|
||||
return HiscoreEndpoint.NORMAL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,17 +25,22 @@
|
||||
package net.runelite.client.plugins.hiscore;
|
||||
|
||||
import static net.runelite.client.plugins.hiscore.HiscorePanel.formatLevel;
|
||||
import net.runelite.http.api.hiscore.HiscoreEndpoint;
|
||||
import okhttp3.OkHttpClient;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.Test;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class HiscorePanelTest
|
||||
{
|
||||
@Test
|
||||
public void testConstructor()
|
||||
{
|
||||
new HiscorePanel(null, mock(HiscoreConfig.class), mock(NameAutocompleter.class), mock(OkHttpClient.class));
|
||||
HiscorePlugin plugin = mock(HiscorePlugin.class);
|
||||
when(plugin.getWorldEndpoint()).thenReturn(HiscoreEndpoint.NORMAL);
|
||||
new HiscorePanel(null, plugin, mock(HiscoreConfig.class),
|
||||
mock(NameAutocompleter.class), mock(OkHttpClient.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user