From a344da4f3e4a569c9c5cb3af8f498d30bb5c3078 Mon Sep 17 00:00:00 2001 From: Thorinwasher Date: Sun, 21 Jan 2024 11:30:08 +0100 Subject: [PATCH] Fix build issues and test failures --- src/main/java/org/sgrewritten/stargate/Stargate.java | 6 +++--- .../org/sgrewritten/stargate/database/SQLDatabase.java | 3 ++- .../resources/database/sqlite-queries/DELETE_GATE_FORMAT | 0 .../database/sqlite-queries/DELETE_GATE_FORMAT.sql | 2 ++ .../database/sqlite-queries/DELETE_INTER_GATE_FORMAT.sql | 2 ++ .../database/sqlite-queries/DELETTE_INTER_GATE_FORMAT.sql | 0 .../org/sgrewritten/stargate/database/StorageMock.java | 7 +++++++ 7 files changed, 16 insertions(+), 4 deletions(-) delete mode 100644 src/main/resources/database/sqlite-queries/DELETE_GATE_FORMAT create mode 100644 src/main/resources/database/sqlite-queries/DELETE_GATE_FORMAT.sql create mode 100644 src/main/resources/database/sqlite-queries/DELETE_INTER_GATE_FORMAT.sql delete mode 100644 src/main/resources/database/sqlite-queries/DELETTE_INTER_GATE_FORMAT.sql diff --git a/src/main/java/org/sgrewritten/stargate/Stargate.java b/src/main/java/org/sgrewritten/stargate/Stargate.java index f42d484f9..d32bc2132 100644 --- a/src/main/java/org/sgrewritten/stargate/Stargate.java +++ b/src/main/java/org/sgrewritten/stargate/Stargate.java @@ -210,10 +210,10 @@ private void sendWarningMessages() { Stargate.log(e); } } - long scheduledGateClearing = Long.parseLong(storedProperties.getProperty(StoredProperty.SCHEDULED_GATE_CLEARING)); - if(scheduledGateClearing < System.currentTimeMillis()){ + String scheduledGateClearingString = storedProperties.getProperty(StoredProperty.SCHEDULED_GATE_CLEARING); + if(scheduledGateClearingString != null && Long.parseLong(scheduledGateClearingString) < System.currentTimeMillis()){ try(InputStream inputStream = Stargate.class.getResourceAsStream("/messages/")){ - Date date = new Date(scheduledGateClearing); + Date date = new Date(Long.parseLong(scheduledGateClearingString)); String dateString = date.toString(); String unformattedMessage = FileHelper.readStreamToString(inputStream); String message = unformattedMessage.replace("%time%",dateString); diff --git a/src/main/java/org/sgrewritten/stargate/database/SQLDatabase.java b/src/main/java/org/sgrewritten/stargate/database/SQLDatabase.java index a5eb4d509..e94d60cc9 100644 --- a/src/main/java/org/sgrewritten/stargate/database/SQLDatabase.java +++ b/src/main/java/org/sgrewritten/stargate/database/SQLDatabase.java @@ -229,7 +229,8 @@ private void loadAllPortals(SQLDatabaseAPI database, StorageType portalType, Sta statement.close(); } removeWorlds(worldsToRemove, portalType); - if (Long.parseLong(propertiesDatabase.getProperty(StoredProperty.SCHEDULED_GATE_CLEARING)) > System.currentTimeMillis()) { + String scheduledGateFormatClearing = propertiesDatabase.getProperty(StoredProperty.SCHEDULED_GATE_CLEARING); + if (scheduledGateFormatClearing != null && Long.parseLong(scheduledGateFormatClearing) > System.currentTimeMillis()) { removeGateFormats(gateFormatsToRemove, portalType); } else { invalidGateFormats.addAll(gateFormatsToRemove); diff --git a/src/main/resources/database/sqlite-queries/DELETE_GATE_FORMAT b/src/main/resources/database/sqlite-queries/DELETE_GATE_FORMAT deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/main/resources/database/sqlite-queries/DELETE_GATE_FORMAT.sql b/src/main/resources/database/sqlite-queries/DELETE_GATE_FORMAT.sql new file mode 100644 index 000000000..6cf5d4dd1 --- /dev/null +++ b/src/main/resources/database/sqlite-queries/DELETE_GATE_FORMAT.sql @@ -0,0 +1,2 @@ +DELETE FROM {Portal} +WHERE gateFileName = ?; \ No newline at end of file diff --git a/src/main/resources/database/sqlite-queries/DELETE_INTER_GATE_FORMAT.sql b/src/main/resources/database/sqlite-queries/DELETE_INTER_GATE_FORMAT.sql new file mode 100644 index 000000000..672df3a8b --- /dev/null +++ b/src/main/resources/database/sqlite-queries/DELETE_INTER_GATE_FORMAT.sql @@ -0,0 +1,2 @@ +DELETE FROM {InterPortal} +WHERE gateFileName = ? AND homeServerId = ?; \ No newline at end of file diff --git a/src/main/resources/database/sqlite-queries/DELETTE_INTER_GATE_FORMAT.sql b/src/main/resources/database/sqlite-queries/DELETTE_INTER_GATE_FORMAT.sql deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/test/java/org/sgrewritten/stargate/database/StorageMock.java b/src/test/java/org/sgrewritten/stargate/database/StorageMock.java index 20898b911..5f5ddf75a 100644 --- a/src/test/java/org/sgrewritten/stargate/database/StorageMock.java +++ b/src/test/java/org/sgrewritten/stargate/database/StorageMock.java @@ -15,6 +15,8 @@ import org.sgrewritten.stargate.network.StorageType; import org.sgrewritten.stargate.network.portal.GlobalPortalId; +import java.util.HashSet; +import java.util.Set; import java.util.Stack; public class StorageMock implements StorageAPI { @@ -127,4 +129,9 @@ public boolean netWorkExists(String netName, StorageType portalType) { return false; } + @Override + public Set getScheduledGatesClearing() { + return new HashSet<>(); + } + }