Skip to content
On this page
Common

KattonPlayerApi

common/src/main/kotlin/top/katton/api/dpcaller/KattonPlayerApi.kt
List-like access to all online players.

KattonPlayerList ​

KattonPlayerListCommonClass
kotlin
class KattonPlayerList( val playerList: PlayerList ) : List<ServerPlayer> by playerList.players

List-like access to all online players.

Properties ​

PropertyDescription
playerListThe underlying PlayerList

KattonPlayerList.get ​

KattonPlayerList.getCommonFunction
kotlin
operator fun get(name: String): ServerPlayer?

Find a player by name.

KattonPlayerList.get ​

KattonPlayerList.getCommonFunction
kotlin
operator fun get(uuid: UUID): ServerPlayer?

Find a player by UUID.

KattonLevelPlayerCollection ​

KattonLevelPlayerCollectionCommonClass
kotlin
class KattonLevelPlayerCollection( val level: ServerLevel ) : List<ServerPlayer> by level.players

Collection of players within a specific level.

Properties ​

PropertyDescription
levelThe ServerLevel containing the players

KattonLevelPlayerCollection.get ​

KattonLevelPlayerCollection.getCommonFunction
kotlin
operator fun get(uuid: UUID): Player?

Find a player by UUID in this level.

addItem ​

addItemCommonFunction
kotlin
fun Player.addItem(item: Item, amount: Int)

Add an item to a player's inventory.

Parameters ​

ParameterDescription
playerthe Player to receive the item
itemthe Item type to add
amountthe quantity to add

clearInventory ​

clearInventoryCommonFunction
kotlin
fun clearInventory(player: Player)

Clear a player's inventory.

Parameters ​

ParameterDescription
playerthe Player whose inventory will be cleared

setItem ​

setItemCommonFunction
kotlin
fun setItem(player: Player, slot: Int, itemStack: ItemStack)

Set an item into a player's inventory slot.

Parameters ​

ParameterDescription
playerthe Player to modify
slotinventory slot index
itemStackitem stack to set

getItem ​

getItemCommonFunction
kotlin
fun getItem(player: Player, slot: Int): ItemStack

Get the item from a player's inventory slot.

Parameters ​

ParameterDescription
playerthe Player to query
slotinventory slot index

Returns ​

in the slot

giveItem ​

giveItemCommonFunction
kotlin
fun giveItem(player: Player, itemStack: ItemStack): Boolean

Try to give an item stack to a player.

Parameters ​

ParameterDescription
playerthe Player to receive the item
itemStackthe ItemStack to give

Returns ​

if added to inventory, false if full

hasItem ​

hasItemCommonFunction
kotlin
fun hasItem(player: Player, item: Item): Boolean

Check if a player has a specific item type in their inventory.

Parameters ​

ParameterDescription
playerthe Player to check
itemthe Item type to search for

Returns ​

true if the player has the item, false otherwise

findItem ​

findItemCommonFunction
kotlin
fun findItem(player: Player, item: Item): Int

Find the slot index of an item in player's inventory.

Parameters ​

ParameterDescription
playerthe Player to search
itemitem type to find

Returns ​

index or -1 if not found

removeItem ​

removeItemCommonFunction
kotlin
fun removeItem(player: Player, item: Item, count: Int): Boolean

Remove a count of items from player's inventory.

Parameters ​

ParameterDescription
playerthe Player to modify
itemitem type to remove
countamount to remove

Returns ​

true if removal succeeded, false otherwise

enchant ​

enchantCommonFunction
kotlin
fun enchant(itemStack: ItemStack, enchantment: Holder<Enchantment>, level: Int)

Enchant an ItemStack with an enchantment.

Parameters ​

ParameterDescription
itemStacktarget ItemStack
enchantmentenchantment holder to apply
levelenchantment level

enchantMainHand ​

enchantMainHandCommonFunction
kotlin
fun enchantMainHand(entity: LivingEntity, enchantment: Holder<Enchantment>, level: Int)

Enchant the item in an entity's main hand if present.

Parameters ​

ParameterDescription
entitytarget LivingEntity
enchantmentenchantment holder to apply
levelenchantment level

addXpPoints ​

addXpPointsCommonFunction
kotlin
fun addXpPoints(player: Player, points: Int)

Give experience points to a player.

Parameters ​

ParameterDescription
playertarget Player
pointsexperience points to add

addXpLevels ​

addXpLevelsCommonFunction
kotlin
fun addXpLevels(player: Player, levels: Int)

Give experience levels to a player.

Parameters ​

ParameterDescription
playertarget Player
levelslevels to add

setXpLevel ​

setXpLevelCommonFunction
kotlin
fun setXpLevel(player: Player, level: Int)

Set a player's experience level.

Parameters ​

ParameterDescription
playertarget Player
levellevel value to set

getXpLevel ​

getXpLevelCommonFunction
kotlin
fun getXpLevel(player: Player): Int

Get a player's experience level.

Parameters ​

ParameterDescription
playertarget Player

Returns ​

experience level

getXpProgress ​

getXpProgressCommonFunction
kotlin
fun getXpProgress(player: Player): Float

Get a player's experience progress (fraction).

Parameters ​

ParameterDescription
playertarget Player

Returns ​

progress as float (0..1)

spawnPoint ​

spawnPointCommonFunction
kotlin
fun spawnPoint(player: MutableCollection<ServerPlayer>, level: ServerLevel, pos: BlockPos, rot: Vec2)

Set spawn point for a collection of players.

Parameters ​

ParameterDescription
playercollection of ServerPlayer to set
levelserver level providing the dimension
posrespawn position
rotrotation vector (pitch,x / yaw,y)

setWorldSpawn ​

setWorldSpawnCommonFunction
kotlin
fun setWorldSpawn(level: ServerLevel, blockPos: BlockPos, rot: Vec2)

Set the world spawn and respawn orientation for a level.

Parameters ​

ParameterDescription
levelserver level
blockPosspawn position
rotrotation vector (pitch,x / yaw,y)

spectate ​

spectateCommonFunction
kotlin
fun spectate(player: ServerPlayer, target: Entity?): Boolean

Make a player spectate a target entity.

Parameters ​

ParameterDescription
playerspectator ServerPlayer
targetentity to spectate, or null to stop

Returns ​

true if spectating succeeded, false otherwise