Implement basic tab-completion
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
5b5faa6b5f
commit
c898a2341d
@ -5,6 +5,7 @@ import org.bukkit.plugin.PluginManager;
|
|||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import wtf.beatrice.nounspicker.commands.NounsCommand;
|
import wtf.beatrice.nounspicker.commands.NounsCommand;
|
||||||
import wtf.beatrice.nounspicker.objects.PAPIManager;
|
import wtf.beatrice.nounspicker.objects.PAPIManager;
|
||||||
|
import wtf.beatrice.nounspicker.objects.TabCompletion;
|
||||||
import wtf.beatrice.nounspicker.utils.Cache;
|
import wtf.beatrice.nounspicker.utils.Cache;
|
||||||
import wtf.beatrice.nounspicker.utils.ConsoleLogger;
|
import wtf.beatrice.nounspicker.utils.ConsoleLogger;
|
||||||
import wtf.beatrice.nounspicker.utils.DatabaseManager;
|
import wtf.beatrice.nounspicker.utils.DatabaseManager;
|
||||||
@ -39,6 +40,7 @@ public class NounsPicker extends JavaPlugin
|
|||||||
|
|
||||||
logger.log("Registering commands...");
|
logger.log("Registering commands...");
|
||||||
getCommand("nouns").setExecutor(new NounsCommand(this));
|
getCommand("nouns").setExecutor(new NounsCommand(this));
|
||||||
|
getCommand("nouns").setTabCompleter(new TabCompletion());
|
||||||
logger.log("Commands registered!");
|
logger.log("Commands registered!");
|
||||||
|
|
||||||
logger.log("Checking files...");
|
logger.log("Checking files...");
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
package wtf.beatrice.nounspicker.objects;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.util.StringUtil;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class TabCompletion implements org.bukkit.command.TabCompleter
|
||||||
|
{
|
||||||
|
|
||||||
|
private final List<String> mainSubCommands = new ArrayList<>(){{
|
||||||
|
add("set");
|
||||||
|
add("create");
|
||||||
|
add("delete");
|
||||||
|
add("update");
|
||||||
|
}};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
List<String> completions = new ArrayList<>();
|
||||||
|
|
||||||
|
if(args.length == 0) return null;
|
||||||
|
|
||||||
|
String mainArg = args[0].toLowerCase();
|
||||||
|
if(args.length == 1)
|
||||||
|
{
|
||||||
|
StringUtil.copyPartialMatches(mainArg, mainSubCommands, completions);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return completions;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -3,10 +3,14 @@ package wtf.beatrice.nounspicker.utils;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class Cache
|
public class Cache
|
||||||
{
|
{
|
||||||
|
|
||||||
public static DatabaseManager dbManager;
|
public static DatabaseManager dbManager;
|
||||||
|
|
||||||
|
public static List<String> pronouns = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
@ -146,6 +146,11 @@ public class DatabaseManager
|
|||||||
pStatement.setString(2, format);
|
pStatement.setString(2, format);
|
||||||
pStatement.setInt(3, pronounId);
|
pStatement.setInt(3, pronounId);
|
||||||
pStatement.executeUpdate();
|
pStatement.executeUpdate();
|
||||||
|
|
||||||
|
// add to cache
|
||||||
|
Cache.pronouns.add(pronoun);
|
||||||
|
|
||||||
|
// announce success
|
||||||
return true;
|
return true;
|
||||||
} catch (SQLException e)
|
} catch (SQLException e)
|
||||||
{
|
{
|
||||||
@ -209,6 +214,9 @@ public class DatabaseManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// remove from cache
|
||||||
|
Cache.pronouns.remove(pronoun);
|
||||||
|
|
||||||
// announce success
|
// announce success
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user