mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-03 22:16:34 +00:00
Fully async EssentialsMigrator
This commit is contained in:
1 parent
74fd90c37f
commit
58eeab20c5
2 files changed
+76
-78
No files matched your search
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>me.William278</groupId>
|
<groupId>me.William278</groupId>
|
||||||
<artifactId>HuskHomes</artifactId>
|
<artifactId>HuskHomes</artifactId>
|
||||||
<version>2.7.1</version>
|
<version>2.7.2</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>HuskHomes</name>
|
<name>HuskHomes</name>
|
||||||
|
|||||||
@@ -33,30 +33,30 @@ public class EssentialsMigrator {
|
|||||||
|
|
||||||
// Migrate data from EssentialsX
|
// Migrate data from EssentialsX
|
||||||
public static void migrate(final String worldFilter, final String targetServer) {
|
public static void migrate(final String worldFilter, final String targetServer) {
|
||||||
final File essentialsDataFolder = new File(Bukkit.getWorldContainer() + File.separator + "plugins" + File.separator + "Essentials");
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
|
final File essentialsDataFolder = new File(Bukkit.getWorldContainer() + File.separator + "plugins" + File.separator + "Essentials");
|
||||||
|
|
||||||
if (essentialsDataFolder.exists()) {
|
if (essentialsDataFolder.exists()) {
|
||||||
plugin.getLogger().info("Essentials plugin data found!");
|
plugin.getLogger().info("Essentials plugin data found!");
|
||||||
if (worldFilter != null) {
|
if (worldFilter != null) {
|
||||||
plugin.getLogger().info("Started Filtered Migration from EssentialsX:\n• World to migrate from: " + worldFilter + "\n• Target server: " + targetServer);
|
plugin.getLogger().info("Started Filtered Migration from EssentialsX:\n• World to migrate from: " + worldFilter + "\n• Target server: " + targetServer);
|
||||||
} else {
|
} else {
|
||||||
plugin.getLogger().info("Started Migration from EssentialsX...\n");
|
plugin.getLogger().info("Started Migration from EssentialsX...\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Migrate user data
|
// Migrate user data
|
||||||
File essentialsPlayerDataFolder = new File(Bukkit.getWorldContainer() + File.separator + "plugins" + File.separator + "Essentials" + File.separator + "userdata");
|
File essentialsPlayerDataFolder = new File(Bukkit.getWorldContainer() + File.separator + "plugins" + File.separator + "Essentials" + File.separator + "userdata");
|
||||||
if (essentialsPlayerDataFolder.exists()) {
|
if (essentialsPlayerDataFolder.exists()) {
|
||||||
File[] playerFiles = essentialsPlayerDataFolder.listFiles();
|
File[] playerFiles = essentialsPlayerDataFolder.listFiles();
|
||||||
if (playerFiles != null) {
|
if (playerFiles != null) {
|
||||||
for (File playerFile : playerFiles) {
|
for (File playerFile : playerFiles) {
|
||||||
try {
|
|
||||||
final String fileName = playerFile.getName();
|
|
||||||
final UUID playerUUID = UUID.fromString(fileName.substring(0, fileName.lastIndexOf(".")));
|
|
||||||
FileConfiguration playerFileConfig = loadConfiguration(playerFile);
|
|
||||||
final String playerName = playerFileConfig.getString("last-account-name", playerFileConfig.getString("lastAccountName"));
|
|
||||||
try {
|
try {
|
||||||
Connection connection = HuskHomes.getConnection();
|
final String fileName = playerFile.getName();
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
final UUID playerUUID = UUID.fromString(fileName.substring(0, fileName.lastIndexOf(".")));
|
||||||
|
FileConfiguration playerFileConfig = loadConfiguration(playerFile);
|
||||||
|
final String playerName = playerFileConfig.getString("last-account-name", playerFileConfig.getString("lastAccountName"));
|
||||||
|
try {
|
||||||
|
Connection connection = HuskHomes.getConnection();
|
||||||
try {
|
try {
|
||||||
if (!DataManager.playerExists(playerUUID, connection)) {
|
if (!DataManager.playerExists(playerUUID, connection)) {
|
||||||
DataManager.createPlayer(playerUUID, playerName, connection);
|
DataManager.createPlayer(playerUUID, playerName, connection);
|
||||||
@@ -106,22 +106,20 @@ public class EssentialsMigrator {
|
|||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
plugin.getLogger().log(Level.SEVERE, "An SQL exception occurred migrating Essentials home data.", e);
|
plugin.getLogger().log(Level.SEVERE, "An SQL exception occurred migrating Essentials home data.", e);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
} catch (NullPointerException ignored) { }
|
} catch (NullPointerException ignored) { }
|
||||||
} catch (IllegalArgumentException ignored) { }
|
} catch (IllegalArgumentException ignored) { }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Migrate warps
|
// Migrate warps
|
||||||
File essentialsWarpsFolder = new File(Bukkit.getWorldContainer() + File.separator + "plugins" + File.separator + "Essentials" + File.separator + "warps");
|
File essentialsWarpsFolder = new File(Bukkit.getWorldContainer() + File.separator + "plugins" + File.separator + "Essentials" + File.separator + "warps");
|
||||||
if (essentialsWarpsFolder.exists()) {
|
if (essentialsWarpsFolder.exists()) {
|
||||||
final File[] warpFiles = essentialsWarpsFolder.listFiles();
|
final File[] warpFiles = essentialsWarpsFolder.listFiles();
|
||||||
|
|
||||||
if (warpFiles != null) {
|
if (warpFiles != null) {
|
||||||
Connection connection = HuskHomes.getConnection();
|
Connection connection = HuskHomes.getConnection();
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
|
||||||
for (File warpFile : warpFiles) {
|
for (File warpFile : warpFiles) {
|
||||||
try {
|
try {
|
||||||
final FileConfiguration warpFileConfig = loadConfiguration(warpFile);
|
final FileConfiguration warpFileConfig = loadConfiguration(warpFile);
|
||||||
@@ -163,54 +161,54 @@ public class EssentialsMigrator {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Migrate /spawn position
|
|
||||||
if (TeleportManager.getSpawnLocation() == null && HuskHomes.getSettings().doCrossServerSpawn()) {
|
|
||||||
File essentialsSpawnData = new File(Bukkit.getWorldContainer() + File.separator + "plugins" + File.separator + "Essentials" + File.separator + "spawn.yml");
|
|
||||||
if (essentialsSpawnData.exists()) {
|
|
||||||
plugin.getLogger().info("Migrating /spawn position from Essentials...");
|
|
||||||
|
|
||||||
FileConfiguration spawnConfig = loadConfiguration(essentialsSpawnData);
|
|
||||||
try {
|
|
||||||
String worldID = spawnConfig.getString("spawns.all.world");
|
|
||||||
try {
|
|
||||||
final UUID worldUUID = UUID.fromString(worldID);
|
|
||||||
final World world = Bukkit.getWorld(worldUUID);
|
|
||||||
if (world != null) {
|
|
||||||
worldID = world.getName();
|
|
||||||
} else {
|
|
||||||
plugin.getLogger().warning("✖ Could not migrate the spawn position as the world value was a UUID and is not loaded on this server.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch (IllegalArgumentException ignored) { }
|
|
||||||
if (worldFilter != null) {
|
|
||||||
if (!worldFilter.equalsIgnoreCase(worldID)) {
|
|
||||||
plugin.getLogger().warning("✖ Did not migrate the /spawn position as the world filter did not match.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
final double x = spawnConfig.getDouble("spawns.all.x");
|
|
||||||
final double y = spawnConfig.getDouble("spawns.all.y");
|
|
||||||
final double z = spawnConfig.getDouble("spawns.all.z");
|
|
||||||
final float yaw = (float) spawnConfig.getDouble("spawns.all.yaw");
|
|
||||||
final float pitch = (float) spawnConfig.getDouble("spawns.all.pitch");
|
|
||||||
|
|
||||||
Location spawnLocation = new Location(Bukkit.getWorld(worldID), x, y, z, yaw, pitch);
|
|
||||||
SettingHandler.setSpawnLocation(spawnLocation);
|
|
||||||
plugin.getLogger().info("→ /spawn position has been migrated!\n");
|
|
||||||
} catch (NullPointerException | IllegalArgumentException e) {
|
|
||||||
plugin.getLogger().warning("✖ Failed to migrate the /spawn position.\n");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Migrate /spawn position
|
||||||
|
if (TeleportManager.getSpawnLocation() == null && HuskHomes.getSettings().doCrossServerSpawn()) {
|
||||||
|
File essentialsSpawnData = new File(Bukkit.getWorldContainer() + File.separator + "plugins" + File.separator + "Essentials" + File.separator + "spawn.yml");
|
||||||
|
if (essentialsSpawnData.exists()) {
|
||||||
|
plugin.getLogger().info("Migrating /spawn position from Essentials...");
|
||||||
|
|
||||||
|
FileConfiguration spawnConfig = loadConfiguration(essentialsSpawnData);
|
||||||
|
try {
|
||||||
|
String worldID = spawnConfig.getString("spawns.all.world");
|
||||||
|
try {
|
||||||
|
final UUID worldUUID = UUID.fromString(worldID);
|
||||||
|
final World world = Bukkit.getWorld(worldUUID);
|
||||||
|
if (world != null) {
|
||||||
|
worldID = world.getName();
|
||||||
|
} else {
|
||||||
|
plugin.getLogger().warning("✖ Could not migrate the spawn position as the world value was a UUID and is not loaded on this server.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (IllegalArgumentException ignored) { }
|
||||||
|
if (worldFilter != null) {
|
||||||
|
if (!worldFilter.equalsIgnoreCase(worldID)) {
|
||||||
|
plugin.getLogger().warning("✖ Did not migrate the /spawn position as the world filter did not match.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
final double x = spawnConfig.getDouble("spawns.all.x");
|
||||||
|
final double y = spawnConfig.getDouble("spawns.all.y");
|
||||||
|
final double z = spawnConfig.getDouble("spawns.all.z");
|
||||||
|
final float yaw = (float) spawnConfig.getDouble("spawns.all.yaw");
|
||||||
|
final float pitch = (float) spawnConfig.getDouble("spawns.all.pitch");
|
||||||
|
|
||||||
|
Location spawnLocation = new Location(Bukkit.getWorld(worldID), x, y, z, yaw, pitch);
|
||||||
|
SettingHandler.setSpawnLocation(spawnLocation);
|
||||||
|
plugin.getLogger().info("→ /spawn position has been migrated!\n");
|
||||||
|
} catch (NullPointerException | IllegalArgumentException e) {
|
||||||
|
plugin.getLogger().warning("✖ Failed to migrate the /spawn position.\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
plugin.getLogger().info("✖ /spawn position migration from EssentialsX has been skipped as it has already been set or Cross Server Spawn has been enabled. Please re-set it again manually if you want.");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
plugin.getLogger().info("✖ /spawn position migration from EssentialsX has been skipped as it has already been set or Cross Server Spawn has been enabled. Please re-set it again manually if you want.");
|
plugin.getLogger().warning("Failed to Migrate from Essentials!");
|
||||||
|
Bukkit.getLogger().warning("Could not find Essentials plugin data to migrate!");
|
||||||
}
|
}
|
||||||
} else {
|
});
|
||||||
plugin.getLogger().warning("Failed to Migrate from Essentials!");
|
|
||||||
Bukkit.getLogger().warning("Could not find Essentials plugin data to migrate!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user