-
-
Notifications
You must be signed in to change notification settings - Fork 71
adding #360 #369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adding #360 #369
Conversation
Also, just wanted to mention that this currently is untested which will be done until noon on Saturday. |
As requested on discord, I will now add some code examples and explain my changes a little more. 1. Internal changesTo be able to implement this without having to use if-statements (in fact, I didn't use a single one), I changed the 1.1 Interfaces and
|
Not scheduling for 8.6.0 - too close to the expected release date. I'm more than happy to have this for 9.0.0. My problem with this implementation is the limited scope for future extensibility. The CommandAPI has been around for just over four years and we're only now adding more accessibly functionality to the
I think going with a record would be better. It would allow us (CommandAPI development team) to be able to expand the list of accessible functions easily without causing backwards-incompatible changes and without CommandAPI users needing to change their executor implementation. Perhaps something like this would be better? new CommandAPICommand("withmap")
.withArguments(new ItemStackArgument("item"))
.executesPlayer(info -> {
ItemStack possibilityOne = info.args()[0]; // Access using args()
ItemStack possibilityTwo = info.argsMap().get("item"); // Access using argsMap()
Player player = info.sender(); // Access command sender. Using generics, we can make this a Player instead of a CommandSender object.
})
.register(); |
Yes, I read that record suggestion in #360 and also tried to implement it like that. |
I envision something along the lines of creating a generalized record like this: public record ExecutionInfo<Sender extends CommandSender> (
Sender sender,
Object[] args,
Map<String, Object> argsMap
) {} I think in the long run it would be safer to create a generic functional interface for our two types rather than using public interface INormalExecution<Sender extends CommandSender> extends IExecutorTyped {
@Override
default int executeWith(CommandSender sender, Object[] args) throws WrapperCommandSyntaxException {
// Some implementation here... either changing the parameters to this function
// to using ExecutionInfo or something? I didn't think this far ahead
return 1;
}
void run(ExecutionInfo<Sender> info) throws WrapperCommandSyntaxException;
} Then I think it's safe to say we can add our implementations for each execution type and then link them into @FunctionalInterface
public interface PlayerCommandExecution extends INormalExecution<Player> {
void run(ExecutionInfo<Player> player) throws WrapperCommandSyntaxException;
@Override
default ExecutorType getType() {
return ExecutorType.PLAYER;
}
} And then linking: // class dev.jorel.commandapi.Executable {
public T executesPlayer(PlayerCommandExecution executor) {
this.executor.addNormalExecutor(executor); // Something to this effect
return (T) this;
}
// } If all of the names of "executor" and "execution" and "executable" start getting too complicated, feel free to choose alternatives for the new classes! In short, the main idea is that we have one centralized record which is easy to update with new changes, and then each new executor implements that. |
This is now tested and should work! Also, I decided to not include the |
@DerEchtePilz Please update this branch with the latest changes from
|
commandapi-core/src/main/java/dev/jorel/commandapi/Brigadier.java
Outdated
Show resolved
Hide resolved
commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIHandler.java
Outdated
Show resolved
Hide resolved
commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIHandler.java
Outdated
Show resolved
Hide resolved
commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIHandler.java
Outdated
Show resolved
Hide resolved
commandapi-core/src/main/java/dev/jorel/commandapi/executors/CommandArguments.java
Show resolved
Hide resolved
commandapi-core/src/main/java/dev/jorel/commandapi/executors/ExecutionInfo.java
Outdated
Show resolved
Hide resolved
So, what I've decided to do is that I will first resolve those issues right here (because honestly, I kinda do not want to mess anything up) and then I will update this branch. Can someone please tell me how to update this branch? I've merged conflicting files before but it is important (for me, you and this pull request) that everything goes well. |
… argsToObjectArr to argsToCommandArgs
commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIHandler.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few minor tid-bits that I noticed during manual testing, but nothing severe enough to prevent merging it over. These minor points should be addressed before 9.0.0 goes out though.
/** | ||
* @return The wrapper type of this command | ||
*/ | ||
WrapperType senderWrapper(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is exposed to the end user. A comment stating that this is only used internally, and you should be using sender()
instead would be nice.
* @param nodeName The node name of this argument. This was set when initializing an argument | ||
* @return an argument which has the given node name | ||
*/ | ||
public Object get(String nodeName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method can return null (if nodeName
is not found). This should be made known to the end user (by using the javax.annotation.Nullable
annotation) and it should be stated in the JavaDocs that this can return null if nodeName
is not found.
Hello!
It's me again.
I opened this PR so you can decide if you want to have it in 8.6.0 or later (or if you want me to change/add anything).