|
| 1 | +/* |
| 2 | + * Copyright (c) 2014-2026 Wurst-Imperium and contributors. |
| 3 | + * |
| 4 | + * This source code is subject to the terms of the GNU General Public |
| 5 | + * License, version 3. If a copy of the GPL was not distributed with this |
| 6 | + * file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt |
| 7 | + */ |
| 8 | +package net.wurstclient.util; |
| 9 | + |
| 10 | +import java.util.LinkedHashSet; |
| 11 | +import java.util.Set; |
| 12 | + |
| 13 | +import net.minecraft.client.Minecraft; |
| 14 | +import net.wurstclient.WurstClient; |
| 15 | +import net.wurstclient.events.UpdateListener; |
| 16 | +import net.wurstclient.hack.Hack; |
| 17 | +import net.wurstclient.hacks.ClickGuiHack; |
| 18 | +import net.wurstclient.hacks.NavigatorHack; |
| 19 | + |
| 20 | +public enum HackToggleFeedback implements UpdateListener |
| 21 | +{ |
| 22 | + INSTANCE; |
| 23 | + |
| 24 | + private final Set<String> enabled = new LinkedHashSet<>(); |
| 25 | + private final Set<String> disabled = new LinkedHashSet<>(); |
| 26 | + private int delayTicks; |
| 27 | + |
| 28 | + public void queue(Hack hack, boolean isEnabled) |
| 29 | + { |
| 30 | + if(hack == null || !shouldReport(hack)) |
| 31 | + return; |
| 32 | + |
| 33 | + if(!isChatFeedbackEnabled()) |
| 34 | + return; |
| 35 | + |
| 36 | + String name = hack.getName(); |
| 37 | + if(isEnabled) |
| 38 | + { |
| 39 | + disabled.remove(name); |
| 40 | + enabled.add(name); |
| 41 | + }else |
| 42 | + { |
| 43 | + enabled.remove(name); |
| 44 | + disabled.add(name); |
| 45 | + } |
| 46 | + |
| 47 | + delayTicks = 1; |
| 48 | + } |
| 49 | + |
| 50 | + @Override |
| 51 | + public void onUpdate() |
| 52 | + { |
| 53 | + if(delayTicks > 0) |
| 54 | + { |
| 55 | + delayTicks--; |
| 56 | + return; |
| 57 | + } |
| 58 | + |
| 59 | + if(enabled.isEmpty() && disabled.isEmpty()) |
| 60 | + return; |
| 61 | + |
| 62 | + if(!isChatFeedbackEnabled() || !isPlayerReady()) |
| 63 | + { |
| 64 | + enabled.clear(); |
| 65 | + disabled.clear(); |
| 66 | + return; |
| 67 | + } |
| 68 | + |
| 69 | + StringBuilder message = new StringBuilder(); |
| 70 | + if(!enabled.isEmpty()) |
| 71 | + { |
| 72 | + message.append("\u00a7aEnabled: ") |
| 73 | + .append(String.join(", ", enabled)).append("\u00a7r"); |
| 74 | + } |
| 75 | + |
| 76 | + if(!disabled.isEmpty()) |
| 77 | + { |
| 78 | + if(message.length() > 0) |
| 79 | + message.append(" | "); |
| 80 | + message.append("\u00a7cDisabled: ") |
| 81 | + .append(String.join(", ", disabled)).append("\u00a7r"); |
| 82 | + } |
| 83 | + |
| 84 | + ChatUtils.message(message.toString()); |
| 85 | + enabled.clear(); |
| 86 | + disabled.clear(); |
| 87 | + } |
| 88 | + |
| 89 | + private boolean shouldReport(Hack hack) |
| 90 | + { |
| 91 | + return !(hack instanceof NavigatorHack || hack instanceof ClickGuiHack); |
| 92 | + } |
| 93 | + |
| 94 | + private boolean isChatFeedbackEnabled() |
| 95 | + { |
| 96 | + WurstClient wurst = WurstClient.INSTANCE; |
| 97 | + if(wurst == null || wurst.getHax() == null) |
| 98 | + return false; |
| 99 | + |
| 100 | + ClickGuiHack clickGuiHack = wurst.getHax().clickGuiHack; |
| 101 | + return clickGuiHack != null |
| 102 | + && clickGuiHack.isHackToggleChatFeedbackEnabled(); |
| 103 | + } |
| 104 | + |
| 105 | + private boolean isPlayerReady() |
| 106 | + { |
| 107 | + Minecraft mc = WurstClient.MC; |
| 108 | + return mc != null && mc.player != null && mc.gui != null; |
| 109 | + } |
| 110 | +} |
0 commit comments