|
| 1 | +/* |
| 2 | + * Copyright 2024 Lambda |
| 3 | + * |
| 4 | + * This program is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation, either version 3 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + */ |
| 17 | + |
| 18 | +package com.lambda.module.modules.player |
| 19 | + |
| 20 | +import com.lambda.event.events.MouseEvent |
| 21 | +import com.lambda.event.listener.SafeListener.Companion.listener |
| 22 | +import com.lambda.friend.FriendManager.befriend |
| 23 | +import com.lambda.friend.FriendManager.isFriend |
| 24 | +import com.lambda.friend.FriendManager.unfriend |
| 25 | +import com.lambda.module.Module |
| 26 | +import com.lambda.module.modules.client.ClickGui |
| 27 | +import com.lambda.module.tag.ModuleTag |
| 28 | +import com.lambda.util.Communication.info |
| 29 | +import com.lambda.util.Mouse |
| 30 | +import com.lambda.util.text.buildText |
| 31 | +import com.lambda.util.text.color |
| 32 | +import com.lambda.util.text.literal |
| 33 | +import com.lambda.util.text.text |
| 34 | +import com.lambda.util.world.raycast.RayCastUtils.entityResult |
| 35 | +import net.minecraft.client.network.OtherClientPlayerEntity |
| 36 | +import org.lwjgl.glfw.GLFW.GLFW_MOD_ALT |
| 37 | +import org.lwjgl.glfw.GLFW.GLFW_MOD_CONTROL |
| 38 | +import org.lwjgl.glfw.GLFW.GLFW_MOD_SHIFT |
| 39 | +import org.lwjgl.glfw.GLFW.GLFW_MOD_SUPER |
| 40 | +import java.awt.Color |
| 41 | + |
| 42 | +object ClickFriend : Module( |
| 43 | + name = "ClickFriend", |
| 44 | + description = "Add or remove friends with a single click", |
| 45 | + defaultTags = setOf(ModuleTag.PLAYER) |
| 46 | +) { |
| 47 | + private val friendButton by setting("Friend Button", Mouse.Button.Right, description = "Button to press to friend a player") |
| 48 | + private val friendAction by setting("Action", Mouse.Action.Release, description = "What mouse action should add or remove the player") |
| 49 | + private val comboUnfriend by setting("Combo Unfriend", false, description = "Press a key and right click a player to unfriend") |
| 50 | + private val modUnfriend by setting("Combo Key", MouseMod.Shift, description = "The key to press to activate the unfriend combo") { comboUnfriend } |
| 51 | + |
| 52 | + init { |
| 53 | + listener<MouseEvent.Click> { |
| 54 | + if (it.button != friendButton || |
| 55 | + it.action != friendAction || |
| 56 | + mc.currentScreen != null |
| 57 | + ) return@listener |
| 58 | + |
| 59 | + val target = mc.crosshairTarget?.entityResult?.entity as? OtherClientPlayerEntity |
| 60 | + ?: return@listener |
| 61 | + |
| 62 | + if ((modUnfriend.flagsPresent(it.modifiers) || !comboUnfriend) && target.isFriend) { |
| 63 | + target.unfriend() |
| 64 | + info(buildText { |
| 65 | + color(Color.RED) { |
| 66 | + literal("Removed ") |
| 67 | + color(Color.CYAN) { |
| 68 | + text(target.name) |
| 69 | + color(Color.WHITE) { literal(" from your friend list") } |
| 70 | + } |
| 71 | + } |
| 72 | + }) |
| 73 | + } |
| 74 | + |
| 75 | + if (!modUnfriend.flagsPresent(it.modifiers) && !target.isFriend) { |
| 76 | + target.befriend() |
| 77 | + info(buildText { |
| 78 | + color(Color.GREEN) { |
| 79 | + literal("Added ") |
| 80 | + color(Color.CYAN) { |
| 81 | + text(target.name) |
| 82 | + color(Color.WHITE) { |
| 83 | + literal(" to your friend list") |
| 84 | + } |
| 85 | + } |
| 86 | + } |
| 87 | + }) |
| 88 | + } |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + private enum class MouseMod(val modifiers: Int) { |
| 93 | + Shift(GLFW_MOD_SHIFT), |
| 94 | + Control(GLFW_MOD_CONTROL), |
| 95 | + Alt(GLFW_MOD_ALT), |
| 96 | + Super(GLFW_MOD_SUPER); |
| 97 | + |
| 98 | + fun flagsPresent(flags: Int) = flags and modifiers == modifiers |
| 99 | + } |
| 100 | +} |
0 commit comments