1. 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!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How is skript parsing a sk file?

Discussion in 'Java' started by Gamebuster, Feb 1, 2017.

  1. Gamebuster

    Addon Developer

    Joined:
    Jan 25, 2017
    Messages:
    26
    Likes Received:
    3
    So, I'm looking at the SkriptParser class (https://github.com/Njol/Skript/blob/master/src/main/java/ch/njol/skript/lang/SkriptParser.java).

    I'm trying to figure out where exactly skript is parsing a string into whatever skript uses to execute code.

    I.E.

    Code (Text):
    1.  
    2. on spawn of player:
    3.     message "lel, %event-player%" to player
    4.  
    How does it determine that player is a valid entity for the on spawn event, or that %event-player% is actually a player? What's actually stopping nonsense like the below code from parsing:

    Code (Text):
    1.  
    2. on spawn of chest:
    3.     teleport %event-chest% to water
    4.  
     
    • Friendly Friendly x 1
  2. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    222
    Some of it is also done in.
    https://github.com/Njol/Skript/blob/master/src/main/java/ch/njol/skript/ScriptLoader.java#L634-L740
    This is where it detects an error and prints it such as "Don't understand condition/effect"
    https://github.com/Njol/Skript/blob/master/src/main/java/ch/njol/skript/lang/SkriptParser.java#L171-L177
    event-* are registered already, so Skript knows which ones are valid or not. Everything is parsed, but not everything matches what Skript expects.
     
    • Friendly Friendly x 1
  3. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    222
    I think it just like store something into an hashmap
    Event can be the key , and the expression can be the value
    if you wanna check the expression is valid on that event just check
    if(hash.get(event).equals(expression))

    i dunno what is exactly Skript doing but that's logic maybe still the same
     
    • Friendly Friendly x 1
  4. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    222
    • Friendly Friendly x 1

Share This Page

Loading...