mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 14:38:53 +00:00
Fix updating home privacy not working on SQLite
This commit is contained in:
1 parent
7a63e8c173
commit
a5d8b6ff35
3 files changed
+22
-1
No files matched your search
@@ -905,6 +905,7 @@ public class SqLiteDatabase extends Database {
|
|||||||
return CompletableFuture.runAsync(() -> getHome(home.uuid)
|
return CompletableFuture.runAsync(() -> getHome(home.uuid)
|
||||||
.thenAccept(existingHome -> existingHome.ifPresentOrElse(presentHome -> {
|
.thenAccept(existingHome -> existingHome.ifPresentOrElse(presentHome -> {
|
||||||
try {
|
try {
|
||||||
|
// Update the home's saved position, including metadata
|
||||||
try (PreparedStatement statement = getConnection().prepareStatement(formatStatementTables("""
|
try (PreparedStatement statement = getConnection().prepareStatement(formatStatementTables("""
|
||||||
SELECT `saved_position_id` FROM `%homes_table%`
|
SELECT `saved_position_id` FROM `%homes_table%`
|
||||||
WHERE `uuid`=?;"""))) {
|
WHERE `uuid`=?;"""))) {
|
||||||
@@ -915,6 +916,16 @@ public class SqLiteDatabase extends Database {
|
|||||||
updateSavedPosition(resultSet.getInt("saved_position_id"), home, connection);
|
updateSavedPosition(resultSet.getInt("saved_position_id"), home, connection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update the home privacy
|
||||||
|
try (PreparedStatement statement = connection.prepareStatement(formatStatementTables("""
|
||||||
|
UPDATE `%homes_table%`
|
||||||
|
SET `public`=?
|
||||||
|
WHERE `uuid`=?;"""))) {
|
||||||
|
statement.setBoolean(1, home.isPublic);
|
||||||
|
statement.setString(2, home.uuid.toString());
|
||||||
|
statement.executeUpdate();
|
||||||
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
getLogger().log(Level.SEVERE,
|
getLogger().log(Level.SEVERE,
|
||||||
"Failed to update a home in the database for " + home.owner.username, e);
|
"Failed to update a home in the database for " + home.owner.username, e);
|
||||||
|
|||||||
@@ -60,11 +60,16 @@ public class PositionMeta {
|
|||||||
* @return The deserialized {@link Map}
|
* @return The deserialized {@link Map}
|
||||||
*/
|
*/
|
||||||
private static Map<String, String> deserializeTags(@Nullable String serializedTags) {
|
private static Map<String, String> deserializeTags(@Nullable String serializedTags) {
|
||||||
|
try {
|
||||||
if (serializedTags == null || serializedTags.isBlank()) {
|
if (serializedTags == null || serializedTags.isBlank()) {
|
||||||
return new HashMap<>();
|
return new HashMap<>();
|
||||||
}
|
}
|
||||||
return new Gson().fromJson(serializedTags, new TypeToken<Map<String, String>>() {
|
return new Gson().fromJson(serializedTags, new TypeToken<Map<String, String>>() {
|
||||||
}.getType());
|
}.getType());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -74,10 +79,15 @@ public class PositionMeta {
|
|||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public String getSerializedTags() {
|
public String getSerializedTags() {
|
||||||
|
try {
|
||||||
if (tags.isEmpty()) {
|
if (tags.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new Gson().toJson(tags);
|
return new Gson().toJson(tags);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -264,7 +264,7 @@ public class SavedPositionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return database.saveHome(home).thenApply(ignored -> {
|
return database.saveHome(home).thenApply(ignored -> {
|
||||||
if (isHomePublic) {
|
if (home.isPublic) {
|
||||||
cache.publicHomes.putIfAbsent(home.owner.username, new ArrayList<>());
|
cache.publicHomes.putIfAbsent(home.owner.username, new ArrayList<>());
|
||||||
cache.publicHomes.get(home.owner.username).add(home.meta.name);
|
cache.publicHomes.get(home.owner.username).add(home.meta.name);
|
||||||
if (mapHook != null) {
|
if (mapHook != null) {
|
||||||
|
|||||||
Reference in new issue
Block a user