From 1717d7f9b4cfc596173daa865c2270bc5fd05997 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sat, 15 Aug 2020 16:41:35 -0400 Subject: [PATCH] Add SimpleCommand.Invocation#alias function. It seems like this ability is generally useful outside RawCommand, so let's add this to SimpleCommand too. --- .../velocitypowered/api/command/SimpleCommand.java | 6 ++++++ .../command/VelocitySimpleCommandInvocation.java | 14 ++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/com/velocitypowered/api/command/SimpleCommand.java b/api/src/main/java/com/velocitypowered/api/command/SimpleCommand.java index 1150c1cf1..2233e2a9b 100644 --- a/api/src/main/java/com/velocitypowered/api/command/SimpleCommand.java +++ b/api/src/main/java/com/velocitypowered/api/command/SimpleCommand.java @@ -16,5 +16,11 @@ public interface SimpleCommand extends InvocableCommand { + /** + * Returns the used alias to execute the command. + * + * @return the used command alias + */ + String alias(); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/VelocitySimpleCommandInvocation.java b/proxy/src/main/java/com/velocitypowered/proxy/command/VelocitySimpleCommandInvocation.java index 584ca092c..55b16c5a9 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/VelocitySimpleCommandInvocation.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/VelocitySimpleCommandInvocation.java @@ -15,11 +15,21 @@ final class VelocitySimpleCommandInvocation extends AbstractCommandInvocation context) { final String[] arguments = BrigadierUtils.getSplitArguments(context); - return new VelocitySimpleCommandInvocation(context.getSource(), arguments); + final String alias = BrigadierUtils.getAlias(context); + return new VelocitySimpleCommandInvocation(context.getSource(), alias, arguments); } } - VelocitySimpleCommandInvocation(final CommandSource source, final String[] arguments) { + private final String alias; + + VelocitySimpleCommandInvocation(final CommandSource source, final String alias, + final String[] arguments) { super(source, arguments); + this.alias = alias; + } + + @Override + public String alias() { + return this.alias; } }