From 865bae6c2d30a7d9a0d94e76cd86175308b829c5 Mon Sep 17 00:00:00 2001 From: Tomas Slusny Date: Fri, 29 Jun 2018 11:45:12 +0200 Subject: [PATCH 1/2] Add ironman status and AccountType to API - Add ironman status varbit and account type to API Signed-off-by: Tomas Slusny --- .../java/net/runelite/api/AccountType.java | 120 ++++++++++++++++++ .../main/java/net/runelite/api/Varbits.java | 5 + 2 files changed, 125 insertions(+) create mode 100644 runelite-api/src/main/java/net/runelite/api/AccountType.java diff --git a/runelite-api/src/main/java/net/runelite/api/AccountType.java b/runelite-api/src/main/java/net/runelite/api/AccountType.java new file mode 100644 index 0000000000..1cf354ea05 --- /dev/null +++ b/runelite-api/src/main/java/net/runelite/api/AccountType.java @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2018, Tomas Slusny + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.api; + +import java.util.HashMap; +import java.util.Map; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +/** + * Account type of target player. + */ +@Getter +@RequiredArgsConstructor +public enum AccountType +{ + /** + * Normal account type. + */ + NORMAL(0, null), + /** + * Ironman account type. + */ + IRONMAN(1, 2), + /** + * Ultimate ironman account type. + */ + ULTIMATE_IRONMAN(2, 3), + /** + * Hardcore ironman account type. + */ + HARDCORE_IRONMAN(3, 10); + + private static final Map FROM_VARBIT = new HashMap<>(); + private static final Map FROM_ICON = new HashMap<>(); + + static + { + for (AccountType accountType : AccountType.values()) + { + FROM_VARBIT.put(accountType.getVarbit(), accountType); + + if (accountType.getIcon() != null) + { + FROM_ICON.put(accountType.getIcon(), accountType); + } + } + } + + private final int varbit; + private final Integer icon; + + /** + * Gets account type from IRONMAN_STATUS varbit value. + * + * @param varbitVal the varbit val + * @return the account type + */ + public static AccountType fromVarbit(final int varbitVal) + { + return FROM_VARBIT.get(varbitVal); + } + + /** + * Gets account type from un-sanitized player name. + * + * @param name the name + * @return the account type + */ + public static AccountType fromName(final String name) + { + if (name == null || !name.contains("")) + { + return accountType; + } + } + + return NORMAL; + } + + /** + * Gets account type from modicon. + * + * @param icon the icon + * @return the account type + */ + public static AccountType fromIcon(final int icon) + { + return FROM_ICON.get(icon); + } +} diff --git a/runelite-api/src/main/java/net/runelite/api/Varbits.java b/runelite-api/src/main/java/net/runelite/api/Varbits.java index 41fdef2104..69a0504bd0 100644 --- a/runelite-api/src/main/java/net/runelite/api/Varbits.java +++ b/runelite-api/src/main/java/net/runelite/api/Varbits.java @@ -57,6 +57,11 @@ public enum Varbits RUNE_POUCH_AMOUNT2(1625), RUNE_POUCH_AMOUNT3(1626), + /** + * Ironman status. See {@link AccountType} + */ + IRONMAN_STATUS(1777), + /** * Prayers */ From c56febc6f2e468619f83119ed19169116e975064 Mon Sep 17 00:00:00 2001 From: Gamer1120 Date: Fri, 29 Jun 2018 11:45:43 +0200 Subject: [PATCH 2/2] Fix hiscore lookup for ironman in chat commands Use correct ironman type when looking up hiscore with lvl/total commands. Fixes #1936 Signed-off-by: Tomas Slusny --- .../chatcommands/ChatCommandsPlugin.java | 61 ++++++++++++++++++- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java index de816ac5e8..824c199e57 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java @@ -33,11 +33,13 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.ScheduledExecutorService; import javax.inject.Inject; import lombok.extern.slf4j.Slf4j; +import net.runelite.api.AccountType; import net.runelite.api.ChatMessageType; import net.runelite.api.Client; import net.runelite.api.GameState; import net.runelite.api.ItemComposition; import net.runelite.api.MessageNode; +import net.runelite.api.Varbits; import net.runelite.api.events.SetMessage; import net.runelite.client.chat.ChatColorType; import net.runelite.client.chat.ChatMessageBuilder; @@ -50,6 +52,7 @@ import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.util.StackFormatter; import net.runelite.http.api.hiscore.HiscoreClient; import net.runelite.http.api.hiscore.HiscoreResult; +import net.runelite.http.api.hiscore.HiscoreEndpoint; import net.runelite.http.api.hiscore.HiscoreSkill; import net.runelite.http.api.hiscore.SingleHiscoreSkillResult; import net.runelite.http.api.hiscore.Skill; @@ -244,18 +247,31 @@ public class ChatCommandsPlugin extends Plugin private void playerSkillLookup(ChatMessageType type, SetMessage setMessage, String search) { search = SkillAbbreviations.getFullName(search); + final String player; + final HiscoreEndpoint ironmanStatus; - String player; if (type.equals(ChatMessageType.PRIVATE_MESSAGE_SENT)) { player = client.getLocalPlayer().getName(); + ironmanStatus = getIronmanStatusByVarbit(); } else { player = sanitize(setMessage.getName()); + + if (player.equals(client.getLocalPlayer().getName())) + { + // Get ironman btw status from varbit + ironmanStatus = getIronmanStatusByVarbit(); + } + else + { + // Get ironman btw status from their icon in chat + ironmanStatus = getIronmanStatusByName(setMessage.getName()); + } } - HiscoreSkill skill; + final HiscoreSkill skill; try { skill = HiscoreSkill.valueOf(search.toUpperCase()); @@ -267,7 +283,7 @@ public class ChatCommandsPlugin extends Plugin try { - SingleHiscoreSkillResult result = hiscoreClient.lookup(player, skill); + SingleHiscoreSkillResult result = hiscoreClient.lookup(player, skill, ironmanStatus); Skill hiscoreSkill = result.getSkill(); String response = new ChatMessageBuilder() @@ -411,4 +427,43 @@ public class ChatCommandsPlugin extends Plugin String cleaned = lookup.contains("') + 1) : lookup; return cleaned.replace('\u00A0', ' '); } + + /** + * Looks up the ironman status of the local player. Does NOT work on other players. + * @return hiscore endpoint + */ + private HiscoreEndpoint getIronmanStatusByVarbit() + { + return toEndPoint(AccountType.fromVarbit(client.getVarbitValue(client.getVarps(), Varbits.IRONMAN_STATUS.getId()))); + } + + /** + * Returns the ironman status based on the symbol in the name of the player. + * @param name player name + * @return hiscore endpoint + */ + private static HiscoreEndpoint getIronmanStatusByName(final String name) + { + return toEndPoint(AccountType.fromName(name)); + } + + /** + * Converts account type to hiscore endpoint + * @param accountType account type + * @return hiscore endpoint + */ + private static HiscoreEndpoint toEndPoint(final AccountType accountType) + { + switch (accountType) + { + case IRONMAN: + return HiscoreEndpoint.IRONMAN; + case ULTIMATE_IRONMAN: + return HiscoreEndpoint.ULTIMATE_IRONMAN; + case HARDCORE_IRONMAN: + return HiscoreEndpoint.HARDCORE_IRONMAN; + default: + return HiscoreEndpoint.NORMAL; + } + } }