PluginStorage
Files for your plugin on the player's computer, in a folder only your plugin can open: the folder named after your plugin's slug in ~/.rlplugins/plugin-data.
Final classRLPlugins API
public final class PluginStorageLocal plugins in the developer client use ~/.rlplugins/dev-plugin-data instead, so testing never touches the published copy's files.
A name is a path inside the folder such as "settings.json" or "trips/today.txt": letters, digits, ., _ and -, with / between folders, at most 8 deep. A name cannot start with a dot. One file holds at most 16 MiB; the folder holds at most 256 MiB in 4096 files. Every write replaces the whole file at once, so a crash never leaves half a file.
JSON uses Gson. It stores your own classes, strings, numbers, booleans, enums, arrays, lists, maps, Gson's JsonObject and JsonArray, and WorldPoint, WorldArea and LocalPoint. Fields of other client or game objects are left out. Reading and writing touch the disk on the calling thread: save when something changes or in shutDown(), not every tick.
Members
Methods
- booleandelete(String)
Deletes the file and any folders it leaves empty.
- booleanexists(String)
True when the file exists.
- TfromJson(String, Class<T>)
JSON text as this type.
- List<T>fromJsonList(String, Class<T>)
A JSON array as a list of this type.
- Map<String, T>fromJsonMap(String, Class<T>)
A JSON object as a map from names to this type.
- List<String>list()
Every file in the folder, as names you can pass to the other methods, sorted.
- PluginStorageof(Plugin)
The storage folder of your plugin.
- byte[]readBytes(String)
The file's bytes, or null when it does not exist.
- TreadJson(String, Class<T>)
The file's JSON as this type, or null when the file does not exist.
- List<T>readJsonList(String, Class<T>)
The file's JSON array as a list of this type, or null when the file does not exist.
- Map<String, T>readJsonMap(String, Class<T>)
The file's JSON object as a map from names to this type, or null when the file does not exist.
- StringreadText(String)
The file as UTF-8 text, or null when it does not exist.
- StringtoJson(Object)
This value as JSON text.
- voidwriteBytes(String, byte[])
Replaces the file with these bytes, creating its folders.
- voidwriteJson(String, Object)
Replaces the file with this value as JSON.
- voidwriteText(String, String)
Replaces the file with this text in UTF-8, creating its folders.
delete(String)
public boolean delete(String name)Deletes the file and any folders it leaves empty.
Returns false when it did not exist.
Parameters
name- Name.
exists(String)
public boolean exists(String name)True when the file exists.
Parameters
name- Name.
fromJson(String, Class<T>)
public T fromJson(String json, Class<T> type)JSON text as this type.
Throws PluginStorageException when the text is not valid JSON for it.
Parameters
json- Json.
type- Type.
fromJsonList(String, Class<T>)
public List<T> fromJsonList(String json, Class<T> elementType)A JSON array as a list of this type.
Parameters
json- Json.
elementType- Element type.
fromJsonMap(String, Class<T>)
public Map<String, T> fromJsonMap(String json, Class<T> valueType)A JSON object as a map from names to this type.
Parameters
json- Json.
valueType- Value type.
list()
public List<String> list()Every file in the folder, as names you can pass to the other methods, sorted.
of(Plugin)static
public static PluginStorage of(Plugin plugin)The storage folder of your plugin.
Pass the plugin itself: PluginStorage.of(this). A plugin can only open its own folder.
Parameters
plugin- Plugin.
readBytes(String)
public byte[] readBytes(String name)The file's bytes, or null when it does not exist.
Parameters
name- Name.
readJson(String, Class<T>)
public T readJson(String name, Class<T> type)The file's JSON as this type, or null when the file does not exist.
Arrays work: Loadout[].class.
Parameters
name- Name.
type- Type.
readJsonList(String, Class<T>)
public List<T> readJsonList(String name, Class<T> elementType)The file's JSON array as a list of this type, or null when the file does not exist.
Parameters
name- Name.
elementType- Element type.
readJsonMap(String, Class<T>)
public Map<String, T> readJsonMap(String name, Class<T> valueType)The file's JSON object as a map from names to this type, or null when the file does not exist.
Parameters
name- Name.
valueType- Value type.
readText(String)
public String readText(String name)The file as UTF-8 text, or null when it does not exist.
Parameters
name- Name.
toJson(Object)
public String toJson(Object value)This value as JSON text.
Parameters
value- Value.
writeBytes(String, byte[])
public void writeBytes(String name, byte[] data)Replaces the file with these bytes, creating its folders.
Parameters
name- Name.
data- Data.
writeJson(String, Object)
public void writeJson(String name, Object value)Replaces the file with this value as JSON.
Parameters
name- Name.
value- Value.
writeText(String, String)
public void writeText(String name, String text)Replaces the file with this text in UTF-8, creating its folders.
Parameters
name- Name.
text- Text.
Also allowed
Every class has these, as in plain Java.
equals, toString