mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 14:38:53 +00:00
Fix invalid warp locale not displaying, make home/warp lookup case-insensitive (#384)
This commit is contained in:
1 parent
a37bc8b3eb
commit
4db9bcf6ba
8 files changed
+89
-27
No files matched your search
@@ -330,8 +330,24 @@ public class BukkitPluginTests {
|
|||||||
Assertions.assertTrue(plugin.getDatabase().getWarp(name).isPresent());
|
Assertions.assertTrue(plugin.getDatabase().getWarp(name).isPresent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DisplayName("Test Querying Warps Case-Insensitively")
|
||||||
|
@ParameterizedTest(name = "Query: \"{0}\"")
|
||||||
|
@MethodSource("provideWarpData")
|
||||||
|
@Order(8)
|
||||||
|
public void testWarpCaseInsensitiveQuery(@NotNull String name, @SuppressWarnings("unused") @NotNull Position position) {
|
||||||
|
final String nameUpper = name.toUpperCase();
|
||||||
|
final Optional<Warp> nameUpperWarp = plugin.getDatabase().getWarp(nameUpper);
|
||||||
|
Assertions.assertTrue(nameUpperWarp.isPresent());
|
||||||
|
Assertions.assertEquals(name, nameUpperWarp.get().getName());
|
||||||
|
|
||||||
|
final String nameLower = name.toLowerCase();
|
||||||
|
final Optional<Warp> nameLowerWarp = plugin.getDatabase().getWarp(nameLower);
|
||||||
|
Assertions.assertTrue(nameLowerWarp.isPresent());
|
||||||
|
Assertions.assertEquals(name, nameLowerWarp.get().getName());
|
||||||
|
}
|
||||||
|
|
||||||
@DisplayName("Test Deleting All Warps")
|
@DisplayName("Test Deleting All Warps")
|
||||||
@Order(7)
|
@Order(9)
|
||||||
@Test
|
@Test
|
||||||
public void testWarpDeleteAll() {
|
public void testWarpDeleteAll() {
|
||||||
final int deleted = plugin.getManager().warps().deleteAllWarps();
|
final int deleted = plugin.getManager().warps().deleteAllWarps();
|
||||||
@@ -488,10 +504,26 @@ public class BukkitPluginTests {
|
|||||||
.contains(name));
|
.contains(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DisplayName("Test Querying Homes Case-Insensitively")
|
||||||
|
@ParameterizedTest(name = "Query: \"{1}\"")
|
||||||
|
@MethodSource("provideHomeData")
|
||||||
|
@Order(8)
|
||||||
|
public void testWarpCaseInsensitiveQuery(@NotNull OnlineUser owner, @NotNull String name, @SuppressWarnings("unused") @NotNull Position position) {
|
||||||
|
final String nameUpper = name.toUpperCase();
|
||||||
|
final Optional<Home> nameUpperWarp = plugin.getDatabase().getHome(owner, nameUpper);
|
||||||
|
Assertions.assertTrue(nameUpperWarp.isPresent());
|
||||||
|
Assertions.assertEquals(name, nameUpperWarp.get().getName());
|
||||||
|
|
||||||
|
final String nameLower = name.toLowerCase();
|
||||||
|
final Optional<Home> nameLowerWarp = plugin.getDatabase().getHome(owner, nameLower);
|
||||||
|
Assertions.assertTrue(nameLowerWarp.isPresent());
|
||||||
|
Assertions.assertEquals(name, nameLowerWarp.get().getName());
|
||||||
|
}
|
||||||
|
|
||||||
@DisplayName("Test Home Deletion")
|
@DisplayName("Test Home Deletion")
|
||||||
@ParameterizedTest(name = "Delete: \"{1}\"")
|
@ParameterizedTest(name = "Delete: \"{1}\"")
|
||||||
@MethodSource("provideHomeData")
|
@MethodSource("provideHomeData")
|
||||||
@Order(8)
|
@Order(9)
|
||||||
public void testHomeDeletion(@NotNull OnlineUser owner, @NotNull String name, @SuppressWarnings("unused") @NotNull Position position) {
|
public void testHomeDeletion(@NotNull OnlineUser owner, @NotNull String name, @SuppressWarnings("unused") @NotNull Position position) {
|
||||||
plugin.getManager().homes().deleteHome(owner, name);
|
plugin.getManager().homes().deleteHome(owner, name);
|
||||||
Assertions.assertFalse(plugin.getDatabase().getHome(owner, name).isPresent());
|
Assertions.assertFalse(plugin.getDatabase().getHome(owner, name).isPresent());
|
||||||
@@ -503,7 +535,7 @@ public class BukkitPluginTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@DisplayName("Test Deleting All Homes")
|
@DisplayName("Test Deleting All Homes")
|
||||||
@Order(9)
|
@Order(10)
|
||||||
@Test
|
@Test
|
||||||
public void testDeleteAllHomes() {
|
public void testDeleteAllHomes() {
|
||||||
final int deleted = plugin.getManager().homes().deleteAllHomes(homeOwner);
|
final int deleted = plugin.getManager().homes().deleteAllHomes(homeOwner);
|
||||||
|
|||||||
@@ -131,8 +131,13 @@ public abstract class SavedPositionCommand<T extends SavedPosition> extends Comm
|
|||||||
|
|
||||||
private Optional<Warp> resolveWarp(@NotNull CommandUser executor, @NotNull String warpName) {
|
private Optional<Warp> resolveWarp(@NotNull CommandUser executor, @NotNull String warpName) {
|
||||||
final Optional<Warp> warp = resolveWarpByName(warpName);
|
final Optional<Warp> warp = resolveWarpByName(warpName);
|
||||||
if (warp.isPresent() && executor instanceof OnlineUser user && plugin.getSettings().doPermissionRestrictWarps()
|
if (warp.isEmpty()) {
|
||||||
&& (!user.hasPermission(Warp.getWildcardPermission()) && !user.hasPermission(Warp.getPermission(warpName)))) {
|
plugin.getLocales().getLocale("error_warp_invalid", warpName)
|
||||||
|
.ifPresent(executor::sendMessage);
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
if (executor instanceof OnlineUser user && plugin.getSettings().doPermissionRestrictWarps()
|
||||||
|
&& !user.hasPermission(Warp.getWildcardPermission()) && !user.hasPermission(Warp.getPermission(warpName))) {
|
||||||
plugin.getLocales().getLocale("error_warp_invalid", warpName)
|
plugin.getLocales().getLocale("error_warp_invalid", warpName)
|
||||||
.ifPresent(executor::sendMessage);
|
.ifPresent(executor::sendMessage);
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|||||||
@@ -137,6 +137,9 @@ public class Settings {
|
|||||||
@YamlKey("general.strict_tpa_here_requests")
|
@YamlKey("general.strict_tpa_here_requests")
|
||||||
private boolean strictTpaHereRequests = true;
|
private boolean strictTpaHereRequests = true;
|
||||||
|
|
||||||
|
@YamlKey("general.case_insensitive_names")
|
||||||
|
private boolean caseInsensitiveNames = true;
|
||||||
|
|
||||||
@YamlKey("general.allow_unicode_names")
|
@YamlKey("general.allow_unicode_names")
|
||||||
private boolean allowUnicodeNames = false;
|
private boolean allowUnicodeNames = false;
|
||||||
|
|
||||||
@@ -361,6 +364,8 @@ public class Settings {
|
|||||||
return strictTpaHereRequests;
|
return strictTpaHereRequests;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean caseInsensitiveNames() { return caseInsensitiveNames; }
|
||||||
|
|
||||||
public boolean doAllowUnicodeNames() {
|
public boolean doAllowUnicodeNames() {
|
||||||
return allowUnicodeNames;
|
return allowUnicodeNames;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 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
|
* @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
|
* Get a {@link Home} by its unique id
|
||||||
@@ -225,12 +238,24 @@ public abstract class Database {
|
|||||||
public abstract Optional<Home> getHome(@NotNull UUID uuid);
|
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
|
* @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
|
* Get a {@link Warp} by its unique id
|
||||||
|
|||||||
@@ -418,7 +418,7 @@ public class MySqlDatabase extends Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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 (Connection connection = getConnection()) {
|
||||||
try (PreparedStatement statement = connection.prepareStatement(formatStatementTables("""
|
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`
|
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 `%positions_table%` ON `%saved_positions_table%`.`position_id`=`%positions_table%`.`id`
|
||||||
INNER JOIN `%players_table%` ON `%homes_table%`.`owner_uuid`=`%players_table%`.`uuid`
|
INNER JOIN `%players_table%` ON `%homes_table%`.`owner_uuid`=`%players_table%`.`uuid`
|
||||||
WHERE `owner_uuid`=?
|
WHERE `owner_uuid`=?
|
||||||
AND `name`=?;"""))) {
|
""" + (caseInsensitive ? "AND UPPER(`name`) LIKE UPPER(?);" : "AND `name`=?;")))) {
|
||||||
statement.setString(1, user.getUuid().toString());
|
statement.setString(1, user.getUuid().toString());
|
||||||
statement.setString(2, homeName);
|
statement.setString(2, homeName);
|
||||||
|
|
||||||
@@ -495,14 +495,14 @@ public class MySqlDatabase extends Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<Warp> getWarp(@NotNull String warpName) {
|
public Optional<Warp> getWarp(@NotNull String warpName, boolean caseInsensitive) {
|
||||||
try (Connection connection = getConnection()) {
|
try (Connection connection = getConnection()) {
|
||||||
try (PreparedStatement statement = connection.prepareStatement(formatStatementTables("""
|
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`
|
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%`
|
FROM `%warps_table%`
|
||||||
INNER JOIN `%saved_positions_table%` ON `%warps_table%`.`saved_position_id`=`%saved_positions_table%`.`id`
|
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`
|
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);
|
statement.setString(1, warpName);
|
||||||
|
|
||||||
final ResultSet resultSet = statement.executeQuery();
|
final ResultSet resultSet = statement.executeQuery();
|
||||||
@@ -991,7 +991,6 @@ public class MySqlDatabase extends Database {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int deleteAllWarps() {
|
public int deleteAllWarps() {
|
||||||
|
|
||||||
try (Connection connection = getConnection()) {
|
try (Connection connection = getConnection()) {
|
||||||
try (PreparedStatement statement = connection.prepareStatement(formatStatementTables("""
|
try (PreparedStatement statement = connection.prepareStatement(formatStatementTables("""
|
||||||
DELETE FROM `%positions_table%`
|
DELETE FROM `%positions_table%`
|
||||||
|
|||||||
@@ -429,7 +429,7 @@ public class SqLiteDatabase extends Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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 {
|
||||||
try (PreparedStatement statement = getConnection().prepareStatement(formatStatementTables("""
|
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`
|
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 `%positions_table%` ON `%saved_positions_table%`.`position_id`=`%positions_table%`.`id`
|
||||||
INNER JOIN `%players_table%` ON `%homes_table%`.`owner_uuid`=`%players_table%`.`uuid`
|
INNER JOIN `%players_table%` ON `%homes_table%`.`owner_uuid`=`%players_table%`.`uuid`
|
||||||
WHERE `owner_uuid`=?
|
WHERE `owner_uuid`=?
|
||||||
AND `name`=?;"""))) {
|
""" + (caseInsensitive ? "AND UPPER(`name`) LIKE UPPER(?);" : "AND `name`=?;")))) {
|
||||||
statement.setString(1, user.getUuid().toString());
|
statement.setString(1, user.getUuid().toString());
|
||||||
statement.setString(2, homeName);
|
statement.setString(2, homeName);
|
||||||
|
|
||||||
@@ -506,14 +506,14 @@ public class SqLiteDatabase extends Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<Warp> getWarp(@NotNull String warpName) {
|
public Optional<Warp> getWarp(@NotNull String warpName, boolean caseInsensitive) {
|
||||||
try {
|
try {
|
||||||
try (PreparedStatement statement = getConnection().prepareStatement(formatStatementTables("""
|
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`
|
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%`
|
FROM `%warps_table%`
|
||||||
INNER JOIN `%saved_positions_table%` ON `%warps_table%`.`saved_position_id`=`%saved_positions_table%`.`id`
|
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`
|
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);
|
statement.setString(1, warpName);
|
||||||
|
|
||||||
final ResultSet resultSet = statement.executeQuery();
|
final ResultSet resultSet = statement.executeQuery();
|
||||||
|
|||||||
@@ -186,6 +186,7 @@ public class HomesManager {
|
|||||||
|
|
||||||
final Home home = existingHome
|
final Home home = existingHome
|
||||||
.map(existing -> {
|
.map(existing -> {
|
||||||
|
existing.getMeta().setName(name);
|
||||||
existing.update(position);
|
existing.update(position);
|
||||||
return existing;
|
return existing;
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -124,13 +124,8 @@ public class WarpsManager {
|
|||||||
|
|
||||||
final Warp warp = existingWarp
|
final Warp warp = existingWarp
|
||||||
.map(existing -> {
|
.map(existing -> {
|
||||||
existing.setX(position.getX());
|
existing.getMeta().setName(name);
|
||||||
existing.setY(position.getY());
|
existing.update(position);
|
||||||
existing.setZ(position.getZ());
|
|
||||||
existing.setWorld(position.getWorld());
|
|
||||||
existing.setServer(position.getServer());
|
|
||||||
existing.setYaw(position.getYaw());
|
|
||||||
existing.setPitch(position.getPitch());
|
|
||||||
return existing;
|
return existing;
|
||||||
})
|
})
|
||||||
.orElse(Warp.from(position, PositionMeta.create(name, "")));
|
.orElse(Warp.from(position, PositionMeta.create(name, "")));
|
||||||
|
|||||||
Reference in new issue
Block a user