mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-03 14:38:53 +00:00
Refactoring, improve database system and add creation timestamp to homes and warps
This commit is contained in:
1 parent
58eeab20c5
commit
98893814f7
24 files changed
+549
-657
No files matched your search
@@ -17,6 +17,7 @@ import org.bukkit.configuration.file.FileConfiguration;
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.time.Instant;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
@@ -94,7 +95,7 @@ public class EssentialsMigrator {
|
||||
continue;
|
||||
}
|
||||
DataManager.addHome(new Home(new TeleportationPoint(worldID, x, y, z, yaw, pitch, targetServer),
|
||||
playerName, playerUUID, homeName, homeDescription, false), playerUUID, connection);
|
||||
playerName, playerUUID, homeName, homeDescription, false, Instant.now().getEpochSecond()), playerUUID, connection);
|
||||
|
||||
plugin.getLogger().info("→ Migrated home " + homeName);
|
||||
} catch (NullPointerException | IllegalArgumentException e) {
|
||||
@@ -152,7 +153,7 @@ public class EssentialsMigrator {
|
||||
}
|
||||
|
||||
DataManager.addWarp(new Warp(new TeleportationPoint(worldID, x, y, z, yaw, pitch, targetServer),
|
||||
warpName, MessageManager.getRawMessage("warp_default_description")), connection);
|
||||
warpName, MessageManager.getRawMessage("warp_default_description"), Instant.now().getEpochSecond()), connection);
|
||||
plugin.getLogger().info("→ Migrated warp " + warpName);
|
||||
} catch (NullPointerException | IllegalArgumentException e) {
|
||||
plugin.getLogger().warning("✖ Failed to migrate warp " + warpFile.getName());
|
||||
|
||||
@@ -5,7 +5,8 @@ import org.bukkit.Bukkit;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Level;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.Instant;
|
||||
|
||||
public class UpgradeDatabase {
|
||||
|
||||
@@ -35,6 +36,36 @@ public class UpgradeDatabase {
|
||||
}
|
||||
});
|
||||
}
|
||||
if (plugin.getConfig().getInt("config_file_version", 1) <= 6) {
|
||||
plugin.getLogger().info("Detected that the database might need updating. Running database upgrade...");
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try (PreparedStatement tableUpdateStatement = HuskHomes.getConnection().prepareStatement(
|
||||
"ALTER TABLE " + HuskHomes.getSettings().getHomesDataTable()
|
||||
+ " ADD `creation_time` timestamp NOT NULL DEFAULT ?;")) {
|
||||
tableUpdateStatement.setTimestamp(1, new Timestamp(Instant.now().getEpochSecond()));
|
||||
tableUpdateStatement.executeUpdate();
|
||||
plugin.getLogger().info("Database update complete!");
|
||||
} catch (SQLException e) {
|
||||
plugin.getLogger().info("Skipped performing the database upgrade: " + e.getCause() + ". This might be because another server on your HuskHomes network already carried out the upgrade - in which case you can safely ignore this warning.");
|
||||
} finally {
|
||||
try (PreparedStatement tableUpdateStatement = HuskHomes.getConnection().prepareStatement(
|
||||
"ALTER TABLE " + HuskHomes.getSettings().getWarpsDataTable()
|
||||
+ " ADD `creation_time` timestamp NOT NULL DEFAULT ?;")) {
|
||||
tableUpdateStatement.setTimestamp(1, new Timestamp(Instant.now().getEpochSecond()));
|
||||
tableUpdateStatement.executeUpdate();
|
||||
plugin.getLogger().info("Database update complete!");
|
||||
} catch (SQLException e) {
|
||||
plugin.getLogger().info("Skipped performing the database upgrade: " + e.getCause() + ". This might be because another server on your HuskHomes network already carried out the upgrade - in which case you can safely ignore this warning.");
|
||||
} finally {
|
||||
// Update the config file version
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
plugin.getConfig().set("config_file_version", 8);
|
||||
plugin.saveConfig();
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user