Skip to content

Commit

Permalink
V1.1.1 (#61)
Browse files Browse the repository at this point in the history
* Added chat emotes (#54)

* Twitch title now showing (#55)

* Bump version to 1.1.1

* Added emote list (#56)

Added emotes list ::odaemotes
Added better handling of emotes, more options per emote

* Send splitted title (#57)

* Fix highlighting (#58)

* Updated 'linked' chatbox text behavior (#59)

Fixes issues with not being able to scroll if you're hovering over the text with link (notifications/livestream notifications).
Always have to right click open stream/link.
You can now click through the link if you have a transparent chatbox.
  • Loading branch information
DapperMickie authored May 26, 2024
1 parent 1d14cb0 commit 2a986da
Show file tree
Hide file tree
Showing 23 changed files with 274 additions and 9 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/github/dappermickie/odablock/OdablockPlugin.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -49,13 +50,15 @@
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;
import net.runelite.api.events.GameTick;
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;
Expand Down Expand Up @@ -214,6 +217,9 @@ public class OdablockPlugin extends Plugin
@Inject
private ChatRightClickManager chatRightClickManager;

@Inject
private EmoteHandler emoteHandler;

@Inject
@Named("developerMode")
private boolean developerMode;
Expand All @@ -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();
Expand Down Expand Up @@ -303,6 +310,8 @@ public void onActorDeath(ActorDeath actorDeath)
@Subscribe
public void onChatMessage(ChatMessage chatMessage)
{
emoteHandler.onChatMessage(chatMessage);

if (acceptTrade.onChatMessage(chatMessage))
{
return;
Expand Down Expand Up @@ -350,6 +359,11 @@ else if (coxSounds.onChatMessage(chatMessage))
}
}

@Subscribe
private void onOverheadTextChanged(OverheadTextChanged event)
{
emoteHandler.onOverheadTextChanged(event);
}

@Subscribe
public void onVarbitChanged(VarbitChanged event)
Expand Down Expand Up @@ -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;
Expand Down
85 changes: 85 additions & 0 deletions src/main/java/com/github/dappermickie/odablock/emotes/Emote.java
Original file line number Diff line number Diff line change
@@ -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<String, Emote> 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<String, Emote> 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);
}
}
Original file line number Diff line number Diff line change
@@ -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 = "<img=" + chatIconManager.chatIconIndex(emoteId) + ">";
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 <lt> and <gt>
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, "<img=" + chatIconManager.chatIconIndex(emoteId) + ">");
editedMessage = true;
}

// If we haven't edited the message any, don't update it.
if (!editedMessage)
{
return null;
}

return Strings.join(messageWords, " ");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,31 +129,31 @@ 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)
.append("TWITCH")
.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);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2a986da

Please sign in to comment.