插件主类是你在新建项目当中填写的主类名称
比如我的是
> cn.lliiooll.demo.DemoMain
那么我就可以在
![](https://img.kancloud.cn/eb/b2/ebb27966815259cc0a7ddf1068bf0390_1920x1048.png)
找到我的主类
我们可以看到主类里面有两个方法是 onLoad和onEnable
onLoad方法可有可无,而onEnable方法是必须的
我们在onEnable方法体里注册命令、以及监听器
就像:
~~~
@Override
public void onEnable() {
getLogger().info("插件加载完毕!");
this.getEventListener().subscribeAlways(事件.class, new 监听器() });
}
~~~
他现在看起来会变成这样
~~~
package cn.lliiooll.demo;
import net.mamoe.mirai.console.plugins.PluginBase;
class DemoMain extends PluginBase {
@Override
public void onLoad() {
super.onLoad();
// 插件加载
}
@Override
public void onEnable() {
super.onEnable();
getLogger().info("插件加载完毕!");
}
@Override
public void onDisable(){
super.onDisable();
//当插件关闭时
}
}
~~~