Skip to content

Commit

Permalink
Improve AutoLog code (MeteorDevelopment#4202)
Browse files Browse the repository at this point in the history
  • Loading branch information
moritztim authored and tyrannus00 committed Apr 25, 2024
1 parent d6265fa commit b26d712
Showing 1 changed file with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
}

0 comments on commit b26d712

Please sign in to comment.