--- type: User Story title: "US-005: Undo the last felled tree" description: Safely restore the player's most recent automatic felling without creating replacement materials. status: done --- # US-005: Undo the last felled tree As a **player**, I want to undo my latest automatically felled tree so that I can recover from an accidental chop without duplicating its materials. ## Acceptance criteria - [x] `/treefeller undo` targets only the issuing player's most recent automatic felling. - [x] An undo record contains only blocks successfully removed by the operation, including the initiating trunk block when its original state can be captured safely. - [x] Each record retains the world, block coordinates, original block material, and original block data needed to restore orientation and other supported state. - [x] Only one undo record is retained per player; a later felling replaces the earlier record after the later operation has removed at least one eligible tree block. - [x] An undo remains available for six minutes after the felling by default, with a configurable duration. - [x] Undo performs a complete preflight before changing the world or inventory. - [x] Preflight requires every target world and chunk to be available and every target position to remain safely restorable; an occupied or otherwise unsafe position fails the whole undo. - [x] Preflight calculates the exact replacement materials required to reconstruct all recorded trunk states and requires those aggregate materials in the issuing player's inventory. - [x] If inventory is insufficient, no item or block changes occur and the error lists every missing material with its missing quantity. - [x] On success, required materials are removed exactly once and all recorded blocks are restored as one logical operation. - [x] If an unexpected restoration failure occurs after preflight, the implementation avoids a silent partial result and reports the recovery action needed to administrators. - [x] A successful undo consumes the record so that it cannot be repeated. - [x] An expired, absent, already-used, or invalid undo produces a clear message and makes no changes. - [x] Undo restores trunk blocks only; it does not restore foliage, caps, roots, drops, experience, or axe durability. - [x] Undo has a distinct player permission and never grants access to `/treefelleradmin`. ## Related - [US-003: Fell unlocked trees](us-003-fell-unlocked-trees.md) - [US-004: Control personal tree felling](us-004-control-personal-tree-felling.md) - [US-008: Configure and persist Tree Feller](us-008-configure-and-persist-tree-feller.md)