Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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"))
}
Binary file added plugin/libs/MeowEco-26.7.0.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -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)
}
}

}
Original file line number Diff line number Diff line change
@@ -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)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Any>("get")
} catch (e: Throwable) {
null
}
}

fun getBalance(player: OfflinePlayer, currencyId: String): Double {
val api = getApiInstance() ?: return 0.0
return try {
api.invokeMethod<Number>("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<Boolean>("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<Boolean>("giveBalance", player, currencyId, amount) ?: false
} catch (e: Throwable) {
false
}
}

}
Original file line number Diff line number Diff line change
@@ -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<Boolean>() {

override fun process(context: QuestContext.Frame): CompletableFuture<Boolean> {
return context.newFrame(value).run<Any>().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)
}

}

}