From fdba64c1602d9aa4af765571e77afc2fb2a5bb6c Mon Sep 17 00:00:00 2001 From: illa4257 <48959534+illa4257@users.noreply.github.com> Date: Wed, 30 Aug 2023 02:20:43 +0300 Subject: [PATCH] Fix #1 --- .../illa4257/opensit/OpenSitListener.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/PaperMC 1.20.1/src/main/java/illa4257/opensit/OpenSitListener.java b/PaperMC 1.20.1/src/main/java/illa4257/opensit/OpenSitListener.java index 7a43774..bfef848 100644 --- a/PaperMC 1.20.1/src/main/java/illa4257/opensit/OpenSitListener.java +++ b/PaperMC 1.20.1/src/main/java/illa4257/opensit/OpenSitListener.java @@ -1,6 +1,7 @@ package illa4257.opensit; import org.bukkit.Location; +import org.bukkit.block.Block; import org.bukkit.block.data.Bisected; import org.bukkit.block.data.BlockData; import org.bukkit.block.data.type.Slab; @@ -8,6 +9,7 @@ import org.bukkit.entity.*; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.spigotmc.event.entity.EntityDismountEvent; @@ -34,11 +36,27 @@ public void onInteract(final PlayerInteractEvent event) { if (d instanceof Slab || d instanceof Stairs) { final boolean t = d instanceof Slab ? ((Slab) d).getType() == Slab.Type.TOP : ((Stairs) d).getHalf() == Bisected.Half.TOP; final Location l = event.getClickedBlock().getLocation(); - final BlockDisplay b = (BlockDisplay) l.getWorld().spawnEntity(new Location(l.getWorld(), l.getX() + .5, - l.getY() + (t ? .8 : .3), + final BlockDisplay b = (BlockDisplay) l.getWorld().spawnEntity(new Location(l.getWorld(), l.getX() + .5, l.getY() + (t ? .8 : .3), l.getZ() + .5), EntityType.BLOCK_DISPLAY); b.addScoreboardTag(d instanceof Slab || t ? "sit" : "sit2"); b.addPassenger(event.getPlayer()); } } + + @EventHandler + public void onBreakBlock(final BlockBreakEvent event) { + final Block b = event.getBlock(); + final Location l = b.getLocation(); + final double sy = l.getBlockY() - .1, ey = l.getBlockY() + 1; + final int sx = l.getBlockX(), sz = l.getBlockZ(), ex = sx + 1, ez = sz + 1; + for (final Entity e : l.getChunk().getEntities()) + if (e instanceof BlockDisplay && (e.getScoreboardTags().contains("sit") || e.getScoreboardTags().contains("sit2"))) { + final Location l2 = e.getLocation(); + if ( + l2.getY() > sy && l2.getY() <= ey && + l2.getX() >= sx && l2.getX() <= ex && + l2.getZ() >= sz && l2.getZ() <= ez + ) e.remove(); + } + } } \ No newline at end of file