diff --git a/src/main/java/ac/grim/grimac/checks/impl/badpackets/BadPacketsZ.java b/src/main/java/ac/grim/grimac/checks/impl/badpackets/BadPacketsZ.java index cd617d93e3..d8e401e8db 100644 --- a/src/main/java/ac/grim/grimac/checks/impl/badpackets/BadPacketsZ.java +++ b/src/main/java/ac/grim/grimac/checks/impl/badpackets/BadPacketsZ.java @@ -4,6 +4,7 @@ import ac.grim.grimac.checks.CheckData; import ac.grim.grimac.checks.type.PacketCheck; import ac.grim.grimac.player.GrimPlayer; +import ac.grim.grimac.utils.anticheat.MessageUtil; import com.github.retrooper.packetevents.PacketEvents; import com.github.retrooper.packetevents.event.PacketReceiveEvent; import com.github.retrooper.packetevents.manager.server.ServerVersion; @@ -39,10 +40,6 @@ private boolean shouldExempt(final Vector3i pos) { return player.getClientVersion().isOlderThan(ClientVersion.V_1_14_4) || getBlockDamage(player, pos) < 1; } - private String formatted(Vector3i vec) { - return vec == null ? "null" : vec.x + ", " + vec.y + ", " + vec.z; - } - public void handle(PacketReceiveEvent event, WrapperPlayClientPlayerDigging dig) { if (dig.getAction() == DiggingAction.START_DIGGING) { final Vector3i pos = dig.getBlockPosition(); @@ -57,7 +54,7 @@ public void handle(PacketReceiveEvent event, WrapperPlayClientPlayerDigging dig) final Vector3i pos = dig.getBlockPosition(); if (shouldExempt(pos)) { - lastCancelledBlock = null; + lastCancelledBlock = pos; lastLastBlock = null; lastBlock = null; return; @@ -66,7 +63,7 @@ public void handle(PacketReceiveEvent event, WrapperPlayClientPlayerDigging dig) if (!pos.equals(lastBlock)) { // https://github.com/GrimAnticheat/Grim/issues/1512 if (player.getClientVersion().isOlderThan(ClientVersion.V_1_14_4) || (!lastBlockWasInstantBreak && pos.equals(lastCancelledBlock))) { - if (flagAndAlert("action=CANCELLED_DIGGING" + ", last=" + formatted(lastBlock) + ", pos=" + formatted(pos))) { + if (flagAndAlert("action=CANCELLED_DIGGING" + ", last=" + MessageUtil.toUnlabledString(lastBlock) + ", pos=" + MessageUtil.toUnlabledString(pos))) { if (shouldModifyPackets()) { event.setCancelled(true); player.onPacketCancel(); @@ -87,7 +84,7 @@ public void handle(PacketReceiveEvent event, WrapperPlayClientPlayerDigging dig) // when a player looks away from the mined block, they send a cancel, and if they look at it again, they don't send another start. (thanks mojang!) if (!pos.equals(lastCancelledBlock) && (!lastBlockWasInstantBreak || player.getClientVersion().isOlderThan(ClientVersion.V_1_14_4)) && !pos.equals(lastBlock)) { - if (flagAndAlert("action=FINISHED_DIGGING" + ", last=" + formatted(lastBlock) + ", pos=" + formatted(pos))) { + if (flagAndAlert("action=FINISHED_DIGGING" + ", last=" + MessageUtil.toUnlabledString(lastBlock) + ", pos=" + MessageUtil.toUnlabledString(pos))) { if (shouldModifyPackets()) { event.setCancelled(true); player.onPacketCancel(); diff --git a/src/main/java/ac/grim/grimac/checks/impl/scaffolding/MultiPlace.java b/src/main/java/ac/grim/grimac/checks/impl/scaffolding/MultiPlace.java index 3d5aeab809..5c34f6eef4 100644 --- a/src/main/java/ac/grim/grimac/checks/impl/scaffolding/MultiPlace.java +++ b/src/main/java/ac/grim/grimac/checks/impl/scaffolding/MultiPlace.java @@ -63,7 +63,7 @@ public void onPacketReceive(PacketReceiveEvent event) { @Override public void onPredictionComplete(PredictionComplete predictionComplete) { - if (player.getClientVersion().isNewerThan(ClientVersion.V_1_8) && !player.skippedTickInActualMovement) { + if (player.getClientVersion().isNewerThan(ClientVersion.V_1_8) && !player.skippedTickInActualMovement && predictionComplete.isChecked()) { for (String verbose : flags) { flagAndAlert(verbose); } diff --git a/src/main/java/ac/grim/grimac/utils/data/attribute/ValuedAttribute.java b/src/main/java/ac/grim/grimac/utils/data/attribute/ValuedAttribute.java index d83882aa53..c6a36071d6 100644 --- a/src/main/java/ac/grim/grimac/utils/data/attribute/ValuedAttribute.java +++ b/src/main/java/ac/grim/grimac/utils/data/attribute/ValuedAttribute.java @@ -101,29 +101,29 @@ public void recalculate() { } public double with(WrapperPlayServerUpdateAttributes.Property property) { - double d0 = property.getValue(); + double baseValue = property.getValue(); + double additionSum = 0; + double multiplyBaseSum = 0; + double multiplyTotalProduct = 1.0; List modifiers = property.getModifiers(); modifiers.removeIf(modifier -> modifier.getUUID().equals(SPRINTING_MODIFIER_UUID) || modifier.getName().getKey().equals("sprinting")); - for (WrapperPlayServerUpdateAttributes.PropertyModifier attributemodifier : modifiers) { - if (attributemodifier.getOperation() == WrapperPlayServerUpdateAttributes.PropertyModifier.Operation.ADDITION) - d0 += attributemodifier.getAmount(); - } - - double d1 = d0; - - for (WrapperPlayServerUpdateAttributes.PropertyModifier attributemodifier : modifiers) { - if (attributemodifier.getOperation() == WrapperPlayServerUpdateAttributes.PropertyModifier.Operation.MULTIPLY_BASE) - d1 += d0 * attributemodifier.getAmount(); - } - - for (WrapperPlayServerUpdateAttributes.PropertyModifier attributemodifier : modifiers) { - if (attributemodifier.getOperation() == WrapperPlayServerUpdateAttributes.PropertyModifier.Operation.MULTIPLY_TOTAL) - d1 *= 1.0D + attributemodifier.getAmount(); + for (WrapperPlayServerUpdateAttributes.PropertyModifier modifier : modifiers) { + switch (modifier.getOperation()) { + case ADDITION: + additionSum += modifier.getAmount(); + break; + case MULTIPLY_BASE: + multiplyBaseSum += modifier.getAmount(); + break; + case MULTIPLY_TOTAL: + multiplyTotalProduct *= (1.0 + modifier.getAmount()); + break; + } } - double newValue = GrimMath.clampFloat((float) d1, (float) min, (float) max); + double newValue = GrimMath.clamp((baseValue + additionSum) * (1 + multiplyBaseSum) * multiplyTotalProduct, min, max); if (setRewriter != null) { newValue = setRewriter.apply(this.value, newValue); }