Skip to content

Commit

Permalink
fix: safely handle duplicate entries when punishing alts (#994)
Browse files Browse the repository at this point in the history
  • Loading branch information
confuser authored Sep 8, 2024
1 parent 282acee commit 1a73048
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import java.io.IOException;
import java.sql.SQLException;
import java.sql.SQLIntegrityConstraintViolationException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
Expand Down Expand Up @@ -541,7 +542,12 @@ private void punishAlts(List<PlayerData> duplicates, UUID uuid) throws SQLExcept
ban.isSilent(),
ban.getExpires());

plugin.getPlayerBanStorage().ban(newBan);
try {
plugin.getPlayerBanStorage().ban(newBan);
} catch (SQLIntegrityConstraintViolationException e) {
// Ignore duplicate entry errors
plugin.getPlayerBanStorage().addBan(newBan);
}

plugin.getScheduler().runSync(() -> {
CommonPlayer bukkitPlayer = plugin.getServer().getPlayer(newBan.getPlayer().getUUID());
Expand Down Expand Up @@ -575,7 +581,12 @@ private void punishAlts(List<PlayerData> duplicates, UUID uuid) throws SQLExcept
mute.isSoft(),
mute.getExpires());

plugin.getPlayerMuteStorage().mute(newMute);
try {
plugin.getPlayerMuteStorage().mute(newMute);
} catch (SQLIntegrityConstraintViolationException e) {
// Ignore duplicate entry errors
plugin.getPlayerMuteStorage().addMute(newMute);
}
}
}
}
Expand Down

0 comments on commit 1a73048

Please sign in to comment.