Implement format update command
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
e6534c54e1
commit
5b5faa6b5f
@ -8,6 +8,7 @@ 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;
|
||||
|
||||
public class NounsCommand implements CommandExecutor
|
||||
{
|
||||
@ -39,6 +40,8 @@ public class NounsCommand implements CommandExecutor
|
||||
return NounsCreateSubCommand.run(sender, args);
|
||||
case "delete":
|
||||
return NounsDeleteSubCommand.run(sender, args);
|
||||
case "update":
|
||||
return NounsUpdateSubCmd.run(sender, args);
|
||||
}
|
||||
|
||||
|
||||
|
@ -11,7 +11,6 @@ public class NounsCreateSubCommand
|
||||
@NotNull String[] args)
|
||||
{
|
||||
|
||||
|
||||
if(args.length < 3)
|
||||
{
|
||||
sender.sendMessage("usage: /nouns create <pronoun> <format>");
|
||||
|
@ -0,0 +1,39 @@
|
||||
package wtf.beatrice.nounspicker.commands.subcommands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import wtf.beatrice.nounspicker.utils.Cache;
|
||||
|
||||
public class NounsUpdateSubCmd
|
||||
{
|
||||
|
||||
|
||||
public static boolean run(@NotNull CommandSender sender,
|
||||
@NotNull String[] args) {
|
||||
|
||||
|
||||
if (args.length < 3) {
|
||||
sender.sendMessage("usage: /nouns update <pronoun> <format>");
|
||||
return true;
|
||||
}
|
||||
|
||||
String pronoun = args[1].toLowerCase();
|
||||
if(!Cache.dbManager.isPronounValid(pronoun)) {
|
||||
sender.sendMessage("Invalid pronoun " + pronoun + "!");
|
||||
return true;
|
||||
}
|
||||
|
||||
int pronounId = Cache.dbManager.getPronounId(pronoun);
|
||||
String oldFormat = Cache.dbManager.getPronounFormat(pronounId);
|
||||
String newFormat = args[2];
|
||||
|
||||
if(Cache.dbManager.updatePronounFormat(pronounId, newFormat)) {
|
||||
sender.sendMessage("Format of pronoun " + pronoun + " updated from " + oldFormat + " to " + newFormat + "!");
|
||||
return true;
|
||||
} else {
|
||||
sender.sendMessage("Error updating pronoun format! Please check console for details.");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -287,5 +287,22 @@ public class DatabaseManager
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updatePronounFormat(int pronounId, String newFormat) {
|
||||
|
||||
String query = "UPDATE pronouns SET format=? " +
|
||||
"WHERE id=?;";
|
||||
|
||||
try(PreparedStatement pStatement = dbConnection.prepareStatement(query)) {
|
||||
pStatement.setString(1, newFormat);
|
||||
pStatement.setInt(2, pronounId);
|
||||
pStatement.executeUpdate();
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user