Skip to content

Commit

Permalink
fix self place
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Jan 24, 2024
1 parent ed58c31 commit be3b9ca
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerMoveEvent;

public class Burrow implements AnarchyExploitFixesModule, Listener {
Expand Down Expand Up @@ -66,12 +67,21 @@ private void teleportUpAndCenter(Player player, Location from) {
player.teleport(from.clone().add(0.5, 1, 0.5));
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onSelfPlace(BlockPlaceEvent event) {
final Location blockLoc = event.getBlock().getLocation();
Location legsLoc = event.getPlayer().getLocation().toBlockLocation();
if (legsLoc.equals(blockLoc) || legsLoc.add(0, 1, 0).equals(blockLoc)) {
event.setCancelled(true);
}
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onPlayerMove(PlayerMoveEvent event) {
Player player = event.getPlayer();
if (!player.getGameMode().equals(GameMode.SURVIVAL)) return;
if (player.isInsideVehicle() || player.isGliding()) return;

final Location playerLocation = player.getLocation();
final Block burrowBlock = playerLocation.getBlock();
final Material burrowMaterial = burrowBlock.getType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerMoveEvent;

import java.util.Arrays;
Expand Down Expand Up @@ -87,6 +88,15 @@ private void teleportUpAndCenter(Player player, Location from) {
player.teleport(from.clone().add(0.5, 1, 0.5));
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onSelfPlace(BlockPlaceEvent event) {
final Location blockLoc = event.getBlock().getLocation();
Location legsLoc = event.getPlayer().getLocation().toBlockLocation();
if (legsLoc.equals(blockLoc) || legsLoc.add(0, 1, 0).equals(blockLoc)) {
event.setCancelled(true);
}
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onPlayerMove(PlayerMoveEvent event) {
Player player = event.getPlayer();
Expand Down

0 comments on commit be3b9ca

Please sign in to comment.