Skip to content

Commit c9d5a31

Browse files
committed
Autocomplete OTF Commands
1 parent 093b76d commit c9d5a31

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import net.wurstclient.events.ChatOutputListener;
1717
import net.wurstclient.hack.Hack;
1818
import net.wurstclient.hacks.TooManyHaxHack;
19+
import net.wurstclient.other_feature.OtherFeature;
1920
import net.wurstclient.util.ChatUtils;
2021

2122
public final class CmdProcessor implements ChatOutputListener
@@ -48,6 +49,9 @@ public void process(String input)
4849
if(runHackShortcut(input))
4950
return;
5051

52+
if(runOtherFeatureShortcut(input))
53+
return;
54+
5155
try
5256
{
5357
Command cmd = parseCmd(input);
@@ -151,6 +155,24 @@ private boolean runHackShortcut(String input)
151155
return true;
152156
}
153157

158+
private boolean runOtherFeatureShortcut(String input)
159+
{
160+
String[] args = input.trim().split("\\s+");
161+
if(args.length != 1 || args[0].isEmpty())
162+
return false;
163+
164+
// If a real command shares this name, let the command parser handle it.
165+
if(cmds.getCmdByName(args[0]) != null)
166+
return false;
167+
168+
OtherFeature otf = WurstClient.INSTANCE.getOtfs().getOtfByName(args[0]);
169+
if(otf == null)
170+
return false;
171+
172+
otf.doPrimaryAction();
173+
return true;
174+
}
175+
154176
private void setHackEnabled(Hack hack, boolean enabled)
155177
{
156178
TooManyHaxHack tooManyHax =

src/main/java/net/wurstclient/mixin/CommandSuggestionsMixin.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import net.wurstclient.command.Command;
2828
import net.wurstclient.hack.Hack;
2929
import net.wurstclient.hacks.AutoCompleteHack;
30+
import net.wurstclient.other_feature.OtherFeature;
3031

3132
@Mixin(CommandSuggestions.class)
3233
public abstract class CommandSuggestionsMixin
@@ -79,6 +80,8 @@ private void onRefresh(CallbackInfo ci)
7980
Collection<Command> commands =
8081
WurstClient.INSTANCE.getCmds().getAllCmds();
8182
Collection<Hack> hacks = WurstClient.INSTANCE.getHax().getAllHax();
83+
Collection<OtherFeature> otfs =
84+
WurstClient.INSTANCE.getOtfs().getAllOtfs();
8285
SuggestionsBuilder builder = new SuggestionsBuilder(draftMessage, 0);
8386
LinkedHashSet<String> candidates = new LinkedHashSet<>();
8487
String inlineSuggestion = "";
@@ -103,6 +106,14 @@ private void onRefresh(CallbackInfo ci)
103106
candidates.add(prefix + hack.getName());
104107
}
105108

109+
for(OtherFeature otf : otfs)
110+
{
111+
if(otf == null || otf.getName() == null)
112+
continue;
113+
114+
candidates.add(prefix + otf.getName());
115+
}
116+
106117
for(String candidate : candidates)
107118
{
108119
if(!candidate.toLowerCase(Locale.ROOT).startsWith(lowerDraft))

0 commit comments

Comments
 (0)