flying-squid/doc/api.md
2015-10-09 17:30:10 -07:00

8.4 KiB

Table of Contents generated with DocToc

API

Classes

Entity

See prismarine-entity

MCServer

Flying-squid.createMCServer(options)

Create and return an instance of the class MCServer.

options is an object containing the settings

Properties

serv.entityMaxId

Current maximum entity id

serv.players

Array of connected players

serv.uuidToPlayer

Object uuid to players

serv.world

The map

serv.entities

All of the entities

serv.bannedPlayers

Object of players that are banned, key is their uuid. Use serv.getUUIDFromUsername() if you only have their username.

Example player:

{
    time: <time in epoch>,
    reason: <reason given>
}

serv.time

Current daylight cycle time in ticks. Morning is 0, noon is 6000, evening is 12000, and night is 18000. Resets to 0 at 24000. Use serv.setTime(time) to set the time.

serv.tickCount

Total number of ticks that have passed since the start of the world. Best to use with modulo (e.g. Something every 10 seconds is serv.tickCount % 20*10 == 0)

serv.doDaylightCycle

Default true. If false, time will not automatically pass.

Events

"error" (error)

Fires when there is an error.

"listening" (port)

Fires when the server is listening.

"newPlayer" (player)

Fires when player login, allow external player plugins.

"banned" (banner,bannedUsername,reason)

banner banned bannedUsername with reason

"tick" (count)

Fires when one tick has passed (default is 50ms). count is the total world ticks (same as serv.tickCount)

Methods

serv.createLog()

creates the log file

serv.log(message)

logs a message

serv.broadcast(message[,color])

broadcasts message to all the players with the optional color.

serv.setBlock(position,blockType)

Saves block in world and sends block update to all players.

serv.getPlayer(username)

Returns player object with that username or, if no such player is on the server, null.

server.banUsername(username,reason,callback)

Bans players given a username. Mainly used if player is not online, otherwise use player.ban().

server.ban(uuid,reason)

Ban player given a uuid. If the player is online, using player.ban(). Bans with reason or You are banned!.

server.pardonUsername(username,callback)

Pardons a player given a username.

server.pardon(uuid)

Pardons a player given their uuid. Returns false if they are not banned.

server.getUUIDFromUsername(username,callback)

Gets UUID from username. Since it needs to fetch from mojang servers, it is not immediate.

Arguments in format: callback(uuid). uuid is null if no such username exists.

server.setTime(time)

Set daylight cycle time in ticks. See serv.time for more info.

server.setTickInterval(ticksPerSecond)

Resets tick interval to occur ticksPerSecond times per second.

Use server.stopTickInterval() if you want but this method already calls that and you can use serv.doDaylightCycle to stop it anyway.

Player

Properties

player.entity

The entity of the player, of type Flying-squid.Entity

player.username

The username of the player

player.view

The view size of the player, for example 8 for 16x16

Events

"connected"

Fires when the player is connected

"spawned"

Fires when the player is spawned

"disconnected"

Fires when the player disconnected

"error" (error)

Fires when there is an error.

"chat" (message)

Fires when the player says message.

"kicked" (kicker,reason)

kicker kick the player with reason

"positionChanged"

fires when the position changed

Methods

player.login()

login

player.ban(reason)

bans player with reason

player.kick(reason)

kicks player with reason

player.getOthers()

return the other players than player

player.chat(message)

sends message to the player

player.changeBlock(position,blockType)

change the block at position position to blockType

this will not change the block for the user themself. It is mainly useful when a user places a block and only needs to send it to other players on the server

player.sendBlock(position,blockType)

change the block at position position to blockType

this will not make any changes on the server's world and only sends it to the user as a "fake" or "local" block

player.sendInitialPosition()

send its initial position to the player

player.spawn()

tell everybody else that the player spawned

player.setGameMode(gameMode)

set player gameMode to gameMode

player.handleCommand(command)

handle command

player.updateHealth(health)

update the player health.

Low level properties

player._client

The internal implementation to communicate with a client

Low level methods

player._writeOthers(packetName, packetFields)

write to other players than player the packet packetName with fields packetFields