aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/Danker/features/ChatAliases.java
diff options
context:
space:
mode:
authorbowser0000 <bowser0000@gmail.com>2022-08-15 20:40:34 -0400
committerGitHub <noreply@github.com>2022-08-15 20:40:34 -0400
commit3aa11b859a2a22be30a5035f7273e1a604a4dde4 (patch)
tree8f428b29a6b56cc9d010b0441bf41b6b78373548 /src/main/java/me/Danker/features/ChatAliases.java
parent33710ac6d9f57fa59e8dfb19a81b053346f1b097 (diff)
parentdaceea1e42371c295c36f80b3246601a6ffb2cc5 (diff)
downloadSkyblockMod-1.8.7.tar.gz
SkyblockMod-1.8.7.tar.bz2
SkyblockMod-1.8.7.zip
Merge pull request #124 from bowser0000/developmentHEADv1.8.7master
1.8.7
Diffstat (limited to 'src/main/java/me/Danker/features/ChatAliases.java')
-rw-r--r--src/main/java/me/Danker/features/ChatAliases.java70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/main/java/me/Danker/features/ChatAliases.java b/src/main/java/me/Danker/features/ChatAliases.java
new file mode 100644
index 0000000..76ab5f6
--- /dev/null
+++ b/src/main/java/me/Danker/features/ChatAliases.java
@@ -0,0 +1,70 @@
+package me.Danker.features;
+
+import com.google.gson.GsonBuilder;
+import me.Danker.events.ModInitEvent;
+import me.Danker.events.PacketWriteEvent;
+import net.minecraft.client.Minecraft;
+import net.minecraft.network.play.client.C01PacketChatMessage;
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
+
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class ChatAliases {
+
+ public static List<Alias> aliases = new ArrayList<>();
+ public static String configFile;
+
+ @SubscribeEvent
+ public void init(ModInitEvent event) {
+ configFile = event.configDirectory + "/dsmaliases.json";
+ }
+
+ @SubscribeEvent
+ public void onPacketWrite(PacketWriteEvent event) {
+ if (event.packet instanceof C01PacketChatMessage) {
+ C01PacketChatMessage packet = (C01PacketChatMessage) event.packet;
+ String message = packet.getMessage();
+
+ for (Alias alias : aliases) {
+ if (!alias.toggled) continue;
+ message = message.replace(alias.text, alias.alias);
+ }
+
+ if (!packet.getMessage().equals(message)) {
+ event.setCanceled(true);
+ Minecraft.getMinecraft().thePlayer.sendQueue.addToSendQueue(new C01PacketChatMessage(message));
+ }
+ }
+ }
+
+ public static void save() {
+ try (FileWriter writer = new FileWriter(configFile)) {
+ new GsonBuilder().create().toJson(aliases, writer);
+ writer.flush();
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ }
+ }
+
+ public static class Alias {
+
+ public String text;
+ public String alias;
+ public boolean toggled;
+
+ public Alias(String text, String alias, boolean toggled) {
+ this.text = text;
+ this.alias = alias;
+ this.toggled = toggled;
+ }
+
+ public void toggle() {
+ toggled = !toggled;
+ }
+
+ }
+
+}