Docs » API reference » Storage

Storage

What a plugin keeps between runs: saved values for itself and for each player, and its own files. Also its requests to the internet.

Saved values are kept with the world, and a plugin sees only its own. Files live in the plugin's folder, plugins/<id>/, and need files. Internet requests need internet and go only to the hosts the manifest lists in internet_hosts. The answer arrives on a later tick.

You get one from server.storage().

Methods

MethodDescription
fn get(&self, key: &str) -> Result<Option<Value>>Optional<Value> get(String key)A value this plugin saved.
fn set(&self, key: &str, value: Value) -> Result<()>void set(String key, Value value)Saves a value.
fn remove(&self, key: &str) -> Result<()>void remove(String key)Forgets a value.
fn keys(&self) -> Result<Vec<String>>List<String> keys()Every key this plugin saved.
fn player_get(&self, player: PlayerId, key: &str) -> Result<Option<Value>>Optional<Value> playerGet(String player, String key)A value saved for a player, in the world or not.
fn player_set(&self, player: PlayerId, key: &str, value: Value) -> Result<()>void playerSet(String player, String key, Value value)Saves a value for a player.
fn read_file(&self, path: &str) -> Result<Option<Vec<u8>>>Optional<byte[]> readFile(String path) filesReads a file in the plugin's folder.
fn write_file(&self, path: &str, data: Vec<u8>) -> Result<()>void writeFile(String path, byte[] data) filesWrites a file in the plugin's folder.
fn list_files(&self, folder: &str) -> Result<Vec<String>>List<String> listFiles(String folder) filesFiles in a folder of the plugin's folder.
fn http(&self, request: HttpRequest, then: impl FnMut(HttpResponse) + 'static) -> Result<()>void http(HttpRequest request, Consumer<HttpResponse> then) internetSends an HTTP request; then is called with the answer on a later tick.

HttpRequest

An HTTP request.

Plain data, copied between the server and the plugin.

FieldDescription
method: StringString method()GET, POST, PUT or DELETE.
url: StringString url()An https address on a host the manifest lists.
headers: Vec<String>List<String> headers()Headers, each Name: value.
body: Vec<u8>byte[] body()The body (empty for none).

HttpResponse

An HTTP answer.

Plain data, copied between the server and the plugin.

FieldDescription
status: i64long status()The status code, or 0 if the request failed.
headers: Vec<String>List<String> headers()Headers, each Name: value.
body: Vec<u8>byte[] body()The body.