Merge pull request #4167 from deathbeam/clues-respect-hiscore
Make !clues command respect account type
This commit is contained in:
@@ -34,6 +34,7 @@ import java.util.concurrent.ScheduledExecutorService;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import lombok.Value;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.runelite.api.ChatMessageType;
|
import net.runelite.api.ChatMessageType;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
@@ -165,7 +166,7 @@ public class ChatCommandsPlugin extends Plugin
|
|||||||
if (config.lvl() && message.toLowerCase().equals("!total"))
|
if (config.lvl() && message.toLowerCase().equals("!total"))
|
||||||
{
|
{
|
||||||
log.debug("Running total level lookup");
|
log.debug("Running total level lookup");
|
||||||
executor.submit(() -> playerSkillLookup(setMessage.getType(), setMessage, "total"));
|
executor.submit(() -> playerSkillLookup(setMessage, "total"));
|
||||||
}
|
}
|
||||||
else if (config.price() && message.toLowerCase().startsWith("!price") && message.length() > 7)
|
else if (config.price() && message.toLowerCase().startsWith("!price") && message.length() > 7)
|
||||||
{
|
{
|
||||||
@@ -179,19 +180,19 @@ public class ChatCommandsPlugin extends Plugin
|
|||||||
String search = message.substring(5);
|
String search = message.substring(5);
|
||||||
|
|
||||||
log.debug("Running level lookup for {}", search);
|
log.debug("Running level lookup for {}", search);
|
||||||
executor.submit(() -> playerSkillLookup(setMessage.getType(), setMessage, search));
|
executor.submit(() -> playerSkillLookup(setMessage, search));
|
||||||
}
|
}
|
||||||
else if (config.clue() && message.toLowerCase().equals("!clues"))
|
else if (config.clue() && message.toLowerCase().equals("!clues"))
|
||||||
{
|
{
|
||||||
log.debug("Running lookup for overall clues");
|
log.debug("Running lookup for overall clues");
|
||||||
executor.submit(() -> playerClueLookup(setMessage.getType(), setMessage, "total"));
|
executor.submit(() -> playerClueLookup(setMessage, "total"));
|
||||||
}
|
}
|
||||||
else if (config.clue() && message.toLowerCase().startsWith("!clues") && message.length() > 7)
|
else if (config.clue() && message.toLowerCase().startsWith("!clues") && message.length() > 7)
|
||||||
{
|
{
|
||||||
String search = message.substring(7);
|
String search = message.substring(7);
|
||||||
|
|
||||||
log.debug("Running clue lookup for {}", search);
|
log.debug("Running clue lookup for {}", search);
|
||||||
executor.submit(() -> playerClueLookup(setMessage.getType(), setMessage, search));
|
executor.submit(() -> playerClueLookup(setMessage, search));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -292,33 +293,9 @@ public class ChatCommandsPlugin extends Plugin
|
|||||||
* @param setMessage The chat message containing the command.
|
* @param setMessage The chat message containing the command.
|
||||||
* @param search The item given with the command.
|
* @param search The item given with the command.
|
||||||
*/
|
*/
|
||||||
private void playerSkillLookup(ChatMessageType type, SetMessage setMessage, String search)
|
private void playerSkillLookup(SetMessage setMessage, String search)
|
||||||
{
|
{
|
||||||
search = SkillAbbreviations.getFullName(search);
|
search = SkillAbbreviations.getFullName(search);
|
||||||
final String player;
|
|
||||||
final HiscoreEndpoint ironmanStatus;
|
|
||||||
|
|
||||||
if (type.equals(ChatMessageType.PRIVATE_MESSAGE_SENT))
|
|
||||||
{
|
|
||||||
player = client.getLocalPlayer().getName();
|
|
||||||
ironmanStatus = getHiscoreEndpointType();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
player = sanitize(setMessage.getName());
|
|
||||||
|
|
||||||
if (player.equals(client.getLocalPlayer().getName()))
|
|
||||||
{
|
|
||||||
// Get ironman status from for the local player
|
|
||||||
ironmanStatus = getHiscoreEndpointType();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Get ironman status from their icon in chat
|
|
||||||
ironmanStatus = getHiscoreEndpointByName(setMessage.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final HiscoreSkill skill;
|
final HiscoreSkill skill;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -329,12 +306,14 @@ public class ChatCommandsPlugin extends Plugin
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final HiscoreLookup lookup = getCorrectLookupFor(setMessage);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SingleHiscoreSkillResult result = hiscoreClient.lookup(player, skill, ironmanStatus);
|
final SingleHiscoreSkillResult result = hiscoreClient.lookup(lookup.getName(), skill, lookup.getEndpoint());
|
||||||
Skill hiscoreSkill = result.getSkill();
|
final Skill hiscoreSkill = result.getSkill();
|
||||||
|
|
||||||
String response = new ChatMessageBuilder()
|
final String response = new ChatMessageBuilder()
|
||||||
.append(ChatColorType.NORMAL)
|
.append(ChatColorType.NORMAL)
|
||||||
.append("Level ")
|
.append("Level ")
|
||||||
.append(ChatColorType.HIGHLIGHT)
|
.append(ChatColorType.HIGHLIGHT)
|
||||||
@@ -366,22 +345,14 @@ public class ChatCommandsPlugin extends Plugin
|
|||||||
* for the requested clue-level (no arg if requesting total)
|
* for the requested clue-level (no arg if requesting total)
|
||||||
* easy, medium, hard, elite, master
|
* easy, medium, hard, elite, master
|
||||||
*/
|
*/
|
||||||
private void playerClueLookup(ChatMessageType type, SetMessage setMessage, String search)
|
private void playerClueLookup(SetMessage setMessage, String search)
|
||||||
{
|
{
|
||||||
String player;
|
final HiscoreLookup lookup = getCorrectLookupFor(setMessage);
|
||||||
if (type.equals(ChatMessageType.PRIVATE_MESSAGE_SENT))
|
|
||||||
{
|
|
||||||
player = client.getLocalPlayer().getName();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
player = sanitize(setMessage.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Skill hiscoreSkill;
|
final Skill hiscoreSkill;
|
||||||
HiscoreResult result = hiscoreClient.lookup(player);
|
final HiscoreResult result = hiscoreClient.lookup(lookup.getName(), lookup.getEndpoint());
|
||||||
String level = search.toLowerCase();
|
String level = search.toLowerCase();
|
||||||
|
|
||||||
switch (level)
|
switch (level)
|
||||||
@@ -442,6 +413,40 @@ public class ChatCommandsPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets correct lookup data for message
|
||||||
|
* @param setMessage chat message
|
||||||
|
* @return hiscore lookup data
|
||||||
|
*/
|
||||||
|
private HiscoreLookup getCorrectLookupFor(final SetMessage setMessage)
|
||||||
|
{
|
||||||
|
final String player;
|
||||||
|
final HiscoreEndpoint ironmanStatus;
|
||||||
|
|
||||||
|
if (setMessage.getType().equals(ChatMessageType.PRIVATE_MESSAGE_SENT))
|
||||||
|
{
|
||||||
|
player = client.getLocalPlayer().getName();
|
||||||
|
ironmanStatus = getHiscoreEndpointType();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
player = sanitize(setMessage.getName());
|
||||||
|
|
||||||
|
if (player.equals(client.getLocalPlayer().getName()))
|
||||||
|
{
|
||||||
|
// Get ironman status from for the local player
|
||||||
|
ironmanStatus = getHiscoreEndpointType();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Get ironman status from their icon in chat
|
||||||
|
ironmanStatus = getHiscoreEndpointByName(setMessage.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new HiscoreLookup(player, ironmanStatus);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compares the names of the items in the list with the original input.
|
* Compares the names of the items in the list with the original input.
|
||||||
* Returns the item if its name is equal to the original input or null
|
* Returns the item if its name is equal to the original input or null
|
||||||
@@ -529,4 +534,11 @@ public class ChatCommandsPlugin extends Plugin
|
|||||||
return HiscoreEndpoint.NORMAL;
|
return HiscoreEndpoint.NORMAL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Value
|
||||||
|
private static class HiscoreLookup
|
||||||
|
{
|
||||||
|
private final String name;
|
||||||
|
private final HiscoreEndpoint endpoint;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user