Implements the scrapper edit command
This commit is contained in:
@ -1,15 +1,32 @@
|
||||
package net.knarcraft.blacksmith.command.scrapper;
|
||||
|
||||
import org.apache.commons.lang.NotImplementedException;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import net.knarcraft.blacksmith.BlacksmithPlugin;
|
||||
import net.knarcraft.blacksmith.command.EditCommand;
|
||||
import net.knarcraft.blacksmith.config.Settings;
|
||||
import net.knarcraft.blacksmith.config.scrapper.ScrapperSetting;
|
||||
import net.knarcraft.blacksmith.trait.ScrapperTrait;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ScrapperEditCommand implements CommandExecutor {
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] strings) {
|
||||
throw new NotImplementedException();
|
||||
/**
|
||||
* The main command used for scrapper editing
|
||||
*/
|
||||
public class ScrapperEditCommand extends EditCommand<ScrapperTrait, ScrapperSetting> {
|
||||
|
||||
/**
|
||||
* Instantiates a new scrapper edit command
|
||||
*/
|
||||
public ScrapperEditCommand() {
|
||||
super(ScrapperTrait.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScrapperSetting getSetting(String input) {
|
||||
return ScrapperSetting.getSetting(input);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Settings<ScrapperSetting> getGlobalSettings() {
|
||||
return BlacksmithPlugin.getInstance().getGlobalScrapperSettings();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,18 +1,62 @@
|
||||
package net.knarcraft.blacksmith.command.scrapper;
|
||||
|
||||
import org.apache.commons.lang.NotImplementedException;
|
||||
import net.knarcraft.blacksmith.config.scrapper.ScrapperSetting;
|
||||
import net.knarcraft.blacksmith.util.TabCompleteValuesHelper;
|
||||
import net.knarcraft.knarlib.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 scrapper editing command
|
||||
*/
|
||||
public class ScrapperEditTabCompleter implements TabCompleter {
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command,
|
||||
@NotNull String s, @NotNull String[] strings) {
|
||||
throw new NotImplementedException();
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command,
|
||||
@NotNull String s, @NotNull String[] args) {
|
||||
if (!sender.hasPermission("blacksmith.edit")) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
List<String> npcSettings = new ArrayList<>();
|
||||
for (ScrapperSetting setting : ScrapperSetting.values()) {
|
||||
if (setting.isPerNPC()) {
|
||||
npcSettings.add(setting.getCommandName());
|
||||
}
|
||||
}
|
||||
|
||||
if (args.length == 1) {
|
||||
return TabCompletionHelper.filterMatchingContains(npcSettings, args[0]);
|
||||
} else {
|
||||
if (npcSettings.contains(args[0]) && args.length == 2) {
|
||||
return tabCompleteCommandValues(args[0], args[1]);
|
||||
} else {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tab completes the values available for the given command
|
||||
*
|
||||
* @param commandName <p>The name of the used command</p>
|
||||
* @param commandValue <p>The command value used to filter tab-completions</p>
|
||||
* @return <p>Some valid options for the command's argument</p>
|
||||
*/
|
||||
private @Nullable List<String> tabCompleteCommandValues(@NotNull String commandName, @NotNull String commandValue) {
|
||||
ScrapperSetting setting = ScrapperSetting.getSetting(commandName);
|
||||
if (setting != null) {
|
||||
return TabCompletionHelper.filterMatchingContains(TabCompleteValuesHelper.getTabCompletions(
|
||||
setting.getValueType()), commandValue);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user