Skip to content

Commit ff751b1

Browse files
committed
Custom Command Prefixes
1 parent 69c9920 commit ff751b1

File tree

7 files changed

+152
-15
lines changed

7 files changed

+152
-15
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,14 @@ I did not, nor could I copy their code directly as most are Meteor based mods. S
387387
- Auto Attack, your jab attack will continue to auto hit once the cooldown has expired so long as you're hitting an entity.
388388
- Designed for elytra-free ground PvP/PvE, though may be even more interesting with one.
389389

390+
### Custom Command Prefixes
391+
- In the Wurst Options menu you can now change your command prefix
392+
- Cycle through commonly used command prefixes by pressing the Command Prefix button
393+
394+
![CMD](https://i.imgur.com/A79Het4.png)
395+
![CMD2](https://i.imgur.com/qBhwEUf.png)
396+
![CMD3](https://i.imgur.com/veagIsN.png)
397+
390398
## What’s changed or improved in this fork?
391399

392400
### ItemESP (Expanded)

src/main/java/net/wurstclient/command/CmdList.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,13 @@ public CmdList()
9494
continue;
9595

9696
Command cmd = (Command)field.get(this);
97-
cmds.put(cmd.getName(), cmd);
97+
// Store commands by their base name without the leading prefix
98+
// (e.g. "help" instead of ".help"). This allows the command
99+
// prefix to be configured independently.
100+
String baseName = cmd.getName();
101+
if(baseName.startsWith("."))
102+
baseName = baseName.substring(1);
103+
cmds.put(baseName, cmd);
98104
}
99105

100106
}catch(Exception e)
@@ -107,7 +113,13 @@ public CmdList()
107113

108114
public Command getCmdByName(String name)
109115
{
110-
return cmds.get("." + name);
116+
if(name == null)
117+
return null;
118+
119+
if(name.startsWith("."))
120+
name = name.substring(1);
121+
122+
return cmds.get(name);
111123
}
112124

113125
public Collection<Command> getAllCmds()

src/main/java/net/wurstclient/command/CmdProcessor.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,20 @@ public void onSentMessage(ChatOutputEvent event)
3232
return;
3333

3434
String message = event.getOriginalMessage().trim();
35-
if(!message.startsWith("."))
35+
// Use the configured command prefix from the Wurst options.
36+
String prefix = ".";
37+
try
38+
{
39+
prefix = WurstClient.INSTANCE.getOtfs().commandPrefixOtf
40+
.getPrefixSetting().getSelected().toString();
41+
}catch(Throwable ignored)
42+
{}
43+
44+
if(!message.startsWith(prefix))
3645
return;
3746

3847
event.cancel();
39-
process(message.substring(1));
48+
process(message.substring(prefix.length()));
4049
}
4150

4251
public void process(String input)
@@ -108,19 +117,28 @@ public CmdNotFoundException(String input)
108117
public void printToChat()
109118
{
110119
String cmdName = input.split(" ")[0];
111-
ChatUtils.error("Unknown command: ." + cmdName);
120+
String prefix = ".";
121+
try
122+
{
123+
prefix = WurstClient.INSTANCE.getOtfs().commandPrefixOtf
124+
.getPrefixSetting().getSelected().toString();
125+
}catch(Throwable ignored)
126+
{}
127+
128+
ChatUtils.error("Unknown command: " + prefix + cmdName);
112129

113130
StringBuilder helpMsg = new StringBuilder();
114131

115132
if(input.startsWith("/"))
116133
{
117-
helpMsg.append("Use \".say " + input + "\"");
134+
helpMsg.append("Use \"" + prefix + "say " + input + "\"");
118135
helpMsg.append(" to send it as a chat command.");
119136

120137
}else
121138
{
122-
helpMsg.append("Type \".help\" for a list of commands or ");
123-
helpMsg.append("\".say ." + input + "\"");
139+
helpMsg.append(
140+
"Type \"" + prefix + "help\" for a list of commands or ");
141+
helpMsg.append("\"" + prefix + "say " + prefix + input + "\"");
124142
helpMsg.append(" to send it as a chat message.");
125143
}
126144

src/main/java/net/wurstclient/commands/HelpCmd.java

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.util.ArrayList;
1111

1212
import net.wurstclient.DontBlock;
13+
import net.wurstclient.WurstClient;
1314
import net.wurstclient.command.CmdException;
1415
import net.wurstclient.command.CmdSyntaxError;
1516
import net.wurstclient.command.Command;
@@ -57,21 +58,45 @@ private void listCommands(int page) throws CmdException
5758
int start = (page - 1) * CMDS_PER_PAGE;
5859
int end = Math.min(page * CMDS_PER_PAGE, cmds.size());
5960

61+
String prefix = ".";
62+
try
63+
{
64+
prefix = WurstClient.INSTANCE.getOtfs().commandPrefixOtf
65+
.getPrefixSetting().getSelected().toString();
66+
}catch(Throwable ignored)
67+
{}
68+
6069
ChatUtils.message("Command list (page " + page + "/" + pages + ")");
6170
for(int i = start; i < end; i++)
62-
ChatUtils.message("- " + cmds.get(i).getName());
71+
{
72+
String name = cmds.get(i).getName();
73+
if(name.startsWith("."))
74+
name = name.substring(1);
75+
ChatUtils.message("- " + prefix + name);
76+
}
6377
}
6478

6579
private void help(String cmdName) throws CmdException
6680
{
67-
if(cmdName.startsWith("."))
68-
cmdName = cmdName.substring(1);
81+
String prefix = ".";
82+
try
83+
{
84+
prefix = WurstClient.INSTANCE.getOtfs().commandPrefixOtf
85+
.getPrefixSetting().getSelected().toString();
86+
}catch(Throwable ignored)
87+
{}
88+
89+
if(cmdName.startsWith(prefix))
90+
cmdName = cmdName.substring(prefix.length());
6991

7092
Command cmd = WURST.getCmds().getCmdByName(cmdName);
7193
if(cmd == null)
72-
throw new CmdSyntaxError("Unknown command: ." + cmdName);
94+
throw new CmdSyntaxError("Unknown command: " + prefix + cmdName);
95+
96+
ChatUtils.message("Available help for " + prefix + cmdName + ":");
7397

74-
ChatUtils.message("Available help for ." + cmdName + ":");
75-
cmd.printHelp();
98+
String desc = cmd.getDescription().replaceAll("\\.(?=\\w)", prefix);
99+
for(String line : desc.split("\n"))
100+
ChatUtils.message(line);
76101
}
77102
}

src/main/java/net/wurstclient/options/WurstOptionsScreen.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void init()
4949
addRenderableWidget(Button
5050
.builder(Component.literal("Back"),
5151
b -> minecraft.setScreen(prevScreen))
52-
.bounds(width / 2 - 100, height / 4 + 168 - 16, 200, 20).build());
52+
.bounds(width / 2 - 100, height / 4 + 192 - 16, 200, 20).build());
5353

5454
addSettingButtons();
5555
addManagerButtons();
@@ -67,6 +67,8 @@ private void addSettingButtons()
6767
wurst.getOtfs().translationsOtf.getForceEnglish();
6868
CheckboxSetting unsafeChatToast =
6969
wurst.getOtfs().noChatReportsOtf.getUnsafeChatToast();
70+
net.wurstclient.other_features.CommandPrefixOtf commandPrefixOtf =
71+
wurst.getOtfs().commandPrefixOtf;
7072

7173
new WurstOptionsButton(-154, 24,
7274
() -> "Click Friends: "
@@ -105,6 +107,15 @@ private void addSettingButtons()
105107
"Shows a toast warning when a server enforces insecure chat/reporting.",
106108
b -> unsafeChatToast.setChecked(!unsafeChatToast.isChecked()));
107109

110+
new WurstOptionsButton(-154, 168,
111+
() -> "Command Prefix: "
112+
+ commandPrefixOtf.getPrefixSetting().getSelected().toString(),
113+
"Cycle through available command prefixes.", b -> {
114+
commandPrefixOtf.getPrefixSetting().selectNext();
115+
ChatUtils.message("Command prefix set to " + commandPrefixOtf
116+
.getPrefixSetting().getSelected().toString());
117+
});
118+
108119
if(NiceWurstModule.showAntiFingerprintControls())
109120
{
110121
new WurstOptionsButton(-154, 144, () -> "Anti-Fingerprint",

src/main/java/net/wurstclient/other_feature/OtfList.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public final class OtfList
3030
public final ServerFinderOtf serverFinderOtf = new ServerFinderOtf();
3131
public final TabGuiOtf tabGuiOtf = new TabGuiOtf();
3232
public final TranslationsOtf translationsOtf = new TranslationsOtf();
33+
public final net.wurstclient.other_features.CommandPrefixOtf commandPrefixOtf =
34+
new net.wurstclient.other_features.CommandPrefixOtf();
3335
public final VanillaSpoofOtf vanillaSpoofOtf = new VanillaSpoofOtf();
3436
public final WikiDataExportOtf wikiDataExportOtf = new WikiDataExportOtf();
3537
public final WurstCapesOtf wurstCapesOtf = new WurstCapesOtf();
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (c) 2014-2025 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.other_features;
9+
10+
import net.wurstclient.other_feature.OtherFeature;
11+
import net.wurstclient.settings.EnumSetting;
12+
import net.wurstclient.util.text.WText;
13+
14+
public final class CommandPrefixOtf extends OtherFeature
15+
{
16+
public enum Prefix
17+
{
18+
DOT("."),
19+
COLON(":"),
20+
SEMICOLON(";"),
21+
COMMA(","),
22+
EXCLAMATION("!"),
23+
AT("@"),
24+
HASH("#"),
25+
DOLLAR("$"),
26+
PERCENT("%"),
27+
CARET("^"),
28+
AMPERSAND("&"),
29+
ASTERISK("*");
30+
31+
private final String symbol;
32+
33+
Prefix(String symbol)
34+
{
35+
this.symbol = symbol;
36+
}
37+
38+
@Override
39+
public String toString()
40+
{
41+
return symbol;
42+
}
43+
}
44+
45+
private final EnumSetting<Prefix> prefixSetting =
46+
new EnumSetting<>("Command Prefix",
47+
WText.translated("options.command_prefix.description"),
48+
Prefix.values(), Prefix.DOT);
49+
50+
public CommandPrefixOtf()
51+
{
52+
super("Command Prefix",
53+
"Change the command prefix used to trigger Wurst commands.");
54+
addSetting(prefixSetting);
55+
}
56+
57+
public EnumSetting<Prefix> getPrefixSetting()
58+
{
59+
return prefixSetting;
60+
}
61+
}

0 commit comments

Comments
 (0)