Skip to content

Commit 2d3baa9

Browse files
author
Xyness
committed
src updated
1 parent 160a517 commit 2d3baa9

37 files changed

Lines changed: 833 additions & 316 deletions

src/main/java/fr/xyness/SCS/ClaimMain.java

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
import org.bukkit.boss.BarColor;
2525
import org.bukkit.boss.BossBar;
2626
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;
2730
import org.bukkit.entity.Player;
2831
import org.bukkit.event.player.PlayerTeleportEvent;
2932
import org.bukkit.scheduler.BukkitRunnable;
@@ -1005,7 +1008,7 @@ public String getClaimNameByChunk(Chunk chunk) {
10051008
*/
10061009
public String getClaimCoords(Claim claim) {
10071010
Location loc = claim.getLocation();
1008-
String world = loc.getWorld().getName();
1011+
String world = instance.getSettings().getWorldAliase(loc.getWorld().getName());
10091012
String x = String.valueOf(Math.round(loc.getX() * 10.0 / 10.0));
10101013
String y = String.valueOf(Math.round(loc.getY() * 10.0 / 10.0));
10111014
String z = String.valueOf(Math.round(loc.getZ() * 10.0 / 10.0));
@@ -1486,6 +1489,95 @@ public void convertDistantToNewDistant() {
14861489
}
14871490
}
14881491

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+
14891581
/**
14901582
* Imports the claims from GriefPrevention
14911583
*/

0 commit comments

Comments
 (0)