Support wildcards in world name lists - #886
Open
HyperGaming99 wants to merge 1 commit into
Open
Conversation
World lists in the config now accept '*' as a wildcard, so 'hub*' or '*hub*' can be used instead of listing every world by name. Entries without '*' keep matching exactly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #807.
World name lists in the config can now use
*as a wildcard instead of spelling out every world:*matches any (possibly empty) sequence of characters, and a pattern has to match the wholename, so
hub*does not matchmyhub01. Entries without*keep being matched exactly, soexisting configs behave exactly as before.
Implementation
org.dreeam.leaf.config.WorldListholds the exact names in aHashSetand compiles thewildcard entries into
Patterns once at config load, so matching does no per-call parsing.DisableWorldDataSaving.shouldSkipSavekeeps itsisEmpty()short circuit, meaning serversthat do not use the option pay nothing. The only call sites are chunk/entity/POI saving and
ServerLevel#save, next to NBT serialization and disk IO, so a regex match there is noise.Currently
disable-world-data-saving.worldsis the only world list in the config;WorldListis written so any future one can reuse it.
Notes
The issue proposed a
--hubprefix to mean "contains". I went with*instead: it expressescontains (
*hub*), prefix (hub*) and suffix (*hub) with the same syntax, it is theconvention users already know, and
*is not a legal character in world folder names onWindows, so it cannot collide with an existing exact entry. Happy to switch to another syntax
if you prefer.
Matching is case sensitive, like world folder names.
Testing
Verified against the compiled class with assertions covering: regex metacharacters in world
names staying literal (
a+b,c(d),e.f*,*g|h),Pattern.quotewith an embedded\E,multiple and adjacent wildcards, anchoring (
hubnot matchinghub01), unicode names,case sensitivity, and blank/null entries being skipped.