Skip to content

Commit

Permalink
Addon: compatible with MCL 1.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
PeratX committed Jul 30, 2021
1 parent cbae85a commit 1fdf1b2
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 11 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ repositories {
}

dependencies {
implementation("org.itxtech:mirai-console-loader:1.2.1")
implementation("org.itxtech:mirai-console-loader:1.2.2")
//Mirai Console Terminal Deps
implementation("net.mamoe:mirai-console-terminal:2.7-M2")
implementation("org.jline:jline:3.15.0")
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/org/itxtech/mcl/addon/InternalAccessor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.itxtech.mcl.addon;

import net.mamoe.mirai.console.plugin.Plugin;

/*
*
* MCL Addon
*
* Copyright (C) 2021 iTX Technologies
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author PeratX
* @website https://github.com/iTXTech/mcl-addon
*
*/
@SuppressWarnings("ALL")
public class InternalAccessor {
public static void addResolvedPlugin(Plugin plugin) {
net.mamoe.mirai.console.internal.plugin.PluginManagerImpl.INSTANCE.resolvedPlugins.add(plugin);
}
}
1 change: 1 addition & 0 deletions src/main/kotlin/org/itxtech/mcl/addon/command.kt
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ object MclCommand : CompositeCommand(
try {
it.load()
it.enable()
InternalAccessor.addResolvedPlugin(it)
} catch (ignored: IllegalStateException) {
} catch (e: Exception) {
addon.mcl.logger.logException(e)
Expand Down
29 changes: 20 additions & 9 deletions src/main/kotlin/org/itxtech/mcl/addon/logger/ConsoleLogger.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,41 +27,52 @@ package org.itxtech.mcl.addon.logger
import kotlinx.coroutines.launch
import net.mamoe.mirai.console.command.CommandSender
import net.mamoe.mirai.console.command.isUser
import net.mamoe.mirai.console.util.sendAnsiMessage
import org.itxtech.mcl.addon.PluginMain
import org.itxtech.mcl.addon.PluginMain.logger
import org.itxtech.mcl.component.Logger
import org.itxtech.mcl.impl.DefaultLogger
import org.itxtech.mcl.utils.AnsiMsg

open class ConsoleLogger : DefaultLogger() {
val sender: ThreadLocal<CommandSender?> = ThreadLocal()

override fun log(s: String, lvl: Int) {
override fun log(s: Any, lvl: Int) {
if (lvl < logLevel) {
return
}
val sender = this.sender.get()
val str = when (s) {
is AnsiMsg -> {
s.renderWithAnsi()
}
!is String -> {
s.toString()
}
else -> s
}
if (sender != null && sender.isUser()) {
PluginMain.launch {
try {
sender.sendMessage(s)
sender.sendAnsiMessage(str)
} catch (ignored: Exception) {
}
}
return
}
when (lvl) {
Logger.LOG_DEBUG -> logger.debug(s)
Logger.LOG_INFO -> logger.info(s)
Logger.LOG_WARNING -> logger.warning(s)
Logger.LOG_ERROR -> logger.error(s)
else -> logger.info(s)
Logger.LOG_DEBUG -> logger.debug(str)
Logger.LOG_INFO -> logger.info(str)
Logger.LOG_WARNING -> logger.warning(str)
Logger.LOG_ERROR -> logger.error(str)
else -> logger.info(str)
}
}

override fun println(s: String) {
override fun println(s: Any) {
info(s)
}

override fun print(s: String) {
override fun print(s: Any) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import net.mamoe.mirai.console.command.isConsole
import net.mamoe.mirai.console.terminal.terminal

class TerminalLogger : ConsoleLogger() {
override fun print(s: String) {
override fun print(s: Any) {
val sender = sender.get()
if (sender != null && sender.isConsole()) {
terminal.writer().print(s)
Expand Down

0 comments on commit 1fdf1b2

Please sign in to comment.