brigadier icon indicating copy to clipboard operation
brigadier copied to clipboard

Support for return values other than ints with backwards-compatability

Open SerenaLynas opened this issue 3 years ago • 1 comments

This PR allows commands to return any object. Because of Java's autoboxing, it is mostly backwards compatible with older code which returns ints. The only breaking changes are that old user code which references Command<S> must be changed to Command<S, Integer>, and the return value from command execution is now Object, so the type needs to be checked/cast to int. Please let me know if there are any other breaking changes. I didn't change the tests aside from adding the Integer generic as mentioned above, so everything else should be the same.

I think that many users of this library will find the minimal cost of refactoring worth it given the immense benefit of returning more than just ints.

SerenaLynas avatar Dec 02 '22 22:12 SerenaLynas

I made minor changes to the new parts in this PR. No other changes were made since @M4ximumPizza's review.

  • Default behavior for all numeric boxed primitives (int, short, double, etc.) is now to add them, not just ints. This makes the behavior a bit more consistent across numeric types.
  • I added overloads for the execute method on CommandDispatcher which allow users to optionally specify a "base" commandResult for the other results to be combined into, ex. to get results in a list: subject.execute(parsed, new ListCommandResult())

TODO: write tests for the new functionality.

SerenaLynas avatar Dec 04 '22 05:12 SerenaLynas