diff --git a/worldguard-core/src/main/java/com/sk89q/worldguard/protection/managers/storage/file/YamlRegionFile.java b/worldguard-core/src/main/java/com/sk89q/worldguard/protection/managers/storage/file/YamlRegionFile.java index 4c38a32b..90cddd1c 100644 --- a/worldguard-core/src/main/java/com/sk89q/worldguard/protection/managers/storage/file/YamlRegionFile.java +++ b/worldguard-core/src/main/java/com/sk89q/worldguard/protection/managers/storage/file/YamlRegionFile.java @@ -192,67 +192,69 @@ public class YamlRegionFile implements RegionDatabase { } @Override - public synchronized void saveAll(Set regions) throws StorageException { + public void saveAll(Set regions) throws StorageException { checkNotNull(regions); - File tempFile = new File(file.getParentFile(), file.getName() + ".tmp"); - YAMLProcessor config = createYamlProcessor(tempFile); + synchronized (YamlRegionFile.class) { + File tempFile = new File(file.getParentFile(), file.getName() + ".tmp"); + YAMLProcessor config = createYamlProcessor(tempFile); - config.clear(); + config.clear(); - YAMLNode regionsNode = config.addNode("regions"); - Map map = regionsNode.getMap(); + YAMLNode regionsNode = config.addNode("regions"); + Map map = regionsNode.getMap(); - for (ProtectedRegion region : regions) { - Map nodeMap = new HashMap<>(); - map.put(region.getId(), nodeMap); - YAMLNode node = new YAMLNode(nodeMap, false); + for (ProtectedRegion region : regions) { + Map nodeMap = new HashMap<>(); + map.put(region.getId(), nodeMap); + YAMLNode node = new YAMLNode(nodeMap, false); - if (region instanceof ProtectedCuboidRegion) { - ProtectedCuboidRegion cuboid = (ProtectedCuboidRegion) region; - node.setProperty("type", "cuboid"); - node.setProperty("min", cuboid.getMinimumPoint()); - node.setProperty("max", cuboid.getMaximumPoint()); - } else if (region instanceof ProtectedPolygonalRegion) { - ProtectedPolygonalRegion poly = (ProtectedPolygonalRegion) region; - node.setProperty("type", "poly2d"); - node.setProperty("min-y", poly.getMinimumPoint().getBlockY()); - node.setProperty("max-y", poly.getMaximumPoint().getBlockY()); + if (region instanceof ProtectedCuboidRegion) { + ProtectedCuboidRegion cuboid = (ProtectedCuboidRegion) region; + node.setProperty("type", "cuboid"); + node.setProperty("min", cuboid.getMinimumPoint()); + node.setProperty("max", cuboid.getMaximumPoint()); + } else if (region instanceof ProtectedPolygonalRegion) { + ProtectedPolygonalRegion poly = (ProtectedPolygonalRegion) region; + node.setProperty("type", "poly2d"); + node.setProperty("min-y", poly.getMinimumPoint().getBlockY()); + node.setProperty("max-y", poly.getMaximumPoint().getBlockY()); - List> points = new ArrayList<>(); - for (BlockVector2 point : poly.getPoints()) { - Map data = new HashMap<>(); - data.put("x", point.getBlockX()); - data.put("z", point.getBlockZ()); - points.add(data); + List> points = new ArrayList<>(); + for (BlockVector2 point : poly.getPoints()) { + Map data = new HashMap<>(); + data.put("x", point.getBlockX()); + data.put("z", point.getBlockZ()); + points.add(data); + } + + node.setProperty("points", points); + } else if (region instanceof GlobalProtectedRegion) { + node.setProperty("type", "global"); + } else { + node.setProperty("type", region.getClass().getCanonicalName()); } - node.setProperty("points", points); - } else if (region instanceof GlobalProtectedRegion) { - node.setProperty("type", "global"); - } else { - node.setProperty("type", region.getClass().getCanonicalName()); + node.setProperty("priority", region.getPriority()); + node.setProperty("flags", getFlagData(region)); + node.setProperty("owners", getDomainData(region.getOwners())); + node.setProperty("members", getDomainData(region.getMembers())); + + ProtectedRegion parent = region.getParent(); + if (parent != null) { + node.setProperty("parent", parent.getId()); + } } - node.setProperty("priority", region.getPriority()); - node.setProperty("flags", getFlagData(region)); - node.setProperty("owners", getDomainData(region.getOwners())); - node.setProperty("members", getDomainData(region.getMembers())); + config.setHeader(FILE_HEADER); + config.save(); - ProtectedRegion parent = region.getParent(); - if (parent != null) { - node.setProperty("parent", parent.getId()); + //noinspection ResultOfMethodCallIgnored + file.delete(); + if (!tempFile.renameTo(file)) { + throw new StorageException("Failed to rename temporary regions file to " + file.getAbsolutePath()); } } - - config.setHeader(FILE_HEADER); - config.save(); - - //noinspection ResultOfMethodCallIgnored - file.delete(); - if (!tempFile.renameTo(file)) { - throw new StorageException("Failed to rename temporary regions file to " + file.getAbsolutePath()); - } } @Override