Skip to content

Commit d6ba669

Browse files
committed
Prevent macros from being added to the chat history
closes #5287
1 parent 7d489bc commit d6ba669

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

src/main/java/meteordevelopment/meteorclient/systems/macros/Macro.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,26 +60,26 @@ public boolean onAction(boolean isKey, int value, int modifiers) {
6060
}
6161

6262
public boolean onAction() {
63-
if (dirty) {
64-
scripts.clear();
63+
if (dirty) {
64+
scripts.clear();
6565

66-
for (String message : messages.get()) {
67-
Script script = MeteorStarscript.compile(message);
68-
if (script != null) scripts.add(script);
69-
}
70-
71-
dirty = false;
66+
for (String message : messages.get()) {
67+
Script script = MeteorStarscript.compile(message);
68+
if (script != null) scripts.add(script);
7269
}
7370

74-
for (Script script : scripts) {
75-
String message = MeteorStarscript.run(script);
71+
dirty = false;
72+
}
73+
74+
for (Script script : scripts) {
75+
String message = MeteorStarscript.run(script);
7676

77-
if (message != null) {
78-
ChatUtils.sendPlayerMsg(message);
79-
}
77+
if (message != null) {
78+
ChatUtils.sendPlayerMsg(message, false);
8079
}
80+
}
8181

82-
return true;
82+
return true;
8383
}
8484

8585
@Override

src/main/java/meteordevelopment/meteorclient/utils/player/ChatUtils.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public static Text getMeteorPrefix() {
4949
/**
5050
* Registers a custom prefix to be used when calling from a class in the specified package. When null is returned from the supplier the default Meteor prefix is used.
5151
*/
52+
@SuppressWarnings("unused")
5253
public static void registerCustomPrefix(String packageName, Supplier<Text> supplier) {
5354
for (Pair<String, Supplier<Text>> pair : customPrefixes) {
5455
if (pair.getLeft().equals(packageName)) {
@@ -63,6 +64,7 @@ public static void registerCustomPrefix(String packageName, Supplier<Text> suppl
6364
/**
6465
* The package name must match exactly to the one provided through {@link #registerCustomPrefix(String, Supplier)}.
6566
*/
67+
@SuppressWarnings("unused")
6668
public static void unregisterCustomPrefix(String packageName) {
6769
customPrefixes.removeIf(pair -> pair.getLeft().equals(packageName));
6870
}
@@ -74,10 +76,17 @@ public static void forceNextPrefixClass(Class<?> klass) {
7476
// Player
7577

7678
/**
77-
* Sends the message as if the user typed it into chat.
79+
* Sends the message as if the user typed it into chat and adds it to the chat history.
7880
*/
7981
public static void sendPlayerMsg(String message) {
80-
mc.inGameHud.getChatHud().addToMessageHistory(message);
82+
sendPlayerMsg(message, true);
83+
}
84+
85+
/**
86+
* Sends the message as if the user typed it into chat.
87+
*/
88+
public static void sendPlayerMsg(String message, boolean addToHistory) {
89+
if (addToHistory) mc.inGameHud.getChatHud().addToMessageHistory(message);
8190

8291
if (message.startsWith("/")) mc.player.networkHandler.sendChatCommand(message.substring(1));
8392
else mc.player.networkHandler.sendChatMessage(message);

0 commit comments

Comments
 (0)