|
24 | 24 | import org.bukkit.boss.BarColor; |
25 | 25 | import org.bukkit.boss.BossBar; |
26 | 26 | import org.bukkit.command.CommandSender; |
| 27 | +import org.bukkit.configuration.ConfigurationSection; |
| 28 | +import org.bukkit.configuration.file.FileConfiguration; |
| 29 | +import org.bukkit.configuration.file.YamlConfiguration; |
27 | 30 | import org.bukkit.entity.Player; |
28 | 31 | import org.bukkit.event.player.PlayerTeleportEvent; |
29 | 32 | import org.bukkit.scheduler.BukkitRunnable; |
@@ -1005,7 +1008,7 @@ public String getClaimNameByChunk(Chunk chunk) { |
1005 | 1008 | */ |
1006 | 1009 | public String getClaimCoords(Claim claim) { |
1007 | 1010 | Location loc = claim.getLocation(); |
1008 | | - String world = loc.getWorld().getName(); |
| 1011 | + String world = instance.getSettings().getWorldAliase(loc.getWorld().getName()); |
1009 | 1012 | String x = String.valueOf(Math.round(loc.getX() * 10.0 / 10.0)); |
1010 | 1013 | String y = String.valueOf(Math.round(loc.getY() * 10.0 / 10.0)); |
1011 | 1014 | String z = String.valueOf(Math.round(loc.getZ() * 10.0 / 10.0)); |
@@ -1486,6 +1489,95 @@ public void convertDistantToNewDistant() { |
1486 | 1489 | } |
1487 | 1490 | } |
1488 | 1491 |
|
| 1492 | + /** |
| 1493 | + * Imports the claims from XClaims |
| 1494 | + */ |
| 1495 | + public void importFromXClaims(CommandSender sender) { |
| 1496 | + instance.executeAsync(() -> { |
| 1497 | + File file = new File("plugins/SimpleClaimSystem/xclaims.yml"); |
| 1498 | + int[] i = {0}; |
| 1499 | + |
| 1500 | + FileConfiguration config = YamlConfiguration.loadConfiguration(file); |
| 1501 | + |
| 1502 | + Set<String> claimKeys = config.getKeys(false); |
| 1503 | + |
| 1504 | + for (String key : claimKeys) { |
| 1505 | + String claim_name = config.getString(key + ".name").replace(" ", "_"); |
| 1506 | + String owner = config.getString(key + ".owner"); |
| 1507 | + UUID uuid_owner = UUID.fromString(owner); |
| 1508 | + String owner_name = Bukkit.getOfflinePlayer(uuid_owner).getName(); |
| 1509 | + int id = findFreeId(uuid_owner); |
| 1510 | + String world_name = config.getString(key + ".world"); |
| 1511 | + World world = Bukkit.getWorld(world_name); |
| 1512 | + ConfigurationSection userSection = config.getConfigurationSection(key + ".users"); |
| 1513 | + Set<String> list_users = userSection.getKeys(false); |
| 1514 | + list_users.add(owner_name); |
| 1515 | + String users = String.join(";", list_users); |
| 1516 | + ConfigurationSection chunkSection = config.getConfigurationSection(key + ".chunks"); |
| 1517 | + Set<Chunk> chunks = ConcurrentHashMap.newKeySet(); |
| 1518 | + |
| 1519 | + Runnable task = () -> { |
| 1520 | + |
| 1521 | + Location loc = getCenterLocationOfChunk(chunks.iterator().next()); |
| 1522 | + String chunksData = serializeChunks(chunks); |
| 1523 | + try (Connection connection = instance.getDataSource().getConnection(); |
| 1524 | + PreparedStatement stmt = connection.prepareStatement( |
| 1525 | + "INSERT INTO scs_claims_1 (id_claim, owner_uuid, owner_name, claim_name, claim_description, chunks, world_name, location, members, permissions) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) { |
| 1526 | + stmt.setInt(1, id); |
| 1527 | + stmt.setString(2, owner); |
| 1528 | + stmt.setString(3, owner_name); |
| 1529 | + stmt.setString(4, claim_name); |
| 1530 | + stmt.setString(5, instance.getLanguage().getMessage("default-description")); |
| 1531 | + stmt.setString(6, chunksData); |
| 1532 | + stmt.setString(7, world_name); |
| 1533 | + stmt.setString(8, getLocationString(loc)); |
| 1534 | + stmt.setString(9, users); |
| 1535 | + stmt.setString(10, instance.getSettings().getDefaultValuesCode("all")); |
| 1536 | + stmt.executeUpdate(); |
| 1537 | + i[0]++; |
| 1538 | + } catch (SQLException e) { |
| 1539 | + e.printStackTrace(); |
| 1540 | + } |
| 1541 | + }; |
| 1542 | + |
| 1543 | + List<CompletableFuture<Void>> futures = new ArrayList<>(); |
| 1544 | + for (String chunkId : chunkSection.getKeys(false)) { |
| 1545 | + int x = chunkSection.getInt(chunkId + ".x"); |
| 1546 | + int z = chunkSection.getInt(chunkId + ".z"); |
| 1547 | + CompletableFuture<Void> future; |
| 1548 | + if (instance.isFolia()) { |
| 1549 | + future = world.getChunkAtAsync(x, z).thenAccept(chunk -> { |
| 1550 | + synchronized (chunks) { |
| 1551 | + chunks.add(chunk); |
| 1552 | + } |
| 1553 | + }).exceptionally(ex -> { |
| 1554 | + ex.printStackTrace(); |
| 1555 | + return null; |
| 1556 | + }); |
| 1557 | + } else { |
| 1558 | + Chunk chunk = world.getChunkAt(x, z); |
| 1559 | + chunks.add(chunk); |
| 1560 | + future = CompletableFuture.completedFuture(null); |
| 1561 | + } |
| 1562 | + futures.add(future); |
| 1563 | + } |
| 1564 | + |
| 1565 | + CompletableFuture<Void> allOf = CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])); |
| 1566 | + allOf.thenRun(() -> { |
| 1567 | + task.run(); |
| 1568 | + }).exceptionally(ex -> { |
| 1569 | + ex.printStackTrace(); |
| 1570 | + return null; |
| 1571 | + }); |
| 1572 | + } |
| 1573 | + |
| 1574 | + instance.executeSync(() -> { |
| 1575 | + sender.sendMessage(getNumberSeparate(String.valueOf(i[0]))+" imported claims, reloading.."); |
| 1576 | + Bukkit.dispatchCommand(sender, "scs reload"); |
| 1577 | + }); |
| 1578 | + }); |
| 1579 | + } |
| 1580 | + |
1489 | 1581 | /** |
1490 | 1582 | * Imports the claims from GriefPrevention |
1491 | 1583 | */ |
|
0 commit comments