-
Notifications
You must be signed in to change notification settings - Fork 0
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.
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.
There are several special global variables:
-
util
The utility object. (see IScriptUtil) -
server
The server wrapper object. (see IScriptServer)
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.
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.
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");