Repository navigation
Derive safe NeoForge defaults from shared Bukkit configuration #1768
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
Draft
BenCodez
wants to merge
6
commits into
master
Choose a base branch
from
neoforge/first-run-defaults-72
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+351
−4
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2ed2457
Give fresh NeoForge installs supported reward defaults
BenCodez de59e74
Reuse shared configuration and keep offline rewards waiting by default
BenCodez 3103f7f
Preserve supported shared commands in NeoForge starter defaults
BenCodez ac9e8a3
Disable unsupported monthly awards in fresh NeoForge defaults
BenCodez 4b18495
Clarify NeoForge monthly award and startup warning limits
BenCodez 5cff131
Scope NeoForge startup diagnostics to global replay blockers
BenCodez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
...lugin/src/main/java/com/bencodez/votingplugin/neoforge/NeoForgeConfigurationDefaults.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package com.bencodez.votingplugin.neoforge; | ||
|
|
||
| import java.io.BufferedReader; | ||
| import java.io.BufferedWriter; | ||
| import java.io.IOException; | ||
| import java.io.StringReader; | ||
| import java.io.StringWriter; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.List; | ||
|
|
||
| import org.spongepowered.configurate.yaml.YamlConfigurationLoader; | ||
|
|
||
| /** Derives missing-file defaults from the shared Bukkit templates, not a second schema. */ | ||
| final class NeoForgeConfigurationDefaults { | ||
| private NeoForgeConfigurationDefaults() { } | ||
|
|
||
| static byte[] fromShared(String name, byte[] template) throws IOException { | ||
| if (!List.of("Config.yml", "VoteSites.yml", "SpecialRewards.yml").contains(name)) return template; | ||
| var node = YamlConfigurationLoader.builder().source(() -> new BufferedReader( | ||
| new StringReader(new String(template, StandardCharsets.UTF_8)))).build().load(); | ||
| switch (name) { | ||
| case "Config.yml" -> { | ||
| for (String key : List.of("CloseInventoryOnVote", "UseVoteStreaks", "PerSiteCoolDownEvents", | ||
| "LimitMonthlyVotes")) node.node(key).set(false); | ||
| node.node("OfflineVotesLimit", "Enabled").set(false); | ||
| node.node("VoteBroadcast", "Type").set("NONE"); | ||
| } | ||
| case "SpecialRewards.yml" -> { | ||
| node.node("VoteParty", "Enabled").set(false); | ||
| node.node("EnableMonthlyAwards").set(false); | ||
| for (String key : List.of("AnySiteRewards", "VoteCoolDownEndedReward", "VoteMilestones", | ||
| "VoteStreaks", "VoteStreak", "Cumulative", "MileStones", "FirstVote", | ||
| "FirstVoteToday", "AllSites", "AlmostAllSites")) node.node(key).set(java.util.Map.of()); | ||
| } | ||
| case "VoteSites.yml" -> { | ||
| // The shared examples combine unsupported actions. Keep their site settings, | ||
| // but offer only one supported action, without opting into offline execution. | ||
| for (var site : node.node("VoteSites").childrenMap().values()) { | ||
| site.node("ForceOffline").set(false); | ||
| site.node("GiveOffline").set(false); | ||
| var commands = site.node("Rewards", "Commands").copy(); | ||
| site.node("Rewards").set(java.util.Map.of()); | ||
| site.node("Rewards", "Commands").set(commands); | ||
| } | ||
| } | ||
| default -> throw new IllegalStateException("Unexpected default template"); | ||
| } | ||
| StringWriter rendered = new StringWriter(); | ||
| YamlConfigurationLoader.builder().sink(() -> new BufferedWriter(rendered)).build().save(node); | ||
| return rendered.toString().getBytes(StandardCharsets.UTF_8); | ||
| } | ||
| } | ||
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.