Implement @ConsumesRest annotation

This commit is contained in:
Ben Woo
2025-04-09 13:36:50 +08:00
parent 5efec647c5
commit 94815618d1
2 changed files with 42 additions and 1 deletions
@@ -25,6 +25,7 @@ package co.aikar.commands;
import co.aikar.commands.annotation.CommandPermission;
import co.aikar.commands.annotation.Conditions;
import co.aikar.commands.annotation.ConsumesRest;
import co.aikar.commands.annotation.Default;
import co.aikar.commands.annotation.Description;
import co.aikar.commands.annotation.Flags;
@@ -101,7 +102,9 @@ public class CommandParameter<CEC extends CommandExecutionContext<CEC, ? extends
//noinspection unchecked
this.commandIssuer = paramIndex == 0 && manager.isCommandIssuer(type);
this.canConsumeInput = !this.commandIssuer && !(resolver instanceof IssuerOnlyContextResolver);
this.consumesRest = isLast && ((type == String.class && !annotations.hasAnnotation(param, Single.class)) || (type == String[].class));
this.consumesRest = isLast && (annotations.hasAnnotation(param, ConsumesRest.class)
|| (type == String.class && !annotations.hasAnnotation(param, Single.class))
|| (type == String[].class));
this.values = annotations.getAnnotationValues(param, Values.class, Annotations.REPLACEMENTS | Annotations.NO_EMPTY);
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2016-2025 Daniel Ennis (Aikar) - MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package co.aikar.commands.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Marks that the parameter this is attached to should consume the rest of the arguments.
* Only applicable to the last parameter of a command.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER, ElementType.ANNOTATION_TYPE})
public @interface ConsumesRest {
}