Java Code Examples for net.runelite.api.events.ChatMessage#getMessageNode()
The following examples show how to use
net.runelite.api.events.ChatMessage#getMessageNode() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SlayerPlugin.java From plugins with GNU General Public License v3.0 | 6 votes |
private void pointsLookup(ChatMessage chatMessage, String message) { if (!config.pointsCommand()) { return; } String response = new ChatMessageBuilder() .append(ChatColorType.NORMAL) .append("Slayer Points: ") .append(ChatColorType.HIGHLIGHT) .append(Integer.toString(getPoints())) .build(); final MessageNode messageNode = chatMessage.getMessageNode(); messageNode.setRuneLiteFormatMessage(response); chatMessageManager.update(messageNode); client.refreshChat(); }
Example 2
Source File: BronzeManPlugin.java From plugins with GNU General Public License v3.0 | 6 votes |
private void countItems(ChatMessage chatMessage, String s) { if (!config.countCommand()) { return; } MessageNode messageNode = chatMessage.getMessageNode(); if (!Text.sanitize(messageNode.getName()).equals(Text.sanitize(client.getLocalPlayer().getName()))) { return; } final ChatMessageBuilder builder = new ChatMessageBuilder() .append(ChatColorType.NORMAL) .append("I have unlocked " + Integer.toString(unlockedItems.size()) + " items.") .append(ChatColorType.HIGHLIGHT); String response = builder.build(); messageNode.setRuneLiteFormatMessage(response); chatMessageManager.update(messageNode); client.refreshChat(); }
Example 3
Source File: LeagueChatIconsPlugin.java From runelite with BSD 2-Clause "Simplified" License | 6 votes |
/** * Adds the League Icon in front of player names chatting from a league world. * * @param chatMessage chat message to edit sender name on */ private void addLeagueIconToMessage(ChatMessage chatMessage) { String name = chatMessage.getName(); if (!name.startsWith(IRONMAN_PREFIX)) { // don't replace non-ironman icons, like mods return; } name = Text.removeTags(name); final MessageNode messageNode = chatMessage.getMessageNode(); messageNode.setName(getNameWithIcon(leagueIconOffset, name)); chatMessageManager.update(messageNode); client.refreshChat(); }
Example 4
Source File: ChatFilterPlugin.java From runelite with BSD 2-Clause "Simplified" License | 6 votes |
@Subscribe(priority = -2) // run after ChatMessageManager public void onChatMessage(ChatMessage chatMessage) { if (COLLAPSIBLE_MESSAGETYPES.contains(chatMessage.getType())) { final MessageNode messageNode = chatMessage.getMessageNode(); // remove and re-insert into map to move to end of list final String key = messageNode.getName() + ":" + messageNode.getValue(); Duplicate duplicate = duplicateChatCache.remove(key); if (duplicate == null) { duplicate = new Duplicate(); } duplicate.count++; duplicate.messageId = messageNode.getId(); duplicateChatCache.put(key, duplicate); } }
Example 5
Source File: BronzeManPlugin.java From plugins with GNU General Public License v3.0 | 5 votes |
private void AddIconToMessage(ChatMessage chatMessage) { String name = chatMessage.getName(); if (!name.equals(Text.removeTags(name))) { return; } final MessageNode messageNode = chatMessage.getMessageNode(); messageNode.setName(setupBronzeManName(iconOffset, name)); chatMessageManager.update(messageNode); client.refreshChat(); }
Example 6
Source File: EmojiPlugin.java From runelite with BSD 2-Clause "Simplified" License | 5 votes |
@Subscribe public void onChatMessage(ChatMessage chatMessage) { if (client.getGameState() != GameState.LOGGED_IN || modIconsStart == -1) { return; } switch (chatMessage.getType()) { case PUBLICCHAT: case MODCHAT: case FRIENDSCHAT: case PRIVATECHAT: case PRIVATECHATOUT: case MODPRIVATECHAT: break; default: return; } final MessageNode messageNode = chatMessage.getMessageNode(); final String message = messageNode.getValue(); final String updatedMessage = updateMessage(message); if (updatedMessage == null) { return; } messageNode.setRuneLiteFormatMessage(updatedMessage); chatMessageManager.update(messageNode); client.refreshChat(); }
Example 7
Source File: EmojiPlugin.java From plugins with GNU General Public License v3.0 | 5 votes |
@Subscribe void onChatMessage(ChatMessage chatMessage) { if (client.getGameState() != GameState.LOGGED_IN || modIconsStart == -1) { return; } switch (chatMessage.getType()) { case PUBLICCHAT: case MODCHAT: case FRIENDSCHAT: case PRIVATECHAT: case PRIVATECHATOUT: case MODPRIVATECHAT: break; default: return; } final MessageNode messageNode = chatMessage.getMessageNode(); final String message = messageNode.getValue(); final String updatedMessage = updateMessage(message); if (updatedMessage == null) { return; } messageNode.setRuneLiteFormatMessage(updatedMessage); chatMessageManager.update(messageNode); client.refreshChat(); }
Example 8
Source File: ChatCommandsPlugin.java From runelite with BSD 2-Clause "Simplified" License | 4 votes |
private void minigameLookup(ChatMessage chatMessage, HiscoreSkill minigame) { try { final Skill hiscoreSkill; final HiscoreLookup lookup = getCorrectLookupFor(chatMessage); final HiscoreResult result = hiscoreClient.lookup(lookup.getName(), lookup.getEndpoint()); if (result == null) { log.warn("error looking up {} score: not found", minigame.getName().toLowerCase()); return; } switch (minigame) { case BOUNTY_HUNTER_HUNTER: hiscoreSkill = result.getBountyHunterHunter(); break; case BOUNTY_HUNTER_ROGUE: hiscoreSkill = result.getBountyHunterRogue(); break; case LAST_MAN_STANDING: hiscoreSkill = result.getLastManStanding(); break; default: log.warn("error looking up {} score: not implemented", minigame.getName().toLowerCase()); return; } int score = hiscoreSkill.getLevel(); if (score == -1) { return; } ChatMessageBuilder chatMessageBuilder = new ChatMessageBuilder() .append(ChatColorType.NORMAL) .append(minigame.getName()) .append(" Score: ") .append(ChatColorType.HIGHLIGHT) .append(Integer.toString(score)); int rank = hiscoreSkill.getRank(); if (rank != -1) { chatMessageBuilder.append(ChatColorType.NORMAL) .append(" Rank: ") .append(ChatColorType.HIGHLIGHT) .append(String.format("%,d", rank)); } String response = chatMessageBuilder.build(); log.debug("Setting response {}", response); final MessageNode messageNode = chatMessage.getMessageNode(); messageNode.setRuneLiteFormatMessage(response); chatMessageManager.update(messageNode); client.refreshChat(); } catch (IOException ex) { log.warn("error looking up {}", minigame.getName().toLowerCase(), ex); } }
Example 9
Source File: SlayerPlugin.java From plugins with GNU General Public License v3.0 | 4 votes |
void taskLookup(ChatMessage chatMessage, String message) { if (!config.taskCommand()) { return; } ChatMessageType type = chatMessage.getType(); final String player; if (type.equals(ChatMessageType.PRIVATECHATOUT)) { player = client.getLocalPlayer().getName(); } else { player = Text.removeTags(chatMessage.getName()) .replace('\u00A0', ' '); } net.runelite.http.api.chat.Task task; try { task = chatClient.getTask(player); } catch (IOException ex) { log.debug("unable to lookup slayer task", ex); return; } if (task == null) { return; } if (TASK_STRING_VALIDATION.matcher(task.getTask()).find() || task.getTask().length() > TASK_STRING_MAX_LENGTH || TASK_STRING_VALIDATION.matcher(task.getLocation()).find() || task.getLocation().length() > TASK_STRING_MAX_LENGTH || Task.getTask(task.getTask()) == null || !Task.LOCATIONS.contains(task.getLocation())) { log.debug("Validation failed for task name or location: {}", task); return; } int killed = task.getInitialAmount() - task.getAmount(); StringBuilder sb = new StringBuilder(); sb.append(task.getTask()); if (!Strings.isNullOrEmpty(task.getLocation())) { sb.append(" (").append(task.getLocation()).append(")"); } sb.append(": "); if (killed < 0) { sb.append(task.getAmount()).append(" left"); } else { sb.append(killed).append('/').append(task.getInitialAmount()).append(" killed"); } String response = new ChatMessageBuilder() .append(ChatColorType.NORMAL) .append("Slayer Task: ") .append(ChatColorType.HIGHLIGHT) .append(sb.toString()) .build(); final MessageNode messageNode = chatMessage.getMessageNode(); messageNode.setRuneLiteFormatMessage(response); chatMessageManager.update(messageNode); client.refreshChat(); }
Example 10
Source File: ChatCommandsPlugin.java From runelite with BSD 2-Clause "Simplified" License | 4 votes |
private void combatLevelLookup(ChatMessage chatMessage, String message) { if (!config.lvl()) { return; } ChatMessageType type = chatMessage.getType(); String player; if (type == ChatMessageType.PRIVATECHATOUT) { player = client.getLocalPlayer().getName(); } else { player = Text.sanitize(chatMessage.getName()); } try { HiscoreResult playerStats = hiscoreClient.lookup(player); if (playerStats == null) { log.warn("Error fetching hiscore data: not found"); return; } int attack = playerStats.getAttack().getLevel(); int strength = playerStats.getStrength().getLevel(); int defence = playerStats.getDefence().getLevel(); int hitpoints = playerStats.getHitpoints().getLevel(); int ranged = playerStats.getRanged().getLevel(); int prayer = playerStats.getPrayer().getLevel(); int magic = playerStats.getMagic().getLevel(); int combatLevel = Experience.getCombatLevel(attack, strength, defence, hitpoints, magic, ranged, prayer); String response = new ChatMessageBuilder() .append(ChatColorType.NORMAL) .append("Combat Level: ") .append(ChatColorType.HIGHLIGHT) .append(String.valueOf(combatLevel)) .append(ChatColorType.NORMAL) .append(" A: ") .append(ChatColorType.HIGHLIGHT) .append(String.valueOf(attack)) .append(ChatColorType.NORMAL) .append(" S: ") .append(ChatColorType.HIGHLIGHT) .append(String.valueOf(strength)) .append(ChatColorType.NORMAL) .append(" D: ") .append(ChatColorType.HIGHLIGHT) .append(String.valueOf(defence)) .append(ChatColorType.NORMAL) .append(" H: ") .append(ChatColorType.HIGHLIGHT) .append(String.valueOf(hitpoints)) .append(ChatColorType.NORMAL) .append(" R: ") .append(ChatColorType.HIGHLIGHT) .append(String.valueOf(ranged)) .append(ChatColorType.NORMAL) .append(" P: ") .append(ChatColorType.HIGHLIGHT) .append(String.valueOf(prayer)) .append(ChatColorType.NORMAL) .append(" M: ") .append(ChatColorType.HIGHLIGHT) .append(String.valueOf(magic)) .build(); log.debug("Setting response {}", response); final MessageNode messageNode = chatMessage.getMessageNode(); messageNode.setRuneLiteFormatMessage(response); chatMessageManager.update(messageNode); client.refreshChat(); } catch (IOException ex) { log.warn("Error fetching hiscore data", ex); } }
Example 11
Source File: ChatCommandsPlugin.java From runelite with BSD 2-Clause "Simplified" License | 4 votes |
/** * Looks up the player skill and changes the original message to the * response. * * @param chatMessage The chat message containing the command. * @param message The chat message */ private void playerSkillLookup(ChatMessage chatMessage, String message) { if (!config.lvl()) { return; } String search; if (message.equalsIgnoreCase(TOTAL_LEVEL_COMMAND_STRING)) { search = "total"; } else { if (message.length() <= LEVEL_COMMAND_STRING.length()) { return; } search = message.substring(LEVEL_COMMAND_STRING.length() + 1); } search = SkillAbbreviations.getFullName(search); final HiscoreSkill skill; try { skill = HiscoreSkill.valueOf(search.toUpperCase()); } catch (IllegalArgumentException i) { return; } final HiscoreLookup lookup = getCorrectLookupFor(chatMessage); try { final SingleHiscoreSkillResult result = hiscoreClient.lookup(lookup.getName(), skill, lookup.getEndpoint()); if (result == null) { log.warn("unable to look up skill {} for {}: not found", skill, search); return; } final Skill hiscoreSkill = result.getSkill(); ChatMessageBuilder chatMessageBuilder = new ChatMessageBuilder() .append(ChatColorType.NORMAL) .append("Level ") .append(ChatColorType.HIGHLIGHT) .append(skill.getName()).append(": ").append(String.valueOf(hiscoreSkill.getLevel())) .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); chatMessageManager.update(messageNode); client.refreshChat(); } catch (IOException ex) { log.warn("unable to look up skill {} for {}", skill, search, ex); } }
Example 12
Source File: ChatCommandsPlugin.java From runelite with BSD 2-Clause "Simplified" License | 4 votes |
/** * Looks up the item price and changes the original message to the * response. * * @param chatMessage The chat message containing the command. * @param message The chat message */ private void itemPriceLookup(ChatMessage chatMessage, String message) { if (!config.price()) { return; } if (message.length() <= PRICE_COMMAND_STRING.length()) { return; } MessageNode messageNode = chatMessage.getMessageNode(); String search = message.substring(PRICE_COMMAND_STRING.length() + 1); List<ItemPrice> results = itemManager.search(search); if (!results.isEmpty()) { ItemPrice item = retrieveFromList(results, search); int itemId = item.getId(); int itemPrice = item.getPrice(); final ChatMessageBuilder builder = new ChatMessageBuilder() .append(ChatColorType.NORMAL) .append("Price of ") .append(ChatColorType.HIGHLIGHT) .append(item.getName()) .append(ChatColorType.NORMAL) .append(": GE average ") .append(ChatColorType.HIGHLIGHT) .append(QuantityFormatter.formatNumber(itemPrice)); ItemComposition itemComposition = itemManager.getItemComposition(itemId); final int alchPrice = itemComposition.getHaPrice(); builder .append(ChatColorType.NORMAL) .append(" HA value ") .append(ChatColorType.HIGHLIGHT) .append(QuantityFormatter.formatNumber(alchPrice)); String response = builder.build(); log.debug("Setting response {}", response); messageNode.setRuneLiteFormatMessage(response); chatMessageManager.update(messageNode); client.refreshChat(); } }
Example 13
Source File: SlayerPlugin.java From runelite with BSD 2-Clause "Simplified" License | 4 votes |
void taskLookup(ChatMessage chatMessage, String message) { if (!config.taskCommand()) { return; } ChatMessageType type = chatMessage.getType(); final String player; if (type.equals(ChatMessageType.PRIVATECHATOUT)) { player = client.getLocalPlayer().getName(); } else { player = Text.removeTags(chatMessage.getName()) .replace('\u00A0', ' '); } net.runelite.http.api.chat.Task task; try { task = chatClient.getTask(player); } catch (IOException ex) { log.debug("unable to lookup slayer task", ex); return; } if (TASK_STRING_VALIDATION.matcher(task.getTask()).find() || task.getTask().length() > TASK_STRING_MAX_LENGTH || TASK_STRING_VALIDATION.matcher(task.getLocation()).find() || task.getLocation().length() > TASK_STRING_MAX_LENGTH || Task.getTask(task.getTask()) == null || !Task.LOCATIONS.contains(task.getLocation())) { log.debug("Validation failed for task name or location: {}", task); return; } int killed = task.getInitialAmount() - task.getAmount(); StringBuilder sb = new StringBuilder(); sb.append(task.getTask()); if (!Strings.isNullOrEmpty(task.getLocation())) { sb.append(" (").append(task.getLocation()).append(")"); } sb.append(": "); if (killed < 0) { sb.append(task.getAmount()).append(" left"); } else { sb.append(killed).append('/').append(task.getInitialAmount()).append(" killed"); } String response = new ChatMessageBuilder() .append(ChatColorType.NORMAL) .append("Slayer Task: ") .append(ChatColorType.HIGHLIGHT) .append(sb.toString()) .build(); final MessageNode messageNode = chatMessage.getMessageNode(); messageNode.setRuneLiteFormatMessage(response); chatMessageManager.update(messageNode); client.refreshChat(); }
Example 14
Source File: ChatMessageManager.java From runelite with BSD 2-Clause "Simplified" License | 4 votes |
@Subscribe(priority = -1) // run after all plugins public void onChatMessage(ChatMessage chatMessage) { MessageNode messageNode = chatMessage.getMessageNode(); ChatMessageType chatMessageType = chatMessage.getType(); boolean isChatboxTransparent = client.isResized() && client.getVar(Varbits.TRANSPARENT_CHATBOX) == 1; Color usernameColor = null; Color senderColor = null; switch (chatMessageType) { // username recoloring for MODPRIVATECHAT, PRIVATECHAT and PRIVATECHATOUT // ChatMessageTypes is handled in the script callback event case TRADEREQ: case AUTOTYPER: case PUBLICCHAT: case MODCHAT: { boolean isFriend = client.isFriended(chatMessage.getName(), true) && !client.getLocalPlayer().getName().equals(chatMessage.getName()); if (isFriend) { usernameColor = isChatboxTransparent ? chatColorConfig.transparentPublicFriendUsernames() : chatColorConfig.opaquePublicFriendUsernames(); } if (usernameColor == null) { usernameColor = isChatboxTransparent ? chatColorConfig.transparentUsername() : chatColorConfig.opaqueUsername(); } break; } case FRIENDSCHAT: usernameColor = isChatboxTransparent ? chatColorConfig.transparentFriendsChatUsernames() : chatColorConfig.opaqueFriendsChatUsernames(); break; } senderColor = isChatboxTransparent ? chatColorConfig.transparentFriendsChatChannelName() : chatColorConfig.opaqueFriendsChatChannelName(); if (usernameColor != null) { messageNode.setName(ColorUtil.wrapWithColorTag(messageNode.getName(), usernameColor)); } String sender = messageNode.getSender(); if (senderColor != null && !Strings.isNullOrEmpty(sender)) { messageNode.setSender(ColorUtil.wrapWithColorTag(sender, senderColor)); } final Collection<ChatColor> chatColors = colorCache.get(chatMessageType); for (ChatColor chatColor : chatColors) { if (chatColor.isTransparent() != isChatboxTransparent || chatColor.getType() != ChatColorType.NORMAL || chatColor.isDefault()) { continue; } // Replace </col> tags in the message with the new color so embedded </col> won't reset the color final Color color = chatColor.getColor(); messageNode.setValue(ColorUtil.wrapWithColorTag( messageNode.getValue().replace(ColorUtil.CLOSING_COLOR_TAG, ColorUtil.colorTag(color)), color)); break; } }
Example 15
Source File: ChatCommandsPlugin.java From runelite with BSD 2-Clause "Simplified" License | 4 votes |
private void clueLookup(ChatMessage chatMessage, String message) { if (!config.clue()) { return; } String search; if (message.equalsIgnoreCase(CLUES_COMMAND_STRING)) { search = "total"; } else { search = message.substring(CLUES_COMMAND_STRING.length() + 1); } try { final Skill hiscoreSkill; final HiscoreLookup lookup = getCorrectLookupFor(chatMessage); final HiscoreResult result = hiscoreClient.lookup(lookup.getName(), lookup.getEndpoint()); if (result == null) { log.warn("error looking up clues: not found"); return; } String level = search.toLowerCase(); switch (level) { case "beginner": hiscoreSkill = result.getClueScrollBeginner(); break; case "easy": hiscoreSkill = result.getClueScrollEasy(); break; case "medium": hiscoreSkill = result.getClueScrollMedium(); break; case "hard": hiscoreSkill = result.getClueScrollHard(); break; case "elite": hiscoreSkill = result.getClueScrollElite(); break; case "master": hiscoreSkill = result.getClueScrollMaster(); break; case "total": hiscoreSkill = result.getClueScrollAll(); break; default: return; } int quantity = hiscoreSkill.getLevel(); int rank = hiscoreSkill.getRank(); if (quantity == -1) { return; } ChatMessageBuilder chatMessageBuilder = new ChatMessageBuilder() .append(ChatColorType.NORMAL) .append("Clue scroll (" + level + ")").append(": ") .append(ChatColorType.HIGHLIGHT) .append(Integer.toString(quantity)); if (rank != -1) { chatMessageBuilder.append(ChatColorType.NORMAL) .append(" Rank: ") .append(ChatColorType.HIGHLIGHT) .append(String.format("%,d", rank)); } String response = chatMessageBuilder.build(); log.debug("Setting response {}", response); final MessageNode messageNode = chatMessage.getMessageNode(); messageNode.setRuneLiteFormatMessage(response); chatMessageManager.update(messageNode); client.refreshChat(); } catch (IOException ex) { log.warn("error looking up clues", ex); } }
Example 16
Source File: RaidsPlugin.java From plugins with GNU General Public License v3.0 | 4 votes |
private void lookupRaid(ChatMessage chatMessage, String s) { ChatMessageType type = chatMessage.getType(); final String player; if (type.equals(ChatMessageType.PRIVATECHATOUT)) { player = client.getLocalPlayer().getName(); } else { player = sanitize(chatMessage.getName()); } LayoutRoom[] layout; try { layout = chatClient.getLayout(player); } catch (IOException ex) { log.debug("unable to lookup layout", ex); return; } if (layout == null || layout.length == 0) { return; } String layoutMessage = Joiner.on(", ").join(Arrays.stream(layout) .map(l -> RaidRoom.valueOf(l.name())) .filter(room -> room.getType() == RoomType.COMBAT || room.getType() == RoomType.PUZZLE) .map(RaidRoom::getName) .toArray()); String response = new ChatMessageBuilder() .append(ChatColorType.HIGHLIGHT) .append("Layout: ") .append(ChatColorType.NORMAL) .append(layoutMessage) .build(); log.debug("Setting response {}", response); final MessageNode messageNode = chatMessage.getMessageNode(); messageNode.setRuneLiteFormatMessage(response); chatMessageManager.update(messageNode); client.refreshChat(); }
Example 17
Source File: ChatCommandsPlugin.java From plugins with GNU General Public License v3.0 | 4 votes |
private void combatLevelLookup(ChatMessage chatMessage, String message) { if (!config.lvl()) { return; } ChatMessageType type = chatMessage.getType(); String player; if (type == ChatMessageType.PRIVATECHATOUT) { player = client.getLocalPlayer().getName(); } else { player = Text.sanitize(chatMessage.getName()); } try { HiscoreResult playerStats = hiscoreClient.lookup(player); if (playerStats == null) { log.warn("Error fetching hiscore data: not found"); return; } int attack = playerStats.getAttack().getLevel(); int strength = playerStats.getStrength().getLevel(); int defence = playerStats.getDefence().getLevel(); int hitpoints = playerStats.getHitpoints().getLevel(); int ranged = playerStats.getRanged().getLevel(); int prayer = playerStats.getPrayer().getLevel(); int magic = playerStats.getMagic().getLevel(); int combatLevel = Experience.getCombatLevel(attack, strength, defence, hitpoints, magic, ranged, prayer); String response = new ChatMessageBuilder() .append(ChatColorType.NORMAL) .append("Combat Level: ") .append(ChatColorType.HIGHLIGHT) .append(String.valueOf(combatLevel)) .append(ChatColorType.NORMAL) .append(" A: ") .append(ChatColorType.HIGHLIGHT) .append(String.valueOf(attack)) .append(ChatColorType.NORMAL) .append(" S: ") .append(ChatColorType.HIGHLIGHT) .append(String.valueOf(strength)) .append(ChatColorType.NORMAL) .append(" D: ") .append(ChatColorType.HIGHLIGHT) .append(String.valueOf(defence)) .append(ChatColorType.NORMAL) .append(" H: ") .append(ChatColorType.HIGHLIGHT) .append(String.valueOf(hitpoints)) .append(ChatColorType.NORMAL) .append(" R: ") .append(ChatColorType.HIGHLIGHT) .append(String.valueOf(ranged)) .append(ChatColorType.NORMAL) .append(" P: ") .append(ChatColorType.HIGHLIGHT) .append(String.valueOf(prayer)) .append(ChatColorType.NORMAL) .append(" M: ") .append(ChatColorType.HIGHLIGHT) .append(String.valueOf(magic)) .build(); log.debug("Setting response {}", response); final MessageNode messageNode = chatMessage.getMessageNode(); messageNode.setRuneLiteFormatMessage(response); chatMessageManager.update(messageNode); client.refreshChat(); } catch (IOException ex) { log.warn("Error fetching hiscore data", ex); } }
Example 18
Source File: ChatCommandsPlugin.java From plugins with GNU General Public License v3.0 | 4 votes |
/** * Looks up the player skill and changes the original message to the * response. * * @param chatMessage The chat message containing the command. * @param message The chat message */ private void playerSkillLookup(ChatMessage chatMessage, String message) { if (!config.lvl()) { return; } String search; if (message.equalsIgnoreCase(TOTAL_LEVEL_COMMAND_STRING)) { search = "total"; } else { if (message.length() <= LEVEL_COMMAND_STRING.length()) { return; } search = message.substring(LEVEL_COMMAND_STRING.length() + 1); } search = SkillAbbreviations.getFullName(search); final HiscoreSkill skill; try { skill = HiscoreSkill.valueOf(search.toUpperCase()); } catch (IllegalArgumentException i) { return; } final HiscoreLookup lookup = getCorrectLookupFor(chatMessage); try { final SingleHiscoreSkillResult result = hiscoreClient.lookup(lookup.getName(), skill, lookup.getEndpoint()); if (result == null) { log.warn("unable to look up skill {} for {}: not found", skill, search); return; } final Skill hiscoreSkill = result.getSkill(); ChatMessageBuilder chatMessageBuilder = new ChatMessageBuilder() .append(ChatColorType.NORMAL) .append("Level ") .append(ChatColorType.HIGHLIGHT) .append(skill.getName()).append(": ").append(String.valueOf(hiscoreSkill.getLevel())) .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); chatMessageManager.update(messageNode); client.refreshChat(); } catch (IOException ex) { log.warn("unable to look up skill {} for {}", skill, search, ex); } }
Example 19
Source File: ChatCommandsPlugin.java From plugins with GNU General Public License v3.0 | 4 votes |
/** * Looks up the item price and changes the original message to the * response. * * @param chatMessage The chat message containing the command. * @param message The chat message */ private void itemPriceLookup(ChatMessage chatMessage, String message) { if (!config.price()) { return; } if (message.length() <= PRICE_COMMAND_STRING.length()) { return; } MessageNode messageNode = chatMessage.getMessageNode(); String search = message.substring(PRICE_COMMAND_STRING.length() + 1); List<ItemPrice> results = itemManager.search(search); if (!results.isEmpty()) { ItemPrice item = retrieveFromList(results, search); CLIENT.lookupItem(item.getId()) .subscribeOn(Schedulers.io()) .observeOn(Schedulers.single()) .subscribe( (osbresult) -> { int itemId = item.getId(); int itemPrice = itemManager.getItemPrice(itemId); final ChatMessageBuilder builder = new ChatMessageBuilder(); builder.append(ChatColorType.NORMAL); builder.append(ChatColorType.HIGHLIGHT); builder.append(item.getName()); builder.append(ChatColorType.NORMAL); builder.append(": GE "); builder.append(ChatColorType.HIGHLIGHT); builder.append(QuantityFormatter.formatNumber(itemPrice)); builder.append(ChatColorType.NORMAL); builder.append(": OSB "); builder.append(ChatColorType.HIGHLIGHT); builder.append(QuantityFormatter.formatNumber(osbresult.getOverall_average())); ItemDefinition itemComposition = itemManager.getItemDefinition(itemId); if (itemComposition != null) { int alchPrice = itemManager.getAlchValue(itemId); builder .append(ChatColorType.NORMAL) .append(" HA value ") .append(ChatColorType.HIGHLIGHT) .append(QuantityFormatter.formatNumber(alchPrice)); } String response = builder.build(); log.debug("Setting response {}", response); messageNode.setRuneLiteFormatMessage(response); chatMessageManager.update(messageNode); client.refreshChat(); } ); } }
Example 20
Source File: RaidsPlugin.java From runelite with BSD 2-Clause "Simplified" License | 4 votes |
private void lookupRaid(ChatMessage chatMessage, String s) { ChatMessageType type = chatMessage.getType(); final String player; if (type.equals(ChatMessageType.PRIVATECHATOUT)) { player = client.getLocalPlayer().getName(); } else { player = sanitize(chatMessage.getName()); } LayoutRoom[] layout; try { layout = chatClient.getLayout(player); } catch (IOException ex) { log.debug("unable to lookup layout", ex); return; } if (layout == null || layout.length == 0) { return; } String layoutMessage = Joiner.on(", ").join(Arrays.stream(layout) .map(l -> RaidRoom.valueOf(l.name())) .filter(room -> room.getType() == RoomType.COMBAT || room.getType() == RoomType.PUZZLE) .map(RaidRoom::getName) .toArray()); if (layoutMessage.length() > MAX_LAYOUT_LEN) { log.debug("layout message too long! {}", layoutMessage.length()); return; } String response = new ChatMessageBuilder() .append(ChatColorType.HIGHLIGHT) .append("Layout: ") .append(ChatColorType.NORMAL) .append(layoutMessage) .build(); log.debug("Setting response {}", response); final MessageNode messageNode = chatMessage.getMessageNode(); messageNode.setRuneLiteFormatMessage(response); chatMessageManager.update(messageNode); client.refreshChat(); }