VillageAI 插件
版本: 3.3.2
API: Paper 1.21 / Java 21
作者: Duong2012G
VillageAI 将原版 Minecraft 村庄转变为鲜活、具有反应能力的社区。
村庄能够自我防御、管理自身的供需经济、发布任务,
并根据玩家声望动态做出反应——无需任何外部依赖。
功能
| 系统 |
描述 |
| 状态机 |
村庄在 SAFE(安全)→ ALERT(警戒)→ DEFENDING(防御中)→ NIGHT / RAID(夜间/袭击)之间自动循环 |
| 空间铃索引 |
通过 ChunkCoord 索引实现 O(1) 复杂度的村庄查找——区块事件触发时无需全量扫描 |
| 经济系统 |
基于供需的定价机制,并带有按玩家声望计算的乘数(−50% 至 +50%) |
| 袭击 |
可配置的多波次袭击,包含多种怪物和绿宝石奖励 |
| 升级 |
WALL(城墙)· WATCHTOWER(瞭望塔)· GRANARY(粮仓)· FORGE(铁匠铺)——每项升级都带来实质性的游戏性影响 |
| 任务 |
24 小时 DeliveryQuest(配送任务)周期,设有截止时间;通过与村民交互获得奖励 |
| 交易 GUI |
54 格箱子界面,实时显示价格以及折扣/加价指示器 |
| 村民命名 |
每个村民拥有自定义名称标签,显示其职业和生命值 |
| 异步存储 |
原子文件保存(写入临时文件 → 重命名),并自动备份 |
安装
- 确保你正在运行 Paper 1.21(或兼容分支)并使用 Java 21。
- 将
VillageAI-3.3.2.jar 放入服务器的 plugins/ 文件夹中。
- 启动(或重启)服务器——请勿使用
/reload 命令。
- 首次运行时,配置文件将在
plugins/VillageAI/ 目录下生成。
注意: 官方不支持 PlugMan 热重载。更新插件时请务必完全重启服务器。
从源码构建
# 克隆/解压源码,然后执行:
mvn clean package -DskipTests
# 阴影 Jar 包将位于:
target/VillageAI-3.3.2.jar
要求:Java 21,Maven 3.8+。
命令
| 命令 |
权限 |
描述 |
/villageai info |
villageai.info |
显示最近村庄的状态 |
/villageai list |
villageai.admin |
列出所有已加载的村庄 |
/villageai reload |
villageai.admin |
重新加载配置(热重载) |
/villageai debug |
villageai.admin |
切换调试输出 |
/villageai raid start |
villageai.admin |
强制开始一次袭击 |
/villageai raid stop |
villageai.admin |
强制停止一次袭击 |
/vtrade |
villageai.trade |
打开最近村庄的交易 GUI |
/vtrade buy <item> [qty] |
villageai.trade |
通过命令直接购买 |
/vtrade sell <item> [qty] |
villageai.trade |
通过命令直接出售 |
/vquest list |
villageai.quest |
查看当前活跃的任务 |
/vquest accept <id> |
villageai.quest |
接受一个任务 |
权限
villageai.info: true # 所有玩家
villageai.trade: true # 所有玩家
villageai.quest: true # 所有玩家
villageai.admin: op # 仅限管理员
配置概览
config.yml 中的关键设置:
village:
check_radius: 64 # 敌对玩家检测半径(方块)
door_radius: 8 # 夜间/警戒状态的房门扫描半径
tick_interval: 40 # 村庄刻率(刻,默认 2 秒)
defense:
max_golems: 2 # 每村最大铁傀儡数量
alert_to_defense_delay: 10000 # 生成铁傀儡前的延迟(毫秒)
bell_sound_cooldown: 15000 # 摇铃间隔(毫秒)
reputation:
hostile_threshold: -30 # 低于此值将触发铁傀儡攻击
interact_reward: 2 # 右键点击村民获得的声望点数
damage_penalty: -25 # 攻击村民损失的声望点数
raid:
max_waves: 5
wave_interval_seconds: 60
reward_per_wave: 64 # 完成每波袭击获得的绿宝石数量
night:
enabled: true
close_doors_at_night: true
3.3.2 版本修复
本次发布解决了六个 Bug——完整详情请参阅 CHANGELOG.md:
- [严重]
TradeService.executeTrade() 验证了交易但未转移物品
- [严重] 在交易 GUI 中快速双击可能导致重复消费(Double-spend)
- [中等] 在多世界服务器上
getNearestVillage() 会因 IllegalArgumentException 崩溃
- [中等]
tradeHistory 列表无限增长——在长期运行的服务器上导致内存泄漏
- [中等] 当 24 小时计时器触发且存在相同任务时,会生成重复任务
- [性能] 用 O(1) 反向查找映射替换了
onEntityDeath 中的 O(n) 村庄扫描
- [性能] 用缓存的门列表替换了
closeAllDoors() 中的区块扫描
数据存储
村庄数据以 YAML 格式保存至 plugins/VillageAI/villages/ 目录,每个村庄对应一个文件。
保存操作使用异步原子写入模式(写入 .tmp → 重命名为最终文件)进行,以防止崩溃导致的数据损坏。
每个文件旁都会保留前一次保存的 .bak 备份。
许可证
本插件按“原样”提供,仅供教育和服务器运营商使用。
未经作者许可,禁止重新分发或转售。
VillageAI Plugin
Version: 3.3.2
API: Paper 1.21 / Java 21
Author: Duong2012G
VillageAI transforms vanilla Minecraft villages into living, reactive communities.
Villages defend themselves, manage their own supply-and-demand economy, issue quests,
and dynamically react to player reputation — all without any external dependencies.
Features
| System |
Description |
| State machine |
Villages cycle through SAFE → ALERT → DEFENDING → NIGHT / RAID automatically |
| Spatial bell index |
O(1) village lookups via ChunkCoord index — no full-scan on chunk events |
| Economy |
Supply/demand pricing with per-player reputation multipliers (−50 % to +50 %) |
| Raids |
Configurable multi-wave raids with mob variety and emerald rewards |
| Upgrades |
WALL · WATCHTOWER · GRANARY · FORGE — each adds tangible gameplay effects |
| Quests |
24-hour DeliveryQuest cycle with deadlines; reward on villager interaction |
| Trade GUI |
54-slot chest GUI with live price display and discount/markup indicators |
| Villager names |
Custom name tags per villager showing profession and health |
| Async storage |
Atomic file save (write-temp → rename) with automatic backup |
Installation
- Ensure you are running Paper 1.21 (or a compatible fork) with Java 21.
- Drop
VillageAI-3.3.2.jar into your server's plugins/ folder.
- Start (or restart) the server — do not use
/reload.
- Configuration files are generated in
plugins/VillageAI/ on first run.
Note: PlugMan hot-reload is not officially supported. Always use a full server restart when updating the plugin.
Building from Source
# Clone / unzip the source, then:
mvn clean package -DskipTests
# The shaded jar will be at:
target/VillageAI-3.3.2.jar
Requirements: Java 21, Maven 3.8+.
Commands
| Command |
Permission |
Description |
/villageai info |
villageai.info |
Show status of the nearest village |
/villageai list |
villageai.admin |
List all loaded villages |
/villageai reload |
villageai.admin |
Reload config (hot) |
/villageai debug |
villageai.admin |
Toggle debug output |
/villageai raid start |
villageai.admin |
Force-start a raid |
/villageai raid stop |
villageai.admin |
Force-stop a raid |
/vtrade |
villageai.trade |
Open trade GUI for the nearest village |
/vtrade buy <item> [qty] |
villageai.trade |
Buy directly via command |
/vtrade sell <item> [qty] |
villageai.trade |
Sell directly via command |
/vquest list |
villageai.quest |
View active quests |
/vquest accept <id> |
villageai.quest |
Accept a quest |
Permissions
villageai.info: true # All players
villageai.trade: true # All players
villageai.quest: true # All players
villageai.admin: op # Operators only
Configuration Overview
Key settings in config.yml:
village:
check_radius: 64 # Hostile-player detection radius (blocks)
door_radius: 8 # Door-scan radius for night/alert
tick_interval: 40 # Village tick rate (ticks, default 2 s)
defense:
max_golems: 2 # Max iron golems per village
alert_to_defense_delay: 10000 # ms before spawning golems
bell_sound_cooldown: 15000 # ms between bell rings
reputation:
hostile_threshold: -30 # Rep below this triggers golem targeting
interact_reward: 2 # Rep gained per villager right-click
damage_penalty: -25 # Rep lost per villager attack
raid:
max_waves: 5
wave_interval_seconds: 60
reward_per_wave: 64 # Emeralds per completed wave
night:
enabled: true
close_doors_at_night: true
Bug Fixes in 3.3.2
Six bugs were resolved in this release — see CHANGELOG.md for full details:
- [Critical]
TradeService.executeTrade() validated trades but never transferred items
- [Critical] Double-spend possible via rapid double-click in Trade GUI
- [Medium]
getNearestVillage() crashed with IllegalArgumentException on multi-world servers
- [Medium]
tradeHistory list grew without bound — memory leak on long-running servers
- [Medium] Quest duplicates generated when 24-hour timer fired with identical quest active
- [Performance]
onEntityDeath O(n) village scan replaced with O(1) reverse-lookup map
- [Performance]
closeAllDoors() block scan replaced with cached door list
Data Storage
Village data is saved to plugins/VillageAI/villages/ as YAML, one file per village.
Saves are performed asynchronously using an atomic write pattern (write to .tmp →
rename to final file) to prevent data corruption on crash. A .bak backup of the
previous save is kept alongside each file.
License
This plugin is provided as-is for educational and server-operator use.
Redistribution or resale without permission from the author is not permitted.
评论 0
登录后参与评分
还没有评论,来抢沙发吧