Check if InventoryHolder BlockState is placed.

Closes #1903.
This commit is contained in:
wizjany 2022-06-14 11:31:24 -04:00
parent 3a181a230f
commit 4a21bf43e7
No known key found for this signature in database
GPG Key ID: 1DB5861C03B76B5E

View File

@ -1215,8 +1215,7 @@ private static <T extends Event & Cancellable> void handleInventoryHolderUse(T o
return; return;
} }
if (holder instanceof Entity) { if (holder instanceof Entity entity) {
Entity entity = (Entity) holder;
Material mat = Materials.getRelatedMaterial((entity).getType()); Material mat = Materials.getRelatedMaterial((entity).getType());
UseEntityEvent useEntityEvent = new UseEntityEvent(originalEvent, cause, entity); UseEntityEvent useEntityEvent = new UseEntityEvent(originalEvent, cause, entity);
if (mat != null && hasInteractBypass((entity).getWorld(), mat)) { if (mat != null && hasInteractBypass((entity).getWorld(), mat)) {
@ -1224,8 +1223,7 @@ private static <T extends Event & Cancellable> void handleInventoryHolderUse(T o
} }
Events.fireToCancel(originalEvent, useEntityEvent); Events.fireToCancel(originalEvent, useEntityEvent);
} else { } else {
if (holder instanceof BlockState) { if (holder instanceof BlockState block && block.isPlaced()) {
final BlockState block = (BlockState) holder;
final UseBlockEvent useBlockEvent = new UseBlockEvent(originalEvent, cause, block.getBlock()); final UseBlockEvent useBlockEvent = new UseBlockEvent(originalEvent, cause, block.getBlock());
if (hasInteractBypass(block.getWorld(), block.getType())) { if (hasInteractBypass(block.getWorld(), block.getType())) {
useBlockEvent.setAllowed(true); useBlockEvent.setAllowed(true);