Skip to content

Server Data

Vinyarion edited this page Apr 26, 2020 · 4 revisions

Server data

This feature allows the server to store data on the disk and to have user-generated datastructures. They are written in JS and are actually executed on the server. They are sandboxed and don't have access to anything except the save data code.

Files

The scripts are in the data/[your pack namespace]/anduril/setup folder and its subfolders. To create a script, create a new file with only lowercase Latin letters, the digits 0-9, and the . or _ characters in the name and with a .js file extension.

There is a utility command, /anduril_reload which reloads all the server's resources.

Writing a script

There are several special global variables:

IScriptData

Calling server.persistant() returns an IScriptData object. You can store primitives (numbers and strings) with the getData and setData methods, lists with the newList, getList, and setList methods, and structures with the newObject, getObject, and setObject methods. Do not use this for storing player-specific data, you should use IScriptPlayer.data() for that, but you SHOULD store player's id (preferably UUID) in here for custom features.

IPermissionConfigure

Calling server.permissions() returns an IPermissionConfigure object. This has all the methods you need to set up simple permissions. These must be created in the setup and do not persist after the server shuts down.

Temporary and Custom Data Structures

Calling server.ephemeral() returns a JS object that you should use to store data structures that you intend for server-wide computation and can include functions.

Here is an example:

var data = server.ephemeral();
data.factions = {};
data.factions.ids = [];
data.factions.values = {};
var Faction = function(id, display) {
  this.id = id;
  this.display = display;
  data.factions.ids.push(id);
  data.factions.values[id] = this;
};
var redfac = new Faction("red", "Red Faction");
var greenfac = new Faction("green", "Green Faction");
var bluefac = new Faction("blue", "Blue Faction");
Clone this wiki locally