From 50ac971fea7bcd9f3316e6b79a17d86016da98e7 Mon Sep 17 00:00:00 2001 From: xGinko Date: Wed, 27 Dec 2023 03:51:53 +0100 Subject: [PATCH] further improve burrow --- .../modules/combat/Burrow.java | 26 +++++++++++-------- .../modules/combat/Burrow.java | 18 ++++++++----- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/Burrow.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/Burrow.java index 88f4a4105..940b262b6 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/Burrow.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/Burrow.java @@ -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(); @@ -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; } @@ -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; } @@ -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; } @@ -110,20 +114,20 @@ 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; @@ -131,7 +135,7 @@ private static boolean isSinkInBlock(Material burrowBlockMaterial) { }; } - 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; @@ -139,7 +143,7 @@ private static boolean isAnvil(Material burrowBlockMaterial) { }; } - private static boolean isSlab(Material burrowBlockMaterial) { + private boolean isSlab(final Material burrowBlockMaterial) { if (burrowBlockMaterial == null) return false; return switch (burrowBlockMaterial) { case @@ -161,4 +165,4 @@ private static boolean isSlab(Material burrowBlockMaterial) { default -> false; }; } -} +} \ No newline at end of file diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/Burrow.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/Burrow.java index f2fcc5cf0..c2a66de9e 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/Burrow.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/Burrow.java @@ -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(); @@ -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; } @@ -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; } @@ -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; } @@ -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()); } } }