Implement list command and fix caching issue
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Cache was not initialized correctly by loading pronouns from database at startup.
This commit is contained in:
parent
c898a2341d
commit
7b3f0941e1
@ -60,6 +60,8 @@ public class NounsPicker extends JavaPlugin
|
||||
{
|
||||
logger.log("Database connection initialized!");
|
||||
Cache.dbManager = dbManager;
|
||||
Cache.pronouns = dbManager.getAllPronouns();
|
||||
logger.log("Database data loaded into memory!");
|
||||
} else {
|
||||
logger.err("Error initializing database connection!");
|
||||
}
|
||||
|
@ -5,10 +5,7 @@ import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import wtf.beatrice.nounspicker.NounsPicker;
|
||||
import wtf.beatrice.nounspicker.commands.subcommands.NounsCreateSubCommand;
|
||||
import wtf.beatrice.nounspicker.commands.subcommands.NounsDeleteSubCommand;
|
||||
import wtf.beatrice.nounspicker.commands.subcommands.NounsSetSubCommand;
|
||||
import wtf.beatrice.nounspicker.commands.subcommands.NounsUpdateSubCmd;
|
||||
import wtf.beatrice.nounspicker.commands.subcommands.*;
|
||||
|
||||
public class NounsCommand implements CommandExecutor
|
||||
{
|
||||
@ -42,6 +39,8 @@ public class NounsCommand implements CommandExecutor
|
||||
return NounsDeleteSubCommand.run(sender, args);
|
||||
case "update":
|
||||
return NounsUpdateSubCmd.run(sender, args);
|
||||
case "list":
|
||||
return NounsListSubCommand.run(sender);
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,25 @@
|
||||
package wtf.beatrice.nounspicker.commands.subcommands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import wtf.beatrice.nounspicker.utils.Cache;
|
||||
|
||||
public class NounsListSubCommand
|
||||
{
|
||||
|
||||
// todo: pagination
|
||||
|
||||
public static boolean run(@NotNull CommandSender sender)
|
||||
{
|
||||
|
||||
sender.sendMessage("Pronouns List:");
|
||||
for(int i = 0; i < Cache.pronouns.size(); i++) {
|
||||
String pronoun = Cache.pronouns.get(i);
|
||||
int pronounId = Cache.dbManager.getPronounId(pronoun);
|
||||
String format = Cache.dbManager.getPronounFormat(pronounId);
|
||||
sender.sendMessage(i+1 + " - " + format);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -12,6 +12,7 @@ public class TabCompletion implements org.bukkit.command.TabCompleter
|
||||
|
||||
private final List<String> mainSubCommands = new ArrayList<>(){{
|
||||
add("set");
|
||||
add("list");
|
||||
add("create");
|
||||
add("delete");
|
||||
add("update");
|
||||
|
@ -312,5 +312,24 @@ public class DatabaseManager
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<String> getAllPronouns() {
|
||||
String query = "SELECT pronoun FROM pronouns;";
|
||||
|
||||
List<String> allPronouns = new ArrayList<>();
|
||||
|
||||
try(Statement stmt = dbConnection.createStatement()) {
|
||||
ResultSet rSet = stmt.executeQuery(query);
|
||||
|
||||
if(rSet.isClosed()) return allPronouns;
|
||||
|
||||
while(rSet.next()) {
|
||||
allPronouns.add(rSet.getString("pronoun"));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return allPronouns;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user