Skip to content
This repository has been archived by the owner on May 3, 2018. It is now read-only.

Dragonet JavaScript Plugin Scripting

The Evil Man edited this page Jun 25, 2015 · 1 revision

Dragonet JavaScript Plugin Scripting

A DragonetAPI Script ("DAPIS") is a JavaScript that can directly interact with the Dragonet server. Hopefully, after some heavy development, this could be similar to ModPE Scripts for MC:PE, and they could be used interchangeably. Additionally, each plugin is treated like a normal Bukkit plugin which means you can use any of the Bukkit APIs with ease.

Example:

var Server = new ServerAPI(); //'Imports' the ServerAPI
var me; //Create variable to store Bukkit instance in
function onLoad(script){
    me = script; //Do the saving. This isn't completely necessary for this script, but it's good to get in the habit.
}
function Tick()
{
    Server.clientMessage("Server Tick!"); //Broadcasts "Server Tick!" to the server
}

Save that code as a file with a .js extension and plop it in your plugins folder, and the next time you launch Dragonet, "Server Tick!" will be printed every tick (0.05 of a second) to the server.

Functions:

  • Tick() - Called every server tick (twentieth of a second)
  • useItem(blockX, blockY, blockZ, blockFace, blockName, playerName) - Called whenever an item is used.
  • destroyBlock - Called whenever a block is destroyed (In Development)
  • onConnect(playerName) - Called whenever a client connects to the server
  • onQuit(playerName) - Called whenever a client leaves the server (and was not kicked)
  • onKick(playerName, kickReason) - Called whenever a player is kicked
  • onCommand(sender, cmdLabel, alias, args) - Port of Bukkit's hook by the same name. Please note that 'args' is a string array.
  • onLoad(Script currentScript), onEnable(), onDisable() - The same methods as Bukkit's, except for one thing: 'onLoad''s parameters include the Bukkit representation of the current script, which is useful for registering commands and the like. It's recommended you save this for later.
    Note: The example of command registration has been moved to the ScriptAPI page, where a more detailed explanation is present.

Importable Classes:

  • PlayerAPI - Edit the attributes of players.
  • WorldAPI - Edit, delete or create new worlds
  • ServerAPI - Maintain the server, ban players, run commands and modify chat.
  • ConfigAPI (In development) - Create, read, edit, and delete configuration files.
  • PermissionsAPI (In development) - Manages permissions for the server
  • ScriptAPI - Customize the DragonetAPI by adding new functions, methods and commands.

Methods:

PlayerAPI

  • kill(player) - Kills the provided player
  • addItemInventory(player, materialName, Count) - Adds the specified material to the provided player's inventory
  • clearInventory(player) - Clears the player's inventory
  • getCurrentWorld(player) - Gets the player's current world's name
  • setHealth(player, health) - Sets the player player's health to the double health
  • getHealth(player) - Returns the player player's health in a double
  • getX(player) - Returns the player player's X coord
  • getY(player) - Returns the player player's Y coord
  • getZ(player) - Returns the player player's Z coord

WorldAPI

  • setArea(worldName, x1, y1, z1, x2, y2, z2, materialName, tileData) - Sets the area inside the coords provided in the world worldName to materialName with the data of tileData
  • setBlock(worldName, x, y, z, materialName, tileData) - Sets the block at the specified coords in the world worldName to materialName with the data of tileData
  • dropItem(worldName, x, y, z, materialName, Count) - Drops an item of the type materialName at the specified coords
  • getBlockAt(worldName, x, y, z) - Returns the block at the specified coords

ServerAPI

  • banPlayer(player, reason) - Bans the player player for the reason reason
  • clientMessage(message) - Broadcasts the message message to the server
  • disconnectPlayer(player, message) - Kicks the player player with the reason message
  • getName() - Returns the server's name (in the server.properties file)
  • runConsoleCommand(command) - Runs the specified command command (the '/' cannot be used before the command)
  • stop(msg) - Kicks everyone on the server with the reason msg and stops the server
  • getServer() - Returns the server
  • getPlugins() - Returns an array containing all of the enabled plugins (not scripts)
  • logMessage(message, type)- Logs the message message to the server's console. Can be a debug, error, trace, warn or info message.

ConfigAPI

  • create(config) - Creates a new directory in the 'plugins' folder with the name config and creates a .yml file with the same name
  • exists(config) - Returns true or false depending on if the specified config file config (don't use the .yml extension) exists
  • readEntry(config, entry) - Returns the value of the entry entry in the config file config or, if the entry does not exist, "EMPTY_NODE"

ScriptAPI

The ScriptAPI's documentation is located here.