在使用
复制代码
后服务端报错
版本: 1.18.1
复制代码
此段代码
- Bukkit.dispatchCommand(Bukkit.getConsoleSender(), e.getMessage().replace("*", ""));
后服务端报错
版本: 1.18.1
- if (e.getMessage().startsWith("*")) {
- if (!Main.list.contains(e.getSenderID())) {
- MiraiBot.getBot(e.getBotID()).getGroup(e.getGroupID()).sendMessage("[警告] 你没有权限这么做!");
- } else {
- try {
- Bukkit.dispatchCommand(Bukkit.getConsoleSender(), e.getMessage().replace("*", ""));
- MiraiBot.getBot(e.getBotID()).getGroup(e.getGroupID()).sendMessage("[信息] 执行成功!");
- } catch (Exception a) {
- MiraiBot.getBot(e.getBotID()).getGroup(e.getGroupID()).sendMessage("[错误] 指令不正确!");
- a.printStackTrace();
- }
- }
- }
此段代码
Bukkit.dispatchCommand需要在主线程内执行
嘉晚饭,赢 发表于 2022-1-30 19:45
Bukkit.dispatchCommand需要在主线程内执行
具体需要怎么做
本帖最后由 嘉晚饭,赢 于 2022-1-30 19:50 编辑
复制代码
ExamplePlugin.instance是你插件主类的实例
EmeraldEgg 发表于 2022-1-30 19:46
具体需要怎么做
- Bukkit.getScheduler().runTask(ExamplePlugin.instance, () -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), e.getMessage().replace("*", "")));
ExamplePlugin.instance是你插件主类的实例