Skip to content

Commit

Permalink
Added CommandBuiltContext parameter to register command event
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucraft committed Sep 12, 2024
1 parent 2b59e1c commit aee6f20
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package net.threetag.palladiumcore.event;

import com.mojang.brigadier.CommandDispatcher;
import net.minecraft.commands.CommandBuildContext;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;

public interface CommandEvents {

/**
* @see Register#register(CommandDispatcher, Commands.CommandSelection)
* @see Register#register(CommandDispatcher, CommandBuildContext, Commands.CommandSelection)
*/
Event<Register> REGISTER = new Event<>(Register.class, listeners -> (d, s) -> {
Event<Register> REGISTER = new Event<>(Register.class, listeners -> (d, c, s) -> {
for (Register listener : listeners) {
listener.register(d, s);
listener.register(d, c, s);
}
});

Expand All @@ -22,9 +23,10 @@ interface Register {
* Used to register custom commands. Called after the server has registered its own.
*
* @param dispatcher Command dispatcher used for registering commands
* @param context Returns the context to build the commands for.
* @param selection The environment the command is being registered for
*/
void register(CommandDispatcher<CommandSourceStack> dispatcher, Commands.CommandSelection selection);
void register(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext context, Commands.CommandSelection selection);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void onInitialize() {
private void events() {
PalladiumSpawnEggItem.setupEvents();

CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> CommandEvents.REGISTER.invoker().register(dispatcher, environment));
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> CommandEvents.REGISTER.invoker().register(dispatcher, registryAccess, environment));

ServerLifecycleEvents.SERVER_STARTING.register(server -> LifecycleEvents.SERVER_ABOUT_TO_START.invoker().server(server));
ServerLifecycleEvents.SERVER_STARTED.register(server -> LifecycleEvents.SERVER_STARTED.invoker().server(server));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class PalladiumCoreEventHandler {

@SubscribeEvent(priority = EventPriority.HIGH)
public static void registerCommands(RegisterCommandsEvent e) {
CommandEvents.REGISTER.invoker().register(e.getDispatcher(), e.getCommandSelection());
CommandEvents.REGISTER.invoker().register(e.getDispatcher(), e.getBuildContext(), e.getCommandSelection());
}

@SubscribeEvent(priority = EventPriority.HIGH)
Expand Down

0 comments on commit aee6f20

Please sign in to comment.