From e47f54e3763df58fccfd1df72cf05a059fda3b0e Mon Sep 17 00:00:00 2001 From: Frank van der Heijden Date: Sat, 18 Dec 2021 12:45:48 +0100 Subject: [PATCH] paper: Fix handling of empty slash buffer in async suggestion listener (#327) --- .../paper/AsyncCommandSuggestionsListener.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cloud-minecraft/cloud-paper/src/main/java/cloud/commandframework/paper/AsyncCommandSuggestionsListener.java b/cloud-minecraft/cloud-paper/src/main/java/cloud/commandframework/paper/AsyncCommandSuggestionsListener.java index 1c9b1988..357b1ec8 100644 --- a/cloud-minecraft/cloud-paper/src/main/java/cloud/commandframework/paper/AsyncCommandSuggestionsListener.java +++ b/cloud-minecraft/cloud-paper/src/main/java/cloud/commandframework/paper/AsyncCommandSuggestionsListener.java @@ -42,7 +42,11 @@ final class AsyncCommandSuggestionsListener implements Listener { @EventHandler void onTabCompletion(final @NonNull AsyncTabCompleteEvent event) { - if (event.getBuffer().trim().isEmpty()) { + /* Turn '(/)plugin:command arg1 arg2 ...' into 'plugin:command arg1 arg2 ...' */ + final String strippedBuffer = event.getBuffer().startsWith("/") + ? event.getBuffer().substring(1) + : event.getBuffer(); + if (strippedBuffer.trim().isEmpty()) { return; } @@ -50,11 +54,8 @@ final class AsyncCommandSuggestionsListener implements Listener { final BukkitPluginRegistrationHandler bukkitPluginRegistrationHandler = (BukkitPluginRegistrationHandler) this.paperCommandManager.getCommandRegistrationHandler(); - /* Turn '(/)plugin:command arg1 arg2 ...' into 'plugin:command' */ - final String commandLabel = (event.getBuffer().startsWith("/") - ? event.getBuffer().substring(1) - : event.getBuffer()) - .split(" ")[0]; + /* Turn 'plugin:command arg1 arg2 ...' into 'plugin:command' */ + final String commandLabel = strippedBuffer.split(" ")[0]; if (!bukkitPluginRegistrationHandler.isRecognized(commandLabel)) { return; }