ServerProxy
服务端:配置 + 两个事件处理器
基本信息
| 属性 | 值 |
|---|---|
| 路径 | com.github.lunatrius.ingameinfo.proxy.ServerProxy |
| 行数 | 24 |
| 父类 | CommonProxy |
preInit(:13-16)
public void preInit(FMLPreInitializationEvent event) {
super.preInit(event);
ConfigurationHandler.init(event.getSuggestedConfigurationFile());
}
⚠️ 用的是 ConfigurationHandler 基类
而非客户端的 ClientConfigurationHandler 子类 ——
ClientConfigurationHandler 实现了 IResourceManagerReloadListener,
那是纯客户端接口,不能在服务端加载。
init(:18-23)
super.init(event); // PacketHandler.init()
FMLCommonHandler.instance().bus().register(new PlayerHandler());
FMLCommonHandler.instance().bus().register(new WorldHandler());
| 处理器 | 作用 |
|---|---|
| PlayerHandler | 玩家登录时下发世界种子 |
| WorldHandler | 每秒广播下次下雨时间 |
⚠️ 服务端不注册任何客户端内容 ——
不注册 TickerManager、不注册 KeyInputHandler、
不注册 /igi 命令、不注册 ClientConfigurationHandler。
覆写情况
| 钩子 | 是否覆写 |
|---|---|
preInit |
✅ |
init |
✅ 加 @Override |
postInit |
❌ 继承基类的空实现 |
serverStarting |
❌ 继承基类的空实现 |
serverStopping |
❌ 继承基类的空实现 |
⚠️ postInit 未覆写有实际后果:
PluginLoader 的
postInit(:60-69)负责真正 plugin.load() 并把
instance 置 null。服务端不调它 →
集成 plugin 只被 preInit 加载进列表,从不 load()。
由于 plugin.load() 只是注册集成 tag,而 tag 只在客户端求值,
这个行为结果正确(服务端不需要 tag)。
但 PluginLoader.instance 单例在服务端永不释放(保持非 null)。
相关
- CommonProxy - 父类,含
PacketHandler.init - ClientProxy - 对侧,7 处注册
- PlayerHandler / WorldHandler - 本类注册的两个处理器