From 07f1661259b5d5e1977232f0b588175716b0cc72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Sat, 20 Jan 2024 19:02:18 +0100 Subject: [PATCH] fix: use numerical Ranges in Brigadier mappings --- .../brigadier/CloudBrigadierManager.java | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/cloud-brigadier/src/main/java/cloud/commandframework/brigadier/CloudBrigadierManager.java b/cloud-brigadier/src/main/java/cloud/commandframework/brigadier/CloudBrigadierManager.java index 7161361d..0e532c3f 100644 --- a/cloud-brigadier/src/main/java/cloud/commandframework/brigadier/CloudBrigadierManager.java +++ b/cloud-brigadier/src/main/java/cloud/commandframework/brigadier/CloudBrigadierManager.java @@ -119,21 +119,27 @@ public CloudBrigadierManager( private void registerInternalMappings() { /* Map byte, short and int to IntegerArgumentType */ this.registerMapping(new TypeToken>() { - }, builder -> builder.to(argument -> IntegerArgumentType.integer(argument.min(), argument.max())).cloudSuggestions()); + }, builder -> builder.to(argument -> IntegerArgumentType.integer( + argument.range().minByte(), + argument.range().maxByte())).cloudSuggestions() + ); this.registerMapping(new TypeToken>() { - }, builder -> builder.to(argument -> IntegerArgumentType.integer(argument.min(), argument.max())).cloudSuggestions()); + }, builder -> builder.to(argument -> IntegerArgumentType.integer( + argument.range().minShort(), + argument.range().maxShort())).cloudSuggestions() + ); this.registerMapping(new TypeToken>() { }, builder -> builder.to(argument -> { if (!argument.hasMin() && !argument.hasMax()) { return IntegerArgumentType.integer(); } if (argument.hasMin() && !argument.hasMax()) { - return IntegerArgumentType.integer(argument.min()); + return IntegerArgumentType.integer(argument.range().minInt()); } else if (!argument.hasMin()) { // Brig uses Integer.MIN_VALUE and Integer.MAX_VALUE for default min/max - return IntegerArgumentType.integer(Integer.MIN_VALUE, argument.max()); + return IntegerArgumentType.integer(Integer.MIN_VALUE, argument.range().maxInt()); } - return IntegerArgumentType.integer(argument.min(), argument.max()); + return IntegerArgumentType.integer(argument.range().minInt(), argument.range().maxInt()); }).cloudSuggestions()); /* Map float to FloatArgumentType */ this.registerMapping(new TypeToken>() { @@ -142,12 +148,12 @@ private void registerInternalMappings() { return FloatArgumentType.floatArg(); } if (argument.hasMin() && !argument.hasMax()) { - return FloatArgumentType.floatArg(argument.min()); + return FloatArgumentType.floatArg(argument.range().minFloat()); } else if (!argument.hasMin()) { // Brig uses -Float.MAX_VALUE and Float.MAX_VALUE for default min/max - return FloatArgumentType.floatArg(-Float.MAX_VALUE, argument.max()); + return FloatArgumentType.floatArg(-Float.MAX_VALUE, argument.range().maxFloat()); } - return FloatArgumentType.floatArg(argument.min(), argument.max()); + return FloatArgumentType.floatArg(argument.range().minFloat(), argument.range().maxFloat()); }).cloudSuggestions()); /* Map double to DoubleArgumentType */ this.registerMapping(new TypeToken>() { @@ -156,12 +162,12 @@ private void registerInternalMappings() { return DoubleArgumentType.doubleArg(); } if (argument.hasMin() && !argument.hasMax()) { - return DoubleArgumentType.doubleArg(argument.min()); + return DoubleArgumentType.doubleArg(argument.range().minDouble()); } else if (!argument.hasMin()) { // Brig uses -Double.MAX_VALUE and Double.MAX_VALUE for default min/max - return DoubleArgumentType.doubleArg(-Double.MAX_VALUE, argument.max()); + return DoubleArgumentType.doubleArg(-Double.MAX_VALUE, argument.range().maxDouble()); } - return DoubleArgumentType.doubleArg(argument.min(), argument.max()); + return DoubleArgumentType.doubleArg(argument.range().minDouble(), argument.range().maxDouble()); }).cloudSuggestions()); /* Map long parser to LongArgumentType */ this.registerMapping(new TypeToken>() { @@ -170,12 +176,12 @@ private void registerInternalMappings() { return LongArgumentType.longArg(); } if (longParser.hasMin() && !longParser.hasMax()) { - return LongArgumentType.longArg(longParser.min()); + return LongArgumentType.longArg(longParser.range().minLong()); } else if (!longParser.hasMin()) { // Brig uses Long.MIN_VALUE and Long.MAX_VALUE for default min/max - return LongArgumentType.longArg(Long.MIN_VALUE, longParser.max()); + return LongArgumentType.longArg(Long.MIN_VALUE, longParser.range().maxLong()); } - return LongArgumentType.longArg(longParser.min(), longParser.max()); + return LongArgumentType.longArg(longParser.range().minLong(), longParser.range().maxLong()); }).cloudSuggestions()); /* Map boolean to BoolArgumentType */ this.registerMapping(new TypeToken>() {