skript-storage wiki

Presentation

skript-storage was made to handle the most used file-storage system and use them easily with Skript. In addition to YAML, you can also manage JSON and TOML files as you like, since all of them have multiple advantages and disadvantages.

File Types Storage

skript-storage allow three main file storage type:

All of them have different advantages and disadvantages which will allow using one or the other for this or that type of storage:

Name

Description

Usage

Example

YAML

YAML is rather poorly optimized when it comes to loading and changing values, but it is the best when it comes to data readability. It’s also the only type that supports “readable” comments.

More in user-editable data, like configuration files.

First:
   Second:
Hello World!
   Third:
       Fourth:
50
   Lastly:
30
SecondMain:
Welcome!

JSON

The change and recovery of data are very fast and optimized, although the visual layout of the data leaves something to be desired.

Data that will be changed regularly, such as player levels or information about the world.

{
  "First":
{
     "Second":
"Hello World!",
     "Third":
{"Fourth": 50},
     "Lastly":
30
 
},
  "SecondMain":
"Welcome!"
}

TOML

It's the perfect middle ground between JSON optimization and clear YAML reading.

Although the data layout is quite weird at first, you get used to it quickly and this type of storage can really be used everywhere.

SecondMain = "Welcome!"
[First]
Second = "Hello World!"
Lastly = 30
        
[First.Third]
        
Fourth = 50

Cross-version Data

skript-storage supports all of these three types, and the best part is that you don’t have to change anything in your code! Every node will be represented in the same way and every expression will be supported with these types.

Only headers comments will be available for YAML and not for JSON neither TOML.

skript-storage determine the file type with its extension (see the second part), and you cannot make a file with another extension (skript-storage will be unable to parse it)

Shortcut System

Are you too lazy to write every time the configuration’s file name of your skript? Well, shortcuts are made for you!

You can define using an effect shortcut (words) which will be replaced by the desired place. For example:

on load:
        
# Better to make it on an on-load event, since with it'll be registered for sure.
        create shortcut
for "plugins/Test/config.yaml" as "config"
        
# Every tiem you'll use 'config' in your node management,
        
# skript-storage will replace it by 'plugins/Test/config.yaml'

Node Management

Let’s start with the best part of skript-storage: how to manage data!

First of all, we’ll try to get back values from a YAML file, as it was a configuration file:

AllowMultipleSpawn: true

MaxMultipleSpawn:
50

Therefore, you can get the values from the following code:

set {_allowMultipleSpawn} to value "AllowMultipleSpawn" from "plugins/test/config.yml" parsed as boolean
set {_maxMultipleSpawn} to value "MaxMultipleSpawn" from "plugins/test/config.yml" parsed as number

You can now use both retrieved values whenever you want!

Let’s now try to set values from our file. You can set every sort of type, where skript-storage will convert it as String using Skript’s serializer. After that, when you get it back, as we did before, simply parse the value as the type you want. It also accepts both single and lists values. For example, to make the example code in the type’s table:

set value "First.Second" from "config" to "Hello World!"
set value "First.Third.Fourth" from "config" to 50
set value "First.Lastly" from "config" to 30
set value "SecondMain" from "config" to "Welcome!"

It also works with custom Skript’s type:

set value "Node.Path" from "config" to red # Color
set value "Node.Path" from "config" to now # Date
set value "Node.Path" from "config" to 20 minutes # Timespan

Lastly, you can get the back section of nodes from your file.

It will return the path of the node related to the optional node path you asked for.

For example, if you have this YAML file:

First:
   Second:
Hello World!
   Third:
       Fourth:
50
   Lastly:
30
SecondMain:
Welcome!

Expression

List Returned

section "" of "config"

  • First.Lastly
  • First.Third.Fourth
  • First.Second
  • SecondMain

section "" of "config" as one layer

  • First
  • SecondMain

section "First" of "config"

  • Second
  • Third.Fourth
  • Lastly

section "First" of "config" as one layer

  • Second
  • Third
  • Lastly