Bloques de código
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
Buttons!
'*':
update: [-1, 5, 20, -1]
display:
material: <skull:9842dc3b917b1a796c303e15105474a8e315de7982b6ca54feafb5a4d13d4e95>
name:
- '&3&lSERVER'
- '&b&lSE&3&lRVER'
- '&3&lS&b&lER&3&lVER'
- '&3&lSE&b&lRV&3&lER'
- '&3&lSER&b&lVE&3&lR'
- '&3&lSERV&b&lER'
lore:
- ''
- '&8| &7RAM: &2%server_ram_used%/%server_ram_total% &7MB'
- '&8[ %progress_bar_{server_ram_used}_m:{server_ram_total}_c:&3■_p:&7■_r:&8■_l:20% &8]'
- ''
- '&b${flash_➥} &3Left-Click &7to open the help menu.'
actions:
left:
- 'open: help'
Functions:
flash: |-
function flash() {
var display = new Date().getSeconds() % 2 == 0
return display ? "{0}" : " "
}
flash()
Assist Utils (TrUtils)
package me.arasple.mc.trmenu.utils
import io.izzel.taboolib.internal.apache.lang3.math.NumberUtils
import io.izzel.taboolib.module.compat.EconomyHook
import io.izzel.taboolib.module.tellraw.TellrawJson
import io.izzel.taboolib.util.item.ItemBuilder
import io.izzel.taboolib.util.item.Items
import io.izzel.taboolib.util.lite.Numbers
import me.arasple.mc.trmenu.data.MetaPlayer.getArguments
import me.arasple.mc.trmenu.modules.action.Actions
import me.arasple.mc.trmenu.modules.hook.HookCronus
import me.arasple.mc.trmenu.modules.hook.HookPlayerPoints
import me.arasple.mc.trmenu.modules.item.ItemIdentifierHandler
import me.arasple.mc.trmenu.modules.web.WebData
import me.clip.placeholderapi.PlaceholderAPI
import org.bukkit.*
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
/**
* @author Arasple
* @date 2020/7/21 20:57
*/
class Assist {
fun runAction(player: Player, vararg actions: String) = actions.filter { it.isNotBlank() }.forEach { Actions.runCachedAction(player, it) }
fun parseBracketPlaceholders(player: OfflinePlayer, string: String): String = PlaceholderAPI.setBracketPlaceholders(player, string)
fun connect(player: Player, server: String) = Bungees.connect(player, server)
fun sendBungeeData(player: Player, vararg data: String) = Bungees.sendBungeeData(player, *data)
fun getPlayerArgs(player: String): Array<String> = getPlayer(player)?.getArguments() ?: arrayOf()
fun isPlayerOperator(player: String) = getPlayer(player).let { return@let it != null && it.isOp }
fun isPlayerOnline(player: String) = getPlayer(player).let { return@let it != null && it.isOnline }
fun getPlayer(player: String): Player? = Bukkit.getPlayerExact(player)
fun getOnlinePlayers(): Collection<Player> = Bukkit.getOnlinePlayers()
@ExperimentalStdlibApi
fun getRandomPlayer(): Player? = Bukkit.getOnlinePlayers().randomOrNull()
fun getItemBuildr(): ItemBuilder = ItemBuilder(Material.STONE)
fun getTellraw(): TellrawJson = TellrawJson.create()
fun emptyString(length: Int) = buildString {
for (i in 0..length) append(" ")
}
fun equalsIgnoreCase(sample: String, temp: String) = sample.equals(temp, true)
fun chance(number: String) = Numbers.random(NumberUtils.toDouble(number, 0.0))
fun randomInteger(low: Int, high: Int): Int = IntRange(low, high).random()
fun randomDouble(low: Double, high: Double) = Numbers.getRandomDouble(low, high)
fun isNumber(number: String) = NumberUtils.isParsable(number)
fun isInt(number: String) =
try {
number.toInt()
true
} catch (e: Throwable) {
false
}
fun toInt(number: String) = NumberUtils.toInt(number, -1)
fun toDouble(number: String) = NumberUtils.toDouble(number, -1.0)
fun isWithin(input: String, low: String, high: String) = IntRange(low.toInt(), high.toInt()).contains(input.toInt())
fun isSmaller(input1: String, input2: String) = NumberUtils.toDouble(input1) < NumberUtils.toDouble(input2)
fun isSmallerOrEqual(input1: String, input2: String) = NumberUtils.toDouble(input1) <= NumberUtils.toDouble(input2)
fun isGreater(input1: String?, input2: String?) = NumberUtils.toDouble(input1) > NumberUtils.toDouble(input2)
fun isGreaterOrEqual(input1: String?, input2: String?) = NumberUtils.toDouble(input1) >= NumberUtils.toDouble(input2)
fun createLocation(world: String?, x: Double, z: Double): Location? {
val y = Bukkit.getWorld(world!!)!!.getHighestBlockYAt(x.toInt(), z.toInt()).toDouble()
return createLocation(world, x, y, z)
}
fun createLocation(world: String?, x: Double, y: Double, z: Double): Location? {
return createLocation(world, x, y, z, 0f, 0f)
}
fun createLocation(world: String?, x: Double, y: Double, z: Double, yaw: Float, pitch: Float): Location? {
return Location(Bukkit.getWorld(world!!), x, y, z, yaw, pitch)
}
fun createLocation(world: World, x: Double, z: Double): Location? {
val y = world.getHighestBlockYAt(x.toInt(), z.toInt()).toDouble()
return createLocation(world, x, y, z)
}
fun createLocation(world: World?, x: Double, y: Double, z: Double): Location? {
return createLocation(world, x, y, z, 0f, 0f)
}
fun createLocation(world: World?, x: Double, y: Double, z: Double, yaw: Float, pitch: Float): Location? {
return Location(world, x, y, z, yaw, pitch)
}
fun hasMoney(player: Player, money: String) = hasMoney(player, NumberUtils.toDouble(money, 0.0))
fun hasMoney(player: Player, money: Double) = EconomyHook.get(player) >= money
fun hasPoints(player: Player, points: String) = hasPoints(player, NumberUtils.toInt(points, 0))
fun hasPoints(player: Player, points: Int) = HookPlayerPoints.hasPoints(player, points)
fun getItemName(itemStack: ItemStack): String = Items.getName(itemStack)
fun query(url: String) = WebData.query(url)
fun hasItem(player: String, identify: String) = getPlayer(player)?.let { ItemIdentifierHandler.read(identify).hasItem(it) } ?: false
fun hasItem(player: Player, identify: String) = ItemIdentifierHandler.read(identify).hasItem(player)
fun evalCronusCondition(player: String, condition: String) = getPlayer(player)?.let { return@let evalCronusCondition(it, condition) } ?: false
fun evalCronusCondition(player: Player, condition: String) = HookCronus.parseCondition(condition).check(player)
companion object {
val INSTANCE = Assist()
}
}
Last updated