Skip to content

Commit 65c29bf

Browse files
committed
Hack Toggle Chat Feedback
1 parent 56be087 commit 65c29bf

4 files changed

Lines changed: 125 additions & 0 deletions

File tree

src/main/java/net/wurstclient/WurstClient.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import net.wurstclient.util.PlayerRangeAlertManager;
4545
import net.wurstclient.util.SetbackDetector;
4646
import net.wurstclient.util.ServerObserver;
47+
import net.wurstclient.util.HackToggleFeedback;
4748
import net.wurstclient.util.timer.TimerManager;
4849
import net.wurstclient.util.json.JsonException;
4950
import net.wurstclient.nicewurst.NiceWurstModule;
@@ -118,6 +119,7 @@ public void initialize()
118119
setbackDetector);
119120
timerManager = new TimerManager();
120121
eventManager.add(UpdateListener.class, timerManager);
122+
eventManager.add(UpdateListener.class, HackToggleFeedback.INSTANCE);
121123

122124
Path enabledHacksFile = wurstFolder.resolve("enabled-hacks.json");
123125
Path favoritesHacksFile = wurstFolder.resolve("favourites.json");

src/main/java/net/wurstclient/hack/Hack.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import net.wurstclient.hacks.ClickGuiHack;
1515
import net.wurstclient.hacks.NavigatorHack;
1616
import net.wurstclient.hacks.TooManyHaxHack;
17+
import net.wurstclient.util.HackToggleFeedback;
1718

1819
public abstract class Hack extends Feature
1920
{
@@ -120,6 +121,8 @@ public final void setEnabled(boolean enabled)
120121

121122
if(stateSaved)
122123
WURST.getHax().saveEnabledHax();
124+
125+
HackToggleFeedback.INSTANCE.queue(this, enabled);
123126
}
124127

125128
@Override

src/main/java/net/wurstclient/hacks/ClickGuiHack.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ public final class ClickGuiHack extends Hack
5454
new CheckboxSetting("Isolate windows",
5555
"Hide overlapping windows behind the front-most window.", false);
5656

57+
private final CheckboxSetting hackToggleChatFeedback =
58+
new CheckboxSetting("Hack toggle chat feedback",
59+
"Show a chat message when hacks are enabled or disabled.", false);
60+
5761
private final SliderSetting maxHeight = new SliderSetting("Max height",
5862
"Maximum window height\n" + "0 = no limit", 200, 0, 1000, 50,
5963
ValueDisplay.INTEGER);
@@ -66,6 +70,7 @@ public final class ClickGuiHack extends Hack
6670
public ClickGuiHack()
6771
{
6872
super("ClickGUI");
73+
addSetting(hackToggleChatFeedback);
6974
addSetting(bgColor);
7075
addSetting(acColor);
7176
addSetting(txtColor);
@@ -136,6 +141,11 @@ public CheckboxSetting getIsolateWindowsSetting()
136141
return isolateWindows;
137142
}
138143

144+
public boolean isHackToggleChatFeedbackEnabled()
145+
{
146+
return hackToggleChatFeedback.isChecked();
147+
}
148+
139149
public int getMaxHeight()
140150
{
141151
return maxHeight.getValueI();
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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

Comments
 (0)