From 90b552d27cd52d045fa6b5243d014ce1f917cd78 Mon Sep 17 00:00:00 2001 From: NopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com> Date: Fri, 23 Sep 2022 01:51:29 +1000 Subject: anti coop add button in profile viewer (#296) --- .../notenoughupdates/miscfeatures/AntiCoopAdd.java | 62 ++++++++++++++++++++++ .../notenoughupdates/mixins/MixinGuiContainer.java | 8 ++- .../options/seperateSections/Misc.java | 8 +++ 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AntiCoopAdd.java (limited to 'src/main/java') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AntiCoopAdd.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AntiCoopAdd.java new file mode 100644 index 00000000..25aaaa0a --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AntiCoopAdd.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.miscfeatures; + +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.inventory.GuiChest; +import net.minecraft.event.ClickEvent; +import net.minecraft.event.HoverEvent; +import net.minecraft.init.Items; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.EnumChatFormatting; + +public class AntiCoopAdd { + + public static boolean onMouseClick(Slot slotIn, int slotId, int clickedButton, int clickType) { + if (!NotEnoughUpdates.INSTANCE.config.misc.coopWarning) return false; + if (slotId == -999) return false; + if (!Utils.getOpenChestName().contains("Profile")) return false; + + GuiChest chest = (GuiChest) Minecraft.getMinecraft().currentScreen; + + ItemStack stack = chest.inventorySlots.getSlot(slotId).getStack(); + if (stack == null) return false; + if (stack.getItem() == Items.diamond && stack.getDisplayName() != null && stack.getDisplayName().contains("Co-op Request")) { + String ign = Utils.getOpenChestName().split("'s Profile")[0]; + ChatComponentText storageMessage = new ChatComponentText( + EnumChatFormatting.YELLOW + "[NEU] " + EnumChatFormatting.YELLOW + + "You just clicked on the Co-op add button. If you want to coop add this person, click this chat message"); + storageMessage.setChatStyle(Utils.createClickStyle(ClickEvent.Action.RUN_COMMAND, "/coopadd " + ign)); + storageMessage.setChatStyle(storageMessage.getChatStyle().setChatHoverEvent( + new HoverEvent(HoverEvent.Action.SHOW_TEXT, + new ChatComponentText(EnumChatFormatting.YELLOW + "Click to add " + ign + " to your coop")))); + ChatComponentText storageChatMessage = new ChatComponentText(""); + storageChatMessage.appendSibling(storageMessage); + Minecraft.getMinecraft().thePlayer.addChatMessage(storageChatMessage); + return true; + } + + return false; + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java index 7d17aa3e..ee14452d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java @@ -23,6 +23,7 @@ import io.github.moulberry.notenoughupdates.NEUOverlay; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.listener.RenderListener; import io.github.moulberry.notenoughupdates.miscfeatures.AbiphoneWarning; +import io.github.moulberry.notenoughupdates.miscfeatures.AntiCoopAdd; import io.github.moulberry.notenoughupdates.miscfeatures.AuctionBINWarning; import io.github.moulberry.notenoughupdates.miscfeatures.AuctionSortModeWarning; import io.github.moulberry.notenoughupdates.miscfeatures.BetterContainers; @@ -30,8 +31,8 @@ import io.github.moulberry.notenoughupdates.miscfeatures.EnchantingSolvers; import io.github.moulberry.notenoughupdates.miscfeatures.PetInfoOverlay; import io.github.moulberry.notenoughupdates.miscfeatures.SlotLocking; import io.github.moulberry.notenoughupdates.miscgui.GuiCustomEnchant; -import io.github.moulberry.notenoughupdates.miscgui.hex.GuiCustomHex; import io.github.moulberry.notenoughupdates.miscgui.StorageOverlay; +import io.github.moulberry.notenoughupdates.miscgui.hex.GuiCustomHex; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; @@ -314,6 +315,11 @@ public abstract class MixinGuiContainer extends GuiScreen { return; } + if (AntiCoopAdd.onMouseClick(slotIn, slotId, clickedButton, clickType)) { + ci.cancel(); + return; + } + AtomicBoolean ret = new AtomicBoolean(false); SlotLocking.getInstance().onWindowClick(slotIn, slotId, clickedButton, clickType, (tuple) -> { 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 84e2322e..c6f00182 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 @@ -229,4 +229,12 @@ public class Misc { @ConfigEditorBoolean public boolean abiphoneWarning = true; + @Expose + @ConfigOption( + name = "Enable Coop Warning", + desc = "Asks for confirmation when clicking the coop diamond in profile menu" + ) + @ConfigEditorBoolean + public boolean coopWarning = true; + } -- cgit