diff --git a/src/main/java/net/knarcraft/paidsigns/PaidSigns.java b/src/main/java/net/knarcraft/paidsigns/PaidSigns.java index 092c127..807933c 100644 --- a/src/main/java/net/knarcraft/paidsigns/PaidSigns.java +++ b/src/main/java/net/knarcraft/paidsigns/PaidSigns.java @@ -3,8 +3,7 @@ package net.knarcraft.paidsigns; import net.knarcraft.paidsigns.command.AddCommand; import net.knarcraft.paidsigns.command.AddTabCompleter; import net.knarcraft.paidsigns.command.ReloadTabCommand; -import net.knarcraft.paidsigns.command.RemoveCommand; -import net.knarcraft.paidsigns.command.RemoveTabCompleter; +import net.knarcraft.paidsigns.command.RemoveTabCommand; import net.knarcraft.paidsigns.listener.SignListener; import net.knarcraft.paidsigns.manager.EconomyManager; import net.knarcraft.paidsigns.manager.PaidSignManager; @@ -108,8 +107,9 @@ public final class PaidSigns extends JavaPlugin { PluginCommand removeCommand = this.getCommand("removePaidSign"); if (removeCommand != null) { - removeCommand.setExecutor(new RemoveCommand()); - removeCommand.setTabCompleter(new RemoveTabCompleter()); + TabExecutor removeTabExecutor = new RemoveTabCommand(); + removeCommand.setExecutor(removeTabExecutor); + removeCommand.setTabCompleter(removeTabExecutor); } PluginCommand reloadCommand = this.getCommand("reload"); diff --git a/src/main/java/net/knarcraft/paidsigns/command/AddTabCompleter.java b/src/main/java/net/knarcraft/paidsigns/command/AddTabCompleter.java index 4e923b3..fa2dea4 100644 --- a/src/main/java/net/knarcraft/paidsigns/command/AddTabCompleter.java +++ b/src/main/java/net/knarcraft/paidsigns/command/AddTabCompleter.java @@ -35,14 +35,15 @@ public class AddTabCompleter implements TabCompleter { loadAvailablePermissions(); } List arguments = Tokenizer.tokenize(String.join(" ", args)); + int argumentSize = args[args.length - 1].isEmpty() ? arguments.size() : arguments.size() - 1; - if (arguments.size() < 1) { + if (argumentSize < 1) { return names; - } else if (arguments.size() < 2) { + } else if (argumentSize < 2) { return costs; - } else if (arguments.size() < 3) { + } else if (argumentSize < 3) { return tabCompletePermission(arguments.get(arguments.size() - 1)); - } else if (arguments.size() < 5) { + } else if (argumentSize < 5) { return options; } return new ArrayList<>(); diff --git a/src/main/java/net/knarcraft/paidsigns/command/RemoveCommand.java b/src/main/java/net/knarcraft/paidsigns/command/RemoveTabCommand.java similarity index 59% rename from src/main/java/net/knarcraft/paidsigns/command/RemoveCommand.java rename to src/main/java/net/knarcraft/paidsigns/command/RemoveTabCommand.java index 2e3eef9..6f2cc85 100644 --- a/src/main/java/net/knarcraft/paidsigns/command/RemoveCommand.java +++ b/src/main/java/net/knarcraft/paidsigns/command/RemoveTabCommand.java @@ -1,13 +1,16 @@ package net.knarcraft.paidsigns.command; import net.knarcraft.paidsigns.PaidSigns; +import net.knarcraft.paidsigns.container.PaidSign; import net.knarcraft.paidsigns.utility.Tokenizer; import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.logging.Level; @@ -16,15 +19,15 @@ import java.util.logging.Logger; /** * A representation of the command for removing a paid sign */ -public class RemoveCommand implements CommandExecutor { +public class RemoveTabCommand implements TabExecutor { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - if (args.length < 1) { + List arguments = Tokenizer.tokenize(String.join(" ", args)); + if (arguments.size() < 1) { return false; } - List arguments = Tokenizer.tokenize(String.join(" ", args)); String name = arguments.get(0); try { @@ -44,4 +47,23 @@ public class RemoveCommand implements CommandExecutor { return false; } + @Nullable + @Override + public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, + @NotNull String[] args) { + List arguments = Tokenizer.tokenize(String.join(" ", args)); + int argumentSize = args[args.length - 1].isEmpty() ? arguments.size() : arguments.size() - 1; + + if (argumentSize < 1) { + List allPaidSigns = PaidSigns.getInstance().getSignManager().getAllPaidSigns(); + List signIds = new ArrayList<>(); + for (PaidSign sign : allPaidSigns) { + signIds.add("\"" + sign.getName() + "\""); + } + return signIds; + } else { + return new ArrayList<>(); + } + } + } diff --git a/src/main/java/net/knarcraft/paidsigns/command/RemoveTabCompleter.java b/src/main/java/net/knarcraft/paidsigns/command/RemoveTabCompleter.java deleted file mode 100644 index 187e866..0000000 --- a/src/main/java/net/knarcraft/paidsigns/command/RemoveTabCompleter.java +++ /dev/null @@ -1,31 +0,0 @@ -package net.knarcraft.paidsigns.command; - -import net.knarcraft.paidsigns.PaidSigns; -import net.knarcraft.paidsigns.container.PaidSign; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabCompleter; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.List; - -/** - * The tab completer for the remove command - */ -public class RemoveTabCompleter implements TabCompleter { - - @Nullable - @Override - public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, - @NotNull String[] args) { - List allPaidSigns = PaidSigns.getInstance().getSignManager().getAllPaidSigns(); - List signIds = new ArrayList<>(); - for (PaidSign sign : allPaidSigns) { - signIds.add("\"" + sign.getName() + "\""); - } - return signIds; - } - -} diff --git a/src/main/java/net/knarcraft/paidsigns/utility/Tokenizer.java b/src/main/java/net/knarcraft/paidsigns/utility/Tokenizer.java index 30d3563..5edb1b9 100644 --- a/src/main/java/net/knarcraft/paidsigns/utility/Tokenizer.java +++ b/src/main/java/net/knarcraft/paidsigns/utility/Tokenizer.java @@ -6,7 +6,11 @@ import java.util.List; /** * A tokenizer for being able to support quotes in commands */ -public class Tokenizer { +public final class Tokenizer { + + private Tokenizer() { + + } /** * Tokenizes a string