-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor anti speed and tune anti KillAura
- Loading branch information
Showing
6 changed files
with
77 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/main/kotlin/com/puffy/mitigations/antispeed/MagnitudeWeighter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.puffy.mitigations.antispeed | ||
|
||
import java.util.function.BiPredicate | ||
import net.minecraft.server.network.ServerPlayerEntity | ||
import org.slf4j.LoggerFactory | ||
|
||
data class Weight( | ||
val title: String, | ||
val multiplier: Double, | ||
val predicate: BiPredicate<ServerPlayerEntity, Double> | ||
) | ||
|
||
const val MAX_FALLING_Y_DIFFERENCE = -0.5 | ||
const val MAX_ASCENDING_Y_DIFFERENCE = 0.2 | ||
const val SERVER_VELOCITY_THRESHOLD = 3 | ||
|
||
object MagnitudeWeighter { | ||
private val logger = LoggerFactory.getLogger("puffy-anti-exploit") | ||
|
||
private val weights = | ||
listOf( | ||
Weight("Elytra Bias", 0.20) { player, _ -> player.isFallFlying }, | ||
Weight("Falling Bias", 0.55) { player, lastY -> | ||
player.y - lastY < MAX_FALLING_Y_DIFFERENCE | ||
}, | ||
Weight("Elytra Flyhack Bias", 6.0) { player, lastY -> | ||
player.isFallFlying && player.y - lastY > MAX_ASCENDING_Y_DIFFERENCE | ||
}, | ||
Weight("Creative Mode Bias", 0.0) { player, _ -> player.isCreative }, | ||
Weight("Server-permitted Flight Bias", 0.25) { player, _ -> | ||
player.abilities.flying || player.abilities.allowFlying | ||
}, | ||
Weight("Server-permitted Velocity Bias", 0.25) { player, _ -> | ||
player.velocity.length() > SERVER_VELOCITY_THRESHOLD | ||
} | ||
) | ||
|
||
private fun getActiveWeightsForPlayer(player: ServerPlayerEntity, lastY: Double) = | ||
weights.filter { weight -> weight.predicate.test(player, lastY) } | ||
|
||
private fun getTotalWeightedMultiplier(weights: List<Weight>) = | ||
weights.fold(1.0) { acc, weight -> weight.multiplier * acc } | ||
|
||
fun getWeightedMagnitude( | ||
initialMagnitude: Double, | ||
player: ServerPlayerEntity, | ||
lastY: Double | ||
): Double { | ||
val activeWeights = getActiveWeightsForPlayer(player, lastY) | ||
|
||
activeWeights.forEach { weight -> | ||
logger.debug("Weight '${weight.title}' is active for player ${player.name.string}") | ||
} | ||
|
||
return initialMagnitude * getTotalWeightedMultiplier(activeWeights) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.puffy.util | ||
|
||
fun <T> MutableList<T>.trimToLength(length: Int) { | ||
if (this.count() >= length) { | ||
this.removeAt(0) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters