mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-13 02:41:41 +01:00
Fix ghost item/block when cancelling interaction
This commit is contained in:
parent
66904f2539
commit
991de2d0cc
@ -44,7 +44,8 @@ public class BlockPlacementListener {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Prevent outdated/modified client data
|
// Prevent outdated/modified client data
|
||||||
if (!ChunkUtils.isLoaded(instance.getChunkAt(blockPosition))) {
|
final Chunk interactedChunk = instance.getChunkAt(blockPosition);
|
||||||
|
if (!ChunkUtils.isLoaded(interactedChunk)) {
|
||||||
// Client tried to place a block in an unloaded chunk, ignore the request
|
// Client tried to place a block in an unloaded chunk, ignore the request
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -64,6 +65,7 @@ public class BlockPlacementListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (blockUse) {
|
if (blockUse) {
|
||||||
|
refresh(player, interactedChunk);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,7 +105,7 @@ public class BlockPlacementListener {
|
|||||||
Check.stateCondition(!ChunkUtils.isLoaded(chunk),
|
Check.stateCondition(!ChunkUtils.isLoaded(chunk),
|
||||||
"A player tried to place a block in the border of a loaded chunk {0}", placementPosition);
|
"A player tried to place a block in the border of a loaded chunk {0}", placementPosition);
|
||||||
if (chunk.isReadOnly()) {
|
if (chunk.isReadOnly()) {
|
||||||
chunk.sendChunk(player);
|
refresh(player, chunk);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,7 +133,7 @@ public class BlockPlacementListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (intersect) {
|
if (intersect) {
|
||||||
chunk.sendChunk(player);
|
refresh(player, chunk);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// BlockPlaceEvent check
|
// BlockPlaceEvent check
|
||||||
@ -139,7 +141,7 @@ public class BlockPlacementListener {
|
|||||||
playerBlockPlaceEvent.consumeBlock(player.getGameMode() != GameMode.CREATIVE);
|
playerBlockPlaceEvent.consumeBlock(player.getGameMode() != GameMode.CREATIVE);
|
||||||
EventDispatcher.call(playerBlockPlaceEvent);
|
EventDispatcher.call(playerBlockPlaceEvent);
|
||||||
if (playerBlockPlaceEvent.isCancelled()) {
|
if (playerBlockPlaceEvent.isCancelled()) {
|
||||||
chunk.sendChunk(player);
|
refresh(player, chunk);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,7 +153,7 @@ public class BlockPlacementListener {
|
|||||||
resultBlock = blockPlacementRule.blockPlace(instance, resultBlock, blockFace, blockPosition, player);
|
resultBlock = blockPlacementRule.blockPlace(instance, resultBlock, blockFace, blockPosition, player);
|
||||||
}
|
}
|
||||||
if (resultBlock == null) {
|
if (resultBlock == null) {
|
||||||
chunk.sendChunk(player);
|
refresh(player, chunk);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Place the block
|
// Place the block
|
||||||
@ -164,4 +166,9 @@ public class BlockPlacementListener {
|
|||||||
playerInventory.setItemInHand(hand, newUsedItem);
|
playerInventory.setItemInHand(hand, newUsedItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void refresh(Player player, Chunk chunk) {
|
||||||
|
player.getInventory().update();
|
||||||
|
chunk.sendChunk(player);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user