Skip to content
On this page
通用

KattonServerApi

common/src/main/kotlin/top/katton/api/dpcaller/KattonServerApi.kt
访问所有在线玩家。

players

players通用属性
kotlin
val players: KattonPlayerList

访问所有在线玩家。

entities

entities通用属性
kotlin
val entities: KattonServerEntityCollection

访问所有维度中的全部实体。

storage

storage通用属性
kotlin
val storage: CommandStorage

用于保存持久数据的服务器命令存储。

scoreboard

scoreboard通用属性
kotlin
val scoreboard: Scoreboard

服务器计分板实例。

difficulty

difficulty通用属性
kotlin
var difficulty: Difficulty

当前服务器难度设置。

execute

execute通用函数
kotlin
fun execute(command: String)

执行一条命令字符串。

参数

参数说明
command要执行的命令字符串。

executeCommand

executeCommand通用函数
kotlin
fun executeCommand(source: CommandSourceStack, command: String)

以指定的命令源执行命令。

参数

参数说明
source用作执行主体的命令源。
command要执行的命令字符串。

executeCommandAsServer

executeCommandAsServer通用函数
kotlin
fun executeCommandAsServer(command: String)

以服务器控制台身份执行命令。

参数

参数说明
command要执行的命令字符串。

findPlayer

findPlayer通用函数
kotlin
fun findPlayer(player: String): ServerPlayer?

根据名称查找玩家。

参数

参数说明
player要查找的玩家名称。

返回值

找到则返回 ServerPlayer,否则返回 null。

findPlayer

findPlayer通用函数
kotlin
fun findPlayer(uuid: UUID): ServerPlayer?

根据 UUID 查找玩家。

参数

参数说明
uuid要查找的玩家 UUID。

返回值

找到则返回 ServerPlayer,否则返回 null。

findEntities

findEntities通用函数
kotlin
fun findEntities(level: ServerLevel, selector: EntitySelector): List<Entity>

在指定维度中使用实体选择器查找实体。

参数

参数说明
level要搜索的 ServerLevel。
selector要使用的 EntitySelector。

返回值

返回匹配的实体列表。

findEntity

findEntity通用函数
kotlin
fun findEntity(uuid: UUID): Entity?

在所有维度中根据 UUID 查找实体。

参数

参数说明
uuid要查找的实体 UUID。

返回值

找到则返回 Entity,否则返回 null。

ban

ban通用函数
kotlin
fun ban(player: ServerPlayer)

将玩家加入服务器封禁列表并断开其连接。

参数

参数说明
player要封禁的 ServerPlayer。

banIp

banIp通用函数
kotlin
fun banIp(ip: String)

封禁一个 IP 地址,并断开所有匹配玩家的连接。

参数

参数说明
ip要封禁的 IP 地址字符串。

deop

deop通用函数
kotlin
fun deop(player: ServerPlayer)

取消玩家的管理员权限。

参数

参数说明
player要取消权限的 ServerPlayer。

op

op通用函数
kotlin
fun op(player: ServerPlayer)

授予玩家管理员权限。

参数

参数说明
player要授予权限的 ServerPlayer。

setDifficulty

setDifficulty通用函数
kotlin
fun setDifficulty(difficulty: Difficulty, ignoreLock: Boolean = true)

设置服务器难度。

参数

参数说明
difficulty新的 Difficulty。
ignoreLock是否忽略难度锁定。

runFunction

runFunction通用函数
kotlin
fun runFunction(id: Identifier, source: CommandSourceStack = requireServer().createCommandSourceStack())

使用可选的命令源执行函数(数据包函数)。

参数

参数说明
id函数标识符。
source要使用的命令源(默认使用服务器)。

setGameMode

setGameMode通用函数
kotlin
fun setGameMode(player: ServerPlayer, gameMode: GameType)

设置玩家的游戏模式。

参数

参数说明
player目标 ServerPlayer。
gameMode目标 GameType。

getGameMode

getGameMode通用函数
kotlin
fun getGameMode(player: ServerPlayer): GameType

获取玩家当前的 GameType。

参数

参数说明
player目标 ServerPlayer。

返回值

返回 GameType。

setGameRule

setGameRule通用函数
kotlin
fun <T : Any> setGameRule(key: GameRule<T>, value: T)

在服务器主世界中设置游戏规则值。

参数

参数说明
keyGameRule 键。
value要设置的值。

getGameRule

getGameRule通用函数
kotlin
fun <T : Any> getGameRule(key: GameRule<T>): T

从服务器主世界获取游戏规则值。

参数

参数说明
keyGameRule 键。

返回值

返回该游戏规则的值。

kick

kick通用函数
kotlin
fun kick(player: Player, reason: Component = Component.translatable("multiplayer.disconnect.kicked"))

踢出玩家,并可附带可选的原因组件。

参数

参数说明
player目标玩家(需要是 ServerPlayer 才能断开连接)。
reason断开连接原因组件。