-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathCommandActionData.java
More file actions
49 lines (41 loc) · 1.3 KB
/
CommandActionData.java
File metadata and controls
49 lines (41 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package xyz.imcodist.quickmenu.data.command_actions;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
public class CommandActionData extends BaseActionData {
public String command = "";
@Override
public String getJsonType() {
return "cmd";
}
@Override
public String getJsonValue() {
return command;
}
@Override
public String getTypeString() { return "CMD"; }
@Override
public String getString() {
return command;
}
@Override
public long run() {
MinecraftClient client = MinecraftClient.getInstance();
if (client == null) return 0;
ClientPlayerEntity player = client.player;
if (player == null) return 0;
// Run the command.
String commandToRun = command;
if (commandToRun != null) {
if (commandToRun.startsWith("/")) {
commandToRun = commandToRun.substring(1);
player.networkHandler.sendChatCommand(commandToRun);
} else {
if (commandToRun.length() >= 256) {
commandToRun = commandToRun.substring(0, 256);
}
player.networkHandler.sendChatMessage(commandToRun);
}
}
return 0;
}
}