From 1a7304873e303e1b49ec8bc267c71bfa07ce19ce Mon Sep 17 00:00:00 2001 From: James Mortemore Date: Sun, 8 Sep 2024 15:12:48 +0200 Subject: [PATCH] fix: safely handle duplicate entries when punishing alts (#994) --- .../common/listeners/CommonJoinListener.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/me/confuser/banmanager/common/listeners/CommonJoinListener.java b/common/src/main/java/me/confuser/banmanager/common/listeners/CommonJoinListener.java index dc561d18..5407a59b 100755 --- a/common/src/main/java/me/confuser/banmanager/common/listeners/CommonJoinListener.java +++ b/common/src/main/java/me/confuser/banmanager/common/listeners/CommonJoinListener.java @@ -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; @@ -541,7 +542,12 @@ private void punishAlts(List 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()); @@ -575,7 +581,12 @@ private void punishAlts(List 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); + } } } }