Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions src/main/java/org/spongepowered/api/event/SpongeEventFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
import org.spongepowered.api.event.cause.Cause;
import org.spongepowered.api.event.cause.entity.damage.DamageModifier;
import org.spongepowered.api.event.cause.entity.health.HealthModifier;
import org.spongepowered.api.event.command.SendCommandEvent;
import org.spongepowered.api.event.command.CommandProcessEvent;
import org.spongepowered.api.event.command.TabCompleteEvent;
import org.spongepowered.api.event.data.ChangeDataHolderEvent;
import org.spongepowered.api.event.economy.EconomyTransactionEvent;
Expand Down Expand Up @@ -1015,21 +1015,39 @@ public static TargetTileEntityEvent createTargetTileEntityEvent(Cause cause, Til
/**
* AUTOMATICALLY GENERATED, DO NOT EDIT.
* Creates a new instance of
* {@link org.spongepowered.api.event.command.SendCommandEvent}.
* {@link org.spongepowered.api.event.command.CommandProcessEvent.Post}.
*
* @param cause The cause
* @param arguments The arguments
* @param command The command
* @param result The result
* @return A new send command event
* @return A new post command process event
*/
public static SendCommandEvent createSendCommandEvent(Cause cause, String arguments, String command, CommandResult result) {
public static CommandProcessEvent.Post createCommandProcessEventPost(Cause cause, String arguments, String command, CommandResult result) {
HashMap<String, Object> values = new HashMap<>();
values.put("cause", cause);
values.put("arguments", arguments);
values.put("command", command);
values.put("result", result);
return SpongeEventFactoryUtils.createEventImpl(SendCommandEvent.class, values);
return SpongeEventFactoryUtils.createEventImpl(CommandProcessEvent.Post.class, values);
}

/**
* AUTOMATICALLY GENERATED, DO NOT EDIT.
* Creates a new instance of
* {@link org.spongepowered.api.event.command.CommandProcessEvent.Pre}.
*
* @param cause The cause
* @param arguments The arguments
* @param command The command
* @return A new pre command process event
*/
public static CommandProcessEvent.Pre createCommandProcessEventPre(Cause cause, String arguments, String command) {
HashMap<String, Object> values = new HashMap<>();
values.put("cause", cause);
values.put("arguments", arguments);
values.put("command", command);
return SpongeEventFactoryUtils.createEventImpl(CommandProcessEvent.Pre.class, values);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,60 @@
import org.spongepowered.api.event.Event;

/**
* Fired when a command is sent
* Fired when a command is processed
*/
public interface SendCommandEvent extends Event, Cancellable {
public interface CommandProcessEvent extends Event {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the setResult() method inside After could be removed.


/**
* Get the command as a string, without any sort of command prefix.
*
* <p>For example, if the message was {@code /example bob 3 -f}, then
* the command would be {@code example}.</p>
*
* @return The command
* Fired before the command is processed
*/
String getCommand();
public interface Pre extends CommandProcessEvent, Cancellable {

/**
* Set the command as a string, without any sort of command prefix.
*
* <p>For example, if the message was {@code /example bob 3 -f}, then
* the command would be {@code example}.</p>
*
* @param command The command
*/
void setCommand(String command);

/**
* Set the arguments as a string.
*
* <p>For example, if the message was {@code /example bob 3 -f}, then
* the arguments would be {@code bob 3 -f}.</p>
*
* @param arguments The arguments
*/
void setArguments(String arguments);

}

/**
* Fired after the command is processed
*/
public interface Post extends CommandProcessEvent {

/**
* The result of the command.
*
* @return The result of the command
*/
CommandResult getResult();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd move this to CommandProcessEvent.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? This event is fired after the command is processed, which allows a result to be present; Pre is fired before the command is processed, meaning no result has been produced yet.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


}

/**
* Set the command as a string, without any sort of command prefix.
* Get the command as a string, without any sort of command prefix.
*
* <p>For example, if the message was {@code /example bob 3 -f}, then
* the command would be {@code example}.</p>
*
* @param command The command
* @return The command
*/
void setCommand(String command);
String getCommand();

/**
* Get the arguments as a string.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The removal of setResult from the Pre event, means that plugins which provide command redirection / rewriting will be unable to return the result of the original processed command, when the event is cancelled.

Whether this is a good or bad thing however I can't decide.

You could argue that instead of cancelling, you should just rewrite the redirected command into the original and let it continue if you actually need the CommandResult.

But without setting a result, cancelling would have to make an assumption about the appropriate CommandResult to return, as

CommandResult process(CommandSource source, String arguments);
does not return an Optional

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about CommandResult.empty()? Or maybe CommandResult.cancelled() (we'll have to create one)

Expand All @@ -63,28 +94,4 @@ public interface SendCommandEvent extends Event, Cancellable {
*/
String getArguments();

/**
* Set the arguments as a string.
*
* <p>For example, if the message was {@code /example bob 3 -f}, then
* the arguments would be {@code bob 3 -f}.</p>
*
* @param arguments The arguments
*/
void setArguments(String arguments);

/**
* The result of the command.
*
* @return The result of the command
*/
CommandResult getResult();

/**
* Sets the result of the command.
*
* @param result The result of the command
*/
void setResult(CommandResult result);

}