Finish implementing pronoun setting 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
72b49a15ed
commit
56c8e2ee1d
@ -31,8 +31,17 @@ public class NounsSetSubCommand
|
||||
return true;
|
||||
}
|
||||
|
||||
// todo: add to sqlite
|
||||
|
||||
if(Cache.dbManager.setPlayerPronouns(sender.getName(), mainPronoun, secondaryPronoun)) {
|
||||
|
||||
mainPronoun = Cache.dbManager.getPronounFormat(Cache.dbManager.getPronounId(mainPronoun));
|
||||
secondaryPronoun = Cache.dbManager.getPronounFormat(Cache.dbManager.getPronounId(secondaryPronoun));
|
||||
|
||||
sender.sendMessage("Your pronouns have correctly been set to " + mainPronoun + "/" + secondaryPronoun + "!");
|
||||
return true;
|
||||
} else {
|
||||
sender.sendMessage("Error updating pronouns! Please contact an administrator.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -111,7 +111,8 @@ public class DatabaseManager
|
||||
public int getPronounId(String pronoun) {
|
||||
String query = "SELECT id " +
|
||||
"FROM pronouns " +
|
||||
"WHERE pronoun = ?;";
|
||||
"WHERE pronoun = ? " +
|
||||
"LIMIT 1;";
|
||||
|
||||
try (PreparedStatement pStatement = dbConnection.prepareStatement(query)) {
|
||||
pStatement.setString(1, pronoun);
|
||||
@ -206,10 +207,46 @@ public class DatabaseManager
|
||||
}
|
||||
}
|
||||
|
||||
// accounce success
|
||||
// announce success
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean setPlayerPronouns(String playerName, String mainPronoun, String secondaryPronoun) {
|
||||
|
||||
int mainPronounId = getPronounId(mainPronoun);
|
||||
int secondaryPronounId = getPronounId(secondaryPronoun);
|
||||
|
||||
String query = "UPDATE players " +
|
||||
"SET (main_pronoun_id, secondary_pronoun_id) = (?,?) " +
|
||||
"WHERE player = ?;";
|
||||
|
||||
try(PreparedStatement pStatement = dbConnection.prepareStatement(query)) {
|
||||
pStatement.setInt(1, mainPronounId);
|
||||
pStatement.setInt(2, secondaryPronounId);
|
||||
pStatement.setString(3, playerName);
|
||||
return pStatement.execute();
|
||||
} catch (SQLException e) {
|
||||
logger.err(e.getMessage());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getPronounFormat(int pronounId) {
|
||||
String query = "SELECT format FROM pronouns" +
|
||||
"WHERE id = " + pronounId + " " +
|
||||
"LIMIT 1;";
|
||||
|
||||
try (Statement stmt = dbConnection.createStatement())
|
||||
{
|
||||
ResultSet rSet = stmt.executeQuery(query);
|
||||
return rSet.getString("id");
|
||||
} catch (SQLException e) {
|
||||
logger.err(e.getMessage());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user