Reading, Writing and Deleting YAML

Original tutorial from Wrong's post, made by kspade.

This tutorial has been updated, and requires skUtilites. You can download it here.

Syntax:
y[a]ml (value|nodes|nodes with keys|list) %string% (from|of) file %string%

Reading
[skutil[ities] ]y[a]ml value %string% (from|of) file %string%
[skutil[ities] ]y[a]ml nodes %string% (from|of) file %-string%
[skutil[ities] ]y[a]ml node[s with] keys %string% (from|of) file %-string%
[skutil[ities] ]y[a]ml list %string% (from|of) file %-string%


Writing
set [skutil[ities] ]y[a]ml value %string% (from|of) file %string% to %object%
add %object% to [skutil[ities] ]y[a]ml nodes %string% (from|of) file %string%
add %object% to [skutil[ities] ]y[a]ml node[s with] keys %string% (from|of) file %string%
add %object% to [skutil[ities] ]y[a]ml list %string% (from|of) file %string%


Deleting
delete [skutil[ities] ]y[a]ml value %string% (from|of) file %string%
delete [skutil[ities] ]y[a]ml nodes %string% (from|of) file %string%
delete [skutil[ities] ]y[a]ml node[s with] keys %string% (from|of) file %string%
delete [skutil[ities] ]y[a]ml list %string% (from|of) file %string%


Removing
remove %object% from [skutil[ities] ]y[a]ml nodes %string% (from|of) file %string%
remove %object% from [skutil[ities] ]y[a]ml node[s with] keys %string% (from|of) file %string%
remove %object% from [skutil[ities] ]y[a]ml list %string% (from|of) file %string%


Other
[skutil[ities] ]y[a]ml[ path] %string% in file %-string% does(n't| not) exist


Example:
Here's an example PvP kit script. You can use this script to help you.


This is the script file. Put this in your /plugins/Skript/scripts folder.
options:
prefix: &4PvP&cKitz &8|
file: yamlkits.yml

command /kit [<text>]:
permission: yaml.kit
trigger:
if arg 1 is "new" or "add":
if arg 2 is not set:
send "{@prefix} &cMissing name! /kit new <name>"
else:
# Setting a value
set skutil yaml value "kits.%arg 2%.enabled" from file "{@file}" to true
loop all items in player's inventory:
loop-item is not air
add "%number of loop-item in player's inventory% %loop-item's type%" to {_tempkit::*}
loop {_tempkit::*}:
# Setting a list
add loop-value to skutil yaml list "kits.%arg 2%.items" from file "{@file}"
send "{@prefix} &2Kit has been created."
else if arg 1 is "enable" or "disable":
set {_exists} to skutil yaml value "kits.%arg 2%.enabled" from file "{@file}"
if {_exists} is set:
if arg-1 is "enable":
# Setting a value
set skutil yaml value "kits.%arg 2%.enabled" from file "{@file}" to true
send "{@prefix} &2Enabled kit %arg 2%"
else:
# Setting a value
set skutil yaml value "kits.%arg 2%.enabled" from file "{@file}" to false
send "{@prefix} &4Disabled kit %arg 2%"
else:
send "{@prefix} &cThis kit was not found"
else if arg 1 is "display" or "all":
if arg 2 is "-detail":
# Reading nodes with keys
set {_nodes::*} to skutil yaml nodes with keys "kits" from file "{@file}"
loop {_nodes::*}:
# Reading a value
set {_expand::%loop-value%} to skutil yaml value "kits.%loop-value%" from file "{@file}"
loop {_expand::*}:
send "%loop-index%: %loop-value%"
else:
# Reading nodes
set {_nodes::*} to skutil yaml nodes "kits" from file "{@file}"
loop {_nodes::*}:
#reading value
skutil yaml value "kits.%loop-value%.enabled" from file "{@file}" is not true
delete {_nodes::%loop-index%}
send {_nodes::*}
else:
# Reading a value
set {_enabled} to skutil yaml value "kits.%arg 1%.enabled" from file "{@file}"
if {_enabled} is true:
# Reading a list
set {_kits::*} to skutil yaml list "kits.%arg 1%.items" from file "{@file}"
loop {_kits::*}:
set {_kits::%loop-index%} to loop-value parsed as material
give player {_kits::*}
else if {_enabled} is false:
send "{@prefix} &xThis kit is disabled."
else:
send "{@prefix} &cThis kit doesn't exist!%nl%{@prefix} &7Use &f/kit display -detail&7."



This is the yaml file. You can put this anywhere you want in your server, as long as you change the file path in the script options.
kits:
redstone:
enabled: true
items:
- 64 redstone
- 64 redstone torch on
- 64 redstone repeaters
- 64 redstone comparators
- 64 redstone blocks
- 64 sticky pistons
- 64 pistons
- 64 stone button
- 64 lever
pet:
enabled: true
items:
- a wolf spawn egg
- 10 bones
- 1 name tag
custom-1:
enabled: false
items:
- a diamond pickaxe
- a diamond sword
- a bow
- 64 arrows