diff --git a/build.gradle b/build.gradle index 00b53e5..aa67811 100644 --- a/build.gradle +++ b/build.gradle @@ -24,9 +24,9 @@ dependencies { } group = 'com.github.dappermickie.odablock' -version = '1.1.0' +version = '1.1.1' tasks.withType(JavaCompile) { options.encoding = 'UTF-8' -} \ No newline at end of file +} diff --git a/src/main/java/com/github/dappermickie/odablock/ChatRightClickManager.java b/src/main/java/com/github/dappermickie/odablock/ChatRightClickManager.java index a66634f..dc23bb5 100644 --- a/src/main/java/com/github/dappermickie/odablock/ChatRightClickManager.java +++ b/src/main/java/com/github/dappermickie/odablock/ChatRightClickManager.java @@ -49,12 +49,12 @@ public void onGameTick(GameTick event) { RightClickAction rightClickAction = rightClickable.get(untaggedText); clientThread.invokeLater(() -> { - w.setAction(1, rightClickAction.getAction()); + w.setAction(5, rightClickAction.getAction()); w.setOnOpListener((JavaScriptCallback) (ScriptEvent ev) -> { openLink(rightClickAction); }); w.setHasListener(true); - w.setNoClickThrough(true); + w.setNoClickThrough(false); w.revalidate(); }); } diff --git a/src/main/java/com/github/dappermickie/odablock/OdablockPlugin.java b/src/main/java/com/github/dappermickie/odablock/OdablockPlugin.java index 9f44137..f89d667 100644 --- a/src/main/java/com/github/dappermickie/odablock/OdablockPlugin.java +++ b/src/main/java/com/github/dappermickie/odablock/OdablockPlugin.java @@ -1,5 +1,6 @@ package com.github.dappermickie.odablock; +import com.github.dappermickie.odablock.emotes.EmoteHandler; import com.github.dappermickie.odablock.livestreams.LivestreamManager; import com.github.dappermickie.odablock.notifications.NotificationManager; import com.github.dappermickie.odablock.sounds.AcbSpec; @@ -49,6 +50,7 @@ import net.runelite.api.events.ActorDeath; import net.runelite.api.events.AreaSoundEffectPlayed; import net.runelite.api.events.ChatMessage; +import net.runelite.api.events.CommandExecuted; import net.runelite.api.events.GameObjectDespawned; import net.runelite.api.events.GameObjectSpawned; import net.runelite.api.events.GameStateChanged; @@ -56,6 +58,7 @@ import net.runelite.api.events.InteractingChanged; import net.runelite.api.events.MenuOptionClicked; import net.runelite.api.events.NpcDespawned; +import net.runelite.api.events.OverheadTextChanged; import net.runelite.api.events.PlayerDespawned; import net.runelite.api.events.PlayerSpawned; import net.runelite.api.events.ProjectileMoved; @@ -214,6 +217,9 @@ public class OdablockPlugin extends Plugin @Inject private ChatRightClickManager chatRightClickManager; + @Inject + private EmoteHandler emoteHandler; + @Inject @Named("developerMode") private boolean developerMode; @@ -227,6 +233,7 @@ protected void startUp() throws Exception clientThread.invoke(this::setupOldMaps); achievementDiaries.setLastLoginTick(-1); prayerDown.setLastLoginTick(-1); + emoteHandler.loadEmotes(); executor.submit(() -> { PlayerKillLineManager.Setup(okHttpClient); SoundFileManager.ensureDownloadDirectoryExists(); @@ -303,6 +310,8 @@ public void onActorDeath(ActorDeath actorDeath) @Subscribe public void onChatMessage(ChatMessage chatMessage) { + emoteHandler.onChatMessage(chatMessage); + if (acceptTrade.onChatMessage(chatMessage)) { return; @@ -350,6 +359,11 @@ else if (coxSounds.onChatMessage(chatMessage)) } } + @Subscribe + private void onOverheadTextChanged(OverheadTextChanged event) + { + emoteHandler.onOverheadTextChanged(event); + } @Subscribe public void onVarbitChanged(VarbitChanged event) @@ -519,6 +533,12 @@ public void onScriptCallbackEvent(ScriptCallbackEvent scriptCallbackEvent) } } + @Subscribe + public void onCommandExecuted(CommandExecuted event) + { + emoteHandler.onCommandExecuted(event); + } + public static int TO_GROUP(int id) { return id >>> 16; diff --git a/src/main/java/com/github/dappermickie/odablock/emotes/Emote.java b/src/main/java/com/github/dappermickie/odablock/emotes/Emote.java new file mode 100644 index 0000000..4d2759e --- /dev/null +++ b/src/main/java/com/github/dappermickie/odablock/emotes/Emote.java @@ -0,0 +1,85 @@ +package com.github.dappermickie.odablock.emotes; + +import com.google.common.collect.ImmutableMap; +import java.awt.image.BufferedImage; +import java.util.Map; +import lombok.AllArgsConstructor; +import net.runelite.client.util.ImageUtil; + +@AllArgsConstructor +public enum Emote +{ + AIAIAI("aiaiai", EmoteType.GIF), + AWKWARD("awkward", EmoteType.GIF), + FUFU("fufu", EmoteType.GIF), + GNEAH("gneah", EmoteType.PNG), + HUH("huh", EmoteType.PNG), + HYPERWANKGE("hyperwankge", EmoteType.GIF), + JANITOR("janitor", EmoteType.PNG), + KEK("kek", EmoteType.GIF), + KISS("kiss", EmoteType.PNG), + NOWAY("noway", EmoteType.PNG), + PFACE(":p", EmoteType.GIF, new String[]{"pface"}), + RLY("rly", EmoteType.GIF), + SMILE(":)", EmoteType.GIF, new String[]{"smile"}), + TUNE("tune", EmoteType.GIF), + ODAWHAT("odawhat", EmoteType.PNG), + WHENITREGISTERS("whenitregisters", EmoteType.GIF), + WINK("wink", EmoteType.PNG); + + private enum EmoteType + { + PNG, + GIF + } + + private static final Map emojiMap; + + private final String trigger; + private final EmoteType emoteType; + private final String[] altTriggers; + + Emote(final String trigger, EmoteType emoteType) + { + this(trigger, emoteType, new String[]{}); + } + + static + { + ImmutableMap.Builder builder = new ImmutableMap.Builder<>(); + + for (final Emote emoji : values()) + { + builder.put(emoji.trigger, emoji); + if (!emoji.trigger.startsWith("oda") && !emoji.trigger.startsWith(":")) + { + builder.put("oda" + emoji.trigger, emoji); + } + for (final String altTrigger : emoji.altTriggers) + { + builder.put(altTrigger, emoji); + if (!altTrigger.startsWith("oda") && !altTrigger.startsWith(":")) + { + builder.put("oda" + altTrigger, emoji); + } + } + } + + emojiMap = builder.build(); + } + + BufferedImage loadImage() + { + return ImageUtil.loadImageResource(getClass(), this.name().toLowerCase() + getEmoteTypeExtension()); + } + + private String getEmoteTypeExtension() + { + return emoteType == EmoteType.GIF ? ".gif" : ".png"; + } + + static Emote getEmoji(String trigger) + { + return emojiMap.get(trigger); + } +} \ No newline at end of file diff --git a/src/main/java/com/github/dappermickie/odablock/emotes/EmoteHandler.java b/src/main/java/com/github/dappermickie/odablock/emotes/EmoteHandler.java new file mode 100644 index 0000000..e7cb500 --- /dev/null +++ b/src/main/java/com/github/dappermickie/odablock/emotes/EmoteHandler.java @@ -0,0 +1,160 @@ +package com.github.dappermickie.odablock.emotes; + +import static com.github.dappermickie.odablock.OdablockPlugin.ODABLOCK; +import java.awt.image.BufferedImage; +import java.util.regex.Pattern; +import javax.annotation.Nullable; +import javax.inject.Inject; +import javax.inject.Singleton; +import joptsimple.internal.Strings; +import lombok.extern.slf4j.Slf4j; +import net.runelite.api.ChatMessageType; +import net.runelite.api.Client; +import net.runelite.api.MessageNode; +import net.runelite.api.Player; +import net.runelite.api.events.ChatMessage; +import net.runelite.api.events.CommandExecuted; +import net.runelite.api.events.OverheadTextChanged; +import net.runelite.client.callback.ClientThread; +import net.runelite.client.game.ChatIconManager; +import net.runelite.client.util.Text; + +@Slf4j +@Singleton +public class EmoteHandler +{ + private static final Pattern WHITESPACE_REGEXP = Pattern.compile("[\\s\\u00A0]"); + + @Inject + private ChatIconManager chatIconManager; + + @Inject + private ClientThread clientThread; + + @Inject + private Client client; + + private int[] iconIds; + + public void loadEmotes() + { + if (iconIds != null) + { + return; + } + + Emote[] emotes = Emote.values(); + iconIds = new int[emotes.length]; + + for (int i = 0; i < emotes.length; i++) + { + final Emote emoji = emotes[i]; + final BufferedImage image = emoji.loadImage(); + iconIds[i] = chatIconManager.registerChatIcon(image); + } + } + + public void onChatMessage(ChatMessage chatMessage) + { + if (iconIds == null) + { + return; + } + + switch (chatMessage.getType()) + { + case PUBLICCHAT: + case MODCHAT: + case FRIENDSCHAT: + case CLAN_CHAT: + case CLAN_GUEST_CHAT: + case CLAN_GIM_CHAT: + 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.setValue(updatedMessage); + } + + 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); + } + + public void onCommandExecuted(CommandExecuted event) + { + if (event.getCommand().startsWith("odaemote") || event.getCommand().startsWith("odablockemote")) + { + clientThread.invoke(this::sendOdaEmotes); + } + } + + private void sendOdaEmotes() + { + client.addChatMessage(ChatMessageType.GAMEMESSAGE, ODABLOCK, "Odablock emote list:", null); + for (Emote emote : Emote.values()) + { + final int emoteId = iconIds[emote.ordinal()]; + final String emoteImage = ""; + client.addChatMessage(ChatMessageType.GAMEMESSAGE, ODABLOCK, emote.name() + " : " + emoteImage, null); + } + } + + @Nullable + String updateMessage(final String message) + { + final String[] messageWords = WHITESPACE_REGEXP.split(message); + + boolean editedMessage = false; + for (int i = 0; i < messageWords.length; i++) + { + // Remove tags except for and + final String originalTrigger = Text.removeFormattingTags(messageWords[i]); + final String trigger = originalTrigger.toLowerCase(); + final Emote emote = Emote.getEmoji(trigger); + + if (emote == null) + { + continue; + } + + final int emoteId = iconIds[emote.ordinal()]; + messageWords[i] = messageWords[i].replace(originalTrigger, ""); + editedMessage = true; + } + + // If we haven't edited the message any, don't update it. + if (!editedMessage) + { + return null; + } + + return Strings.join(messageWords, " "); + } +} diff --git a/src/main/java/com/github/dappermickie/odablock/livestreams/LivestreamManager.java b/src/main/java/com/github/dappermickie/odablock/livestreams/LivestreamManager.java index b5b19f9..d79483a 100644 --- a/src/main/java/com/github/dappermickie/odablock/livestreams/LivestreamManager.java +++ b/src/main/java/com/github/dappermickie/odablock/livestreams/LivestreamManager.java @@ -129,23 +129,23 @@ private void sendLivestreamMessage(boolean force) String message; if (livestream.getKick().isLive()) { + final String title = livestream.getKick().getTitle().split("\\|")[0].trim(); chatMessage - .append(ChatColorType.HIGHLIGHT) - .append("Odablock") .append(ChatColorType.NORMAL) - .append(" is live on ") + .append("Odablock is live on ") .append(ChatColorType.HIGHLIGHT) .append("KICK") .append(ChatColorType.NORMAL) .append("! ") .append(ChatColorType.HIGHLIGHT) - .append(livestream.getKick().getTitle()); + .append(title); message = chatMessage.build().replaceAll("colHIGHLIGHT", "col=" + hex); RightClickAction rightClickAction = new RightClickAction("Open Kick Stream", "https://kick.com/odablock"); chatRightClickManager.putInMap(message, rightClickAction); } else if (livestream.getTwitch().isLive()) { + final String title = livestream.getTwitch().getTitle().split("\\|")[0].trim(); chatMessage.append(ChatColorType.NORMAL) .append("Odablock is live on ") .append(ChatColorType.HIGHLIGHT) @@ -153,7 +153,7 @@ else if (livestream.getTwitch().isLive()) .append(ChatColorType.NORMAL) .append("! ") .append(ChatColorType.HIGHLIGHT) - .append(livestream.getKick().getTitle()); + .append(title); message = chatMessage.build().replaceAll("colHIGHLIGHT", "col=" + hex); RightClickAction rightClickAction = new RightClickAction("Open Twitch Stream", "https://twitch.tv/odablock"); chatRightClickManager.putInMap(message, rightClickAction); diff --git a/src/main/resources/com/github/dappermickie/odablock/emotes/aiaiai.gif b/src/main/resources/com/github/dappermickie/odablock/emotes/aiaiai.gif new file mode 100644 index 0000000..89e0067 Binary files /dev/null and b/src/main/resources/com/github/dappermickie/odablock/emotes/aiaiai.gif differ diff --git a/src/main/resources/com/github/dappermickie/odablock/emotes/awkward.gif b/src/main/resources/com/github/dappermickie/odablock/emotes/awkward.gif new file mode 100644 index 0000000..f882105 Binary files /dev/null and b/src/main/resources/com/github/dappermickie/odablock/emotes/awkward.gif differ diff --git a/src/main/resources/com/github/dappermickie/odablock/emotes/fufu.gif b/src/main/resources/com/github/dappermickie/odablock/emotes/fufu.gif new file mode 100644 index 0000000..d97d184 Binary files /dev/null and b/src/main/resources/com/github/dappermickie/odablock/emotes/fufu.gif differ diff --git a/src/main/resources/com/github/dappermickie/odablock/emotes/gneah.png b/src/main/resources/com/github/dappermickie/odablock/emotes/gneah.png new file mode 100644 index 0000000..f48c697 Binary files /dev/null and b/src/main/resources/com/github/dappermickie/odablock/emotes/gneah.png differ diff --git a/src/main/resources/com/github/dappermickie/odablock/emotes/huh.png b/src/main/resources/com/github/dappermickie/odablock/emotes/huh.png new file mode 100644 index 0000000..36f5497 Binary files /dev/null and b/src/main/resources/com/github/dappermickie/odablock/emotes/huh.png differ diff --git a/src/main/resources/com/github/dappermickie/odablock/emotes/hyperwankge.gif b/src/main/resources/com/github/dappermickie/odablock/emotes/hyperwankge.gif new file mode 100644 index 0000000..2535c28 Binary files /dev/null and b/src/main/resources/com/github/dappermickie/odablock/emotes/hyperwankge.gif differ diff --git a/src/main/resources/com/github/dappermickie/odablock/emotes/janitor.png b/src/main/resources/com/github/dappermickie/odablock/emotes/janitor.png new file mode 100644 index 0000000..5e8300d Binary files /dev/null and b/src/main/resources/com/github/dappermickie/odablock/emotes/janitor.png differ diff --git a/src/main/resources/com/github/dappermickie/odablock/emotes/kek.gif b/src/main/resources/com/github/dappermickie/odablock/emotes/kek.gif new file mode 100644 index 0000000..7de8c27 Binary files /dev/null and b/src/main/resources/com/github/dappermickie/odablock/emotes/kek.gif differ diff --git a/src/main/resources/com/github/dappermickie/odablock/emotes/kiss.png b/src/main/resources/com/github/dappermickie/odablock/emotes/kiss.png new file mode 100644 index 0000000..9d76dfe Binary files /dev/null and b/src/main/resources/com/github/dappermickie/odablock/emotes/kiss.png differ diff --git a/src/main/resources/com/github/dappermickie/odablock/emotes/noway.png b/src/main/resources/com/github/dappermickie/odablock/emotes/noway.png new file mode 100644 index 0000000..2fdc4db Binary files /dev/null and b/src/main/resources/com/github/dappermickie/odablock/emotes/noway.png differ diff --git a/src/main/resources/com/github/dappermickie/odablock/emotes/odawhat.png b/src/main/resources/com/github/dappermickie/odablock/emotes/odawhat.png new file mode 100644 index 0000000..dd814e1 Binary files /dev/null and b/src/main/resources/com/github/dappermickie/odablock/emotes/odawhat.png differ diff --git a/src/main/resources/com/github/dappermickie/odablock/emotes/pface.gif b/src/main/resources/com/github/dappermickie/odablock/emotes/pface.gif new file mode 100644 index 0000000..3b812df Binary files /dev/null and b/src/main/resources/com/github/dappermickie/odablock/emotes/pface.gif differ diff --git a/src/main/resources/com/github/dappermickie/odablock/emotes/rly.gif b/src/main/resources/com/github/dappermickie/odablock/emotes/rly.gif new file mode 100644 index 0000000..99a4fbb Binary files /dev/null and b/src/main/resources/com/github/dappermickie/odablock/emotes/rly.gif differ diff --git a/src/main/resources/com/github/dappermickie/odablock/emotes/smile.gif b/src/main/resources/com/github/dappermickie/odablock/emotes/smile.gif new file mode 100644 index 0000000..9ef0422 Binary files /dev/null and b/src/main/resources/com/github/dappermickie/odablock/emotes/smile.gif differ diff --git a/src/main/resources/com/github/dappermickie/odablock/emotes/tune.gif b/src/main/resources/com/github/dappermickie/odablock/emotes/tune.gif new file mode 100644 index 0000000..673c26a Binary files /dev/null and b/src/main/resources/com/github/dappermickie/odablock/emotes/tune.gif differ diff --git a/src/main/resources/com/github/dappermickie/odablock/emotes/whenitregisters.gif b/src/main/resources/com/github/dappermickie/odablock/emotes/whenitregisters.gif new file mode 100644 index 0000000..54cd2af Binary files /dev/null and b/src/main/resources/com/github/dappermickie/odablock/emotes/whenitregisters.gif differ diff --git a/src/main/resources/com/github/dappermickie/odablock/emotes/wink.png b/src/main/resources/com/github/dappermickie/odablock/emotes/wink.png new file mode 100644 index 0000000..985cddd Binary files /dev/null and b/src/main/resources/com/github/dappermickie/odablock/emotes/wink.png differ