aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/net
diff options
context:
space:
mode:
authorPetr Ilin <hevav@hevav.dev>2023-01-02 23:48:06 +0300
committerPetr Ilin <hevav@hevav.dev>2023-01-02 23:48:06 +0300
commitade67d8df404f1e3f264dcd90f815722f719a1cd (patch)
tree55aae66df5ee70d708fc96f5df593ea98d96a0a0 /src/main/java/net
parent711a554a773184610b183405276ccc516907d872 (diff)
downloadLimboAuth-ade67d8df404f1e3f264dcd90f815722f719a1cd.tar.gz
LimboAuth-ade67d8df404f1e3f264dcd90f815722f719a1cd.tar.bz2
LimboAuth-ade67d8df404f1e3f264dcd90f815722f719a1cd.zip
Correctly use Exceptions
Diffstat (limited to 'src/main/java/net')
-rw-r--r--src/main/java/net/elytrium/limboauth/LimboAuth.java68
-rw-r--r--src/main/java/net/elytrium/limboauth/Settings.java1
-rw-r--r--src/main/java/net/elytrium/limboauth/command/ChangePasswordCommand.java3
-rw-r--r--src/main/java/net/elytrium/limboauth/command/ForceChangePasswordCommand.java3
-rw-r--r--src/main/java/net/elytrium/limboauth/command/ForceUnregisterCommand.java3
-rw-r--r--src/main/java/net/elytrium/limboauth/command/LimboAuthCommand.java10
-rw-r--r--src/main/java/net/elytrium/limboauth/command/PremiumCommand.java3
-rw-r--r--src/main/java/net/elytrium/limboauth/command/TotpCommand.java5
-rw-r--r--src/main/java/net/elytrium/limboauth/command/UnregisterCommand.java3
-rw-r--r--src/main/java/net/elytrium/limboauth/dependencies/BaseLibrary.java14
-rw-r--r--src/main/java/net/elytrium/limboauth/dependencies/DatabaseLibrary.java23
-rw-r--r--src/main/java/net/elytrium/limboauth/handler/AuthSessionHandler.java27
-rw-r--r--src/main/java/net/elytrium/limboauth/listener/AuthListener.java9
-rw-r--r--src/main/java/net/elytrium/limboauth/model/SQLRuntimeException.java29
14 files changed, 120 insertions, 81 deletions
diff --git a/src/main/java/net/elytrium/limboauth/LimboAuth.java b/src/main/java/net/elytrium/limboauth/LimboAuth.java
index 60bec84..0837fea 100644
--- a/src/main/java/net/elytrium/limboauth/LimboAuth.java
+++ b/src/main/java/net/elytrium/limboauth/LimboAuth.java
@@ -47,6 +47,7 @@ import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
@@ -73,6 +74,7 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
import net.elytrium.java.commons.mc.serialization.Serializer;
import net.elytrium.java.commons.mc.serialization.Serializers;
+import net.elytrium.java.commons.reflection.ReflectionException;
import net.elytrium.java.commons.updates.UpdatesChecker;
import net.elytrium.limboapi.api.Limbo;
import net.elytrium.limboapi.api.LimboFactory;
@@ -101,6 +103,7 @@ import net.elytrium.limboauth.floodgate.FloodgateApiHolder;
import net.elytrium.limboauth.handler.AuthSessionHandler;
import net.elytrium.limboauth.listener.AuthListener;
import net.elytrium.limboauth.model.RegisteredPlayer;
+import net.elytrium.limboauth.model.SQLRuntimeException;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.ComponentSerializer;
import net.kyori.adventure.title.Title;
@@ -190,7 +193,7 @@ public class LimboAuth {
}
@Subscribe
- public void onProxyInitialization(ProxyInitializeEvent event) throws Exception {
+ public void onProxyInitialization(ProxyInitializeEvent event) {
System.setProperty("com.j256.simplelogging.level", "ERROR");
this.reload();
@@ -214,7 +217,7 @@ public class LimboAuth {
}
@SuppressFBWarnings(value = "NP_NULL_ON_SOME_PATH", justification = "LEGACY_AMPERSAND can't be null in velocity.")
- public void reload() throws Exception {
+ public void reload() {
Settings.IMP.reload(this.configFile, Settings.IMP.PREFIX);
if (this.floodgateApi == null && !Settings.IMP.MAIN.FLOODGATE_NEED_AUTH) {
@@ -261,14 +264,18 @@ public class LimboAuth {
this.registrationsDisabledKick = SERIALIZER.deserialize(Settings.IMP.MAIN.STRINGS.REGISTRATIONS_DISABLED_KICK);
if (Settings.IMP.MAIN.CHECK_PASSWORD_STRENGTH) {
- this.unsafePasswords.clear();
- Path unsafePasswordsPath = Paths.get(this.dataDirectoryFile.getAbsolutePath(), Settings.IMP.MAIN.UNSAFE_PASSWORDS_FILE);
- if (!unsafePasswordsPath.toFile().exists()) {
- Files.copy(Objects.requireNonNull(this.getClass().getResourceAsStream("/unsafe_passwords.txt")), unsafePasswordsPath);
- }
+ try {
+ this.unsafePasswords.clear();
+ Path unsafePasswordsPath = Paths.get(this.dataDirectoryFile.getAbsolutePath(), Settings.IMP.MAIN.UNSAFE_PASSWORDS_FILE);
+ if (!unsafePasswordsPath.toFile().exists()) {
+ Files.copy(Objects.requireNonNull(this.getClass().getResourceAsStream("/unsafe_passwords.txt")), unsafePasswordsPath);
+ }
- try (Stream<String> unsafePasswordsStream = Files.lines(unsafePasswordsPath)) {
- this.unsafePasswords.addAll(unsafePasswordsStream.collect(Collectors.toList()));
+ try (Stream<String> unsafePasswordsStream = Files.lines(unsafePasswordsPath)) {
+ this.unsafePasswords.addAll(unsafePasswordsStream.collect(Collectors.toList()));
+ }
+ } catch (IOException e) {
+ throw new IllegalArgumentException(e);
}
}
@@ -278,13 +285,21 @@ public class LimboAuth {
Settings.DATABASE dbConfig = Settings.IMP.DATABASE;
DatabaseLibrary databaseLibrary = DatabaseLibrary.valueOf(dbConfig.STORAGE_TYPE.toUpperCase(Locale.ROOT));
- this.connectionSource = databaseLibrary.connectToORM(
- this.dataDirectoryFile.toPath().toAbsolutePath(),
- dbConfig.HOSTNAME,
- dbConfig.DATABASE + dbConfig.CONNECTION_PARAMETERS,
- dbConfig.USER,
- dbConfig.PASSWORD
- );
+ try {
+ this.connectionSource = databaseLibrary.connectToORM(
+ this.dataDirectoryFile.toPath().toAbsolutePath(),
+ dbConfig.HOSTNAME,
+ dbConfig.DATABASE + dbConfig.CONNECTION_PARAMETERS,
+ dbConfig.USER,
+ dbConfig.PASSWORD
+ );
+ } catch (ReflectiveOperationException e) {
+ throw new ReflectionException(e);
+ } catch (SQLException e) {
+ throw new SQLRuntimeException(e);
+ } catch (IOException | URISyntaxException e) {
+ throw new IllegalArgumentException(e);
+ }
this.nicknameValidationPattern = Pattern.compile(Settings.IMP.MAIN.ALLOWED_NICKNAME_REGEX);
@@ -293,7 +308,7 @@ public class LimboAuth {
this.playerDao = DaoManager.createDao(this.connectionSource, RegisteredPlayer.class);
this.migrateDb(this.playerDao);
} catch (SQLException e) {
- e.printStackTrace();
+ throw new SQLRuntimeException(e);
}
CommandManager manager = this.server.getCommandManager();
@@ -347,7 +362,7 @@ public class LimboAuth {
Settings.MAIN.WORLD_COORDS coords = Settings.IMP.MAIN.WORLD_COORDS;
file.toWorld(this.factory, authWorld, coords.X, coords.Y, coords.Z, Settings.IMP.MAIN.WORLD_LIGHT_LEVEL);
} catch (IOException e) {
- e.printStackTrace();
+ throw new IllegalArgumentException(e);
}
}
@@ -472,11 +487,11 @@ public class LimboAuth {
dao.executeRawNoArgs(builder.toString());
} catch (SQLException e) {
- e.printStackTrace();
+ throw new SQLRuntimeException(e);
}
});
} catch (Exception e) {
- e.printStackTrace();
+ throw new SQLRuntimeException(e);
}
}
@@ -536,7 +551,7 @@ public class LimboAuth {
try {
this.playerDao.update(registeredPlayer);
} catch (SQLException e) {
- e.printStackTrace();
+ throw new SQLRuntimeException(e);
}
}
@@ -557,7 +572,7 @@ public class LimboAuth {
try {
this.playerDao.create(registeredPlayer);
} catch (SQLException e) {
- e.printStackTrace();
+ throw new SQLRuntimeException(e);
}
}
@@ -612,7 +627,7 @@ public class LimboAuth {
try {
this.updateLoginData(player);
} catch (SQLException e) {
- e.printStackTrace();
+ throw new SQLRuntimeException(e);
}
break;
}
@@ -625,12 +640,7 @@ public class LimboAuth {
}
case NORMAL:
default: {
- try {
- this.authServer.spawnPlayer(player, new AuthSessionHandler(this.playerDao, player, this, registeredPlayer));
- } catch (Throwable t) {
- t.printStackTrace();
- }
-
+ this.authServer.spawnPlayer(player, new AuthSessionHandler(this.playerDao, player, this, registeredPlayer));
break;
}
}
diff --git a/src/main/java/net/elytrium/limboauth/Settings.java b/src/main/java/net/elytrium/limboauth/Settings.java
index 29fa14b..fb342b3 100644
--- a/src/main/java/net/elytrium/limboauth/Settings.java
+++ b/src/main/java/net/elytrium/limboauth/Settings.java
@@ -260,7 +260,6 @@ public class Settings extends YamlConfig {
public static class STRINGS {
public String RELOAD = "{PRFX} &aReloaded successfully!";
- public String RELOAD_FAILED = "{PRFX} &cReload failed, check console for details.";
public String ERROR_OCCURRED = "{PRFX} &cAn internal error has occurred!";
public String DATABASE_ERROR_KICK = "{PRFX} &cA database error has occurred!";
diff --git a/src/main/java/net/elytrium/limboauth/command/ChangePasswordCommand.java b/src/main/java/net/elytrium/limboauth/command/ChangePasswordCommand.java
index 26c75eb..c940226 100644
--- a/src/main/java/net/elytrium/limboauth/command/ChangePasswordCommand.java
+++ b/src/main/java/net/elytrium/limboauth/command/ChangePasswordCommand.java
@@ -29,6 +29,7 @@ import net.elytrium.limboauth.LimboAuth;
import net.elytrium.limboauth.Settings;
import net.elytrium.limboauth.handler.AuthSessionHandler;
import net.elytrium.limboauth.model.RegisteredPlayer;
+import net.elytrium.limboauth.model.SQLRuntimeException;
import net.kyori.adventure.text.Component;
public class ChangePasswordCommand implements SimpleCommand {
@@ -96,7 +97,7 @@ public class ChangePasswordCommand implements SimpleCommand {
source.sendMessage(this.successful);
} catch (SQLException e) {
source.sendMessage(this.errorOccurred);
- e.printStackTrace();
+ throw new SQLRuntimeException(e);
}
} else {
source.sendMessage(this.notPlayer);
diff --git a/src/main/java/net/elytrium/limboauth/command/ForceChangePasswordCommand.java b/src/main/java/net/elytrium/limboauth/command/ForceChangePasswordCommand.java
index 899aff6..5c960e1 100644
--- a/src/main/java/net/elytrium/limboauth/command/ForceChangePasswordCommand.java
+++ b/src/main/java/net/elytrium/limboauth/command/ForceChangePasswordCommand.java
@@ -32,6 +32,7 @@ import net.elytrium.limboauth.LimboAuth;
import net.elytrium.limboauth.Settings;
import net.elytrium.limboauth.handler.AuthSessionHandler;
import net.elytrium.limboauth.model.RegisteredPlayer;
+import net.elytrium.limboauth.model.SQLRuntimeException;
import net.kyori.adventure.text.Component;
public class ForceChangePasswordCommand implements SimpleCommand {
@@ -81,7 +82,7 @@ public class ForceChangePasswordCommand implements SimpleCommand {
source.sendMessage(serializer.deserialize(MessageFormat.format(this.successful, nickname)));
} catch (SQLException e) {
source.sendMessage(serializer.deserialize(MessageFormat.format(this.notSuccessful, nickname)));
- e.printStackTrace();
+ throw new SQLRuntimeException(e);
}
} else {
source.sendMessage(this.usage);
diff --git a/src/main/java/net/elytrium/limboauth/command/ForceUnregisterCommand.java b/src/main/java/net/elytrium/limboauth/command/ForceUnregisterCommand.java
index 3d2f9ed..3acc2d0 100644
--- a/src/main/java/net/elytrium/limboauth/command/ForceUnregisterCommand.java
+++ b/src/main/java/net/elytrium/limboauth/command/ForceUnregisterCommand.java
@@ -31,6 +31,7 @@ import net.elytrium.limboauth.LimboAuth;
import net.elytrium.limboauth.Settings;
import net.elytrium.limboauth.event.AuthUnregisterEvent;
import net.elytrium.limboauth.model.RegisteredPlayer;
+import net.elytrium.limboauth.model.SQLRuntimeException;
import net.kyori.adventure.text.Component;
public class ForceUnregisterCommand implements SimpleCommand {
@@ -78,7 +79,7 @@ public class ForceUnregisterCommand implements SimpleCommand {
source.sendMessage(serializer.deserialize(MessageFormat.format(this.successful, playerNick)));
} catch (SQLException e) {
source.sendMessage(serializer.deserialize(MessageFormat.format(this.notSuccessful, playerNick)));
- e.printStackTrace();
+ throw new SQLRuntimeException(e);
}
} else {
source.sendMessage(this.usage);
diff --git a/src/main/java/net/elytrium/limboauth/command/LimboAuthCommand.java b/src/main/java/net/elytrium/limboauth/command/LimboAuthCommand.java
index 669a978..b4587b4 100644
--- a/src/main/java/net/elytrium/limboauth/command/LimboAuthCommand.java
+++ b/src/main/java/net/elytrium/limboauth/command/LimboAuthCommand.java
@@ -100,14 +100,8 @@ public class LimboAuthCommand implements SimpleCommand {
Serializer serializer = LimboAuth.getSerializer();
if (argsAmount == 1) {
if (command.equalsIgnoreCase("reload") && source.hasPermission("limboauth.admin.reload")) {
- try {
- this.plugin.reload();
- source.sendMessage(serializer.deserialize(Settings.IMP.MAIN.STRINGS.RELOAD));
- } catch (Exception e) {
- e.printStackTrace();
- source.sendMessage(serializer.deserialize(Settings.IMP.MAIN.STRINGS.RELOAD_FAILED));
- }
-
+ this.plugin.reload();
+ source.sendMessage(serializer.deserialize(Settings.IMP.MAIN.STRINGS.RELOAD));
return;
}
/*
diff --git a/src/main/java/net/elytrium/limboauth/command/PremiumCommand.java b/src/main/java/net/elytrium/limboauth/command/PremiumCommand.java
index 9257adc..f81ce10 100644
--- a/src/main/java/net/elytrium/limboauth/command/PremiumCommand.java
+++ b/src/main/java/net/elytrium/limboauth/command/PremiumCommand.java
@@ -29,6 +29,7 @@ import net.elytrium.limboauth.LimboAuth;
import net.elytrium.limboauth.Settings;
import net.elytrium.limboauth.handler.AuthSessionHandler;
import net.elytrium.limboauth.model.RegisteredPlayer;
+import net.elytrium.limboauth.model.SQLRuntimeException;
import net.kyori.adventure.text.Component;
public class PremiumCommand implements SimpleCommand {
@@ -85,7 +86,7 @@ public class PremiumCommand implements SimpleCommand {
((Player) source).disconnect(this.successful);
} catch (SQLException e) {
source.sendMessage(this.errorOccurred);
- e.printStackTrace();
+ throw new SQLRuntimeException(e);
}
} else {
source.sendMessage(this.notPremium);
diff --git a/src/main/java/net/elytrium/limboauth/command/TotpCommand.java b/src/main/java/net/elytrium/limboauth/command/TotpCommand.java
index e57cae9..afa4b30 100644
--- a/src/main/java/net/elytrium/limboauth/command/TotpCommand.java
+++ b/src/main/java/net/elytrium/limboauth/command/TotpCommand.java
@@ -36,6 +36,7 @@ import net.elytrium.limboauth.LimboAuth;
import net.elytrium.limboauth.Settings;
import net.elytrium.limboauth.handler.AuthSessionHandler;
import net.elytrium.limboauth.model.RegisteredPlayer;
+import net.elytrium.limboauth.model.SQLRuntimeException;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
@@ -127,7 +128,7 @@ public class TotpCommand implements SimpleCommand {
updateBuilder.update();
} catch (SQLException e) {
source.sendMessage(this.errorOccurred);
- e.printStackTrace();
+ throw new SQLRuntimeException(e);
}
source.sendMessage(this.successful);
@@ -167,7 +168,7 @@ public class TotpCommand implements SimpleCommand {
source.sendMessage(this.disabled);
} catch (SQLException e) {
source.sendMessage(this.errorOccurred);
- e.printStackTrace();
+ throw new SQLRuntimeException(e);
}
} else {
source.sendMessage(this.wrong);
diff --git a/src/main/java/net/elytrium/limboauth/command/UnregisterCommand.java b/src/main/java/net/elytrium/limboauth/command/UnregisterCommand.java
index 69edc8c..53fe58e 100644
--- a/src/main/java/net/elytrium/limboauth/command/UnregisterCommand.java
+++ b/src/main/java/net/elytrium/limboauth/command/UnregisterCommand.java
@@ -30,6 +30,7 @@ import net.elytrium.limboauth.Settings;
import net.elytrium.limboauth.event.AuthUnregisterEvent;
import net.elytrium.limboauth.handler.AuthSessionHandler;
import net.elytrium.limboauth.model.RegisteredPlayer;
+import net.elytrium.limboauth.model.SQLRuntimeException;
import net.kyori.adventure.text.Component;
public class UnregisterCommand implements SimpleCommand {
@@ -83,7 +84,7 @@ public class UnregisterCommand implements SimpleCommand {
((Player) source).disconnect(this.successful);
} catch (SQLException e) {
source.sendMessage(this.errorOccurred);
- e.printStackTrace();
+ throw new SQLRuntimeException(e);
}
} else {
source.sendMessage(this.wrongPassword);
diff --git a/src/main/java/net/elytrium/limboauth/dependencies/BaseLibrary.java b/src/main/java/net/elytrium/limboauth/dependencies/BaseLibrary.java
index 6e1b11f..5c864be 100644
--- a/src/main/java/net/elytrium/limboauth/dependencies/BaseLibrary.java
+++ b/src/main/java/net/elytrium/limboauth/dependencies/BaseLibrary.java
@@ -18,6 +18,7 @@
package net.elytrium.limboauth.dependencies;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
@@ -66,14 +67,11 @@ public enum BaseLibrary {
this.filenamePath = Path.of("libraries/" + mavenPath);
- URL mavenRepoURL = null;
try {
- mavenRepoURL = new URL("https://repo1.maven.org/maven2/" + mavenPath);
- } catch (Exception e) {
- e.printStackTrace();
+ this.mavenRepoURL = new URL("https://repo1.maven.org/maven2/" + mavenPath);
+ } catch (MalformedURLException e) {
+ throw new IllegalArgumentException(e);
}
-
- this.mavenRepoURL = mavenRepoURL;
}
@SuppressFBWarnings("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE")
@@ -84,8 +82,8 @@ public enum BaseLibrary {
Files.createDirectories(this.filenamePath.getParent());
Files.copy(in, Files.createFile(this.filenamePath), StandardCopyOption.REPLACE_EXISTING);
}
- } catch (Exception e) {
- e.printStackTrace();
+ } catch (IOException e) {
+ throw new IllegalArgumentException(e);
}
}
diff --git a/src/main/java/net/elytrium/limboauth/dependencies/DatabaseLibrary.java b/src/main/java/net/elytrium/limboauth/dependencies/DatabaseLibrary.java
index 6e416f8..ea78f61 100644
--- a/src/main/java/net/elytrium/limboauth/dependencies/DatabaseLibrary.java
+++ b/src/main/java/net/elytrium/limboauth/dependencies/DatabaseLibrary.java
@@ -19,14 +19,17 @@ package net.elytrium.limboauth.dependencies;
import com.j256.ormlite.jdbc.JdbcSingleConnectionSource;
import com.j256.ormlite.support.ConnectionSource;
+import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
+import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
+import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
@@ -90,23 +93,27 @@ public enum DatabaseLibrary {
this.stringGetter = stringGetter;
}
- public Connection connect(ClassLoader classLoader, Path dir, String hostname, String database, String user, String password) throws Exception {
+ public Connection connect(ClassLoader classLoader, Path dir, String hostname, String database, String user, String password)
+ throws ReflectiveOperationException, SQLException, IOException {
return this.connect(classLoader, dir, this.stringGetter.getJdbcString(dir, hostname, database), user, password);
}
- public Connection connect(Path dir, String hostname, String database, String user, String password) throws Exception {
+ public Connection connect(Path dir, String hostname, String database, String user, String password)
+ throws ReflectiveOperationException, SQLException, IOException {
return this.connect(dir, this.stringGetter.getJdbcString(dir, hostname, database), user, password);
}
- public Connection connect(ClassLoader classLoader, Path dir, String jdbc, String user, String password) throws Exception {
+ public Connection connect(ClassLoader classLoader, Path dir, String jdbc, String user, String password)
+ throws ReflectiveOperationException, SQLException, IOException {
return this.connector.connect(classLoader, dir, jdbc, user, password);
}
- public Connection connect(Path dir, String jdbc, String user, String password) throws Exception {
+ public Connection connect(Path dir, String jdbc, String user, String password) throws IOException, ReflectiveOperationException, SQLException {
return this.connector.connect(new IsolatedClassLoader(new URL[]{this.baseLibrary.getClassLoaderURL()}), dir, jdbc, user, password);
}
- public ConnectionSource connectToORM(Path dir, String hostname, String database, String user, String password) throws Exception {
+ public ConnectionSource connectToORM(Path dir, String hostname, String database, String user, String password)
+ throws ReflectiveOperationException, IOException, SQLException, URISyntaxException {
String jdbc = this.stringGetter.getJdbcString(dir, hostname, database);
URL baseLibraryURL = this.baseLibrary.getClassLoaderURL();
ClassLoader currentClassLoader = DatabaseLibrary.class.getClassLoader();
@@ -117,7 +124,8 @@ public enum DatabaseLibrary {
return new JdbcSingleConnectionSource(jdbc, this.connect(currentClassLoader, dir, jdbc, user, password));
}
- private static Connection fromDriver(Class<?> connectionClass, String jdbc, String user, String password, boolean register) throws Exception {
+ private static Connection fromDriver(Class<?> connectionClass, String jdbc, String user, String password, boolean register)
+ throws ReflectiveOperationException, SQLException {
Constructor<?> legacyConstructor = connectionClass.getConstructor();
Properties info = new Properties();
@@ -142,7 +150,8 @@ public enum DatabaseLibrary {
}
public interface DatabaseConnector {
- Connection connect(ClassLoader classLoader, Path dir, String jdbc, String user, String password) throws Exception;
+ Connection connect(ClassLoader classLoader, Path dir, String jdbc, String user, String password)
+ throws ReflectiveOperationException, SQLException, IOException;
}
public interface DatabaseStringGetter {
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<RegisteredPlayer, String> playerDao, UUID uuid) {
- List<RegisteredPlayer> playerList = null;
try {
- playerList = playerDao.queryForEq(RegisteredPlayer.PREMIUM_UUID_FIELD, uuid.toString());
+ List<RegisteredPlayer> 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<RegisteredPlayer, String> playerDao, String nickname) {
- List<RegisteredPlayer> playerList = null;
try {
- playerList = playerDao.queryForEq(RegisteredPlayer.LOWERCASE_NICKNAME_FIELD, nickname.toLowerCase(Locale.ROOT));
+ List<RegisteredPlayer> 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) {
diff --git a/src/main/java/net/elytrium/limboauth/listener/AuthListener.java b/src/main/java/net/elytrium/limboauth/listener/AuthListener.java
index ca7f031..6e6e124 100644
--- a/src/main/java/net/elytrium/limboauth/listener/AuthListener.java
+++ b/src/main/java/net/elytrium/limboauth/listener/AuthListener.java
@@ -45,6 +45,7 @@ import net.elytrium.limboauth.Settings;
import net.elytrium.limboauth.floodgate.FloodgateApiHolder;
import net.elytrium.limboauth.handler.AuthSessionHandler;
import net.elytrium.limboauth.model.RegisteredPlayer;
+import net.elytrium.limboauth.model.SQLRuntimeException;
// TODO: Customizable events priority
public class AuthListener {
@@ -137,9 +138,8 @@ public class AuthListener {
try {
registeredPlayer.setUuid(event.getGameProfile().getId().toString());
this.playerDao.update(registeredPlayer);
- } catch (SQLException ex) {
- ex.printStackTrace();
- return;
+ } catch (SQLException e) {
+ throw new SQLRuntimeException(e);
}
} else {
event.setGameProfile(event.getOriginalProfile().withId(UUID.fromString(currentUuid)));
@@ -152,8 +152,7 @@ public class AuthListener {
updateBuilder.updateColumnValue(RegisteredPlayer.HASH_FIELD, "");
updateBuilder.update();
} catch (SQLException e) {
- e.printStackTrace();
- return;
+ throw new SQLRuntimeException(e);
}
}
diff --git a/src/main/java/net/elytrium/limboauth/model/SQLRuntimeException.java b/src/main/java/net/elytrium/limboauth/model/SQLRuntimeException.java
new file mode 100644
index 0000000..19aa10d
--- /dev/null
+++ b/src/main/java/net/elytrium/limboauth/model/SQLRuntimeException.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2021 - 2023 Elytrium
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.elytrium.limboauth.model;
+
+public class SQLRuntimeException extends RuntimeException {
+
+ public SQLRuntimeException(Throwable cause) {
+ this("An unexpected internal error was caught during the database SQL operations.", cause);
+ }
+
+ public SQLRuntimeException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}