Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
83d329c95a | ||
|
|
9f03abbefe |
@@ -0,0 +1,9 @@
|
|||||||
|
# spigot-harvest agent entrypoint
|
||||||
|
|
||||||
|
The canonical stories, engineering guidance, and **all process documents** are in the private [SoMC OKF wiki](https://git.garvis.dev/dmg/somc-okf/src/branch/main/index.md).
|
||||||
|
|
||||||
|
Before work, read the sibling `../somc-okf/index.md`, `../somc-okf/processes/index.md`, `../somc-okf/projects/spigot-harvest/index.md`, `engineering.md` in that project section, and relevant `../somc-okf/user-stories/spigot-harvest/` stories. Also follow the parent workspace `AGENTS.md` when present.
|
||||||
|
|
||||||
|
For standalone checkouts, start at the [project page](https://git.garvis.dev/dmg/somc-okf/src/branch/main/projects/spigot-harvest/index.md) and [shared process](https://git.garvis.dev/dmg/somc-okf/src/branch/main/processes/development.md). Obtain wiki access before feature work; do not recreate a local knowledge bundle. Source builds do not require private wiki access.
|
||||||
|
|
||||||
|
Development follows [Development cycle](https://git.garvis.dev/dmg/somc-okf/src/branch/main/runbooks/development-cycle.md): approved stories, failing tests, passing implementation, verification, then source/wiki commit and push. GitOps updates are committed locally **without pushing**; only [Do release](https://git.garvis.dev/dmg/somc-okf/src/branch/main/runbooks/do-release.md) authorizes a reviewed GitOps push.
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
A Spigot 26.2 plugin providing progression-gated, connected crop harvesting and automatic replanting.
|
A Spigot 26.2 plugin providing progression-gated, connected crop harvesting and automatic replanting.
|
||||||
|
|
||||||
The approved behavior is specified in the [OKF design bundle](design/index.md).
|
The approved behavior is specified in the [SoMC OKF wiki](https://git.garvis.dev/dmg/somc-okf/src/branch/main/projects/spigot-harvest/index.md).
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
---
|
|
||||||
type: Index
|
|
||||||
title: Spigot Harvest Design
|
|
||||||
description: Entry point for the Spigot Harvest OKF knowledge bundle.
|
|
||||||
okf_version: "0.1"
|
|
||||||
---
|
|
||||||
|
|
||||||
# Spigot Harvest Design
|
|
||||||
|
|
||||||
This bundle documents per-crop progression, animated connected harvesting, automatic replanting, player feedback, administration, persistence, configuration, and delivery requirements for the Spigot Harvest plugin.
|
|
||||||
|
|
||||||
## Explore
|
|
||||||
|
|
||||||
- [User stories](user-stories/index.md)
|
|
||||||
- [Design log](log.md)
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
---
|
|
||||||
type: Log
|
|
||||||
title: Spigot Harvest Design Log
|
|
||||||
description: Chronological record of material decisions affecting the Spigot Harvest design.
|
|
||||||
---
|
|
||||||
|
|
||||||
# Spigot Harvest Design Log
|
|
||||||
|
|
||||||
## 2026-08-14 — Initial harvesting progression design
|
|
||||||
|
|
||||||
- Initial crop support includes wheat, carrots, potatoes, and beetroot, with an independent Level 0–X progression path for each crop.
|
|
||||||
- Normal crop breaking triggers auto-harvest, while sneaking bypasses auto-harvest without preventing the manually broken mature crop from contributing progress.
|
|
||||||
- Connected crops may be adjacent in any of the eight horizontal directions and differ by no more than one Y level for each connection.
|
|
||||||
- The total operation cap includes the triggering crop and doubles from 4 at Level I through 2,048 at Level X.
|
|
||||||
- Level requirements are incremental rather than cumulative and are based on the preceding level's harvest cap: a multiplier of 100 through Level V, 200 for Levels VI–VIII, 300 for Level IX, and 400 for Level X.
|
|
||||||
- Automated harvests contribute progression, execute at one crop per server tick by default, and permit only one active auto-harvest operation per player.
|
|
||||||
- Qualifying progress displays a player-toggleable boss bar that is enabled by default, persists its preference, and remains visible for five seconds after its latest update by default.
|
|
||||||
- Harvested crops are automatically replanted, remaining drops go to the player's inventory, and inventory overflow drops near the player.
|
|
||||||
- The project and delivery pipeline will follow the neighboring Spigot Base project where applicable.
|
|
||||||
|
|
||||||
## 2026-08-14 — Build and release foundation completed
|
|
||||||
|
|
||||||
- Added the Java 17 Gradle/Spigot foundation, strict compiler linting, JUnit 5 lifecycle, plugin metadata, and initial documentation.
|
|
||||||
- Added Gitea CI and semantic-release workflows with development and versioned JAR artifacts.
|
|
||||||
- Verified the foundation with `./gradlew clean check jar`.
|
|
||||||
|
|
||||||
## 2026-08-14 — Initial plugin scope completed
|
|
||||||
|
|
||||||
- Implemented independent Level 0–X progression for wheat, carrots, potatoes, and beetroot with validated configuration and atomic UUID-keyed YAML state.
|
|
||||||
- Implemented deterministic connected-crop traversal, one-operation-per-player scheduling, one-crop-per-tick harvesting, protection-event checks, automatic replanting, inventory delivery, and overflow drops.
|
|
||||||
- Added player status and boss-bar controls, five-second idle progress presentation, unlock titles, administrative inspection and mutations, offline-player lookup, and safe confirmed resets.
|
|
||||||
- Developed the progression, traversal, drops, persistence, settings, status, and administration behavior through failing-first automated tests.
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
---
|
|
||||||
type: Index
|
|
||||||
title: Spigot Harvest User Stories
|
|
||||||
description: Catalog of user stories for the Spigot Harvest plugin.
|
|
||||||
---
|
|
||||||
|
|
||||||
# Spigot Harvest User Stories
|
|
||||||
|
|
||||||
1. [US-001: Track crop harvesting progression](us-001-track-crop-harvesting-progression.md)
|
|
||||||
2. [US-002: Unlock crop auto-harvest levels](us-002-unlock-crop-auto-harvest-levels.md)
|
|
||||||
3. [US-003: Harvest connected mature crops](us-003-harvest-connected-mature-crops.md)
|
|
||||||
4. [US-004: Replant crops and distribute drops](us-004-replant-crops-and-distribute-drops.md)
|
|
||||||
5. [US-005: View crop progress and notifications](us-005-view-crop-progress-and-notifications.md)
|
|
||||||
6. [US-006: Administer player harvest progression](us-006-administer-player-harvest-progression.md)
|
|
||||||
7. [US-007: Configure and persist harvesting behavior](us-007-configure-and-persist-harvesting-behavior.md)
|
|
||||||
8. [US-008: Build and release the plugin](us-008-build-and-release-plugin.md)
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
---
|
|
||||||
type: User Story
|
|
||||||
title: "US-001: Track crop harvesting progression"
|
|
||||||
description: Track qualifying harvest activity independently for each player and supported crop.
|
|
||||||
status: done
|
|
||||||
---
|
|
||||||
|
|
||||||
# US-001: Track crop harvesting progression
|
|
||||||
|
|
||||||
As a **player**, I want my mature crop harvests tracked separately by crop so that my experience with each crop unlocks its own harvesting benefits.
|
|
||||||
|
|
||||||
## Acceptance criteria
|
|
||||||
|
|
||||||
- [x] Initial progression paths exist independently for wheat, carrots, potatoes, and beetroot.
|
|
||||||
- [x] A crop contributes progress only when it is fully grown at the time a player harvests it.
|
|
||||||
- [x] Only crops harvested by a player in Survival mode contribute progress by default.
|
|
||||||
- [x] A manually broken mature crop contributes one unit to its matching crop path.
|
|
||||||
- [x] Each mature crop collected by an auto-harvest operation contributes one unit to the player who started that operation.
|
|
||||||
- [x] Sneaking prevents a manual break from starting auto-harvest but does not prevent the mature triggering crop from contributing progress.
|
|
||||||
- [x] Immature crops, unsupported crops, and non-harvest block changes do not contribute progress.
|
|
||||||
- [x] Progress is associated with the player's UUID and survives reconnects and server restarts.
|
|
||||||
|
|
||||||
## Related
|
|
||||||
|
|
||||||
- [US-002: Unlock crop auto-harvest levels](us-002-unlock-crop-auto-harvest-levels.md)
|
|
||||||
- [US-003: Harvest connected mature crops](us-003-harvest-connected-mature-crops.md)
|
|
||||||
- [US-007: Configure and persist harvesting behavior](us-007-configure-and-persist-harvesting-behavior.md)
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
---
|
|
||||||
type: User Story
|
|
||||||
title: "US-002: Unlock crop auto-harvest levels"
|
|
||||||
description: Let players earn ten independently configured auto-harvest levels for every supported crop.
|
|
||||||
status: done
|
|
||||||
---
|
|
||||||
|
|
||||||
# US-002: Unlock crop auto-harvest levels
|
|
||||||
|
|
||||||
As a **player**, I want increasingly large auto-harvest limits as I gain experience with a crop so that repeated farming becomes progressively more efficient.
|
|
||||||
|
|
||||||
## Acceptance criteria
|
|
||||||
|
|
||||||
- [x] Every supported crop has independent levels from Level 0 through Level X.
|
|
||||||
- [x] Level 0 provides normal harvesting without connected auto-harvest.
|
|
||||||
- [x] Progress toward a level is incremental and resets to zero when that level is earned.
|
|
||||||
- [x] Excess progress from a single progression update carries into the next level rather than being discarded.
|
|
||||||
- [x] The default Level 0 to I requirement is 100 mature crops and Level I permits an operation containing at most 4 crops.
|
|
||||||
- [x] The default Level I to II requirement is 400 mature crops and Level II permits at most 8 crops.
|
|
||||||
- [x] The default Level II to III requirement is 800 mature crops and Level III permits at most 16 crops.
|
|
||||||
- [x] The default Level III to IV requirement is 1,600 mature crops and Level IV permits at most 32 crops.
|
|
||||||
- [x] The default Level IV to V requirement is 3,200 mature crops and Level V permits at most 64 crops.
|
|
||||||
- [x] The default Level V to VI requirement is 12,800 mature crops and Level VI permits at most 128 crops.
|
|
||||||
- [x] The default Level VI to VII requirement is 25,600 mature crops and Level VII permits at most 256 crops.
|
|
||||||
- [x] The default Level VII to VIII requirement is 51,200 mature crops and Level VIII permits at most 512 crops.
|
|
||||||
- [x] The default Level VIII to IX requirement is 153,600 mature crops and Level IX permits at most 1,024 crops.
|
|
||||||
- [x] The default Level IX to X requirement is 409,600 mature crops and Level X permits at most 2,048 crops.
|
|
||||||
- [x] Each requirement and operation cap can be configured independently without changing another crop's earned player state.
|
|
||||||
- [x] An auto-harvest operation uses the cap held when the operation starts; unlocking a level during that operation does not enlarge the operation already in progress.
|
|
||||||
- [x] Reaching Level X stops further level progression without preventing harvesting or status display.
|
|
||||||
|
|
||||||
## Related
|
|
||||||
|
|
||||||
- [US-001: Track crop harvesting progression](us-001-track-crop-harvesting-progression.md)
|
|
||||||
- [US-003: Harvest connected mature crops](us-003-harvest-connected-mature-crops.md)
|
|
||||||
- [US-005: View crop progress and notifications](us-005-view-crop-progress-and-notifications.md)
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
---
|
|
||||||
type: User Story
|
|
||||||
title: "US-003: Harvest connected mature crops"
|
|
||||||
description: Animate bounded harvesting across connected mature crops when a player performs a normal crop break.
|
|
||||||
status: done
|
|
||||||
---
|
|
||||||
|
|
||||||
# US-003: Harvest connected mature crops
|
|
||||||
|
|
||||||
As a **player**, I want one normal crop break to harvest a connected area at a visible pace so that unlocked farming feels powerful and satisfying without harming server performance.
|
|
||||||
|
|
||||||
## Acceptance criteria
|
|
||||||
|
|
||||||
- [x] Normally breaking a fully grown supported crop starts auto-harvest when the player has at least Level I for that crop.
|
|
||||||
- [x] Breaking while sneaking performs normal single-crop harvesting and never starts auto-harvest.
|
|
||||||
- [x] The manually broken triggering crop is included in the operation's maximum crop count.
|
|
||||||
- [x] Auto-harvest traverses only fully grown crops of the same type as the triggering crop.
|
|
||||||
- [x] A crop is connected when its horizontal position touches the current crop in any of the eight directions and its Y coordinate differs from the current crop by no more than one block.
|
|
||||||
- [x] Connectivity is evaluated per link, allowing a connected operation to follow gradual rises and drops.
|
|
||||||
- [x] Traversal is deterministic and never processes the same block more than once in an operation.
|
|
||||||
- [x] The operation stops when it reaches the player's crop-level cap or no eligible connected crop remains.
|
|
||||||
- [x] Auto-harvest processes a configurable number of crops per server tick, defaulting to one.
|
|
||||||
- [x] A player can have no more than one active auto-harvest operation at a time.
|
|
||||||
- [x] A normal crop broken while that player already has an active operation is harvested normally and may contribute progress, but it does not start or join another operation.
|
|
||||||
- [x] Auto-harvest does not force-load chunks or continue into unloaded chunks.
|
|
||||||
- [x] A crop that is no longer mature or matching when its turn arrives is skipped safely.
|
|
||||||
- [x] Crop breaks denied by the server or another protection plugin are left unchanged, yield no drops, and contribute no progress.
|
|
||||||
- [x] An operation ends safely when exhausted, cancelled, the player disconnects, or the plugin disables.
|
|
||||||
- [x] Separate players may run independent auto-harvest operations concurrently.
|
|
||||||
|
|
||||||
## Related
|
|
||||||
|
|
||||||
- [US-002: Unlock crop auto-harvest levels](us-002-unlock-crop-auto-harvest-levels.md)
|
|
||||||
- [US-004: Replant crops and distribute drops](us-004-replant-crops-and-distribute-drops.md)
|
|
||||||
- [US-007: Configure and persist harvesting behavior](us-007-configure-and-persist-harvesting-behavior.md)
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
---
|
|
||||||
type: User Story
|
|
||||||
title: "US-004: Replant crops and distribute drops"
|
|
||||||
description: Automatically replant harvested crops and deliver their remaining drops safely to the player.
|
|
||||||
status: done
|
|
||||||
---
|
|
||||||
|
|
||||||
# US-004: Replant crops and distribute drops
|
|
||||||
|
|
||||||
As a **player**, I want harvested crops replanted and their useful drops delivered to me so that auto-harvest saves repetitive work without duplicating or losing items.
|
|
||||||
|
|
||||||
## Acceptance criteria
|
|
||||||
|
|
||||||
- [x] Every crop successfully harvested by an auto-harvest operation is immediately replanted as the same crop at its minimum growth stage.
|
|
||||||
- [x] Replanting consumes one appropriate planting item from that crop's generated drops before remaining drops are delivered.
|
|
||||||
- [x] Wheat consumes one wheat seed, carrots consume one carrot, potatoes consume one potato, and beetroot consumes one beetroot seed when replanted.
|
|
||||||
- [x] A crop is not auto-harvested when its generated drops cannot supply the item required to replant it.
|
|
||||||
- [x] Drop quantities follow normal server crop-drop behavior and applicable tool enchantments where supported by the Spigot API.
|
|
||||||
- [x] Replanting does not consume an additional item from the player's existing inventory.
|
|
||||||
- [x] Remaining planting items, produce, and other generated drops are inserted into the initiating player's inventory.
|
|
||||||
- [x] Items that do not fit in the inventory are dropped safely near the initiating player rather than at every harvested crop.
|
|
||||||
- [x] No crop harvest duplicates or silently discards generated items.
|
|
||||||
- [x] If the initiating player becomes unavailable, the operation ends without harvesting further crops.
|
|
||||||
|
|
||||||
## Related
|
|
||||||
|
|
||||||
- [US-003: Harvest connected mature crops](us-003-harvest-connected-mature-crops.md)
|
|
||||||
- [US-007: Configure and persist harvesting behavior](us-007-configure-and-persist-harvesting-behavior.md)
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
---
|
|
||||||
type: User Story
|
|
||||||
title: "US-005: View crop progress and notifications"
|
|
||||||
description: Give players command and boss-bar feedback about each crop's current progression.
|
|
||||||
status: done
|
|
||||||
---
|
|
||||||
|
|
||||||
# US-005: View crop progress and notifications
|
|
||||||
|
|
||||||
As a **player**, I want to inspect crop progression and see recent progress updates so that I understand my current benefits and next unlock.
|
|
||||||
|
|
||||||
## Acceptance criteria
|
|
||||||
|
|
||||||
- [x] `/harvest` and `/harvest status` display a concise summary of all supported crop paths and the player's current boss-bar preference.
|
|
||||||
- [x] `/harvest status <crop>` displays that crop's earned level, current level-local progress, next requirement, and current and next operation caps.
|
|
||||||
- [x] Level X status clearly reports that the crop path is complete.
|
|
||||||
- [x] `/harvest bossbar enable` enables progress boss bars idempotently, and `/harvest bossbar disable` disables them idempotently.
|
|
||||||
- [x] Boss bars are enabled by default.
|
|
||||||
- [x] Disabling boss bars does not affect progression, unlock notifications, or command-based status display.
|
|
||||||
- [x] Crop names and boss-bar modes are offered through autocomplete, and invalid or extra arguments show friendly usage guidance.
|
|
||||||
- [x] Every qualifying manual or automated harvest updates a crop-specific progress boss bar for the initiating player when boss bars are enabled.
|
|
||||||
- [x] Boss-bar text identifies the crop and accurately displays current level-local progress and its requirement.
|
|
||||||
- [x] Boss-bar fill never falls below zero or exceeds 100 percent.
|
|
||||||
- [x] The boss bar remains visible for a configurable duration after the latest progress update, defaulting to five seconds.
|
|
||||||
- [x] A new qualifying update resets the boss bar's disappearance timer.
|
|
||||||
- [x] Unlocking a crop level displays a prominent one-time notification identifying the crop, new level, and new operation cap.
|
|
||||||
- [x] Unlock notifications do not repeat after reconnecting or restarting.
|
|
||||||
|
|
||||||
## Related
|
|
||||||
|
|
||||||
- [US-001: Track crop harvesting progression](us-001-track-crop-harvesting-progression.md)
|
|
||||||
- [US-002: Unlock crop auto-harvest levels](us-002-unlock-crop-auto-harvest-levels.md)
|
|
||||||
- [US-006: Administer player harvest progression](us-006-administer-player-harvest-progression.md)
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
---
|
|
||||||
type: User Story
|
|
||||||
title: "US-006: Administer player harvest progression"
|
|
||||||
description: Let administrators inspect, correct, and reset player crop progression safely through commands.
|
|
||||||
status: done
|
|
||||||
---
|
|
||||||
|
|
||||||
# US-006: Administer player harvest progression
|
|
||||||
|
|
||||||
As a **server administrator**, I want command-based controls for crop progression so that I can inspect players and correct their state safely.
|
|
||||||
|
|
||||||
## Acceptance criteria
|
|
||||||
|
|
||||||
- [x] Administrative commands require `spigotharvest.admin`, which server operators receive by default.
|
|
||||||
- [x] Administrative player arguments safely resolve online players and previously known offline players.
|
|
||||||
- [x] Player state remains keyed by UUID while retaining the latest known name for lookup and display.
|
|
||||||
- [x] `/harvestadmin status <player> [crop]` displays the selected player's crop levels, level-local progress, and any active operation.
|
|
||||||
- [x] `/harvestadmin setlevel <player> <crop> <0|I|II|III|IV|V|VI|VII|VIII|IX|X>` sets that crop's level and resets its level-local progress.
|
|
||||||
- [x] `/harvestadmin setprogress <player> <crop> <amount>` sets level-local progress and consistently evaluates any reached levels, carrying excess progress forward.
|
|
||||||
- [x] `/harvestadmin reset <player> <crop>` resets only the selected crop to Level 0 with zero progress.
|
|
||||||
- [x] `/harvestadmin reset <player> all confirm` resets all crop progression only after explicit confirmation.
|
|
||||||
- [x] A reset or level reduction cancels the player's active operation when that operation would exceed the resulting entitlement.
|
|
||||||
- [x] Every successful mutation reports exactly what changed.
|
|
||||||
- [x] Invalid requests make no partial changes and provide friendly usage guidance.
|
|
||||||
- [x] Permission-aware autocomplete offers subcommands, online and known offline players, supported crops, valid levels, and reset confirmation.
|
|
||||||
|
|
||||||
## Related
|
|
||||||
|
|
||||||
- [US-005: View crop progress and notifications](us-005-view-crop-progress-and-notifications.md)
|
|
||||||
- [US-007: Configure and persist harvesting behavior](us-007-configure-and-persist-harvesting-behavior.md)
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
---
|
|
||||||
type: User Story
|
|
||||||
title: "US-007: Configure and persist harvesting behavior"
|
|
||||||
description: Give operators validated configuration and durable storage for crop progression and harvesting behavior.
|
|
||||||
status: done
|
|
||||||
---
|
|
||||||
|
|
||||||
# US-007: Configure and persist harvesting behavior
|
|
||||||
|
|
||||||
As a **server operator**, I want harvesting behavior to be configurable and player progression to be durable so that the plugin remains predictable across restarts and server changes.
|
|
||||||
|
|
||||||
## Acceptance criteria
|
|
||||||
|
|
||||||
- [x] Configuration defines supported crops and the block material, maturity rule, and planting item for each crop.
|
|
||||||
- [x] Configuration defines every level-local requirement and operation cap independently for each supported crop.
|
|
||||||
- [x] Configuration defines eligible game modes, crops processed per tick, boss-bar idle duration, and unlock-notification timing.
|
|
||||||
- [x] Defaults match the crops, requirements, caps, one-crop-per-tick pace, Survival-only progression, and five-second boss-bar duration documented by related stories.
|
|
||||||
- [x] Requirements and caps are positive, representable, and sequentially coherent.
|
|
||||||
- [x] Processing rates and notification durations reject unsafe or nonsensical values.
|
|
||||||
- [x] Invalid required configuration prevents partial plugin initialization and produces a clear server log message.
|
|
||||||
- [x] UUID-keyed state persists latest known player names, each crop's earned level and level-local progress, and the player's boss-bar preference.
|
|
||||||
- [x] Existing player records without a boss-bar preference safely default to enabled.
|
|
||||||
- [x] Active auto-harvest operations are transient and do not resume after a restart or reconnect.
|
|
||||||
- [x] State is saved safely so a failed write does not replace valid persisted state with a partial document.
|
|
||||||
- [x] Corrupt or invalid records are handled defensively and cannot silently grant progression or larger operation caps.
|
|
||||||
- [x] Unknown forward-compatible configuration and state fields are preserved where practical.
|
|
||||||
|
|
||||||
## Related
|
|
||||||
|
|
||||||
- [US-001: Track crop harvesting progression](us-001-track-crop-harvesting-progression.md)
|
|
||||||
- [US-003: Harvest connected mature crops](us-003-harvest-connected-mature-crops.md)
|
|
||||||
- [US-006: Administer player harvest progression](us-006-administer-player-harvest-progression.md)
|
|
||||||
- [US-008: Build and release the plugin](us-008-build-and-release-plugin.md)
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
---
|
|
||||||
type: User Story
|
|
||||||
title: "US-008: Build and release the plugin"
|
|
||||||
description: Give maintainers repeatable Spigot builds, automated verification, and versioned Gitea releases.
|
|
||||||
status: done
|
|
||||||
---
|
|
||||||
|
|
||||||
# US-008: Build and release the plugin
|
|
||||||
|
|
||||||
As a **plugin maintainer**, I want automated builds and releases modeled on Spigot Base so that tested, correctly versioned artifacts can be distributed consistently.
|
|
||||||
|
|
||||||
## Acceptance criteria
|
|
||||||
|
|
||||||
- [x] The Gradle project compiles against Spigot API `26.2-R0.1-SNAPSHOT` using a Java 17 toolchain.
|
|
||||||
- [x] Compiler lint warnings fail the build.
|
|
||||||
- [x] Automated JUnit 5 tests run as part of the Gradle check lifecycle.
|
|
||||||
- [x] Pushes and pull requests build and test the plugin in Gitea Actions.
|
|
||||||
- [x] Pull requests validate conventional commit messages.
|
|
||||||
- [x] CI stores a development JAR as a workflow artifact.
|
|
||||||
- [x] Main-branch conventional commits drive semantic versioning.
|
|
||||||
- [x] A successful release builds a versioned JAR and attaches it to the corresponding Gitea release.
|
|
||||||
- [x] Build files, Gradle wrapper, workflows, and release behavior follow `../spigot-base/` where applicable while using Spigot Harvest names and identifiers.
|
|
||||||
|
|
||||||
## Related
|
|
||||||
|
|
||||||
- [US-007: Configure and persist harvesting behavior](us-007-configure-and-persist-harvesting-behavior.md)
|
|
||||||
- [User-story catalog](index.md)
|
|
||||||
@@ -51,9 +51,9 @@ public final class HarvestListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int cap = settings.progression(crop).capForLevel(level);
|
int cap = settings.progression(crop).capForLevel(level);
|
||||||
if (operations.start(player, block, crop, cap)) {
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
} else {
|
if (!operations.start(player, block, crop, cap)) {
|
||||||
|
event.setCancelled(false);
|
||||||
progress.record(player, crop, 1);
|
progress.record(player, crop, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,18 +38,38 @@ public final class HarvestOperationManager {
|
|||||||
task = Bukkit.getScheduler().runTaskTimer(plugin, this::tick, 1, 1);
|
task = Bukkit.getScheduler().runTaskTimer(plugin, this::tick, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HarvestOperationManager(
|
||||||
|
HarvestSettings settings,
|
||||||
|
HarvestProgressService progress,
|
||||||
|
BukkitTask task
|
||||||
|
) {
|
||||||
|
this.settings = settings;
|
||||||
|
this.progress = progress;
|
||||||
|
this.task = task;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean start(Player player, Block origin, CropType crop, int cap) {
|
public boolean start(Player player, Block origin, CropType crop, int cap) {
|
||||||
if (operations.containsKey(player.getUniqueId())) {
|
if (operations.containsKey(player.getUniqueId())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
World world = origin.getWorld();
|
World world = origin.getWorld();
|
||||||
BlockPosition start = position(origin);
|
BlockPosition start = position(origin);
|
||||||
List<BlockPosition> crops = ConnectedCropSearch.find(
|
final HarvestOperationPlan plan;
|
||||||
|
try {
|
||||||
|
plan = HarvestOperationPlan.create(
|
||||||
start, candidate -> isMatureLoaded(world, candidate, crop), cap);
|
start, candidate -> isMatureLoaded(world, candidate, crop), cap);
|
||||||
if (crops.isEmpty()) {
|
} catch (IllegalArgumentException exception) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
operations.put(player.getUniqueId(), new Operation(world.getUID(), crop, crops));
|
Operation operation = new Operation(world.getUID(), crop, plan.connectedCrops());
|
||||||
|
operations.put(player.getUniqueId(), operation);
|
||||||
|
if (!harvest(player, world, crop, plan.trigger(), false)) {
|
||||||
|
operations.remove(player.getUniqueId());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!operation.hasNext()) {
|
||||||
|
operations.remove(player.getUniqueId());
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,7 +108,7 @@ public final class HarvestOperationManager {
|
|||||||
}
|
}
|
||||||
int processed = 0;
|
int processed = 0;
|
||||||
while (processed < settings.cropsPerTick() && operation.hasNext()) {
|
while (processed < settings.cropsPerTick() && operation.hasNext()) {
|
||||||
harvest(player, world, operation.crop(), operation.next());
|
harvest(player, world, operation.crop(), operation.next(), true);
|
||||||
processed++;
|
processed++;
|
||||||
}
|
}
|
||||||
if (!operation.hasNext()) {
|
if (!operation.hasNext()) {
|
||||||
@@ -97,11 +117,18 @@ public final class HarvestOperationManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void harvest(Player player, World world, CropType crop, BlockPosition position) {
|
private boolean harvest(
|
||||||
|
Player player,
|
||||||
|
World world,
|
||||||
|
CropType crop,
|
||||||
|
BlockPosition position,
|
||||||
|
boolean dispatchProtectionEvent
|
||||||
|
) {
|
||||||
if (!isMatureLoaded(world, position, crop)) {
|
if (!isMatureLoaded(world, position, crop)) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
Block block = world.getBlockAt(position.x(), position.y(), position.z());
|
Block block = world.getBlockAt(position.x(), position.y(), position.z());
|
||||||
|
if (dispatchProtectionEvent) {
|
||||||
BlockBreakEvent event = new BlockBreakEvent(block, player);
|
BlockBreakEvent event = new BlockBreakEvent(block, player);
|
||||||
dispatchingBreakEvent.add(player.getUniqueId());
|
dispatchingBreakEvent.add(player.getUniqueId());
|
||||||
try {
|
try {
|
||||||
@@ -110,12 +137,13 @@ public final class HarvestOperationManager {
|
|||||||
dispatchingBreakEvent.remove(player.getUniqueId());
|
dispatchingBreakEvent.remove(player.getUniqueId());
|
||||||
}
|
}
|
||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
return;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Collection<ItemStack> generated = block.getDrops(player.getInventory().getItemInMainHand(), player);
|
Collection<ItemStack> generated = block.getDrops(player.getInventory().getItemInMainHand(), player);
|
||||||
CropDropPlan plan = CropDropPlan.create(crop, generated);
|
CropDropPlan plan = CropDropPlan.create(crop, generated);
|
||||||
if (!plan.canReplant()) {
|
if (!plan.canReplant()) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
block.setType(Material.AIR, false);
|
block.setType(Material.AIR, false);
|
||||||
block.setType(crop.blockMaterial(), false);
|
block.setType(crop.blockMaterial(), false);
|
||||||
@@ -125,6 +153,7 @@ public final class HarvestOperationManager {
|
|||||||
}
|
}
|
||||||
deliver(player, plan.remainingDrops());
|
deliver(player, plan.remainingDrops());
|
||||||
progress.record(player, crop, 1);
|
progress.record(player, crop, 1);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void deliver(Player player, List<ItemStack> drops) {
|
private static void deliver(Player player, List<ItemStack> drops) {
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package games.dmg.spigotharvest;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
/** A bounded operation split into its immediate trigger and animated remainder. */
|
||||||
|
public record HarvestOperationPlan(
|
||||||
|
BlockPosition trigger,
|
||||||
|
List<BlockPosition> connectedCrops
|
||||||
|
) {
|
||||||
|
public HarvestOperationPlan {
|
||||||
|
connectedCrops = List.copyOf(connectedCrops);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HarvestOperationPlan create(
|
||||||
|
BlockPosition trigger,
|
||||||
|
Predicate<BlockPosition> eligible,
|
||||||
|
int maximumCrops
|
||||||
|
) {
|
||||||
|
List<BlockPosition> crops = ConnectedCropSearch.find(trigger, eligible, maximumCrops);
|
||||||
|
if (crops.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("trigger must be an eligible crop");
|
||||||
|
}
|
||||||
|
return new HarvestOperationPlan(crops.get(0), crops.subList(1, crops.size()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public int totalCropCount() {
|
||||||
|
return 1 + connectedCrops.size();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package games.dmg.spigotharvest;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
final class HarvestOperationPlanTest {
|
||||||
|
@Test
|
||||||
|
void levelOneProcessesTriggerFirstAndOnlyThreeConnectedCrops() {
|
||||||
|
BlockPosition trigger = new BlockPosition(0, 64, 0);
|
||||||
|
Set<BlockPosition> mature = Set.of(
|
||||||
|
trigger,
|
||||||
|
new BlockPosition(1, 64, 0),
|
||||||
|
new BlockPosition(0, 64, 1),
|
||||||
|
new BlockPosition(-1, 64, 0),
|
||||||
|
new BlockPosition(0, 64, -1)
|
||||||
|
);
|
||||||
|
|
||||||
|
HarvestOperationPlan plan = HarvestOperationPlan.create(trigger, mature::contains, 4);
|
||||||
|
|
||||||
|
assertEquals(trigger, plan.trigger());
|
||||||
|
assertEquals(3, plan.connectedCrops().size());
|
||||||
|
assertTrue(!plan.connectedCrops().contains(trigger));
|
||||||
|
assertEquals(4, plan.totalCropCount());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
package games.dmg.spigotharvest;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.data.Ageable;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
final class TriggerCropReplantTest {
|
||||||
|
@Test
|
||||||
|
void startImmediatelyHarvestsAndReplantsTriggerExactlyOnce() {
|
||||||
|
HarvestProgressService progress = mock(HarvestProgressService.class);
|
||||||
|
BukkitTask task = mock(BukkitTask.class);
|
||||||
|
HarvestOperationManager manager = new HarvestOperationManager(
|
||||||
|
HarvestSettings.defaults(), progress, task);
|
||||||
|
Player player = mock(Player.class);
|
||||||
|
PlayerInventory inventory = mock(PlayerInventory.class);
|
||||||
|
World world = mock(World.class);
|
||||||
|
Block trigger = mock(Block.class);
|
||||||
|
Block air = mock(Block.class);
|
||||||
|
Ageable ageable = mock(Ageable.class);
|
||||||
|
UUID playerId = UUID.randomUUID();
|
||||||
|
|
||||||
|
when(player.getUniqueId()).thenReturn(playerId);
|
||||||
|
when(player.getInventory()).thenReturn(inventory);
|
||||||
|
when(inventory.getItemInMainHand()).thenReturn(new ItemStack(Material.AIR));
|
||||||
|
when(world.getUID()).thenReturn(UUID.randomUUID());
|
||||||
|
when(world.isChunkLoaded(anyInt(), anyInt())).thenReturn(true);
|
||||||
|
when(world.getBlockAt(anyInt(), anyInt(), anyInt()))
|
||||||
|
.thenAnswer(invocation -> invocation.getArgument(0, Integer.class) == 0
|
||||||
|
&& invocation.getArgument(1, Integer.class) == 64
|
||||||
|
&& invocation.getArgument(2, Integer.class) == 0 ? trigger : air);
|
||||||
|
when(air.getType()).thenReturn(Material.AIR);
|
||||||
|
when(trigger.getWorld()).thenReturn(world);
|
||||||
|
when(trigger.getX()).thenReturn(0);
|
||||||
|
when(trigger.getY()).thenReturn(64);
|
||||||
|
when(trigger.getZ()).thenReturn(0);
|
||||||
|
when(trigger.getType()).thenReturn(Material.WHEAT);
|
||||||
|
when(trigger.getBlockData()).thenReturn(ageable);
|
||||||
|
when(ageable.getAge()).thenReturn(7);
|
||||||
|
when(ageable.getMaximumAge()).thenReturn(7);
|
||||||
|
when(trigger.getDrops(any(ItemStack.class), any(Player.class))).thenReturn(List.of(
|
||||||
|
new ItemStack(Material.WHEAT), new ItemStack(Material.WHEAT_SEEDS, 2)));
|
||||||
|
when(progress.record(player, CropType.WHEAT, 1)).thenReturn(true);
|
||||||
|
|
||||||
|
assertTrue(manager.start(player, trigger, CropType.WHEAT, 4));
|
||||||
|
|
||||||
|
verify(trigger).setType(Material.AIR, false);
|
||||||
|
verify(trigger).setType(Material.WHEAT, false);
|
||||||
|
verify(ageable).setAge(0);
|
||||||
|
verify(trigger).setBlockData(ageable, false);
|
||||||
|
verify(progress).record(player, CropType.WHEAT, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user