Add handling for TeleportExceptions thrown when completing TimedTeleports

This commit is contained in:
William committed 2023-05-05 23:48:59 +01:00
1 parent daa72182f8
commit 28ab6d4a87
5 files changed
+31 -20

No files matched your search

@@ -23,6 +23,7 @@ import com.zaxxer.hikari.HikariDataSource;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.position.*;
import net.william278.huskhomes.teleport.Teleport;
import net.william278.huskhomes.teleport.TeleportationException;
import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.user.SavedUser;
import net.william278.huskhomes.user.User;
@@ -592,6 +593,8 @@ public class MySqlDatabase extends Database {
}
} catch (SQLException e) {
plugin.log(Level.SEVERE, "Failed to query the current teleport of " + onlineUser.getUsername(), e);
} catch (TeleportationException e) {
e.displayMessage(onlineUser, plugin);
}
return Optional.empty();
}
@@ -22,6 +22,7 @@ package net.william278.huskhomes.database;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.position.*;
import net.william278.huskhomes.teleport.Teleport;
import net.william278.huskhomes.teleport.TeleportationException;
import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.user.SavedUser;
import net.william278.huskhomes.user.User;
@@ -108,7 +109,7 @@ public class SqLiteDatabase extends Database {
// Prepare database schema; make tables if they don't exist
try {
// Load database schema CREATE statements from schema file
// Load the database schema CREATE statements from schema file
final String[] databaseSchema = getSchemaStatements("database/sqlite_schema.sql");
try (Statement statement = getConnection().createStatement()) {
for (String tableCreationStatement : databaseSchema) {
@@ -432,13 +433,13 @@ public class SqLiteDatabase extends Database {
public Optional<Home> getHome(@NotNull User user, @NotNull String homeName, boolean caseInsensitive) {
try {
try (PreparedStatement statement = getConnection().prepareStatement(formatStatementTables("""
SELECT `%homes_table%`.`uuid` AS `home_uuid`, `owner_uuid`, `username` AS `owner_username`, `name`, `description`, `tags`, `timestamp`, `x`, `y`, `z`, `yaw`, `pitch`, `world_name`, `world_uuid`, `server_name`, `public`
FROM `%homes_table%`
INNER JOIN `%saved_positions_table%` ON `%homes_table%`.`saved_position_id`=`%saved_positions_table%`.`id`
INNER JOIN `%positions_table%` ON `%saved_positions_table%`.`position_id`=`%positions_table%`.`id`
INNER JOIN `%players_table%` ON `%homes_table%`.`owner_uuid`=`%players_table%`.`uuid`
WHERE `owner_uuid`=?
""" + (caseInsensitive ? "AND UPPER(`name`) LIKE UPPER(?);" : "AND `name`=?;")))) {
SELECT `%homes_table%`.`uuid` AS `home_uuid`, `owner_uuid`, `username` AS `owner_username`, `name`, `description`, `tags`, `timestamp`, `x`, `y`, `z`, `yaw`, `pitch`, `world_name`, `world_uuid`, `server_name`, `public`
FROM `%homes_table%`
INNER JOIN `%saved_positions_table%` ON `%homes_table%`.`saved_position_id`=`%saved_positions_table%`.`id`
INNER JOIN `%positions_table%` ON `%saved_positions_table%`.`position_id`=`%positions_table%`.`id`
INNER JOIN `%players_table%` ON `%homes_table%`.`owner_uuid`=`%players_table%`.`uuid`
WHERE `owner_uuid`=?
""" + (caseInsensitive ? "AND UPPER(`name`) LIKE UPPER(?);" : "AND `name`=?;")))) {
statement.setString(1, user.getUuid().toString());
statement.setString(2, homeName);
@@ -509,11 +510,11 @@ public class SqLiteDatabase extends Database {
public Optional<Warp> getWarp(@NotNull String warpName, boolean caseInsensitive) {
try {
try (PreparedStatement statement = getConnection().prepareStatement(formatStatementTables("""
SELECT `%warps_table%`.`uuid` AS `warp_uuid`, `name`, `description`, `tags`, `timestamp`, `x`, `y`, `z`, `yaw`, `pitch`, `world_name`, `world_uuid`, `server_name`
FROM `%warps_table%`
INNER JOIN `%saved_positions_table%` ON `%warps_table%`.`saved_position_id`=`%saved_positions_table%`.`id`
INNER JOIN `%positions_table%` ON `%saved_positions_table%`.`position_id`=`%positions_table%`.`id`
""" + (caseInsensitive ? "WHERE UPPER(`name`) LIKE UPPER(?);" : "WHERE `name`=?;")))) {
SELECT `%warps_table%`.`uuid` AS `warp_uuid`, `name`, `description`, `tags`, `timestamp`, `x`, `y`, `z`, `yaw`, `pitch`, `world_name`, `world_uuid`, `server_name`
FROM `%warps_table%`
INNER JOIN `%saved_positions_table%` ON `%warps_table%`.`saved_position_id`=`%saved_positions_table%`.`id`
INNER JOIN `%positions_table%` ON `%saved_positions_table%`.`position_id`=`%positions_table%`.`id`
""" + (caseInsensitive ? "WHERE UPPER(`name`) LIKE UPPER(?);" : "WHERE `name`=?;")))) {
statement.setString(1, warpName);
final ResultSet resultSet = statement.executeQuery();
@@ -603,6 +604,8 @@ public class SqLiteDatabase extends Database {
} catch (SQLException e) {
plugin.log(Level.SEVERE, "Failed to query the current teleport of " + onlineUser.getUsername(), e);
} catch (TeleportationException e) {
e.displayMessage(onlineUser, plugin);
}
return Optional.empty();
}