Skip to content

Commit

Permalink
Fix ignore commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Brikster committed Dec 22, 2023
1 parent 694d759 commit 6734cfa
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public void handleCommand(@NotNull CommandContext<@NotNull CommandSender> comman
pmMessageService.addConversation(sender.getName(),
target instanceof ConsoleCommandSender ? "Console" : target.getName());

boolean ignored = sender instanceof Player && target instanceof Player
&& playerDataRepository.isIgnoredPlayer((Player) target, ((Player) sender).getUniqueId());
boolean ignored = sender instanceof Player && target.isConsole()
&& playerDataRepository.isIgnoredPlayer(target.getUuid(), ((Player) sender).getUniqueId());

Component spyComponentFormat = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ public void execute(@NotNull CommandContext<CommandSender> commandContext) {
return;
}

if (repository.isIgnoredPlayer(sender, targetUuid)) {
if (repository.isIgnoredPlayer(sender.getUniqueId(), targetUuid)) {
audiences.sender(sender).sendMessage(messagesConfig.getPmYouAlreadyIgnore());
} else {
repository.createOrUpdateUser(sender.getUniqueId(), sender.getName());
if (target != null) {
repository.createOrUpdateUser(target.getUuid(), target.getName());
}

repository.addIgnoredPlayer(sender, targetUuid);
repository.addIgnoredPlayer(sender.getUniqueId(), targetUuid);
audiences.sender(sender).sendMessage(messagesConfig.getPmYouNowIgnore());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ public void execute(@NotNull CommandContext<CommandSender> commandContext) {
return;
}

if (repository.isIgnoredPlayer(sender, targetUuid)) {
if (repository.isIgnoredPlayer(sender.getUniqueId(), targetUuid)) {
repository.createOrUpdateUser(sender.getUniqueId(), sender.getName());
if (target != null) {
repository.createOrUpdateUser(target.getUuid(), target.getName());
}

repository.removeIgnoredPlayer(sender, targetUuid);
repository.removeIgnoredPlayer(sender.getUniqueId(), targetUuid);
audiences.sender(sender).sendMessage(messagesConfig.getPmYouDontNowIgnore());
} else {
audiences.sender(sender).sendMessage(messagesConfig.getPmYouDontIgnore());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,11 @@ public void createOrUpdateUser(@NotNull UUID uuid, @NotNull String username) {
}

@Override
public void addIgnoredPlayer(@NotNull Player player, @NotNull UUID uuid) {
public void addIgnoredPlayer(@NotNull UUID playerUuid, @NotNull UUID uuid) {
try (Connection connection = dataSource.getConnection();
PreparedStatement statement = connection.prepareStatement(
"INSERT INTO chatty_ignored_users (player_uuid, ignored_uuid) VALUES (?, ?)")) {
statement.setString(1, player.getUniqueId().toString());
statement.setString(1, playerUuid.toString());
statement.setString(2, uuid.toString());
statement.executeUpdate();
} catch (SQLException sqlException) {
Expand All @@ -177,12 +177,12 @@ public void addIgnoredPlayer(@NotNull Player player, @NotNull UUID uuid) {
}

@Override
public void removeIgnoredPlayer(@NotNull Player player, @NotNull UUID uuid) {
public void removeIgnoredPlayer(@NotNull UUID playerUuid, @NotNull UUID uuid) {
try (Connection connection = dataSource.getConnection();
PreparedStatement statement = connection.prepareStatement(
"DELETE FROM chatty_ignored_users" +
" WHERE player_uuid = ? AND ignored_uuid = ?")) {
statement.setString(1, player.getUniqueId().toString());
statement.setString(1, playerUuid.toString());
statement.setString(2, uuid.toString());
statement.executeUpdate();
} catch (SQLException sqlException) {
Expand All @@ -191,13 +191,13 @@ public void removeIgnoredPlayer(@NotNull Player player, @NotNull UUID uuid) {
}

@Override
public boolean isIgnoredPlayer(@NotNull Player player, @NotNull UUID uuid) {
public boolean isIgnoredPlayer(@NotNull UUID playerUuid, @NotNull UUID uuid) {
try (Connection connection = dataSource.getConnection();
PreparedStatement statement = connection.prepareStatement(
"SELECT ignored_uuid " +
"FROM chatty_ignored_users " +
"WHERE player_uuid = ? AND ignored_uuid = ?")) {
statement.setString(1, player.getUniqueId().toString());
statement.setString(1, playerUuid.toString());
statement.setString(2, uuid.toString());

ResultSet resultSet = statement.executeQuery();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ public interface PlayerDataRepository extends AutoCloseable {

@Nullable String getCachedUsername(@NotNull UUID uuid);

void addIgnoredPlayer(@NotNull Player player, @NotNull UUID uuid);
void addIgnoredPlayer(@NotNull UUID playerUuid, @NotNull UUID uuid);

void removeIgnoredPlayer(@NotNull Player player, @NotNull UUID uuid);
void removeIgnoredPlayer(@NotNull UUID playerUuid, @NotNull UUID uuid);

boolean isIgnoredPlayer(@NotNull Player player, @NotNull UUID uuid);
boolean isIgnoredPlayer(@NotNull UUID playerUuid, @NotNull UUID uuid);

}
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,11 @@ public void createOrUpdateUser(@NotNull UUID uuid, @NotNull String username) {
}

@Override
public void addIgnoredPlayer(@NotNull Player player, @NotNull UUID uuid) {
public void addIgnoredPlayer(@NotNull UUID playerUuid, @NotNull UUID uuid) {
try (Connection connection = dataSource.getConnection();
PreparedStatement statement = connection.prepareStatement(
"INSERT INTO chatty_ignored_users (player_uuid, ignored_uuid) VALUES (?, ?)")) {
statement.setObject(1, player.getUniqueId());
statement.setObject(1, playerUuid);
statement.setObject(2, uuid);
statement.executeUpdate();
} catch (SQLException sqlException) {
Expand All @@ -178,12 +178,12 @@ public void addIgnoredPlayer(@NotNull Player player, @NotNull UUID uuid) {
}

@Override
public void removeIgnoredPlayer(@NotNull Player player, @NotNull UUID uuid) {
public void removeIgnoredPlayer(@NotNull UUID playerUuid, @NotNull UUID uuid) {
try (Connection connection = dataSource.getConnection();
PreparedStatement statement = connection.prepareStatement(
"DELETE FROM chatty_ignored_users" +
" WHERE player_uuid = ? AND ignored_uuid = ?")) {
statement.setObject(1, player.getUniqueId());
statement.setObject(1, playerUuid);
statement.setObject(2, uuid);
statement.executeUpdate();
} catch (SQLException sqlException) {
Expand All @@ -192,13 +192,13 @@ public void removeIgnoredPlayer(@NotNull Player player, @NotNull UUID uuid) {
}

@Override
public boolean isIgnoredPlayer(@NotNull Player player, @NotNull UUID uuid) {
public boolean isIgnoredPlayer(@NotNull UUID playerUuid, @NotNull UUID uuid) {
try (Connection connection = dataSource.getConnection();
PreparedStatement statement = connection.prepareStatement(
"SELECT ignored_uuid " +
"FROM chatty_ignored_users " +
"WHERE player_uuid = ? AND ignored_uuid = ?")) {
statement.setObject(1, player.getUniqueId());
statement.setObject(1, playerUuid);
statement.setObject(2, uuid);

ResultSet resultSet = statement.executeQuery();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,11 @@ public void createOrUpdateUser(@NotNull UUID uuid, @NotNull String username) {
}

@Override
public void addIgnoredPlayer(@NotNull Player player, @NotNull UUID uuid) {
public void addIgnoredPlayer(@NotNull UUID playerUuid, @NotNull UUID uuid) {
try (Connection connection = dataSource.getConnection();
PreparedStatement statement = connection.prepareStatement(
"INSERT INTO ignored_users (player_uuid, ignored_uuid) VALUES (?, ?)")) {
statement.setBytes(1, SqliteUtil.fromUUID(player.getUniqueId()));
statement.setBytes(1, SqliteUtil.fromUUID(playerUuid));
statement.setBytes(2, SqliteUtil.fromUUID(uuid));
statement.executeUpdate();
} catch (SQLException sqlException) {
Expand All @@ -181,12 +181,12 @@ public void addIgnoredPlayer(@NotNull Player player, @NotNull UUID uuid) {
}

@Override
public void removeIgnoredPlayer(@NotNull Player player, @NotNull UUID uuid) {
public void removeIgnoredPlayer(@NotNull UUID playerUuid, @NotNull UUID uuid) {
try (Connection connection = dataSource.getConnection();
PreparedStatement statement = connection.prepareStatement(
"DELETE FROM ignored_users" +
" WHERE player_uuid = ? AND ignored_uuid = ?")) {
statement.setBytes(1, SqliteUtil.fromUUID(player.getUniqueId()));
statement.setBytes(1, SqliteUtil.fromUUID(playerUuid));
statement.setBytes(2, SqliteUtil.fromUUID(uuid));
statement.executeUpdate();
} catch (SQLException sqlException) {
Expand All @@ -195,13 +195,13 @@ public void removeIgnoredPlayer(@NotNull Player player, @NotNull UUID uuid) {
}

@Override
public boolean isIgnoredPlayer(@NotNull Player player, @NotNull UUID uuid) {
public boolean isIgnoredPlayer(@NotNull UUID playerUuid, @NotNull UUID uuid) {
try (Connection connection = dataSource.getConnection();
PreparedStatement statement = connection.prepareStatement(
"SELECT ignored_uuid " +
"FROM ignored_users " +
"WHERE player_uuid = ? AND ignored_uuid = ?")) {
statement.setBytes(1, SqliteUtil.fromUUID(player.getUniqueId()));
statement.setBytes(1, SqliteUtil.fromUUID(playerUuid));
statement.setBytes(2, SqliteUtil.fromUUID(uuid));

ResultSet resultSet = statement.executeQuery();
Expand Down

0 comments on commit 6734cfa

Please sign in to comment.