-
-
Notifications
You must be signed in to change notification settings - Fork 75
Implement "safe-casting" #540
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
Conversation
commandapi-core/src/main/java/dev/jorel/commandapi/executors/CommandArguments.java
Outdated
Show resolved
Hide resolved
commandapi-core/src/main/java/dev/jorel/commandapi/executors/CommandArguments.java
Outdated
Show resolved
Hide resolved
ef00068
to
9f8e4cd
Compare
This comment was marked as outdated.
This comment was marked as outdated.
b3201cb
to
f15895a
Compare
7afb060
to
4aca81f
Compare
Just a note that some arguments use a raw type as their If That just means this code has a little warning: MapArgument<String, Integer> argument = new MapArgumentBuilder<String, Integer>("map")
.withKeyMapper(s -> s)
.withValueMapper(s -> Integer.parseInt(s))
.withoutKeyList()
.withoutValueList()
.build();
new CommandAPICommand("command")
.withArguments(argument)
.executes(info -> {
// Type safety: The expression of type LinkedHashMap needs unchecked conversion to conform to Map<String,Integer>
Map<String, Integer> map = info.args().getByArgument(argument);
info.sender().sendMessage(map.toString());
})
.register(); This note might also be relevant for #545. It's not a big problem, but the two systems don't currently work perfectly for these arguments: |
True, but if I am not mistaken, this is the best we can do here. |
656cb5c
to
9c6af63
Compare
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 couple of minor documentation changes and code linting tweaks (avoid the use of variables which declared non-final and are only ever used once). A critical change required for PRIMITIVE_TO_WRAPPER
commandapi-core/src/main/java/dev/jorel/commandapi/executors/CommandArguments.java
Outdated
Show resolved
Hide resolved
commandapi-core/src/main/java/dev/jorel/commandapi/executors/CommandArguments.java
Outdated
Show resolved
Hide resolved
commandapi-core/src/main/java/dev/jorel/commandapi/executors/CommandArguments.java
Outdated
Show resolved
Hide resolved
commandapi-core/src/main/java/dev/jorel/commandapi/executors/CommandArguments.java
Outdated
Show resolved
Hide resolved
commandapi-core/src/main/java/dev/jorel/commandapi/executors/CommandArguments.java
Outdated
Show resolved
Hide resolved
commandapi-core/src/main/java/dev/jorel/commandapi/executors/CommandArguments.java
Show resolved
Hide resolved
b8c182e
to
8315291
Compare
…or an index is used
8315291
to
a48f1a6
Compare
This PR is supposed to implement certain methods as suggested by Hawk here and by #535.
Currently, there is a bit more testing I want to do, additionally I am not sure if this would actually be something we want.
If so, there is a bit more work required: