Scripts
Built-In Cached Scripts accessible anytime in your menus

Objects

Name
Description
player
The player object: org.bukkit.entity.Player
bukkitServer
The server object: Bukkit.getServer()
utils
Assist Utils (TrUtils): me.arasple.mc.trmenu.utils.Assist (see below)

Example

1
Buttons!
2
'*':
3
update: [-1, 5, 20, -1]
4
display:
5
material: <skull:9842dc3b917b1a796c303e15105474a8e315de7982b6ca54feafb5a4d13d4e95>
6
name:
7
- '&3&lSERVER'
8
- '&b&lSE&3&lRVER'
9
- '&3&lS&b&lER&3&lVER'
10
- '&3&lSE&b&lRV&3&lER'
11
- '&3&lSER&b&lVE&3&lR'
12
- '&3&lSERV&b&lER'
13
lore:
14
- ''
15
- '&8| &7RAM: &2%server_ram_used%/%server_ram_total% &7MB'
16
- '&8[ %progress_bar_{server_ram_used}_m:{server_ram_total}_c:&3■_p:&7■_r:&8■_l:20% &8]'
17
- ''
18
- '&b${flash_➥} &3Left-Click &7to open the help menu.'
19
actions:
20
left:
21
- 'open: help'
22
23
Functions:
24
flash: |-
25
function flash() {
26
var display = new Date().getSeconds() % 2 == 0
27
return display ? "{0}" : " "
28
}
29
flash()
Copied!

Assist Utils (TrUtils)

1
package me.arasple.mc.trmenu.utils
2
3
import io.izzel.taboolib.internal.apache.lang3.math.NumberUtils
4
import io.izzel.taboolib.module.compat.EconomyHook
5
import io.izzel.taboolib.module.tellraw.TellrawJson
6
import io.izzel.taboolib.util.item.ItemBuilder
7
import io.izzel.taboolib.util.item.Items
8
import io.izzel.taboolib.util.lite.Numbers
9
import me.arasple.mc.trmenu.data.MetaPlayer.getArguments
10
import me.arasple.mc.trmenu.modules.action.Actions
11
import me.arasple.mc.trmenu.modules.hook.HookCronus
12
import me.arasple.mc.trmenu.modules.hook.HookPlayerPoints
13
import me.arasple.mc.trmenu.modules.item.ItemIdentifierHandler
14
import me.arasple.mc.trmenu.modules.web.WebData
15
import me.clip.placeholderapi.PlaceholderAPI
16
import org.bukkit.*
17
import org.bukkit.entity.Player
18
import org.bukkit.inventory.ItemStack
19
20
21
/**
22
* @author Arasple
23
* @date 2020/7/21 20:57
24
*/
25
class Assist {
26
27
fun runAction(player: Player, vararg actions: String) = actions.filter { it.isNotBlank() }.forEach { Actions.runCachedAction(player, it) }
28
29
fun parseBracketPlaceholders(player: OfflinePlayer, string: String): String = PlaceholderAPI.setBracketPlaceholders(player, string)
30
31
fun connect(player: Player, server: String) = Bungees.connect(player, server)
32
33
fun sendBungeeData(player: Player, vararg data: String) = Bungees.sendBungeeData(player, *data)
34
35
fun getPlayerArgs(player: String): Array<String> = getPlayer(player)?.getArguments() ?: arrayOf()
36
37
fun isPlayerOperator(player: String) = getPlayer(player).let { return@let it != null && it.isOp }
38
39
fun isPlayerOnline(player: String) = getPlayer(player).let { return@let it != null && it.isOnline }
40
41
fun getPlayer(player: String): Player? = Bukkit.getPlayerExact(player)
42
43
fun getOnlinePlayers(): Collection<Player> = Bukkit.getOnlinePlayers()
44
45
@ExperimentalStdlibApi
46
fun getRandomPlayer(): Player? = Bukkit.getOnlinePlayers().randomOrNull()
47
48
fun getItemBuildr(): ItemBuilder = ItemBuilder(Material.STONE)
49
50
fun getTellraw(): TellrawJson = TellrawJson.create()
51
52
fun emptyString(length: Int) = buildString {
53
for (i in 0..length) append(" ")
54
}
55
56
fun equalsIgnoreCase(sample: String, temp: String) = sample.equals(temp, true)
57
58
fun chance(number: String) = Numbers.random(NumberUtils.toDouble(number, 0.0))
59
60
fun randomInteger(low: Int, high: Int): Int = IntRange(low, high).random()
61
62
fun randomDouble(low: Double, high: Double) = Numbers.getRandomDouble(low, high)
63
64
fun isNumber(number: String) = NumberUtils.isParsable(number)
65
66
fun isInt(number: String) =
67
try {
68
number.toInt()
69
true
70
} catch (e: Throwable) {
71
false
72
}
73
74
75
fun toInt(number: String) = NumberUtils.toInt(number, -1)
76
77
fun toDouble(number: String) = NumberUtils.toDouble(number, -1.0)
78
79
fun isWithin(input: String, low: String, high: String) = IntRange(low.toInt(), high.toInt()).contains(input.toInt())
80
81
fun isSmaller(input1: String, input2: String) = NumberUtils.toDouble(input1) < NumberUtils.toDouble(input2)
82
83
fun isSmallerOrEqual(input1: String, input2: String) = NumberUtils.toDouble(input1) <= NumberUtils.toDouble(input2)
84
85
fun isGreater(input1: String?, input2: String?) = NumberUtils.toDouble(input1) > NumberUtils.toDouble(input2)
86
87
fun isGreaterOrEqual(input1: String?, input2: String?) = NumberUtils.toDouble(input1) >= NumberUtils.toDouble(input2)
88
89
fun createLocation(world: String?, x: Double, z: Double): Location? {
90
val y = Bukkit.getWorld(world!!)!!.getHighestBlockYAt(x.toInt(), z.toInt()).toDouble()
91
return createLocation(world, x, y, z)
92
}
93
94
fun createLocation(world: String?, x: Double, y: Double, z: Double): Location? {
95
return createLocation(world, x, y, z, 0f, 0f)
96
}
97
98
fun createLocation(world: String?, x: Double, y: Double, z: Double, yaw: Float, pitch: Float): Location? {
99
return Location(Bukkit.getWorld(world!!), x, y, z, yaw, pitch)
100
}
101
102
fun createLocation(world: World, x: Double, z: Double): Location? {
103
val y = world.getHighestBlockYAt(x.toInt(), z.toInt()).toDouble()
104
return createLocation(world, x, y, z)
105
}
106
107
fun createLocation(world: World?, x: Double, y: Double, z: Double): Location? {
108
return createLocation(world, x, y, z, 0f, 0f)
109
}
110
111
fun createLocation(world: World?, x: Double, y: Double, z: Double, yaw: Float, pitch: Float): Location? {
112
return Location(world, x, y, z, yaw, pitch)
113
}
114
115
fun hasMoney(player: Player, money: String) = hasMoney(player, NumberUtils.toDouble(money, 0.0))
116
117
fun hasMoney(player: Player, money: Double) = EconomyHook.get(player) >= money
118
119
fun hasPoints(player: Player, points: String) = hasPoints(player, NumberUtils.toInt(points, 0))
120
121
fun hasPoints(player: Player, points: Int) = HookPlayerPoints.hasPoints(player, points)
122
123
fun getItemName(itemStack: ItemStack): String = Items.getName(itemStack)
124
125
fun query(url: String) = WebData.query(url)
126
127
fun hasItem(player: String, identify: String) = getPlayer(player)?.let { ItemIdentifierHandler.read(identify).hasItem(it) } ?: false
128
129
fun hasItem(player: Player, identify: String) = ItemIdentifierHandler.read(identify).hasItem(player)
130
131
fun evalCronusCondition(player: String, condition: String) = getPlayer(player)?.let { return@let evalCronusCondition(it, condition) } ?: false
132
133
fun evalCronusCondition(player: Player, condition: String) = HookCronus.parseCondition(condition).check(player)
134
135
companion object {
136
137
val INSTANCE = Assist()
138
139
}
140
141
142
}
Copied!
Last modified 1yr ago