chatcommands: fix showing -1 experience/rank in lvl
This commit is contained in:
@@ -55,8 +55,8 @@ import net.runelite.api.events.WidgetLoaded;
|
||||
import net.runelite.api.vars.AccountType;
|
||||
import net.runelite.api.widgets.Widget;
|
||||
import static net.runelite.api.widgets.WidgetID.ADVENTURE_LOG_ID;
|
||||
import static net.runelite.api.widgets.WidgetID.KILL_LOGS_GROUP_ID;
|
||||
import static net.runelite.api.widgets.WidgetID.COUNTERS_LOG_GROUP_ID;
|
||||
import static net.runelite.api.widgets.WidgetID.KILL_LOGS_GROUP_ID;
|
||||
import net.runelite.api.widgets.WidgetInfo;
|
||||
import net.runelite.client.chat.ChatColorType;
|
||||
import net.runelite.client.chat.ChatCommandManager;
|
||||
@@ -119,7 +119,6 @@ public class ChatCommandsPlugin extends Plugin
|
||||
@VisibleForTesting
|
||||
static final int ADV_LOG_EXPLOITS_TEXT_INDEX = 1;
|
||||
|
||||
private final HiscoreClient hiscoreClient = new HiscoreClient();
|
||||
private final ChatClient chatClient = new ChatClient();
|
||||
|
||||
private boolean bossLogLoaded;
|
||||
@@ -157,6 +156,9 @@ public class ChatCommandsPlugin extends Plugin
|
||||
@Inject
|
||||
private ChatKeyboardListener chatKeyboardListener;
|
||||
|
||||
@Inject
|
||||
private HiscoreClient hiscoreClient;
|
||||
|
||||
@Override
|
||||
public void startUp()
|
||||
{
|
||||
@@ -1005,21 +1007,27 @@ public class ChatCommandsPlugin extends Plugin
|
||||
|
||||
final Skill hiscoreSkill = result.getSkill();
|
||||
|
||||
final String response = new ChatMessageBuilder()
|
||||
ChatMessageBuilder chatMessageBuilder = new ChatMessageBuilder()
|
||||
.append(ChatColorType.NORMAL)
|
||||
.append("Level ")
|
||||
.append(ChatColorType.HIGHLIGHT)
|
||||
.append(skill.getName()).append(": ").append(String.valueOf(hiscoreSkill.getLevel()))
|
||||
.append(ChatColorType.NORMAL)
|
||||
.append(" Experience: ")
|
||||
.append(ChatColorType.HIGHLIGHT)
|
||||
.append(String.format("%,d", hiscoreSkill.getExperience()))
|
||||
.append(ChatColorType.NORMAL)
|
||||
.append(" Rank: ")
|
||||
.append(ChatColorType.HIGHLIGHT)
|
||||
.append(String.format("%,d", hiscoreSkill.getRank()))
|
||||
.build();
|
||||
.append(ChatColorType.NORMAL);
|
||||
if (hiscoreSkill.getExperience() != -1)
|
||||
{
|
||||
chatMessageBuilder.append(" Experience: ")
|
||||
.append(ChatColorType.HIGHLIGHT)
|
||||
.append(String.format("%,d", hiscoreSkill.getExperience()))
|
||||
.append(ChatColorType.NORMAL);
|
||||
}
|
||||
if (hiscoreSkill.getRank() != -1)
|
||||
{
|
||||
chatMessageBuilder.append(" Rank: ")
|
||||
.append(ChatColorType.HIGHLIGHT)
|
||||
.append(String.format("%,d", hiscoreSkill.getRank()));
|
||||
}
|
||||
|
||||
final String response = chatMessageBuilder.build();
|
||||
log.debug("Setting response {}", response);
|
||||
final MessageNode messageNode = chatMessage.getMessageNode();
|
||||
messageNode.setRuneLiteFormatMessage(response);
|
||||
|
||||
@@ -27,32 +27,44 @@ package net.runelite.client.plugins.chatcommands;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.testing.fieldbinder.Bind;
|
||||
import com.google.inject.testing.fieldbinder.BoundFieldModule;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.function.BiConsumer;
|
||||
import javax.inject.Inject;
|
||||
import net.runelite.api.ChatMessageType;
|
||||
import static net.runelite.api.ChatMessageType.FRIENDSCHATNOTIFICATION;
|
||||
import static net.runelite.api.ChatMessageType.GAMEMESSAGE;
|
||||
import static net.runelite.api.ChatMessageType.TRADE;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.MessageNode;
|
||||
import net.runelite.api.Player;
|
||||
import net.runelite.api.events.ChatMessage;
|
||||
import net.runelite.api.events.GameTick;
|
||||
import net.runelite.api.events.WidgetLoaded;
|
||||
import net.runelite.api.widgets.Widget;
|
||||
import net.runelite.api.widgets.WidgetInfo;
|
||||
import net.runelite.client.config.ChatColorConfig;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import static net.runelite.api.widgets.WidgetID.ADVENTURE_LOG_ID;
|
||||
import static net.runelite.api.widgets.WidgetID.COUNTERS_LOG_GROUP_ID;
|
||||
import net.runelite.api.widgets.WidgetInfo;
|
||||
import net.runelite.client.chat.ChatCommandManager;
|
||||
import net.runelite.client.chat.ChatMessageManager;
|
||||
import net.runelite.client.config.ChatColorConfig;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.http.api.hiscore.HiscoreClient;
|
||||
import net.runelite.http.api.hiscore.HiscoreSkill;
|
||||
import net.runelite.http.api.hiscore.SingleHiscoreSkillResult;
|
||||
import net.runelite.http.api.hiscore.Skill;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import org.mockito.Mock;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.anyInt;
|
||||
import static org.mockito.Mockito.anyString;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -79,6 +91,18 @@ public class ChatCommandsPluginTest
|
||||
@Bind
|
||||
ChatColorConfig chatColorConfig;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
ChatCommandManager chatCommandManager;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
HiscoreClient hiscoreClient;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
ChatMessageManager chatMessageManager;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
ChatCommandsConfig chatCommandsConfig;
|
||||
@@ -92,6 +116,14 @@ public class ChatCommandsPluginTest
|
||||
Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
|
||||
|
||||
when(client.getUsername()).thenReturn(PLAYER_NAME);
|
||||
|
||||
chatCommandsPlugin.startUp();
|
||||
}
|
||||
|
||||
@After
|
||||
public void after()
|
||||
{
|
||||
chatCommandsPlugin.shutDown();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -380,22 +412,22 @@ public class ChatCommandsPluginTest
|
||||
chatCommandsPlugin.onGameTick(new GameTick());
|
||||
|
||||
String COUNTER_TEXT = "Duel Arena<br>Wins: <col=d0c0b0>4</col><br>Losses: <col=d0c0b0>2</col>" +
|
||||
"<br><br>Last Man Standing<br>Rank: <col=d0c0b0>0</col>" +
|
||||
"<br><br>Treasure Trails<br>Beginner: <col=d0c0b0>0</col><br>Easy: <col=d0c0b0>7</col>" +
|
||||
"<br>Medium: <col=d0c0b0>28</col><br>Hard: <col=d0c0b0>108</col><br>Elite: <col=d0c0b0>15</col>" +
|
||||
"<br>Master: <col=d0c0b0>27</col><br>Rank: <col=d0c0b0>Novice</col>" +
|
||||
"<br><br>Chompy Hunting<br>Kills: <col=d0c0b0>1,000</col><br>Rank: <col=d0c0b0>Ogre Expert</col>" +
|
||||
"<br><br>Order of the White Knights<br>Rank: <col=d0c0b0>Master</col><br>with a kill score of <col=d0c0b0>1,300</col>" +
|
||||
"<br><br>TzHaar Fight Cave<br>Fastest run: <col=d0c0b0>38:10</col>" +
|
||||
"<br><br>Inferno<br>Fastest run: <col=d0c0b0>-</col><br><br>Zulrah<br>" +
|
||||
"Fastest kill: <col=d0c0b0>5:48</col><br><br>Vorkath<br>Fastest kill: <col=d0c0b0>1:21</col>" +
|
||||
"<br><br>Galvek<br>Fastest kill: <col=d0c0b0>-</col><br><br>Grotesque Guardians<br>" +
|
||||
"Fastest kill: <col=d0c0b0>2:49</col><br><br>Alchemical Hydra<br>Fastest kill: <col=d0c0b0>-</col>" +
|
||||
"<br><br>Hespori<br>Fastest kill: <col=d0c0b0>0:57</col><br><br>Nightmare<br>" +
|
||||
"Fastest kill: <col=d0c0b0>3:30</col><br><br>The Gauntlet<br>Fastest run: <col=d0c0b0>-</col>" +
|
||||
"<br><br>The Corrupted Gauntlet<br>Fastest run: <col=d0c0b0>-</col><br><br>Fragment of Seren<br>" +
|
||||
"Fastest kill: <col=d0c0b0>-</col><br><br>Barbarian Assault<br>High-level gambles: " +
|
||||
"<col=d0c0b0>15</col><br><br>Fremennik spirits rested: <col=d0c0b0>0</col>";
|
||||
"<br><br>Last Man Standing<br>Rank: <col=d0c0b0>0</col>" +
|
||||
"<br><br>Treasure Trails<br>Beginner: <col=d0c0b0>0</col><br>Easy: <col=d0c0b0>7</col>" +
|
||||
"<br>Medium: <col=d0c0b0>28</col><br>Hard: <col=d0c0b0>108</col><br>Elite: <col=d0c0b0>15</col>" +
|
||||
"<br>Master: <col=d0c0b0>27</col><br>Rank: <col=d0c0b0>Novice</col>" +
|
||||
"<br><br>Chompy Hunting<br>Kills: <col=d0c0b0>1,000</col><br>Rank: <col=d0c0b0>Ogre Expert</col>" +
|
||||
"<br><br>Order of the White Knights<br>Rank: <col=d0c0b0>Master</col><br>with a kill score of <col=d0c0b0>1,300</col>" +
|
||||
"<br><br>TzHaar Fight Cave<br>Fastest run: <col=d0c0b0>38:10</col>" +
|
||||
"<br><br>Inferno<br>Fastest run: <col=d0c0b0>-</col><br><br>Zulrah<br>" +
|
||||
"Fastest kill: <col=d0c0b0>5:48</col><br><br>Vorkath<br>Fastest kill: <col=d0c0b0>1:21</col>" +
|
||||
"<br><br>Galvek<br>Fastest kill: <col=d0c0b0>-</col><br><br>Grotesque Guardians<br>" +
|
||||
"Fastest kill: <col=d0c0b0>2:49</col><br><br>Alchemical Hydra<br>Fastest kill: <col=d0c0b0>-</col>" +
|
||||
"<br><br>Hespori<br>Fastest kill: <col=d0c0b0>0:57</col><br><br>Nightmare<br>" +
|
||||
"Fastest kill: <col=d0c0b0>3:30</col><br><br>The Gauntlet<br>Fastest run: <col=d0c0b0>-</col>" +
|
||||
"<br><br>The Corrupted Gauntlet<br>Fastest run: <col=d0c0b0>-</col><br><br>Fragment of Seren<br>" +
|
||||
"Fastest kill: <col=d0c0b0>-</col><br><br>Barbarian Assault<br>High-level gambles: " +
|
||||
"<col=d0c0b0>15</col><br><br>Fremennik spirits rested: <col=d0c0b0>0</col>";
|
||||
|
||||
Widget countersPage = mock(Widget.class);
|
||||
when(countersPage.getText()).thenReturn(COUNTER_TEXT);
|
||||
@@ -411,7 +443,7 @@ public class ChatCommandsPluginTest
|
||||
verify(configManager).setConfiguration(eq("personalbest.adam"), eq("vorkath"), eq(1 * 60 + 21));
|
||||
verify(configManager).setConfiguration(eq("personalbest.adam"), eq("grotesque guardians"), eq(2 * 60 + 49));
|
||||
verify(configManager).setConfiguration(eq("personalbest.adam"), eq("hespori"), eq(57));
|
||||
verify(configManager).setConfiguration(eq("personalbest.adam"), eq("nightmare"), eq( 3 * 60 + 30));
|
||||
verify(configManager).setConfiguration(eq("personalbest.adam"), eq("nightmare"), eq(3 * 60 + 30));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -490,4 +522,33 @@ public class ChatCommandsPluginTest
|
||||
|
||||
verifyNoMoreInteractions(configManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPlayerSkillLookup() throws IOException
|
||||
{
|
||||
Player player = mock(Player.class);
|
||||
when(player.getName()).thenReturn(PLAYER_NAME);
|
||||
when(client.getLocalPlayer()).thenReturn(player);
|
||||
|
||||
when(chatCommandsConfig.lvl()).thenReturn(true);
|
||||
ArgumentCaptor<BiConsumer<ChatMessage, String>> captor = ArgumentCaptor.forClass(BiConsumer.class);
|
||||
verify(chatCommandManager).registerCommandAsync(eq("!lvl"), captor.capture());
|
||||
BiConsumer<ChatMessage, String> value = captor.getValue();
|
||||
|
||||
SingleHiscoreSkillResult skillResult = new SingleHiscoreSkillResult();
|
||||
skillResult.setPlayer(PLAYER_NAME);
|
||||
skillResult.setSkill(new Skill(10, 1000, -1));
|
||||
|
||||
when(hiscoreClient.lookup(PLAYER_NAME, HiscoreSkill.ZULRAH, null)).thenReturn(skillResult);
|
||||
|
||||
MessageNode messageNode = mock(MessageNode.class);
|
||||
|
||||
ChatMessage chatMessage = new ChatMessage();
|
||||
chatMessage.setType(ChatMessageType.PUBLICCHAT);
|
||||
chatMessage.setName(PLAYER_NAME);
|
||||
chatMessage.setMessageNode(messageNode);
|
||||
value.accept(chatMessage, "!lvl zulrah");
|
||||
|
||||
verify(messageNode).setRuneLiteFormatMessage("<colNORMAL>Level <colHIGHLIGHT>Zulrah: 1000<colNORMAL> Rank: <colHIGHLIGHT>10");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user