From 8fd2f2ebb3781eb630befa8419a8f84849a32ad6 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Thu, 22 May 2025 17:24:04 +0700 Subject: [PATCH] refactor: just make `getBlock` return 0 when it fails --- build-number.txt | 2 +- .../chomens_bot/plugins/CorePlugin.java | 26 +++++++------------ .../chomens_bot/plugins/WorldPlugin.java | 7 ++++- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/build-number.txt b/build-number.txt index f0dfa1fe..350756b9 100644 --- a/build-number.txt +++ b/build-number.txt @@ -1 +1 @@ -3266 \ No newline at end of file +3268 \ No newline at end of file diff --git a/src/main/java/me/chayapak1/chomens_bot/plugins/CorePlugin.java b/src/main/java/me/chayapak1/chomens_bot/plugins/CorePlugin.java index 1d7c54c6..f1402b8d 100644 --- a/src/main/java/me/chayapak1/chomens_bot/plugins/CorePlugin.java +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/CorePlugin.java @@ -377,11 +377,9 @@ public class CorePlugin implements Listener { for (int y = from.getY(); y <= to.getY(); y++) { for (int z = from.getZ(); z <= to.getZ(); z++) { for (int x = from.getX(); x <= to.getX(); x++) { - try { - final int block = bot.world.getBlock(x, y, z); + final int block = bot.world.getBlock(x, y, z); - if (!isCommandBlockState(block)) return false; - } catch (final Exception ignored) { } + if (!isCommandBlockState(block)) return false; } } } @@ -400,11 +398,9 @@ public class CorePlugin implements Listener { for (int y = from.getY(); y <= to.getY(); y++) { for (int z = from.getZ(); z <= to.getZ(); z++) { for (int x = from.getX(); x <= to.getX(); x++) { - try { - final int block = bot.world.getBlock(x, y, z); + final int block = bot.world.getBlock(x, y, z); - if (isCommandBlockState(block)) return true; - } catch (final Exception ignored) { } + if (isCommandBlockState(block)) return true; } } } @@ -560,16 +556,14 @@ public class CorePlugin implements Listener { for (int y = from.getY(); y <= to.getY(); y++) { for (int z = from.getZ(); z <= to.getZ(); z++) { for (int x = from.getX(); x <= to.getX(); x++) { - try { - final int block = bot.world.getBlock(x, y, z); + final int block = bot.world.getBlock(x, y, z); - final Boolean refilled = refilledMap.get(y); + final Boolean refilled = refilledMap.get(y); - if ( - (!force && isCommandBlockState(block)) || - (refilled != null && refilled) - ) continue; - } catch (final Exception ignored) { } + if ( + (!force && isCommandBlockState(block)) || + (refilled != null && refilled) + ) continue; final boolean useChat = positionChangesPerSecond.get() > 10; diff --git a/src/main/java/me/chayapak1/chomens_bot/plugins/WorldPlugin.java b/src/main/java/me/chayapak1/chomens_bot/plugins/WorldPlugin.java index ac40ed5a..9e89b25f 100644 --- a/src/main/java/me/chayapak1/chomens_bot/plugins/WorldPlugin.java +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/WorldPlugin.java @@ -136,7 +136,12 @@ public class WorldPlugin implements Listener { public int getBlock (final int x, final int y, final int z) { final ChunkPos chunkPos = new ChunkPos(Math.floorDiv(x, 16), Math.floorDiv(z, 16)); final ChunkColumn chunk = chunks.get(chunkPos); - return chunk == null ? 0 : chunks.get(chunkPos).getBlock(x & 15, y, z & 15); + + try { + return chunk == null ? 0 : chunks.get(chunkPos).getBlock(x & 15, y, z & 15); + } catch (final Exception e) { + return 0; + } } // should this be public?