mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 22:17:17 +00:00
Add metadata tag Maps to PositionMeta for API integrations
This commit is contained in:
1 parent
9d80d455f2
commit
0ee8c97a6e
3 files changed
+100
-39
No files matched your search
@@ -174,14 +174,15 @@ public class MySqlDatabase extends Database {
|
||||
@Override
|
||||
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`, `timestamp`)
|
||||
VALUES (?,?,?,?);"""),
|
||||
INSERT INTO `%saved_positions_table%` (`position_id`, `name`, `description`, `tags`, `timestamp`)
|
||||
VALUES (?,?,?,?,?);"""),
|
||||
Statement.RETURN_GENERATED_KEYS)) {
|
||||
|
||||
statement.setInt(1, setPosition(position, connection));
|
||||
statement.setString(2, position.meta.name);
|
||||
statement.setString(3, position.meta.description);
|
||||
statement.setTimestamp(4, Timestamp.from(position.meta.creationTime));
|
||||
statement.setString(4, position.meta.getSerializedTags());
|
||||
statement.setTimestamp(5, Timestamp.from(position.meta.creationTime));
|
||||
statement.executeUpdate();
|
||||
|
||||
final ResultSet resultSet = statement.getGeneratedKeys();
|
||||
@@ -208,11 +209,13 @@ public class MySqlDatabase extends Database {
|
||||
try (PreparedStatement updateStatement = connection.prepareStatement(formatStatementTables("""
|
||||
UPDATE `%saved_positions_table%`
|
||||
SET `name`=?,
|
||||
`description`=?
|
||||
`description`=?,
|
||||
`tags`=?
|
||||
WHERE `id`=?;"""))) {
|
||||
updateStatement.setString(1, position.meta.name);
|
||||
updateStatement.setString(2, position.meta.description);
|
||||
updateStatement.setInt(3, savedPositionId);
|
||||
updateStatement.setString(3, position.meta.getSerializedTags());
|
||||
updateStatement.setInt(4, savedPositionId);
|
||||
updateStatement.executeUpdate();
|
||||
}
|
||||
}
|
||||
@@ -319,7 +322,7 @@ 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`, `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`
|
||||
@@ -341,7 +344,8 @@ public class MySqlDatabase extends Database {
|
||||
new Server(resultSet.getString("server_name")),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant()),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
resultSet.getString("tags")),
|
||||
UUID.fromString(resultSet.getString("home_uuid")),
|
||||
user,
|
||||
resultSet.getBoolean("public")));
|
||||
@@ -360,7 +364,7 @@ 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`, `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`
|
||||
@@ -378,7 +382,8 @@ public class MySqlDatabase extends Database {
|
||||
new Server(resultSet.getString("server_name")),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant()),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
resultSet.getString("tags")),
|
||||
UUID.fromString(resultSet.getString("warp_uuid"))));
|
||||
}
|
||||
}
|
||||
@@ -395,7 +400,7 @@ 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`, `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`
|
||||
@@ -415,7 +420,8 @@ public class MySqlDatabase extends Database {
|
||||
new Server(resultSet.getString("server_name")),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant()),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
resultSet.getString("tags")),
|
||||
UUID.fromString(resultSet.getString("home_uuid")),
|
||||
new User(UUID.fromString(resultSet.getString("owner_uuid")),
|
||||
resultSet.getString("owner_username")),
|
||||
@@ -434,7 +440,7 @@ public class MySqlDatabase extends Database {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
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`, `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`
|
||||
@@ -456,7 +462,8 @@ public class MySqlDatabase extends Database {
|
||||
new Server(resultSet.getString("server_name")),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant()),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
resultSet.getString("tags")),
|
||||
UUID.fromString(resultSet.getString("home_uuid")),
|
||||
new User(UUID.fromString(resultSet.getString("owner_uuid")),
|
||||
resultSet.getString("owner_username")),
|
||||
@@ -477,7 +484,7 @@ public class MySqlDatabase extends Database {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
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`, `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`
|
||||
@@ -497,7 +504,8 @@ public class MySqlDatabase extends Database {
|
||||
new Server(resultSet.getString("server_name")),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant()),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
resultSet.getString("tags")),
|
||||
UUID.fromString(resultSet.getString("home_uuid")),
|
||||
new User(UUID.fromString(resultSet.getString("owner_uuid")),
|
||||
resultSet.getString("owner_username")),
|
||||
@@ -516,7 +524,7 @@ public class MySqlDatabase extends Database {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
try (Connection connection = getConnection()) {
|
||||
try (PreparedStatement statement = connection.prepareStatement(formatStatementTables("""
|
||||
SELECT `%warps_table%`.`uuid` AS `warp_uuid`, `name`, `description`, `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`
|
||||
@@ -535,7 +543,8 @@ public class MySqlDatabase extends Database {
|
||||
new Server(resultSet.getString("server_name")),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant()),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
resultSet.getString("tags")),
|
||||
UUID.fromString(resultSet.getString("warp_uuid"))));
|
||||
}
|
||||
}
|
||||
@@ -551,7 +560,7 @@ public class MySqlDatabase extends Database {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
try (Connection connection = getConnection()) {
|
||||
try (PreparedStatement statement = connection.prepareStatement(formatStatementTables("""
|
||||
SELECT `%warps_table%`.`uuid` AS `warp_uuid`, `name`, `description`, `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`
|
||||
@@ -570,7 +579,8 @@ public class MySqlDatabase extends Database {
|
||||
new Server(resultSet.getString("server_name")),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant()),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
resultSet.getString("tags")),
|
||||
UUID.fromString(resultSet.getString("warp_uuid"))));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,14 +190,15 @@ public class SqLiteDatabase extends Database {
|
||||
@Override
|
||||
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`, `timestamp`)
|
||||
VALUES (?,?,?,?);"""),
|
||||
INSERT INTO `%saved_positions_table%` (`position_id`, `name`, `description`, `tags`, `timestamp`)
|
||||
VALUES (?,?,?,?,?);"""),
|
||||
Statement.RETURN_GENERATED_KEYS)) {
|
||||
|
||||
statement.setInt(1, setPosition(position, connection));
|
||||
statement.setString(2, position.meta.name);
|
||||
statement.setString(3, position.meta.description);
|
||||
statement.setTimestamp(4, Timestamp.from(position.meta.creationTime));
|
||||
statement.setString(4, position.meta.getSerializedTags());
|
||||
statement.setTimestamp(5, Timestamp.from(position.meta.creationTime));
|
||||
statement.executeUpdate();
|
||||
|
||||
// Return the ID of the newly inserted row
|
||||
@@ -226,11 +227,13 @@ public class SqLiteDatabase extends Database {
|
||||
try (PreparedStatement updateStatement = connection.prepareStatement(formatStatementTables("""
|
||||
UPDATE `%saved_positions_table%`
|
||||
SET `name`=?,
|
||||
`description`=?
|
||||
`description`=?,
|
||||
`tags`=?
|
||||
WHERE `id`=?;"""))) {
|
||||
updateStatement.setString(1, position.meta.name);
|
||||
updateStatement.setString(2, position.meta.description);
|
||||
updateStatement.setInt(3, savedPositionId);
|
||||
updateStatement.setString(3, position.meta.getSerializedTags());
|
||||
updateStatement.setInt(4, savedPositionId);
|
||||
updateStatement.executeUpdate();
|
||||
}
|
||||
}
|
||||
@@ -337,7 +340,7 @@ public class SqLiteDatabase extends Database {
|
||||
final List<Home> userHomes = new ArrayList<>();
|
||||
try {
|
||||
try (PreparedStatement statement = getConnection().prepareStatement(formatStatementTables("""
|
||||
SELECT `%homes_table%`.`uuid` AS `home_uuid`, `owner_uuid`, `name`, `description`, `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`
|
||||
@@ -359,7 +362,8 @@ public class SqLiteDatabase extends Database {
|
||||
new Server(resultSet.getString("server_name")),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant()),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
resultSet.getString("tags")),
|
||||
UUID.fromString(resultSet.getString("home_uuid")),
|
||||
user,
|
||||
resultSet.getBoolean("public")));
|
||||
@@ -378,7 +382,7 @@ public class SqLiteDatabase extends Database {
|
||||
final List<Warp> warps = new ArrayList<>();
|
||||
try {
|
||||
try (PreparedStatement statement = getConnection().prepareStatement(formatStatementTables("""
|
||||
SELECT `%warps_table%`.`uuid` AS `warp_uuid`, `name`, `description`, `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`
|
||||
@@ -396,7 +400,8 @@ public class SqLiteDatabase extends Database {
|
||||
new Server(resultSet.getString("server_name")),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant()),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
resultSet.getString("tags")),
|
||||
UUID.fromString(resultSet.getString("warp_uuid"))));
|
||||
}
|
||||
}
|
||||
@@ -413,7 +418,7 @@ public class SqLiteDatabase extends Database {
|
||||
final List<Home> userHomes = new ArrayList<>();
|
||||
try {
|
||||
try (PreparedStatement statement = getConnection().prepareStatement(formatStatementTables("""
|
||||
SELECT `%homes_table%`.`uuid` AS `home_uuid`, `owner_uuid`, `username` AS `owner_username`, `name`, `description`, `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`
|
||||
@@ -433,7 +438,8 @@ public class SqLiteDatabase extends Database {
|
||||
new Server(resultSet.getString("server_name")),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant()),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
resultSet.getString("tags")),
|
||||
UUID.fromString(resultSet.getString("home_uuid")),
|
||||
new User(UUID.fromString(resultSet.getString("owner_uuid")),
|
||||
resultSet.getString("owner_username")),
|
||||
@@ -452,7 +458,7 @@ public class SqLiteDatabase extends Database {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
try (PreparedStatement statement = getConnection().prepareStatement(formatStatementTables("""
|
||||
SELECT `%homes_table%`.`uuid` AS `home_uuid`, `owner_uuid`, `username` AS `owner_username`, `name`, `description`, `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`
|
||||
@@ -474,7 +480,8 @@ public class SqLiteDatabase extends Database {
|
||||
new Server(resultSet.getString("server_name")),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant()),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
resultSet.getString("tags")),
|
||||
UUID.fromString(resultSet.getString("home_uuid")),
|
||||
new User(UUID.fromString(resultSet.getString("owner_uuid")),
|
||||
resultSet.getString("owner_username")),
|
||||
@@ -493,7 +500,7 @@ public class SqLiteDatabase extends Database {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
try (PreparedStatement statement = getConnection().prepareStatement(formatStatementTables("""
|
||||
SELECT `%homes_table%`.`uuid` AS `home_uuid`, `owner_uuid`, `username` AS `owner_username`, `name`, `description`, `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`
|
||||
@@ -513,7 +520,8 @@ public class SqLiteDatabase extends Database {
|
||||
new Server(resultSet.getString("server_name")),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant()),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
resultSet.getString("tags")),
|
||||
UUID.fromString(resultSet.getString("home_uuid")),
|
||||
new User(UUID.fromString(resultSet.getString("owner_uuid")),
|
||||
resultSet.getString("owner_username")),
|
||||
@@ -532,7 +540,7 @@ public class SqLiteDatabase extends Database {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
try (PreparedStatement statement = getConnection().prepareStatement(formatStatementTables("""
|
||||
SELECT `%warps_table%`.`uuid` AS `warp_uuid`, `name`, `description`, `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`
|
||||
@@ -551,7 +559,8 @@ public class SqLiteDatabase extends Database {
|
||||
new Server(resultSet.getString("server_name")),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant()),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
resultSet.getString("tags")),
|
||||
UUID.fromString(resultSet.getString("warp_uuid"))));
|
||||
}
|
||||
}
|
||||
@@ -567,7 +576,7 @@ public class SqLiteDatabase extends Database {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
try (PreparedStatement statement = getConnection().prepareStatement(formatStatementTables("""
|
||||
SELECT `%warps_table%`.`uuid` AS `warp_uuid`, `name`, `description`, `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`
|
||||
@@ -586,7 +595,8 @@ public class SqLiteDatabase extends Database {
|
||||
new Server(resultSet.getString("server_name")),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant()),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
resultSet.getString("tags")),
|
||||
UUID.fromString(resultSet.getString("warp_uuid"))));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
package net.william278.huskhomes.position;
|
||||
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.gson.Gson;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Represents metadata about a {@link Position}, used in {@link SavedPosition} implementations
|
||||
@@ -21,22 +26,58 @@ public class PositionMeta {
|
||||
@NotNull
|
||||
public String description;
|
||||
|
||||
/**
|
||||
* Map of metadata tags for a position
|
||||
*/
|
||||
@NotNull
|
||||
public Map<String, String> tags;
|
||||
|
||||
/**
|
||||
* The time the position was created
|
||||
*/
|
||||
@NotNull
|
||||
public Instant creationTime;
|
||||
|
||||
public PositionMeta(@NotNull String name, @NotNull String description, @NotNull Instant creationTime) {
|
||||
public PositionMeta(@NotNull String name, @NotNull String description, @NotNull Instant creationTime,
|
||||
@Nullable String serializedTags) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.creationTime = creationTime;
|
||||
this.tags = deserializeTags(serializedTags);
|
||||
}
|
||||
|
||||
public PositionMeta(@NotNull String name, @NotNull String description) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.creationTime = Instant.now();
|
||||
this.tags = new HashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize a JSON string into a {@link Map} of meta tags
|
||||
*
|
||||
* @param serializedTags The JSON string to deserialize
|
||||
* @return The deserialized {@link Map}
|
||||
*/
|
||||
private static Map<String, String> deserializeTags(@Nullable String serializedTags) {
|
||||
if (serializedTags == null || serializedTags.isBlank()) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
return new Gson().fromJson(serializedTags, new TypeToken<Map<String, String>>() {
|
||||
}.getType());
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize a {@link Map} of meta tags into a JSON string
|
||||
*
|
||||
* @return The serialized JSON string
|
||||
*/
|
||||
@Nullable
|
||||
public String getSerializedTags() {
|
||||
if (tags.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return new Gson().toJson(tags);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user