Skip to content

Commit

Permalink
Update BlockDataService.java
Browse files Browse the repository at this point in the history
  • Loading branch information
mcchampions committed Dec 8, 2024
1 parent fbe52f6 commit 4ae7580
Showing 1 changed file with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
import javax.annotation.Nullable;

Expand Down Expand Up @@ -118,13 +119,29 @@ public Optional<UUID> getUniversalDataUUID(Block b) {
}

public static Optional<String> getBlockData(Block b, NamespacedKey key) {
BlockState state = b.getState(false);
PersistentDataContainer container = getPersistentDataContainer(state);

if (container != null) {
return Optional.ofNullable(container.get(key, PersistentDataType.STRING));
} else {
return Optional.empty();
try {
BlockState state = b.getState(false);
PersistentDataContainer container = getPersistentDataContainer(state);
if (container != null) {
return Optional.ofNullable(container.get(key, PersistentDataType.STRING));
} else {
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);
}
}
}

Expand Down

0 comments on commit 4ae7580

Please sign in to comment.