diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/BlockDataService.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/BlockDataService.java index 22050b000c..58596ec3ca 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/BlockDataService.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/BlockDataService.java @@ -119,29 +119,26 @@ public Optional getUniversalDataUUID(Block b) { } public static Optional getBlockData(Block b, NamespacedKey key) { - try { + if (Bukkit.isPrimaryThread()) { BlockState state = b.getState(false); PersistentDataContainer container = getPersistentDataContainer(state); - if (container != null) { - return Optional.ofNullable(container.get(key, PersistentDataType.STRING)); - } else { + if (container == null) { return Optional.empty(); } - } catch (IllegalStateException e) { - try { - return Bukkit.getScheduler().callSyncMethod(Slimefun.instance(), () -> { - BlockState state = b.getState(false); - PersistentDataContainer container = getPersistentDataContainer(state); - if (container != null) { - return Optional.ofNullable(container.get(key, PersistentDataType.STRING)); - } else { - //noinspection OptionalOfNullableMisuse - return Optional.ofNullable((String) null); - } - }).get(); - } catch (InterruptedException | ExecutionException ex) { - throw new RuntimeException(ex); - } + return Optional.ofNullable(container.get(key, PersistentDataType.STRING)); + } + try { + return Bukkit.getScheduler().callSyncMethod(Slimefun.instance(), () -> { + BlockState state = b.getState(false); + PersistentDataContainer container = getPersistentDataContainer(state); + if (container == null) { + //noinspection OptionalOfNullableMisuse + return Optional.ofNullable((String) null); + } + return Optional.ofNullable(container.get(key, PersistentDataType.STRING)); + }).get(); + } catch (InterruptedException | ExecutionException ex) { + throw new RuntimeException(ex); } }