Skip to content

Commit

Permalink
fix: message replacer
Browse files Browse the repository at this point in the history
  • Loading branch information
darksaid98 committed Jul 10, 2024
1 parent 2a8834a commit 1a4eaf6
Showing 1 changed file with 33 additions and 50 deletions.
83 changes: 33 additions & 50 deletions src/main/java/me/ShermansWorld/AlathraExtras/chat/ChatListener.java
Original file line number Diff line number Diff line change
@@ -1,61 +1,44 @@
package me.ShermansWorld.AlathraExtras.chat;

import io.papermc.paper.event.player.AsyncChatEvent;
import me.ShermansWorld.AlathraExtras.Helper;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;

public class ChatListener implements Listener {
import java.util.HashMap;
import java.util.Map;

public class ChatListener implements Listener {
private static final PlainTextComponentSerializer plainText = PlainTextComponentSerializer.plainText();
private static final Map<String, String> replacements;
static {
replacements = new HashMap<>();
replacements.put("(?i)stoneworks", "rock function ");
replacements.put("(?i)stone works", "rock function ");
replacements.put("(?i)stonework", "rock function ");
replacements.put("(?i)\\ssw\\s", "rock function ");
replacements.put("(?i)shears", "✂");
replacements.put("(?i)o_o", Helper.color("&9&lO_O&r"));
replacements.put("->", "➡");
replacements.put("<-", "⬅");
replacements.put(":\\)", "☺");
replacements.put(":\\(", "☹");
replacements.put("~~", "〰");
replacements.put("<3", Helper.color("&c❤&r"));
replacements.put("(?i)\\^up", "⬆");
replacements.put("<>", Helper.color("&a♢&r"));
replacements.put("(?i)o==", Helper.color("&b☄&r"));
}

@EventHandler
public void chatReplace(AsyncPlayerChatEvent e) {
if (e.getMessage().toLowerCase().contains("stoneworks")) {
e.setMessage(e.getMessage().toLowerCase().replace("stoneworks", "rock function "));
}
if (e.getMessage().toLowerCase().contains("stone works")) {
e.setMessage(e.getMessage().toLowerCase().replace("stone works", "rock function "));
}
if (e.getMessage().toLowerCase().contains("stonework")) {
e.setMessage(e.getMessage().toLowerCase().replace("stonework", "rock function "));
}
if (e.getMessage().toLowerCase().contains(" sw ")) {
e.setMessage(e.getMessage().toLowerCase().replace(" sw ", "rock function "));
}
if (e.getMessage().toLowerCase().contains("shears")) {
e.setMessage(e.getMessage().toLowerCase().replace("shears", "✂"));
}
if (e.getMessage().toLowerCase().contains("o_o")) {
e.setMessage(e.getMessage().replace("o_o", Helper.color("&9&lO_O&r")));
}
if (e.getMessage().toLowerCase().contains("->")) {
e.setMessage(e.getMessage().replace("->", "➡"));
}
if (e.getMessage().toLowerCase().contains("<-")) {
e.setMessage(e.getMessage().replace("<-", "⬅"));
}
if (e.getMessage().toLowerCase().contains(":)")) {
e.setMessage(e.getMessage().replace(":)", "☺"));
}
if (e.getMessage().toLowerCase().contains(":(")) {
e.setMessage(e.getMessage().replace(":(", "☹"));
}
if (e.getMessage().toLowerCase().contains("~~")) {
e.setMessage(e.getMessage().replace("~~", "〰"));
}
if (e.getMessage().toLowerCase().contains("<3")) {
e.setMessage(e.getMessage().replace("<3", Helper.color("&c❤&r")));
}
if (e.getMessage().toLowerCase().contains("<>")) {
e.setMessage(e.getMessage().replace("<>", Helper.color("&a♢&r")));
}
if (e.getMessage().toLowerCase().contains("^up")) {
e.setMessage(e.getMessage().toLowerCase().replace("^up", "⬆"));
}
if (e.getMessage().toLowerCase().contains("<>")) {
e.setMessage(e.getMessage().replace("<>", Helper.color("&a♢&r")));
}
if (e.getMessage().toLowerCase().contains("o==")) {
e.setMessage(e.getMessage().replace("o==", Helper.color("&b☄&r")));
public void chatReplace(AsyncChatEvent e) {
String msg = plainText.serialize(e.message());

for (String s : replacements.keySet()) {
msg = msg.replaceAll(s, replacements.get(s));
}

e.message(plainText.deserialize(msg));
}
}

0 comments on commit 1a4eaf6

Please sign in to comment.