Duel
A consented fight between two players in which the losing blow is cancelled and both duellists are restored to the health and position they started from.
A duel is a fight two players agree to, which nobody dies in. It sits inside Medieval Factions without touching the faction model at all: no Faction id appears anywhere on the record, and challenger and challenged are plain player ids.
The record is a snapshot
MfDuel stores both participants' health and position as they were when the duel began, taken at the moment the invite is accepted, along with an end time. Positions use MfPosition, so yaw and pitch are captured too; the duellists are put back facing the way they were.
Death is replaced, not survived
The interesting mechanic is in EntityDamageListener. When a participant would drop to zero health or below, the damage event is cancelled — the losing blow never lands. Both players are then cleaned up and reset: potion effects cleared, fire extinguished, health restored, teleported back. The winner is restored too, so a duel costs neither side anything material.
What changes hands is a trophy: the winner is given the loser's head — a PLAYER_HEAD carrying the loser as its owning player, named after them, with the lore "Lost in a duel against" the winner — dropped at their feet if their inventory is full. The duel row is then deleted.
Ending on time
A duel also ends when its clock runs out. A repeating task drives a boss bar per duel from the remaining time against the configured duels.duration (default PT2M, parsed as an ISO-8601 duration), and on expiry runs the identical restoration and announces a tie to players within duels.notificationDistance blocks. Both outcomes share the same ending; only the message and the head differ.
Why it is persisted
Duels go through the Service Layer to a repository and carry a version for Optimistic Locking, and the service loads them all at startup. A duel therefore outlives a restart mid-fight — and because the boss bar does not, the plugin sweeps boss bars named duel_* whose duel no longer exists during startup.
Related
Like Locked Block, a duel is player-owned state living inside a faction-shaped plugin. Its restoration path is also why an in-flight teleport is cancelled on damage, handled in the same listener.