BlockEntityLimiter
一个兼容 Folia 的 Minecraft 插件,用于限制 Minecraft 1.21.x 中每个区块的实体方块数量。
功能特性
- 兼容 Folia:完全支持 Folia 的多线程区域系统
- 高性能:智能缓存系统显著减少卡顿
- 基于区块的限制:按区块为单位限制实体方块数量
- 全局上限:可选的全局上限,控制所有类型实体方块的总数
- 独立限制:每种实体方块类型都有各自可配置的上限
- 开关系统:可为每种实体方块类型启用或禁用限制
- 不删除实体:插件仅阻止放置,绝不会移除已存在的实体方块
- 热重载:无需重启服务器即可重新加载配置
- 潜影盒支持:单个配置项涵盖所有颜色的潜影盒
- 线程安全:专为 Folia 的并发区域系统设计
- 自动强制加载:自动强制加载高实体方块数量的区块
监控的实体方块
- 装饰陶罐 (Decorated Pot)
- 末影箱 (Ender Chest)
- 高炉 (Blast Furnace)
- 烟熏炉 (Smoker)
- 熔炉 (Furnace)
- 木桶 (Barrel)
- 投掷器 (Dropper)
- 发射器 (Dispenser)
- 箱子 (Chest)
- 陷阱箱 (Trapped Chest)
- 漏斗 (Hopper)
- 潜影盒 (Shulker Box,所有颜色)
安装方法
- 下载最新版本的 JAR 文件
- 将其放入服务器的
plugins 文件夹中
- 重启服务器或加载该插件
- 根据需求配置
plugins/BlockEntityLimiter/config.yml
配置说明
全局上限 (Master Limit)
全局上限控制所有类型实体方块的总数量:
master-limit:
enabled: true # 启用/禁用全局上限
amount: 1000 # 每个区块的最大实体方块总数
示例场景(全局上限为 1000):
- 500 个箱子 + 500 个末影箱 = 允许
- 100 个箱子 + 900 个末影箱 = 允许
- 600 个箱子 + 500 个末影箱 = 被阻止(超出全局上限)
独立实体方块限制
每种实体方块类型有两个设置:
block-entities:
chest:
enabled: true # 为此类型启用限制
limit: 100 # 每个区块此类型的最大数量
enabled: true - 将对此类实体方块进行限制
enabled: false - 此类实体方块可无限制放置
limit - 每个区块此特定类型的最大数量
限制如何协同工作
在放置实体方块时,插件会检查:
- 是否为此实体方块类型启用了限制?
- 是否已达到独立上限?
- (如果启用了全局上限)是否已达到全局上限?
如果达到任何限制,放置将被阻止。
强制加载功能
插件可以自动强制加载拥有大量实体方块的区块:
forceload:
enabled: false # 启用/禁用自动强制加载
threshold: 50 # 触发强制加载所需的最小实体方块数
notify-player: true # 在区块被强制加载时通知玩家
periodic-check:
enabled: true # 启用对强制加载区块的定期验证
interval: 30 # 每 X 分钟检查一次
delay-per-chunk: 20 # 检查每个区块之间的延迟(20 = 1 秒)
verbose: false # 记录每次区块检查的详细日志
工作原理:
- 当区块达到阈值时,会自动将其强制加载
- 强制加载的区块即使附近没有玩家也会保持加载状态
- 适用于农场、存储系统和自动化装置
- 重启后持久保存:强制加载的区块会保存到
forceloaded-chunks.yml
- 当实体方块数量低于阈值(通过破坏方块实现)时,强制加载会被移除
- 玩家其区块被强制加载时会收到通知(可选)
定期验证:
- 每隔 X 分钟,插件会检查所有强制加载的区块
- 验证每个区块是否仍有足够的实体方块
- 如果低于阈值,则自动移除强制加载
- 逐个检查区块并配置延迟以防止卡顿
- 示例:如果有 100 个强制加载的区块且延迟为 20 tick,完整检查大约需要 33 秒
- 详细模式:启用后,会将每个区块检查的详细信息记录到控制台
示例: 将阈值设置为 50。当某个区块拥有 50+ 漏斗/箱子/熔炉时,它将保持加载状态。
命令
| 命令 |
权限 |
描述 |
/belimiter reload |
blockentitylimiter.reload |
重新加载配置 |
/belimiter forceloaded [page] |
blockentitylimiter.admin |
列出所有强制加载的区块(分页显示) |
/belimiter |
blockentitylimiter.use |
显示帮助信息 |
别名:/bel、/blocklimiter
强制加载命令页面:
- 第 1 页:显示包含总数的摘要
- 第 2 页及以后:显示区块列表(每页 10 个)
权限
| 权限 |
默认值 |
描述 |
blockentitylimiter.use |
true |
访问主命令 |
blockentitylimiter.reload |
op |
重新加载配置 |
blockentitylimiter.admin |
op |
访问管理命令 |
性能优化
插件使用智能缓存系统以最大限度地减少卡顿:
- 缓存持续时间:500ms(可在代码中配置)
- 自动失效:放置或破坏方块时更新缓存
- 内存管理:自动清理旧的缓存条目
- 线程安全:使用 ConcurrentHashMap 以确保 Folia 兼容性
在高频率放置方块的测试场景中,缓存可减少超过 95% 的区块扫描操作,从而防止卡顿峰值。
强制加载安全性
强制加载功能旨在确保安全且可逆:
- ✅ 非破坏性:仅将区块设置为强制加载状态,不会修改方块
- ✅ 自动清理:当实体块低于阈值时自动移除强制加载
- ✅ 持久化存储:保存至
forceloaded-chunks.yml 并在重启后恢复
- ✅ 定期验证:自动检查并移除无效的强制加载
- ✅ 手动覆盖:管理员可使用
/forceload remove 手动移除强制加载
- ✅ 优雅关闭:在服务器停止前保存所有数据
- ⚠️ 内存占用:强制加载的区块会消耗服务器内存 - 请使用合理的阈值
- ⚠️ 性能影响:过多的强制加载区块可能会影响性能 - 可通过
/belimiter forceloaded 进行监控
BlockEntityLimiter
A Folia-compatible Minecraft plugin that limits the number of block entities per chunk for Minecraft 1.21.x.
Features
- Folia Compatible: Fully compatible with Folia's multi-threaded regions
- High Performance: Smart caching system reduces lag significantly
- Chunk-based Limiting: Limits block entities on a per-chunk basis
- Master Limit: Optional master limit that controls total block entities across all types
- Individual Limits: Each block entity type has its own configurable limit
- Toggle System: Enable/disable limiting for each block entity type
- No Deletion: Plugin only prevents placement, never removes existing block entities
- Hot Reload: Reload configuration without restarting the server
- Shulker Box Support: Single config entry covers all shulker box colors
- Thread-Safe: Designed for Folia's concurrent region system
- Auto-Forceload: Automatically forceloads chunks with high block entity counts
Tracked Block Entities
- Decorated Pot
- Ender Chest
- Blast Furnace
- Smoker
- Furnace
- Barrel
- Dropper
- Dispenser
- Chest
- Trapped Chest
- Hopper
- Shulker Box (all colors)
Installation
- Download the latest release JAR file
- Place it in your server's
plugins folder
- Restart your server or load the plugin
- Configure
plugins/BlockEntityLimiter/config.yml to your needs
Configuration
Master Limit
The master limit controls the total number of block entities across ALL types:
master-limit:
enabled: true # Enable/disable master limit
amount: 1000 # Maximum total block entities per chunk
Example Scenarios (with master limit of 1000):
- 500 chests + 500 ender chests = Allowed
- 100 chests + 900 ender chests = Allowed
- 600 chests + 500 ender chests = Blocked (exceeds master limit)
Individual Block Entity Limits
Each block entity type has two settings:
block-entities:
chest:
enabled: true # Enable limiting for this type
limit: 100 # Maximum of this type per chunk
enabled: true - This block entity type will be limited
enabled: false - This block entity type can be placed without restriction
limit - Maximum number of this specific type per chunk
How Limits Work Together
When placing a block entity, the plugin checks:
- Is limiting enabled for this block entity type?
- Has the individual limit been reached?
- (If master limit is enabled) Has the master limit been reached?
Placement is blocked if any limit is reached.
Forceload Feature
The plugin can automatically forceload chunks with many block entities:
forceload:
enabled: false # Enable/disable auto-forceload
threshold: 50 # Minimum block entities to trigger forceload
notify-player: true # Notify player when chunk is forceloaded
periodic-check:
enabled: true # Enable periodic validation of forceloaded chunks
interval: 30 # Check every X minutes
delay-per-chunk: 20 # Ticks between checking each chunk (20 = 1 second)
verbose: false # Log detailed info for each chunk check
How it works:
- When a chunk reaches the threshold, it's automatically forceloaded
- Forceloaded chunks stay loaded even when no players are nearby
- Useful for farms, storage systems, and automated setups
- Persistent across restarts: Forceloaded chunks are saved to
forceloaded-chunks.yml
- When block entities drop below threshold (by breaking blocks), forceload is removed
- Players are notified when their chunk is forceloaded (optional)
Periodic Validation:
- Every X minutes, the plugin checks all forceloaded chunks
- Validates each chunk still has enough block entities
- If below threshold, removes forceload automatically
- Checks chunks one at a time with configurable delay to prevent lag
- Example: With 100 forceloaded chunks and 20 tick delay, full check takes ~33 seconds
- Verbose mode: When enabled, logs detailed information about each chunk check to console
Example: Set threshold to 50. When a chunk has 50+ hoppers/chests/furnaces, it stays loaded.
Commands
| Command |
Permission |
Description |
/belimiter reload |
blockentitylimiter.reload |
Reload the configuration |
/belimiter forceloaded [page] |
blockentitylimiter.admin |
List all forceloaded chunks (paginated) |
/belimiter |
blockentitylimiter.use |
Show help message |
Aliases: /bel, /blocklimiter
Forceloaded Command Pages:
- Page 1: Shows summary with total count
- Page 2+: Shows list of chunks (10 per page)
Permissions
| Permission |
Default |
Description |
blockentitylimiter.use |
true |
Access to main command |
blockentitylimiter.reload |
op |
Reload configuration |
blockentitylimiter.admin |
op |
Access admin commands |
Performance
The plugin uses an intelligent caching system to minimize lag:
- Cache Duration: 500ms (configurable in code)
- Automatic Invalidation: Cache updates when blocks are placed/broken
- Memory Management: Automatic cleanup of old cache entries
- Thread-Safe: ConcurrentHashMap for Folia compatibility
In testing scenarios with high block placement rates, the cache reduces chunk scanning by over 95%, preventing lag spikes.
Forceload Safety
The forceload feature is designed to be safe and reversible:
- ✅ Non-destructive: Only sets chunks to forceloaded, never modifies blocks
- ✅ Automatic cleanup: Removes forceload when block entities drop below threshold
- ✅ Persistent storage: Saves to
forceloaded-chunks.yml and restores on restart
- ✅ Periodic validation: Automatically checks and removes invalid forceloads
- ✅ Manual override: Admins can manually remove forceload with
/forceload remove
- ✅ Graceful shutdown: Saves all data before server stops
- ⚠️ Memory usage: Forceloaded chunks consume server memory - use reasonable thresholds
- ⚠️ Performance: Too many forceloaded chunks can impact performance - monitor with
/belimiter forceloaded
评论 0
登录后参与评分
还没有评论,来抢沙发吧