TrMenu
PurchaseGithubLicense
Chinese
Chinese
  • 主页
  • 开始
    • 新版
    • 购买
    • 安装
    • 配置
  • 迁移
  • MENU
    • 结构
      • 标题
      • 布局
      • 选项
      • 绑定
      • 事件
      • 图标
      • 内置脚本
      • 周期任务
    • 图标
      • 更新周期
      • 刷新周期
      • 图标显示
        • 材质
        • 名称
        • Lore
        • 数量
        • 发光
        • 标签
        • NBT
      • 动作交互
      • 优先级
      • 条件
      • 继承
  • ACTIONS
    • 动作
      • 执行命令
      • 执行命令 (OP)
      • 执行命令 (CONSOLE)
      • 执行发送
      • 发送消息
      • 发送 Tellraw
      • 发送 Actionbar
      • 发送 Title & SubTitle
      • 音效
      • 跨服传送
      • 执行脚本
      • 输入捕获
        • 重新输入
      • 辅助
        • 延时
        • 中断
      • 物品
        • 扣除物品
        • 给予物品
        • 附魔物品
        • 修复物品
      • 经济
        • 给予金币
        • 扣除金币
        • 设置金币
        • 给予点卷
        • 扣除点卷
        • 设置点卷
      • 菜单
        • 关闭菜单
        • 关闭菜单 (静默)
        • 打开菜单
        • 切换页码
        • 设置参数
        • 设置标题
        • 刷新图标
      • 数据
        • 设置 Meta
        • 删除 Meta
        • 设置 Data
        • 删除 Data
      • 其他
        • Cronus Effect
        • TabooLib Hologram
        • TabooLib Particle
    • 选项
      • 延时执行
      • 执行条件
      • 执行概率
      • 遍历执行
    • 反应
  • SCRIPT
    • 表达式
      • stringEquals
      • stringEqualsIgnoreCase
      • isNumber
      • isOperator
      • isPlayerOperator
      • hasPermission
      • hasLevel
      • hasMoney
      • hasPoints
      • hasItem
    • 脚本
  • FUNCTIONS
    • 菜单传参
    • 物品特征
    • 脚本变量
    • 注册命令
    • 快捷绑定
    • 模板创建
  • HOOK
    • PlaceholderAPI
    • Cronus
    • Vault
    • PlayerPoints
    • HeadDatabase
    • Oraxen
    • SkinRestorer
  • API
    • TrMenuAPI
    • Events
      • MenuOpenEvent
      • MenuCloseEvent
      • MenuClickEvent
    • MenuFactory
Powered by GitBook
On this page
  • 对象
  • Assist Utils

Was this helpful?

  1. SCRIPT

脚本

对象

Name

Description

player

玩家对象 org.bukkit.entity.Player

bukkitServer

Bukkit 服务器对象 Bukkit.getServer()

utils

辅助工具类 me.arasple.mc.trmenu.utils.Assist

Assist Utils

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()

    }


}
PrevioushasItemNext菜单传参

Last updated 4 years ago

Was this helpful?