Repository navigation
Conversation
A damage plugin fires it from its EntityDamageEvent handler with the final per-type damage of a hit, before writing it to the Bukkit event. Other plugins read and change the damage by type id or as a total, or cancel the hit, without depending on the damage plugin. Subclasses share its handler list, so a provider's own event can extend it. Providers register with a per-hit predicate so that other plugins can ask whether the event will fire for a hit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FaEyTumvDQFz1sVuq8xWK9
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.
Codex half of phase 4.3b of the combat restructure: a final-damage event that doesn't belong to any one plugin, in
studio.magemonkey.codex.api.damage.What it adds
FinalDamageEvent(Event,Cancellable, server thread only, plain Java, no 1.20.4+ types):EntityDamageEvent, theDamageRequest(nullable),DamageOrigin,WeaponStatsMode,getRequestedAmounts().Map<String, Double>keyed by type id.setDamage(type, amount)changes one type, and the total moves by the difference.setTotalDamage(total)scales every type by the same factor. If the total is 0, it splits evenly across the listed types; if there are no types, the amount goes toDEFAULT_TYPE("default"). Amounts must be finite and not negative.registerProvider(plugin[, Predicate<EntityDamageEvent>]),unregisterProvider,hasProvider(),willFire(EntityDamageEvent). A provider that is disabled but never unregistered is not counted.Subclassing (so
DivinityHitEvent.Resultcan extend it)getHandlers()is final and subclasses must not declaregetHandlerList(). I checked this against the 1.16.5spigot-apijar Codex compiles with.SimplePluginManager.getRegistrationClasswalksgetSuperclass()looking for a declaredgetHandlerList(). TheJavaPluginLoaderexecutor drops events that aren'tisAssignableFromthe listened class. So listeners on the subclass land in the base list and receive only subclass instances, while base listeners receive everything.getDamages(),getDamage(String)andsetDamage(String, double), all three.getTotalDamage()andsetTotalDamage(double)are built on those three, so they stay correct without overrides.Why a predicate rather than just a flag
Divinity depends on Fabled, so Fabled's
HIGHESThandler normally runs before Divinity's. A per-event "was fired" marker would arrive too late. A plain global flag would make Fabled skip hits that Divinity leaves alone, so they would lose the trigger completely. The predicate is a pure, cheap check that the provider registers at enable time. It lets Fabled ask about each hit, up front, whether the event will come.registerProvider(plugin)is shorthand for "every hit".How Divinity and Fabled will use this
DivinityHitEvent.Result extends FinalDamageEvent, drops its owngetHandlerList(), and overrides the three storage methods to map ids onto its attribute storage. InonEnableit callsFinalDamageEvent.registerProvider(this, e -> /* the hits Divinity calculates */), and inonDisableit callsunregisterProvider(this). It keeps firing the Result where it does now and honorsisCancelled(). ExistingResultlisteners keep working.MainListener.onPhysicalDamage, ifFinalDamageEvent.willFire(event), it skips firingPhysicalDamageEventand doesn't touchevent.setDamage(...). A newFinalDamageEventlistener fires the Physical Damage trigger ongetTotalDamage()and writes buffs back withsetTotalDamage(...)orsetDamage(type, …). Without a provider, behavior is unchanged.Tests
FinalDamageEventTest(25 tests) covers:SimplePluginManager+JavaPluginLoader.mvn -DskipNms -pl codex-api -am verify: 432 tests pass.Generated by Claude Code