mirror of
https://github.com/YouHaveTrouble/Enchantio.git
synced 2026-10-26 12:25:28 +00:00
fix minor bugs related to tools enchanted with tunnelling breaking
This commit is contained in:
@@ -3,7 +3,6 @@ package me.youhavetrouble.enchantio.listeners;
|
|||||||
import io.papermc.paper.registry.RegistryAccess;
|
import io.papermc.paper.registry.RegistryAccess;
|
||||||
import io.papermc.paper.registry.RegistryKey;
|
import io.papermc.paper.registry.RegistryKey;
|
||||||
import io.papermc.paper.registry.keys.tags.BlockTypeTagKeys;
|
import io.papermc.paper.registry.keys.tags.BlockTypeTagKeys;
|
||||||
import me.youhavetrouble.enchantio.Enchantio;
|
|
||||||
import me.youhavetrouble.enchantio.EnchantioConfig;
|
import me.youhavetrouble.enchantio.EnchantioConfig;
|
||||||
import me.youhavetrouble.enchantio.enchants.EnchantioEnchant;
|
import me.youhavetrouble.enchantio.enchants.EnchantioEnchant;
|
||||||
import me.youhavetrouble.enchantio.enchants.TunnellingEnchant;
|
import me.youhavetrouble.enchantio.enchants.TunnellingEnchant;
|
||||||
@@ -22,9 +21,7 @@ import org.bukkit.event.player.PlayerInteractEvent;
|
|||||||
import org.bukkit.inventory.EquipmentSlot;
|
import org.bukkit.inventory.EquipmentSlot;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@SuppressWarnings("UnstableApiUsage")
|
@SuppressWarnings("UnstableApiUsage")
|
||||||
@@ -41,7 +38,7 @@ public class TunnellingListener implements Listener {
|
|||||||
if (event.getHand() != EquipmentSlot.HAND) return;
|
if (event.getHand() != EquipmentSlot.HAND) return;
|
||||||
if (event.getAction() != Action.LEFT_CLICK_BLOCK) return;
|
if (event.getAction() != Action.LEFT_CLICK_BLOCK) return;
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
if (player.isSneaking() || GameMode.CREATIVE.equals(player.getGameMode())) return;
|
if (GameMode.CREATIVE.equals(player.getGameMode())) return;
|
||||||
ItemStack item = event.getItem();
|
ItemStack item = event.getItem();
|
||||||
if (item == null) return;
|
if (item == null) return;
|
||||||
if (!item.containsEnchantment(tunnelling)) return;
|
if (!item.containsEnchantment(tunnelling)) return;
|
||||||
@@ -74,31 +71,29 @@ public class TunnellingListener implements Listener {
|
|||||||
Set<Block> blocksToBreak = getSquare(block, blockFace, tunnellingEnchant.getBlocksPerLevel() * enchantLevel);
|
Set<Block> blocksToBreak = getSquare(block, blockFace, tunnellingEnchant.getBlocksPerLevel() * enchantLevel);
|
||||||
blockBreakSkips.addAll(blocksToBreak);
|
blockBreakSkips.addAll(blocksToBreak);
|
||||||
for (Block b : blocksToBreak) {
|
for (Block b : blocksToBreak) {
|
||||||
|
if (player.getInventory().getItemInMainHand().isEmpty()) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
blockBreakSkips.removeAll(blocksToBreak);
|
||||||
|
break;
|
||||||
|
}
|
||||||
event.getPlayer().breakBlock(b);
|
event.getPlayer().breakBlock(b);
|
||||||
blockBreakSkips.remove(b);
|
blockBreakSkips.remove(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set<Block> getSquare(Block block, BlockFace face, int range) {
|
private Set<Block> getSquare(Block block, BlockFace face, int range) {
|
||||||
Set<Block> blocks = new HashSet<>();
|
|
||||||
switch (face) {
|
switch (face) {
|
||||||
case DOWN:
|
case DOWN, UP -> {
|
||||||
case UP:
|
return getBlocksToTunnel(block.getLocation(), range, 0, range);
|
||||||
blocks.addAll(getBlocksToTunnel(block.getLocation(), range, 0, range));
|
}
|
||||||
break;
|
case EAST, WEST -> {
|
||||||
case EAST:
|
return getBlocksToTunnel(block.getLocation(), 0, range, range);
|
||||||
case WEST:
|
}
|
||||||
blocks.addAll(getBlocksToTunnel(block.getLocation(), 0, range, range));
|
case NORTH, SOUTH -> {
|
||||||
break;
|
return getBlocksToTunnel(block.getLocation(), range, range, 0);
|
||||||
case NORTH:
|
}
|
||||||
case SOUTH:
|
|
||||||
blocks.addAll(getBlocksToTunnel(block.getLocation(), range, range, 0));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return blocks;
|
return new HashSet<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -106,8 +101,8 @@ public class TunnellingListener implements Listener {
|
|||||||
* @param base location at the centre of selection
|
* @param base location at the centre of selection
|
||||||
* @return All blocks that will get broken
|
* @return All blocks that will get broken
|
||||||
*/
|
*/
|
||||||
private List<Block> getBlocksToTunnel(Location base, int changeX, int changeY, int changeZ) {
|
private Set<Block> getBlocksToTunnel(Location base, int changeX, int changeY, int changeZ) {
|
||||||
List<Block> blocks = new ArrayList<>();
|
Set<Block> blocks = new HashSet<>();
|
||||||
for (int x = (base.getBlockX() - changeX); x <= (base.getBlockX() + changeX); x++) {
|
for (int x = (base.getBlockX() - changeX); x <= (base.getBlockX() + changeX); x++) {
|
||||||
for (int y = (base.getBlockY() - changeY); y <= (base.getBlockY() + changeY); y++) {
|
for (int y = (base.getBlockY() - changeY); y <= (base.getBlockY() + changeY); y++) {
|
||||||
for (int z = (base.getBlockZ() - changeZ); z <= (base.getBlockZ() + changeZ); z++) {
|
for (int z = (base.getBlockZ() - changeZ); z <= (base.getBlockZ() + changeZ); z++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user