diff --git a/common/src/main/kotlin/taboolib/common/io/File1.kt b/common/src/main/kotlin/taboolib/common/io/FileCreate.kt similarity index 74% rename from common/src/main/kotlin/taboolib/common/io/File1.kt rename to common/src/main/kotlin/taboolib/common/io/FileCreate.kt index 1f788d76e..eab4f6162 100644 --- a/common/src/main/kotlin/taboolib/common/io/File1.kt +++ b/common/src/main/kotlin/taboolib/common/io/FileCreate.kt @@ -1,5 +1,8 @@ +@file:Isolated +@file:Suppress("NOTHING_TO_INLINE") package taboolib.common.io +import taboolib.common.Isolated import java.io.File /** @@ -11,7 +14,7 @@ import java.io.File * @param folder 该文件是否为文件夹(默认为否) * @return 该文件自身 */ -fun newFile(file: File, path: String, create: Boolean = true, folder: Boolean = false): File { +inline fun newFile(file: File, path: String, create: Boolean = true, folder: Boolean = false): File { return newFile(File(file, path), create, folder) } @@ -23,7 +26,7 @@ fun newFile(file: File, path: String, create: Boolean = true, folder: Boolean = * @param folder 该文件是否为文件夹(默认为否) * @return 该文件自身 */ -fun newFile(path: String, create: Boolean = true, folder: Boolean = false): File { +inline fun newFile(path: String, create: Boolean = true, folder: Boolean = false): File { return newFile(File(path), create, folder) } @@ -35,7 +38,7 @@ fun newFile(path: String, create: Boolean = true, folder: Boolean = false): File * @param folder 该文件是否为文件夹(默认为否) * @return 该文件自身 */ -fun newFile(file: File, create: Boolean = true, folder: Boolean = false): File { +inline fun newFile(file: File, create: Boolean = true, folder: Boolean = false): File { if (!file.parentFile.exists()) { file.parentFile.mkdirs() } @@ -57,7 +60,7 @@ fun newFile(file: File, create: Boolean = true, folder: Boolean = false): File { * @param create 若目录不存在是否新建(默认为是) * @return 该目录自身 */ -fun newFolder(folder: File, path: String, create: Boolean = true): File { +inline fun newFolder(folder: File, path: String, create: Boolean = true): File { return newFile(folder, path, create, folder = true) } @@ -68,6 +71,6 @@ fun newFolder(folder: File, path: String, create: Boolean = true): File { * @param create 若目录不存在是否新建(默认为是) * @return 该目录自身 */ -fun newFolder(path: String, create: Boolean = true): File { +inline fun newFolder(path: String, create: Boolean = true): File { return newFile(path, create, folder = true) } \ No newline at end of file diff --git a/common/src/main/kotlin/taboolib/common/io/FileDelete1.kt b/common/src/main/kotlin/taboolib/common/io/FileDelete1.kt new file mode 100644 index 000000000..8483d1eb9 --- /dev/null +++ b/common/src/main/kotlin/taboolib/common/io/FileDelete1.kt @@ -0,0 +1,32 @@ +@file:Isolated + +package taboolib.common.io + +import taboolib.common.Isolated +import java.io.File +import java.util.concurrent.Executors +import java.util.concurrent.Future + +/** + * 删除特定文件夹下的所有子文件 + */ +fun File.deepDelete() { + if (exists()) { + if (isDirectory) { + listFiles()?.forEach { it.deepDelete() } + } + delete() + } +} + +/** + * 复制文件或文件夹 + * 若目标为文件夹则复制其所有子文件 + */ +fun File.deepCopyTo(target: File) { + if (isDirectory) { + listFiles()?.forEach { it.deepCopyTo(File(target, it.name)) } + } else { + copyTo(target) + } +} diff --git a/common/src/main/kotlin/taboolib/common/io/File2.kt b/common/src/main/kotlin/taboolib/common/io/FileDelete2.kt similarity index 78% rename from common/src/main/kotlin/taboolib/common/io/File2.kt rename to common/src/main/kotlin/taboolib/common/io/FileDelete2.kt index 55e0e4d13..422bd5ee3 100644 --- a/common/src/main/kotlin/taboolib/common/io/File2.kt +++ b/common/src/main/kotlin/taboolib/common/io/FileDelete2.kt @@ -41,28 +41,4 @@ fun File.deepDeleteAsync(await: Boolean = false, futures: MutableSet>? // Wait the task to finish before returning if await is true // It shouldn't be called inside this function if (await) future.get() -} - -/** - * 删除特定文件夹下的所有子文件 - */ -fun File.deepDelete() { - if (exists()) { - if (isDirectory) { - listFiles()?.forEach { it.deepDelete() } - } - delete() - } -} - -/** - * 复制文件或文件夹 - * 若目标为文件夹则复制其所有子文件 - */ -fun File.deepCopyTo(target: File) { - if (isDirectory) { - listFiles()?.forEach { it.deepCopyTo(File(target, it.name)) } - } else { - copyTo(target) - } -} +} \ No newline at end of file diff --git a/common/src/main/kotlin/taboolib/common/io/File3.kt b/common/src/main/kotlin/taboolib/common/io/FileDigest.kt similarity index 87% rename from common/src/main/kotlin/taboolib/common/io/File3.kt rename to common/src/main/kotlin/taboolib/common/io/FileDigest.kt index 3f27921b6..ecbf5e2d2 100644 --- a/common/src/main/kotlin/taboolib/common/io/File3.kt +++ b/common/src/main/kotlin/taboolib/common/io/FileDigest.kt @@ -1,4 +1,5 @@ @file:Isolated +@file:Suppress("NOTHING_TO_INLINE") package taboolib.common.io @@ -15,7 +16,7 @@ import java.security.MessageDigest * @param algorithm 算法类型(可使用:md5, sha-1, sha-256 等) * @return 数字签名 */ -fun String.digest(algorithm: String): String { +inline fun String.digest(algorithm: String): String { val digest = MessageDigest.getInstance(algorithm) digest.update(toByteArray(StandardCharsets.UTF_8)) return BigInteger(1, digest.digest()).toString(16) @@ -27,7 +28,7 @@ fun String.digest(algorithm: String): String { * @param algorithm 算法类型(可使用:md5, sha-1, sha-256 等) * @return 数字签名 */ -fun File.digest(algorithm: String): String { +inline fun File.digest(algorithm: String): String { return FileInputStream(this).use { val digest = MessageDigest.getInstance(algorithm) val buffer = ByteArray(1024) diff --git a/common/src/main/kotlin/taboolib/common/platform/PlatformFactory.kt b/common/src/main/kotlin/taboolib/common/platform/PlatformFactory.kt index b5268c901..aefd6795a 100644 --- a/common/src/main/kotlin/taboolib/common/platform/PlatformFactory.kt +++ b/common/src/main/kotlin/taboolib/common/platform/PlatformFactory.kt @@ -13,6 +13,7 @@ import taboolib.common.platform.function.runningPlatform import taboolib.common.platform.function.unregisterCommands import java.util.concurrent.ConcurrentHashMap +@Suppress("UNCHECKED_CAST") object PlatformFactory { val awokenMap = ConcurrentHashMap() @@ -104,30 +105,32 @@ object PlatformFactory { /** * 获取已被唤醒的 API 实例 */ - inline fun getAPI(): T { - return awokenMap[T::class.java.name] as? T ?: error("API (${T::class.java.name}) not found, currently: ${awokenMap.keys}") - } + inline fun getAPI() : T = getAPI(T::class.java.name) /** * 获取已被唤醒的 API 实例(可能为空) */ - inline fun getAPIOrNull(): T? { - return awokenMap[T::class.java.name] as? T - } + inline fun getAPIOrNull() = awokenMap[T::class.java.name] as? T + + /** + * 获取已被唤醒的 API 实例 + */ + fun getAPI(name: String) = (awokenMap[name] ?: error("API ($name) not found, currently: ${awokenMap.keys}")) as T /** * 获取已注册的跨平台服务 */ - inline fun getService(): T { - return serviceMap[T::class.java.name] as? T ?: error("Service (${T::class.java}) not found, currently: ${serviceMap.keys}") - } + inline fun getService() : T = getService(T::class.java.name) /** * 获取已注册的跨平台服务(可能为空) */ - inline fun getServiceOrNull(): T? { - return serviceMap[T::class.java.name] as? T - } + inline fun getServiceOrNull() = serviceMap[T::class.java.name] as? T + + /** + * 获取已注册的跨平台服务 + */ + fun getService(name: String) = (serviceMap[name] ?: error("Service ($name) not found, currently: ${serviceMap.keys}")) as T /** * 注册 API 实例 diff --git a/common/src/main/kotlin/taboolib/common/platform/function/Adapter.kt b/common/src/main/kotlin/taboolib/common/platform/function/Adapter.kt index ae38ec65c..401bf039a 100644 --- a/common/src/main/kotlin/taboolib/common/platform/function/Adapter.kt +++ b/common/src/main/kotlin/taboolib/common/platform/function/Adapter.kt @@ -1,5 +1,9 @@ +@file:Isolated +@file:Suppress("NOTHING_TO_INLINE") + package taboolib.common.platform.function +import taboolib.common.Isolated import taboolib.common.platform.PlatformFactory import taboolib.common.platform.ProxyCommandSender import taboolib.common.platform.ProxyPlayer @@ -10,49 +14,49 @@ import java.util.* /** * 获取控制台 */ -fun console(): ProxyCommandSender { +inline fun console(): ProxyCommandSender { return PlatformFactory.getService().console() } /** * 将平台实现转换为跨平台实现 */ -fun adaptCommandSender(any: Any): ProxyCommandSender { +inline fun adaptCommandSender(any: Any): ProxyCommandSender { return PlatformFactory.getService().adaptCommandSender(any) } /** * 获取所有在线玩家 */ -fun onlinePlayers(): List { +inline fun onlinePlayers(): List { return PlatformFactory.getService().onlinePlayers() } /** * 将平台实现转换为跨平台实现 */ -fun adaptPlayer(any: Any): ProxyPlayer { +inline fun adaptPlayer(any: Any): ProxyPlayer { return PlatformFactory.getService().adaptPlayer(any) } /** * 通过名称获取玩家 */ -fun getProxyPlayer(name: String): ProxyPlayer? { +inline fun getProxyPlayer(name: String): ProxyPlayer? { return onlinePlayers().firstOrNull { it.name.equals(name, true) } } /** * 通过 UUID 获取玩家 */ -fun getProxyPlayer(uuid: UUID): ProxyPlayer? { +inline fun getProxyPlayer(uuid: UUID): ProxyPlayer? { return onlinePlayers().firstOrNull { it.uniqueId == uuid } } /** * 将平台实现转换为跨平台实现 */ -fun adaptLocation(any: Any): Location { +inline fun adaptLocation(any: Any): Location { return PlatformFactory.getService().adaptLocation(any) } @@ -60,13 +64,13 @@ fun adaptLocation(any: Any): Location { * 将跨平台实现转换为平台实现 */ @Suppress("UNCHECKED_CAST") -fun platformLocation(location: Location): T { +inline fun platformLocation(location: Location): T { return PlatformFactory.getService().platformLocation(location) as T } /** * 获取所有世界 */ -fun allWorlds(): List { +inline fun allWorlds(): List { return PlatformFactory.getService().allWorlds() } \ No newline at end of file diff --git a/common/src/main/kotlin/taboolib/common/platform/function/Command.kt b/common/src/main/kotlin/taboolib/common/platform/function/Command.kt index ddd0161ad..ac7a4e2ca 100644 --- a/common/src/main/kotlin/taboolib/common/platform/function/Command.kt +++ b/common/src/main/kotlin/taboolib/common/platform/function/Command.kt @@ -1,5 +1,9 @@ +@file:Isolated +@file:Suppress("NOTHING_TO_INLINE") + package taboolib.common.platform.function +import taboolib.common.Isolated import taboolib.common.platform.PlatformFactory import taboolib.common.platform.command.CommandCompleter import taboolib.common.platform.command.CommandExecutor @@ -15,7 +19,7 @@ import taboolib.common.platform.service.PlatformCommand * @param completer 补全器 * @param commandBuilder 命令构建器 */ -fun registerCommand(command: CommandStructure, executor: CommandExecutor, completer: CommandCompleter, commandBuilder: CommandBase.() -> Unit) { +inline fun registerCommand(command: CommandStructure, executor: CommandExecutor, completer: CommandCompleter, noinline commandBuilder: CommandBase.() -> Unit) { PlatformFactory.getService().registerCommand(command, executor, completer, commandBuilder) } @@ -24,7 +28,7 @@ fun registerCommand(command: CommandStructure, executor: CommandExecutor, comple * * @param command 命令结构 */ -fun unregisterCommand(command: CommandStructure) { +inline fun unregisterCommand(command: CommandStructure) { unregisterCommand(command.name) command.aliases.forEach { unregisterCommand(it) } } @@ -34,13 +38,13 @@ fun unregisterCommand(command: CommandStructure) { * * @param command 命令名称 */ -fun unregisterCommand(command: String) { +inline fun unregisterCommand(command: String) { PlatformFactory.getService().unregisterCommand(command) } /** * 注销所有命令 */ -fun unregisterCommands() { +inline fun unregisterCommands() { PlatformFactory.getService().unregisterCommands() } \ No newline at end of file diff --git a/common/src/main/kotlin/taboolib/common/platform/function/Common.kt b/common/src/main/kotlin/taboolib/common/platform/function/Common.kt index 3d4d2c0fd..c0f174924 100644 --- a/common/src/main/kotlin/taboolib/common/platform/function/Common.kt +++ b/common/src/main/kotlin/taboolib/common/platform/function/Common.kt @@ -1,4 +1,6 @@ @file:Isolated +@file:Suppress("NOTHING_TO_INLINE") + package taboolib.common.platform.function import taboolib.common.Isolated @@ -16,7 +18,7 @@ inline val runningPlatform: Platform /** * 停用插件 */ -fun disablePlugin() { +inline fun disablePlugin() { TabooLibCommon.setStopped(true) } @@ -26,7 +28,7 @@ fun disablePlugin() { * @param lifeCycle 生命周期 * @param runnable 任务 */ -fun postpone(lifeCycle: LifeCycle = LifeCycle.ENABLE, runnable: Runnable) { +inline fun postpone(lifeCycle: LifeCycle = LifeCycle.ENABLE, runnable: Runnable) { TabooLibCommon.postpone(lifeCycle, runnable) } diff --git a/common/src/main/kotlin/taboolib/common/platform/function/Event.kt b/common/src/main/kotlin/taboolib/common/platform/function/Event.kt index 3b9442766..c3202cb98 100644 --- a/common/src/main/kotlin/taboolib/common/platform/function/Event.kt +++ b/common/src/main/kotlin/taboolib/common/platform/function/Event.kt @@ -1,9 +1,13 @@ +@file:Isolated +@file:Suppress("NOTHING_TO_INLINE") + package taboolib.common.platform.function +import taboolib.common.Isolated import taboolib.common.platform.PlatformFactory import taboolib.common.platform.event.ProxyEvent import taboolib.common.platform.service.PlatformEvent -fun callEvent(proxyEvent: ProxyEvent) { +inline fun callEvent(proxyEvent: ProxyEvent) { PlatformFactory.getService().callEvent(proxyEvent) } \ No newline at end of file diff --git a/common/src/main/kotlin/taboolib/common/platform/function/IO.kt b/common/src/main/kotlin/taboolib/common/platform/function/IO.kt index 2adc84d65..803093377 100644 --- a/common/src/main/kotlin/taboolib/common/platform/function/IO.kt +++ b/common/src/main/kotlin/taboolib/common/platform/function/IO.kt @@ -1,34 +1,20 @@ +@file:Isolated +@file:Suppress("NOTHING_TO_INLINE") + package taboolib.common.platform.function +import taboolib.common.Isolated import taboolib.common.io.isDevelopmentMode import taboolib.common.platform.PlatformFactory import taboolib.common.platform.service.PlatformIO import java.io.File -/** - * 获取当前插件名称 - */ -val pluginId: String - get() = PlatformFactory.getService().pluginId - -/** - * 获取当前插件版本 - */ -val pluginVersion: String - get() = PlatformFactory.getService().pluginVersion - -/** - * 当前是否在主线程中运行 - */ -val isPrimaryThread: Boolean - get() = PlatformFactory.getService().isPrimaryThread - /** * 获取控制台对象 * 例如: * server() */ -fun server(): T { +inline fun server(): T { return PlatformFactory.getService().server() } @@ -37,7 +23,7 @@ fun server(): T { * * @param message 日志内容 */ -fun dev(vararg message: Any?) { +inline fun dev(vararg message: Any?) { if (isDevelopmentMode) { info(*message) } @@ -48,7 +34,7 @@ fun dev(vararg message: Any?) { * * @param message 日志内容 */ -fun info(vararg message: Any?) { +inline fun info(vararg message: Any?) { PlatformFactory.getService().info(*message) } @@ -57,7 +43,7 @@ fun info(vararg message: Any?) { * * @param message 日志内容 */ -fun severe(vararg message: Any?) { +inline fun severe(vararg message: Any?) { PlatformFactory.getService().severe(*message) } @@ -66,7 +52,7 @@ fun severe(vararg message: Any?) { * * @param message 日志内容 */ -fun warning(vararg message: Any?) { +inline fun warning(vararg message: Any?) { PlatformFactory.getService().warning(*message) } @@ -77,14 +63,14 @@ fun warning(vararg message: Any?) { * @param replace 是否覆盖文件 * @param target 资源文件目标路径 */ -fun releaseResourceFile(source: String, replace: Boolean = false, target: String = source): File { +inline fun releaseResourceFile(source: String, replace: Boolean = false, target: String = source): File { return PlatformFactory.getService().releaseResourceFile(source, target, replace) } /** * 获取当前插件的 Jar 文件对象 */ -fun getJarFile(): File { +inline fun getJarFile(): File { return PlatformFactory.getService().getJarFile() } @@ -92,7 +78,7 @@ fun getJarFile(): File { * 获取当前插件的配置文件目录 * 可能不存在,需要手动调用 mkdirs 方法创建 */ -fun getDataFolder(): File { +inline fun getDataFolder(): File { return PlatformFactory.getService().getDataFolder() } @@ -100,6 +86,6 @@ fun getDataFolder(): File { * 获取当前平台的信息 * 用于 BStats 统计,无实际用途 */ -fun getPlatformData(): Map { +inline fun getPlatformData(): Map { return PlatformFactory.getService().getPlatformData() } \ No newline at end of file diff --git a/common/src/main/kotlin/taboolib/common/platform/function/OpenContainer.kt b/common/src/main/kotlin/taboolib/common/platform/function/OpenContainer.kt index f04632bef..5d705447e 100644 --- a/common/src/main/kotlin/taboolib/common/platform/function/OpenContainer.kt +++ b/common/src/main/kotlin/taboolib/common/platform/function/OpenContainer.kt @@ -1,5 +1,9 @@ +@file:Isolated +@file:Suppress("NOTHING_TO_INLINE") + package taboolib.common.platform.function +import taboolib.common.Isolated import taboolib.common.OpenContainer import taboolib.common.platform.PlatformFactory import taboolib.common.platform.service.PlatformOpenContainer @@ -7,7 +11,7 @@ import taboolib.common.platform.service.PlatformOpenContainer /** * 获取当前服务端中运行的所有开放接口 */ -fun getOpenContainers(): List { +inline fun getOpenContainers(): List { return PlatformFactory.getService().getOpenContainers() } @@ -16,6 +20,6 @@ fun getOpenContainers(): List { * * @param name 接口名称 */ -fun getOpenContainer(name: String): OpenContainer? { +inline fun getOpenContainer(name: String): OpenContainer? { return PlatformFactory.getService().getOpenContainers().firstOrNull { it.name == name } } \ No newline at end of file diff --git a/common/src/main/kotlin/taboolib/common/platform/function/Plugin.kt b/common/src/main/kotlin/taboolib/common/platform/function/Plugin.kt new file mode 100644 index 000000000..950c2e6e6 --- /dev/null +++ b/common/src/main/kotlin/taboolib/common/platform/function/Plugin.kt @@ -0,0 +1,25 @@ +@file:Isolated + +package taboolib.common.platform.function + +import taboolib.common.Isolated +import taboolib.common.platform.PlatformFactory +import taboolib.common.platform.service.PlatformIO + +/** + * 获取当前插件名称 + */ +inline val pluginId: String + get() = PlatformFactory.getService().pluginId + +/** + * 获取当前插件版本 + */ +inline val pluginVersion: String + get() = PlatformFactory.getService().pluginVersion + +/** + * 当前是否在主线程中运行 + */ +inline val isPrimaryThread: Boolean + get() = PlatformFactory.getService().isPrimaryThread \ No newline at end of file diff --git a/common/src/main/kotlin/taboolib/common/util/Collection.kt b/common/src/main/kotlin/taboolib/common/util/Collection.kt index b4efbb066..e65d2a53d 100644 --- a/common/src/main/kotlin/taboolib/common/util/Collection.kt +++ b/common/src/main/kotlin/taboolib/common/util/Collection.kt @@ -1,9 +1,10 @@ @file:Isolated +@file:Suppress("NOTHING_TO_INLINE") package taboolib.common.util import taboolib.common.Isolated -fun Any.asList(): List { +inline fun Any.asList(): List { return when (this) { is Collection<*> -> map { it.toString() } is Array<*> -> map { it.toString() } diff --git a/common/src/main/kotlin/taboolib/common/util/Common.kt b/common/src/main/kotlin/taboolib/common/util/Common.kt index f0c55bbe8..09240ece2 100644 --- a/common/src/main/kotlin/taboolib/common/util/Common.kt +++ b/common/src/main/kotlin/taboolib/common/util/Common.kt @@ -1,8 +1,12 @@ +@file:Isolated +@file:Suppress("NOTHING_TO_INLINE") + package taboolib.common.util +import taboolib.common.Isolated import java.util.function.Supplier -fun join(args: Array, start: Int = 0, separator: String = " "): String { +inline fun join(args: Array, start: Int = 0, separator: String = " "): String { return args.filterIndexed { index, _ -> index >= start }.joinToString(separator) } @@ -13,11 +17,14 @@ fun join(args: Array, start: Int = 0, separator: String = " "): String { * @param start 开始位置 * @param end 结束位置(默认为元素数量) */ -fun subList(list: List, start: Int = 0, end: Int = list.size): List { +inline fun subList(list: List, start: Int = 0, end: Int = list.size): List { return list.filterIndexed { index, _ -> index in start until end } } -fun Class<*>.nonPrimitive(): Class<*> { +/** + * 将原始类型转换为包装类型 + */ +inline fun Class<*>.nonPrimitive(): Class<*> { return when { this == Integer.TYPE -> Integer::class.java this == Character.TYPE -> Character::class.java @@ -31,7 +38,7 @@ fun Class<*>.nonPrimitive(): Class<*> { } } -fun lazySupplier(supplier: () -> T): Supplier { +inline fun lazySupplier(noinline supplier: () -> T): Supplier { return object : Supplier { val value by unsafeLazy { supplier() } diff --git a/common/src/main/kotlin/taboolib/common/util/Executor.kt b/common/src/main/kotlin/taboolib/common/util/Executor.kt index 96ff175b9..07b8d0dc0 100644 --- a/common/src/main/kotlin/taboolib/common/util/Executor.kt +++ b/common/src/main/kotlin/taboolib/common/util/Executor.kt @@ -1,4 +1,6 @@ @file:Isolated +@file:Suppress("NOTHING_TO_INLINE") + package taboolib.common.util import taboolib.common.Isolated @@ -12,7 +14,7 @@ import java.util.concurrent.CompletableFuture * @throws IllegalStateException 如果当前线程为主线程 * @return 任务返回值 */ -fun sync(func: () -> T): T { +inline fun sync(noinline func: () -> T): T { if (isPrimaryThread) { error("Cannot run sync task in main thread.") } diff --git a/common/src/main/kotlin/taboolib/common/util/Map.kt b/common/src/main/kotlin/taboolib/common/util/Map.kt index 9d19d5b6d..6084e09e7 100644 --- a/common/src/main/kotlin/taboolib/common/util/Map.kt +++ b/common/src/main/kotlin/taboolib/common/util/Map.kt @@ -1,8 +1,10 @@ @file:Isolated +@file:Suppress("NOTHING_TO_INLINE") + package taboolib.common.util import taboolib.common.Isolated -fun subMap(map: Map, start: Int = 0, end: Int = map.size - 1): List> { +inline fun subMap(map: Map, start: Int = 0, end: Int = map.size - 1): List> { return map.entries.filterIndexed { index, _ -> index in start..end } } \ No newline at end of file diff --git a/common/src/main/kotlin/taboolib/common/util/Optional.kt b/common/src/main/kotlin/taboolib/common/util/Optional.kt index 940a6d8cc..71213f245 100644 --- a/common/src/main/kotlin/taboolib/common/util/Optional.kt +++ b/common/src/main/kotlin/taboolib/common/util/Optional.kt @@ -1,4 +1,6 @@ @file:Isolated +@file:Suppress("NOTHING_TO_INLINE") + package taboolib.common.util import taboolib.common.Isolated @@ -9,15 +11,15 @@ import java.util.* * * @param func 执行函数 */ -fun Optional.presentRun(func: T.() -> Unit) { +inline fun Optional.presentRun(noinline func: T.() -> Unit) { ifPresent(func) } -fun Optional.orNull(): T? { +inline fun Optional.orNull(): T? { return orElse(null) } -fun optional(value: Any, func: () -> T): T? { +inline fun optional(value: Any, func: () -> T): T? { try { return func() } catch (ex: NullPointerException) { diff --git a/common/src/main/kotlin/taboolib/common/util/Platform.kt b/common/src/main/kotlin/taboolib/common/util/Platform.kt index fdd515399..b5d1cb236 100644 --- a/common/src/main/kotlin/taboolib/common/util/Platform.kt +++ b/common/src/main/kotlin/taboolib/common/util/Platform.kt @@ -1,4 +1,6 @@ @file:Isolated +@file:Suppress("NOTHING_TO_INLINE") + package taboolib.common.util import taboolib.common.Isolated @@ -8,6 +10,6 @@ import taboolib.common.platform.ProxyPlayer /** * 是否为控制台对象 */ -fun ProxyCommandSender?.isConsole(): Boolean { +inline fun ProxyCommandSender?.isConsole(): Boolean { return this !is ProxyPlayer } \ No newline at end of file diff --git a/common/src/main/kotlin/taboolib/common/util/Random.kt b/common/src/main/kotlin/taboolib/common/util/Random.kt index 32c2147cb..e64314173 100644 --- a/common/src/main/kotlin/taboolib/common/util/Random.kt +++ b/common/src/main/kotlin/taboolib/common/util/Random.kt @@ -1,4 +1,5 @@ @file:Isolated +@file:Suppress("NOTHING_TO_INLINE") package taboolib.common.util @@ -11,7 +12,7 @@ import kotlin.math.min /** * 创建线程安全的随机数生成器 */ -fun random(): Random { +inline fun random(): Random { return ThreadLocalRandom.current() } @@ -20,7 +21,7 @@ fun random(): Random { * * @param v 0-1 */ -fun random(v: Double): Boolean { +inline fun random(v: Double): Boolean { return ThreadLocalRandom.current().nextDouble() <= v } @@ -29,7 +30,7 @@ fun random(v: Double): Boolean { * * @param v 最大值 */ -fun random(v: Int): Int { +inline fun random(v: Int): Int { return ThreadLocalRandom.current().nextInt(v) } @@ -39,7 +40,7 @@ fun random(v: Int): Int { * @param num1 最小值 * @param num2 最大值 */ -fun random(num1: Int, num2: Int): Int { +inline fun random(num1: Int, num2: Int): Int { val min = min(num1, num2) val max = max(num1, num2) return ThreadLocalRandom.current().nextInt(min, max + 1) @@ -51,7 +52,7 @@ fun random(num1: Int, num2: Int): Int { * @param num1 最小值 * @param num2 最大值 */ -fun random(num1: Double, num2: Double): Double { +inline fun random(num1: Double, num2: Double): Double { val min = min(num1, num2) val max = max(num1, num2) return if (min == max) max else ThreadLocalRandom.current().nextDouble(min, max) @@ -62,6 +63,6 @@ fun random(num1: Double, num2: Double): Double { * * @return 0-1 */ -fun randomDouble(): Double { +inline fun randomDouble(): Double { return random().nextDouble() } \ No newline at end of file diff --git a/expansion/expansion-command-helper/src/main/kotlin/taboolib/expansion/CommandHelper.kt b/expansion/expansion-command-helper/src/main/kotlin/taboolib/expansion/CommandHelper.kt index 81e2687c5..8210e4667 100644 --- a/expansion/expansion-command-helper/src/main/kotlin/taboolib/expansion/CommandHelper.kt +++ b/expansion/expansion-command-helper/src/main/kotlin/taboolib/expansion/CommandHelper.kt @@ -1,5 +1,6 @@ package taboolib.expansion +import taboolib.common.Isolated import taboolib.common.platform.ProxyCommandSender import taboolib.common.platform.command.component.CommandComponent import taboolib.common.platform.command.component.CommandComponentDynamic diff --git a/module/module-configuration/build.gradle.kts b/module/module-configuration/build.gradle.kts index 0b635a07d..064b18627 100644 --- a/module/module-configuration/build.gradle.kts +++ b/module/module-configuration/build.gradle.kts @@ -24,9 +24,13 @@ tasks { dependencies { include(dependency("com.electronwill.night-config:core-conversion:6.0.0")) } - relocate("com.electronwill.nightconfig.core.conversion", "taboolib.library.configuration") - relocate("org.yaml.snakeyaml.", "org.yaml.snakeyaml_2_2.") + // 反射库 relocate("org.tabooproject", "taboolib.library") + // nightconfig + relocate("com.electronwill.nightconfig.core.conversion", "taboolib.library.configuration") + relocate("com.electronwill.nightconfig", "com.electronwill.nightconfig_3_6_7") + // snakeyaml + relocate("org.yaml.snakeyaml", "org.yaml.snakeyaml_2_2") minimize() } build { diff --git a/module/module-configuration/src/main/kotlin/taboolib/module/configuration/ConfigLoader.kt b/module/module-configuration/src/main/kotlin/taboolib/module/configuration/ConfigLoader.kt index 69cc310d5..4c195471b 100644 --- a/module/module-configuration/src/main/kotlin/taboolib/module/configuration/ConfigLoader.kt +++ b/module/module-configuration/src/main/kotlin/taboolib/module/configuration/ConfigLoader.kt @@ -18,11 +18,31 @@ import java.util.function.Supplier test = "!org.yaml.snakeyaml_2_2.Yaml", relocate = ["!org.yaml.snakeyaml", "!org.yaml.snakeyaml_2_2"] ), - RuntimeDependency("!com.typesafe:config:1.4.3", test = "!com.typesafe.config.Config"), - RuntimeDependency("!com.electronwill.night-config:core:3.6.7", test = "!com.electronwill.nightconfig.core.Config"), - RuntimeDependency("!com.electronwill.night-config:toml:3.6.7", test = "!com.electronwill.nightconfig.toml.TomlFormat"), - RuntimeDependency("!com.electronwill.night-config:json:3.6.7", test = "!com.electronwill.nightconfig.json.JsonFormat"), - RuntimeDependency("!com.electronwill.night-config:hocon:3.6.7", test = "!com.electronwill.nightconfig.hocon.HoconFormat") + RuntimeDependency( + "!com.typesafe:config:1.4.3", + test = "!com.typesafe.config.Config", + relocate = ["!com.typesafe.config", "!com.typesafe.config_1_4_3"] + ), + RuntimeDependency( + "!com.electronwill.night-config:core:3.6.7", + test = "!com.electronwill.nightconfig.core.Config", + relocate = ["!com.electronwill.nightconfig", "!com.electronwill.nightconfig_3_6_7", "!com.typesafe.config", "!com.typesafe.config_1_4_3"] + ), + RuntimeDependency( + "!com.electronwill.night-config:toml:3.6.7", + test = "!com.electronwill.nightconfig.toml.TomlFormat", + relocate = ["!com.electronwill.nightconfig", "!com.electronwill.nightconfig_3_6_7", "!com.typesafe.config", "!com.typesafe.config_1_4_3"] + ), + RuntimeDependency( + "!com.electronwill.night-config:json:3.6.7", + test = "!com.electronwill.nightconfig.json.JsonFormat", + relocate = ["!com.electronwill.nightconfig", "!com.electronwill.nightconfig_3_6_7", "!com.typesafe.config", "!com.typesafe.config_1_4_3"] + ), + RuntimeDependency( + "!com.electronwill.night-config:hocon:3.6.7", + test = "!com.electronwill.nightconfig.hocon.HoconFormat", + relocate = ["!com.electronwill.nightconfig", "!com.electronwill.nightconfig_3_6_7", "!com.typesafe.config", "!com.typesafe.config_1_4_3"] + ) ) @Awake class ConfigLoader : ClassVisitor(1) { @@ -35,7 +55,6 @@ class ConfigLoader : ClassVisitor(1) { val target = configAnno.property("target", name).let { it.ifEmpty { name } } - if (files.containsKey(name)) { field.set(instance?.get(), files[name]!!.configuration) } else { diff --git a/module/module-metrics/src/main/java/taboolib/module/metrics/Metrics.java b/module/module-metrics/src/main/java/taboolib/module/metrics/Metrics.java index 9e087d4d8..4a556fe73 100644 --- a/module/module-metrics/src/main/java/taboolib/module/metrics/Metrics.java +++ b/module/module-metrics/src/main/java/taboolib/module/metrics/Metrics.java @@ -2,7 +2,7 @@ import kotlin.Unit; import taboolib.common.TabooLibCommon; -import taboolib.common.io.File1Kt; +import taboolib.common.io.FileCreateKt; import taboolib.common.platform.Platform; import taboolib.common.platform.function.AdapterKt; import taboolib.common.platform.function.ExecutorKt; @@ -30,7 +30,7 @@ public Metrics(int serviceId, String pluginVersion, Platform runningPlatform) { } // Get the config file File bStatsFolder = new File(IOKt.getDataFolder().getParentFile(), "bStats"); - File configFile = File1Kt.newFile(bStatsFolder, "config.yml", true, false); + File configFile = FileCreateKt.newFile(bStatsFolder, "config.yml", true, false); SecuredFile config = SecuredFile.Companion.loadConfiguration(configFile); if (!config.contains("serverUUID")) { config.set("enabled", true);