JorelAli / CommandAPI

A Bukkit/Spigot API for the command UI introduced in Minecraft 1.13
https://commandapi.jorel.dev
MIT License
504 stars 60 forks source link

Cast object to class like as it is done in JOOQ #535

Closed Hxncusik closed 2 months ago

Hxncusik commented 3 months ago

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

DerEchtePilz commented 3 months ago

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.

Hxncusik commented 3 months ago

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

JorelAli commented 2 months ago

Implemented in version 9.4.0.