Fixes tab-completion when editing default messages

This commit is contained in:
Kristian Knarvik 2022-10-25 19:45:45 +02:00
parent b38cfbe710
commit 4d740521f3

View File

@ -31,6 +31,11 @@ public class BlackSmithConfigTabCompleter implements TabCompleter {
//Arguments: <setting> [new value/material or enchantment] []
//Prevent tab-completion when typing messages with spaces
if (skipCompletionForSpacedMessage(args) != null) {
return new ArrayList<>();
}
if (args.length == 1) {
List<String> availableCommands = new ArrayList<>();
availableCommands.add("reload");
@ -55,6 +60,28 @@ public class BlackSmithConfigTabCompleter implements TabCompleter {
return null;
}
/**
* Checks whether to tab-complete nothing because a message containing spaces is being written
*
* @param args <p>The arguments given by the user</p>
* @return <p>Null if not writing a spaced message</p>
*/
private List<String> skipCompletionForSpacedMessage(String[] args) {
if (args.length > 2) {
NPCSetting npcSetting = null;
for (NPCSetting setting : NPCSetting.values()) {
if (setting.getCommandName().equalsIgnoreCase(args[0])) {
npcSetting = setting;
break;
}
}
if (npcSetting != null && npcSetting.getPath().startsWith("defaults.messages")) {
return new ArrayList<>();
}
}
return null;
}
/**
* Gets tab-completions for a selected material or enchantment
*