Skip to content

Commit

Permalink
fix safetp bug where a player could bug out of his box randomly
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Jan 18, 2023
1 parent 7edda80 commit 1868eca
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,17 @@ public static void teleportFromCeiling(Player player) {

// Create air pocket for player
Block blockAtPlayerLegs = playerTeleportedLocation.getBlock();
if (!blockAtPlayerLegs.getType().equals(Material.AIR)) {
if (
!blockAtPlayerLegs.getType().equals(Material.AIR)
&& !blockAtPlayerLegs.getType().equals(Material.PORTAL)
) {
blockAtPlayerLegs.setType(Material.AIR, false);
}
Block blockAtPlayerTorso = blockAtPlayerLegs.getRelative(BlockFace.UP);
if (!blockAtPlayerTorso.getType().equals(Material.AIR)) {
if (
!blockAtPlayerTorso.getType().equals(Material.AIR)
&& !blockAtPlayerTorso.getType().equals(Material.PORTAL)
) {
blockAtPlayerTorso.setType(Material.AIR, false);
}

Expand All @@ -51,11 +57,19 @@ public static void teleportFromCeiling(Player player) {
airPocketBlock.getRelative(BlockFace.WEST).setType(Material.NETHERRACK, false);
}

// Create block below feet if not solid
// Create block below feet if not netherrack
Block blockBelowFeet = blockAtPlayerLegs.getRelative(BlockFace.DOWN);
if (!blockBelowFeet.getType().equals(Material.NETHERRACK)) {
if (
!blockBelowFeet.getType().equals(Material.NETHERRACK)
&& !blockBelowFeet.getType().equals(Material.PORTAL)
) {
blockBelowFeet.setType(Material.NETHERRACK, false);
}

// Teleport player to the center of that block to avoid glitching out of the safe box
player.teleport(new Location(
player.getWorld(), blockAtPlayerLegs.getX()+0.5, blockAtPlayerLegs.getY(), blockAtPlayerLegs.getZ()+0.5
));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,20 @@ public static void teleportFromCeiling(Player player) {
blockAboveHead.setType(Material.NETHERRACK, false);
}


// Create air pocket for player
Block blockAtPlayerLegs = playerTeleportedLocation.getBlock();
if (!blockAtPlayerLegs.getType().equals(Material.AIR)) {
if (
!blockAtPlayerLegs.getType().equals(Material.AIR)
&& !blockAtPlayerLegs.getType().equals(Material.NETHER_PORTAL)
) {
blockAtPlayerLegs.setType(Material.AIR, false);
}
Block blockAtPlayerTorso = blockAtPlayerLegs.getRelative(BlockFace.UP);
if (!blockAtPlayerTorso.getType().equals(Material.AIR)) {
if (
!blockAtPlayerTorso.getType().equals(Material.AIR)
&& !blockAtPlayerTorso.getType().equals(Material.NETHER_PORTAL)
) {
blockAtPlayerTorso.setType(Material.AIR, false);
}

Expand All @@ -53,9 +60,17 @@ public static void teleportFromCeiling(Player player) {

// Create block below feet if not solid
Block blockBelowFeet = blockAtPlayerLegs.getRelative(BlockFace.DOWN);
if (!blockBelowFeet.isSolid()) {
if (
!blockBelowFeet.isSolid()
&& !blockBelowFeet.getType().equals(Material.NETHER_PORTAL)
) {
blockBelowFeet.setType(Material.NETHERRACK, false);
}

// Teleport player to the center of that block to avoid glitching out of the safe box
player.teleport(new Location(
player.getWorld(), blockAtPlayerLegs.getX()+0.5, blockAtPlayerLegs.getY(), blockAtPlayerLegs.getZ()+0.5
));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,17 @@ public static void teleportFromCeiling(Player player) {

// Create air pocket for player
Block blockAtPlayerLegs = playerTeleportedLocation.getBlock();
if (!blockAtPlayerLegs.getType().equals(Material.AIR)) {
if (
!blockAtPlayerLegs.getType().equals(Material.AIR)
&& !blockAtPlayerLegs.getType().equals(Material.NETHER_PORTAL)
) {
blockAtPlayerLegs.setType(Material.AIR, false);
}
Block blockAtPlayerTorso = blockAtPlayerLegs.getRelative(BlockFace.UP);
if (!blockAtPlayerTorso.getType().equals(Material.AIR)) {
if (
!blockAtPlayerTorso.getType().equals(Material.AIR)
&& !blockAtPlayerTorso.getType().equals(Material.NETHER_PORTAL)
) {
blockAtPlayerTorso.setType(Material.AIR, false);
}

Expand All @@ -53,9 +59,17 @@ public static void teleportFromCeiling(Player player) {

// Create block below feet if not solid
Block blockBelowFeet = blockAtPlayerLegs.getRelative(BlockFace.DOWN);
if (!blockBelowFeet.isSolid()) {
if (
!blockBelowFeet.isSolid()
&& !blockBelowFeet.getType().equals(Material.NETHER_PORTAL)
) {
blockBelowFeet.setType(Material.NETHERRACK, false);
}

// Teleport player to the center of that block to avoid glitching out of the safe box
player.teleport(new Location(
player.getWorld(), blockAtPlayerLegs.getX()+0.5, blockAtPlayerLegs.getY(), blockAtPlayerLegs.getZ()+0.5
));
}
}

Expand Down

0 comments on commit 1868eca

Please sign in to comment.