Skip to content

Commit

Permalink
style(fabric): fix onebot-client导入变化
Browse files Browse the repository at this point in the history
  • Loading branch information
cnlimiter committed Feb 21, 2024
1 parent eef9b51 commit 0b06e3d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 32 deletions.
17 changes: 9 additions & 8 deletions fabric/src/main/java/cn/evole/mods/mcbot/McBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import cn.evole.mods.mcbot.util.locale.I18n;
import cn.evole.onebot.client.connection.ConnectFactory;
import cn.evole.onebot.client.core.Bot;
import cn.evole.onebot.client.handler.EventBus;
import cn.evole.onebot.client.factory.ListenerFactory;
import cn.evole.onebot.sdk.util.FileUtils;
import net.fabricmc.api.ModInitializer;
//#if MC >= 11900
Expand All @@ -31,7 +31,7 @@ public class McBot implements ModInitializer {

public static LinkedBlockingQueue<String> blockingQueue;
public static ConnectFactory service;
public static EventBus bus;
public static ListenerFactory listenerFactory;
public static Bot bot;
public static Thread app;

Expand Down Expand Up @@ -93,19 +93,20 @@ public void onServerStarted(MinecraftServer server) {
Const.LOGGER.error("▌ §c机器人服务端未配置或未打开");
}
}
bus = new EventBus(blockingQueue);//创建事件分发器
listenerFactory = new ListenerFactory(blockingQueue);//创建事件分发器
listenerFactory.start();
CustomCmdHandler.INSTANCE.load();//自定义命令加载
IBotEvent.init(bus);//事件监听
IBotEvent.init(listenerFactory);//事件监听
}

public void onServerStopping(MinecraftServer server) {
Const.isShutdown = true;
Const.LOGGER.info("▌ §c正在关闭群服互联 §a┈━═☆");
bus.stop();//分发器关闭
service.stop();
app.interrupt();
UserBindApi.save(CONFIG_FOLDER);
CustomCmdHandler.INSTANCE.clear();//自定义命令持久层清空
listenerFactory.stop();//分发器关闭
service.stop();
app.interrupt();
}

public void onServerStopped(MinecraftServer server) {
Expand All @@ -114,7 +115,7 @@ public void onServerStopped(MinecraftServer server) {

private static void killOutThreads() {
try {
bus.stop();//分发器关闭
listenerFactory.stop();//分发器关闭
service.stop();
app.interrupt();
} catch (Exception ignored) {
Expand Down
10 changes: 5 additions & 5 deletions fabric/src/main/java/cn/evole/mods/mcbot/cmds/CustomCmd.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cn.evole.mods.mcbot.cmds;

import cn.evole.onebot.sdk.util.json.JsonsObject;
import cn.evole.onebot.sdk.util.json.GsonUtils;
import com.google.gson.JsonObject;
import lombok.val;

Expand Down Expand Up @@ -28,13 +28,13 @@ public CustomCmd(String cmdAlies, String cmdContent, int requirePermission) {

public static CustomCmd loadFromJson(JsonObject json) {

val alies = JsonsObject.parse(json).optString("alies");
val content = JsonsObject.parse(json).optString("content");
int role = JsonsObject.parse(json).optInt("role", 0);
val alies = GsonUtils.getAsString(json,"alies");
val content = GsonUtils.getAsString(json,"content");
int role = GsonUtils.getAsInt(json,"role", 0);

val cmd = new CustomCmd(alies, content, role);

val enabled = JsonsObject.parse(json).optBool("enabled", true);
val enabled = GsonUtils.getAsBoolean(json,"enabled", true);

cmd.setEnabled(enabled);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public BotConfig(TomlTable source) {
this.load(BotConfig.class);
}

public cn.evole.onebot.client.config.BotConfig toBot(){
return new cn.evole.onebot.client.config.BotConfig(url, token, botId, isAccessToken, miraiHttp, reconnect, maxReconnectAttempts, msgType);
public cn.evole.onebot.client.core.BotConfig toBot(){
return new cn.evole.onebot.client.core.BotConfig(url, token, botId, isAccessToken, miraiHttp, reconnect, maxReconnectAttempts, msgType);
}
}
35 changes: 18 additions & 17 deletions fabric/src/main/java/cn/evole/mods/mcbot/init/event/IBotEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
import cn.evole.mods.mcbot.cmds.CmdApi;
import cn.evole.mods.mcbot.init.config.ModConfig;
import cn.evole.mods.mcbot.util.onebot.CQUtils;
import cn.evole.onebot.client.handler.DefaultEventHandler;
import cn.evole.onebot.client.handler.EventBus;
import cn.evole.onebot.client.listener.SimpleEventListener;
import cn.evole.onebot.client.factory.ListenerFactory;
import cn.evole.onebot.client.interfaces.handler.DefaultHandler;
import cn.evole.onebot.client.interfaces.listener.SimpleListener;
import cn.evole.onebot.sdk.event.message.GroupMessageEvent;
import cn.evole.onebot.sdk.event.message.GuildMessageEvent;
import cn.evole.onebot.sdk.event.message.MessageEvent;
import cn.evole.onebot.sdk.event.meta.LifecycleMetaEvent;
import cn.evole.onebot.sdk.event.notice.group.GroupDecreaseNoticeEvent;
import cn.evole.onebot.sdk.event.notice.group.GroupIncreaseNoticeEvent;
Expand All @@ -23,7 +24,7 @@
* Version: 1.0
*/
public class IBotEvent {
public static void init(EventBus dispatchers) {
public static void init(ListenerFactory dispatchers) {

GroupChatHandler(dispatchers);
GroupCmdsHandler(dispatchers);
Expand All @@ -33,8 +34,8 @@ public static void init(EventBus dispatchers) {
LifeCycleHandler(dispatchers);
}

private static void GroupChatHandler(EventBus dispatchers) {
dispatchers.addListener(new DefaultEventHandler<GroupMessageEvent>() {
private static void GroupChatHandler(ListenerFactory dispatchers) {
dispatchers.addListener(new DefaultHandler<GroupMessageEvent>() {
@Override
public void onMessage(GroupMessageEvent event) {
if (ModConfig.INSTANCE.getCommon().getGroupIdList().contains(event.getGroupId())//判断是否是配置中的群
Expand Down Expand Up @@ -69,8 +70,8 @@ public void onMessage(GroupMessageEvent event) {
});
}

private static void GroupCmdsHandler(EventBus dispatchers) {
dispatchers.addListener(new SimpleEventListener<GroupMessageEvent>() {
private static void GroupCmdsHandler(ListenerFactory dispatchers) {
dispatchers.addListener(new SimpleListener<GroupMessageEvent>() {
@Override
public void onMessage(GroupMessageEvent event) {
if (ModConfig.INSTANCE.getCommon().getGroupIdList().contains(event.getGroupId())
Expand All @@ -84,8 +85,8 @@ public void onMessage(GroupMessageEvent event) {
});
}

private static void GroupNoticeHandler(EventBus dispatchers) {
dispatchers.addListener(new SimpleEventListener<GroupIncreaseNoticeEvent>() {
private static void GroupNoticeHandler(ListenerFactory dispatchers) {
dispatchers.addListener(new SimpleListener<GroupIncreaseNoticeEvent>() {
@Override
public void onMessage(GroupIncreaseNoticeEvent event) {
if (ModConfig.INSTANCE.getCommon().getGroupIdList().contains(event.getGroupId())
Expand All @@ -97,7 +98,7 @@ public void onMessage(GroupIncreaseNoticeEvent event) {
}
});

dispatchers.addListener(new SimpleEventListener<GroupDecreaseNoticeEvent>() {
dispatchers.addListener(new SimpleListener<GroupDecreaseNoticeEvent>() {
@Override
public void onMessage(GroupDecreaseNoticeEvent event) {
if (ModConfig.INSTANCE.getCommon().getGroupIdList().contains(event.getGroupId())
Expand All @@ -112,8 +113,8 @@ public void onMessage(GroupDecreaseNoticeEvent event) {

}

private static void GuildChatHandler(EventBus dispatchers) {
dispatchers.addListener(new SimpleEventListener<GuildMessageEvent>() {
private static void GuildChatHandler(ListenerFactory dispatchers) {
dispatchers.addListener(new SimpleListener<GuildMessageEvent>() {
@Override
public void onMessage(GuildMessageEvent event) {
if (event.getGuildId().equals(ModConfig.INSTANCE.getCommon().getGuildId())
Expand Down Expand Up @@ -149,8 +150,8 @@ public void onMessage(GuildMessageEvent event) {
});
}

private static void GuildCmdsHandler(EventBus dispatchers) {
dispatchers.addListener(new SimpleEventListener<GuildMessageEvent>() {
private static void GuildCmdsHandler(ListenerFactory dispatchers) {
dispatchers.addListener(new SimpleListener<GuildMessageEvent>() {
@Override
public void onMessage(GuildMessageEvent event) {
if (ModConfig.INSTANCE.getCommon().getChannelIdList().contains(event.getChannelId())
Expand All @@ -165,8 +166,8 @@ public void onMessage(GuildMessageEvent event) {
}


private static void LifeCycleHandler(EventBus dispatchers) {
dispatchers.addListener(new SimpleEventListener<LifecycleMetaEvent>() {
private static void LifeCycleHandler(ListenerFactory dispatchers) {
dispatchers.addListener(new SimpleListener<LifecycleMetaEvent>() {
@Override
public void onMessage(LifecycleMetaEvent event) {
if (!event.getSubType().equals("connect")) return;
Expand Down

0 comments on commit 0b06e3d

Please sign in to comment.