新区块提醒
一个 Paper 服务器插件,当玩家生成全新区块时会向他们发出通知!让你的服务器上的玩家知道他们正在探索未charted(未开发)且未掠夺的领域。这是一个轻量级、非侵入式的插件,New Chunk Alerts 利用 Paper API 的 PlayerChunkLoadEvent 与 Bukkit 的 ChunkLoadEvent 相结合,以高性能检测和通知玩家新生成的区块。

该插件最初是为了探索目的而编写的,但它也可以作为在启用 PvP 的服务器上寻找玩家的一种有趣方式!如果一名玩家在远离出生点的地方没有生成任何区块,很明显有人去过那里,并且可以通过观察 New Chunk Alerts 来追踪所谓的“区块痕迹”以找到敌人。
在新世界的最初几分钟里,每个人都会收到大量的新区块提醒!随着玩家建立基地和进行探索,新区块提醒的频率会降低,并且只会提醒你全新的地形!如果早期的提醒变得令人厌烦,玩家可以通过 /nca 命令为自己关闭它们。
要求
此插件使用了仅存在于 Paper API 中的类,因此使用的服务器软件必须是 Paper 或基于 Paper 的分支。New Chunk Alerts 目前官方支持适用于 Minecraft 版本 1.21.11 到 26.2 的稳定版 Paper 构建。
功能
- 在一个区块生成后,只有第一个符合条件的、其客户端加载了该区块的玩家才会收到提醒。一旦为该区块发送了提醒,它将从通知映射中移除,防止对同一新生成区块的后续误报。
- 不会对性能造成显著影响,特别是在小型到中型服务器上,因为下文详述的精心设计的解决方案。
- 基于事件驱动:如果有大量静止或 AFK(挂机)玩家,或者位于预生成区块内的玩家,New Chunk Alerts 将简单地忽略他们!
- 每个玩家只需运行
/nca 或 /newchunkalerts 即可切换区块提醒。
在不占用主服务器线程的情况下解决这个问题的过程比最初想象的更为复杂,因为 ChunkLoadEvent 的 getPlayersViewingChunk() 方法在生成时始终返回空列表,而 Paper 的 PlayerChunkLoadEvent 并未提供关于区块生成时间的任何信息。
为了按顺序跟踪生成的区块,并实现 O(1) 的查找和插入时间,在区块生成和玩家加载之间,使用由 HashMap 支持的 Deque 来跟踪区块。ChunkLoadEvent 监听器会将每个全新区块添加到 Deque 和 HashMap 中,而 PlayerChunkLoadEvent 监听器会在玩家启用了提醒且冷却时间已过时执行地图查找,如果存在则将其移除。相同的区块也会在下次清理时从队列中移除。
这使得插件能够在将区块发送给玩家客户端之前保留区块用于通知,而不必在每个 PlayerChunkLoadEvent 上执行 O(n) 操作。即使默认每 15 秒运行一次的清理操作也是 O(1) 操作的总和,这意味着总操作的时间由过期区块的数量决定。
不兼容项
- 预生成的世界(使用诸如 Chunky 等插件):玩家仅会收到那些
ChunkLoadEvent 的 isNewChunk() 方法返回 true 的区块的通知,因此此插件不会通知玩家那些尚未访问但已被其他插件生成的区块。
配置
首次在你的服务器上运行插件时,会生成一个默认配置文件 (plugins/NewChunkAlerts/config.yml)。这是存储已禁用提醒的玩家列表的地方,但它还包含一些其他重要的变量,服务器所有者可以对其进行调整。这些变量的默认值应该适用于大多数服务器,但你可以根据自己的喜好随意调整它们。
chunk-queue-cleanup-cooldown-ms(默认相当于 15 秒):插件在重复清理区块队列之前等待的毫秒数。减少此值将使插件更频繁地检查过期的区块。
chunk-queue-entry-expiration-time-ms(默认相当于 3 分钟):在区块生成后,将其保留在队列中的毫秒数。将此数字设置得太小会导致插件在玩家有时间触发 PlayerChunkLoadEvent 并收到提醒之前就“忘记”了新区块。此配置选项的默认值对于大多数服务器来说应该没问题。然而,如果插件似乎不起作用,并且玩家在服务器上移动非常缓慢或渲染距离非常低,增加此数字并重启服务器可能会解决问题。
max-queued-chunks(默认 = 100,000):允许在队列中的最大区块数。一旦队列超过此大小,队列中最旧的区块将被移除,直到队列大小再次低于此值。如果你的服务器非常大且玩家未能正确接收提醒,请尝试增加此数字。
notification-cooldown-ms(默认相当于 1 分钟):插件在向同一玩家发送另一个通知之前必须等待的最小毫秒数。
其他项目
查看我在 Modrinth 或 CurseForge 上的其他项目:
modrinth.com/user/timnorthrop
curseforge.com/members/timnorthrop/projects
此插件中的代码均非 AI 生成。我的所有插件也是如此。如果我需要生成式 AI 来编写简单的 Minecraft 插件,我可能真的需要开始寻找新的工作了。
New Chunk Alerts
A Paper server plugin that notifies players when they are generating brand-new chunks! Let players on your server
know when they are exploring uncharted and unlooted territory. A lightweight, non-intrusive plugin, New Chunk Alerts
takes advantage of the Paper API's PlayerChunkLoadEvent in tandem with Bukkit's ChunkLoadEvent to detect and notify
players of newly generated chunks with great performance.

The plugin was written for the purpose of exploration, but it could also be introduced as an interesting way to find
players on PvP-enabled servers! If a player isn't generating any chunks far from spawn, it's evident someone's been
there and they could follow a sort of "chunk trail" by watching the New Chunk Alerts to find enemies.
In a new world's first few minutes, everyone will get lots of New Chunk Alerts! As players establish their bases and
explore, New Chunk Alerts become less frequent and will only alert you to brand-new terrain! If early-game alerts get
annoying, players can turn them off for themselves with /nca.
Requirements
This plugin uses a class exclusive to Paper's API, so the server software used must be Paper or a fork of Paper. New
Chunk Alerts currently officially supports stable builds of Paper built for versions 1.21.11 through 26.2 of
Minecraft.
Features
- After a chunk is generated, only the first eligible player whose client loads it can be alerted. Once an alert is sent
for that chunk, it is removed from the notification map, preventing later false alerts for the same newly generated
chunk.
- Won't significantly impact performance, especially on small to medium servers, due to careful solution laid out in the
paragraphs below.
- Event-driven: if there are a ton of stationary or AFK players, or players within pre-generated chunks on your server,
New Chunk Alerts simply ignores them!
- Each player can toggle chunk alerts simply by running
/nca or /newchunkalerts.
Cracking this problem without commandeering the main server thread was more involved than initially thought, because
ChunkLoadEvent's getPlayersViewingChunk() method will always return an empty list at generation time, and Paper's
PlayerChunkLoadEvent doesn't offer any information on the recency of the chunk's generation.
To keep track of the chunks generated, in order, and to also achieve O(1) lookup and insertion times, chunks are kept
track of in a Deque backed by a HashMap between generation and player loading time. A ChunkLoadEvent listener adds
every brand-new chunk to both the Deque and the HashMap, and a PlayerChunkLoadEvent listener performs a lookup on
the map if the player has alerts enabled and the cooldown has passed, and removes it if present. The same chunk will
also be removed from the queue on the next cleanup.
This allows the plugin to hold onto chunks for notification until they are sent to the player's client, without having
to perform an O(n) operation on every PlayerChunkLoadEvent. Even cleanup, which runs every 15s by default, is a
summation of O(1) operations, meaning the total operation's timing is bound by the number of expired chunks.
Incompatibilities
- Pre-generated worlds (using plugins like Chunky, etc.): players are only alerted to chunks for which the
ChunkLoadEvent's isNewChunk() method returns true, so this plugin will not notify players of chunks that have not
yet been visited but have already been generated by another plugin.
Configuration
A default configuration file (plugins/NewChunkAlerts/config.yml) is generated upon running the plugin with your server
for the first time. This is where the list of players who've disabled alerts is stored, but it also contains a few other
important variables by default that server owners can tweak. The default values of these variables should work for the
majority of servers, but feel free to tweak them as you see fit.
chunk-queue-cleanup-cooldown-ms (default equivalent to 15s): The number of milliseconds the plugin waits before
repeating cleanup of the chunk
queue. Decreasing this will simply make the plugin check for expired chunks more often.
chunk-queue-entry-expiration-time-ms (default equivalent to 3m): The number of milliseconds to retain a chunk in the
queue after it is
generated. Making this number too small will cause the plugin to "forget" new chunks before the player has time to
trigger a PlayerChunkLoadEvent and be alerted. The default for this configuration option should be just fine for
most servers. However, if the plugin doesn't seem to be working and players move very slowly on the server or have
very low render distances, increasing this number and restarting the server may fix it.
max-queued-chunks (default = 100,000): The maximum number of chunks to allow in the queue. Once the queue exceeds this
size, the oldest
chunks in the queue are removed until the size of the queue is once again under this value. Try increasing this number
if your server is extremely large and players are not correctly receiving alerts.
notification-cooldown-ms (default equivalent to 1m): The minimum number of milliseconds the plugin must wait before
sending another
notification to the same player.
Other Projects
Check out my other projects on either Modrinth or CurseForge:
modrinth.com/user/timnorthrop
curseforge.com/members/timnorthrop/projects
None of the code in this plugin is AI-generated. The same holds true for all of my plugins. If I needed generative AI to
write simple Minecraft plugins, I would probably need to start looking for a new day job.
评论 0
登录后参与评分
还没有评论,来抢沙发吧