From bbcb091daf7119a89a06d8f3202cdb60dbe688bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Rom=C3=A3o?= <12960698+rafaelflromao@users.noreply.github.com> Date: Wed, 21 Jun 2023 10:45:17 +0100 Subject: [PATCH] Fix locked map data saving (#140) --- .../william278/husksync/data/BukkitMapHandler.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/bukkit/src/main/java/net/william278/husksync/data/BukkitMapHandler.java b/bukkit/src/main/java/net/william278/husksync/data/BukkitMapHandler.java index b20bb5fb..cc1ddac1 100644 --- a/bukkit/src/main/java/net/william278/husksync/data/BukkitMapHandler.java +++ b/bukkit/src/main/java/net/william278/husksync/data/BukkitMapHandler.java @@ -29,6 +29,7 @@ import org.jetbrains.annotations.Nullable; import java.awt.*; import java.io.IOException; import java.util.Objects; +import java.util.concurrent.ExecutionException; import java.util.logging.Level; /** @@ -55,8 +56,14 @@ public class BukkitMapHandler { } // Get the map view from the map - final MapView mapView = mapMeta.getMapView(); - if (mapView == null || !mapView.isLocked() || mapView.isVirtual()) { + final MapView mapView; + try { + mapView = Bukkit.getScheduler().callSyncMethod(plugin, mapMeta::getMapView).get(); + if (mapView == null || !mapView.isLocked() || mapView.isVirtual()) { + return; + } + } catch (InterruptedException | ExecutionException e) { + plugin.getLogger().log(Level.WARNING, "Failed to save map data for a player", e); return; }