JorelAli / CommandAPI

A Bukkit/Spigot API for the command UI introduced in Minecraft 1.13

Home Page:https://commandapi.jorel.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cast object to class like as it is done in JOOQ

Hxncusik opened this issue · comments

Description

Record#get(String var1, Class<? extends U> var2)
For example:
String item = entry.get("item", String.class);
double chance = entry.get("chance", Double.class);
double range = entry.get("range", Double.class);

Expected code

new CommandAPICommand("test").withPermission("*")
.withArguments(new FloatArgument("chance"), new FloatArgument("range"))
.executesPlayer((player, args) -> {
float chance = args.get("chance", float.class);
float range = args.get("range", float.class);
});

Extra details

No response

First off, I like this idea and this can actually be grouped with a discussion that took place on the CommandAPI discord server about two weeks ago where the general gist was to use argument instances to safe-cast arguments.
I also planned working on it eventually so thanks for your suggestion as I believe Brigadier does this like this too, I will definitely consider this when coming up with a potential solution.

Thank you for your reply, I'm very pleased to hear that. I will look forward to implementing the new features.

Implemented in version 9.4.0.