From f6cb19cf4060940957e84d126ee3c8374b5fe1b9 Mon Sep 17 00:00:00 2001 From: William Date: Thu, 9 Jun 2022 14:17:45 +0100 Subject: [PATCH] Fix offline/last/respawn position setting --- .../net/william278/huskhomes/HuskHomesBukkit.java | 1 - .../net/william278/huskhomes/data/MySqlDatabase.java | 6 +++++- .../net/william278/huskhomes/data/SqLiteDatabase.java | 11 +++++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/bukkit/src/main/java/net/william278/huskhomes/HuskHomesBukkit.java b/bukkit/src/main/java/net/william278/huskhomes/HuskHomesBukkit.java index 4678ce87..272d03ba 100644 --- a/bukkit/src/main/java/net/william278/huskhomes/HuskHomesBukkit.java +++ b/bukkit/src/main/java/net/william278/huskhomes/HuskHomesBukkit.java @@ -171,7 +171,6 @@ public class HuskHomesBukkit extends JavaPlugin implements HuskHomes { for (CommandBase commandBase : commands) { final PluginCommand pluginCommand = getCommand(commandBase.command); if (pluginCommand != null) { - getLogger().log(Level.INFO, "Registered /" + commandBase.command); new BukkitCommand(commandBase, this).register(pluginCommand); } } diff --git a/common/src/main/java/net/william278/huskhomes/data/MySqlDatabase.java b/common/src/main/java/net/william278/huskhomes/data/MySqlDatabase.java index 3a903469..2e4226ac 100644 --- a/common/src/main/java/net/william278/huskhomes/data/MySqlDatabase.java +++ b/common/src/main/java/net/william278/huskhomes/data/MySqlDatabase.java @@ -699,7 +699,9 @@ public class MySqlDatabase extends Database { return CompletableFuture.runAsync(() -> { try (Connection connection = getConnection()) { try (PreparedStatement queryStatement = connection.prepareStatement(formatStatementTables(""" - SELECT `last_position` FROM `%players_table%` + SELECT `last_position` + FROM `%players_table%` + INNER JOIN `%positions_table%` ON `%players_table%`.last_position = "%positions_table%".id WHERE `uuid`=?;"""))) { queryStatement.setString(1, user.uuid.toString()); @@ -760,6 +762,7 @@ public class MySqlDatabase extends Database { try (Connection connection = getConnection()) { try (PreparedStatement queryStatement = connection.prepareStatement(formatStatementTables(""" SELECT `offline_position` FROM `%players_table%` + INNER JOIN `%positions_table%` ON `%players_table%`.offline_position = "%positions_table%".id WHERE `uuid`=?;"""))) { queryStatement.setString(1, user.uuid.toString()); @@ -820,6 +823,7 @@ public class MySqlDatabase extends Database { try (Connection connection = getConnection()) { try (PreparedStatement queryStatement = connection.prepareStatement(formatStatementTables(""" SELECT `respawn_position` FROM `%players_table%` + INNER JOIN `%positions_table%` ON `%players_table%`.respawn_position = "%positions_table%".id WHERE `uuid`=?;"""))) { queryStatement.setString(1, user.uuid.toString()); diff --git a/common/src/main/java/net/william278/huskhomes/data/SqLiteDatabase.java b/common/src/main/java/net/william278/huskhomes/data/SqLiteDatabase.java index ddff4fae..28208f13 100644 --- a/common/src/main/java/net/william278/huskhomes/data/SqLiteDatabase.java +++ b/common/src/main/java/net/william278/huskhomes/data/SqLiteDatabase.java @@ -185,10 +185,10 @@ public class SqLiteDatabase extends Database { updatePosition(positionId, position, connection); try (PreparedStatement updateStatement = connection.prepareStatement(formatStatementTables(""" - UPDATE `%saved_positions_table%` - SET `name`=?, - `description`=? - WHERE `id`=?;"""))) { + UPDATE `%saved_positions_table%` + SET `name`=?, + `description`=? + WHERE `id`=?;"""))) { updateStatement.setString(1, position.meta.name); updateStatement.setString(2, position.meta.description); updateStatement.setInt(3, savedPositionId); @@ -683,6 +683,7 @@ public class SqLiteDatabase extends Database { try { try (PreparedStatement queryStatement = getConnection().prepareStatement(formatStatementTables(""" SELECT `last_position` FROM `%players_table%` + INNER JOIN `%positions_table%` ON `%players_table%`.last_position = "%positions_table%".id WHERE `uuid`=?;"""))) { queryStatement.setString(1, user.uuid.toString()); @@ -743,6 +744,7 @@ public class SqLiteDatabase extends Database { try { try (PreparedStatement queryStatement = getConnection().prepareStatement(formatStatementTables(""" SELECT `offline_position` FROM `%players_table%` + INNER JOIN `%positions_table%` ON `%players_table%`.offline_position = "%positions_table%".id WHERE `uuid`=?;"""))) { queryStatement.setString(1, user.uuid.toString()); @@ -803,6 +805,7 @@ public class SqLiteDatabase extends Database { try { try (PreparedStatement queryStatement = getConnection().prepareStatement(formatStatementTables(""" SELECT `respawn_position` FROM `%players_table%` + INNER JOIN `%positions_table%` ON `%players_table%`.respawn_position = "%positions_table%".id WHERE `uuid`=?;"""))) { queryStatement.setString(1, user.uuid.toString());