2019-02-09 02:41:50 +01:00
|
|
|
/*
|
2022-04-14 03:42:00 +00:00
|
|
|
* Copyright (c) Forge Development LLC and contributors
|
2022-02-28 13:41:23 -08:00
|
|
|
* SPDX-License-Identifier: LGPL-2.1-only
|
2019-02-09 02:41:50 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package net.minecraftforge.event;
|
|
|
|
|
|
|
|
|
|
import com.mojang.brigadier.ParseResults;
|
2021-07-17 00:08:49 -05:00
|
|
|
import net.minecraft.commands.CommandSourceStack;
|
2021-11-26 05:09:56 +08:00
|
|
|
import net.minecraft.commands.Commands;
|
|
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
2019-02-09 02:41:50 +01:00
|
|
|
import net.minecraftforge.eventbus.api.Cancelable;
|
|
|
|
|
import net.minecraftforge.eventbus.api.Event;
|
2022-07-28 00:20:31 -05:00
|
|
|
import net.minecraftforge.fml.LogicalSide;
|
|
|
|
|
import org.jetbrains.annotations.Nullable;
|
2019-02-09 02:41:50 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* CommandEvent is fired after a command is parsed, but before it is executed.
|
2022-07-28 00:20:31 -05:00
|
|
|
* This event is fired during the invocation of {@link Commands#performCommand(ParseResults, String)}.
|
|
|
|
|
* <p>
|
|
|
|
|
* This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
|
|
|
|
* If the event is cancelled, the command will not be executed.
|
|
|
|
|
* <p>
|
|
|
|
|
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
|
|
|
|
* only on the {@linkplain LogicalSide#SERVER logical server}.
|
2019-02-09 02:41:50 +01:00
|
|
|
**/
|
|
|
|
|
@Cancelable
|
|
|
|
|
public class CommandEvent extends Event
|
|
|
|
|
{
|
2021-07-17 00:08:49 -05:00
|
|
|
private ParseResults<CommandSourceStack> parse;
|
2022-07-28 00:20:31 -05:00
|
|
|
@Nullable
|
2019-02-09 02:41:50 +01:00
|
|
|
private Throwable exception;
|
|
|
|
|
|
2021-07-17 00:08:49 -05:00
|
|
|
public CommandEvent(ParseResults<CommandSourceStack> parse)
|
2019-02-09 02:41:50 +01:00
|
|
|
{
|
|
|
|
|
this.parse = parse;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-28 00:20:31 -05:00
|
|
|
/**
|
|
|
|
|
* {@return the parsed command results}
|
|
|
|
|
*/
|
|
|
|
|
public ParseResults<CommandSourceStack> getParseResults()
|
|
|
|
|
{
|
|
|
|
|
return this.parse;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setParseResults(ParseResults<CommandSourceStack> 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;
|
|
|
|
|
}
|
2019-02-09 02:41:50 +01:00
|
|
|
}
|