diff --git a/build.sbt b/build.sbt index d139cc5..104e354 100644 --- a/build.sbt +++ b/build.sbt @@ -117,18 +117,19 @@ saveConfigComments := { val subMatcher = subRegex.matcher(line) val subParamMatcher = subParamRegex.matcher(line) val sub = line.contains("@Subcommand") || line.contains("@Command2.Subcommand") - if (subCommand || sub) //This line or the previous one had the annotation - if (subMatcher.find()) { - /*val groups = (2 to subMatcher.groupCount()).map(subMatcher.group) - val pairs = for (i <- groups.indices by 2) yield (groups(i), groups(i + 1))*/ - val mname = subMatcher.group(1) - val params = Iterator.continually(()).takeWhile(_ => subParamMatcher.find()) - .map(_ => subParamMatcher.group(1)).drop(1) - val section = commandConfig.createSection(s"$pkg.$clName.$mname") - section.set("method", s"$mname()") - section.set("params", params.mkString(" ")) - } - subCommand = sub + if (sub) subCommand = true + else if (line.contains("}")) subCommand = false + if (subCommand && subMatcher.find()) { + /*val groups = (2 to subMatcher.groupCount()).map(subMatcher.group) + val pairs = for (i <- groups.indices by 2) yield (groups(i), groups(i + 1))*/ + val mname = subMatcher.group(1) + val params = Iterator.continually(()).takeWhile(_ => subParamMatcher.find()) + .map(_ => subParamMatcher.group(1)).drop(1) + val section = commandConfig.createSection(s"$pkg.$clName.$mname") + section.set("method", s"$mname()") + section.set("params", params.mkString(" ")) + subCommand = false + } } configConfig.save("target/configHelp.yml") commandConfig.save("target/commands.yml") diff --git a/src/main/scala/buttondevteam/discordplugin/mcchat/MCChatUtils.scala b/src/main/scala/buttondevteam/discordplugin/mcchat/MCChatUtils.scala index bdb8f61..3f0438d 100644 --- a/src/main/scala/buttondevteam/discordplugin/mcchat/MCChatUtils.scala +++ b/src/main/scala/buttondevteam/discordplugin/mcchat/MCChatUtils.scala @@ -49,12 +49,13 @@ object MCChatUtils { def updatePlayerList(): Unit = { val mod = getModule - if (mod == null || !mod.showPlayerListOnDC.get) return + if (mod == null || !mod.showPlayerListOnDC.get) return () if (lastmsgdata != null) updatePL(lastmsgdata) MCChatCustom.lastmsgCustom.foreach(MCChatUtils.updatePL) } private def notEnabled = (module == null || !module.disabling) && getModule == null //Allow using things while disabling the module + private def getModule = { if (module == null || !module.isEnabled) module = ComponentManager.getIfEnabled(classOf[MinecraftChatModule]) //If disabled, it will try to get it again because another instance may be enabled - useful for /discord restart @@ -218,7 +219,7 @@ object MCChatUtils { * @param channel The channel to reset in - the process is slightly different for the public, private and custom chats */ def resetLastMessage(channel: Channel): Unit = { - if (notEnabled) return + if (notEnabled) return () if (channel.getId.asLong == module.chatChannel.get.asLong) { if (lastmsgdata == null) lastmsgdata = new MCChatUtils.LastMsgData(module.chatChannelMono.block(), null) else lastmsgdata.message = null diff --git a/src/main/scala/buttondevteam/discordplugin/mcchat/MinecraftChatModule.scala b/src/main/scala/buttondevteam/discordplugin/mcchat/MinecraftChatModule.scala index 77e35d5..fa2c467 100644 --- a/src/main/scala/buttondevteam/discordplugin/mcchat/MinecraftChatModule.scala +++ b/src/main/scala/buttondevteam/discordplugin/mcchat/MinecraftChatModule.scala @@ -101,7 +101,7 @@ class MinecraftChatModule extends Component[DiscordPlugin] { final private val channelconCommand = new ChannelconCommand(this) override protected def enable(): Unit = { - if (DPUtils.disableIfConfigErrorRes(this, chatChannel, chatChannelMono)) return + if (DPUtils.disableIfConfigErrorRes(this, chatChannel, chatChannelMono)) return () listener = new MCChatListener(this) TBMCCoreAPI.RegisterEventsForExceptions(listener, getPlugin) TBMCCoreAPI.RegisterEventsForExceptions(new MCListener(this), getPlugin) //These get undone if restarting/resetting - it will ignore events if disabled @@ -219,10 +219,14 @@ class MinecraftChatModule extends Component[DiscordPlugin] { * It will block to make sure all messages are sent */ private def sendStateMessage(color: Color, message: String) = - MCChatUtils.forCustomAndAllMCChat(_.flatMap(_.createEmbed(spec => spec.setColor(color).setTitle(message)).^^()), - ChannelconBroadcast.RESTART, hookmsg = false).block() + MCChatUtils.forCustomAndAllMCChat(_.flatMap( + _.createEmbed(_.setColor(color).setTitle(message)).^^() + .onErrorResume(_ => SMono.empty) + ), ChannelconBroadcast.RESTART, hookmsg = false).block() private def sendStateMessage(color: Color, message: String, extra: String) = - MCChatUtils.forCustomAndAllMCChat(_.flatMap(_.createEmbed(_.setColor(color).setTitle(message).setDescription(extra).^^()).^^() - .onErrorResume(_ => SMono.empty)), ChannelconBroadcast.RESTART, hookmsg = false).block() + MCChatUtils.forCustomAndAllMCChat(_.flatMap( + _.createEmbed(_.setColor(color).setTitle(message).setDescription(extra).^^()).^^() + .onErrorResume(_ => SMono.empty) + ), ChannelconBroadcast.RESTART, hookmsg = false).block() } \ No newline at end of file