forked from MeteorDevelopment/meteor-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommands.java
More file actions
123 lines (109 loc) · 4.56 KB
/
Commands.java
File metadata and controls
123 lines (109 loc) · 4.56 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
* This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client).
* Copyright (c) Meteor Development.
*/
package meteordevelopment.meteorclient.commands;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import meteordevelopment.meteorclient.MeteorClient;
import meteordevelopment.meteorclient.commands.commands.*;
import meteordevelopment.meteorclient.events.game.GameJoinedEvent;
import meteordevelopment.meteorclient.pathing.PathManagers;
import meteordevelopment.meteorclient.utils.PostInit;
import meteordevelopment.orbit.EventHandler;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.command.CommandSource;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import static meteordevelopment.meteorclient.MeteorClient.mc;
public class Commands {
public static final List<Command> COMMANDS = new ArrayList<>();
public static CommandDispatcher<CommandSource> DISPATCHER = new CommandDispatcher<>();
@PostInit(dependencies = PathManagers.class)
public static void init() {
add(new VClipCommand());
add(new HClipCommand());
add(new DismountCommand());
add(new DisconnectCommand());
add(new DamageCommand());
add(new DropCommand());
add(new EnchantCommand());
add(new FakePlayerCommand());
add(new FriendsCommand());
add(new CommandsCommand());
add(new InventoryCommand());
add(new NbtCommand());
add(new NotebotCommand());
add(new PeekCommand());
add(new EnderChestCommand());
add(new ProfilesCommand());
add(new ReloadCommand());
add(new ResetCommand());
add(new SayCommand());
add(new ServerCommand());
add(new SwarmCommand());
add(new ToggleCommand());
add(new SettingCommand());
add(new SpectateCommand());
add(new GamemodeCommand());
add(new SaveMapCommand());
add(new MacroCommand());
add(new ModulesCommand());
add(new BindsCommand());
add(new GiveCommand());
add(new NameHistoryCommand());
add(new BindCommand());
add(new FovCommand());
add(new RotationCommand());
add(new WaypointCommand());
add(new InputCommand());
add(new WaspCommand());
add(new LocateCommand());
add(new HelpCommand());
COMMANDS.sort(Comparator.comparing(Command::getName));
MeteorClient.EVENT_BUS.subscribe(Commands.class);
}
public static void add(Command command) {
COMMANDS.removeIf(existing -> existing.getName().equals(command.getName()));
COMMANDS.add(command);
}
public static void dispatch(String message) throws CommandSyntaxException {
DISPATCHER.execute(message, mc.getNetworkHandler().getCommandSource());
}
public static Command get(String name) {
for (Command command : COMMANDS) {
if (command.getName().equals(name)) {
return command;
}
}
return null;
}
/**
* Argument types that rely on Minecraft registries access those registries through a {@link CommandRegistryAccess}
* object. Since dynamic registries are specific to each server, we need to make a new CommandRegistryAccess object
* every time we join a server.
* <p>
* The command tree and by extension the {@link CommandDispatcher} also have to be rebuilt because:
* <ol>
* <li>Argument types that require registries use a registry wrapper object that is created and stored in the
* argument type objects when the command tree is built.
* <li>Registry entries and keys are compared using referential equality. Even if the data encoded is the same,
* registry wrapper objects' dynamic data becomes stale after joining another server.
* <li>The CommandDispatcher's node merging only adds missing children, it cannot replace stale argument type
* objects.
* </ol>
*
* @author Crosby
*/
@EventHandler
private static void onJoin(GameJoinedEvent event) {
ClientPlayNetworkHandler networkHandler = mc.getNetworkHandler();
Command.REGISTRY_ACCESS = CommandRegistryAccess.of(networkHandler.getRegistryManager(), networkHandler.getEnabledFeatures());
DISPATCHER = new CommandDispatcher<>();
for (Command command : COMMANDS) {
command.registerTo(DISPATCHER);
}
}
}