javadiscordminecraftbungeecord

Java - emoji4j static method call ends/vanishes/dies without error


I am writing a plugin which takes a message from discord and sends it to a minecraft server. Minecraft clients have a hard time rendering emojis. Therefore I opted to use https://github.com/kcthota/emoji4j to convert all emojis into their shortcodes (example: 😃 -> :smile: ..or similar)

The problem:

When calling the static method shortCodify it never returns. Almost as if it kills the code where it is and never continues. No errors in console.

It almost seems as though calling the method kills it right there. Step 1 is never printed.

It is able to run through this multiple times (every time I send a discord message). It has not killed the process completely.

I have tried:

Adding the debug prints all over the place to try to track down the issue.

PS: don't hate me for mixing logger.info and system println, I am removing all of this later xD

Console output

13:35:48 [INFO] [Core] Emoji manager exists.

13:35:48 [INFO] [Core] Attempting shortcodify (contains 1738 emojis)

13:35:48 [INFO] DEBUG: EventChat.java step 0

Yes.... it stops there!

Code snippets:

My code / EventChat.java

Note: msg is a String

The if statement (of which you see the else) just checks that the emoji data was loaded, because I ran the config loading in a separate thread. Knowing it is able to get to here and prints that the data exists, this is not the problem.

...
      } else {
        logger.info("Emoji manager exists.");
        try {
          logger.info("Attempting shortcodify (contains " + EmojiManager.data().size() + " emojis)");
          System.out.println("DEBUG: EventChat.java step 0");
          msg = EmojiUtils.shortCodify(msg);
          logger.info("new message: " + msg);
        } catch (Exception e) {
          logger.info("Catching exception");
          e.printStackTrace();
        }
      }
      logger.info("Emoji processed.");

Emoji4j / EmojiUtils.java

public static String shortCodify(String text) {
    System.out.println("DEBUG: EmojiUtils.java step 1");
    String emojifiedText = emojify(text);
    System.out.println("DEBUG: EmojiUtils.java step 2");

    
    for (Emoji emoji : EmojiManager.data()) {
        StringBuilder shortCodeBuilder = new StringBuilder();
        shortCodeBuilder.append(":").append(emoji.getAliases().get(0)).append(":");

        emojifiedText = emojifiedText.replace(emoji.getEmoji(), shortCodeBuilder.toString());
        System.out.println("DEBUG: EmojiUtils.java step 2.loop");
    }
    System.out.println("DEBUG: EmojiUtils.java step 3");
    return emojifiedText;
}

Solution

  • I found the answer after what seems to be wayyy too long. (yes, 2 months lol)

    NOTE: this only applies to anyone using JDA with emoji4j

    JDA catches all Throwables by default and attempts to log it to the console but fails due to bungeecord not using the same logger (or something similar, I don't really know why).

    I wasn't too stupid, as I tried catching all exceptions and logging them. BUT it was throwing a throwable instead of an exception.... for whatever reason...

    So, long story short, I was catching excpetions and JDA was catching the Throwable that indicated the missing dependency and making the error vanish instead of printing to console.

    Fix

    try {
    
    } catch (Throwable t) {
      // error is now caught and can be logged using bungee's logger
    }