Skip to content

Conversation

cheeezburga
Copy link
Member

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

@cheeezburga cheeezburga requested review from a team as code owners September 15, 2025 05:40
@cheeezburga cheeezburga requested review from APickledWalrus and Pesekjak and removed request for a team September 15, 2025 05:40
@skriptlang-automation skriptlang-automation bot added the needs reviews A PR that needs additional reviews label Sep 15, 2025
@Fusezion
Copy link
Contributor

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?

Copy link
Member

@Efnilite Efnilite left a 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) {
Copy link
Member

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() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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;
Copy link
Member

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

Copy link
Member

@sovdeeth sovdeeth left a 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.

Comment on lines +12 to +23
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")
Copy link
Member

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 {
Copy link
Member

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

@skriptlang-automation skriptlang-automation bot removed the needs reviews A PR that needs additional reviews label Sep 16, 2025
@sovdeeth sovdeeth added the feature Pull request adding a new feature. label Sep 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Pull request adding a new feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants