The proper way to do yaml in skript
Rather then checking the file each time this addon caches the yaml file to memory
Effects
Expressions
Conditions
Loads a yaml file into memory
[non[(-| )]relative]
allows for root directory access[re]load [(1¦non[(-| )]relative)] [y[a]ml] %strings%
[re]load [(1¦non[(-| )]relative)] [y[a]ml] %string% as %string%
[re]load [(1¦non[(-| )]relative)] [y[a]ml] %strings% using [the] [file] path[s] as [the] id[s]
#Root directory
#If the server is on drive D:\(on windows) for example then that would be the root path
load non-relative yaml "RootFolder/MyAwesomePlugin/config.yml"
#Otherwise you can specify a drive
load non-relative yaml "C:/RootFolder/MyAwesomePlugin/config.yml"
#Both examples produce the same id for use in other effects/expressions
load yaml "plugins/MyAwesomePlugin/config.yml"
load yaml "plugins/MyAwesomePlugin/config.yml" as "config"
#to get similar function as the other addons you would do this sort of thing with the id...
load yaml "plugins/MyAwesomePlugin/config.yml" as "plugins/MyAwesomePlugin/config.yml"
set yaml value "version" from "plugins/MyAwesomePlugin/config.yml" to 1.0
broadcast "%yaml value "version" from "plugins/MyAwesomePlugin/config.yml"%"
Loads a directory YAML files into memory.
test.yml
"[re]load all [y[a]ml] from [(1¦non[(-| )]relative)] director(y|ies) %strings% [using [the] filename as [the] id]
#This isn't something you would really want to do, or is it?
load all yaml from directory "plugins/skript-yaml/test"
loop all of the currently loaded yaml files:
loop yaml nodes "" from loop-value-1:
loop yaml nodes loop-value-2 from loop-value-1:
broadcast yaml value "%loop-value-2%.%loop-value-3%" from loop-value-1
Unloads a yaml file from memory and deletes the file
delete [y[a]ml] %string%
Unloads a directory of yaml files from memory and deletes them
delete (all|any) [y[a]ml] from [(1¦non[(-| )]relative)] director(y|ies) %strings%
delete (all|any) loaded [y[a]ml] from [(1¦non[(-| )]relative)] director(y|ies) %strings% [using [the] filename as [the] id]
Unloads one or more yaml files from memory
[(1¦director(y|ies))]
option the input string must be a directory instead of an idunload [y[a]ml] [(1¦director(y|ies))] %strings%
unload yaml "config"
Saves the current cached yaml elements to file
[with an indentation of %-number%]
option allows you to save the file with a different amount of spacing between 1 and 10
save [y[a]ml] %strings% [with an indentation of %-number%] [(1¦[and] with(out| no) extra lines between nodes)]
save yaml "config"
save yaml "config" with an indentation of 2
Returns a list of all 'cached' yaml file ids
from (director(y|ies) %-strings%
option gets ids from only said directories[(the|all [(of the|the)])] [currently] loaded y[a]ml [files] [from (director(y|ies) %-strings%|all directories)]
set {_list::*} to the currently loaded yaml files
broadcast "%{_list::*}%"
loop the loaded yaml
broadcast loop-value
loop the loaded yaml from directory "plugins\skript-yaml"
broadcast loop-value
Returns a list of directories from all 'cached' yaml file ids
[(the|all [(of the|the)])] [currently] loaded y[a]ml directories
loop the loaded yaml directories
broadcast loop-value
Gets, sets, removes values/node keys etc.. of a cached yaml file
[[skript-]y[a]ml] (1¦value|2¦(node|path) list|3¦(node|path)[s with] keys|4¦list) %string% (of|in|from) %string% [without string checks]
set yaml value "test1.test2" from "config" to "test3"
set yaml list "list.name" from "config" to {_list::*}
set {_test} to yaml value "test1.test2" from "config"
broadcast "%{_test}%"
on script load:
load yaml "plugins/skript-yaml/teleport.yml" as "plugins/skript-yaml/teleport.yml"
command /savetp:
trigger:
set yaml value "%player%.location" from "plugins/skript-yaml/teleport.yml" to location of player
save yaml "plugins/skript-yaml/teleport.yml"
command /tp:
trigger:
teleport player to yaml value "%player%.location" from "plugins/skript-yaml/teleport.yml"
Gets a list of all nodes of a cached yaml file
[all] [[skript-]y[a]ml] (node|path)[s] (of|in|from) %string%
set yaml value "test1.test2" from "config" to "test3"
set yaml value "boop.beep" from "config" to "bop"
set {_list::*} to all yaml nodes of "config"
broadcast "%{_list::*}%"
Gets, sets, deletes comments or the header of a cached yaml file
[the] comment[s] (of|from) [y[a]ml] node[s] %strings% (of|in|from) %string%" [(1¦with [an] extra line)]
[the] (comment[s] (at|on) [the] top of |header (of|from)) %string% [(1¦with [an] extra line)]
set the comments of yaml node "test" from "config" to "First line" and "Second line"
delete the comments of yaml node "test" from "config"
set {_header::*} to "First line" and "Second line"
set the comments at the top of "config" to {_header::*}
delete the comments at the top of "config"
set the header of "config" to "First line" and "Second line"
delete the header of "config"
set the header of "config" to {_header::*}
Loop expressions to use while looping a yaml expression
loop-id
gets the id used in the yaml expressionloop-val
gets a value at that node if one existsloop-list
gets a list at that node if one existsloop-node
gets the full path plus keyloop-key
gets just the keysloop-subnodekeys
gets any subnode from the current node (does not work on lists)[the] loop-(1¦id|2¦val|3¦list|4¦node|5¦key|6¦subnodekey[s]|7¦iteration)
Yaml file:
settings:
subnode1: value1
subnode2: value2
node2:
subnode1: value1
subnode2: value2
node3:
- listValue1
- listValue2
Skript file:
loop yaml node keys "node" from "config":
broadcast yaml value loop-node from loop-id
Checks if one or more yaml files are loaded into memory using said id
y[a]ml[s] %strings% (is|are) loaded
y[a]ml[s] %strings% ((are|is) not|(is|are)n[']t) loaded
Only checks if there are any nodes or not
[skript-]y[a]ml %string% is[(n't| not)] empty
Checks if one or more values exist at a path in a cached YAML file using said ID.
[skript-]y[a]ml [(node|path)[s]] %strings% (of|in|from) %string% has [a] value[s]
[skript-]y[a]ml [(node|path)[s]] %strings% (of|in|from) %string% does(n't| not) have [a] value[s]
set skript-yaml value "test.test" from "config" to "test"
yaml path \"test.test\" in \"config\" has value:
broadcast "has value"
Checks if one or more paths exist in a cached yaml file using said id
[skript-]y[a]ml [(node|path)[s]] %strings% (of|in|from) %string% exists
[skript-]y[a]ml [(node|path)[s]] %strings% (of|in|from) %string% does(n't| not) exist
set skript-yaml value "test.test" from "config" to "test"
set skript-yaml value "test2.test2" from "config" to "test"
yaml path "test.test" and "test2.test2" in "config" exists:
broadcast "this works"
yaml path "test.test" and "boop.boop" in "config" exists:
broadcast "this will fail"
Checks if one or more paths contain a list in a cached yaml file using said id
[skript-]y[a]ml [(node|path)[s]] %string% (of|in|from) %string% has [a] list
[skript-]y[a]ml [(node|path)[s]] %string% (of|in|from) %string% does(n't| not) have [a] list
if yaml node "listnode" from "example" has list:
loop yaml list "listnode" from "example":
broadcast "%loop-val%"
Checks if a yaml file exists
[(1¦non[(-| )]relative)] y[a]ml file %string% exists
[(1¦non[(-| )]relative)] y[a]ml file %string% does(n't| not) exist
createYMLFile("plugins/MyAwesomePlugin/boop.yml", "list: listName:50;3.14;true;false;yes;no;on;off||value: valueName1:true||value: valueName2:2||value: valueName3:2.6||value: valueName4:This is a string")
I'd like to thank the whole Skript community, without users like you I wouldn't have bothered to make this!
A special shout out goes to @Pikachu920 for helping me with the syntax and some ideas <3