Adds a preset command which can be used to see available presets Adds preset filters which can be used to specify item sub-categories within a preset Removes SWORD_SMITH and RANGED_SMITH, as those are replaced by the RANGED and SWORD filters Adds a list of usable filters for each preset
61 lines
2.2 KiB
Java
61 lines
2.2 KiB
Java
package net.knarcraft.blacksmith.command;
|
|
|
|
import net.knarcraft.blacksmith.config.SmithPreset;
|
|
import net.knarcraft.blacksmith.config.SmithPresetFilter;
|
|
import net.knarcraft.blacksmith.util.TabCompletionHelper;
|
|
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 preset command
|
|
*/
|
|
public class PresetTabCompleter implements TabCompleter {
|
|
|
|
@Nullable
|
|
@Override
|
|
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
|
|
@NotNull String[] args) {
|
|
//Only one argument is expected
|
|
if (args.length > 1) {
|
|
return new ArrayList<>();
|
|
}
|
|
//If no preset has been fully matched, tab-complete for presets.
|
|
//If a preset has been fully matched, tab-complete for applicable filters
|
|
|
|
String input = args[0].toUpperCase().replace('-', '_');
|
|
|
|
List<String> completions = new ArrayList<>();
|
|
String filterString = "";
|
|
|
|
if (input.contains(":")) {
|
|
String[] parts = input.split(":");
|
|
input = parts[0];
|
|
filterString = parts.length > 1 ? parts[1] : "";
|
|
}
|
|
|
|
//Add tab-completions for all supported filters
|
|
try {
|
|
List<SmithPresetFilter> filters = SmithPreset.valueOf(input).getSupportedFilters();
|
|
for (SmithPresetFilter filter : filters) {
|
|
if (filterString.isEmpty() || filter.name().contains(filterString)) {
|
|
completions.add(input + ":" + filter.name());
|
|
}
|
|
}
|
|
} catch (IllegalArgumentException ignored) {
|
|
/* An illegal argument exception here simply means that the user has typed an unrecognized smith preset.
|
|
This can be safely ignored, as it simply means no filter tab-completions are necessary. */
|
|
}
|
|
|
|
//Adds all default completions
|
|
completions.addAll(TabCompletionHelper.filterMatchingContains(SmithPreset.getPresetNames(), input));
|
|
return completions;
|
|
}
|
|
|
|
}
|