Skript: [Suggestion] 'Required plugins' section checked before loading/parsing individual scripts

Created on 3 May 2019  路  10Comments  路  Source: SkriptLang/Skript

Description

My suggestion is to allow some form of condition to load/parse a script if a particular addon/plugin is recognised.

In a Java Plugin you can create allowances for certain things only to be used if a player has a certain version/library/API.
For instance, a plugin using NMS methods would have separate code for 1.8 servers and 1.13 servers.

This is not available for Skript at all.

An example of where this could be used:

Bob posts his clans skript to Spigot.
If the user has "skript-yaml" addon, clan data will be saved to YAML files.
If the user doesn't have skript-yaml addon, Bob wants to save the data in variables.

While he could just include both, the user will get hundreds of errors showing up if they don't have "skript-yaml".

What would be nice would be to have some way to check before parsing if a particular plugin is present, or if a certain syntax pattern exists. If this condition fails, then the script won't be loaded.

I have no idea of the best way to implement this, but I am imagining either a section at the top of the file:

required-plugins:
  skript-yaml
  MundoSK
  ProtocolLib
  PlaceholderAPI

Like the options section, this would be checked first (case-sensitive) against the plugin list. If the condition is not met, it would stop parsing the script and move on to the next one.

An alternative would be to have some sort of option to disable the parsing errors for individual scripts, such as:

disable parsing errors: true

While obviously, this second one would be quite a dangerous option, this functionality is suggested for Skript users who are publishing their completed, tested work to Spigot or other similar Skript sites.

The purpose of this suggestion is ONLY for seasoned skript users who wish to publish their work, and their work allows for plugin use.

It would allow much greater functionality/utility within public skripts, without the need for separate downloads and versions, allowing for greater user experience.

Alternative syntax suggestions:
[plugin] %strings% (is|are) installed
parse if <.+> (regex for condition)
plugin version (from @Blueyescat 馃槂)

enhancement medium

Most helpful comment

If this is doable I think it's an awesome idea. It'd be cool if we could do this per-code section as well, e.g. in your example most of the clans script would likely be the same except for the variable storage sections (which could be outsourced to functions), in which case you might want two of the same function but with conditional load markers based on plugins.

I'm setting this to medium because enhancements are effectively all optional so IMO it makes sense to use priority to denote their value and I see a lot of value in this idea.

All 10 comments

If this is doable I think it's an awesome idea. It'd be cool if we could do this per-code section as well, e.g. in your example most of the clans script would likely be the same except for the variable storage sections (which could be outsourced to functions), in which case you might want two of the same function but with conditional load markers based on plugins.

I'm setting this to medium because enhancements are effectively all optional so IMO it makes sense to use priority to denote their value and I see a lot of value in this idea.

Thanks for your support!

Originally, I was thinking of suggesting a more in-line approach (as you recommend), such as a condition:
[plugin] %strings% (is|are) installed
Which you could then use for individual sections, but I thought this might be rather complicated to actually implement (since it would require individual lines to be parsed/not parsed). I'm not a Java expert, though, so that might still be possible.

I'd love to see this added, though. I very much dislike sharing skripts that require multiple dependencies as 99% of the comments I then receive are usually asking why X version doesn't work, why there are errors, etc.
I would see this as being a major step forward.

Edit:
Just thought of another way the expression might be formatted.
A section starting with:
parse if <.+> (a condition)
Although obviously very few things could be put there since you can't exactly set variables or run code before the script has parsed. Make of it what you will.

Isn't this a duplicate of #1449?

Yeah kinda. That one is specific to add-ons while this one is more generalize to all plugins and offers a different (or perhaps additional) approach -- conditions for loading the entire script instead of just a extra single condition. Perhaps we should close 1449 in favor of this one?

The other issue suggests more logical syntax for this system, but this one covers every plugin.

I hadn't noticed Shane's suggestion.
If this functionality was being added at all, it would make much more sense to extend it to all plugins. That way if somebody has, for example, MundoSK, they can check for both MundoSK and ProtocolLib to use the packet syntax.
SkUniversal would be the best example actually, as it has syntax for SO many plugins, you'd want to know more than just if the basic addon was installed.
Plus, it would give us a more powerful tool to use that way.

In terms of how to check, would it be practical to include plugin version conditions as well? Or is that . not practical.

I don't like the syntax you are suggesting, i think it should work like conditions and it can accept any condition (so we can have plugin version expression), but for events... Need to think about.

Oh, I only suggested the top-of-file because I thought it would be easier to add and, therefore, more likely to be added. I'll edit the alternatives from these comments into the original post if you like.

a condition type thing would actually be easier to add

I'm not supposed to give my opinion but
parse if <.+> sounds cool, even if it might be hard to implement(I'm no java expert)

just what came in my head as an example of that

#First section
parse if plugin "PlaceholderAPI" is loaded:

on load:
    send "Loading PlaceholderAPI placeholders" to console

on placeholder request with prefix "Game":
    loop "coins", "level" and "xp": 
        identifier is "%loop-value%"
        set {_stats} to yaml value "STATS.%loop-value%" from "game.player.data.%uuid of player%"
        set the result to "%{_stats}%"      

#End section(somehow something must be added here to mark the section end)

#Second section
parse if plugin "PlaceholderAPI" is not loaded:

on load:
    send "PlaceholderAPI not found, switching to something else" to console

#End section.
Was this page helpful?
0 / 5 - 0 ratings

Related issues

GiraffeCubed picture GiraffeCubed  路  3Comments

Misio12320 picture Misio12320  路  3Comments

Anoniempje1234 picture Anoniempje1234  路  3Comments

Coolfire02 picture Coolfire02  路  3Comments

TrademarkTM picture TrademarkTM  路  4Comments