Load ignores from database and add them into the chat event

This commit is contained in:
destro174 2021-06-23 20:05:47 +02:00
parent 5bea7c95f9
commit 11343938bc
2 changed files with 17 additions and 20 deletions

View File

@ -8,10 +8,7 @@ import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
public class Queries { public class Queries {
@ -65,33 +62,33 @@ public class Queries {
//Ignore //Ignore
public static void getIgnoredUsers() { //TODO store this in a user object or something? -> ChatPlayer /**
HashMap<UUID, ArrayList<UUID>> ignoredUsers = new HashMap<>(); //TODO Replace with a proper way/location to store this in -> a list<UUID> in ChatPlayer? * returns the UUID of all players this player has ignored.
String query = "SELECT * FROM ignored_users"; *
* @param uuid the player who ignored the other players
* @return LinkedList<UUID>
*/
public static LinkedList<UUID> getIgnoredUsers(UUID uuid) {
LinkedList<UUID> uuids = new LinkedList<>();
String query = "SELECT * FROM ignored_users WHERE uuid = ?";
try { try {
Connection connection = DatabaseConnection.getConnection(); Connection connection = DatabaseConnection.getConnection();
PreparedStatement statement = connection.prepareStatement(query);
ResultSet resultSet = connection.prepareStatement(query).executeQuery(); statement.setString(1, uuid.toString());
ResultSet resultSet = statement.executeQuery();
while (resultSet.next()) { while (resultSet.next()) {
UUID uuid = UUID.fromString(resultSet.getString("uuid"));
UUID ignoredUuid = UUID.fromString(resultSet.getString("ignored_uuid")); UUID ignoredUuid = UUID.fromString(resultSet.getString("ignored_uuid"));
ArrayList<UUID> uuids;
if (ignoredUsers.containsKey(uuid)) {
uuids = ignoredUsers.get(uuid);
} else {
uuids = new ArrayList<>();
}
uuids.add(ignoredUuid); uuids.add(ignoredUuid);
ignoredUsers.put(uuid, uuids);
} }
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
return uuids;
} }
public static void ignoreUser(UUID uuid, UUID ignoredUuid) { public static void ignoreUser(UUID uuid, UUID ignoredUuid) {
@ -299,7 +296,7 @@ public class Queries {
boolean toggled_chat = resultSet.getInt("toggled_chat") == 1; boolean toggled_chat = resultSet.getInt("toggled_chat") == 1;
boolean toggle_Gc = resultSet.getInt("toggled_gc") == 1; boolean toggle_Gc = resultSet.getInt("toggled_gc") == 1;
// could do a constructor for chatuser to accept the record? // could do a constructor for chatuser to accept the record?
ChatUserManager.addUser(new ChatUser(uuid, partyId, toggled_chat, toggle_Gc)); //ChatUserManager.addUser(new ChatUser(uuid, partyId, toggled_chat, toggle_Gc));
} }
} catch (SQLException e) { } catch (SQLException e) {

View File

@ -41,7 +41,7 @@ public class ChatUser {
replyTarget = null; replyTarget = null;
gcCooldown = System.currentTimeMillis(); // players can't use gc for 30 seconds after logging in if we use this? gcCooldown = System.currentTimeMillis(); // players can't use gc for 30 seconds after logging in if we use this?
mails = new LinkedList<>(); // todo load mails mails = new LinkedList<>(); // todo load mails
ignoredPlayers = new LinkedList<>(); // todo load ignoredPlayers ignoredPlayers = Queries.getIgnoredUsers(uuid);
ignoredBy = new LinkedList<>(); // todo load ignoredPlayers ignoredBy = new LinkedList<>(); // todo load ignoredPlayers
} }