Compatibility
Minecraft: Java Edition
Platforms
Tags
Creators
Details
mknockback
- Spigot / Paper / Purpur
- Java 8 bytecode, runs 1.7 through 26.2
- MIT
Purpose
Two things. Fix wrong-direction knockback for laggy players. Do some cheap movement detection that doesn't false-positive on honey blocks. That's it.
Knockback
So the thing is. You're playing. Your ping is whatever. Server thinks you're at one spot, your client thinks you're at another. Someone hits you. Server calculates knockback relative to the server-side position. You fly off sideways. Everyone thinks you're glitching. You're not. The server just used the wrong position.
mknockback looks at where your client actually thinks you are — current position plus your movement vector times ping ticks — and rotates the knockback vector to point at that. Then it fires the corrected velocity at you. Works with PacketEvents for the good path, falls back to a one-tick delayed setVelocity if you don't have it installed.
Has a multiplier. Has a minimum vertical velocity threshold so tiny nudges don't get recalculated. Skips projectiles. Skips things that aren't aimed at you.
Movement checks
Three checks. Speed. Hover. Fall. That's the whole set.
Speed check normalizes your horizontal velocity by elapsed ticks — actual time, not event count — then compares against max-speed plus a ping buffer (pingTicks × 0.3). Needs required-violations consecutive over-limit ticks before it says anything.
Hover check watches for mid-air suspension where vertical velocity stays under 0.05 for hover-ticks — default 30, about 1.5 seconds. Also checks that you were actually falling before that, so you can't just stand on a block and get flagged.
Fall check is similar to speed but downward. max-fall-speed plus ping tolerance, two consecutive violations.
The exemption list is long. Flight, creative, vehicles, elytra, ladders, vines, liquids, riptide, bubble columns, cobwebs, slow-falling, honey blocks, external knockback from attacks or explosions, wind charges, recent jump, recent teleport, recent knockback, recent join. All of it is checked and skipped before any counter increments.
Big displacement over teleport-threshold resets everything.
Config
18 keys, live-reloadable. YAML file. Change anything with /mkb config <path> <value> or the inventory GUI that only OPs see. No restart. Fields are volatile so the network thread reads the latest value without extra locking.
Dependencies
Spigot API 1.12.2 — provided, compile target only. PacketEvents 2.13.0 — soft, provided. If it's there you get the fast path and cross-version ping without NMS reflection. If it's not, the plugin degrades gracefully.
ProtocolLib, ProtocolSupport, ViaVersion, ViaBackwards, ViaRewind, Geyser — soft-declared in plugin.yml, no compile dependency on any of them.
Commands
/mkb is the entry point. Subcommands: status, on, off, restart, reload, gui, config <path> <value>, debug. Permission node is mknockback.admin, defaults to OP.
Architecture
HitInfo only stores primitives — immutable snapshot, main thread writes it, PacketEvents network thread reads it. ConfigManager holds the volatile caches. PacketEventsBridge is loaded via Class.forName() when PacketEvents is present, so the classes never load if the plugin isn't installed. VersionUtils does all the reflection shims for 1.13+ APIs.
Java 7 compatible source, no lambdas, no streams, no diamond operators, no ConcurrentHashMap.merge().
用途
就两个事。修高延迟玩家被击退方向不对的问题。跑点便宜的移动检测,别因为走蜂蜜块就误报。没了。
击退
事情是这样的。你在玩。延迟嘛,多少有点。服务端觉得你在一个位置,客户端觉得你在另一个位置。别人打你一下。服务端按它看到的位置算击退方向。你就横着飞出去了。谁看了都觉得你卡。其实没卡。是服务端用了错误的位置。
mknockback 看看你客户端到底觉得自己在哪——当前位置加上移动向量乘以延迟 tick 数——然后把击退向量旋转到那个方向上。发出修正后的速度。有 PacketEvents 就走快路径,没有就退到单 tick 延迟的 setVelocity,照样能用,只是没那么准。
有倍率可调。有个最小垂直速度阈值,太小的推挤不重新算。弹射物不管。没对着你的击退不管。
移动检测
三个检测。速度。悬空。坠落。就这些。
速度检测把你的水平速度按实际流逝的 tick 数归一化——按时间差,不按事件数——再跟 max-speed 加上延迟缓冲(pingTicks × 0.3)比。得连续 required-violations 次超标才说话。
悬空检测盯着空中悬浮,垂直速度低于 0.05 持续 hover-ticks 次——默认 30,大概 1.5 秒。还要确认你之前真的在坠落,不能站地上就报。
坠落检测跟速度差不多,不过往下。max-fall-speed 加延迟缓冲,连续两次违规。
白名单很长。飞行、创造、载具、鞘翅、梯子、藤蔓、液体、海锋、气泡柱、蛛网、缓降药水、蜂蜜块、外力击退(攻击或爆炸)、风弹、近期跳跃、近期传送、近期击退、近期登录——全部检查完毕,跳过的,计数器才不动。
位移超过 teleport-threshold 就重置一切。
配置
18 个 key,热加载。YAML 文件。/mkb config <路径> <值> 直接改,或者 OP 能看到的物品栏 GUI 里改。不用重启。字段都是 volatile,网络线程读到的就是最新值,不用额外加锁。
依赖
Spigot API 1.12.2——provided,只用作编译目标。PacketEvents 2.13.0——软依赖,provided。有它就有快路径,跨版本延迟也不用翻 NMS。没有它就优雅退化。
ProtocolLib、ProtocolSupport、ViaVersion、ViaBackwards、ViaRewind、Geyser——plugin.yml 里软声明了,编译不依赖任何一个。
指令
/mkb 是入口。子指令:status、on、off、restart、reload、gui、config <路径> <值>、debug。权限节点 mknockback.admin,默认 OP。
架构
HitInfo 只存基本类型,不可变快照。主线程写,PacketEvents 网络线程读。ConfigManager 存 volatile 缓存。PacketEventsBridge 在 PacketEvents 存在时通过 Class.forName() 加载,这样插件不存在时那些类根本不进 classloader。VersionUtils 做所有 1.13+ API 的反射垫片。
Java 7 兼容源码,没有 lambda,没有流,没有菱形操作符,没有 ConcurrentHashMap.merge()。

