mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-01 22:16:08 +00:00
feat: allow /phome <name> on uniquely named homes
If multiple public homes with the same name exist, typing /phome (name) will bring up a filtered public home list containing the list of public homes with that name for you to click on. The username-prefixed name will also be the only one to show up in TAB. This commit also fixes a bug with home/warp lists showing a blank description on hover instead of `(none)`.
This commit is contained in:
32 files changed
+353
-81
No files matched your search
@@ -296,19 +296,19 @@ public class H2Database extends Database {
|
||||
try (Connection connection = getConnection()) {
|
||||
// Delete Position
|
||||
PreparedStatement statement = connection.prepareStatement(formatStatementTables("""
|
||||
DELETE FROM `%positions_table%`
|
||||
WHERE `id`
|
||||
IN ((SELECT `last_position` FROM `%players_table%` WHERE `uuid` = ?),
|
||||
(SELECT `offline_position` FROM `%players_table%` WHERE `uuid` = ?),
|
||||
(SELECT `respawn_position` FROM `%players_table%` WHERE `uuid` = ?));"""));
|
||||
DELETE FROM `%positions_table%`
|
||||
WHERE `id`
|
||||
IN ((SELECT `last_position` FROM `%players_table%` WHERE `uuid` = ?),
|
||||
(SELECT `offline_position` FROM `%players_table%` WHERE `uuid` = ?),
|
||||
(SELECT `respawn_position` FROM `%players_table%` WHERE `uuid` = ?));"""));
|
||||
statement.setString(1, uuid.toString());
|
||||
statement.setString(2, uuid.toString());
|
||||
statement.setString(3, uuid.toString());
|
||||
statement.executeUpdate();
|
||||
|
||||
statement = connection.prepareStatement(formatStatementTables("""
|
||||
DELETE FROM `%players_table%`
|
||||
WHERE `uuid`=?;"""));
|
||||
DELETE FROM `%players_table%`
|
||||
WHERE `uuid`=?;"""));
|
||||
statement.setString(1, uuid.toString());
|
||||
statement.executeUpdate();
|
||||
|
||||
@@ -498,6 +498,54 @@ public class H2Database extends Database {
|
||||
return userHomes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Home> getPublicHomes(@NotNull String name, boolean caseInsensitive) {
|
||||
final List<Home> userHomes = new ArrayList<>();
|
||||
try (Connection connection = getConnection()) {
|
||||
try (PreparedStatement statement = connection.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 `public`=true
|
||||
AND ((? AND UPPER(`name`) LIKE UPPER(?)) OR (`name`=?))
|
||||
ORDER BY `name`;"""))) {
|
||||
statement.setBoolean(1, caseInsensitive);
|
||||
statement.setString(2, name);
|
||||
statement.setString(3, name);
|
||||
|
||||
final ResultSet resultSet = statement.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
userHomes.add(Home.from(resultSet.getDouble("x"),
|
||||
resultSet.getDouble("y"),
|
||||
resultSet.getDouble("z"),
|
||||
resultSet.getFloat("yaw"),
|
||||
resultSet.getFloat("pitch"),
|
||||
World.from(resultSet.getString("world_name"),
|
||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||
resultSet.getString("server_name"),
|
||||
PositionMeta.from(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
resultSet.getString("tags")),
|
||||
UUID.fromString(resultSet.getString("home_uuid")),
|
||||
User.of(UUID.fromString(resultSet.getString("owner_uuid")),
|
||||
resultSet.getString("owner_username")),
|
||||
resultSet.getBoolean("public")));
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
plugin.log(Level.SEVERE, "Failed to query the database for public home data");
|
||||
}
|
||||
return userHomes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Home> getHome(@NotNull User user, @NotNull String homeName, boolean caseInsensitive) {
|
||||
try (Connection connection = getConnection()) {
|
||||
|
||||
Reference in new issue
Block a user