Skip to content

Fix null PacketEvents player in AFK packet limiter#25

Open
HyacinthHaru wants to merge 1 commit intoRothes:masterfrom
HyacinthHaru:master
Open

Fix null PacketEvents player in AFK packet limiter#25
HyacinthHaru wants to merge 1 commit intoRothes:masterfrom
HyacinthHaru:master

Conversation

@HyacinthHaru
Copy link
Copy Markdown

修复了 #24

修复 LimitedPacketEfficiency 中 PacketEvents 发送事件无玩家时的空指针异常(NPE)

服务器日志中反复出现来自 LimitedPacketEfficiency$PacketListeners.onPacketSend 的异常,根本原因是对 e.getPlayer() 缺少 null 检查。

摘要

  • 修复了 LimitedPacketEfficiency 在处理数据包发送时,玩家为空的边界情况。
  • 在某些发送路径中,PacketSendEvent.getPlayer() 可能返回 null,之前直接传入 limiting.contains(...),导致触发空指针异常。
  • 通过在玩家为空时提前返回,并在后续 AFK 检测和距离计算中复用已验证的玩家实例来解决问题。
  • 在避免 PacketEvents 监听器反复抛出异常的同时,保持对正常玩家相关数据包的 AFK 限流行为不变。

Copilot AI review requested due to automatic review settings March 24, 2026 08:23
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a recurring NPE in the AFK packet limiter by handling the edge case where PacketEvents fires a PacketSendEvent without an associated Bukkit Player.

Changes:

  • Add a null-check for e.getPlayer<Player>() and early-return when absent.
  • Reuse the validated player instance throughout the packet-type handling logic.
  • Refactor helper methods to take Player explicitly (instead of re-fetching from the event).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants