This repository was archived by the owner on Sep 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 249
Expand file tree
/
Copy pathItemSource.kt
More file actions
38 lines (33 loc) · 1.46 KB
/
ItemSource.kt
File metadata and controls
38 lines (33 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package trplugins.menu.module.internal.item
import trplugins.menu.module.display.MenuSession
import trplugins.menu.module.internal.hook.HookPlugin
import trplugins.menu.module.internal.hook.impl.HookSkulls
import trplugins.menu.module.internal.script.js.JavaScriptAgent
import org.bukkit.inventory.ItemStack
import trplugins.menu.api.event.CustomItemSourceEvent
import trplugins.menu.module.internal.script.asItemStack
/**
* @author Arasple
* @date 2021/1/27 12:04
*/
object ItemSource {
fun fromSource(session: MenuSession, string: String): ItemStack? {
val identifier = string.split(":", "=", limit = 2)
val name = identifier[0].replace("-", "").uppercase()
val id = identifier[1]
return when (name) {
"HEADDATABASE", "HDB" -> {
if (id.equals("RANDOM", true)) HookPlugin.getHeadDatabase().getRandomHead()
else HookPlugin.getHeadDatabase().getHead(id)
}
"SKULLS" -> {
if (id.equals("RANDOM", true)) HookPlugin[HookSkulls::class.java].getRandomSkull()
else HookPlugin[HookSkulls::class.java].getSkull(id)
}
"JAVASCRIPT", "JS" -> JavaScriptAgent.eval(session, id).asItemStack()
"ITEMSADDER", "IA" -> HookPlugin.getItemsAdder().getItem(id)
"ZAPHKIEL", "ZL" -> HookPlugin.getZaphkiel().getItem(id)
else -> CustomItemSourceEvent(name, id, session).also { it.call() }.source
}
}
}