Add fabric builds for older MC versions & add checkstyle (#449)

* Remove instance getters, improve command logic, register APi

* Publish multiple fabric builds, enforce checkstyle

* Bump guava

* Bump to 4.4.2
This commit is contained in:
William authored and GitHub committed 2023-07-02 13:26:12 +01:00
1 parent 51baf196b3
commit c9f5262292
219 files changed
+8032 -1392

No files matched your search

@@ -30,6 +30,7 @@ import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.user.SavedUser;
import net.william278.huskhomes.user.User;
import net.william278.huskhomes.util.TransactionResolver;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -38,23 +39,20 @@ import java.nio.charset.StandardCharsets;
import java.sql.Connection;
import java.sql.SQLException;
import java.time.Instant;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.*;
import java.util.stream.Collectors;
/**
* An abstract representation of the plugin database, storing home, warp and player data.
* <p>
* Implemented by different database platforms - MySQL, SQLite, etc. - as configured by the administrator.
*
* <p>Implemented by different database platforms - MySQL, SQLite, etc. - as configured by the administrator.
*/
public abstract class Database {
protected final HuskHomes plugin;
/**
* Loads SQL table creation schema statements from a resource file as a string array
* Loads SQL table creation schema statements from a resource file as a string array.
*
* @param schemaFileName database script resource file to load from
* @return Array of string-formatted table creation schema statements
@@ -68,24 +66,31 @@ public abstract class Database {
}
/**
* Format all table name placeholder strings in a SQL statement
* Format all table name placeholder strings in an SQL statement.
*
* @param sql the SQL statement with unformatted table name placeholders
* @return the formatted statement, with table placeholders replaced with the correct names
*/
protected final String formatStatementTables(@NotNull String sql) {
return sql
.replaceAll("%positions_table%", plugin.getSettings().getTableName(Table.POSITION_DATA))
.replaceAll("%players_table%", plugin.getSettings().getTableName(Table.PLAYER_DATA))
.replaceAll("%cooldowns_table%", plugin.getSettings().getTableName(Table.PLAYER_COOLDOWNS_DATA))
.replaceAll("%teleports_table%", plugin.getSettings().getTableName(Table.TELEPORT_DATA))
.replaceAll("%saved_positions_table%", plugin.getSettings().getTableName(Table.SAVED_POSITION_DATA))
.replaceAll("%homes_table%", plugin.getSettings().getTableName(Table.HOME_DATA))
.replaceAll("%warps_table%", plugin.getSettings().getTableName(Table.WARP_DATA));
.replaceAll("%positions_table%", plugin.getSettings()
.getTableName(Table.POSITION_DATA))
.replaceAll("%players_table%", plugin.getSettings()
.getTableName(Table.PLAYER_DATA))
.replaceAll("%cooldowns_table%", plugin.getSettings()
.getTableName(Table.PLAYER_COOLDOWNS_DATA))
.replaceAll("%teleports_table%", plugin.getSettings()
.getTableName(Table.TELEPORT_DATA))
.replaceAll("%saved_positions_table%", plugin.getSettings()
.getTableName(Table.SAVED_POSITION_DATA))
.replaceAll("%homes_table%", plugin.getSettings()
.getTableName(Table.HOME_DATA))
.replaceAll("%warps_table%", plugin.getSettings()
.getTableName(Table.WARP_DATA));
}
/**
* Create a database instance, pulling table names from the plugin config
* Create a database instance, pulling table names from the plugin config.
*
* @param plugin the implementing plugin instance
*/
@@ -99,7 +104,7 @@ public abstract class Database {
public abstract void initialize() throws IllegalStateException;
/**
* <b>(Internal use only)</b> - Sets a position to the position table in the database
* <b>(Internal use only)</b> - Sets a position to the position table in the database.
*
* @param position The {@link Position} to set
* @param connection SQL connection
@@ -109,44 +114,50 @@ public abstract class Database {
protected abstract int setPosition(@NotNull Position position, @NotNull Connection connection) throws SQLException;
/**
* <b>(Internal use only)</b> - Updates position data
* <b>(Internal use only)</b> - Updates position data.
*
* @param positionId ID of the position to update
* @param position the Position.at
* @param connection SQL connection
* @throws SQLException if an SQL exception occurs doing this
*/
protected abstract void updatePosition(int positionId, @NotNull Position position, @NotNull Connection connection) throws SQLException;
@ApiStatus.Internal
protected abstract void updatePosition(int positionId, @NotNull Position position,
@NotNull Connection connection) throws SQLException;
/**
* <b>(Internal use only)</b> - Sets a {@link SavedPosition} to the database
* <b>(Internal use only)</b> - Sets a {@link SavedPosition} to the database.
*
* @param position The {@link SavedPosition} to set
* @param connection SQL connection
* @return The newly inserted row ID
* @throws SQLException if an SQL exception occurs doing this
*/
protected abstract int setSavedPosition(@NotNull SavedPosition position, @NotNull Connection connection) throws SQLException;
@ApiStatus.Internal
protected abstract int setSavedPosition(@NotNull SavedPosition position,
@NotNull Connection connection) throws SQLException;
/**
* <b>(Internal use only)</b> - Updates a saved position metadata
* <b>(Internal use only)</b> - Updates a saved position metadata.
*
* @param savedPositionId ID of the metadata to update
* @param savedPosition the new saved position
* @param connection SQL connection
* @throws SQLException if an SQL exception occurs doing this
*/
protected abstract void updateSavedPosition(int savedPositionId, @NotNull SavedPosition savedPosition, @NotNull Connection connection) throws SQLException;
@ApiStatus.Internal
protected abstract void updateSavedPosition(int savedPositionId, @NotNull SavedPosition savedPosition,
@NotNull Connection connection) throws SQLException;
/**
* Ensure a {@link User} has a {@link SavedUser} entry in the database and that their username is up-to-date
* Ensure a {@link User} has a {@link SavedUser} entry in the database and that their username is up-to-date.
*
* @param user The {@link User} to ensure
*/
public abstract void ensureUser(@NotNull User user);
/**
* Get {@link SavedUser} for a user by their Minecraft username (<i>case-insensitive</i>)
* Get {@link SavedUser} for a user by their Minecraft username (<i>case-insensitive</i>).
*
* @param name Username of the {@link SavedUser} to get (<i>case-insensitive</i>)
* @return An optional with the {@link SavedUser} present if they exist
@@ -154,7 +165,7 @@ public abstract class Database {
public abstract Optional<SavedUser> getUserDataByName(@NotNull String name);
/**
* Get {@link SavedUser} for a user by their Minecraft account {@link UUID}
* Get {@link SavedUser} for a user by their Minecraft account {@link UUID}.
*
* @param uuid Minecraft account {@link UUID} of the {@link SavedUser} to get
* @return An optional with the {@link SavedUser} present if they exist
@@ -162,23 +173,24 @@ public abstract class Database {
public abstract Optional<SavedUser> getUserData(@NotNull UUID uuid);
/**
* Get the currently active cooldown of a {@link User} for a specific {@link TransactionResolver.Action}
* Get the currently active cooldown of a {@link User} for a specific {@link TransactionResolver.Action}.
*
* @return An optional containing the {@link Instant} the cooldown expires at, or empty if the {@link User} has no cooldown
* @return An optional with the {@link Instant} the cooldown expires, or empty if the {@link User} has no cooldown
*/
public abstract Optional<Instant> getCooldown(@NotNull TransactionResolver.Action action, @NotNull User user);
/**
* Set the cooldown of a {@link User} for a specific {@link TransactionResolver.Action}
* Set the cooldown of a {@link User} for a specific {@link TransactionResolver.Action}.
*
* @param action The {@link TransactionResolver.Action} to set the cooldown for
* @param user The {@link User} to set the cooldown for
* @param cooldownExpiry The {@link Instant} the cooldown expires at
*/
public abstract void setCooldown(@NotNull TransactionResolver.Action action, @NotNull User user, @NotNull Instant cooldownExpiry);
public abstract void setCooldown(@NotNull TransactionResolver.Action action, @NotNull User user,
@NotNull Instant cooldownExpiry);
/**
* Remove the cooldown of a {@link User} for a specific {@link TransactionResolver.Action}
* Remove the cooldown of a {@link User} for a specific {@link TransactionResolver.Action}.
*
* @param action The {@link TransactionResolver.Action} to remove the cooldown for
* @param user The {@link User} to remove the cooldown for
@@ -186,7 +198,7 @@ public abstract class Database {
public abstract void removeCooldown(@NotNull TransactionResolver.Action action, @NotNull User user);
/**
* Get a list of {@link Home}s set by a {@link User}
* Get a list of {@link Home}s set by a {@link User}.
*
* @param user {@link User} to get the homes of
* @return A future returning void when complete
@@ -194,14 +206,14 @@ public abstract class Database {
public abstract List<Home> getHomes(@NotNull User user);
/**
* Get a list of all {@link Warp}s that have been set
* Get a list of all {@link Warp}s that have been set.
*
* @return A list containing all {@link Warp}s
*/
public abstract List<Warp> getWarps();
/**
* Get a list of publicly-set {@link Warp}s on <i>this {@link Server}</i>
* Get a list of publicly-set {@link Warp}s on <i>this {@link Server server}</i>.
*
* @param plugin The plugin instance
* @return A list containing all {@link Warp}s set on this server
@@ -214,14 +226,14 @@ public abstract class Database {
}
/**
* Get a list of all publicly-set {@link Home}s
* Get a list of all publicly-set {@link Home}s.
*
* @return A list containing all publicly-set {@link Home}s
*/
public abstract List<Home> getPublicHomes();
/**
* Get a list of publicly-set {@link Home}s on <i>this {@link Server}</i>
* Get a list of publicly-set {@link Home}s on <i>this {@link Server server}</i>.
*
* @param plugin The plugin instance
* @return A list containing all publicly-set {@link Home}s on this server
@@ -234,19 +246,19 @@ public abstract class Database {
}
/**
* Get a {@link Home} with the given name, set by the given {@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 name of the home to get
* @return 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
* @apiNote Whether lookup is case-sensitive 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}
* 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
@@ -256,7 +268,7 @@ public abstract class Database {
public 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 {@link UUID unique ID}.
*
* @param uuid the {@link UUID} of the home to get
* @return An optional with the {@link Home} present if it exists
@@ -264,18 +276,18 @@ public abstract class Database {
public abstract Optional<Home> getHome(@NotNull UUID uuid);
/**
* Get a {@link Warp} with the given name
* Get a {@link Warp} with the given name.
*
* @param warpName The name of the warp to get
* @return 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
* @apiNote Whether lookup 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
* 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
@@ -284,7 +296,7 @@ public abstract class Database {
public abstract Optional<Warp> getWarp(@NotNull String warpName, boolean caseInsensitive);
/**
* Get a {@link Warp} by its unique id
* Get a {@link Warp} by its {@link UUID unique ID}.
*
* @param uuid the {@link UUID} of the warp to get
* @return An optional with the {@link Warp} present if it exists
@@ -292,7 +304,7 @@ public abstract class Database {
public abstract Optional<Warp> getWarp(@NotNull UUID uuid);
/**
* Get the current {@link Teleport} being executed by the specified {@link OnlineUser}
* Get the current {@link Teleport} being executed by the specified {@link OnlineUser}.
*
* @param onlineUser The {@link OnlineUser} to check
* @return An optional with the {@link Teleport} present if they are teleporting cross-server
@@ -300,23 +312,23 @@ public abstract class Database {
public abstract Optional<Teleport> getCurrentTeleport(@NotNull OnlineUser onlineUser);
/**
* Updates a user in the database with new {@link SavedUser}
* Updates a user in the database with new {@link SavedUser}.
*
* @param savedUser The {@link SavedUser} to update
*/
public abstract void updateUserData(@NotNull SavedUser savedUser);
/**
* Sets or clears the current {@link Teleport} being executed by a {@link User}
* Sets or clears the current {@link Teleport} being executed by a {@link User}.
*
* @param user The {@link User} to set the current teleport of.
* Pass as {@code null} to clear the player's current teleport.<p>
* Pass as {@code null} to clear the player's current teleport
* @param teleport The {@link Teleport} to set as their current cross-server teleport
*/
public abstract void setCurrentTeleport(@NotNull User user, @Nullable Teleport teleport);
/**
* Clears the current {@link Teleport} being executed by a {@link User}
* Clears the current {@link Teleport} being executed by a {@link User}.
*
* @param user The {@link User} to clear the current teleport of
*/
@@ -325,7 +337,7 @@ public abstract class Database {
}
/**
* Get the last teleport {@link Position} of a specified {@link User}
* Get the last teleport {@link Position} of a specified {@link User}.
*
* @param user The {@link User} to check
* @return An optional with the {@link Position} present if it has been set
@@ -333,7 +345,7 @@ public abstract class Database {
public abstract Optional<Position> getLastPosition(@NotNull User user);
/**
* Sets the last teleport {@link Position} of a {@link User}
* Sets the last teleport {@link Position} of a {@link User}.
*
* @param user The {@link User} to set the last position of
* @param position The {@link Position} to set as their last position
@@ -341,7 +353,7 @@ public abstract class Database {
public abstract void setLastPosition(@NotNull User user, @NotNull Position position);
/**
* Get the offline {@link Position} of a specified {@link User}
* Get the offline {@link Position} of a specified {@link User}.
*
* @param user The {@link User} to check
* @return An optional with the {@link Position} present if it has been set
@@ -349,7 +361,7 @@ public abstract class Database {
public abstract Optional<Position> getOfflinePosition(@NotNull User user);
/**
* Sets the offline {@link Position} of a {@link User}
* Sets the offline {@link Position} of a {@link User}.
*
* @param user The {@link User} to set the offline position of
* @param position The {@link Position} to set as their offline position
@@ -357,7 +369,7 @@ public abstract class Database {
public abstract void setOfflinePosition(@NotNull User user, @NotNull Position position);
/**
* Get the respawn {@link Position} of a specified {@link User}
* Get the respawn {@link Position} of a specified {@link User}.
*
* @param user The {@link User} to check
* @return An optional with the {@link Position} present if it has been set
@@ -365,11 +377,11 @@ public abstract class Database {
public abstract Optional<Position> getRespawnPosition(@NotNull User user);
/**
* Sets or clears the respawn {@link Position} of a {@link User}
* Sets or clears the respawn {@link Position} of a {@link User}.
*
* @param user The {@link User} to set the respawn position of
* @param position The {@link Position} to set as their respawn position
* Pass as {@code null} to clear the player's current respawn position.<p>
* Pass as {@code null} to clear the player's current respawn position.
*/
public abstract void setRespawnPosition(@NotNull User user, @Nullable Position position);
@@ -410,23 +422,24 @@ public abstract class Database {
public abstract void deleteWarp(@NotNull UUID uuid);
/**
* Deletes all {@link Warp}s set on the database table
* Deletes all {@link Warp}s set on the database table.
*
* @return An integer; the number of deleted warps
*/
public abstract int deleteAllWarps();
/**
* Close any remaining connection to the database source
* Close any remaining connection to the database source.
*/
public abstract void terminate();
/**
* Identifies types of databases
* Identifies types of databases.
*/
public enum Type {
MYSQL("MySQL"),
MARIADB("MariaDB"),
SQLITE("SQLite");
private final String displayName;
@@ -442,7 +455,7 @@ public abstract class Database {
}
/**
* Represents the names of tables in the database
* Represents the names of tables in the database.
*/
public enum Table {
PLAYER_DATA("huskhomes_users"),
@@ -460,8 +473,18 @@ public abstract class Database {
}
@NotNull
public String getDefaultName() {
public String getName() {
return defaultName;
}
@NotNull
public static Map<String, String> getConfigMap() {
return Arrays.stream(values())
.collect(Collectors.toMap(
Table::name,
action -> action.defaultName
));
}
}
}
@@ -38,7 +38,7 @@ import java.util.*;
import java.util.logging.Level;
/**
* A MySQL implementation of the plugin {@link Database}
* A MySQL implementation of the plugin {@link Database}.
*/
@SuppressWarnings("DuplicatedCode")
public class MySqlDatabase extends Database {
@@ -51,7 +51,7 @@ public class MySqlDatabase extends Database {
}
/**
* Fetch the auto-closeable connection from the hikariDataSource
* Fetch the auto-closeable connection from the hikariDataSource.
*
* @return The {@link Connection} to the MySQL database
* @throws SQLException if the connection fails for some reason
@@ -64,13 +64,15 @@ public class MySqlDatabase extends Database {
public void initialize() throws IllegalStateException {
// Initialize the Hikari pooled connection
dataSource = new HikariDataSource();
dataSource.setJdbcUrl("jdbc:mysql://" +
plugin.getSettings().getMySqlHost() +
":" +
plugin.getSettings().getMySqlPort() +
"/" +
plugin.getSettings().getMySqlDatabase() +
plugin.getSettings().getMySqlConnectionParameters());
dataSource.setJdbcUrl("jdbc:" + (plugin.getSettings().getDatabaseType() == Type.MARIADB ? "mariadb" : "mysql")
+ "://"
+ plugin.getSettings().getMySqlHost()
+ ":"
+ plugin.getSettings().getMySqlPort()
+ "/"
+ plugin.getSettings().getMySqlDatabase()
+ plugin.getSettings().getMySqlConnectionParameters()
);
// Authenticate with the database
dataSource.setUsername(plugin.getSettings().getMySqlUsername());
@@ -85,19 +87,24 @@ public class MySqlDatabase extends Database {
dataSource.setPoolName(DATA_POOL_NAME);
// Set additional connection pool properties
dataSource.setDataSourceProperties(new Properties() {{
put("cachePrepStmts", "true");
put("prepStmtCacheSize", "250");
put("prepStmtCacheSqlLimit", "2048");
put("useServerPrepStmts", "true");
put("useLocalSessionState", "true");
put("useLocalTransactionState", "true");
put("rewriteBatchedStatements", "true");
put("cacheResultSetMetadata", "true");
put("cacheServerConfiguration", "true");
put("elideSetAutoCommits", "true");
put("maintainTimeStats", "false");
}});
final Properties properties = new Properties();
properties.putAll(
Map.of("cachePrepStmts", "true",
"prepStmtCacheSize", "250",
"prepStmtCacheSqlLimit", "2048",
"useServerPrepStmts", "true",
"useLocalSessionState", "true",
"useLocalTransactionState", "true"
));
properties.putAll(
Map.of(
"rewriteBatchedStatements", "true",
"cacheResultSetMetadata", "true",
"cacheServerConfiguration", "true",
"elideSetAutoCommits", "true",
"maintainTimeStats", "false")
);
dataSource.setDataSourceProperties(properties);
// Prepare database schema; make tables if they don't exist
try (Connection connection = dataSource.getConnection()) {
@@ -107,20 +114,22 @@ public class MySqlDatabase extends Database {
statement.execute(tableCreationStatement);
}
} catch (SQLException e) {
throw new IllegalStateException("Failed to create database tables. Please ensure you are running MySQL v8.0+ " +
"and that your connecting user account has privileges to create tables.", e);
throw new IllegalStateException("Failed to create database tables. Make sure you're running MySQL v8.0+"
+ "and that your connecting user account has privileges to create tables.", e);
}
} catch (SQLException | IOException e) {
throw new IllegalStateException("Failed to establish a connection to the MySQL database. " +
"Please check the supplied database credentials in the config file", e);
throw new IllegalStateException("Failed to establish a connection to the MySQL database. "
+ "Please check the supplied database credentials in the config file", e);
}
}
@Override
protected int setPosition(@NotNull Position position, @NotNull Connection connection) throws SQLException {
try (PreparedStatement statement = connection.prepareStatement(formatStatementTables("""
INSERT INTO `%positions_table%` (`x`,`y`,`z`,`yaw`,`pitch`,`world_name`,`world_uuid`,`server_name`)
VALUES (?,?,?,?,?,?,?,?);"""),
INSERT INTO `%positions_table%`
(`x`,`y`,`z`,`yaw`,`pitch`,`world_name`,`world_uuid`,`server_name`)
VALUES
(?,?,?,?,?,?,?,?);"""),
Statement.RETURN_GENERATED_KEYS)) {
statement.setDouble(1, position.getX());
@@ -142,7 +151,8 @@ public class MySqlDatabase extends Database {
}
@Override
protected void updatePosition(int positionId, @NotNull Position position, @NotNull Connection connection) throws SQLException {
protected void updatePosition(int positionId, @NotNull Position position,
@NotNull Connection connection) throws SQLException {
try (PreparedStatement statement = connection.prepareStatement(formatStatementTables("""
UPDATE `%positions_table%`
SET `x`=?,
@@ -168,10 +178,13 @@ public class MySqlDatabase extends Database {
}
@Override
protected int setSavedPosition(@NotNull SavedPosition position, @NotNull Connection connection) throws SQLException {
protected int setSavedPosition(@NotNull SavedPosition position,
@NotNull Connection connection) throws SQLException {
try (PreparedStatement statement = connection.prepareStatement(formatStatementTables("""
INSERT INTO `%saved_positions_table%` (`position_id`, `name`, `description`, `tags`, `timestamp`)
VALUES (?,?,?,?,?);"""),
INSERT INTO `%saved_positions_table%`
(`position_id`, `name`, `description`, `tags`, `timestamp`)
VALUES
(?,?,?,?,?);"""),
Statement.RETURN_GENERATED_KEYS)) {
statement.setInt(1, setPosition(position, connection));
@@ -190,7 +203,8 @@ public class MySqlDatabase extends Database {
}
@Override
protected void updateSavedPosition(int savedPositionId, @NotNull SavedPosition position, @NotNull Connection connection) throws SQLException {
protected void updateSavedPosition(int savedPositionId, @NotNull SavedPosition position,
@NotNull Connection connection) throws SQLException {
try (PreparedStatement selectStatement = connection.prepareStatement(formatStatementTables("""
SELECT `position_id`
FROM `%saved_positions_table%`
@@ -220,7 +234,8 @@ public class MySqlDatabase extends Database {
@Override
public void ensureUser(@NotNull User onlineUser) {
getUserData(onlineUser.getUuid()).ifPresentOrElse(existingUserData -> {
getUserData(onlineUser.getUuid()).ifPresentOrElse(
existingUserData -> {
if (!existingUserData.getUsername().equals(onlineUser.getUsername())) {
// Update a player's name if it has changed in the database
try (Connection connection = getConnection()) {
@@ -233,7 +248,9 @@ public class MySqlDatabase extends Database {
statement.setString(2, existingUserData.getUserUuid().toString());
statement.executeUpdate();
}
plugin.log(Level.INFO, "Updated " + onlineUser.getUsername() + "'s name in the database (" + existingUserData.getUsername() + " -> " + onlineUser.getUsername() + ")");
plugin.log(Level.INFO, "Updated " + onlineUser.getUsername()
+ "'s name in the database (" + existingUserData.getUsername()
+ " -> " + onlineUser.getUsername() + ")");
} catch (SQLException e) {
plugin.log(Level.SEVERE, "Failed to update a player's name on the database", e);
}
@@ -331,7 +348,8 @@ public class MySqlDatabase extends Database {
}
@Override
public void setCooldown(@NotNull TransactionResolver.Action action, @NotNull User user, @NotNull Instant cooldownExpiry) {
public void setCooldown(@NotNull TransactionResolver.Action action, @NotNull User user,
@NotNull Instant cooldownExpiry) {
try (Connection connection = getConnection()) {
try (PreparedStatement statement = connection.prepareStatement(formatStatementTables("""
INSERT INTO `%cooldowns_table%` (`player_uuid`, `type`, `start_timestamp`, `end_timestamp`)
@@ -368,11 +386,15 @@ public class MySqlDatabase extends Database {
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`, `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`, `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`
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`=?
ORDER BY `name`;"""))) {
@@ -408,10 +430,13 @@ public class MySqlDatabase extends Database {
final List<Warp> warps = new ArrayList<>();
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`
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`
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`
ORDER BY `name`;"""))) {
final ResultSet resultSet = statement.executeQuery();
@@ -442,14 +467,18 @@ public class MySqlDatabase extends Database {
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`
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`
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
ORDER BY `name`;"""))) {
final ResultSet resultSet = statement.executeQuery();
while (resultSet.next()) {
userHomes.add(Home.from(resultSet.getDouble("x"),
@@ -480,11 +509,16 @@ public class MySqlDatabase extends Database {
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`
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`
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`=?
AND ((? AND UPPER(`name`) LIKE UPPER(?)) OR (`name`=?))"""))) {
statement.setString(1, user.getUuid().toString());
@@ -521,11 +555,16 @@ public class MySqlDatabase extends Database {
public Optional<Home> getHome(@NotNull UUID uuid) {
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`
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`
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 `%homes_table%`.`uuid`=?;"""))) {
statement.setString(1, uuid.toString());
@@ -559,10 +598,13 @@ public class MySqlDatabase extends Database {
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`
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`
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`
AND ((? AND UPPER(`name`) LIKE UPPER(?)) OR (`name`=?))"""))) {
statement.setBoolean(1, caseInsensitive);
statement.setString(2, warpName);
@@ -595,10 +637,13 @@ public class MySqlDatabase extends Database {
public Optional<Warp> getWarp(@NotNull UUID uuid) {
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`
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`
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 `%warps_table%`.uuid=?;"""))) {
statement.setString(1, uuid.toString());
@@ -675,7 +720,7 @@ public class MySqlDatabase extends Database {
statement.executeUpdate();
}
} catch (SQLException e) {
plugin.log(Level.SEVERE, "Failed to update user data for " + savedUser.getUsername() + " on the database", e);
plugin.log(Level.SEVERE, "Failed to update user data for " + savedUser.getUsername(), e);
}
}
@@ -39,23 +39,23 @@ import java.util.*;
import java.util.logging.Level;
/**
* An SQLite implementation of the plugin {@link Database}
* An SQLite implementation of the plugin {@link Database}.
*/
@SuppressWarnings("DuplicatedCode")
public class SqLiteDatabase extends Database {
/**
* Path to the SQLite HuskHomesData.db file
* Path to the SQLite HuskHomesData.db file.
*/
private final File databaseFile;
/**
* The name of the database file
* The name of the database file.
*/
private static final String DATABASE_FILE_NAME = "HuskHomesData.db";
/**
* The persistent SQLite database connection
* The persistent SQLite database connection.
*/
private Connection connection;
@@ -91,7 +91,9 @@ public class SqLiteDatabase extends Database {
config.setSynchronous(SQLiteConfig.SynchronousMode.FULL);
// Establish the connection
connection = DriverManager.getConnection("jdbc:sqlite:" + databaseFile.getAbsolutePath(), config.toProperties());
connection = DriverManager.getConnection(
"jdbc:sqlite:" + databaseFile.getAbsolutePath(), config.toProperties()
);
} catch (IOException e) {
plugin.log(Level.SEVERE, "An exception occurred creating the database file", e);
} catch (SQLException e) {
@@ -123,8 +125,10 @@ public class SqLiteDatabase extends Database {
@Override
protected int setPosition(@NotNull Position position, @NotNull Connection connection) throws SQLException {
try (PreparedStatement statement = getConnection().prepareStatement(formatStatementTables("""
INSERT INTO `%positions_table%` (`x`,`y`,`z`,`yaw`,`pitch`,`world_name`,`world_uuid`,`server_name`)
VALUES (?,?,?,?,?,?,?,?);"""),
INSERT INTO `%positions_table%`
(`x`,`y`,`z`,`yaw`,`pitch`,`world_name`,`world_uuid`,`server_name`)
VALUES
(?,?,?,?,?,?,?,?);"""),
Statement.RETURN_GENERATED_KEYS)) {
statement.setDouble(1, position.getX());
@@ -148,7 +152,8 @@ public class SqLiteDatabase extends Database {
}
@Override
protected void updatePosition(int positionId, @NotNull Position position, @NotNull Connection connection) throws SQLException {
protected void updatePosition(int positionId, @NotNull Position position,
@NotNull Connection connection) throws SQLException {
try (PreparedStatement statement = connection.prepareStatement(formatStatementTables("""
UPDATE `%positions_table%`
SET `x`=?,
@@ -174,10 +179,13 @@ public class SqLiteDatabase extends Database {
}
@Override
protected int setSavedPosition(@NotNull SavedPosition position, @NotNull Connection connection) throws SQLException {
protected int setSavedPosition(@NotNull SavedPosition position,
@NotNull Connection connection) throws SQLException {
try (PreparedStatement statement = connection.prepareStatement(formatStatementTables("""
INSERT INTO `%saved_positions_table%` (`position_id`, `name`, `description`, `tags`, `timestamp`)
VALUES (?,?,?,?,?);"""),
INSERT INTO `%saved_positions_table%`
(`position_id`, `name`, `description`, `tags`, `timestamp`)
VALUES
(?,?,?,?,?);"""),
Statement.RETURN_GENERATED_KEYS)) {
statement.setInt(1, setPosition(position, connection));
@@ -198,7 +206,8 @@ public class SqLiteDatabase extends Database {
}
@Override
protected void updateSavedPosition(int savedPositionId, @NotNull SavedPosition position, @NotNull Connection connection) throws SQLException {
protected void updateSavedPosition(int savedPositionId, @NotNull SavedPosition position,
@NotNull Connection connection) throws SQLException {
try (PreparedStatement selectStatement = connection.prepareStatement(formatStatementTables("""
SELECT `position_id`
FROM `%saved_positions_table%`
@@ -228,7 +237,8 @@ public class SqLiteDatabase extends Database {
@Override
public void ensureUser(@NotNull User onlineUser) {
getUserData(onlineUser.getUuid()).ifPresentOrElse(existingUser -> {
getUserData(onlineUser.getUuid()).ifPresentOrElse(
existingUser -> {
if (!existingUser.getUsername().equals(onlineUser.getUsername())) {
// Update a player's name if it has changed in the database
try (PreparedStatement statement = getConnection().prepareStatement(formatStatementTables("""
@@ -239,7 +249,9 @@ public class SqLiteDatabase extends Database {
statement.setString(1, onlineUser.getUsername());
statement.setString(2, existingUser.getUserUuid().toString());
statement.executeUpdate();
plugin.log(Level.INFO, "Updated " + onlineUser.getUsername() + "'s name in the database (" + existingUser.getUsername() + " -> " + onlineUser.getUsername() + ")");
plugin.log(Level.INFO, "Updated " + onlineUser.getUsername()
+ "'s name in the database (" + existingUser.getUsername()
+ " -> " + onlineUser.getUsername() + ")");
} catch (SQLException e) {
plugin.log(Level.SEVERE, "Failed to update a player's name on the database", e);
}
@@ -343,7 +355,8 @@ public class SqLiteDatabase extends Database {
}
@Override
public void setCooldown(@NotNull TransactionResolver.Action action, @NotNull User user, @NotNull Instant cooldownExpiry) {
public void setCooldown(@NotNull TransactionResolver.Action action, @NotNull User user,
@NotNull Instant cooldownExpiry) {
try (PreparedStatement statement = getConnection().prepareStatement(formatStatementTables("""
INSERT INTO `%cooldowns_table%` (`player_uuid`, `type`, `start_timestamp`, `end_timestamp`)
VALUES (?,?,?,?);"""))) {
@@ -361,11 +374,15 @@ public class SqLiteDatabase extends Database {
public List<Home> getHomes(@NotNull User user) {
final List<Home> userHomes = new ArrayList<>();
try (PreparedStatement statement = getConnection().prepareStatement(formatStatementTables("""
SELECT `%homes_table%`.`uuid` AS `home_uuid`, `owner_uuid`, `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`, `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`
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`=?
ORDER BY `name`;"""))) {
statement.setString(1, user.getUuid().toString());
@@ -399,12 +416,14 @@ public class SqLiteDatabase extends Database {
public List<Warp> getWarps() {
final List<Warp> warps = new ArrayList<>();
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%`
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 `%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`
ORDER BY `name`;"""))) {
final ResultSet resultSet = statement.executeQuery();
while (resultSet.next()) {
warps.add(Warp.from(resultSet.getDouble("x"),
@@ -431,14 +450,18 @@ public class SqLiteDatabase extends Database {
public List<Home> getPublicHomes() {
final List<Home> userHomes = new ArrayList<>();
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`
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`
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
ORDER BY `name`;"""))) {
final ResultSet resultSet = statement.executeQuery();
while (resultSet.next()) {
userHomes.add(Home.from(resultSet.getDouble("x"),
@@ -468,11 +491,16 @@ public class SqLiteDatabase extends Database {
@Override
public Optional<Home> getHome(@NotNull User user, @NotNull String homeName, boolean caseInsensitive) {
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`
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`
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`=?
AND ((? AND UPPER(`name`) LIKE UPPER(?)) OR (`name`=?))"""))) {
statement.setString(1, user.getUuid().toString());
@@ -507,11 +535,16 @@ public class SqLiteDatabase extends Database {
@Override
public Optional<Home> getHome(@NotNull UUID uuid) {
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`
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`
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 `%homes_table%`.`uuid`=?;"""))) {
statement.setString(1, uuid.toString());
@@ -543,10 +576,13 @@ public class SqLiteDatabase extends Database {
@Override
public Optional<Warp> getWarp(@NotNull String warpName, boolean caseInsensitive) {
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%`
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 `%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`
AND ((? AND UPPER(`name`) LIKE UPPER(?)) OR (`name`=?))"""))) {
statement.setBoolean(1, caseInsensitive);
statement.setString(2, warpName);
@@ -577,10 +613,13 @@ public class SqLiteDatabase extends Database {
@Override
public Optional<Warp> getWarp(@NotNull UUID uuid) {
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%`
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 `%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 `%warps_table%`.uuid=?;"""))) {
statement.setString(1, uuid.toString());
@@ -652,7 +691,7 @@ public class SqLiteDatabase extends Database {
statement.setString(3, savedUser.getUserUuid().toString());
statement.executeUpdate();
} catch (SQLException e) {
plugin.log(Level.SEVERE, "Failed to update user data for " + savedUser.getUsername() + " on the database", e);
plugin.log(Level.SEVERE, "Failed to update user data for " + savedUser.getUsername(), e);
}
}