Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaces various emoticons entered in public/friends/private chats with their corresponding emoji images. Co-authored-by: Adam <Adam@sigterm.info> Co-authored-by: Tomas Slusny <slusnucky@gmail.com>
- Loading branch information
1 parent
da2c195
commit 64019ea
Showing
53 changed files
with
307 additions
and
0 deletions.
There are no files selected for viewing
114 changes: 114 additions & 0 deletions
114
runelite-client/src/main/java/net/runelite/client/plugins/emojis/Emoji.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
* Copyright (c) 2019, Lotto <https://github.com/devLotto> | ||
* 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.client.plugins.emojis; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import java.awt.image.BufferedImage; | ||
import java.util.Map; | ||
import net.runelite.client.util.ImageUtil; | ||
|
||
enum Emoji | ||
{ | ||
SLIGHT_SMILE(":)"), | ||
JOY("=')"), | ||
COWBOY("3:)"), | ||
BLUSH("^_^"), | ||
SMILE(":D"), | ||
GRINNING("=D"), | ||
WINK(";)"), | ||
STUCK_OUT_TONGUE_CLOSED_EYES("X-P"), | ||
STUCK_OUT_TONGUE(":P"), | ||
YUM("=P~"), | ||
HUGGING("<gt>:D<lt>"), // >:D< | ||
TRIUMPH(":<gt>"), // :> | ||
THINKING(":-?"), | ||
CONFUSED(":/"), | ||
NEUTRAL_FACE("=|"), | ||
EXPRESSIONLESS(":|"), | ||
UNAMUSED(":-|"), | ||
SLIGHT_FROWN(":("), | ||
FROWNING2("=("), | ||
CRY(":'("), | ||
SOB(":_("), | ||
FLUSHED(":$"), | ||
ZIPPER_MOUTH(":-#"), | ||
PERSEVERE("<gt>_<lt>"), // >_< | ||
SUNGLASSES("8-)"), | ||
INNOCENT("O:)"), | ||
SMILING_IMP("<gt>:)"), // >:) | ||
RAGE("<gt>:("), // >:( | ||
HUSHED(":-O"), | ||
OPEN_MOUTH(":O"), | ||
SCREAM(":-@"), | ||
SEE_NO_EVIL("X_X"), | ||
DANCER("\\:D/"), | ||
OK_HAND("(Ok)"), | ||
THUMBSUP("(Y)"), | ||
THUMBSDOWN("(N)"), | ||
HEARTS("<lt>3"), // <3 | ||
BROKEN_HEART("<lt>/3"), // </3 | ||
ZZZ("Zzz"), | ||
FISH("<lt><gt><lt>"), // <>< | ||
CAT(":3"), | ||
DOG("=3"), | ||
CRAB("V(;,;)V"), | ||
FORK_AND_KNIFE("--E"), | ||
COOKING("--(o)"), | ||
PARTY_POPPER("@@@"), | ||
EYES("O.O"), | ||
SWEAT(";;"), | ||
PILE_OF_POO("~@~"); | ||
|
||
private static final Map<String, Emoji> emojiMap; | ||
|
||
private final String trigger; | ||
|
||
static | ||
{ | ||
ImmutableMap.Builder<String, Emoji> builder = new ImmutableMap.Builder<>(); | ||
|
||
for (final Emoji emoji : values()) | ||
{ | ||
builder.put(emoji.trigger, emoji); | ||
} | ||
|
||
emojiMap = builder.build(); | ||
} | ||
|
||
Emoji(String trigger) | ||
{ | ||
this.trigger = trigger; | ||
} | ||
|
||
BufferedImage loadImage() | ||
{ | ||
return ImageUtil.getResourceStreamFromClass(getClass(), this.name().toLowerCase() + ".png"); | ||
} | ||
|
||
static Emoji getEmoji(String trigger) | ||
{ | ||
return emojiMap.get(trigger); | ||
} | ||
} |
192 changes: 192 additions & 0 deletions
192
runelite-client/src/main/java/net/runelite/client/plugins/emojis/EmojiPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
/* | ||
* Copyright (c) 2019, Lotto <https://github.com/devLotto> | ||
* 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.client.plugins.emojis; | ||
|
||
import java.awt.image.BufferedImage; | ||
import java.util.Arrays; | ||
import javax.annotation.Nullable; | ||
import javax.inject.Inject; | ||
import joptsimple.internal.Strings; | ||
import lombok.extern.slf4j.Slf4j; | ||
import net.runelite.api.Client; | ||
import net.runelite.api.GameState; | ||
import net.runelite.api.IndexedSprite; | ||
import net.runelite.api.MessageNode; | ||
import net.runelite.api.Player; | ||
import net.runelite.api.events.ChatMessage; | ||
import net.runelite.api.events.GameStateChanged; | ||
import net.runelite.api.events.OverheadTextChanged; | ||
import net.runelite.client.chat.ChatMessageManager; | ||
import net.runelite.client.eventbus.Subscribe; | ||
import net.runelite.client.plugins.Plugin; | ||
import net.runelite.client.plugins.PluginDescriptor; | ||
import net.runelite.client.util.ImageUtil; | ||
|
||
@PluginDescriptor( | ||
name = "Emojis", | ||
description = "Replaces common emoticons such as :) with their corresponding emoji in the chat", | ||
enabledByDefault = false | ||
) | ||
@Slf4j | ||
public class EmojiPlugin extends Plugin | ||
{ | ||
@Inject | ||
private Client client; | ||
|
||
@Inject | ||
private ChatMessageManager chatMessageManager; | ||
|
||
private int modIconsStart = -1; | ||
|
||
@Override | ||
protected void startUp() | ||
{ | ||
loadEmojiIcons(); | ||
} | ||
|
||
@Subscribe | ||
public void onGameStateChanged(GameStateChanged gameStateChanged) | ||
{ | ||
if (gameStateChanged.getGameState() == GameState.LOGGED_IN) | ||
{ | ||
loadEmojiIcons(); | ||
} | ||
} | ||
|
||
private void loadEmojiIcons() | ||
{ | ||
final IndexedSprite[] modIcons = client.getModIcons(); | ||
if (modIconsStart != -1 || modIcons == null) | ||
{ | ||
return; | ||
} | ||
|
||
final Emoji[] emojis = Emoji.values(); | ||
final IndexedSprite[] newModIcons = Arrays.copyOf(modIcons, modIcons.length + emojis.length); | ||
modIconsStart = modIcons.length; | ||
|
||
for (int i = 0; i < emojis.length; i++) | ||
{ | ||
final Emoji emoji = emojis[i]; | ||
|
||
try | ||
{ | ||
final BufferedImage image = emoji.loadImage(); | ||
final IndexedSprite sprite = ImageUtil.getImageIndexedSprite(image, client); | ||
newModIcons[modIconsStart + i] = sprite; | ||
} | ||
catch (Exception ex) | ||
{ | ||
log.warn("Failed to load the sprite for emoji " + emoji, ex); | ||
} | ||
} | ||
|
||
log.debug("Adding emoji icons"); | ||
client.setModIcons(newModIcons); | ||
} | ||
|
||
@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: | ||
break; | ||
default: | ||
return; | ||
} | ||
|
||
final String message = chatMessage.getMessage(); | ||
final String updatedMessage = updateMessage(message); | ||
|
||
if (updatedMessage == null) | ||
{ | ||
return; | ||
} | ||
|
||
final MessageNode messageNode = chatMessage.getMessageNode(); | ||
messageNode.setRuneLiteFormatMessage(updatedMessage); | ||
chatMessageManager.update(messageNode); | ||
client.refreshChat(); | ||
} | ||
|
||
@Subscribe | ||
public void onOverheadTextChanged(final OverheadTextChanged event) | ||
{ | ||
if (!(event.getActor() instanceof Player)) | ||
{ | ||
return; | ||
} | ||
|
||
final String message = event.getOverheadText(); | ||
final String updatedMessage = updateMessage(message); | ||
|
||
if (updatedMessage == null) | ||
{ | ||
return; | ||
} | ||
|
||
event.getActor().setOverheadText(updatedMessage); | ||
} | ||
|
||
@Nullable | ||
private String updateMessage(final String message) | ||
{ | ||
final String[] messageWords = message.split(" "); | ||
|
||
boolean editedMessage = false; | ||
for (int i = 0; i < messageWords.length; i++) | ||
{ | ||
final Emoji emoji = Emoji.getEmoji(messageWords[i]); | ||
|
||
if (emoji == null) | ||
{ | ||
continue; | ||
} | ||
|
||
final int emojiId = modIconsStart + emoji.ordinal(); | ||
|
||
messageWords[i] = "<img=" + emojiId + ">"; | ||
editedMessage = true; | ||
} | ||
|
||
// If we haven't edited the message any, don't update it. | ||
if (!editedMessage) | ||
{ | ||
return null; | ||
} | ||
|
||
return Strings.join(messageWords, " "); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
runelite-client/src/main/resources/net/runelite/client/plugins/emojis/LICENSE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
The images in this folder are derivatives of "twemoji" (https://github.com/twitter/twemoji) by "Twitter, Inc", used under CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). The derivatives are licensed under the same license. |
Binary file added
BIN
+1.29 KB
runelite-client/src/main/resources/net/runelite/client/plugins/emojis/blush.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+15.8 KB
...e-client/src/main/resources/net/runelite/client/plugins/emojis/broken_heart.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.47 KB
runelite-client/src/main/resources/net/runelite/client/plugins/emojis/cat.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.2 KB
runelite-client/src/main/resources/net/runelite/client/plugins/emojis/confused.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.29 KB
runelite-client/src/main/resources/net/runelite/client/plugins/emojis/cooking.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.34 KB
runelite-client/src/main/resources/net/runelite/client/plugins/emojis/cowboy.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+15.5 KB
runelite-client/src/main/resources/net/runelite/client/plugins/emojis/crab.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+312 Bytes
runelite-client/src/main/resources/net/runelite/client/plugins/emojis/cry.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+15.4 KB
runelite-client/src/main/resources/net/runelite/client/plugins/emojis/dancer.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.42 KB
runelite-client/src/main/resources/net/runelite/client/plugins/emojis/dog.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.13 KB
...client/src/main/resources/net/runelite/client/plugins/emojis/expressionless.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.37 KB
runelite-client/src/main/resources/net/runelite/client/plugins/emojis/eyes.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.25 KB
runelite-client/src/main/resources/net/runelite/client/plugins/emojis/fish.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.4 KB
runelite-client/src/main/resources/net/runelite/client/plugins/emojis/flushed.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+15.8 KB
...client/src/main/resources/net/runelite/client/plugins/emojis/fork_and_knife.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.19 KB
...lite-client/src/main/resources/net/runelite/client/plugins/emojis/frowning2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.32 KB
runelite-client/src/main/resources/net/runelite/client/plugins/emojis/grinning.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+15.8 KB
runelite-client/src/main/resources/net/runelite/client/plugins/emojis/hearts.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.34 KB
runelite-client/src/main/resources/net/runelite/client/plugins/emojis/hugging.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.25 KB
runelite-client/src/main/resources/net/runelite/client/plugins/emojis/hushed.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.41 KB
runelite-client/src/main/resources/net/runelite/client/plugins/emojis/innocent.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.41 KB
runelite-client/src/main/resources/net/runelite/client/plugins/emojis/joy.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.15 KB
runelite-client/src/main/resources/net/runelite/client/plugins/emojis/kissing.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.17 KB
...e-client/src/main/resources/net/runelite/client/plugins/emojis/neutral_face.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+15.8 KB
runelite-client/src/main/resources/net/runelite/client/plugins/emojis/ok_hand.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.2 KB
...ite-client/src/main/resources/net/runelite/client/plugins/emojis/open_mouth.png
Oops, something went wrong.
Binary file added
BIN
+1.37 KB
...e-client/src/main/resources/net/runelite/client/plugins/emojis/party_popper.png
Oops, something went wrong.
Binary file added
BIN
+1.33 KB
...lite-client/src/main/resources/net/runelite/client/plugins/emojis/persevere.png
Oops, something went wrong.
Binary file added
BIN
+1.26 KB
...te-client/src/main/resources/net/runelite/client/plugins/emojis/pile_of_poo.png
Oops, something went wrong.
Binary file added
BIN
+1.2 KB
runelite-client/src/main/resources/net/runelite/client/plugins/emojis/rage.png
Oops, something went wrong.
Binary file added
BIN
+1.38 KB
runelite-client/src/main/resources/net/runelite/client/plugins/emojis/scream.png
Oops, something went wrong.
Binary file added
BIN
+1.45 KB
...te-client/src/main/resources/net/runelite/client/plugins/emojis/see_no_evil.png
Oops, something went wrong.
Binary file added
BIN
+1.21 KB
...e-client/src/main/resources/net/runelite/client/plugins/emojis/slight_frown.png
Oops, something went wrong.
Binary file added
BIN
+1.22 KB
...e-client/src/main/resources/net/runelite/client/plugins/emojis/slight_smile.png
Oops, something went wrong.
Binary file added
BIN
+1.29 KB
runelite-client/src/main/resources/net/runelite/client/plugins/emojis/smile.png
Oops, something went wrong.
Binary file added
BIN
+1.22 KB
...te-client/src/main/resources/net/runelite/client/plugins/emojis/smiling_imp.png
Oops, something went wrong.
Binary file added
BIN
+1.32 KB
runelite-client/src/main/resources/net/runelite/client/plugins/emojis/sob.png
Oops, something went wrong.
Binary file added
BIN
+1.28 KB
...ient/src/main/resources/net/runelite/client/plugins/emojis/stuck_out_tongue.png
Oops, something went wrong.
Binary file added
BIN
+1.31 KB
...n/resources/net/runelite/client/plugins/emojis/stuck_out_tongue_closed_eyes.png
Oops, something went wrong.
Binary file added
BIN
+1.28 KB
...ite-client/src/main/resources/net/runelite/client/plugins/emojis/sunglasses.png
Oops, something went wrong.
Binary file added
BIN
+1.06 KB
runelite-client/src/main/resources/net/runelite/client/plugins/emojis/sweat.png
Oops, something went wrong.
Binary file added
BIN
+15.5 KB
runelite-client/src/main/resources/net/runelite/client/plugins/emojis/thinking.png
Oops, something went wrong.
Binary file added
BIN
+1.19 KB
...ite-client/src/main/resources/net/runelite/client/plugins/emojis/thumbsdown.png
Oops, something went wrong.
Binary file added
BIN
+1.19 KB
runelite-client/src/main/resources/net/runelite/client/plugins/emojis/thumbsup.png
Oops, something went wrong.
Binary file added
BIN
+1.4 KB
runelite-client/src/main/resources/net/runelite/client/plugins/emojis/triumph.png
Oops, something went wrong.
Binary file added
BIN
+15.9 KB
runelite-client/src/main/resources/net/runelite/client/plugins/emojis/unamused.png
Oops, something went wrong.
Binary file added
BIN
+1.27 KB
runelite-client/src/main/resources/net/runelite/client/plugins/emojis/wink.png
Oops, something went wrong.
Binary file added
BIN
+1.29 KB
runelite-client/src/main/resources/net/runelite/client/plugins/emojis/yum.png
Oops, something went wrong.
Binary file added
BIN
+1.27 KB
...e-client/src/main/resources/net/runelite/client/plugins/emojis/zipper_mouth.png
Oops, something went wrong.
Binary file added
BIN
+15.8 KB
runelite-client/src/main/resources/net/runelite/client/plugins/emojis/zzz.png
Oops, something went wrong.