aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal002@users.noreply.github.com>2022-11-01 23:16:54 +0100
committerGitHub <noreply@github.com>2022-11-01 23:16:54 +0100
commit797b858e27c5e3c502e35f8fca74ee06f31e04a7 (patch)
tree24433270a0978588763878843e77dc10f9945062 /src/main
parente42dd2aa0a2e0a988e820e1ceb13cf2bc30ba987 (diff)
downloadNotEnoughUpdates-797b858e27c5e3c502e35f8fca74ee06f31e04a7.tar.gz
NotEnoughUpdates-797b858e27c5e3c502e35f8fca74ee06f31e04a7.tar.bz2
NotEnoughUpdates-797b858e27c5e3c502e35f8fca74ee06f31e04a7.zip
Prevents wrong coopadd commands (#412)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java2
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AntiCoopAdd.java18
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinNetHandlerPlayClient.java4
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java2
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 <name>");
+ 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;