Skip to content

Commit

Permalink
further improve burrow
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Dec 27, 2023
1 parent c861f8a commit 50ac971
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ public void disable() {
HandlerList.unregisterAll(this);
}

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 onPlayerMove(PlayerMoveEvent event) {
Player player = event.getPlayer();
Expand All @@ -81,7 +85,7 @@ private void onPlayerMove(PlayerMoveEvent event) {
if (burrowMaterial.isOccluding() && !isSinkInBlock(burrowMaterial)) {
if (!allowSlabs || !isSlab(burrowMaterial)) {
player.damage(damageWhenMovingInBurrow);
if (shouldTeleportUp) player.teleportAsync(burrowBlock.getLocation().add(0.5, 1, 0.5));
if (shouldTeleportUp) teleportUpAndCenter(player, burrowBlock.getLocation());
}
return;
}
Expand All @@ -90,7 +94,7 @@ private void onPlayerMove(PlayerMoveEvent event) {
if (burrowMaterial.equals(Material.ENDER_CHEST) || isSinkInBlock(burrowMaterial)) {
if (playerLocation.getY() - playerLocation.getBlockY() < 0.875) {
player.damage(damageWhenMovingInBurrow);
if (shouldTeleportUp) player.teleportAsync(burrowBlock.getLocation().add(0.5, 1, 0.5));
if (shouldTeleportUp) teleportUpAndCenter(player, burrowBlock.getLocation());
}
return;
}
Expand All @@ -99,7 +103,7 @@ private void onPlayerMove(PlayerMoveEvent event) {
if (burrowMaterial.equals(Material.ENCHANTING_TABLE)) {
if (playerLocation.getY() - playerLocation.getBlockY() < 0.75) {
player.damage(damageWhenMovingInBurrow);
if (shouldTeleportUp) player.teleportAsync(burrowBlock.getLocation().add(0.5, 1, 0.5));
if (shouldTeleportUp) teleportUpAndCenter(player, burrowBlock.getLocation());
}
return;
}
Expand All @@ -110,36 +114,36 @@ private void onPlayerMove(PlayerMoveEvent event) {
if (breakAnvilInsteadOfTP) {
burrowBlock.breakNaturally();
} else {
if (shouldTeleportUp) player.teleportAsync(burrowBlock.getLocation().add(0.5, 1, 0.5));
if (shouldTeleportUp) teleportUpAndCenter(player, burrowBlock.getLocation());
}
return;
}

// Bedrock & Beacon
if (burrowMaterial.equals(Material.BEDROCK) || burrowMaterial.equals(Material.BEACON)) {
// Beacon and Indestructibles
if (burrowMaterial.equals(Material.BEACON) || ItemUtils.isIndestructible(burrowMaterial)) {
player.damage(damageWhenMovingInBurrow);
if (shouldTeleportUp) player.teleportAsync(burrowBlock.getLocation().add(0.5, 1, 0.5));
if (shouldTeleportUp) teleportUpAndCenter(player, burrowBlock.getLocation());
}
}
}

private static boolean isSinkInBlock(Material burrowBlockMaterial) {
private boolean isSinkInBlock(final Material burrowBlockMaterial) {
if (burrowBlockMaterial == null) return false;
return switch (burrowBlockMaterial) {
case SOUL_SAND, MUD, FARMLAND -> true;
default -> false;
};
}

private static boolean isAnvil(Material burrowBlockMaterial) {
private boolean isAnvil(final Material burrowBlockMaterial) {
if (burrowBlockMaterial == null) return false;
return switch (burrowBlockMaterial) {
case ANVIL, CHIPPED_ANVIL, DAMAGED_ANVIL -> true;
default -> false;
};
}

private static boolean isSlab(Material burrowBlockMaterial) {
private boolean isSlab(final Material burrowBlockMaterial) {
if (burrowBlockMaterial == null) return false;
return switch (burrowBlockMaterial) {
case
Expand All @@ -161,4 +165,4 @@ private static boolean isSlab(Material burrowBlockMaterial) {
default -> false;
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ public boolean shouldEnable() {
return AnarchyExploitFixes.getConfiguration().getBoolean("combat.prevent-burrow.enable", false);
}

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 onPlayerMove(PlayerMoveEvent event) {
Player player = event.getPlayer();
Expand All @@ -118,7 +122,7 @@ private void onPlayerMove(PlayerMoveEvent event) {
if (burrowMaterial.isOccluding() && !SINK_IN_BLOCKS.contains(burrowMaterial)) {
if (!allowSlabs || !SLAB_LIKE.contains(burrowMaterial)) {
player.damage(damageWhenMovingInBurrow);
if (shouldTeleportUp) player.teleport(burrowBlock.getLocation().add(0.5, 1, 0.5));
if (shouldTeleportUp) teleportUpAndCenter(player, burrowBlock.getLocation());
}
return;
}
Expand All @@ -127,7 +131,7 @@ private void onPlayerMove(PlayerMoveEvent event) {
if (burrowMaterial.equals(ENDER_CHEST) || SINK_IN_BLOCKS.contains(burrowMaterial)) {
if (playerLocation.getY() - playerLocation.getBlockY() < 0.875) {
player.damage(damageWhenMovingInBurrow);
if (shouldTeleportUp) player.teleport(burrowBlock.getLocation().add(0.5, 1, 0.5));
if (shouldTeleportUp) teleportUpAndCenter(player, burrowBlock.getLocation());
}
return;
}
Expand All @@ -136,7 +140,7 @@ private void onPlayerMove(PlayerMoveEvent event) {
if (burrowMaterial.equals(ENCHANTING_TABLE)) {
if (playerLocation.getY() - playerLocation.getBlockY() < 0.75) {
player.damage(damageWhenMovingInBurrow);
if (shouldTeleportUp) player.teleport(burrowBlock.getLocation().add(0.5, 1, 0.5));
if (shouldTeleportUp) teleportUpAndCenter(player, burrowBlock.getLocation());
}
return;
}
Expand All @@ -147,15 +151,15 @@ private void onPlayerMove(PlayerMoveEvent event) {
if (breakAnvilInsteadOfTP) {
burrowBlock.breakNaturally();
} else {
if (shouldTeleportUp) player.teleport(burrowBlock.getLocation().add(0.5, 1, 0.5));
if (shouldTeleportUp) teleportUpAndCenter(player, burrowBlock.getLocation());
}
return;
}

// Bedrock & Beacons
if (burrowMaterial.equals(BEDROCK) || burrowMaterial.equals(BEACON)) {
// Beacons and Indestructibles
if (burrowMaterial.equals(BEACON) || ItemUtils.isIndestructible(burrowMaterial)) {
player.damage(damageWhenMovingInBurrow);
if (shouldTeleportUp) player.teleport(burrowBlock.getLocation().add(0.5, 1, 0.5));
if (shouldTeleportUp) teleportUpAndCenter(player, burrowBlock.getLocation());
}
}
}
Expand Down

0 comments on commit 50ac971

Please sign in to comment.