EmojiPlugin extends Plugin { @Nullable String updateMessage(final String message) { final String[] messageWords = WHITESPACE_REGEXP.split(message); boolean editedMessage = false; for (int i = 0; i < messageWords.length; i++) { final String trigger = Text.removeFormattingTags(messageWords[i]); final Emoji emoji = Emoji.getEmoji(trigger); if (emoji == null) { continue; } final int emojiId = modIconsStart + emoji.ordinal(); messageWords[i] = messageWords[i].replace(trigger, "<img=" + emojiId + ">"); editedMessage = true; } if (!editedMessage) { return null; } return Strings.join(messageWords, " "); }  @Subscribe void onGameStateChanged(GameStateChanged gameStateChanged); @Subscribe void onChatMessage(ChatMessage chatMessage); @Subscribe void onOverheadTextChanged(final OverheadTextChanged event);  }
@Test public void testEmojiUpdateMessage() { String PARTY_POPPER = "<img=" + (-1 + Emoji.getEmoji("@@@").ordinal()) + '>'; String OPEN_MOUTH = "<img=" + (-1 + Emoji.getEmoji(":O").ordinal()) + '>'; assertNull(emojiPlugin.updateMessage("@@@@@")); assertEquals(PARTY_POPPER, emojiPlugin.updateMessage("@@@")); assertEquals(PARTY_POPPER + ' ' + PARTY_POPPER, emojiPlugin.updateMessage("@@@ @@@")); assertEquals(PARTY_POPPER + ' ' + OPEN_MOUTH, emojiPlugin.updateMessage("@@@\u00A0:O")); assertEquals(PARTY_POPPER + ' ' + OPEN_MOUTH + ' ' + PARTY_POPPER, emojiPlugin.updateMessage("@@@\u00A0:O @@@")); assertEquals(PARTY_POPPER + " Hello World " + PARTY_POPPER, emojiPlugin.updateMessage("@@@\u00A0Hello World\u00A0@@@")); }