Fix invalid warp locale not displaying, make home/warp lookup case-insensitive (#384)

This commit is contained in:
William authored and GitHub committed 2023-05-03 17:21:27 +01:00
1 parent a37bc8b3eb
commit 4db9bcf6ba
8 files changed
+89 -27

No files matched your search

@@ -208,13 +208,26 @@ public abstract class Database {
}
/**
* Get a {@link Home} set by a {@link User}
* Get a {@link Home} with the given name, set by the given {@link User}
*
* @param user The {@link User} who set the home
* @param homeName The <i>case-insensitive</i> name of the home to get
* @param homeName The name of the home to get
* @return A future returning an optional with the {@link Home} present if it exists
* @apiNote Whether the name lookup query is case-insensitive is determined by the {@code general.case_insensitive_names} setting
*/
public final Optional<Home> getHome(@NotNull User user, @NotNull String homeName) {
return this.getHome(user, homeName, plugin.getSettings().caseInsensitiveNames());
}
/**
* Get a {@link Home} with the given name, set by the given {@link User}
*
* @param user The {@link User} who set the home
* @param homeName The name of the home to get
* @param caseInsensitive Whether the name lookup query should be case-insensitive
* @return A future returning an optional with the {@link Home} present if it exists
*/
public abstract Optional<Home> getHome(@NotNull User user, @NotNull String homeName);
protected abstract Optional<Home> getHome(@NotNull User user, @NotNull String homeName, boolean caseInsensitive);
/**
* Get a {@link Home} by its unique id
@@ -225,12 +238,24 @@ public abstract class Database {
public abstract Optional<Home> getHome(@NotNull UUID uuid);
/**
* Get a {@link Warp} with the given name (<i>case-insensitive</i>)
* Get a {@link Warp} with the given name
*
* @param warpName The <i>case-insensitive</i> name of the warp to get
* @param warpName The name of the warp to get
* @return A future returning an optional with the {@link Warp} present if it exists
* @apiNote Whether the name lookup query is case-insensitive is determined by the {@code general.case_insensitive_names} setting
*/
public final Optional<Warp> getWarp(@NotNull String warpName) {
return getWarp(warpName, plugin.getSettings().caseInsensitiveNames());
}
/**
* Get a {@link Warp} with the given name
*
* @param warpName The name of the warp to get
* @param caseInsensitive Whether the search should be case-insensitive
* @return A future returning an optional with the {@link Warp} present if it exists
*/
public abstract Optional<Warp> getWarp(@NotNull String warpName);
protected abstract Optional<Warp> getWarp(@NotNull String warpName, boolean caseInsensitive);
/**
* Get a {@link Warp} by its unique id
@@ -418,7 +418,7 @@ public class MySqlDatabase extends Database {
}
@Override
public Optional<Home> getHome(@NotNull User user, @NotNull String homeName) {
public Optional<Home> getHome(@NotNull User user, @NotNull String homeName, boolean caseInsensitive) {
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`
@@ -427,7 +427,7 @@ public class MySqlDatabase extends Database {
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`=?
AND `name`=?;"""))) {
""" + (caseInsensitive ? "AND UPPER(`name`) LIKE UPPER(?);" : "AND `name`=?;")))) {
statement.setString(1, user.getUuid().toString());
statement.setString(2, homeName);
@@ -495,14 +495,14 @@ public class MySqlDatabase extends Database {
}
@Override
public Optional<Warp> getWarp(@NotNull String warpName) {
public Optional<Warp> getWarp(@NotNull String warpName, boolean caseInsensitive) {
try (Connection connection = getConnection()) {
try (PreparedStatement statement = connection.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`
WHERE `name`=?;"""))) {
""" + (caseInsensitive ? "WHERE UPPER(`name`) LIKE UPPER(?);" : "WHERE `name`=?;")))) {
statement.setString(1, warpName);
final ResultSet resultSet = statement.executeQuery();
@@ -991,7 +991,6 @@ public class MySqlDatabase extends Database {
@Override
public int deleteAllWarps() {
try (Connection connection = getConnection()) {
try (PreparedStatement statement = connection.prepareStatement(formatStatementTables("""
DELETE FROM `%positions_table%`
@@ -429,7 +429,7 @@ public class SqLiteDatabase extends Database {
}
@Override
public Optional<Home> getHome(@NotNull User user, @NotNull String homeName) {
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`
@@ -438,7 +438,7 @@ public class SqLiteDatabase extends Database {
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`=?
AND `name`=?;"""))) {
""" + (caseInsensitive ? "AND UPPER(`name`) LIKE UPPER(?);" : "AND `name`=?;")))) {
statement.setString(1, user.getUuid().toString());
statement.setString(2, homeName);
@@ -506,14 +506,14 @@ public class SqLiteDatabase extends Database {
}
@Override
public Optional<Warp> getWarp(@NotNull String warpName) {
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`
WHERE `name`=?;"""))) {
""" + (caseInsensitive ? "WHERE UPPER(`name`) LIKE UPPER(?);" : "WHERE `name`=?;")))) {
statement.setString(1, warpName);
final ResultSet resultSet = statement.executeQuery();