Skip to content

[WIP] Add CommandResult#552

Closed
boformer wants to merge 9 commits intoSpongePowered:masterfrom
boformer:feature/commandresult
Closed

[WIP] Add CommandResult#552
boformer wants to merge 9 commits intoSpongePowered:masterfrom
boformer:feature/commandresult

Conversation

@boformer
Copy link
Contributor

@boformer boformer commented Apr 6, 2015

Continuation of #409 and #524

This issue explains what command stats are used for: #326. I don't know why it was closed.

This PR replaces the boolean that is returned when a command is called with a CommandResult object, which stores the command stats SuccessCount, AffectedBlocks, AffectedEntities, AffectedItems and QueryResult. I also added a Map for custom data.

The CommandResult is passed with the CommandEvent after the execution of the command.

The implementation is based on @AlphaModder's pull request, but uses classes instead of interfaces to make it easier to use the system (similar to the Text API).

The only thing that changes is that plugin developers now have to use a builder to create a CommandResult:

MyCommand implements CommandCallable {
    CommandResult call(CommandSource source, String arguments, List<String> parents) {
        ...
        return CommandResults.processed(); 
        // equal to CommandResults.builder().setProcessed(true).build();
    }
    ...
}

I'm not sure if this is the best way of implementing it. I also thought about a system that uses separate classes for each result data type (similar to the Data API proposal):

CommandResult {
    boolean wasProcessed();
    <T> Optional<T> getData(Class<T extends CommandResultData> clazz);
}

@stephan-gh
Copy link
Contributor

The code style is wrong in some files

Copy link
Contributor

Choose a reason for hiding this comment

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

Need better docs here for what the query result is.

@boformer boformer changed the title Add CommandResult [WIP] Add CommandResult Apr 7, 2015
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right now there is a problem with this setter (tests fail).

Should I change it to setResult(Optional<CommandResult> result)?

Copy link
Member

Choose a reason for hiding this comment

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

No Afaik the optional is only for return types.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's true, but the event system does not work if the setter does not use the same type.

Copy link
Contributor

Choose a reason for hiding this comment

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

You haven't added the key 'result' to the SpongeEventFactory

@zml2008
Copy link
Member

zml2008 commented Apr 7, 2015

I'm not sure about even having the processed flag in here. If we go with what I proposed in #551, the SimpleCommandService call method can handle all the logic of calling the event and printing not found messages if necessary.

I definitely think adding a map for custom attributes is too much at this point in time. If somebody can give an actual (meaning something they're trying to do in a plugin), specific use case for it that is a lot more complicated without, then we can always add it in later.

Also, you should expand on your javadocs to explain what each value does in terms of the game (like: entities affected is entities matched by arguments, success count is entities successfuly affected (why? who knows)

I'll put in a few line comments on other little things.

Copy link
Member

Choose a reason for hiding this comment

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

This should be private or package-local (no spec) or this class should be marked final. We only want people instantiating it through the builder

@Zidane Zidane added this to the 2.1-Release milestone Apr 8, 2015
Copy link
Contributor

Choose a reason for hiding this comment

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

public?

@boformer boformer force-pushed the feature/commandresult branch from b5eb229 to 01c87a3 Compare April 9, 2015 13:57
@zml2008 zml2008 mentioned this pull request Apr 10, 2015
@Zidane
Copy link
Member

Zidane commented Apr 11, 2015

This is now a part of zml's Commands Overhaul PR. Closing.

@Zidane Zidane closed this Apr 11, 2015
zml2008 added a commit that referenced this pull request Apr 17, 2015
Fixes #551. Closes #539. Closes #532. Closes #523.

Add CommandResult object to hold results of command execution.
Closes #552

Add LocatedSource class for command sources with a location

Allow configurable conflict resoultion at command execution time
Closes #562

Tweak formatting, work on dimension, world, and child command elements

Add an abstract command element that supports matching by pattern and apply it to world, player, catalog type, and enum values argument types
@gabizou gabizou modified the milestones: Revision 3.0, Revision 2.1 May 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants