From 7624f7ad105bd5ae414b3bed2c5a45881e0e0c13 Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 25 Mar 2023 22:50:42 +0000 Subject: [PATCH] cleaned up stuff --- .../cc/fascinated/wildaddons/addon/Addon.java | 16 +++---- .../wildaddons/addon/AddonManager.java | 40 +++++++++------- .../addon/impl/chat/ChatGameHelperAddon.java | 47 +++++++++++++++++++ .../addon/impl/chat/MessageFilterAddon.java | 18 +++++-- .../addon/impl/ui/OverlayAddon.java | 8 +--- .../wildaddons/listener/ArmorListener.java | 2 +- .../listener/ResearchTasksListener.java | 3 -- .../wildaddons/mixin/ChatHudMixin.java | 5 ++ .../wildaddons/mixin/PlayerListGuiMixin.java | 2 - .../wildaddons/tpsmonitor/TpsMonitor.java | 1 + 10 files changed, 102 insertions(+), 40 deletions(-) create mode 100644 src/main/java/cc/fascinated/wildaddons/addon/impl/chat/ChatGameHelperAddon.java diff --git a/src/main/java/cc/fascinated/wildaddons/addon/Addon.java b/src/main/java/cc/fascinated/wildaddons/addon/Addon.java index 78a7595..d8cadfe 100644 --- a/src/main/java/cc/fascinated/wildaddons/addon/Addon.java +++ b/src/main/java/cc/fascinated/wildaddons/addon/Addon.java @@ -7,9 +7,14 @@ import lombok.Getter; @Getter public abstract class Addon implements EventListener { + public enum Category { + CHAT, + UI + } private final String name; private final String description; private final Category category; + private boolean enabled; public Addon(String name, String description, Category category) { @@ -19,12 +24,7 @@ public abstract class Addon implements EventListener { this.enabled = true; EventManager.registerListener(this); - onEnable(); - } - - public enum Category { - CHAT, - UI + this.onEnable(); } /** @@ -34,9 +34,9 @@ public abstract class Addon implements EventListener { this.enabled = !this.enabled; if (this.enabled) { - onDisable(); + this.onDisable(); } else { - onEnable(); + this.onEnable(); } } diff --git a/src/main/java/cc/fascinated/wildaddons/addon/AddonManager.java b/src/main/java/cc/fascinated/wildaddons/addon/AddonManager.java index 4d9a90d..517d73b 100644 --- a/src/main/java/cc/fascinated/wildaddons/addon/AddonManager.java +++ b/src/main/java/cc/fascinated/wildaddons/addon/AddonManager.java @@ -1,12 +1,13 @@ package cc.fascinated.wildaddons.addon; -import cc.fascinated.wildaddons.addon.impl.chat.AutoWelcomerAddon; -import cc.fascinated.wildaddons.addon.impl.chat.MessageFilterAddon; -import cc.fascinated.wildaddons.addon.impl.ui.OverlayAddon; - import java.util.HashSet; import java.util.Set; +import cc.fascinated.wildaddons.addon.impl.chat.AutoWelcomerAddon; +import cc.fascinated.wildaddons.addon.impl.chat.ChatGameHelperAddon; +import cc.fascinated.wildaddons.addon.impl.chat.MessageFilterAddon; +import cc.fascinated.wildaddons.addon.impl.ui.OverlayAddon; + public class AddonManager { /** @@ -14,10 +15,26 @@ public class AddonManager { */ public static final Set ADDONS = new HashSet<>(); + /** + * Checks if the addon is enabled + * + * @param clazz the class of the addon + * @return true if the addon is enabled, false otherwise + */ + public static boolean isEnabled(Class clazz) { + for (Addon addon : ADDONS) { + if (addon.getClass().equals(clazz)) { + return addon.isEnabled(); + } + } + return false; + } + public AddonManager() { - registerAddon(new AutoWelcomerAddon()); - registerAddon(new OverlayAddon()); - registerAddon(new MessageFilterAddon()); + this.registerAddon(new AutoWelcomerAddon()); + this.registerAddon(new OverlayAddon()); + this.registerAddon(new MessageFilterAddon()); + this.registerAddon(new ChatGameHelperAddon()); } /** @@ -28,13 +45,4 @@ public class AddonManager { public void registerAddon(Addon addon) { ADDONS.add(addon); } - - public static boolean isEnabled(Class clazz) { - for (Addon addon : ADDONS) { - if (addon.getClass() == clazz) { - return addon.isEnabled(); - } - } - return false; - } } diff --git a/src/main/java/cc/fascinated/wildaddons/addon/impl/chat/ChatGameHelperAddon.java b/src/main/java/cc/fascinated/wildaddons/addon/impl/chat/ChatGameHelperAddon.java new file mode 100644 index 0000000..2dcccef --- /dev/null +++ b/src/main/java/cc/fascinated/wildaddons/addon/impl/chat/ChatGameHelperAddon.java @@ -0,0 +1,47 @@ +package cc.fascinated.wildaddons.addon.impl.chat; + +import cc.fascinated.wildaddons.Main; +import cc.fascinated.wildaddons.addon.Addon; +import net.minecraft.text.MutableText; +import net.minecraft.text.Text; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +public class ChatGameHelperAddon extends Addon { + + public ChatGameHelperAddon() { + super("Chat Game Helper", "Calculates the answers for Chat Games", Category.CHAT); + } + + @Override + public void onChat(String message, String messageStripped, CallbackInfo ci) { + if (!messageStripped.startsWith("✎ MATHS » First player to calculate")) { // Check if the message is a maths chat game + return; + } + ci.cancel(); + + String[] parts = message.split(" "); + try { + int first = Integer.parseInt(parts[7]); + String mathExpression = parts[8]; + int second = Integer.parseInt(parts[9]); + int answer = 0; + + if (mathExpression.equals("*")) { + answer = first * second; + } + if (mathExpression.equals("+")) { + answer = first + second; + } + if (mathExpression.equals("-")) { + answer = first - second; + } + if (mathExpression.equals("/")) { + answer = first / second; + } + + Main.getMinecraftClient().inGameHud.getChatHud().addToMessageHistory(message + " §[Answer: " + answer + "]"); + } catch (Exception ex) { + ex.printStackTrace(); + } + } +} diff --git a/src/main/java/cc/fascinated/wildaddons/addon/impl/chat/MessageFilterAddon.java b/src/main/java/cc/fascinated/wildaddons/addon/impl/chat/MessageFilterAddon.java index 3c03635..5e19d71 100644 --- a/src/main/java/cc/fascinated/wildaddons/addon/impl/chat/MessageFilterAddon.java +++ b/src/main/java/cc/fascinated/wildaddons/addon/impl/chat/MessageFilterAddon.java @@ -1,5 +1,6 @@ package cc.fascinated.wildaddons.addon.impl.chat; +import cc.fascinated.wildaddons.Main; import cc.fascinated.wildaddons.addon.Addon; import cc.fascinated.wildaddons.statistic.Statistic; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -17,21 +18,30 @@ public class MessageFilterAddon extends Addon { //"has just won a", "+ KeyFinder", "ALERT", - "WILDPASS", - "VALUE", - "----------------------------------------------------" + "WILDPASS" ); + private String lastMessage = null; + public MessageFilterAddon() { super("Chat Filter", "Removes all the junk messages from chat.", Category.CHAT); } @Override public void onChat(String message, String messageStripped, CallbackInfo ci) { - if (message.equals("")) { + Main.getMinecraftClient().inGameHud.getChatHud().addToMessageHistory(""); + if (lastMessage != null && lastMessage.equals(message)) { // Fixes double new lines for certain messages ci.cancel(); return; } + lastMessage = message; + + if (messageStripped.equals("----------------------------------------------------")) { + ci.cancel(); + Main.getMinecraftClient().inGameHud.getChatHud().addToMessageHistory(""); + return; + } + for (String check : toRemove) { if (messageStripped.startsWith(check)) { ci.cancel(); diff --git a/src/main/java/cc/fascinated/wildaddons/addon/impl/ui/OverlayAddon.java b/src/main/java/cc/fascinated/wildaddons/addon/impl/ui/OverlayAddon.java index 104bd14..8103391 100644 --- a/src/main/java/cc/fascinated/wildaddons/addon/impl/ui/OverlayAddon.java +++ b/src/main/java/cc/fascinated/wildaddons/addon/impl/ui/OverlayAddon.java @@ -4,21 +4,17 @@ import cc.fascinated.wildaddons.Main; import cc.fascinated.wildaddons.addon.Addon; import cc.fascinated.wildaddons.listener.ActivePotionsListener; import cc.fascinated.wildaddons.listener.ArmorListener; -import cc.fascinated.wildaddons.listener.PlayerListener; import cc.fascinated.wildaddons.listener.ResearchTasksListener; import cc.fascinated.wildaddons.statistic.Statistic; import cc.fascinated.wildaddons.tpsmonitor.TpsMonitor; import cc.fascinated.wildaddons.utils.GameUtils; import cc.fascinated.wildaddons.utils.NumberUtils; import cc.fascinated.wildaddons.utils.PlayerUtils; -import lombok.Getter; import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; -import java.util.LinkedHashSet; import java.util.Map; -import java.util.Set; public class OverlayAddon extends Addon { @@ -28,8 +24,8 @@ public class OverlayAddon extends Addon { @Override public void onEnable() { - HudRenderCallback.EVENT.register((matrixStack, somefloatidkwhatitdoes) -> { - if (!this.isEnabled() || Main.getMinecraftClient().options.debugEnabled) { // Check if module is enabled or, if f3 debug menu is open + HudRenderCallback.EVENT.register((matrixStack, yes) -> { + if (!this.isEnabled() || Main.getMinecraftClient().options.debugEnabled) { // Check if module is enabled or if f3 debug menu is open return; } int lastY = 5; diff --git a/src/main/java/cc/fascinated/wildaddons/listener/ArmorListener.java b/src/main/java/cc/fascinated/wildaddons/listener/ArmorListener.java index dc584fa..22d7472 100644 --- a/src/main/java/cc/fascinated/wildaddons/listener/ArmorListener.java +++ b/src/main/java/cc/fascinated/wildaddons/listener/ArmorListener.java @@ -21,7 +21,7 @@ public class ArmorListener implements EventListener { /** * The current multipliers from armor */ - @Getter private static Map armorMultipliers = new HashMap<>(); + @Getter private static final Map armorMultipliers = new HashMap<>(); @Override public void onTick(int ticksPassed) { diff --git a/src/main/java/cc/fascinated/wildaddons/listener/ResearchTasksListener.java b/src/main/java/cc/fascinated/wildaddons/listener/ResearchTasksListener.java index ed7d5ff..378d774 100644 --- a/src/main/java/cc/fascinated/wildaddons/listener/ResearchTasksListener.java +++ b/src/main/java/cc/fascinated/wildaddons/listener/ResearchTasksListener.java @@ -1,11 +1,8 @@ package cc.fascinated.wildaddons.listener; -import cc.fascinated.wildaddons.Main; import cc.fascinated.wildaddons.event.EventListener; -import cc.fascinated.wildaddons.utils.PlayerUtils; import cc.fascinated.wildaddons.utils.TextUtils; import lombok.Getter; -import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.text.Text; import java.util.LinkedHashSet; diff --git a/src/main/java/cc/fascinated/wildaddons/mixin/ChatHudMixin.java b/src/main/java/cc/fascinated/wildaddons/mixin/ChatHudMixin.java index ade065d..dbec011 100644 --- a/src/main/java/cc/fascinated/wildaddons/mixin/ChatHudMixin.java +++ b/src/main/java/cc/fascinated/wildaddons/mixin/ChatHudMixin.java @@ -5,14 +5,19 @@ import cc.fascinated.wildaddons.event.EventManager; import cc.fascinated.wildaddons.utils.PlayerUtils; import cc.fascinated.wildaddons.utils.TextUtils; import net.minecraft.client.gui.hud.ChatHud; +import net.minecraft.client.gui.hud.ChatHudLine; import net.minecraft.client.gui.hud.MessageIndicator; import net.minecraft.network.message.MessageSignatureData; import net.minecraft.text.Text; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import java.util.List; + @Mixin(ChatHud.class) public class ChatHudMixin { diff --git a/src/main/java/cc/fascinated/wildaddons/mixin/PlayerListGuiMixin.java b/src/main/java/cc/fascinated/wildaddons/mixin/PlayerListGuiMixin.java index 3c60f11..7b5b5a5 100644 --- a/src/main/java/cc/fascinated/wildaddons/mixin/PlayerListGuiMixin.java +++ b/src/main/java/cc/fascinated/wildaddons/mixin/PlayerListGuiMixin.java @@ -1,9 +1,7 @@ package cc.fascinated.wildaddons.mixin; -import cc.fascinated.wildaddons.addon.impl.ui.OverlayAddon; import cc.fascinated.wildaddons.event.EventListener; import cc.fascinated.wildaddons.event.EventManager; -import cc.fascinated.wildaddons.utils.TextUtils; import net.minecraft.client.gui.hud.PlayerListHud; import net.minecraft.text.Text; import org.spongepowered.asm.mixin.Mixin; diff --git a/src/main/java/cc/fascinated/wildaddons/tpsmonitor/TpsMonitor.java b/src/main/java/cc/fascinated/wildaddons/tpsmonitor/TpsMonitor.java index 3f0901f..c846ccd 100644 --- a/src/main/java/cc/fascinated/wildaddons/tpsmonitor/TpsMonitor.java +++ b/src/main/java/cc/fascinated/wildaddons/tpsmonitor/TpsMonitor.java @@ -8,6 +8,7 @@ import net.minecraft.network.packet.s2c.play.WorldTimeUpdateS2CPacket; public class TpsMonitor implements EventListener { + @SuppressWarnings("UnstableApiUsage") private static final EvictingQueue serverTPS = EvictingQueue.create(3); private static long systemTime = 0; private static long worldTicks = 0;