Skip to content
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

User configs #6720

Open
wants to merge 97 commits into
base: feature/script-reflection
Choose a base branch
from

Conversation

Moderocky
Copy link
Member

Description

User-provided config files.

I was inspired by a conversation with Walrus yesterday around the lack of config stuff in Skript when they're normally such a big part of setting up a server.
We talked a lot about safety (I suggested registration, he suggested storing them in a /configs/ directory) and this was the basic layout I came up with.

Additions

This adds:
- Config registration structure
- Config get expression
- Changers for nodes
- Config reloading & saving via EffScriptFile

A script-maker can register their own config file within a script. They are then able to read (and write) this config, in order to take input from a user in a more sanitary way than in-script options.
This also means users don't have to download and learn an unsafe file addon in order to make a config file.

It's primarily aimed at people publishing their resources, but it's also potentially a better alternative to the suggestion in historic issue #2028, since it allows common values to be collated in one safe place and shared between scripts.

There is a heavy focus on resource safety.

Syntax

register config %*string%

[the] config [named] %*string%
(load|reload|unload|save) %config%

What does this actually do?

It allows users to register a config file used by their script.
This file is linked to the script: they are loaded, reloaded and discarded together.
A config can be registered by multiple scripts.

Config values can be edited via the node tree.

register config "my cool config" # we register here

on load:
    set {config} to the config named "my cool config"
    # there's actually no point setting a variable since `config named x` config literals are handled during parse but i thought it looked cooler in my amazing example

on join:
    set {_node} to node "welcome message" in {config}
    broadcast the text value of {_node}

    set {_node} to node "join item" in {config}
    give player (item type value of {_type})
    

command /reset the config:
    trigger:
        set the text value at "welcome message" in {config} to "Welcome!"
        set the number value at "maximum players" in {config} to 15
        set the text value at "message.prefix" in {config} to "[message]"
        set the color value at "message.color" in {config} to red
        save {config}

Other Notes

I considered opening this up to other .sk files, since it wouldn't be a huge stretch to allow users to read and write general data files in the same way.

That said, I was concerned about not being able to manage the opening/closing of unknown files safely and decided that was better left to an addon or a future project.

For anybody wishing to implement that themselves, you'd just need to return a Config or even a Node from some expression.


This is part of a series of linked stages around config and script management.

image

Related Issues: requires #6718, requires #6702, requires #6719, fixes #2028

@Moderocky Moderocky marked this pull request as draft May 24, 2024 19:52
Copy link
Member

@APickledWalrus APickledWalrus left a comment

Choose a reason for hiding this comment

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

Feel free to re-request me once conflicts are resolved/branch updated

@Moderocky Moderocky requested a review from sovdeeth December 27, 2024 08:12
@Moderocky Moderocky force-pushed the feature/script-reflection branch 2 times, most recently from 88f2061 to 1235d8d Compare December 31, 2024 11:57
@Moderocky Moderocky force-pushed the user-configs branch 3 times, most recently from d5d2b9c to 4aa297f Compare December 31, 2024 19:15
@Moderocky Moderocky force-pushed the feature/script-reflection branch from b945e0c to 2dd5cff Compare January 1, 2025 09:24
Moderocky and others added 9 commits January 1, 2025 09:42
Mass-merge for script reflection pull requests.
* Registry Cleanup

* registry.sk - add a few more tests
* Queueueue basics.

* Add dequeueing expression.

* Move closing quote.

* Update src/main/java/org/skriptlang/skript/lang/util/SkriptQueue.java

* Update src/main/java/ch/njol/skript/expressions/ExprQueue.java

Co-authored-by: Patrick Miller <apickledwalrus@gmail.com>

* Review bits.

* Apply suggestions from code review

Co-authored-by: Efnilite <35348263+Efnilite@users.noreply.github.com>
Co-authored-by: Patrick Miller <apickledwalrus@gmail.com>

* Add some bits.

* Bits from review.

* Fix return type.

* Docs.

* Do requested changes.

* Fix things for walrus.

* Merge dev/feature.

---------

Co-authored-by: Patrick Miller <apickledwalrus@gmail.com>
Co-authored-by: Efnilite <35348263+Efnilite@users.noreply.github.com>
…kriptLang#7346)

* Suppress all removal warnings & remove getters.

* Fix casing.
* minecraft tags part 1

* tags part 2

paper's material/entity tags, get all tags of something

* forgot to remove _settag for entity tags too

* all tags of type

* major refactor

* Add origin filtering

* populate omitted namespaces

* implement simplify for future use cases

* all the documentation you could ever want!

* gatekeep gaslight girlboss the paper tags

* basic tests and fix comparisons

Tests are kept deliberately small due to the volatile nature of tag contents.

* custom tags!

* add ways to turn tag into a string

* a few more examples

* requested changes

* plural exprtags and parity between tag toString and toVariableString

* Fix over-zealous refactor

* Requested changes

* Requested changes

* Update src/main/java/ch/njol/util/Pair.java

Co-authored-by: Efnilite <35348263+Efnilite@users.noreply.github.com>

* Update src/main/java/org/skriptlang/skript/bukkit/tags/TagType.java

Co-authored-by: Patrick Miller <apickledwalrus@gmail.com>
Make closeable an auto-closeable and allow try-with-resources.

Deprecate unused case insensitive strings for removal.
* Mark VectorMath as internal

* Replace usages
* Make Setter a Consumer.

* Remove Setter from Option.

* Remove setter from entry validator.

* Remove setter from enum entry validator.

* Remove setter from parsed entry validator.

* Remove setter from parsed section validator.
Moderocky and others added 29 commits January 15, 2025 22:01
Merge feature branch into master (before release).
* Create Script type.

* Support script string/name conversion.

* Script expression.

* Add script lang entry.

* Tests for script expression & names.

* Support all scripts expression.

* Script effects & tests.

* Create dummy Script handle for disabled scripts.

* Script reflection feature flag.

* Restrict literal parsing to commands & parse.

* Test feature flag for resolving name.

* Split ExprScripts by feature to support disabled scripts.

* Fix ExprName tests for new & old behaviour.

* Add tests for disabled script handles.

* Apply suggestions from code review

Co-authored-by: Patrick Miller <apickledwalrus@gmail.com>

* Improve script loading/unloading safety.

* Add feature check for script hotswapping.

* Use expression stream.

* Conformity for file names and proper loading safety.

* Document validity & add condition support.

* Add script is loaded condition + tests.

* Some changes from code review.

* More changes.

* Apply suggestions from code review

Co-authored-by: Patrick Miller <apickledwalrus@gmail.com>

* Clean up EffScriptFile and rename ExprScripts variations.

* Finish code review changes.

* Clean up script loader stuff.

* Fix conflicts.

* Suggested changes.

* Apply suggestions from code review

Co-authored-by: Patrick Miller <apickledwalrus@gmail.com>

* Finished.

---------

Co-authored-by: Patrick Miller <apickledwalrus@gmail.com>
Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com>
* Create Script type.

* Support script string/name conversion.

* Script expression.

* Add script lang entry.

* Tests for script expression & names.

* Support all scripts expression.

* Script effects & tests.

* Create dummy Script handle for disabled scripts.

* Script reflection feature flag.

* Restrict literal parsing to commands & parse.

* Test feature flag for resolving name.

* Split ExprScripts by feature to support disabled scripts.

* Fix ExprName tests for new & old behaviour.

* Add tests for disabled script handles.

* Apply suggestions from code review

Co-authored-by: Patrick Miller <apickledwalrus@gmail.com>

* Improve script loading/unloading safety.

* Add feature check for script hotswapping.

* Use expression stream.

* Conformity for file names and proper loading safety.

* Document validity & add condition support.

* Add script is loaded condition + tests.

* Dynamic function calling + tests.

* Add language entry for types.

* Single-encounter input bootstrapping.

* Apply suggestions from code review

Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com>

* Fix inspection.

* Update src/main/java/ch/njol/skript/expressions/ExprFunction.java

Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com>

* Update src/main/java/ch/njol/skript/expressions/ExprResult.java

Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com>

* Changes from review.

* Fix merge problems.

* Remove script command method usage.

* Fix branch muck.

* Fix more branch muck.

* Fix up ExprName.

* Add docs.

* Add docs.

* Add docs.

* Fix bits.

* Apply suggestions from code review

Co-authored-by: Patrick Miller <apickledwalrus@gmail.com>

* Fix some bits.

* Function parsing by name.

* Fix up some bits for Walrus.

* Fix merge error.

---------

Co-authored-by: Patrick Miller <apickledwalrus@gmail.com>
Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com>
* Create Script type.

* Support script string/name conversion.

* Script expression.

* Add script lang entry.

* Tests for script expression & names.

* Support all scripts expression.

* Script effects & tests.

* Create dummy Script handle for disabled scripts.

* Script reflection feature flag.

* Restrict literal parsing to commands & parse.

* Test feature flag for resolving name.

* Split ExprScripts by feature to support disabled scripts.

* Fix ExprName tests for new & old behaviour.

* Add tests for disabled script handles.

* Apply suggestions from code review

Co-authored-by: Patrick Miller <apickledwalrus@gmail.com>

* Improve script loading/unloading safety.

* Add feature check for script hotswapping.

* Use expression stream.

* Conformity for file names and proper loading safety.

* Document validity & add condition support.

* Add script is loaded condition + tests.

* Some changes from code review.

* More changes.

* Apply suggestions from code review

Co-authored-by: Patrick Miller <apickledwalrus@gmail.com>

* Clean up EffScriptFile and rename ExprScripts variations.

* Finish code review changes.

* Clean up script loader stuff.

* Fix conflicts.

* Suggested changes.

* Apply suggestions from code review

Co-authored-by: Patrick Miller <apickledwalrus@gmail.com>

* Finished.

---------

Co-authored-by: Patrick Miller <apickledwalrus@gmail.com>
Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com>
Co-authored-by: Patrick Miller <apickledwalrus@gmail.com>
Co-authored-by: Patrick Miller <apickledwalrus@gmail.com>
* Create Script type.

* Support script string/name conversion.

* Script expression.

* Add script lang entry.

* Tests for script expression & names.

* Support all scripts expression.

* Script effects & tests.

* Create dummy Script handle for disabled scripts.

* Script reflection feature flag.

* Restrict literal parsing to commands & parse.

* Test feature flag for resolving name.

* Split ExprScripts by feature to support disabled scripts.

* Fix ExprName tests for new & old behaviour.

* Add tests for disabled script handles.

* Apply suggestions from code review

Co-authored-by: Patrick Miller <apickledwalrus@gmail.com>

* Improve script loading/unloading safety.

* Add feature check for script hotswapping.

* Use expression stream.

* Conformity for file names and proper loading safety.

* Document validity & add condition support.

* Add script is loaded condition + tests.

* Some changes from code review.

* More changes.

* Apply suggestions from code review

Co-authored-by: Patrick Miller <apickledwalrus@gmail.com>

* Clean up EffScriptFile and rename ExprScripts variations.

* Finish code review changes.

* Clean up script loader stuff.

* Fix conflicts.

* Suggested changes.

* Apply suggestions from code review

Co-authored-by: Patrick Miller <apickledwalrus@gmail.com>

* Finished.

---------

Co-authored-by: Patrick Miller <apickledwalrus@gmail.com>
Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants