/* * Copyright (c) Forge Development LLC and contributors * SPDX-License-Identifier: LGPL-2.1-only */ package net.minecraftforge.event; import com.mojang.brigadier.ParseResults; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; import net.minecraftforge.eventbus.api.bus.CancellableEventBus; import net.minecraftforge.eventbus.api.event.MutableEvent; import net.minecraftforge.eventbus.api.event.characteristic.Cancellable; import net.minecraftforge.fml.LogicalSide; import org.jspecify.annotations.NullMarked; import org.jspecify.annotations.Nullable; /** * CommandEvent is fired after a command is parsed, but before it is executed. * This event is fired during the invocation of {@link Commands#performCommand(ParseResults, String)}. *

* This event is {@linkplain Cancellable cancellable}. If the event is cancelled, the command will not be executed. *

* This event is fired only on the {@linkplain LogicalSide#SERVER logical server}. **/ @NullMarked public final class CommandEvent extends MutableEvent implements Cancellable { public static final CancellableEventBus BUS = CancellableEventBus.create(CommandEvent.class); private ParseResults parse; private @Nullable Throwable exception; public CommandEvent(ParseResults parse) { this.parse = parse; } /** * {@return the parsed command results} */ public ParseResults getParseResults() { return this.parse; } public void setParseResults(ParseResults parse) { this.parse = parse; } /** * {@return an exception to be thrown when performing the command, starts null} */ @Nullable public Throwable getException() { return this.exception; } public void setException(@Nullable Throwable exception) { this.exception = exception; } }