Java Code Examples for net.runelite.api.events.ChatMessage#getType()

The following examples show how to use net.runelite.api.events.ChatMessage#getType() . 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: WoodcuttingPlugin.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
@Subscribe
void onChatMessage(ChatMessage event)
{
	if (event.getType() == ChatMessageType.SPAM || event.getType() == ChatMessageType.GAMEMESSAGE)
	{
		if (WOOD_CUT_PATTERN.matcher(event.getMessage()).matches())
		{
			if (session == null)
			{
				session = new WoodcuttingSession();
				gpEarned = 0;
			}

			session.setLastChopping();

			typeOfLogCut(event.getMessage());
			gpEarned += itemManager.getItemPrice(treeTypeID);
		}

		if (event.getMessage().contains("A bird's nest falls out of the tree") && config.showNestNotification())
		{
			notifier.notify("A bird nest has spawned!");
		}
	}
}
 
Example 2
Source File: FriendsChatPlugin.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void insertRankIcon(final ChatMessage message)
{
	final FriendsChatRank rank = friendChatManager.getRank(message.getName());

	if (rank != null && rank != FriendsChatRank.UNRANKED)
	{
		int iconNumber = friendChatManager.getIconNumber(rank);
		final String img = "<img=" + iconNumber + ">";
		if (message.getType() == ChatMessageType.FRIENDSCHAT)
		{
			message.getMessageNode()
				.setSender(message.getMessageNode().getSender() + " " + img);
		}
		else
		{
			message.getMessageNode()
				.setName(img + message.getMessageNode().getName());
		}
		client.refreshChat();
	}
}
 
Example 3
Source File: WoodcuttingPlugin.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Subscribe
public void onChatMessage(ChatMessage event)
{
	if (event.getType() == ChatMessageType.SPAM || event.getType() == ChatMessageType.GAMEMESSAGE)
	{
		if (WOOD_CUT_PATTERN.matcher(event.getMessage()).matches())
		{
			if (session == null)
			{
				session = new WoodcuttingSession();
			}

			session.setLastChopping();
		}

		if (event.getMessage().contains("A bird's nest falls out of the tree") && config.showNestNotification())
		{
			notifier.notify("A bird nest has spawned!");
		}
	}
}
 
Example 4
Source File: RunecraftPlugin.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Subscribe
public void onChatMessage(ChatMessage event)
{
	if (event.getType() != ChatMessageType.GAMEMESSAGE)
	{
		return;
	}

	if (config.degradingNotification())
	{
		if (event.getMessage().contains(POUCH_DECAYED_MESSAGE))
		{
			notifier.notify(POUCH_DECAYED_NOTIFICATION_MESSAGE);
		}
	}
}
 
Example 5
Source File: FriendsChatPlugin.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
private void insertRankIcon(final ChatMessage message)
{
	final FriendsChatRank rank = friendChatManager.getRank(message.getName());

	if (rank != null && rank != FriendsChatRank.UNRANKED)
	{
		int iconNumber = friendChatManager.getIconNumber(rank);
		final String img = "<img=" + iconNumber + ">";
		if (message.getType() == ChatMessageType.FRIENDSCHAT)
		{
			message.getMessageNode()
				.setSender(message.getMessageNode().getSender() + " " + img);
		}
		else
		{
			message.getMessageNode()
				.setName(img + message.getMessageNode().getName());
		}
		client.refreshChat();
	}
}
 
Example 6
Source File: ChatCommandsPlugin.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets correct lookup data for message
 *
 * @param chatMessage chat message
 * @return hiscore lookup data
 */
private HiscoreLookup getCorrectLookupFor(final ChatMessage chatMessage)
{
	Player localPlayer = client.getLocalPlayer();
	final String player = Text.sanitize(chatMessage.getName());

	// If we are sending the message then just use the local hiscore endpoint for the world
	if (chatMessage.getType().equals(ChatMessageType.PRIVATECHATOUT)
		|| player.equals(localPlayer.getName()))
	{
		return new HiscoreLookup(localPlayer.getName(), hiscoreEndpoint);
	}

	// Public chat on a leagues world is always league hiscores, regardless of icon
	if (chatMessage.getType() == ChatMessageType.PUBLICCHAT || chatMessage.getType() == ChatMessageType.MODCHAT)
	{
		if (client.getWorldType().contains(WorldType.LEAGUE))
		{
			return new HiscoreLookup(player, HiscoreEndpoint.LEAGUE);
		}
	}

	// Get ironman status from their icon in chat
	HiscoreEndpoint endpoint = getHiscoreEndpointByName(chatMessage.getName());
	return new HiscoreLookup(player, endpoint);
}
 
Example 7
Source File: ThievingPlugin.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
@Subscribe
private void onChatMessage(ChatMessage event)
{
	if (event.getType() != ChatMessageType.SPAM)
	{
		return;
	}

	final String message = event.getMessage();

	if (message.startsWith("You pickpocket") || message.startsWith("You pick-pocket") || message.startsWith("You steal") || message.startsWith("You successfully pick-pocket") || message.startsWith("You successfully pick") || message.startsWith("You successfully steal") || message.startsWith("You pick the knight") || message.startsWith("You pick the Elf"))
	{
		if (session == null)
		{
			session = new ThievingSession();
		}

		session.updateLastThevingAction();
		session.hasSucceeded();
	}
	else if (message.startsWith("You fail to pick") || message.startsWith("You fail to steal"))
	{
		if (session == null)
		{
			session = new ThievingSession();
		}

		session.updateLastThevingAction();
		session.hasFailed();
	}
}
 
Example 8
Source File: ClueScrollPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Subscribe
public void onChatMessage(ChatMessage event)
{
	if (event.getType() != ChatMessageType.GAMEMESSAGE && event.getType() != ChatMessageType.SPAM)
	{
		return;
	}

	if (clue instanceof HotColdClue)
	{
		if (((HotColdClue) clue).update(event.getMessage(), this))
		{
			worldMapPointsSet = false;
		}
	}

	if (clue instanceof SkillChallengeClue)
	{
		String text = Text.removeTags(event.getMessage());
		if (text.equals("Skill challenge completed.") ||
			text.equals("You have completed your master level challenge!") ||
			text.startsWith("You have completed Charlie's task,") ||
			text.equals("You have completed this challenge scroll."))
		{
			((SkillChallengeClue) clue).setChallengeCompleted(true);
		}
	}
}
 
Example 9
Source File: WorldHopperPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Subscribe
public void onChatMessage(ChatMessage event)
{
	if (event.getType() != ChatMessageType.GAMEMESSAGE)
	{
		return;
	}

	if (event.getMessage().equals("Please finish what you're doing before using the World Switcher."))
	{
		resetQuickHopper();
	}
}
 
Example 10
Source File: KourendLibraryPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Subscribe
public void onChatMessage(ChatMessage event)
{
	if (lastBookcaseAnimatedOn != null && event.getType() == ChatMessageType.GAMEMESSAGE)
	{
		if (event.getMessage().equals("You don't find anything useful here."))
		{
			library.mark(lastBookcaseAnimatedOn, null);
			updateBooksPanel();
			lastBookcaseAnimatedOn = null;
		}
	}
}
 
Example 11
Source File: LeagueChatIconsPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Subscribe
public void onChatMessage(ChatMessage chatMessage)
{
	if (client.getGameState() != GameState.LOADING && client.getGameState() != GameState.LOGGED_IN)
	{
		return;
	}

	switch (chatMessage.getType())
	{
		case PRIVATECHAT:
		case MODPRIVATECHAT:
			// Note this is unable to change icon on PMs if they are not a friend or in friends chat
		case FRIENDSCHAT:
			String name = Text.removeTags(chatMessage.getName());
			if (isChatPlayerOnLeague(name))
			{
				addLeagueIconToMessage(chatMessage);
			}
			break;
		case PUBLICCHAT:
		case MODCHAT:
			if (onLeagueWorld)
			{
				addLeagueIconToMessage(chatMessage);
			}
			break;
	}
}
 
Example 12
Source File: FriendsChatPlugin.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Subscribe
public void onChatMessage(ChatMessage chatMessage)
{
	if (client.getGameState() != GameState.LOADING && client.getGameState() != GameState.LOGGED_IN)
	{
		return;
	}

	FriendsChatManager friendsChatManager = client.getFriendsChatManager();
	if (friendsChatManager == null || friendsChatManager.getCount() == 0)
	{
		return;
	}

	switch (chatMessage.getType())
	{
		case PRIVATECHAT:
		case MODPRIVATECHAT:
			if (!config.privateMessageIcons())
			{
				return;
			}
			break;
		case PUBLICCHAT:
		case MODCHAT:
			if (!config.publicChatIcons())
			{
				return;
			}
			break;
		case FRIENDSCHAT:
			if (!config.chatIcons())
			{
				return;
			}
			break;
		default:
			return;
	}

	insertRankIcon(chatMessage);
}
 
Example 13
Source File: ChatCommandsPlugin.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
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 14
Source File: SuppliesTrackerPlugin.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
@Subscribe
void onChatMessage(ChatMessage event)
{
	String message = event.getMessage();

	if (event.getType() == ChatMessageType.GAMEMESSAGE || event.getType() == ChatMessageType.SPAM)
	{
		if (message.toLowerCase().contains("you plant "))
		{
			farming.OnChatPlant(message.toLowerCase());
		}
		else if (message.toLowerCase().contains("you treat "))
		{
			farming.setEndlessBucket(message);
			farming.OnChatTreat(message.toLowerCase());
		}
		else if (message.toLowerCase().contains("you bury the bones"))
		{
			prayer.OnChat(message);
		}
		else if (message.toLowerCase().contains("you eat the sweets."))
		{
			buildEntries(PURPLE_SWEETS_10476);
		}
		else if (message.toLowerCase().contains("dark lord"))
		{
			skipBone = true;
		}
		else if (message.toLowerCase().contains("your amulet has") ||
			message.toLowerCase().contains("your amulet's last charge"))
		{
			buildChargesEntries(AMULET_OF_GLORY6);
		}
		else if (message.toLowerCase().contains("your ring of dueling has") ||
			message.toLowerCase().contains("your ring of dueling crumbles"))
		{
			buildChargesEntries(RING_OF_DUELING8);
		}
		else if (message.toLowerCase().contains("your ring of wealth has"))
		{
			buildChargesEntries(RING_OF_WEALTH_5);
		}
		else if (message.toLowerCase().contains("your combat bracelet has") ||
			message.toLowerCase().contains("your combat bracelet's last charge"))
		{
			buildChargesEntries(COMBAT_BRACELET6);
		}
		else if (message.toLowerCase().contains("your games necklace has") ||
			message.toLowerCase().contains("your games necklace crumbles"))
		{
			buildChargesEntries(GAMES_NECKLACE8);
		}
		else if (message.toLowerCase().contains("your skills necklace has") ||
			message.toLowerCase().contains("your skills necklace's last charge"))
		{
			buildChargesEntries(SKILLS_NECKLACE6);
		}
		else if (message.toLowerCase().contains("your necklace of passage has") ||
			message.toLowerCase().contains("your necklace of passage crumbles"))
		{
			buildChargesEntries(NECKLACE_OF_PASSAGE5);
		}
		else if (message.toLowerCase().contains("your burning amulet has") ||
			message.toLowerCase().contains("your burning amulet crumbles"))
		{
			buildChargesEntries(BURNING_AMULET5);
		}
		else if (event.getMessage().contains("A magical chest")
			&& event.getMessage().contains("outside the Theatre of Blood"))
		{
			buildEntries(HEALER_ICON_20802);
		}
		else if (event.getMessage().contains("Torfinn has retrieved some of your items."))
		{
			buildEntries(HEALER_ICON_22308);
		}
	}
}
 
Example 15
Source File: NightmareZonePlugin.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Subscribe
public void onChatMessage(ChatMessage event)
{
	if (event.getType() != ChatMessageType.GAMEMESSAGE
			|| !isInNightmareZone())
	{
		return;
	}

	String msg = Text.removeTags(event.getMessage()); //remove color
	if (msg.contains("The effects of overload have worn off, and you feel normal again."))
	{
		if (config.overloadNotification())
		{
			notifier.notify("Your overload has worn off");
		}
	}
	else if (msg.contains("A power-up has spawned:"))
	{
		if (msg.contains("Power surge"))
		{
			if (config.powerSurgeNotification())
			{
				notifier.notify(msg);
			}
		}
		else if (msg.contains("Recurrent damage"))
		{
			if (config.recurrentDamageNotification())
			{
				notifier.notify(msg);
			}
		}
		else if (msg.contains("Zapper"))
		{
			if (config.zapperNotification())
			{
				notifier.notify(msg);
			}
		}
		else if (msg.contains("Ultimate force"))
		{
			if (config.ultimateForceNotification())
			{
				notifier.notify(msg);
			}
		}
	}
}
 
Example 16
Source File: ExaminePlugin.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
@Subscribe
void onChatMessage(ChatMessage event)
{
	ExamineType type;
	switch (event.getType())
	{
		case ITEM_EXAMINE:
			type = ExamineType.ITEM;
			break;
		case OBJECT_EXAMINE:
			type = ExamineType.OBJECT;
			break;
		case NPC_EXAMINE:
			type = ExamineType.NPC;
			break;
		case GAMEMESSAGE:
			type = ExamineType.ITEM_BANK_EQ;
			break;
		default:
			return;
	}

	if (pending.isEmpty())
	{
		log.debug("Got examine without a pending examine?");
		return;
	}

	PendingExamine pendingExamine = pending.pop();

	if (pendingExamine.getType() != type)
	{
		log.debug("Type mismatch for pending examine: {} != {}", pendingExamine.getType(), type);
		pending.clear(); // eh
		return;
	}

	log.debug("Got examine for {} {}: {}", pendingExamine.getType(), pendingExamine.getId(), event.getMessage());

	// If it is an item, show the price of it
	final ItemDefinition itemDefinition;
	if (pendingExamine.getType() == ExamineType.ITEM || pendingExamine.getType() == ExamineType.ITEM_BANK_EQ)
	{
		final int itemId = pendingExamine.getId();
		final int itemQuantity = pendingExamine.getQuantity();

		if (itemId == ItemID.COINS_995)
		{
			return;
		}

		itemDefinition = itemManager.getItemDefinition(itemId);
		getItemPrice(itemDefinition.getId(), itemDefinition, itemQuantity);
	}
	else
	{
		itemDefinition = null;
	}

	// Don't submit examine info for tradeable items, which we already have from the RS item api
	if (itemDefinition != null && itemDefinition.isTradeable())
	{
		return;
	}

	// Large quantities of items show eg. 100000 x Coins
	if (type == ExamineType.ITEM && X_PATTERN.matcher(event.getMessage()).lookingAt())
	{
		return;
	}

	CacheKey key = new CacheKey(type, pendingExamine.getId());
	Boolean cached = cache.getIfPresent(key);
	if (cached != null)
	{
		return;
	}

	cache.put(key, Boolean.TRUE);
	submitExamine(pendingExamine, event.getMessage());
}
 
Example 17
Source File: ChatCommandsPlugin.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
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: SlayerPlugin.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
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 19
Source File: ChatCommandManager.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Subscribe
public void onChatMessage(ChatMessage chatMessage)
{
	if (client.getGameState() != GameState.LOGGED_IN)
	{
		return;
	}

	switch (chatMessage.getType())
	{
		case PUBLICCHAT:
		case MODCHAT:
		case FRIENDSCHAT:
		case PRIVATECHAT:
		case MODPRIVATECHAT:
		case PRIVATECHATOUT:
			break;
		default:
			return;
	}

	String message = chatMessage.getMessage();

	String command = extractCommand(message);
	if (command == null)
	{
		return;
	}

	ChatCommand chatCommand = commands.get(command.toLowerCase());
	if (chatCommand == null)
	{
		return;
	}

	if (chatCommand.isAsync())
	{
		scheduledExecutorService.execute(() -> chatCommand.getExecute().accept(chatMessage, message));
	}
	else
	{
		chatCommand.getExecute().accept(chatMessage, message);
	}
}
 
Example 20
Source File: ChatCommandsPlugin.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void killCountLookup(ChatMessage chatMessage, String message)
{
	if (!config.killcount())
	{
		return;
	}

	if (message.length() <= KILLCOUNT_COMMAND_STRING.length())
	{
		return;
	}

	ChatMessageType type = chatMessage.getType();
	String search = message.substring(KILLCOUNT_COMMAND_STRING.length() + 1);

	final String player;
	if (type.equals(ChatMessageType.PRIVATECHATOUT))
	{
		player = client.getLocalPlayer().getName();
	}
	else
	{
		player = Text.sanitize(chatMessage.getName());
	}

	search = longBossName(search);

	final int kc;
	try
	{
		kc = chatClient.getKc(player, search);
	}
	catch (IOException ex)
	{
		log.debug("unable to lookup killcount", ex);
		return;
	}

	String response = new ChatMessageBuilder()
		.append(ChatColorType.HIGHLIGHT)
		.append(search)
		.append(ChatColorType.NORMAL)
		.append(" kill count: ")
		.append(ChatColorType.HIGHLIGHT)
		.append(Integer.toString(kc))
		.build();

	log.debug("Setting response {}", response);
	final MessageNode messageNode = chatMessage.getMessageNode();
	messageNode.setRuneLiteFormatMessage(response);
	chatMessageManager.update(messageNode);
	client.refreshChat();
}