-
-
Notifications
You must be signed in to change notification settings - Fork 408
Example Script API #8191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev/feature
Are you sure you want to change the base?
Example Script API #8191
Conversation
Haven't looked over this much but regarding your comment about it always readding the examples can we not just add a config toggle? And does this load example skripts on server start or is it unloaded until reloaded? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good 🔥
/** | ||
* Represents an example script bundled with Skript or an addon. | ||
*/ | ||
public record ExampleScript(String name, String content) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe this could be an interface where all the example scripts are registered? this can then be extended by addons and registered with SkriptAddon
|
||
private CoreExampleScripts() {} | ||
|
||
public static Collection<ExampleScript> all() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public static Collection<ExampleScript> all() { | |
public static Collection<ExampleScript> values() { |
this method should probably be moved to ExampleScript if it becomes an interface
private static boolean disabled = false; | ||
private static boolean partDisabled = false; | ||
|
||
public static @Nullable ExampleScriptManager exampleManager; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should probably be package-private and have a getter to enforce usage through SkriptAddon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like this will continually generate the -examples directory if i delete it from my installation, instead of only generating on first install. Is this correct, and if so, that needs to be fixed.
load("chest menus.sk"), | ||
load("commands.sk"), | ||
load("events.sk"), | ||
load("experimental features/for loops.sk"), | ||
load("experimental features/queues.sk"), | ||
load("experimental features/script reflection.sk"), | ||
load("functions.sk"), | ||
load("loops.sk"), | ||
load("options and meta.sk"), | ||
load("text formatting.sk"), | ||
load("timings.sk"), | ||
load("variables.sk") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it'd be nice to separate the bukkit-based examples out into a different list where feasible
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public final class ExampleScriptManager { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs javadocs in this class
Problem
The current method of providing the example scripts isn't ideal, and doesn't allow addons to extend this useful function.
This PR gives addons a way to add their own example scripts, allowing for another method of providing documentation to new and experienced Skript players alike.
Solution
This PR introduces a new way to create and track the example scripts. It now uses a hidden
.examples-loaded
file in the Skript folder to identify which examples need to be created on plugin enable, and which have already been handled. This is a better alternative, as before Skript used to just go off of whether the scripts folder existed, which isn't a sure way to get this info.The example scripts are stored as
ExampleScript
records, and loaded from the resources where they're currently stored.It also provides
SkriptAddon#registerExampleScripts
so that addons are able to provide example scripts. With this change, the example scripts have been separated into different folders based on the addon name.Testing Completed
Manually tested going from old versions of Skript to this one, and from this version of Skript to itself.
Haven't included tests for this as I'm unsure how to validate that, once Skript has loaded them once, they don't get loaded again. My own testing confirms that the behaviour works as intended, but unsure how to prove it via code.
Supporting Information
With this PR, given the updated way that example scripts are created and tracked, all example scripts will be created again if they were deleted. I think this is pretty minor, and don't think it's possible to avoid.
Not massively attached to this implementation, just thought it might be a nice addition and put together a solution quickly, so thoughts and feedback are appreciated.
Completes: none
Related: none