diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/AutoLog.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/AutoLog.java index 113e995ea5..b76d882d68 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/AutoLog.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/AutoLog.java @@ -100,39 +100,46 @@ private void onTick(TickEvent.Post event) { return; } if (playerHealth <= health.get()) { - mc.player.networkHandler.onDisconnect(new DisconnectS2CPacket(Text.literal("[AutoLog] Health was lower than " + health.get() + "."))); + disconnect("Health was lower than " + health.get() + "."); if(smartToggle.get()) { this.toggle(); enableHealthListener(); } } - if(smart.get() && playerHealth + mc.player.getAbsorptionAmount() - PlayerUtils.possibleHealthReductions() < health.get()){ - mc.player.networkHandler.onDisconnect(new DisconnectS2CPacket(Text.literal("[AutoLog] Health was going to be lower than " + health.get() + "."))); + if (smart.get() && playerHealth + mc.player.getAbsorptionAmount() - PlayerUtils.possibleHealthReductions() < health.get()){ + disconnect("Health was going to be lower than " + health.get() + "."); if (toggleOff.get()) this.toggle(); } + + if (!onlyTrusted.get() && !instantDeath.get() && !crystalLog.get()) return; // only check all entities if needed + for (Entity entity : mc.world.getEntities()) { if (entity instanceof PlayerEntity && entity.getUuid() != mc.player.getUuid()) { if (onlyTrusted.get() && entity != mc.player && !Friends.get().isFriend((PlayerEntity) entity)) { - mc.player.networkHandler.onDisconnect(new DisconnectS2CPacket(Text.literal("[AutoLog] A non-trusted player appeared in your render distance."))); + disconnect("A non-trusted player appeared in your render distance."); if (toggleOff.get()) this.toggle(); break; } - if (PlayerUtils.isWithin(entity, 8) && instantDeath.get() && DamageUtils.getSwordDamage((PlayerEntity) entity, true) + if (instantDeath.get() && PlayerUtils.isWithin(entity, 8) && DamageUtils.getSwordDamage((PlayerEntity) entity, true) > playerHealth + mc.player.getAbsorptionAmount()) { - mc.player.networkHandler.onDisconnect(new DisconnectS2CPacket(Text.literal("[AutoLog] Anti-32k measures."))); + disconnect("Anti-32k measures."); if (toggleOff.get()) this.toggle(); break; } } - if (entity instanceof EndCrystalEntity && PlayerUtils.isWithin(entity, range.get()) && crystalLog.get()) { - mc.player.networkHandler.onDisconnect(new DisconnectS2CPacket(Text.literal("[AutoLog] End Crystal appeared within specified range."))); + if (crystalLog.get() && entity instanceof EndCrystalEntity && PlayerUtils.isWithin(entity, range.get())) { + disconnect("End Crystal appeared within specified range."); if (toggleOff.get()) this.toggle(); } } } + private void disconnect(String reason) { + mc.player.networkHandler.onDisconnect(new DisconnectS2CPacket(Text.literal("[AutoLog] " + reason))); + } + private class StaticListener { @EventHandler private void healthListener(TickEvent.Post event) { @@ -149,10 +156,11 @@ else if (Utils.canUpdate() private final StaticListener staticListener = new StaticListener(); - private void enableHealthListener(){ + private void enableHealthListener() { MeteorClient.EVENT_BUS.subscribe(staticListener); } - private void disableHealthListener(){ + + private void disableHealthListener() { MeteorClient.EVENT_BUS.unsubscribe(staticListener); } }