skUtilities Reading, Writing and Deleting YAML

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

TonyMaster21

Supporter ++
Supporter +
Supporter
Addon Developer
Nov 28, 2016
50
15
8
New Jersey
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
code_language.skript:
[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
code_language.skript:
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
code_language.skript:
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
code_language.skript:
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
code_language.skript:
[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.
code_language.skript:
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.
YAML:
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
 
You forgot the condition for check if a yml value exists there. The condition is:
code_language.skript:
[skutil[ities] ]y[a]ml[ path] %string% in file %-string% does(n't| not) exist
 
  • Like
Reactions: TonyMaster21
You forgot the condition for check if a yml value exists there. The condition is:
code_language.skript:
[skutil[ities] ]y[a]ml[ path] %string% in file %-string% does(n't| not) exist

Added.
 
Can use the remove yaml list specified number of rows?
 
You delete them by the value, example:
code_language.skript:
remove "test 3" from yml list "Some list" of file "path/Test.yml"
If yml list value is UniCode?
Can do this?
Ex:delete yml list value line
 
If yml list value is UniCode?
Can do this?
Ex:delete yml list value line
Other time, what do you mean? Be more specific.

Also, if you don't know the value of some item on the list you can do:

code_language.skript:
set {_list::*} to yml list "some list" of file "some path"
remove {_list::3} from yml list "some list" of file "some path"
 
Other time, what do you mean? Be more specific.

Also, if you don't know the value of some item on the list you can do:

code_language.skript:
set {_list::*} to yml list "some list" of file "some path"
remove {_list::3} from yml list "some list" of file "some path"
Okay I'll try
Very sorry
I'm from Taiwan
English is not very good
Think you
 
Im trying to delete the node "Text" with "other1" and "other2" but it doesn't work..
its:
Sosss:
Text:
Other1: true
Other2: false
 
delete yaml nodes "Sosss.Text" from file "test.yml"
the yml is:
code_language.skript:
Sosss:
  Text:
    Other1: true
    Other2: false
 
Try adding skutil:

code_language.skript:
delete skutil yaml nodes "Sosss.Text" from file "test.yml"
 
Hi, I need help!

code:
code_language.skript:
on load:
    file "plugins\SuperBans\config.yml" doesn't exist:
        create file "plugins\SuperBans\config.yml"
    skutil yaml path "messages.ban_screen_message" in file "plugins\SuperBans\config.yml" doesn't exist:
        set skutil yaml value "messages.ban_screen_message" from file "plugins\SuperBans\config.yml" to ""
        add "&7Sadly, you were &cBanned &7from &6ServerName&7. Apply on our forums if you want to dispute your ban!" to skutil yaml list "messages.ban_screen_message" from file "plugins\SuperBans\config.yml"
        add "" to skutil yaml list "messages.ban_screen_message" from file "plugins\SuperBans\config.yml"
        add "" to skutil yaml list "messages.ban_screen_message" from file "plugins\SuperBans\config.yml"
        add "&7Banned by: &a%{sban.bannedby.%{_p}%}%" to skutil yaml list "messages.ban_screen_message" from file "plugins\SuperBans\config.yml"
        add "" to skutil yaml list "messages.ban_screen_message" from file "plugins\SuperBans\config.yml"
        add "" to skutil yaml list "messages.ban_screen_message" from file "plugins\SuperBans\config.yml"
        add "&7Banned on: &c%{sban.bannedon.%{_p}%}%" to skutil yaml list "messages.ban_screen_message" from file "plugins\SuperBans\config.yml"
        add "" to skutil yaml list "messages.ban_screen_message" from file "plugins\SuperBans\config.yml"
        add "&7Autounban: &c%{sban.banexpire.%{_p}%}%" to skutil yaml list "messages.ban_screen_message" from file "plugins\SuperBans\config.yml"
        add "" to skutil yaml list "messages.ban_screen_message" from file "plugins\SuperBans\config.yml"
        add "&7IP Banned: &c%{sban.banip.%{_p}%}%" to skutil yaml list "messages.ban_screen_message" from file "plugins\SuperBans\config.yml"
        add "" to skutil yaml list "messages.ban_screen_message" from file "plugins\SuperBans\config.yml"
        add "&7Reason: &c%{sban.banreason.%{_p}%}%" to skutil yaml list "messages.ban_screen_message" from file "plugins\SuperBans\config.yml"
        add "" to skutil yaml list "messages.ban_screen_message" from file "plugins\SuperBans\config.yml"
        add "" to skutil yaml list "messages.ban_screen_message" from file "plugins\SuperBans\config.yml"
        add "&eBuy an unban &8» &cwww.yourserver.buycraft.net" to skutil yaml list "messages.ban_screen_message" from file "plugins\SuperBans\config.yml"
        add "" to skutil yaml list "messages.ban_screen_message" from file "plugins\SuperBans\config.yml"
        add "&eForums to apply &8» &cwww.yourserver.net" to skutil yaml list "messages.ban_screen_message" from file "plugins\SuperBans\config.yml"
    set {superbans::messages::ban_screen_message::*} to yml list "messages.ban_screen_message" of file "plugins\SuperBans\config.yml"

But when using {superbans::messages::ban_screen_message::*} the message is displayed with commas, and I want it to be displayed with spaces. And also, the variables are writed to the file like <none>
 
@KroterPvP Your asking help , so free time of others , for a resource that you will publish premium for earn money.
It's not a really good way.
It's good ask help , when you will be able to back it in the future, that's how a community works.

That's my opinion , only that.
 
@KroterPvP Your asking help , so free time of others , for a resource that you will publish premium for earn money.
It's not a really good way.
It's good ask help , when you will be able to back it in the future, that's how a community works.

That's my opinion , only that.
I only need anyone to help me with a little issue I'm having. That doesn't mean the premium resource is not mine, couse it has more than 1500 lines, and the part that I've posted here only ocupated 20 lines.

Although, you are right, I have a free resource and now I'm coding the paid version with YML, among many other thinhgs, because it's not funny to lose all your configuration options on every plugin update where a skript config value changes.

If you don't wanna help me, don't do it.