Removes some redundancy between tab completers
This commit is contained in:
parent
7e01d77723
commit
8a030276c5
@ -1,10 +1,8 @@
|
||||
package net.knarcraft.paidsigns.command;
|
||||
|
||||
import net.knarcraft.paidsigns.utility.TabCompleteHelper;
|
||||
import net.knarcraft.paidsigns.utility.Tokenizer;
|
||||
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;
|
||||
|
||||
@ -14,7 +12,7 @@ import java.util.List;
|
||||
/**
|
||||
* The tab completer for the add paid sign condition command
|
||||
*/
|
||||
public class AddConditionTabCompleter implements TabCompleter {
|
||||
public class AddConditionTabCompleter extends TokenizedTabCompleter {
|
||||
|
||||
private List<String> lineIndices;
|
||||
private List<String> stringsToMatch;
|
||||
@ -25,12 +23,10 @@ public class AddConditionTabCompleter implements TabCompleter {
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias,
|
||||
@NotNull String[] args) {
|
||||
super.onTabComplete(sender, command, alias, args);
|
||||
if (lineIndices == null) {
|
||||
initializeValues();
|
||||
}
|
||||
|
||||
List<String> arguments = Tokenizer.tokenize(String.join(" ", args));
|
||||
int argumentSize = args[args.length - 1].isEmpty() ? arguments.size() : arguments.size() - 1;
|
||||
if (argumentSize < 1) {
|
||||
return TabCompleteHelper.getPaidSignNames();
|
||||
} else if (argumentSize < 2) {
|
||||
|
@ -1,11 +1,9 @@
|
||||
package net.knarcraft.paidsigns.command;
|
||||
|
||||
import net.knarcraft.paidsigns.utility.TabCompleteHelper;
|
||||
import net.knarcraft.paidsigns.utility.Tokenizer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@ -19,7 +17,7 @@ import java.util.StringJoiner;
|
||||
/**
|
||||
* The tab completer for the add paid sign command
|
||||
*/
|
||||
public class AddTabCompleter implements TabCompleter {
|
||||
public class AddTabCompleter extends TokenizedTabCompleter {
|
||||
|
||||
private static List<String> names;
|
||||
private static List<String> costs;
|
||||
@ -31,12 +29,11 @@ public class AddTabCompleter implements TabCompleter {
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias,
|
||||
@NotNull String[] args) {
|
||||
super.onTabComplete(sender, command, alias, args);
|
||||
if (names == null) {
|
||||
initializeValues();
|
||||
loadAvailablePermissions();
|
||||
}
|
||||
List<String> arguments = Tokenizer.tokenize(String.join(" ", args));
|
||||
int argumentSize = args[args.length - 1].isEmpty() ? arguments.size() : arguments.size() - 1;
|
||||
|
||||
if (argumentSize < 1) {
|
||||
return names;
|
||||
|
@ -1,10 +1,8 @@
|
||||
package net.knarcraft.paidsigns.command;
|
||||
|
||||
import net.knarcraft.paidsigns.utility.TabCompleteHelper;
|
||||
import net.knarcraft.paidsigns.utility.Tokenizer;
|
||||
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;
|
||||
|
||||
@ -14,7 +12,7 @@ import java.util.List;
|
||||
/**
|
||||
* The tab completer for the remove paid sign condition command
|
||||
*/
|
||||
public class RemoveConditionTabCompleter implements TabCompleter {
|
||||
public class RemoveConditionTabCompleter extends TokenizedTabCompleter {
|
||||
|
||||
private List<String> lineIndices;
|
||||
|
||||
@ -22,11 +20,10 @@ public class RemoveConditionTabCompleter implements TabCompleter {
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias,
|
||||
@NotNull String[] args) {
|
||||
super.onTabComplete(sender, command, alias, args);
|
||||
if (lineIndices == null) {
|
||||
initializeValues();
|
||||
}
|
||||
List<String> arguments = Tokenizer.tokenize(String.join(" ", args));
|
||||
int argumentSize = args[args.length - 1].isEmpty() ? arguments.size() : arguments.size() - 1;
|
||||
|
||||
if (argumentSize < 1) {
|
||||
return TabCompleteHelper.getPaidSignNames();
|
||||
|
@ -0,0 +1,28 @@
|
||||
package net.knarcraft.paidsigns.command;
|
||||
|
||||
import net.knarcraft.paidsigns.utility.Tokenizer;
|
||||
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.List;
|
||||
|
||||
/**
|
||||
* A tab completer with tokenized arguments
|
||||
*/
|
||||
public class TokenizedTabCompleter implements TabCompleter {
|
||||
|
||||
protected List<String> arguments;
|
||||
protected int argumentSize;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
|
||||
arguments = Tokenizer.tokenize(String.join(" ", args));
|
||||
argumentSize = args[args.length - 1].isEmpty() ? arguments.size() : arguments.size() - 1;
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user