MetaCore
面向 Paper 插件的共享触发引擎平台 —— MetaCore 提供了触发引擎、其 Paper 集成层以及 Kotlin DSL,作为一个集中式库供其他插件(MetaJobs 及您自己的插件)依赖使用,而无需打包重复的引擎代码。
概述
MetaCore 是一个实用工具库插件,它在您的 Paper/Folia 服务器上托管单个共享实例的 Trigger Engine。与其让每个插件都嵌入自己的引擎副本——造成内存浪费、复制配置逻辑并使跨插件触发器变得复杂——不如让插件将其触发器配置作为模块注册到 MetaCore 的共享引擎中。
可以将其视为您服务器的“触发引擎即服务”。
库依赖:
为什么选择 MetaCore?
| 问题 |
MetaCore 解决方案 |
| 多个插件各自捆绑 Trigger Engine → 内存膨胀、版本冲突 |
单个共享引擎实例仅加载一次 |
| 插件难以引用彼此的触发器 |
通过共享 TriggerHolder ID 实现跨模块触发器引用 |
| 每个插件都重新实现 Paper 集成(解析器、元素、属性) |
由 MetaCore 在启动时统一注册 |
| 配置重载需要重启插件 |
通过 /metacore reload <module> 热重载单个模块 |
| Kotlin DSL 设置样板代码过多 |
LoadScope DSL + PaperTriggers.load { } 辅助方法,可在共享引擎上工作 |
功能特性
- 共享 Trigger Engine — 一个
DefaultTriggerEngine 实例,一个事件桥接,一个占位符注册表
- Paper 集成层 — 所有 Paper 特定的解析器、元素、属性、查找器和触发类型仅注册一次
- 外部物品支持 — 内置 ItemsAdder、Oraxen、Nexo、CraftEngine 的提供者(自动检测)
- PlaceholderAPI 集成 — 可选,当检测到 PlaceholderAPI 时自动启用
- 持久化占位符存储 — SQLite(默认)或 MySQL,支持异步刷新
- Kotlin DSL —
LoadScope DSL + PaperTriggers.load { } / yaml() 辅助方法位于 io.github.neoramm.triggerengine.kotlin.paper,可在共享引擎上使用
- Brigadier 命令 — 现代命令 API,支持模块管理的标签补全
- 兼容 Folia — 区域感知、线程安全的引擎操作
- 模块热重载 — 重新加载单个插件的触发器而不影响其他插件
安装
服务器管理员
- 下载最新的
MetaCore-<version>.jar
- 放入
plugins/ 目录
- 启动服务器 —— MetaCore 会创建
plugins/MetaCore/config.yml
- 配置存储(可选):SQLite(默认)或 MySQL
- 安装依赖插件(MetaJobs、MetaEnchants 或您自己的插件)
插件开发者 (Gradle)
// 您插件的 build.gradle.kts
dependencies {
compileOnly("io.papermc.paper:paper-api:26.2.build.+")
compileOnly(files("libs/MetaCore.jar"))
}
paper-plugin.yml (依赖插件)
name: YourPlugin
version: 1.0.0
main: com.your.YourPlugin
api-version: '26.2'
depend: [MetaCore] # 硬依赖 —— MetaCore 优先加载
# 或者软依赖:
# load: BEFORE
# required: false
快速入门(插件开发者)
1. 访问共享引擎
import io.github.neoramm.metacore.MetaCore;
import io.github.neoramm.triggerengine.paper.PaperTriggers;
public class YourPlugin extends JavaPlugin {
private PaperTriggers triggers;
@Override
public void onEnable() {
// 获取共享引擎(由 MetaCore 初始化)
triggers = MetaCore.triggers();
// 将您的插件注册为模块以支持重载
MetaCore.registerModule("yourplugin", session -> {
loadTriggers(session);
});
}
private void loadTriggers(LoadSession session) {
// 加载 YAML、Kotlin DSL 或程序化触发器
ConfigNode root = triggers.read(dataFolder.toPath().resolve("triggers.yml"), session);
if (root != null) {
session.add(root.get("triggers"), root.get("placeholders"), TriggerHolder.of("yourplugin", "1.0"));
}
}
}
2. 在共享引擎上使用 Kotlin DSL(推荐)
Kotlin DSL 不会创建引擎。它提供 LoadScope 构建器
(paper.load { }、yaml()),这些构建器可以在任何 PaperTriggers 上运行——包括
由 MetaCore 启动的全局实例:
// 在您插件的 Kotlin 代码中
import io.github.neoramm.metacore.MetaCore
import io.github.neoramm.triggerengine.kotlin.holder
import io.github.neoramm.triggerengine.kotlin.paper.load
import io.github.neoramm.triggerengine.kotlin.paper.yaml
class YourPlugin : JavaPlugin() {
override fun onEnable() {
// 共享单例,已由 MetaCore 初始化并启动。
// Paper 元素/解析器/属性已由 MetaCore 统一注册。
val paper = MetaCore.triggers()
val holder = holder("yourplugin")
fun loadAll() = paper.load {
yaml(dataFolder.toPath().resolve("triggers.yml"), holder)
// 或者在同一会话中使用程序化触发器:
// add(holder, "in-code") { trigger("welcome") { on("player-join") /* ... */ } }
}
loadAll()
// 重用相同的加载器进行热重载(模式与 MetaJobs 相同)。
// 这里不使用 MetaCore 传递的 LoadSession,因为
// paper.load{} 内部管理自己的会话。
MetaCore.registerModule("yourplugin") { loadAll() }
}
}
不要在此处调用 Plugin.triggerEngine() —— 该辅助方法会创建一个新的、独立的
引擎(见下文),而不是共享的那个。
3. 共享引擎与独立引擎
| 模式 |
方法 |
生命周期所有者 |
适用场景 |
| 共享模式(MetaCore 默认) |
MetaCore.triggers() |
MetaCore(通过 createShared() + 调用一次 start() / shutdown()) |
MetaJobs、MetaEnchants 或任何在插件描述中声明了 depend: [MetaCore] 的插件。启用跨模块 run_trigger 和 /metacore reload <module> 功能。 |
| 独立模式(需手动启用,不依赖 MetaCore) |
Plugin.triggerEngine()(Kotlin DSL)或 PaperTriggers.create(plugin, ...)(Paper 模块) |
你的插件(自行调用 start() / shutdown(),拥有独立的 EventBridge) |
你明确不希望使用共享实例:例如隔离测试、独立服务器或分支行为。新的引擎会注册完整的 Paper 默认配置(包括属性、解析器、元素和类型)。 |
虽然允许在依赖 MetaCore 的同时创建自己的引擎,但不建议这样做:你将承担两个引擎和两个事件桥接器的开销,且私有引擎上的触发器对其他模块不可见。
// 仅独立模式 — 无 MetaCore 依赖:
val isolated: PaperTriggers = triggerEngine {
// 可选的 DefaultTriggerEngine.Builder 自定义
}
isolated.start()
// ... isolated.load { ... } ...
// onDisable: isolated.shutdown()
4. 热重载支持
玩家/管理员可以仅重载你插件的触发器:
/metacore reload yourplugin
或通过编程方式:
MetaCore.reloadModule("yourplugin");
配置文件 (config.yml)
storage:
# sqlite -> 位于 plugins/MetaCore 内的文件(零配置)
# mysql -> 外部数据库,用于多服务器同步
type: sqlite
sqlite:
file: data.db
mysql:
host: localhost
port: 3306
database: minecraft
user: root
password: ""
properties:
useSSL: false
characterEncoding: utf8
# 刷盘间隔(秒),最小值为 5。关闭服务器或玩家退出时也会保存。
flush-seconds: 30
命令
| 命令 |
权限节点 |
描述 |
/metacore |
metacore.base |
显示版本和已加载的模块 |
/metacore modules |
metacore.base |
列出已注册的模块 ID |
/metacore reload |
metacore.admin |
重载所有模块 |
/metacore reload <module> |
metacore.admin |
重载指定模块 |
Tab 补全 支持在 /metacore reload <module> 中补全模块名称。
API 参考
MetaCore(主入口点)
| 方法 |
描述 |
static PaperTriggers triggers() |
获取共享的 PaperTriggers 实例 |
static CompositeExternalItemRegistry externalItems() |
访问组合的外部物品注册表 |
static ModuleHandle registerModule(String id, ModuleInitializer init) |
注册一个支持热重载的模块 |
static ModuleHandle getModule(String id) |
检索模块句柄 |
static Set<String> getModuleIds() |
列出所有已注册的模块 ID |
static void reloadModule(String id) |
热重载单个模块 |
static void reloadAllModules() |
重载所有模块 |
static void unregisterModule(String id) |
注销模块(通常在插件禁用时调用) |
ModuleInitializer(函数式接口)
@FunctionalInterface
public interface ModuleInitializer {
void accept(LoadSession session);
}
接收一个新的 LoadSession —— 在此处添加你的触发器、占位符和配置。
PaperTriggers(引擎访问)
你将使用的主要方法:
// 引擎与注册表
DefaultTriggerEngine engine();
PaperKeys keys();
PaperTriggerTypes types();
CompositeExternalItemRegistry externalItemRegistry();
// 加载
LoadSession engine().beginLoad();
ConfigNode read(Path file, LoadSession session);
CompileResult loadFile(Path file, String section, TriggerHolder holder);
CompileResult report(CompileResult result); // 记录诊断信息
// 生命周期
void start(); // 由所有者调用一次:对于共享实例是 MetaCore,
// 对于独立 PaperTriggers.create() 引擎则是你的插件
void shutdown(); // 遵循与 start() 相同的所有者规则
外部物品提供者
MetaCore 会自动为以下插件注册提供者(如果存在):
| 提供者 |
物品 |
需要 |
| ItemsAdder |
itemsadder: 命名空间 |
ItemsAdder |
| Nexo |
nexo: 命名空间 |
Nexo |
| CraftEngine |
craftengine: 命名空间 |
CraftEngine |
在触发器中像使用原版物品一样使用它们:
# triggers.yml
triggers:
give_custom_sword:
type: player-join
actions:
- give_item:
item: "itemsadder:my_custom_sword"
amount: 1
跨模块触发器
由于所有模块共享同一个引擎,触发器可以相互引用:
# MetaJobs triggers.yml
triggers:
miner_level_up:
type: job-level-up
conditions:
- job_id: "miner"
actions:
- run_trigger: "namespace:apply_mining_bonus" # 引用其他插件的触发器
# 其他插件 triggers.yml
triggers:
apply_mining_bonus:
type: manual # 仅通过 run_trigger 运行
actions:
- add-enchantment:
enchantment: "fortune"
level: 1
兼容性
| 平台 |
版本 |
| Paper |
26.2+ (API 26.2+) |
| Folia |
支持(区域感知) |
| Java |
25+ |
| Trigger Engine |
内置(core/paper 模块) |
许可证
MIT 许可证 — 免费用于任何用途,包括商业服务器和插件。
链接
给插件作者:发布你的插件
当发布依赖 MetaCore 的插件时:
-
在 paper-plugin.yml 中声明依赖:
depend: [MetaCore]
# 或者软依赖:
# load: BEFORE
# required: false
-
在你的插件 README 中注明需求:
需要 MetaCore(提供共享的 Trigger Engine)。请从 releases 下载。
-
使用 MetaCore.registerModule(),以便服务器管理员可以通过 /metacore reload yourplugin 热重载你的触发器。
-
不要对 Trigger Engine 类进行阴影打包(shade)——请使用 compileOnly / provided 作用域。
-
不要调用 Plugin.triggerEngine() ——当你目标是共享引擎时,请使用
MetaCore.triggers() + paper.load { }。将 Plugin.triggerEngine() /
PaperTriggers.create() 保留给可选的独立模式,该模式下不依赖 MetaCore。
MetaCore
A shared Trigger Engine platform for Paper plugins — MetaCore provides the Trigger Engine, its Paper integration layer, and a Kotlin DSL as a centralized library that other plugins (MetaJobs and your own) can depend on without bundling duplicate engine code.
Overview
MetaCore is a utility library plugin that hosts a single, shared instance of the Trigger Engine on your Paper/Folia server. Instead of every plugin embedding its own copy of the engine — wasting memory, duplicating configuration logic, and complicating cross-plugin triggers — plugins register their trigger configurations as modules against MetaCore's shared engine.
Think of it as "Trigger Engine as a Service" for your server.
Libraries:
Why MetaCore?
| Problem |
MetaCore Solution |
| Multiple plugins each bundle the Trigger Engine → memory bloat, version conflicts |
Single shared engine instance loaded once |
| Plugins can't easily reference each other's triggers |
Cross-module trigger references via shared TriggerHolder IDs |
| Each plugin reimplements Paper integrations (parsers, elements, properties) |
Registered once at startup by MetaCore |
| Configuration reload requires plugin restart |
Hot-reload individual modules via /metacore reload <module> |
| Kotlin DSL setup is boilerplate-heavy |
LoadScope DSL + PaperTriggers.load { } helpers that work on the shared engine |
Features
- Shared Trigger Engine — One
DefaultTriggerEngine instance, one event bridge, one placeholder registry
- Paper Integration Layer — All Paper-specific parsers, elements, properties, lookups, and trigger types registered once
- External Item Support — Built-in providers for ItemsAdder, Oraxen, Nexo, CraftEngine (auto-detected)
- PlaceholderAPI Integration — Optional, auto-enabled when PlaceholderAPI is present
- Persistent Placeholder Storage — SQLite (default) or MySQL with async flush
- Kotlin DSL —
LoadScope DSL + PaperTriggers.load { } / yaml() helpers in io.github.neoramm.triggerengine.kotlin.paper, usable on the shared engine
- Brigadier Commands — Modern command API with tab completion for module management
- Folia Compatible — Region-aware, thread-safe engine operation
- Hot Module Reload — Reload a single plugin's triggers without touching others
Installation
For Server Administrators
- Download the latest
MetaCore-<version>.jar
- Place in
plugins/
- Start the server — MetaCore creates
plugins/MetaCore/config.yml
- Configure storage (optional): SQLite (default) or MySQL
- Install dependent plugins (MetaJobs, MetaEnchants, or your own)
For Plugin Developers (Gradle)
// build.gradle.kts of your plugin
dependencies {
compileOnly("io.papermc.paper:paper-api:26.2.build.+")
compileOnly(files("libs/MetaCore.jar"))
}
paper-plugin.yml (Dependent Plugin)
name: YourPlugin
version: 1.0.0
main: com.your.YourPlugin
api-version: '26.2'
depend: [MetaCore] # Hard dependency — MetaCore loads first
# Or soft dependency:
# load: BEFORE
# required: false
Quick Start (Plugin Developer)
1. Access the Shared Engine
import io.github.neoramm.metacore.MetaCore;
import io.github.neoramm.triggerengine.paper.PaperTriggers;
public class YourPlugin extends JavaPlugin {
private PaperTriggers triggers;
@Override
public void onEnable() {
// Get the shared engine (initialized by MetaCore)
triggers = MetaCore.triggers();
// Register your plugin as a module for reload support
MetaCore.registerModule("yourplugin", session -> {
loadTriggers(session);
});
}
private void loadTriggers(LoadSession session) {
// Load YAML, Kotlin DSL, or programmatic triggers
ConfigNode root = triggers.read(dataFolder.toPath().resolve("triggers.yml"), session);
if (root != null) {
session.add(root.get("triggers"), root.get("placeholders"), TriggerHolder.of("yourplugin", "1.0"));
}
}
}
2. Using the Kotlin DSL on the shared engine (Recommended)
The Kotlin DSL does not create an engine. It provides LoadScope builders
(paper.load { }, yaml()) that run on any PaperTriggers — including the
global instance started by MetaCore:
// In your plugin's Kotlin code
import io.github.neoramm.metacore.MetaCore
import io.github.neoramm.triggerengine.kotlin.holder
import io.github.neoramm.triggerengine.kotlin.paper.load
import io.github.neoramm.triggerengine.kotlin.paper.yaml
class YourPlugin : JavaPlugin() {
override fun onEnable() {
// Shared singleton, already initialized + started by MetaCore.
// Paper elements/parsers/properties were registered once by MetaCore.
val paper = MetaCore.triggers()
val holder = holder("yourplugin")
fun loadAll() = paper.load {
yaml(dataFolder.toPath().resolve("triggers.yml"), holder)
// or programmatic triggers in the same session:
// add(holder, "in-code") { trigger("welcome") { on("player-join") /* ... */ } }
}
loadAll()
// Reuse the same loader for hot-reload (same pattern as MetaJobs).
// The LoadSession passed by MetaCore is unused here because
// paper.load{} manages its own session internally.
MetaCore.registerModule("yourplugin") { loadAll() }
}
}
Do not call Plugin.triggerEngine() here — that helper creates a new,
standalone engine (see below), not the shared one.
3. Shared vs. standalone engine
| Mode |
How |
Who owns lifecycle |
When to use |
| Shared (default with MetaCore) |
MetaCore.triggers() |
MetaCore (createShared() + start() / shutdown() once) |
MetaJobs, MetaEnchants, any plugin with depend: [MetaCore]. Enables cross-module run_trigger and /metacore reload <module>. |
| Standalone (opt-in, no MetaCore) |
Plugin.triggerEngine() (kotlin-dsl) or PaperTriggers.create(plugin, ...) (paper module) |
Your plugin (start() / shutdown() yourself, own EventBridge) |
You explicitly don't want the shared instance: isolated tests, separate server, forked behavior. Full Paper defaults (properties, parsers, elements, types) are registered on the new engine. |
Creating your own engine while also depending on MetaCore is allowed but
discouraged: you pay for two engines, two event bridges, and triggers on the
private engine are invisible to other modules.
// Standalone only — no MetaCore dependency:
val isolated: PaperTriggers = triggerEngine {
// optional DefaultTriggerEngine.Builder customization
}
isolated.start()
// ... isolated.load { ... } ...
// onDisable: isolated.shutdown()
4. Hot Reload Support
Players/ops can reload just your plugin's triggers:
/metacore reload yourplugin
Or programmatically:
MetaCore.reloadModule("yourplugin");
Configuration (config.yml)
storage:
# sqlite -> file inside plugins/MetaCore (zero setup)
# mysql -> external database for multi-server sync
type: sqlite
sqlite:
file: data.db
mysql:
host: localhost
port: 3306
database: minecraft
user: root
password: ""
properties:
useSSL: false
characterEncoding: utf8
# Flush interval in seconds (min 5). Also saves on shutdown/player quit.
flush-seconds: 30
Commands
| Command |
Permission |
Description |
/metacore |
metacore.base |
Show version and loaded modules |
/metacore modules |
metacore.base |
List registered module IDs |
/metacore reload |
metacore.admin |
Reload all modules |
/metacore reload <module> |
metacore.admin |
Reload a specific module |
Tab completion works for module names in /metacore reload <module>.
API Reference
MetaCore (Main Entry Point)
| Method |
Description |
static PaperTriggers triggers() |
Get the shared PaperTriggers instance |
static CompositeExternalItemRegistry externalItems() |
Access the combined external item registry |
static ModuleHandle registerModule(String id, ModuleInitializer init) |
Register a module for hot-reload |
static ModuleHandle getModule(String id) |
Retrieve a module handle |
static Set<String> getModuleIds() |
List all registered module IDs |
static void reloadModule(String id) |
Hot-reload a single module |
static void reloadAllModules() |
Reload all modules |
static void unregisterModule(String id) |
Unregister a module (on plugin disable) |
ModuleInitializer (Functional Interface)
@FunctionalInterface
public interface ModuleInitializer {
void accept(LoadSession session);
}
Receives a fresh LoadSession — add your triggers, placeholders, and configs here.
PaperTriggers (Engine Access)
Key methods you'll use:
// Engine & registries
DefaultTriggerEngine engine();
PaperKeys keys();
PaperTriggerTypes types();
CompositeExternalItemRegistry externalItemRegistry();
// Loading
LoadSession engine().beginLoad();
ConfigNode read(Path file, LoadSession session);
CompileResult loadFile(Path file, String section, TriggerHolder holder);
CompileResult report(CompileResult result); // Logs diagnostics
// Lifecycle
void start(); // Owner calls once: MetaCore for the shared instance,
// your plugin for a standalone PaperTriggers.create() engine
void shutdown(); // Same owner rule as start()
External Item Providers
MetaCore auto-registers providers for these plugins (if present):
| Provider |
Items |
Requires |
| ItemsAdder |
itemsadder: namespace |
ItemsAdder |
| Nexo |
nexo: namespace |
Nexo |
| CraftEngine |
craftengine: namespace |
CraftEngine |
Use in triggers like any vanilla item:
# triggers.yml
triggers:
give_custom_sword:
type: player-join
actions:
- give_item:
item: "itemsadder:my_custom_sword"
amount: 1
Cross-Module Triggers
Since all modules share one engine, triggers can reference each other:
# MetaJobs triggers.yml
triggers:
miner_level_up:
type: job-level-up
conditions:
- job_id: "miner"
actions:
- run_trigger: "namespace:apply_mining_bonus" # References other plugin trigger
# Other plugin triggers.yml
triggers:
apply_mining_bonus:
type: manual # Only run via run_trigger
actions:
- add-enchantment:
enchantment: "fortune"
level: 1
Compatibility
| Platform |
Version |
| Paper |
26.2+ (API 26.2+) |
| Folia |
Supported (region-aware) |
| Java |
25+ |
| Trigger Engine |
Bundled (core/paper modules) |
License
MIT License — Free for any use, including commercial servers and plugins.
Links
For Plugin Authors: Publishing Your Plugin
When publishing a plugin that depends on MetaCore:
-
Declare dependency in paper-plugin.yml:
depend: [MetaCore]
# Or soft dependency:
# load: BEFORE
# required: false
-
Document requirement in your plugin's README:
Requires MetaCore (provides shared Trigger Engine). Download from releases.
-
Use MetaCore.registerModule() so server admins can hot-reload your triggers via /metacore reload yourplugin.
-
Don't shade Trigger Engine classes — use compileOnly / provided scope.
-
Don't call Plugin.triggerEngine() when you target the shared engine — use
MetaCore.triggers() + paper.load { }. Reserve Plugin.triggerEngine() /
PaperTriggers.create() for the opt-in standalone mode with no MetaCore dependency.
评论 0
登录后参与评分
还没有评论,来抢沙发吧