Skip to content

Commit faa25ba

Browse files
authored
Merge pull request #260 from xiaoyiluck666/pr/meoweco-clean-20260308
fix(meoweco): align UUID API + services provider integration
2 parents 8919f2a + 02f290a commit faa25ba

7 files changed

Lines changed: 174 additions & 0 deletions

File tree

plugin/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ taboolib {
3131
name("NBTAPI").with("bukkit").optional(true).loadafter(true)
3232
name("TrMenu-Graal").with("bukkit").optional(true)
3333
name("AzureFlow").with("bukkit").optional(true)
34+
name("MeowEco").with("bukkit").optional(true)
3435
name("CraftEngine").with("bukkit").optional(true)
3536
name("SX-Item").with("bukkit").optional(true)
3637
}
@@ -98,5 +99,6 @@ dependencies {
9899
compileOnly("com.willfp:EcoItems:5.49.1") { isTransitive = false }
99100
compileOnly("net.momirealms:craft-engine-core:0.0.22") { isTransitive = false }
100101
compileOnly("net.momirealms:craft-engine-bukkit:0.0.22") { isTransitive = false }
102+
compileOnly(files("libs/MeowEco-26.7.0.jar"))
101103
compileOnly(fileTree("libs"))
102104
}

plugin/libs/MeowEco-26.7.0.jar

919 KB
Binary file not shown.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package trplugins.menu.api.action.impl.hook
2+
3+
import taboolib.common.platform.ProxyPlayer
4+
import trplugins.menu.api.action.ActionHandle
5+
import trplugins.menu.api.action.base.ActionBase
6+
import trplugins.menu.api.action.base.ActionContents
7+
import trplugins.menu.module.internal.hook.HookPlugin
8+
9+
/**
10+
* @author Arasple
11+
* @date 2024/3/7
12+
*/
13+
class MecoGive(handle: ActionHandle) : ActionBase(handle) {
14+
15+
override val regex = "meco-give".toRegex()
16+
17+
override fun onExecute(contents: ActionContents, player: ProxyPlayer, placeholderPlayer: ProxyPlayer) {
18+
val args = contents.stringContent().parseContent(placeholderPlayer).trim().split(Regex("\\s+"))
19+
if (args.size >= 2) {
20+
val currencyId = args[0]
21+
val amount = args[1].toDoubleOrNull() ?: 0.0
22+
HookPlugin.getMeowEco().giveBalance(player.cast(), currencyId, amount)
23+
}
24+
}
25+
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package trplugins.menu.api.action.impl.hook
2+
3+
import taboolib.common.platform.ProxyPlayer
4+
import trplugins.menu.api.action.ActionHandle
5+
import trplugins.menu.api.action.base.ActionBase
6+
import trplugins.menu.api.action.base.ActionContents
7+
import trplugins.menu.module.internal.hook.HookPlugin
8+
9+
/**
10+
* @author Arasple
11+
* @date 2024/3/7
12+
*/
13+
class MecoTake(handle: ActionHandle) : ActionBase(handle) {
14+
15+
override val regex = "meco-take".toRegex()
16+
17+
override fun onExecute(contents: ActionContents, player: ProxyPlayer, placeholderPlayer: ProxyPlayer) {
18+
val args = contents.stringContent().parseContent(placeholderPlayer).trim().split(Regex("\\s+"))
19+
if (args.size >= 2) {
20+
val currencyId = args[0]
21+
val amount = args[1].toDoubleOrNull() ?: 0.0
22+
HookPlugin.getMeowEco().takeBalance(player.cast(), currencyId, amount)
23+
}
24+
}
25+
26+
}

plugin/src/main/kotlin/trplugins/menu/module/internal/hook/HookPlugin.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ object HookPlugin {
9898
return get(HookNeigeItems::class.java)
9999
}
100100

101+
fun getMeowEco(): HookMeowEco {
102+
return get(HookMeowEco::class.java)
103+
}
104+
101105
fun getEcoItem(): HookEcoItems {
102106
return get(HookEcoItems::class.java)
103107
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package trplugins.menu.module.internal.hook.impl
2+
3+
import org.bukkit.OfflinePlayer
4+
import org.bukkit.Bukkit
5+
import taboolib.library.reflex.Reflex.Companion.invokeMethod
6+
import trplugins.menu.module.internal.hook.HookAbstract
7+
import java.util.UUID
8+
9+
/**
10+
* @author Arasple
11+
* @date 2024/3/7
12+
*/
13+
class HookMeowEco : HookAbstract() {
14+
15+
private val apiClassName = "com.xiaoyiluck.meoweco.api.MeowEcoAPI"
16+
17+
private fun getApiInstance(): Any? {
18+
if (!isHooked) return null
19+
return runCatching {
20+
val apiClass = Class.forName(apiClassName)
21+
val registration = Bukkit.getServicesManager().invokeMethod<Any>("getRegistration", apiClass) ?: return null
22+
registration.invokeMethod<Any>("getProvider")
23+
}.getOrNull()
24+
}
25+
26+
private fun invokeApi(api: Any, methodName: String, vararg rawArgs: Any?): Any? {
27+
return runCatching { api.invokeMethod<Any?>(methodName, *rawArgs) }.getOrNull()
28+
}
29+
30+
private fun asDouble(value: Any?): Double {
31+
return when (value) {
32+
is Number -> value.toDouble()
33+
else -> value?.toString()?.toDoubleOrNull() ?: 0.0
34+
}
35+
}
36+
37+
private fun asBoolean(value: Any?): Boolean {
38+
return when (value) {
39+
is Boolean -> value
40+
is Number -> value.toInt() != 0
41+
else -> value?.toString()?.toBooleanStrictOrNull() ?: false
42+
}
43+
}
44+
45+
fun getBalance(player: OfflinePlayer, currencyId: String): Double {
46+
val api = getApiInstance() ?: return 0.0
47+
return asDouble(invokeApi(api, "getBalance", player.uniqueId, currencyId))
48+
}
49+
50+
fun takeBalance(player: OfflinePlayer, currencyId: String, amount: Double): Boolean {
51+
val api = getApiInstance() ?: return false
52+
return asBoolean(invokeApi(api, "withdraw", player.uniqueId, currencyId, amount))
53+
}
54+
55+
fun giveBalance(player: OfflinePlayer, currencyId: String, amount: Double): Boolean {
56+
val api = getApiInstance() ?: return false
57+
return asBoolean(invokeApi(api, "deposit", player.uniqueId, currencyId, amount))
58+
}
59+
60+
fun getAvailableBalance(player: OfflinePlayer, currencyId: String): Double {
61+
val api = getApiInstance() ?: return 0.0
62+
return asDouble(invokeApi(api, "getAvailableBalance", player.uniqueId, currencyId))
63+
}
64+
65+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package trplugins.menu.module.internal.script.impl
2+
3+
import taboolib.library.kether.ArgTypes
4+
import taboolib.library.kether.ParsedAction
5+
import taboolib.library.kether.QuestContext
6+
import taboolib.module.kether.KetherParser
7+
import taboolib.module.kether.scriptParser
8+
import trplugins.menu.module.internal.hook.HookPlugin
9+
import trplugins.menu.module.internal.script.kether.BaseAction
10+
import java.util.concurrent.CompletableFuture
11+
12+
/**
13+
* @author Arasple
14+
* @date 2024/3/7
15+
*/
16+
class KetherMeco(val currencyId: String, val operator: String, val value: ParsedAction<*>) : BaseAction<Boolean>() {
17+
18+
override fun process(context: QuestContext.Frame): CompletableFuture<Boolean> {
19+
return context.newFrame(value).run<Any>().thenApply {
20+
val amount = it.toString().toDoubleOrNull() ?: 0.0
21+
val player = context.viewer()
22+
val balance = HookPlugin.getMeowEco().getBalance(player, currencyId)
23+
24+
when (operator) {
25+
"==" -> balance == amount
26+
"!=" -> balance != amount
27+
">" -> balance > amount
28+
"<" -> balance < amount
29+
">=" -> balance >= amount
30+
"<=" -> balance <= amount
31+
else -> false
32+
}
33+
}
34+
}
35+
36+
companion object {
37+
38+
/**
39+
* meco points >= 100
40+
*/
41+
@KetherParser(["meco"], namespace = "trmenu", shared = true)
42+
fun parser() = scriptParser {
43+
val currencyId = it.nextToken()
44+
val operator = it.nextToken()
45+
val value = it.next(ArgTypes.ACTION)
46+
KetherMeco(currencyId, operator, value)
47+
}
48+
49+
}
50+
51+
}

0 commit comments

Comments
 (0)