From ade67d8df404f1e3f264dcd90f815722f719a1cd Mon Sep 17 00:00:00 2001 From: Petr Ilin Date: Mon, 2 Jan 2023 23:48:06 +0300 Subject: Correctly use Exceptions --- .../limboauth/handler/AuthSessionHandler.java | 27 +++++++++------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'src/main/java/net/elytrium/limboauth/handler') diff --git a/src/main/java/net/elytrium/limboauth/handler/AuthSessionHandler.java b/src/main/java/net/elytrium/limboauth/handler/AuthSessionHandler.java index a3c4e6f..493e96c 100644 --- a/src/main/java/net/elytrium/limboauth/handler/AuthSessionHandler.java +++ b/src/main/java/net/elytrium/limboauth/handler/AuthSessionHandler.java @@ -44,6 +44,7 @@ import net.elytrium.limboauth.event.PostRegisterEvent; import net.elytrium.limboauth.event.TaskEvent; import net.elytrium.limboauth.migration.MigrationHash; import net.elytrium.limboauth.model.RegisteredPlayer; +import net.elytrium.limboauth.model.SQLRuntimeException; import net.kyori.adventure.bossbar.BossBar; import net.kyori.adventure.text.Component; import net.kyori.adventure.title.Title; @@ -149,9 +150,8 @@ public class AuthSessionHandler implements LimboSessionHandler { } } } catch (SQLException e) { - e.printStackTrace(); this.proxyPlayer.disconnect(databaseErrorKick); - return; + throw new SQLRuntimeException(e); } } else { if (!this.proxyPlayer.getUsername().equals(this.playerInfo.getNickname())) { @@ -212,8 +212,8 @@ public class AuthSessionHandler implements LimboSessionHandler { this.playerDao.create(registeredPlayer); this.playerInfo = registeredPlayer; } catch (SQLException e) { - e.printStackTrace(); this.proxyPlayer.disconnect(databaseErrorKick); + throw new SQLRuntimeException(e); } this.proxyPlayer.sendMessage(registerSuccessful); @@ -369,7 +369,7 @@ public class AuthSessionHandler implements LimboSessionHandler { try { this.plugin.updateLoginData(this.proxyPlayer); } catch (SQLException e) { - e.printStackTrace(); + throw new SQLRuntimeException(e); } this.plugin.cacheAuthUser(this.proxyPlayer); @@ -468,8 +468,7 @@ public class AuthSessionHandler implements LimboSessionHandler { try { playerDao.update(player); } catch (SQLException e) { - e.printStackTrace(); - return false; + throw new SQLRuntimeException(e); } } } @@ -478,25 +477,21 @@ public class AuthSessionHandler implements LimboSessionHandler { } public static RegisteredPlayer fetchInfo(Dao playerDao, UUID uuid) { - List playerList = null; try { - playerList = playerDao.queryForEq(RegisteredPlayer.PREMIUM_UUID_FIELD, uuid.toString()); + List playerList = playerDao.queryForEq(RegisteredPlayer.PREMIUM_UUID_FIELD, uuid.toString()); + return (playerList != null ? playerList.size() : 0) == 0 ? null : playerList.get(0); } catch (SQLException e) { - e.printStackTrace(); + throw new SQLRuntimeException(e); } - - return (playerList != null ? playerList.size() : 0) == 0 ? null : playerList.get(0); } public static RegisteredPlayer fetchInfo(Dao playerDao, String nickname) { - List playerList = null; try { - playerList = playerDao.queryForEq(RegisteredPlayer.LOWERCASE_NICKNAME_FIELD, nickname.toLowerCase(Locale.ROOT)); + List playerList = playerDao.queryForEq(RegisteredPlayer.LOWERCASE_NICKNAME_FIELD, nickname.toLowerCase(Locale.ROOT)); + return (playerList != null ? playerList.size() : 0) == 0 ? null : playerList.get(0); } catch (SQLException e) { - e.printStackTrace(); + throw new SQLRuntimeException(e); } - - return (playerList != null ? playerList.size() : 0) == 0 ? null : playerList.get(0); } public static String genHash(String password) { -- cgit