@@ -7,7 +7,6 @@ import com.mojang.brigadier.arguments.BoolArgumentType
77import com.mojang.brigadier.arguments.IntegerArgumentType
88import com.mojang.brigadier.arguments.StringArgumentType
99import com.mojang.brigadier.context.CommandContext
10- import com.mojang.brigadier.tree.RootCommandNode
1110import net.minecraft.command.CommandSource
1211import net.minecraft.command.arguments.EntityArgument
1312import net.minecraft.entity.Entity
@@ -18,30 +17,9 @@ import net.minecraft.entity.player.ServerPlayerEntity
1817 * @since 2.0.0-SNAPSHOT.1.
1918 */
2019object CommandAPI {
21- private lateinit var registeredCommands: RootCommandNode <CommandSource >
2220 private lateinit var dispatcher: CommandDispatcher <CommandSource >
2321 private var dispatcherAssigned = false
2422
25- /* *
26- * Internal function. Assign dispatcher root
27- * for removing command. Must be called before
28- * any processor initializing.
29- * @param dispatcher command dispatcher.
30- * @since 2.0.0-SNAPSHOT.1.
31- */
32- /*
33- This is a crutch to replace vanilla commands,
34- and to gain access to the dispatcher root.
35- */
36- @Suppress(" UNCHECKED_CAST" )
37- internal fun assignDispatcherRoot (
38- dispatcher : CommandDispatcher <CommandSource >
39- ) {
40- val root = dispatcher.javaClass.getDeclaredField(" root" )
41- root.isAccessible = true
42- registeredCommands = root.get(dispatcher) as RootCommandNode <CommandSource >
43- }
44-
4523 /* *
4624 * Assign dispatcher for command registering.
4725 * @param dispatcher command dispatcher.
@@ -50,10 +28,8 @@ object CommandAPI {
5028 fun assignDispatcher (
5129 dispatcher : CommandDispatcher <CommandSource >
5230 ) {
53- if (! dispatcherAssigned) {
54- dispatcherAssigned = true
55- this .dispatcher = dispatcher
56- }
31+ if (! dispatcherAssigned) dispatcherAssigned = true
32+ this .dispatcher = dispatcher
5733 }
5834
5935 /* *
@@ -81,8 +57,8 @@ object CommandAPI {
8157 * @return true if command removed, false otherwise.
8258 * @since 2.0.0-SNAPSHOT.1.
8359 */
84- fun removeCommand (command : String ): Boolean =
85- registeredCommands .children.removeIf { it.name == command }
60+ fun removeCommand (command : String ) =
61+ dispatcher.root .children.removeIf { it.name == command }
8662
8763 /* *
8864 * @param context command context.
0 commit comments