From 797b858e27c5e3c502e35f8fca74ee06f31e04a7 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Tue, 1 Nov 2022 23:16:54 +0100 Subject: Prevents wrong coopadd commands (#412) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../moulberry/notenoughupdates/NotEnoughUpdates.java | 2 +- .../notenoughupdates/miscfeatures/AntiCoopAdd.java | 18 ++++++++++++++++++ .../mixins/MixinNetHandlerPlayClient.java | 4 ++++ .../options/seperateSections/Misc.java | 2 +- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java index b514e419..fb6e0901 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java @@ -318,7 +318,7 @@ public class NotEnoughUpdates { MinecraftForge.EVENT_BUS.register(new SignCalculator()); MinecraftForge.EVENT_BUS.register(TrophyRewardOverlay.getInstance()); MinecraftForge.EVENT_BUS.register(PowerStoneStatsDisplay.getInstance()); - MinecraftForge.EVENT_BUS.register(new AntiCoopAdd()); + MinecraftForge.EVENT_BUS.register(AntiCoopAdd.getInstance()); MinecraftForge.EVENT_BUS.register(AbiphoneWarning.getInstance()); MinecraftForge.EVENT_BUS.register(new BetterContainers()); MinecraftForge.EVENT_BUS.register(AuctionBINWarning.getInstance()); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AntiCoopAdd.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AntiCoopAdd.java index 70ac4489..aaa13d39 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AntiCoopAdd.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AntiCoopAdd.java @@ -27,12 +27,19 @@ import net.minecraft.event.ClickEvent; import net.minecraft.event.HoverEvent; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; +import net.minecraft.network.play.client.C01PacketChatMessage; import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; public class AntiCoopAdd { + private static final AntiCoopAdd INSTANCE = new AntiCoopAdd(); + + public static AntiCoopAdd getInstance() { + return INSTANCE; + } + @SubscribeEvent public void onMouseClick(SlotClickEvent event) { if (!NotEnoughUpdates.INSTANCE.config.misc.coopWarning) return; @@ -59,4 +66,15 @@ public class AntiCoopAdd { event.setCanceled(true); } } + + public Boolean onPacketChatMessage(C01PacketChatMessage packet) { + if (!NotEnoughUpdates.INSTANCE.config.misc.coopWarning) return false; + + String message = packet.getMessage().toLowerCase(); + if (message.startsWith("/hypixelcommand:coopadd")) { + Utils.addChatMessage("§e[NEU] You just entered a malicious looking Co-op add command! If you truly want to add someone to your coop, type §e/coopadd "); + return true; + } + return false; + } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinNetHandlerPlayClient.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinNetHandlerPlayClient.java index 0b33609d..e47b03df 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinNetHandlerPlayClient.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinNetHandlerPlayClient.java @@ -19,6 +19,7 @@ package io.github.moulberry.notenoughupdates.mixins; +import io.github.moulberry.notenoughupdates.miscfeatures.AntiCoopAdd; import io.github.moulberry.notenoughupdates.miscfeatures.CrystalWishingCompassSolver; import io.github.moulberry.notenoughupdates.miscfeatures.CustomItemEffects; import io.github.moulberry.notenoughupdates.miscfeatures.EnchantingSolvers; @@ -133,6 +134,9 @@ public class MixinNetHandlerPlayClient { } if (packet instanceof C01PacketChatMessage) { NewApiKeyHelper.getInstance().hookPacketChatMessage((C01PacketChatMessage) packet); + if (AntiCoopAdd.getInstance().onPacketChatMessage((C01PacketChatMessage) packet)) { + ci.cancel(); + } } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java index 78bb0f95..dbf79bce 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java @@ -262,7 +262,7 @@ public class Misc { @Expose @ConfigOption( name = "Enable Coop Warning", - desc = "Asks for confirmation when clicking the coop diamond in profile menu" + desc = "Asks for confirmation when clicking the coop diamond in profile menu and prevents 'wrong' /coopadd commands" ) @ConfigEditorBoolean public boolean coopWarning = true; -- cgit