diff --git a/plugin/build.gradle.kts b/plugin/build.gradle.kts index 4f882efd..98020ad1 100644 --- a/plugin/build.gradle.kts +++ b/plugin/build.gradle.kts @@ -31,6 +31,7 @@ taboolib { name("NBTAPI").with("bukkit").optional(true).loadafter(true) name("TrMenu-Graal").with("bukkit").optional(true) name("AzureFlow").with("bukkit").optional(true) + name("MeowEco").with("bukkit").optional(true) name("CraftEngine").with("bukkit").optional(true) name("SX-Item").with("bukkit").optional(true) } @@ -98,5 +99,6 @@ dependencies { compileOnly("com.willfp:EcoItems:5.49.1") { isTransitive = false } compileOnly("net.momirealms:craft-engine-core:0.0.22") { isTransitive = false } compileOnly("net.momirealms:craft-engine-bukkit:0.0.22") { isTransitive = false } + compileOnly(files("libs/MeowEco-26.7.0.jar")) compileOnly(fileTree("libs")) } diff --git a/plugin/libs/MeowEco-26.7.0.jar b/plugin/libs/MeowEco-26.7.0.jar new file mode 100644 index 00000000..3e2c109c Binary files /dev/null and b/plugin/libs/MeowEco-26.7.0.jar differ diff --git a/plugin/src/main/kotlin/trplugins/menu/api/action/impl/hook/MecoGive.kt b/plugin/src/main/kotlin/trplugins/menu/api/action/impl/hook/MecoGive.kt new file mode 100644 index 00000000..1ce2c5e1 --- /dev/null +++ b/plugin/src/main/kotlin/trplugins/menu/api/action/impl/hook/MecoGive.kt @@ -0,0 +1,26 @@ +package trplugins.menu.api.action.impl.hook + +import taboolib.common.platform.ProxyPlayer +import trplugins.menu.api.action.ActionHandle +import trplugins.menu.api.action.base.ActionBase +import trplugins.menu.api.action.base.ActionContents +import trplugins.menu.module.internal.hook.HookPlugin + +/** + * @author Arasple + * @date 2024/3/7 + */ +class MecoGive(handle: ActionHandle) : ActionBase(handle) { + + override val regex = "meco-give".toRegex() + + override fun onExecute(contents: ActionContents, player: ProxyPlayer, placeholderPlayer: ProxyPlayer) { + val args = contents.stringContent().parseContent(placeholderPlayer).split(" ") + if (args.size >= 2) { + val currencyId = args[0] + val amount = args[1].toDoubleOrNull() ?: 0.0 + HookPlugin.getMeowEco().giveBalance(player.cast(), currencyId, amount) + } + } + +} diff --git a/plugin/src/main/kotlin/trplugins/menu/api/action/impl/hook/MecoTake.kt b/plugin/src/main/kotlin/trplugins/menu/api/action/impl/hook/MecoTake.kt new file mode 100644 index 00000000..3cddbf31 --- /dev/null +++ b/plugin/src/main/kotlin/trplugins/menu/api/action/impl/hook/MecoTake.kt @@ -0,0 +1,26 @@ +package trplugins.menu.api.action.impl.hook + +import taboolib.common.platform.ProxyPlayer +import trplugins.menu.api.action.ActionHandle +import trplugins.menu.api.action.base.ActionBase +import trplugins.menu.api.action.base.ActionContents +import trplugins.menu.module.internal.hook.HookPlugin + +/** + * @author Arasple + * @date 2024/3/7 + */ +class MecoTake(handle: ActionHandle) : ActionBase(handle) { + + override val regex = "meco-take".toRegex() + + override fun onExecute(contents: ActionContents, player: ProxyPlayer, placeholderPlayer: ProxyPlayer) { + val args = contents.stringContent().parseContent(placeholderPlayer).split(" ") + if (args.size >= 2) { + val currencyId = args[0] + val amount = args[1].toDoubleOrNull() ?: 0.0 + HookPlugin.getMeowEco().takeBalance(player.cast(), currencyId, amount) + } + } + +} diff --git a/plugin/src/main/kotlin/trplugins/menu/module/internal/hook/HookPlugin.kt b/plugin/src/main/kotlin/trplugins/menu/module/internal/hook/HookPlugin.kt index e2348461..e87af9b3 100644 --- a/plugin/src/main/kotlin/trplugins/menu/module/internal/hook/HookPlugin.kt +++ b/plugin/src/main/kotlin/trplugins/menu/module/internal/hook/HookPlugin.kt @@ -98,6 +98,10 @@ object HookPlugin { return get(HookNeigeItems::class.java) } + fun getMeowEco(): HookMeowEco { + return get(HookMeowEco::class.java) + } + fun getEcoItem(): HookEcoItems { return get(HookEcoItems::class.java) } diff --git a/plugin/src/main/kotlin/trplugins/menu/module/internal/hook/impl/HookMeowEco.kt b/plugin/src/main/kotlin/trplugins/menu/module/internal/hook/impl/HookMeowEco.kt new file mode 100644 index 00000000..8e748c32 --- /dev/null +++ b/plugin/src/main/kotlin/trplugins/menu/module/internal/hook/impl/HookMeowEco.kt @@ -0,0 +1,51 @@ +package trplugins.menu.module.internal.hook.impl + +import org.bukkit.OfflinePlayer +import taboolib.library.reflex.Reflex.Companion.invokeMethod +import trplugins.menu.module.internal.hook.HookAbstract + +/** + * @author Arasple + * @date 2024/3/7 + */ +class HookMeowEco : HookAbstract() { + + private val apiClassName = "com.xiaoyiluck.meoweco.api.MeowEcoAPI" + + private fun getApiInstance(): Any? { + if (!isHooked) return null + return try { + Class.forName(apiClassName).invokeMethod("get") + } catch (e: Throwable) { + null + } + } + + fun getBalance(player: OfflinePlayer, currencyId: String): Double { + val api = getApiInstance() ?: return 0.0 + return try { + api.invokeMethod("getBalance", player, currencyId)?.toDouble() ?: 0.0 + } catch (e: Throwable) { + 0.0 + } + } + + fun takeBalance(player: OfflinePlayer, currencyId: String, amount: Double): Boolean { + val api = getApiInstance() ?: return false + return try { + api.invokeMethod("takeBalance", player, currencyId, amount) ?: false + } catch (e: Throwable) { + false + } + } + + fun giveBalance(player: OfflinePlayer, currencyId: String, amount: Double): Boolean { + val api = getApiInstance() ?: return false + return try { + api.invokeMethod("giveBalance", player, currencyId, amount) ?: false + } catch (e: Throwable) { + false + } + } + +} diff --git a/plugin/src/main/kotlin/trplugins/menu/module/internal/script/impl/KetherMeco.kt b/plugin/src/main/kotlin/trplugins/menu/module/internal/script/impl/KetherMeco.kt new file mode 100644 index 00000000..26a955a9 --- /dev/null +++ b/plugin/src/main/kotlin/trplugins/menu/module/internal/script/impl/KetherMeco.kt @@ -0,0 +1,51 @@ +package trplugins.menu.module.internal.script.impl + +import taboolib.library.kether.ArgTypes +import taboolib.library.kether.ParsedAction +import taboolib.library.kether.QuestContext +import taboolib.module.kether.KetherParser +import taboolib.module.kether.scriptParser +import trplugins.menu.module.internal.hook.HookPlugin +import trplugins.menu.module.internal.script.kether.BaseAction +import java.util.concurrent.CompletableFuture + +/** + * @author Arasple + * @date 2024/3/7 + */ +class KetherMeco(val currencyId: String, val operator: String, val value: ParsedAction<*>) : BaseAction() { + + override fun process(context: QuestContext.Frame): CompletableFuture { + return context.newFrame(value).run().thenApply { + val amount = it.toString().toDoubleOrNull() ?: 0.0 + val player = context.viewer() + val balance = HookPlugin.getMeowEco().getBalance(player, currencyId) + + when (operator) { + "==" -> balance == amount + "!=" -> balance != amount + ">" -> balance > amount + "<" -> balance < amount + ">=" -> balance >= amount + "<=" -> balance <= amount + else -> false + } + } + } + + companion object { + + /** + * meco points >= 100 + */ + @KetherParser(["meco"], namespace = "trmenu", shared = true) + fun parser() = scriptParser { + val currencyId = it.nextToken() + val operator = it.nextToken() + val value = it.next(ArgTypes.ACTION) + KetherMeco(currencyId, operator, value) + } + + } + +}