Repository navigation
Add block change listener API for third-party integrations - #69
Open
HezyyyCode wants to merge 1 commit into
Open
HezyyyCode wants to merge 1 commit into
HezyyyCode wants to merge 1 commit into
Conversation
Axiom currently exposes canBreakBlock/canPlaceBlock/checkSection, so plugins can veto edits but cannot observe them. Servers that need to audit or protect Axiom edits (logging plugins such as Prism, region protection) have no supported hook, and the only existing sink - CoreProtect - is hardcoded inside the write paths. Add Integration.BlockChangeListener, registered per plugin and dispatched from every block write path: - SetBlockBufferOperation: the batched chunk path - SetBlockPacketListener: both updateNeighbors branches - SetBlockPacketListener#setWithoutUpdates: the delayed/preventUpdates path Listeners receive the NMS BlockState before and after the change, matching the existing CoreProtectIntegration signatures, so consumers can convert with CraftBlockData.fromData if needed. Dispatch is short-circuited by hasBlockChangeListeners(), which keeps the current zero-overhead behaviour when nothing is registered, and the volatile array copy means the hot write loop never takes a lock. Listener exceptions are caught and logged so a misbehaving plugin cannot abort a world edit. Listeners are unregistered automatically in onPluginUnload, following the existing ImplServerCustomBlocks/ImplServerCustomDisplays pattern. CoreProtect integration is unchanged: it keeps its own enabled check and records exactly the same callbacks as before. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Integration.CustomIntegrationexposescanBreakBlock,canPlaceBlockandcheckSection. That lets a plugin veto an edit, but there is no way to observe one. The only existing sink is CoreProtect, and it is hardcoded inside the write paths (SetBlockBufferOperation,SetBlockPacketListener).That gap is visible on real servers. A region/plot protection plugin can deny an Axiom edit, but an auditing plugin (Prism, or any CoreProtect-style block log) cannot record one, so Axiom edits stay invisible to block history and rollbacks while WorldEdit/FAWE edits are recorded. This cannot be fixed from the consumer side: the coordinates and the old/new states only exist inside Axiom's write loop.
What this adds
Integration.BlockChangeListener:plus
registerBlockChangeListener(Plugin, BlockChangeListener),unregisterBlockChangeListener(Plugin),hasBlockChangeListeners()and an internalblockChanged(...)dispatcher.Registration is keyed by plugin name, following the existing
customIntegrationsByPluginpattern, so re-registering replaces the previous listener and a real unregister is possible.Dispatch points
All three block write paths are covered:
SetBlockBufferOperationupdateNeighborsbranches (both)SetBlockPacketListener#onReceivedelayedSetWithoutUpdates/preventUpdatesAtSetBlockPacketListener#setWithoutUpdatesEach call sits next to the existing CoreProtect calls and only fires when the state actually changed.
Properties
getBlockStateread and the dispatch are both behindhasBlockChangeListeners(), so servers with no listener take exactly today's path. CoreProtect keeps its ownisEnabled()check.volatile BlockChangeListener[], rebuilt under a lock only on register/unregister), so the hot loop just reads a field.try/catch (Throwable)and logged atSEVERE.onPluginUnloadcallsunregisterBlockChangeListener, matching the existingImplServerCustomBlocks/ImplServerCustomDisplayshandling.logRemoval/logPlacementpairs, same order, same guards.Notes for consumers
Listeners receive the raw NMS
BlockStatebefore and after the change, mirroring theCoreProtectIntegrationsignatures; convert withCraftBlockData.fromData(...)when BukkitBlockDatais needed. Callbacks run on the server thread inside the write loop, so anything that touches a database should be handed to an async queue.Verification
Existing installs behave identically: the CoreProtect path is preserved and every new read/dispatch is short-circuited when no listener is registered. CI compiles the module.
A downstream consumer is a Paper plugin that uses Prism for block history: with this hook it can record Axiom edits as first-class block actions instead of being blind to them.