mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-04 07:28:19 +01:00
parent
f0fa81b712
commit
21e6ed4918
@ -57,16 +57,12 @@ public final class PlayerDiggingListener {
|
||||
final Block block = instance.getBlock(blockPosition);
|
||||
final GameMode gameMode = player.getGameMode();
|
||||
|
||||
if (gameMode == GameMode.SPECTATOR) {
|
||||
// Spectators can't break blocks
|
||||
// Prevent spectators and check players in adventure mode
|
||||
if (shouldPreventBreaking(player, block)) {
|
||||
return new DiggingResult(block, false);
|
||||
} else if (gameMode == GameMode.ADVENTURE) {
|
||||
// Check if the item can break the block with the current item
|
||||
final ItemStack itemInMainHand = player.getItemInMainHand();
|
||||
if (!itemInMainHand.meta().getCanDestroy().contains(block)) {
|
||||
return new DiggingResult(block, false);
|
||||
}
|
||||
} else if (gameMode == GameMode.CREATIVE) {
|
||||
}
|
||||
|
||||
if (gameMode == GameMode.CREATIVE) {
|
||||
return breakBlock(instance, player, blockPosition, block);
|
||||
}
|
||||
|
||||
@ -89,10 +85,28 @@ public final class PlayerDiggingListener {
|
||||
|
||||
private static DiggingResult finishDigging(Player player, Instance instance, Point blockPosition) {
|
||||
final Block block = instance.getBlock(blockPosition);
|
||||
// TODO sanity check
|
||||
|
||||
if (shouldPreventBreaking(player, block)) {
|
||||
return new DiggingResult(block, false);
|
||||
}
|
||||
|
||||
return breakBlock(instance, player, blockPosition, block);
|
||||
}
|
||||
|
||||
private static boolean shouldPreventBreaking(@NotNull Player player, Block block) {
|
||||
if (player.getGameMode() == GameMode.SPECTATOR) {
|
||||
// Spectators can't break blocks
|
||||
return true;
|
||||
} else if (player.getGameMode() == GameMode.ADVENTURE) {
|
||||
// Check if the item can break the block with the current item
|
||||
final ItemStack itemInMainHand = player.getItemInMainHand();
|
||||
if (!itemInMainHand.meta().getCanDestroy().contains(block)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void dropStack(Player player) {
|
||||
final ItemStack droppedItemStack = player.getInventory().getItemInMainHand();
|
||||
dropItem(player, droppedItemStack, ItemStack.AIR);
|
||||
|
Loading…
Reference in New Issue
Block a user