|
| 1 | +/* |
| 2 | + * This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards |
| 3 | + * Copyright (C) 2016-2024 ViaVersion and contributors |
| 4 | + * |
| 5 | + * This program is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU General Public License as published by |
| 7 | + * the Free Software Foundation, either version 3 of the License, or |
| 8 | + * (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License |
| 16 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + */ |
| 18 | +package com.viaversion.viabackwards.listener; |
| 19 | + |
| 20 | +import com.viaversion.viabackwards.BukkitPlugin; |
| 21 | +import com.viaversion.viabackwards.protocol.v1_11to1_10.Protocol1_11To1_10; |
| 22 | +import com.viaversion.viaversion.bukkit.listeners.ViaBukkitListener; |
| 23 | +import org.bukkit.GameMode; |
| 24 | +import org.bukkit.entity.Player; |
| 25 | +import org.bukkit.event.EventHandler; |
| 26 | +import org.bukkit.event.EventPriority; |
| 27 | +import org.bukkit.event.block.BlockBreakEvent; |
| 28 | +import org.bukkit.inventory.ItemStack; |
| 29 | + |
| 30 | +public class BlockBreakListener extends ViaBukkitListener { |
| 31 | + |
| 32 | + public BlockBreakListener(final BukkitPlugin plugin) { |
| 33 | + super(plugin, Protocol1_11To1_10.class); |
| 34 | + } |
| 35 | + |
| 36 | + @EventHandler(priority = EventPriority.MONITOR) |
| 37 | + public void onBlockBreak(final BlockBreakEvent event) { |
| 38 | + if (!event.isCancelled()) { |
| 39 | + return; |
| 40 | + } |
| 41 | + |
| 42 | + final Player player = event.getPlayer(); |
| 43 | + if (player.getGameMode() == GameMode.CREATIVE || !isOnPipe(player)) { |
| 44 | + return; |
| 45 | + } |
| 46 | + |
| 47 | + // Resend the item in the hand to sync durability |
| 48 | + final int slot = player.getInventory().getHeldItemSlot(); |
| 49 | + final ItemStack item = player.getInventory().getItem(slot); |
| 50 | + if (item != null && item.getType().getMaxDurability() > 0) { |
| 51 | + player.getInventory().setItem(slot, item); |
| 52 | + } |
| 53 | + } |
| 54 | +} |
0 commit comments