mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 14:38:53 +00:00
Updated and improved the Essentials Migrator's compatibility
Signed-off-by: BuildTools <[email protected]>
This commit is contained in:
1 parent
e9066e13e3
commit
7f7081a434
3 files changed
+97
-46
No files matched your search
@@ -142,8 +142,13 @@ public class DataManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return a player's UUID
|
// Return a player's UUID
|
||||||
public static String getPlayerUUID(int playerID, Connection connection) throws SQLException {
|
public static UUID getPlayerUUID(int playerID, Connection connection) throws SQLException {
|
||||||
return getPlayerString(playerID, "user_uuid", connection);
|
String uuidString = getPlayerString(playerID, "user_uuid", connection);
|
||||||
|
if (uuidString != null) {
|
||||||
|
return UUID.fromString(uuidString);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return a player's username
|
// Return a player's username
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import me.william278.huskhomes2.teleport.points.TeleportationPoint;
|
|||||||
import me.william278.huskhomes2.teleport.points.Warp;
|
import me.william278.huskhomes2.teleport.points.Warp;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
|
||||||
@@ -45,32 +46,39 @@ public class EssentialsMigrator {
|
|||||||
// 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()) {
|
||||||
plugin.getLogger().info("Migrating user and home data from Essentials...\n");
|
|
||||||
|
|
||||||
File[] playerFiles = essentialsPlayerDataFolder.listFiles();
|
File[] playerFiles = essentialsPlayerDataFolder.listFiles();
|
||||||
if (playerFiles != null) {
|
if (playerFiles != null) {
|
||||||
|
|
||||||
for (File playerFile : playerFiles) {
|
for (File playerFile : playerFiles) {
|
||||||
String uuidS = playerFile.getName().split("\\.")[0];
|
try {
|
||||||
UUID uuid = UUID.fromString(uuidS);
|
final String fileName = playerFile.getName();
|
||||||
|
final UUID playerUUID = UUID.fromString(fileName.substring(0, fileName.lastIndexOf(".")));
|
||||||
FileConfiguration playerFileConfig = loadConfiguration(playerFile);
|
FileConfiguration playerFileConfig = loadConfiguration(playerFile);
|
||||||
String playerName = playerFileConfig.getString("lastAccountName");
|
final String playerName = playerFileConfig.getString("last-account-name", playerFileConfig.getString("lastAccountName"));
|
||||||
plugin.getLogger().info("Migrating user data for " + playerName);
|
|
||||||
try {
|
try {
|
||||||
Connection connection = HuskHomes.getConnection();
|
Connection connection = HuskHomes.getConnection();
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
try {
|
try {
|
||||||
if (!DataManager.playerExists(uuid, connection)) {
|
if (!DataManager.playerExists(playerUUID, connection)) {
|
||||||
DataManager.createPlayer(uuid, playerName, connection);
|
DataManager.createPlayer(playerUUID, playerName, connection);
|
||||||
}
|
}
|
||||||
ConfigurationSection homesSection = playerFileConfig.getConfigurationSection("homes");
|
final ConfigurationSection homesSection = playerFileConfig.getConfigurationSection("homes");
|
||||||
if (homesSection != null) {
|
if (homesSection != null) {
|
||||||
Set<String> essentialsHomes = homesSection.getKeys(false);
|
Set<String> essentialsHomes = homesSection.getKeys(false);
|
||||||
for (String homeName : essentialsHomes) {
|
for (String homeName : essentialsHomes) {
|
||||||
try {
|
try {
|
||||||
final String worldName = playerFileConfig.getString("homes." + homeName + ".world");
|
String worldID = playerFileConfig.getString("homes." + homeName + ".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 " + homeName + " as the world value was a UUID and is not loaded on this server.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} catch (IllegalArgumentException ignored) { }
|
||||||
if (worldFilter != null) {
|
if (worldFilter != null) {
|
||||||
if (!worldFilter.equalsIgnoreCase(worldName)) {
|
if (!worldFilter.equalsIgnoreCase(worldID)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -81,12 +89,17 @@ public class EssentialsMigrator {
|
|||||||
final float yaw = (float) playerFileConfig.getDouble("homes." + homeName + ".yaw");
|
final float yaw = (float) playerFileConfig.getDouble("homes." + homeName + ".yaw");
|
||||||
final String homeDescription = MessageManager.getRawMessage("home_default_description", playerName);
|
final String homeDescription = MessageManager.getRawMessage("home_default_description", playerName);
|
||||||
|
|
||||||
DataManager.addHome(new Home(new TeleportationPoint(worldName, x, y, z, yaw, pitch, targetServer),
|
if (DataManager.homeExists(playerName, homeName, connection)) {
|
||||||
playerName, uuidS, homeName, homeDescription, false), uuid, connection);
|
plugin.getLogger().warning("✖ Failed to migrate home " + homeName + " (Already exists!)");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
DataManager.addHome(new Home(new TeleportationPoint(worldID, x, y, z, yaw, pitch, targetServer),
|
||||||
|
playerName, playerUUID, homeName, homeDescription, false), playerUUID, connection);
|
||||||
|
|
||||||
plugin.getLogger().info("→ Migrated home " + homeName);
|
plugin.getLogger().info("→ Migrated home " + homeName);
|
||||||
} catch (NullPointerException | IllegalArgumentException e) {
|
} catch (NullPointerException | IllegalArgumentException e) {
|
||||||
plugin.getLogger().warning("✖ Failed to migrate home " + homeName);
|
plugin.getLogger().warning("✖ Failed to migrate home " + homeName + "!");
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -95,18 +108,15 @@ public class EssentialsMigrator {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException ignored) { }
|
||||||
plugin.getLogger().info("→ No Essentials home data was found for " + playerName);
|
} catch (IllegalArgumentException ignored) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
plugin.getLogger().info("Finished migrating homes from Essentials!\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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()) {
|
||||||
plugin.getLogger().info("Migrating warps from Essentials...\n");
|
|
||||||
final File[] warpFiles = essentialsWarpsFolder.listFiles();
|
final File[] warpFiles = essentialsWarpsFolder.listFiles();
|
||||||
|
|
||||||
if (warpFiles != null) {
|
if (warpFiles != null) {
|
||||||
@@ -116,9 +126,19 @@ public class EssentialsMigrator {
|
|||||||
try {
|
try {
|
||||||
final FileConfiguration warpFileConfig = loadConfiguration(warpFile);
|
final FileConfiguration warpFileConfig = loadConfiguration(warpFile);
|
||||||
final String warpName = warpFileConfig.getString("name");
|
final String warpName = warpFileConfig.getString("name");
|
||||||
final String worldName = warpFileConfig.getString("world");
|
String worldID = warpFileConfig.getString("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 " + warpName + " as the world value was a UUID and is not loaded on this server.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} catch (IllegalArgumentException ignored) { }
|
||||||
if (worldFilter != null) {
|
if (worldFilter != null) {
|
||||||
if (!worldFilter.equalsIgnoreCase(worldName)) {
|
if (!worldFilter.equalsIgnoreCase(worldID)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -128,7 +148,12 @@ public class EssentialsMigrator {
|
|||||||
final float yaw = (float) warpFileConfig.getDouble("yaw");
|
final float yaw = (float) warpFileConfig.getDouble("yaw");
|
||||||
final float pitch = (float) warpFileConfig.getDouble("pitch");
|
final float pitch = (float) warpFileConfig.getDouble("pitch");
|
||||||
|
|
||||||
DataManager.addWarp(new Warp(new TeleportationPoint(worldName, x, y, z, yaw, pitch, targetServer),
|
if (DataManager.warpExists(warpName, connection)) {
|
||||||
|
plugin.getLogger().warning("✖ Failed to migrate warp " + warpName + " (Already exists!)");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
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")), connection);
|
||||||
plugin.getLogger().info("→ Migrated warp " + warpName);
|
plugin.getLogger().info("→ Migrated warp " + warpName);
|
||||||
} catch (NullPointerException | IllegalArgumentException e) {
|
} catch (NullPointerException | IllegalArgumentException e) {
|
||||||
@@ -140,7 +165,6 @@ public class EssentialsMigrator {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
plugin.getLogger().info("Finished migrating warps from Essentials!\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Migrate /spawn position
|
// Migrate /spawn position
|
||||||
@@ -151,36 +175,39 @@ public class EssentialsMigrator {
|
|||||||
|
|
||||||
FileConfiguration spawnConfig = loadConfiguration(essentialsSpawnData);
|
FileConfiguration spawnConfig = loadConfiguration(essentialsSpawnData);
|
||||||
try {
|
try {
|
||||||
final String worldName = spawnConfig.getString("spawns.all.world");
|
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 x = spawnConfig.getDouble("spawns.all.x");
|
||||||
final double y = spawnConfig.getDouble("spawns.all.y");
|
final double y = spawnConfig.getDouble("spawns.all.y");
|
||||||
final double z = spawnConfig.getDouble("spawns.all.z");
|
final double z = spawnConfig.getDouble("spawns.all.z");
|
||||||
final float yaw = (float) spawnConfig.getDouble("spawns.all.yaw");
|
final float yaw = (float) spawnConfig.getDouble("spawns.all.yaw");
|
||||||
final float pitch = (float) spawnConfig.getDouble("spawns.all.pitch");
|
final float pitch = (float) spawnConfig.getDouble("spawns.all.pitch");
|
||||||
|
|
||||||
if (worldFilter != null) {
|
Location spawnLocation = new Location(Bukkit.getWorld(worldID), x, y, z, yaw, pitch);
|
||||||
if (worldFilter.equalsIgnoreCase(worldName)) {
|
|
||||||
Location spawnLocation = new Location(Bukkit.getWorld(worldName), x, y, z, yaw, pitch);
|
|
||||||
SettingHandler.setSpawnLocation(spawnLocation);
|
SettingHandler.setSpawnLocation(spawnLocation);
|
||||||
plugin.getLogger().info("→ /spawn position has been migrated!\n");
|
plugin.getLogger().info("→ /spawn position has been migrated!\n");
|
||||||
} else {
|
|
||||||
plugin.getLogger().info("✖ /spawn position was not migrated as the world filter did not match.\n");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Location spawnLocation = new Location(Bukkit.getWorld(worldName), x, y, z, yaw, pitch);
|
|
||||||
SettingHandler.setSpawnLocation(spawnLocation);
|
|
||||||
plugin.getLogger().info("→ /spawn position has been migrated!\n");
|
|
||||||
}
|
|
||||||
} catch (NullPointerException | IllegalArgumentException e) {
|
} catch (NullPointerException | IllegalArgumentException e) {
|
||||||
plugin.getLogger().warning("✖ Failed to migrate the /spawn position.\n");
|
plugin.getLogger().warning("✖ Failed to migrate the /spawn position.\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} 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().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().info("Finished migrating data from Essentials!\n");
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
plugin.getLogger().warning("Failed to Migrate from Essentials!");
|
plugin.getLogger().warning("Failed to Migrate from Essentials!");
|
||||||
Bukkit.getLogger().warning("Could not find Essentials plugin data to migrate!");
|
Bukkit.getLogger().warning("Could not find Essentials plugin data to migrate!");
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public class Home extends TeleportationPoint {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* An object representing a Player's home in-game
|
* An object representing a Player's home in-game
|
||||||
* @param location The Bukkit location of the home
|
* @param location The Bukkit {@link Location} of the home
|
||||||
* @param server The Bungee server ID of the home
|
* @param server The Bungee server ID of the home
|
||||||
* @param homeOwner The Player who owns the home
|
* @param homeOwner The Player who owns the home
|
||||||
* @param name The name of the home
|
* @param name The name of the home
|
||||||
@@ -41,14 +41,15 @@ public class Home extends TeleportationPoint {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* An object representing a Player's home in-game
|
* An object representing a Player's home in-game
|
||||||
* @param teleportationPoint The position of the home
|
* @deprecated Use other method that accepts UUID instead of UUID-string
|
||||||
|
* @param teleportationPoint The {@link TeleportationPoint} position of the home
|
||||||
* @param ownerUsername The username of the owner
|
* @param ownerUsername The username of the owner
|
||||||
* @param ownerUUID The UUID of the owner
|
* @param ownerUUID The UUID string of the owner
|
||||||
* @param name The name of the home
|
* @param name The name of the home
|
||||||
* @param description The description of the home
|
* @param description The description of the home
|
||||||
* @param isPublic Whether or not the home is public
|
* @param isPublic Whether or not the home is public
|
||||||
*/
|
*/
|
||||||
public Home(TeleportationPoint teleportationPoint, String ownerUsername, String ownerUUID, String name, String description, boolean isPublic) {
|
public Home(TeleportationPoint teleportationPoint, String ownerUsername, String ownerUUID, String name, String description, boolean isPublic) throws IllegalArgumentException {
|
||||||
super(teleportationPoint.worldName, teleportationPoint.x, teleportationPoint.y, teleportationPoint.z, teleportationPoint.yaw, teleportationPoint.pitch, teleportationPoint.server);
|
super(teleportationPoint.worldName, teleportationPoint.x, teleportationPoint.y, teleportationPoint.z, teleportationPoint.yaw, teleportationPoint.pitch, teleportationPoint.server);
|
||||||
this.ownerUsername = ownerUsername;
|
this.ownerUsername = ownerUsername;
|
||||||
this.ownerUUID = UUID.fromString(ownerUUID);
|
this.ownerUUID = UUID.fromString(ownerUUID);
|
||||||
@@ -57,6 +58,24 @@ public class Home extends TeleportationPoint {
|
|||||||
this.isPublic = isPublic;
|
this.isPublic = isPublic;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An object representing a Player's home in-game
|
||||||
|
* @param teleportationPoint The {@link TeleportationPoint} position of the home
|
||||||
|
* @param ownerUsername The username of the owner
|
||||||
|
* @param ownerUUID The {@link UUID} of the owner
|
||||||
|
* @param name The name of the home
|
||||||
|
* @param description The description of the home
|
||||||
|
* @param isPublic Whether or not the home is public
|
||||||
|
*/
|
||||||
|
public Home(TeleportationPoint teleportationPoint, String ownerUsername, UUID ownerUUID, String name, String description, boolean isPublic) {
|
||||||
|
super(teleportationPoint.worldName, teleportationPoint.x, teleportationPoint.y, teleportationPoint.z, teleportationPoint.yaw, teleportationPoint.pitch, teleportationPoint.server);
|
||||||
|
this.ownerUsername = ownerUsername;
|
||||||
|
this.ownerUUID = ownerUUID;
|
||||||
|
this.name = name;
|
||||||
|
this.description = description;
|
||||||
|
this.isPublic = isPublic;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether or not the Home is public
|
* Returns whether or not the Home is public
|
||||||
* @return if the Home is public
|
* @return if the Home is public
|
||||||
|
|||||||
Reference in new issue
Block a user