-
-
Notifications
You must be signed in to change notification settings - Fork 407
Global Options #8192
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?
Global Options #8192
Conversation
reloading(sender, "global options", logHandler); | ||
GlobalOptions.load(); | ||
reloaded(sender, logHandler, timingLogHandler, "global options"); |
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.
should also send a warning that the users should reload all scripts using global options.
private static void loadOptions(SectionNode sectionNode, String prefix, Map<String, String> options) { | ||
for (Node node : sectionNode) { | ||
if (node instanceof EntryNode) { | ||
options.put(prefix + node.getKey(), ((EntryNode) node).getValue()); | ||
} else if (node instanceof SectionNode) { | ||
loadOptions((SectionNode) node, prefix + node.getKey() + ".", options); | ||
} else { | ||
Skript.error("Invalid line in options"); | ||
} | ||
} | ||
} |
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.
can we make this public so we don't have duplicated code between Struct and GlobalOptions
# This file lets you set options globally. | ||
# Options here will be available across all scripts. | ||
# Scripts can override a global option by creating an option with the same name as the global one. | ||
# When you edit this file, you must reload global-options and all script files that use global options. |
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.
# When you edit this file, you must reload global-options and all script files that use global options. | |
# When you edit this file, you must first reload global-options and then reload all the script files that use global options. |
Problem
The problem is explained in detail in #2028, but the general idea is that having a global options file makes it easier to change static values across lots of script files.
This PR also fixes another issue, using the code below:
{@hello}
is parsed as a variable, because the script doesn't contain theoptions
structure.Therefore, it doesn't throw the
unknown option
error.Solution
Added a new
global-options.sk
file inside/plugins/Skript/
folder. The entries inside are loaded into a static map.Whenever
replaceOptions
is called, it checks if the script has that option first and returns it. If it doesn't, it gets the option from the static map instead. This lets scripts override global options.You can also use sections just like the structure version.
Testing Completed
Only manual testing, unit tests will be added after reviews when it's finalised
TODO (after finalised)
Completes: #2028
Related: none