Skip to content

Commit

Permalink
fix vehicle bypass in anti-nether-roof
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Jan 11, 2024
1 parent 2c32575 commit 7469392
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.entity.Vehicle;
import org.bukkit.event.EventHandler;
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;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.vehicle.VehicleMoveEvent;

import java.util.Set;

Expand Down Expand Up @@ -80,6 +84,22 @@ private void onPlayerMove(PlayerMoveEvent event) {
}
}

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
private void onVehicleMove(VehicleMoveEvent event) {
Vehicle vehicle = event.getVehicle();
if (LocationUtil.isNetherCeiling(vehicle.getLocation())) {
// Teleport any players riding the vehicle
for (Entity entity : vehicle.getPassengers()) {
if (entity.getType() == EntityType.PLAYER) {
this.teleportFromCeiling((Player) entity);
} else {
entity.remove(); // Remove non-player passenger
}
}
vehicle.remove(); // Remove vehicle
}
}

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
private void onBlockPlace(BlockPlaceEvent event) {
Player player = event.getPlayer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.entity.Vehicle;
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 org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.vehicle.VehicleMoveEvent;

import java.util.Arrays;

Expand Down Expand Up @@ -67,6 +71,22 @@ private void onTeleport(PlayerTeleportEvent event) {
}
}

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
private void onVehicleMove(VehicleMoveEvent event) {
Vehicle vehicle = event.getVehicle();
if (LocationUtil.isNetherCeiling(vehicle.getLocation())) {
// Teleport any players riding the vehicle
for (Entity entity : vehicle.getPassengers()) {
if (entity.getType() == EntityType.PLAYER) {
this.teleportFromCeiling((Player) entity);
} else {
entity.remove(); // Remove non-player passenger
}
}
vehicle.remove(); // Remove vehicle
}
}

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
private void onPlayerMove(PlayerMoveEvent event) {
Player player = event.getPlayer();
Expand All @@ -93,12 +113,13 @@ private void onBlockPlace(BlockPlaceEvent event) {
}

private void teleportFromCeiling(Player player) {
final Location teleportDestination = player.getLocation().clone().subtract(0.5, 7, 0.5);
player.teleport(teleportDestination);
if (player.isInsideVehicle()) player.leaveVehicle();
if (player.isGliding()) player.setGliding(false);
if (!safe_teleport_enabled) return;

final Location teleportDestination = player.getLocation().clone().subtract(0.5, 7, 0.5);
player.teleport(teleportDestination);

if (!safe_teleport_enabled) return;
// Check block above for liquid or falling block
Block blockAboveHead = teleportDestination.clone().add(0,2,0).getBlock();
if (blockAboveHead.isLiquid() || blockAboveHead.getType().hasGravity())
Expand Down

0 comments on commit 7469392

Please sign in to comment.