Skip to content

Commit 16c7bb1

Browse files
committed
get block state from main thread
1 parent 28a57dc commit 16c7bb1

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/main/java/pro/cloudnode/smp/bankaccounts/commands/POSCommand.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package pro.cloudnode.smp.bankaccounts.commands;
22

33
import org.bukkit.block.Block;
4+
import org.bukkit.block.BlockState;
45
import org.bukkit.block.Chest;
56
import org.bukkit.command.CommandSender;
67
import org.bukkit.entity.Player;
@@ -65,7 +66,9 @@ public boolean execute(final @NotNull CommandSender sender, final @NotNull Strin
6566
final @Nullable Block target = player.getTargetBlockExact(5);
6667
if (target == null) return sendMessage(sender, BankAccounts.getInstance().config().messagesErrorsBlockTooFar());
6768

68-
if (!(target.getState() instanceof final @NotNull Chest chest))
69+
final @NotNull Optional<@NotNull BlockState> block = BankAccounts.runOnMain(target::getState, 5);
70+
if (block.isEmpty()) return sendMessage(sender, BankAccounts.getInstance().config().messagesErrorsAsyncFailed());
71+
if (!(block.get() instanceof final @NotNull Chest chest))
6972
return sendMessage(sender, BankAccounts.getInstance().config().messagesErrorsPosNotChest());
7073
if (chest.getInventory() instanceof DoubleChestInventory)
7174
return sendMessage(sender, BankAccounts.getInstance().config().messagesErrorsPosDoubleChest());

0 commit comments

Comments
 (0)