Add cancellable GeneratorPreBuyEvent (#137) - #153
Merged
Conversation
The existing GeneratorBuyEvent fires after a purchase completes, so it cannot be used to veto a purchase. Add a new cancellable GeneratorPreBuyEvent fired at the start of StoneGeneratorManager.purchaseGenerator, before any money is withdrawn and before GeneratorBuyEvent is fired. Cancelling it aborts the purchase. This lets other plugins add their own requirements to the generator purchasing process. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01D7NWPeGXmsUJnnX42X24Rd
SonarCloud flagged the new GeneratorPreBuyEvent as duplicated code: it repeated the targetPlayer/islandUUID/generator/generatorID fields and accessors that GeneratorBuyEvent, GeneratorActivationEvent and GeneratorUnlockEvent already duplicated among themselves. Introduce an abstract GeneratorEvent base holding those common fields and their getters/setters, and have all four events extend it. The change is backwards compatible: the public accessors are simply inherited, so external listeners are unaffected. Each concrete event keeps its own HandlerList, as Bukkit requires for correct per-type routing. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01D7NWPeGXmsUJnnX42X24Rd
|
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.



Closes #137
Problem
The existing
GeneratorBuyEventis fired after a purchase has completed, so listeners cannot use it to veto a purchase. Servers/plugins that want to add their own requirements to the buying process have no hook.Change
Adds a new cancellable
GeneratorPreBuyEvent, fired at the very start ofStoneGeneratorManager.purchaseGenerator(...)— before any money is withdrawn and before the existingGeneratorBuyEventfires. If a listener cancels it, the purchase is aborted (no withdrawal, no tier granted, no post-buy event).The existing
GeneratorBuyEventis unchanged, so this is fully backwards compatible.API
Tests
GeneratorPreBuyEventTest— field population, cancellable contract, handlers.StoneGeneratorManagerTest:testPurchaseGeneratorFiresPreBuyEvent— event is fired on purchase.testPurchaseGeneratorCancelledPreBuyEventStopsPurchase— cancelling aborts the purchase (tier not added,GeneratorBuyEventnot fired).All 58 tests in the affected classes pass.
🤖 Generated with Claude Code