Skip to content

Commit

Permalink
Fix #1
Browse files Browse the repository at this point in the history
  • Loading branch information
illa4257 committed Aug 29, 2023
1 parent b32f012 commit fdba64c
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions PaperMC 1.20.1/src/main/java/illa4257/opensit/OpenSitListener.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
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;
import org.bukkit.block.data.type.Stairs;
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;

Expand All @@ -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();
}
}
}

0 comments on commit fdba64c

Please sign in to comment.