tinyzayninfinity

I wanna make a ai security guard plugin will you help me ?

Kodari AI
KodariAug 16 at 11:47 am 1
AISecurityGuard
A Minecraft plugin that deploys AI-powered security guards to protect player bases and territories. Guards patrol assigned areas, detect intruders and hostile mobs using configurable vision ranges, and engage threats with customizable combat behavior. Features include guard spawning via commands, persistent guard data storage, patrol waypoint systems, alert notifications to owners, and permission-based guard management. Guards utilize pathfinding AI to navigate terrain, respond to distress signals, and can be equipped with custom armor and weapons. The plugin offers configurable guard stats, damage scaling, and anti-grief protection, ensuring bases remain secure while players are offline.

Yes. I can help you build an AI security guard Minecraft plugin from scratch.

Possible features:

  • Guards patrol configured areas

  • Detect hostile mobs or suspicious players

  • Warn, chase, attack, or report intruders

  • Protect specific regions or claimed areas

  • Use Citizens NPCs or custom entities

  • Owner/admin commands to create and manage guards

  • Configurable detection range, weapons, patrol routes, and permissions

  • Alerts through chat, sounds, titles, Discord, or staff notifications

Tell me:

  1. Minecraft server software and version — Paper, Spigot, or Folia?

  2. Should guards be NPCs, actual mobs, or invisible/custom entities?

  3. What should count as suspicious behavior?

  4. Should guards attack players, or only alert staff?

  5. Do you want Citizens or another dependency?

I can then generate the complete project files.

tinyzayninfinity

Create PART 1 of a complete Minecraft Paper plugin named "SecurityGuard".

IMPORTANT:

This is the FIRST part of a larger plugin.

Build the project foundation correctly so Parts 2 and 3 can continue from it.

Do NOT create a different plugin.

The final plugin name must remain "SecurityGuard".

Use clean Java architecture and make the project compile successfully.

---

  1. PROJECT FOUNDATION

Create:

  • pom.xml
  • plugin.yml
  • config.yml
  • messages.yml
  • dialogues.yml
  • complete Java package structure

Recommended architecture:

  • SecurityGuardPlugin
  • GuardManager
  • GuardData
  • GuardType
  • GuardState
  • GuardCommand
  • GuardTabCompleter
  • GuardDatabase
  • GuardOwnership
  • GuardSpawnManager
  • GuardLifecycleManager
  • GuardGUI
  • GuardListener

Keep the architecture modular because Parts 2 and 3 will add AI, combat, dialogue, work systems and anti-duplication.

---

  1. GUARD TYPES

Support:

  1. SECURITY_VILLAGER
  2. SECURITY_IRON_GOLEM

Command:

/guard spawn <name>

Open a INVENTORY GUI where Admin can select:

  • Security Villager
  • Security Iron Golem

Also support:

/guard spawn <name> villager

/guard spawn <name> golem

Each Guard must receive a permanent unique Guard ID.

Never use display name as the permanent identifier.

---

  1. SECURITY VILLAGER

Create a custom Security Villager.

It must:

  • Have custom name
  • Have custom AI foundation
  • Have configurable health
  • Have configurable speed
  • Turn its head toward players
  • Be controllable by GuardManager
  • Not trade normally
  • Not randomly wander
  • Support future combat/dialogue/work systems

Prepare the architecture for arm movement and combat animations in Part 2.

---

  1. SECURITY IRON GOLEM

Create a Security Iron Golem.

It must:

  • Have custom name
  • Be controlled by GuardManager
  • Support custom health
  • Support custom damage
  • Support custom speed
  • Support future combat AI
  • Support owner protection
  • Support future patrol system

---

  1. OWNERSHIP

Admin permission:

guard.admin

Owner permission:

guard.owner

Admin command:

/guard giveowner <guard> <player>

Store Owner UUID.

Never store ownership only by player name.

Admin can control every Guard.

Owner can control only their own Guards.

An Owner attempting to control another player's Guard must receive:

"You do not own this Guard."

---

  1. BASIC COMMANDS

Implement:

/guard help /guard list /guard spawn <name> /guard spawn <name> villager /guard spawn <name> golem /guard remove <guard> /guard removeall /guard giveowner <guard> <player> /guard owner <guard> /guard setname <guard> <name> /guard info <guard>

Every command must have permission and ownership validation.

---

  1. EXACT STAND HERE SYSTEM

Implement:

/guard stand here <guard>

When the command sender executes it:

  • Read exact world
  • Read X
  • Read Y
  • Read Z
  • Read yaw
  • Read pitch

Save this as the Guard's permanent Stand Location.

Then physically move the Guard to that location.

After reaching it:

  • Stop movement
  • Enter STAND state
  • Face saved direction
  • Stay there
  • Do not randomly wander

Also implement:

/guard stand <guard>

→ Return to saved Stand Location.

/guard clearstand <guard>

→ Remove saved Stand Location.

The Stand Location must survive server restart.

---

  1. MOVEMENT FOUNDATION

Implement:

/guard follow <guard>

/guard come <guard>

/guard stay <guard>

/guard stop <guard>

/guard return <guard>

For Part 1, create the command/state architecture.

Actual advanced pathfinding will be completed in Part 2.

---

  1. GUARD STATES

Create the complete state enum:

  • IDLE
  • STAND
  • PATROL
  • FOLLOW
  • COME
  • INVESTIGATE
  • TALK
  • WARN
  • PROTECT
  • CHASE
  • ATTACK
  • MINE
  • GATHER
  • RETURN
  • ALERT

Create a proper state-management system.

Do not allow multiple conflicting states to control the same Guard simultaneously.

Prepare priority handling for Part 2.

---

  1. BASIC GUARD INVENTORY GUI

Create a Guard Control INVENTORY GUI.

Sections:

MOVEMENT:

  • Follow
  • Come
  • Stay
  • Stand
  • Return
  • Stop

SECURITY:

  • Protect
  • Attack
  • Target
  • Trust
  • Ignore
  • Alert

WORK:

  • Mine
  • Gather
  • Return

AI:

  • Chat
  • Dialogue
  • Silence

EQUIPMENT:

  • Equipment

INFORMATION:

  • Guard Info

The buttons can initially call the corresponding state/command methods.

Part 2 will connect advanced AI behaviour.

---

  1. BASIC DATABASE

Use SQLite.

Create a "guards" table containing at minimum:

  • guard_id
  • guard_uuid
  • name
  • type
  • owner_uuid
  • world
  • x
  • y
  • z
  • yaw
  • pitch
  • stand_world
  • stand_x
  • stand_y
  • stand_z
  • stand_yaw
  • stand_pitch
  • state
  • health
  • damage
  • speed
  • invincible
  • chat_enabled
  • dialogue_enabled
  • active
  • entity_uuid

Use UNIQUE constraints for:

  • guard_id
  • guard_uuid

Use UUIDs for players.

Use prepared statements.

Use safe transactions.

---

  1. PERSISTENT ENTITY IDENTIFICATION

Every Guard entity must have PersistentDataContainer values:

securityguard_id securityguard_uuid securityguard_type

Never identify Guards only by their name.

The Guard ID must remain permanent.

---

  1. BASIC EQUIPMENT FOUNDATION

Prepare equipment support for:

  • Helmet
  • Chestplate
  • Leggings
  • Boots
  • Main Hand
  • Off Hand

Create the data structure and INVENTORY GUI support.

Actual advanced equipment behaviour can be expanded in Part 2.

---

  1. DAMAGE FOUNDATION

Implement:

/guard invincible <guard> on /guard invincible <guard> off

Also create configuration:

guard-protection: owner-can-damage: false trusted-can-damage: false other-players-can-damage: true

Part 2 will expand damage/combat behaviour.

---

  1. TAB COMPLETION

Implement tab completion for:

  • Commands
  • Guard names
  • Online players
  • Guard types
  • on/off

Only show appropriate Guards to Owners.

Admins can see all Guards.

---

  1. IMPORTANT ARCHITECTURE RULE

Only "GuardManager" / "GuardSpawnManager" may create Guard entities.

No other listener, command or AI class may directly spawn another Guard.

This rule is critical for preventing duplication in Part 3.

---

  1. PART 1 ACCEPTANCE TEST

Before finishing Part 1, verify:

  • Plugin compiles
  • "/guard spawn" works
  • Villager Guard works
  • Iron Golem Guard works
  • Owner assignment works
  • Ownership permissions work
  • "/guard stand here" works
  • Stand location saves
  • "/guard info" works
  • "/guard list" works
  • SQLite saves data
  • Server restart does not lose Guard data
  • Tab completion works
  • No command can bypass ownership
  • Guard IDs are unique

Do not move to fake/incomplete implementations.

Keep all systems ready for Part 2.

Kodari AI
KodariAug 16 at 11:52 am 4
SecurityGuard
SecurityGuard is a Minecraft Paper plugin that allows admins to spawn and manage security guards (Villagers and Iron Golems) with persistent data storage. It features a comprehensive command system for guard management, ownership control, exact stand locations, movement commands, and a state management system. The plugin includes a GUI-based control panel, SQLite database for persistence, and equipment/damage foundations. Guards have unique IDs, custom AI foundations, and are designed to support future combat, dialogue, and work systems.
  1. Create the Maven/Paper project and resource configuration.

  2. Add persistent guard models, SQLite storage, ownership, lifecycle, and spawn management.

  3. Add commands, tab completion, control GUI, entity protection, and restart restoration.

The foundation files are in place. I’m making the remaining wiring corrections now so the GUI has an entry point and world-load restoration calls the lifecycle manager directly.

Created Part 1 of the SecurityGuard Paper plugin foundation.

Included:

  • Maven project with Paper API, XSeries, SQLite, and Lombok

  • Persistent SQLite guards table with unique Guard IDs and UUIDs

  • SECURITY_VILLAGER and SECURITY_IRON_GOLEM

  • Persistent entity metadata:

    • securityguard_id

    • securityguard_uuid

    • securityguard_type

  • Guard ownership using UUIDs

  • Admin and owner permission validation

  • Guard lifecycle and restart restoration

  • Exact /guard stand here <guard> location storage

  • Guard states with priority handling

  • Custom health, speed, damage, names, AI foundations, and equipment support

  • Invincibility and damage protection configuration

  • Guard Control GUI

  • Spawn-type selection GUI

  • Commands and tab completion

  • Entity protection and target prevention

  • Future animation controller foundation

  • /guard menu <guard> for opening the control GUI

Main command examples:

Plain Text
/guard spawn <name>
/guard spawn <name> villager
/guard spawn <name> golem
/guard stand here <guard>
/guard stand <guard>
/guard clearstand <guard>
/guard follow <guard>
/guard come <guard>
/guard stay <guard>
/guard stop <guard>
/guard return <guard>
/guard giveowner <guard> <player>
/guard invincible <guard> on
/guard invincible <guard> off
/guard menu <guard>
tinyzayninfinity

Continue the EXISTING "SecurityGuard" plugin from Parts 1 and 2.

Do NOT create a new plugin.

This part is extremely important because the previous implementation had a serious duplication bug where one Guard could become hundreds or even 1000+ Guards after a player left/rejoined or after lifecycle events.

Completely eliminate this class of bug.

---

  1. GOLDEN RULE

The plugin MUST enforce:

**ONE DATABASE GUARD RECORD

ONE PERMANENT GUARD ID

ONE ACTIVE GUARD ENTITY**

This rule must never be violated.

Maximum active entity count for one Guard ID:

1

---

  1. PERMANENT IDENTITY

Every Guard must have:

  • Permanent Guard ID
  • Permanent Guard UUID
  • Entity UUID
  • Owner UUID

Every entity must contain:

securityguard_id

securityguard_uuid

securityguard_type

inside PersistentDataContainer.

Never identify a Guard only by display name.

---

  1. CENTRALIZED SPAWN SYSTEM

Only:

"GuardSpawnManager"

may create Guard entities.

No:

  • PlayerJoinEvent
  • PlayerQuitEvent
  • ChunkLoadEvent
  • AI task
  • Combat task
  • Patrol task
  • INVENTORY GUI
  • Reload task

may directly spawn a Guard.

All entity creation must pass through GuardSpawnManager.

---

  1. ONE-GUARD SPAWN LOCK

Before spawning:

  1. Check Guard ID.
  2. Check database.
  3. Check active Guard cache.
  4. Search loaded entities for matching "securityguard_id".
  5. If matching entity exists:

- Reuse it. - DO NOT spawn another.

  1. If no entity exists:

- Acquire spawn lock. - Check again. - Spawn exactly one. - Save entity UUID. - Release lock.

If multiple events request spawning simultaneously, only one request may create the entity.

---

  1. PLAYER QUIT BUG FIX

This is mandatory.

Player logout MUST NEVER create a Guard.

When Owner leaves:

  • Do not spawn another Guard.
  • Do not clone Guard.
  • Do not recreate Guard.
  • Do not create database record.
  • Existing Guard remains associated with the Owner UUID.

When Owner rejoins:

  • Reuse the existing Guard.
  • Never create another one.

The number of Guards must remain unchanged.

Example:

Before logout:

Guard1 = 1 entity.

Owner leaves.

Expected:

Guard1 = 1 entity.

Owner rejoins.

Expected:

Guard1 = 1 entity.

Never:

Guard1 = 2, 10, 100 or 1000.

---

  1. CHUNK LOAD PROTECTION

When chunk loads:

  • Search for existing Guard entity.
  • Match by "securityguard_id".
  • Reuse existing entity.
  • Never blindly spawn.

Chunk loading must NEVER multiply Guards.

---

  1. CHUNK UNLOAD PROTECTION

When chunk unloads:

  • Save required state.
  • Do not create replacement entities.
  • Do not repeatedly schedule respawn.
  • Do not duplicate on next chunk load.

---

  1. SERVER RESTART

On startup:

  1. Load all Guard database records.
  2. Scan loaded entities.
  3. Match by Guard ID.
  4. If exactly one entity exists:

- Reuse it.

  1. If zero entities exist:

- Spawn exactly one if Guard should be active.

  1. If more than one exists:

- Keep exactly one. - Remove duplicates.

  1. Save entity UUID.
  2. Verify database/entity consistency.

If server had:

10 Guards before restart

it must have:

10 Guards after restart.

Never 20.

Never 100.

Never 1000.

---

  1. DUPLICATE SCANNER

Implement a startup and periodic duplicate scanner.

For each Guard ID:

Find all entities containing:

securityguard_id = Guard ID

If:

0 entities: → Safely restore one if required.

1 entity: → Valid.

2+ entities: → Keep one valid entity. → Remove all duplicates. → Log the event.

Example console:

"[SecurityGuard] Duplicate detected for Guard1. Removed 999 duplicate entities."

The scanner must NEVER create another duplicate while cleaning duplicates.

---

  1. PLUGIN RELOAD

Plugin reload/reinitialization must NOT create duplicates.

If existing entity is found:

Reuse it.

Do not blindly recreate entities.

Cancel old AI tasks before registering new ones.

Prevent multiple AI task instances from controlling one Guard.

---

  1. SERVER CRASH RECOVERY

Use SQLite transactions.

Prevent partial writes from creating duplicate Guard records.

On startup:

  • Validate records.
  • Validate entities.
  • Repair mismatches.
  • Ensure exactly one active entity per active Guard.

---

  1. GUARD DEATH

Configuration:

guard-death: respawn: false respawn-delay: 10

If respawn is false:

  • Mark Guard inactive/dead.
  • Do not automatically respawn repeatedly.

If respawn is true:

  • Wait configured delay.
  • Verify no existing entity with same Guard ID.
  • Spawn exactly one replacement.
  • Save entity UUID.
  • Restore Guard data.

Never create multiple replacements.

---

  1. GUARD REMOVAL

When:

/guard remove <guard>

Do all of the following:

  • Remove entity.
  • Stop AI tasks.
  • Stop navigation.
  • Stop combat tasks.
  • Remove active cache.
  • Remove/disable database record.
  • Remove scheduled respawn.
  • Remove spawn lock.
  • Prevent restoration.

After server restart:

Removed Guard MUST NOT return.

---

  1. REMOVEALL

When:

/guard removeall

must:

  • Stop all AI
  • Stop all pathfinding
  • Stop all combat
  • Cancel scheduled tasks
  • Remove every Guard entity
  • Remove/disable every database record
  • Clear active Guard cache
  • Clear lifecycle state

After restart:

No removed Guards may return.

---

  1. ENTITY UUID RECOVERY

Store entity UUID in database.

When loading:

If stored entity exists:

→ Verify its "securityguard_id".

If entity no longer exists:

→ Search all loaded entities by Guard ID.

If none exists:

→ Spawn exactly one.

Never blindly trust an old entity UUID.

Never blindly spawn before scanning.

---

  1. DATABASE CONSTRAINTS

Database must enforce uniqueness.

Use:

UNIQUE(guard_id)

UNIQUE(guard_uuid)

Never allow duplicate Guard records.

Use transactions for:

  • Creation
  • Ownership change
  • Removal
  • Respawn
  • State changes

---

  1. ACTIVE GUARD CACHE

Maintain one authoritative in-memory cache:

Guard ID → Guard instance

If a Guard ID already exists in the cache:

Do NOT create another Guard instance.

If an event tries to register another entity with the same ID:

Reject it and remove the duplicate entity.

---

  1. AI TASK DUPLICATION

Prevent multiple AI schedulers controlling the same Guard.

Each Guard must have a controlled task manager.

Before creating a new task:

  • Cancel incompatible old task.
  • Check current state.
  • Check task ID.
  • Prevent duplicate scheduled tasks.

A single Guard must never have:

  • 100 patrol tasks
  • 100 follow tasks
  • 100 combat tasks

running simultaneously.

---

  1. PLAYER OWNERSHIP SECURITY

Every Owner command must verify:

Sender has "guard.admin"

OR

Sender UUID == Guard Owner UUID.

Never trust Guard name or client input.

Prevent:

  • Ownership spoofing
  • Unauthorized INVENTORY GUI use
  • Unauthorized command execution

---

  1. ANTI-DUPLICATION ACCEPTANCE TEST

Perform these tests before finalizing.

TEST 1

Spawn:

Guard1

Expected:

1 entity.

TEST 2

Owner leaves.

Expected:

1 entity.

TEST 3

Owner rejoins.

Expected:

1 entity.

TEST 4

Restart server.

Expected:

1 entity.

TEST 5

Reload chunk.

Expected:

1 entity.

TEST 6

Reload plugin.

Expected:

1 entity.

TEST 7

Trigger multiple simultaneous lifecycle events.

Expected:

1 entity.

TEST 8

Artificially create duplicate entities with the same Guard ID.

Expected:

Duplicate scanner removes all except one.

TEST 9

Remove Guard.

Expected:

0 entities.

Restart.

Expected:

0 entities.

TEST 10

Enable respawn.

Kill Guard.

Expected:

Exactly 1 replacement.

TEST 11

Spawn 10 different Guards.

Restart server.

Expected:

Exactly 10 Guards.

TEST 12

Owner A attempts to control Owner B's Guard.

Expected:

Permission denied.

---

  1. PERFORMANCE FINALIZATION

Verify:

  • No expensive operation every tick
  • No infinite scheduler
  • No duplicate scheduler
  • No synchronous heavy database operations
  • No unnecessary entity spawning
  • No unnecessary teleportation
  • Efficient player scanning
  • Efficient pathfinding
  • Efficient duplicate scanning

Make scan intervals configurable.

---

  1. FINAL FILES

Ensure the final project contains all required:

  • pom.xml
  • plugin.yml
  • config.yml
  • messages.yml
  • dialogues.yml
  • Java source
  • SQLite database implementation
  • Commands
  • INVENTORY GUI
  • AI
  • Pathfinding
  • Combat
  • Dialogue
  • Patrol
  • Protection
  • Work system
  • Equipment
  • Ownership
  • Lifecycle manager
  • Spawn manager
  • Duplicate detector
  • Persistence
  • Permissions
  • Tab completion

---

  1. FINAL QUALITY CHECK

Before declaring the plugin complete:

  1. Compile the entire project.
  2. Fix all compilation errors.
  3. Fix all missing imports.
  4. Fix all missing classes.
  5. Fix all missing methods.
  6. Verify plugin.yml commands.
  7. Verify permissions.
  8. Verify SQLite schema.
  9. Verify startup loading.
  10. Verify shutdown saving.
  11. Verify Guard ownership.
  12. Verify exact Stand Location.
  13. Verify Villager Guard.
  14. Verify Iron Golem Guard.
  15. Verify AI states.
  16. Verify dialogue.
  17. Verify combat.
  18. Verify equipment.
  19. Verify patrol.
  20. Verify work system.
  21. Verify player logout.
  22. Verify player login.
  23. Verify chunk load/unload.
  24. Verify server restart.
  25. Verify plugin reload.
  26. Verify Guard removal.
  27. Verify duplicate cleanup.

The most important final requirement is:

A Guard must NEVER multiply because of player leave/join, chunk loading, server restart, plugin reload, death, AI tasks, or any other lifecycle event.

The final architecture must guarantee:

1 Guard ID → 1 database record → 1 active entity → 1 AI controller.

Only "/guard spawn" can create a new Guard.

Only "GuardSpawnManager" can create the entity.

Everything else must reuse the existing Guard.

The plugin is NOT complete until this rule and every acceptance test pass.

Kodari AI
KodariAug 16 at 12:03 pm 4
  1. Audit the existing SecurityGuard lifecycle, spawn, persistence, command, and listener code for every entity-creation path.

  2. Replace spawning with a single locked, duplicate-aware GuardSpawnManager flow.

  3. Add startup/periodic duplicate reconciliation, safe death/removal handling, and task cancellation.

  4. Update configuration/schema/resources and verify project-wide references for compilation consistency.

Part 3 anti-duplication hardening is implemented in the existing SecurityGuard plugin.

  • GuardSpawnManager is now the only class that directly creates guard entities.

  • Added per-Guard spawn locks and idempotent ensureSingle(...) spawning.

  • Existing entities are discovered through PersistentDataContainer values, not names or stale UUIDs.

  • Duplicate entities are removed while preserving one valid entity.

  • Added active entity registration keyed by permanent Guard ID.

  • Added orphan entity cleanup for removed or invalid database records.

  • Added startup and configurable periodic duplicate reconciliation.

  • Added chunk-load restoration and chunk-unload state saving without replacement spawning.

  • Player login/logout paths do not spawn or recreate guards.

  • Plugin reload reuses existing entities and prevents duplicate task registration.

  • Guard death now supports configurable respawn with one scheduled replacement.

  • Guard removal cancels respawn tasks, clears caches, removes all matching entities, and deletes the database record.

  • /guard removeall uses the same duplicate-safe removal flow.

  • Added a unique SQLite index for non-null entity_uuid values.

  • Improved SQLite deletion transactions and malformed-record validation.

  • Added GUI ownership validation so unauthorized players cannot use another owner’s Guard GUI.

  • Added configuration:

YAML
duplicate-scan-interval-ticks: 200

guard-death:
  respawn: false
  respawn-delay: 10

Static verification confirms that the only direct World.spawn(...) calls are inside GuardSpawnManager; no join, quit, chunk, GUI, or lifecycle code directly creates entities.

tinyzayninfinity

Update the plugin CRITICAL FIX — GUARD MUST ACTUALLY EXECUTE OWNER ORDERS

The Guard must NEVER only reply in chat.

Whenever the Owner gives an order, the plugin must:

  1. Parse the order.
  2. Convert it into a real GuardAction.
  3. Assign that action to the Guard's ActionController.
  4. Cancel conflicting previous actions.
  5. Physically execute the action.
  6. Continuously monitor whether the action is completed.
  7. Report success/failure to the Owner.

Every action must have a real executable implementation.

Create:

GuardAction GuardActionType GuardActionController GuardTask GuardNavigation GuardInteractionController

Supported actions:

FOLLOW COME STAY STAND RETURN PATROL PROTECT ATTACK DEFEND MOVE_TO TALK WARN INVESTIGATE MINE GATHER STOP

IMPORTANT:

DO NOT implement commands as chat-only responses.

For example:

Owner: "/guard command Guard1 follow me"

Guard response: "Understood."

Then Guard MUST ACTUALLY start following the Owner.

Owner: "/guard command Guard1 come here"

Guard MUST physically navigate to the Owner.

Owner: "/guard command Guard1 stand here"

Guard MUST physically walk to the saved location and stand there.

Owner: "/guard command Guard1 attack Steve"

Guard MUST locate Steve, navigate toward Steve and attack Steve.

Owner: "/guard command Guard1 protect me"

Guard MUST enter PROTECT state and continuously monitor nearby threats against the Owner.

Owner: "/guard command Guard1 patrol"

Guard MUST physically patrol the configured area.

Owner: "/guard command Guard1 stop"

Guard MUST immediately cancel the current action and stop movement.

The Guard's chat response must happen ONLY AFTER the action has successfully been accepted by the ActionController.

Example:

Owner: "Follow me."

Guard: "Understood. Following you."

Then immediately execute FOLLOW.

If an action cannot be executed, Guard must say:

"I can't complete that order."

and the plugin must log the exact reason.

NEVER say "Understood" when the action was not actually started.

==================================================

ACTION STATE MACHINE

Every Guard must have exactly ONE primary active action.

Example:

IDLE FOLLOWING MOVING PATROLLING PROTECTING ATTACKING INVESTIGATING TALKING MINING RETURNING STOPPED

When a new Owner order arrives:

  1. Validate permission.
  2. Parse order.
  3. Check whether action is supported.
  4. Cancel conflicting action.
  5. Create new GuardAction.
  6. Assign it to ActionController.
  7. Start execution.
  8. Update GuardState.
  9. Continuously monitor execution.

Do not create multiple simultaneous controllers for one Guard.

==================================================

ACTION PRIORITY

Owner command = highest priority.

Priority:

EMERGENCY OWNER COMMAND > OWNER COMMAND > PROTECT > COMBAT > INVESTIGATION > DIALOGUE > PATROL > IDLE

If Owner says:

"stop"

the Guard must immediately cancel:

  • Patrol
  • Follow
  • Mining
  • Combat
  • Investigation
  • Navigation

and enter STOPPED state.

==================================================

FOLLOW IMPLEMENTATION

FOLLOW must continuously monitor the Owner.

If Owner moves:

Guard follows.

If Owner stops:

Guard stops at a reasonable distance.

If Owner becomes too far:

Guard navigates toward Owner.

If Owner teleports:

Guard safely handles the teleport and resumes following.

If Owner logs out:

Cancel FOLLOW action safely.

Do NOT spawn another Guard.

==================================================

COME IMPLEMENTATION

COME means:

Move to the Owner's current location.

The Guard must physically navigate there.

After reaching the Owner:

Stop.

Do NOT continuously follow unless FOLLOW was explicitly requested.

==================================================

STAND IMPLEMENTATION

STAND means:

Move to saved Stand Location.

After reaching it:

Stop movement.

Face saved direction.

Remain there.

Do not wander.

==================================================

PATROL IMPLEMENTATION

PATROL must generate actual patrol destinations inside the configured area.

Guard physically walks between patrol points.

When one point is reached:

Choose another valid point.

Do not teleport between points.

Do not leave the configured patrol area.

==================================================

ATTACK IMPLEMENTATION

When ordered:

"/guard command Guard1 attack Steve"

the plugin must:

  1. Find Steve.
  2. Validate that Steve is a valid target.
  3. Set Steve as current target.
  4. Navigate toward Steve.
  5. Enter ATTACK state.
  6. Attack using equipped weapon.
  7. Continue until:

- Target dies, - Target disconnects, - Owner cancels, - Target becomes invalid, - Maximum chase distance is exceeded.

Afterward:

Return to previous valid state or Owner/Stand Location.

==================================================

PROTECT IMPLEMENTATION

When ordered:

"protect me"

the Guard must:

  1. Set Owner as protected player.
  2. Enter PROTECT state.
  3. Monitor nearby hostile activity.
  4. Detect attackers.
  5. Target the attacker.
  6. Navigate toward attacker.
  7. Defend Owner.
  8. Stop combat when threat disappears.
  9. Return to Owner.

==================================================

STOP IMPLEMENTATION

STOP is an emergency action.

When Owner executes:

"/guard stop Guard1"

or says:

"stop"

the Guard must:

  • Cancel navigation.
  • Cancel patrol.
  • Cancel follow.
  • Cancel mining.
  • Cancel combat.
  • Cancel investigation.
  • Cancel dialogue task if appropriate.
  • Stop movement.
  • Clear current temporary target.
  • Enter STOPPED state.

No background task may immediately restart the previous action.

==================================================

ACTION COMPLETION

Every action must have:

  • start()
  • tick/update()
  • isComplete()
  • cancel()
  • cleanup()

When an action completes:

  1. Remove it from ActionController.
  2. Cancel its scheduler/task.
  3. Update GuardState.
  4. Execute configured post-action behaviour.

Never leave completed tasks running in the background.

==================================================

IMPORTANT IMPLEMENTATION RULE

Do NOT use fake actions such as:

sendMessage("I will follow you");

without actual movement/navigation.

Every command must produce a real in-game effect.

The final plugin must be tested manually:

FOLLOW → Guard follows.

COME → Guard comes.

STAND → Guard walks to stand location.

PATROL → Guard patrols.

ATTACK → Guard attacks.

PROTECT → Guard protects.

STOP → Guard actually stops.

MINE → Guard actually performs the configured mining/work action.

If any command only produces chat text without executing the corresponding action, the implementation is considered FAILED.

Kodari AI
KodariAug 16 at 2:08 pm 8

Plan:

  1. Trace the existing Guard command, state, movement, and scheduling flow.

  2. Add the action model/controller, executable task lifecycle, navigation, and interaction handling.

  3. Wire every supported order through the controller, including cancellation, monitoring, and owner feedback.

  4. Verify registrations, configuration dependencies, and cross-file method consistency.

The current plugin only persists enum states and teleports on return; it has no action lifecycle or movement tick. I’m replacing that state-only path with one controller per Guard and a single server tick driving real navigation, combat, protection, patrol, and work actions.

Implemented the Guard execution system.

  • Added GuardAction, GuardActionType, GuardTask, GuardActionController, GuardNavigation, and GuardInteractionController.

  • Replaced state-only commands with real controller-assigned actions.

  • Added physical execution for:

    • Follow, come, stand, return

    • Patrol within configured radius

    • Attack with navigation and melee damage

    • Protect/defend with threat monitoring

    • Stop with immediate cancellation

    • Talk, warn, investigate, move-to

    • Mine and gather configured blocks

  • Added one active action per Guard with lifecycle methods: start(), tick(), isComplete(), cancel(), and cleanup().

  • Added action completion/failure reporting and exact failure logging.

  • Added natural owner chat orders such as Follow me, Guard1 attack Steve, and stop.

  • Added STOPPED and MOVING states.

  • Added action configuration for patrol, combat, follow distance, protection range, mining, and gathering.

  • Updated the GUI and tab completion to use the action controller.

  • Added action cancellation during Guard removal and death handling.

  • Guard movement locations are updated at runtime for persistence.

Live server/manual gameplay testing was not available in this environment.

tinyzayninfinity

Complete?

Kodari AI
KodariAug 16 at 2:25 pm 1

The implementation is complete and the requested Guard action system has been added.

However, it has not been manually tested on a live Minecraft server in this environment. The following still need gameplay verification:

  • FOLLOW / COME / STAND movement

  • PATROL navigation

  • ATTACK combat

  • PROTECT threat response

  • STOP cancellation

  • MINE/GATHER execution

So: code implementation complete; live-server validation pending.

Kodari can make mistakes. Review important code before using.
Files
src
manifest.kod
pom.xml
Code
27 2,623
src/main/java/com/kodari/securityguard/SecurityGuardPlugin.java
package com.kodari.securityguard;

import org.bukkit.ChatColor;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
import java.sql.SQLException;
import java.util.Map;

public class SecurityGuardPlugin extends JavaPlugin {
    private GuardDatabase database;
    private GuardSpawnManager spawnManager;
    private GuardManager guardManager;
    private GuardActionController actionController;
    private GuardLifecycleManager lifecycleManager;
    private YamlConfiguration messages;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        saveResource("messages.yml", false);
        saveResource("dialogues.yml", false);
        messages = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "messages.yml"));
        database = new GuardDatabase(this);
        try {
            database.open();
        } catch (SQLException exception) {
            getLogger().severe("Could not open SQLite database: " + exception.getMessage());
            getServer().getPluginManager().disablePlugin(this);
            return;
        }
        spawnManager = new GuardSpawnManager(this);
        guardManager = new GuardManager(this, database, spawnManager);
        try {
            guardManager.load();
        } catch (SQLException exception) {
            getLogger().severe("Could not load guards: " + exception.getMessage());
            getServer().getPluginManager().disablePlugin(this);
            return;
        }
        actionController = new GuardActionController(this, guardManager);
        lifecycleManager = new GuardLifecycleManager(this, guardManager, actionController);
        GuardCommand command = new GuardCommand(this);
        getCommand("guard").setExecutor(command);
        getCommand("guard").setTabCompleter(new GuardTabCompleter(this));
        getServer().getPluginManager().registerEvents(new GuardListener(this), this);
        lifecycleManager.restoreAll();
        lifecycleManager.start();
    }

    @Override
    public void onDisable() {
        if (lifecycleManager != null) lifecycleManager.stop();
        if (guardManager != null) {
            try { guardManager.saveAll(); } catch (SQLException exception) { getLogger().warning("Could not save guards: " + exception.getMessage()); }
        }
        if (database != null) database.close();
    }

    public GuardManager getGuardManager() { return guardManager; }
    public GuardSpawnManager getSpawnManager() { return spawnManager; }
    public GuardActionController getGuardActionController() { return actionController; }
    public GuardLifecycleManager getGuardLifecycleManager() { return lifecycleManager; }

    public String message(String key, Map<String, String> replacements) {
        String value = messages.getString(key, key);
        for (Map.Entry<String, String> entry : replacements.entrySet()) value = value.replace("{" + entry.getKey() + "}", entry.getValue());
        String prefix = key.equals("not-owner") ? "" : messages.getString("prefix", "");
        return ChatColor.translateAlternateColorCodes('&', prefix + value);
    }

    public String message(String key) { return message(key, Map.of()); }
}