diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/neoforge/NeoForgeConfigurationDefaults.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/neoforge/NeoForgeConfigurationDefaults.java new file mode 100644 index 0000000000..380b9cbe71 --- /dev/null +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/neoforge/NeoForgeConfigurationDefaults.java @@ -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); + } +} diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/neoforge/NeoForgeRewardConfiguration.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/neoforge/NeoForgeRewardConfiguration.java index e5de5e9d53..420988bb2d 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/neoforge/NeoForgeRewardConfiguration.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/neoforge/NeoForgeRewardConfiguration.java @@ -82,7 +82,7 @@ private static NeoForgeRewardPlan.Action expand(NeoForgeRewardPlan.Action action .replace("%ServiceSite%", serviceSite).replace("%servicesite%", serviceSite)); } - private String unsupportedGlobalBehavior() { + String unsupportedGlobalBehavior() { if (node(config, ignoreCase, "CloseInventoryOnVote").getBoolean(true)) { return "CloseInventoryOnVote is not supported by NeoForge replay yet"; } diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/neoforge/NeoForgeRuntime.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/neoforge/NeoForgeRuntime.java index d9d9b30c1b..ef35a12e9f 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/neoforge/NeoForgeRuntime.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/neoforge/NeoForgeRuntime.java @@ -2,6 +2,7 @@ import java.io.IOException; import java.io.InputStream; +import java.io.ByteArrayInputStream; import java.nio.file.FileAlreadyExistsException; import java.nio.file.Files; import java.nio.file.Path; @@ -10,6 +11,7 @@ import java.util.List; import java.util.Objects; import java.util.Optional; +import java.util.logging.Logger; import org.spongepowered.configurate.ConfigurationNode; import org.spongepowered.configurate.yaml.YamlConfigurationLoader; @@ -98,6 +100,13 @@ private static NeoForgeRuntime start(Path directory, Clock clock, Object server) ConfigurationNode voteSites = YamlConfigurationLoader.builder().path(voteSitesFile).build().load(); ConfigurationNode specialRewards = YamlConfigurationLoader.builder().path(specialRewardsFile).build().load(); ConfigurationNode bungeeSettings = YamlConfigurationLoader.builder().path(bungeeSettingsFile).build().load(); + String rewardBlocker = new NeoForgeRewardConfiguration(config, voteSites, specialRewards) + .unsupportedGlobalBehavior(); + if (rewardBlocker != null) { + Logger.getLogger(NeoForgeRuntime.class.getName()).warning("NeoForge reward configuration: " + + rewardBlocker + "; affected votes remain pending. Review the NeoForge setup guide;" + + " existing configuration files are not changed."); + } NeoForgeVoteConfiguration voteConfiguration = NeoForgeVoteConfiguration.load(config, voteSites); NeoForgeProxySocketConfiguration proxyConfiguration; try { @@ -138,8 +147,9 @@ private static Path installDefault(Path directory, String name) throws IOExcepti if (Files.notExists(target)) { try (InputStream resource = NeoForgeRuntime.class.getClassLoader().getResourceAsStream(name)) { if (resource == null) throw new IOException("Missing packaged configuration: " + name); + byte[] initial = NeoForgeConfigurationDefaults.fromShared(name, resource.readAllBytes()); try { - Files.copy(resource, target); + Files.copy(new ByteArrayInputStream(initial), target); } catch (FileAlreadyExistsException ignored) { // Another bootstrap installed the same file; load the installed file below. } diff --git a/VotingPlugin/src/test/java/com/bencodez/votingplugin/tests/neoforge/NeoForgeFirstRunConfigurationTest.java b/VotingPlugin/src/test/java/com/bencodez/votingplugin/tests/neoforge/NeoForgeFirstRunConfigurationTest.java new file mode 100644 index 0000000000..5006d83400 --- /dev/null +++ b/VotingPlugin/src/test/java/com/bencodez/votingplugin/tests/neoforge/NeoForgeFirstRunConfigurationTest.java @@ -0,0 +1,274 @@ +package com.bencodez.votingplugin.tests.neoforge; + +import static org.junit.jupiter.api.Assertions.*; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.logging.Handler; +import java.util.logging.LogRecord; +import java.util.logging.Logger; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import org.spongepowered.configurate.yaml.YamlConfigurationLoader; + +import com.bencodez.votingplugin.core.vote.SharedVoteIdentity; +import com.bencodez.votingplugin.neoforge.*; + +class NeoForgeFirstRunConfigurationTest { + @TempDir Path directory; + + @Test + void freshConfigurationCanCompleteOneSupportedRewardAcrossRestart() throws Exception { + try (NeoForgeRuntime runtime = NeoForgeRuntimeAccess.start(directory)) { + assertFalse(runtime.config().node("CloseInventoryOnVote").getBoolean(true)); + assertFalse(runtime.config().node("UseVoteStreaks").getBoolean(true)); + assertFalse(runtime.specialRewards().node("EnableMonthlyAwards").getBoolean(true)); + assertEquals("NONE", runtime.config().node("VoteBroadcast", "Type").getString()); + assertTrue(runtime.voteConfiguration().voteSites().stream().noneMatch(NeoForgeVoteSite::enabled)); + assertTrue(runtime.voteConfiguration().voteSites().stream().noneMatch(NeoForgeVoteSite::giveOfflineRewards)); + assertFalse(runtime.voteSites().node("VoteSites", "ExampleVoteSite", "GiveOffline").getBoolean(true)); + } + Path sitesFile = directory.resolve("VoteSites.yml"); + var loader = YamlConfigurationLoader.builder().path(sitesFile).build(); + var sites = loader.load(); + sites.node("VoteSites", "ExampleVoteSite", "Enabled").set(true); + loader.save(sites); + UUID player = UUID.randomUUID(); + UUID vote = UUID.randomUUID(); + try (NeoForgeRuntime runtime = NeoForgeRuntimeAccess.start(directory)) { + NeoForgePlayerDirectoryAccess.joined(runtime.players(), new SharedVoteIdentity(player, "Alex", true)); + assertEquals(NeoForgeVoteResult.Status.DEFERRED, runtime.voteProcessor().process( + new NeoForgeVoteRequest(vote, player, "Alex", "PlanetMinecraft.com", 100L, + true, true, true, NeoForgeVoteRequest.Scope.COMPLETE)).status()); + assertEquals(vote, runtime.deferredVotes().pending(player).get(0).voteId()); + } + try (NeoForgeRuntime runtime = NeoForgeRuntimeAccess.start(directory); + NeoForgeRewardReplayService replay = NeoForgeRewardReplayServiceAccess.create( + runtime.voteConfiguration(), new NeoForgeRewardConfigurationAccess(runtime.config(), + runtime.voteSites(), runtime.specialRewards()), runtime.accounting(), + runtime.deferredVotes(), runtime.players(), (occurrence, plan) -> { + fail("The default console reward must wait while the player is offline"); + return CompletableFuture.completedFuture(null); + })) { + assertEquals(NeoForgeRewardReplayService.Status.WAITING_FOR_PLAYER, + replay.replayOnce().get(5, TimeUnit.SECONDS).get(0).status()); + assertEquals(vote, runtime.deferredVotes().pending(player).get(0).voteId()); + assertEquals(0, runtime.accounting().load(player).map(NeoForgeVoteAccount::allTimeTotal).orElse(0)); + } + AtomicInteger actions = new AtomicInteger(); + try (NeoForgeRuntime runtime = NeoForgeRuntimeAccess.start(directory); + NeoForgeRewardReplayService replay = NeoForgeRewardReplayServiceAccess.create( + runtime.voteConfiguration(), new NeoForgeRewardConfigurationAccess(runtime.config(), + runtime.voteSites(), runtime.specialRewards()), runtime.accounting(), + runtime.deferredVotes(), runtime.players(), (occurrence, plan) -> { + assertEquals(vote, occurrence.voteId()); + assertEquals(1, plan.actions().size()); + assertEquals(NeoForgeRewardPlan.ActionType.CONSOLE_COMMAND, plan.actions().get(0).type()); + actions.incrementAndGet(); + return CompletableFuture.completedFuture(null); + })) { + NeoForgePlayerDirectoryAccess.joined(runtime.players(), new SharedVoteIdentity(player, "Alex", true)); + assertEquals(NeoForgeRewardReplayService.Status.COMPLETED, + replay.replayOnce().get(5, TimeUnit.SECONDS).get(0).status()); + assertEquals(1, actions.get()); + assertEquals(1, runtime.accounting().load(player).orElseThrow().allTimeTotal()); + assertEquals(1, runtime.accounting().load(player).orElseThrow().points()); + assertTrue(runtime.deferredVotes().pending(player).isEmpty()); + } + try (NeoForgeRuntime runtime = NeoForgeRuntimeAccess.start(directory)) { + assertEquals(NeoForgeVoteResult.Status.ALREADY_COMPLETED, runtime.voteProcessor().process( + new NeoForgeVoteRequest(vote, player, "Alex", "PlanetMinecraft.com", 100L, + true, true, true, NeoForgeVoteRequest.Scope.COMPLETE)).status()); + assertEquals(1, runtime.accounting().load(player).orElseThrow().allTimeTotal()); + } + } + + @Test + void preservesEveryExistingFileByteForByteAndStillBlocksUnsupportedSettings() throws Exception { + String config = "# Operator configuration\nDataStorage: SQLITE\nCloseInventoryOnVote: true\n"; + Files.writeString(directory.resolve("Config.yml"), config); + Files.writeString(directory.resolve("VoteSites.yml"), "# Existing sites\nVoteSites: {}\n"); + Files.writeString(directory.resolve("SpecialRewards.yml"), + "# Existing rewards\nEnableMonthlyAwards: true\nFirstVote: {}\n"); + List files = List.of(directory.resolve("Config.yml"), directory.resolve("VoteSites.yml"), + directory.resolve("SpecialRewards.yml")); + List before = files.stream().map(path -> { + try { return Files.readString(path); } catch (Exception e) { throw new RuntimeException(e); } + }).toList(); + for (int restart = 0; restart < 2; restart++) { + try (NeoForgeRuntime runtime = NeoForgeRuntimeAccess.start(directory)) { + assertTrue(runtime.config().node("CloseInventoryOnVote").getBoolean()); + assertTrue(runtime.specialRewards().node("VoteMilestones").virtual()); + assertTrue(runtime.specialRewards().node("EnableMonthlyAwards").getBoolean()); + } + } + for (int i = 0; i < files.size(); i++) assertEquals(before.get(i), Files.readString(files.get(i))); + } + + @Test + void existingUnsupportedSettingKeepsPendingVoteAndExplainsWhyAfterRestart() throws Exception { + try (NeoForgeRuntime runtime = NeoForgeRuntimeAccess.start(directory)) { } + Path configFile = directory.resolve("Config.yml"); + var configLoader = YamlConfigurationLoader.builder().path(configFile).build(); + var config = configLoader.load(); + config.node("CloseInventoryOnVote").set(true); + configLoader.save(config); + Path sitesFile = directory.resolve("VoteSites.yml"); + var sitesLoader = YamlConfigurationLoader.builder().path(sitesFile).build(); + var sites = sitesLoader.load(); + sites.node("VoteSites", "ExampleVoteSite", "Enabled").set(true); + sitesLoader.save(sites); + UUID player = UUID.randomUUID(); + UUID vote = UUID.randomUUID(); + AtomicInteger warnings = new AtomicInteger(); + Logger logger = Logger.getLogger(NeoForgeRuntime.class.getName()); + Handler handler = new Handler() { + @Override public void publish(LogRecord record) { + if (record.getMessage().contains("CloseInventoryOnVote") + && record.getMessage().contains("remain pending")) warnings.incrementAndGet(); + } + @Override public void flush() { } + @Override public void close() { } + }; + logger.addHandler(handler); + try { + try (NeoForgeRuntime runtime = NeoForgeRuntimeAccess.start(directory)) { + NeoForgePlayerDirectoryAccess.joined(runtime.players(), new SharedVoteIdentity(player, "Alex", true)); + assertEquals(NeoForgeVoteResult.Status.DEFERRED, runtime.voteProcessor().process( + new NeoForgeVoteRequest(vote, player, "Alex", "PlanetMinecraft.com", 100L, + true, true, true, NeoForgeVoteRequest.Scope.COMPLETE)).status()); + } + try (NeoForgeRuntime runtime = NeoForgeRuntimeAccess.start(directory); + NeoForgeRewardReplayService replay = NeoForgeRewardReplayServiceAccess.create( + runtime.voteConfiguration(), new NeoForgeRewardConfigurationAccess(runtime.config(), + runtime.voteSites(), runtime.specialRewards()), runtime.accounting(), + runtime.deferredVotes(), runtime.players(), (occurrence, plan) -> { + fail("Unsupported configuration must not execute a reward"); + return CompletableFuture.completedFuture(null); + })) { + var result = replay.replayOnce().get(5, TimeUnit.SECONDS).get(0); + assertEquals(NeoForgeRewardReplayService.Status.BLOCKED_UNSUPPORTED, result.status()); + assertTrue(result.detail().contains("CloseInventoryOnVote")); + assertEquals(vote, runtime.deferredVotes().pending(player).get(0).voteId()); + assertEquals(0, runtime.accounting().load(player).map(NeoForgeVoteAccount::allTimeTotal).orElse(0)); + } + assertEquals(2, warnings.get()); + } finally { + logger.removeHandler(handler); + } + } + + @Test + void sharedBukkitResourcesKeepTheirEstablishedDefaults() throws Exception { + Path bukkitConfig = directory.resolve("bukkit.yml"); + Path bukkitRewards = directory.resolve("bukkit-rewards.yml"); + try (var config = getClass().getClassLoader().getResourceAsStream("Config.yml"); + var rewards = getClass().getClassLoader().getResourceAsStream("SpecialRewards.yml")) { + Files.copy(config, bukkitConfig); + Files.copy(rewards, bukkitRewards); + } + var config = YamlConfigurationLoader.builder().path(bukkitConfig).build().load(); + var rewards = YamlConfigurationLoader.builder().path(bukkitRewards).build().load(); + assertTrue(config.node("CloseInventoryOnVote").getBoolean()); + assertTrue(config.node("UseVoteStreaks").getBoolean()); + assertEquals("EVERY_VOTE", config.node("VoteBroadcast", "Type").getString()); + assertTrue(rewards.node("VoteMilestones", "FirstVoteAllTime", "Enabled").getBoolean()); + assertTrue(rewards.node("EnableMonthlyAwards").getBoolean()); + } + + @Test + void freshFilesReuseSupportedSharedTemplateValues() throws Exception { + Path sharedFile = directory.resolve("shared.yml"); + try (var resource = getClass().getClassLoader().getResourceAsStream("Config.yml")) { + Files.copy(resource, sharedFile); + } + var shared = YamlConfigurationLoader.builder().path(sharedFile).build().load(); + Path sharedSitesFile = directory.resolve("shared-sites.yml"); + try (var resource = getClass().getClassLoader().getResourceAsStream("VoteSites.yml")) { + Files.copy(resource, sharedSitesFile); + } + var sharedSites = YamlConfigurationLoader.builder().path(sharedSitesFile).build().load(); + var overridden = java.util.Set.of("CloseInventoryOnVote", "UseVoteStreaks", "PerSiteCoolDownEvents", + "LimitMonthlyVotes", "OfflineVotesLimit", "VoteBroadcast"); + try (NeoForgeRuntime runtime = NeoForgeRuntimeAccess.start(directory)) { + for (var entry : shared.childrenMap().entrySet()) { + if (!overridden.contains(String.valueOf(entry.getKey()))) { + assertEquals(entry.getValue().raw(), runtime.config().node(entry.getKey()).raw(), + "Shared supported setting: " + entry.getKey()); + } + } + assertEquals(shared.node("OfflineVotesLimit", "Amount").raw(), + runtime.config().node("OfflineVotesLimit", "Amount").raw()); + assertEquals(shared.node("VoteBroadcast", "Format").raw(), + runtime.config().node("VoteBroadcast", "Format").raw()); + for (var entry : sharedSites.node("VoteSites").childrenMap().entrySet()) { + var actual = runtime.voteSites().node("VoteSites", entry.getKey()); + assertEquals(entry.getValue().node("Rewards", "Commands").raw(), + actual.node("Rewards", "Commands").raw(), "Preserve supported shared commands"); + assertEquals(java.util.Set.of("Commands"), actual.node("Rewards").childrenMap().keySet()); + for (var field : entry.getValue().childrenMap().entrySet()) { + if (!java.util.Set.of("Rewards", "ForceOffline", "GiveOffline").contains(field.getKey())) { + assertEquals(field.getValue().raw(), actual.node(field.getKey()).raw(), + "Preserve shared site field: " + field.getKey()); + } + } + } + } + } + + @Test + void copiedBukkitFilesAndExplicitOfflineChoicesArePreserved() throws Exception { + for (String name : List.of("Config.yml", "VoteSites.yml", "SpecialRewards.yml")) { + try (var resource = getClass().getClassLoader().getResourceAsStream(name)) { + Files.copy(resource, directory.resolve(name)); + } + } + Path sitesFile = directory.resolve("VoteSites.yml"); + var loader = YamlConfigurationLoader.builder().path(sitesFile).build(); + var sites = loader.load(); + sites.node("VoteSites", "ExampleVoteSite", "ForceOffline").set(true); + sites.node("VoteSites", "ExampleVoteSite", "GiveOffline").set(false); + loader.save(sites); + var originals = new java.util.HashMap(); + for (String name : List.of("Config.yml", "VoteSites.yml", "SpecialRewards.yml")) { + originals.put(name, Files.readString(directory.resolve(name))); + } + for (int restart = 0; restart < 2; restart++) { + try (NeoForgeRuntime runtime = NeoForgeRuntimeAccess.start(directory)) { + var site = runtime.voteConfiguration().voteSites().stream() + .filter(value -> value.key().equals("ExampleVoteSite")).findFirst().orElseThrow(); + assertTrue(site.giveOfflineRewards(), "Explicit canonical key takes precedence over legacy alias"); + for (var entry : originals.entrySet()) { + assertEquals(entry.getValue(), Files.readString(directory.resolve(entry.getKey()))); + } + } + } + } + + @Test + void omittedOfflineKeysDefaultFalseAndLegacyAliasMatchesBukkitPrecedence() throws Exception { + String[] options = { "", " GiveOffline: false\n", " GiveOffline: true\n", + " GiveOffline: true\n ForceOffline: false\n", + " GiveOffline: false\n ForceOffline: true\n" }; + boolean[] expected = { false, false, true, false, true }; + for (int i = 0; i < options.length; i++) { + Path installation = directory.resolve("case" + i); + Files.createDirectories(installation); + String yaml = "VoteSites:\n ExampleVoteSite:\n Enabled: true\n ServiceSite: PlanetMinecraft.com\n" + + options[i]; + Files.writeString(installation.resolve("VoteSites.yml"), yaml); + try (NeoForgeRuntime runtime = NeoForgeRuntimeAccess.start(installation)) { + var site = runtime.voteConfiguration().resolveEnabledSite("PlanetMinecraft.com").orElseThrow(); + assertEquals(expected[i], site.giveOfflineRewards()); + assertEquals(expected[i], runtime.voteConfiguration().policyFor(site).giveOfflineRewards()); + } + assertEquals(yaml, Files.readString(installation.resolve("VoteSites.yml"))); + } + } +} diff --git a/VotingPlugin/src/test/java/com/bencodez/votingplugin/tests/packaging/PackagedArtifactTest.java b/VotingPlugin/src/test/java/com/bencodez/votingplugin/tests/packaging/PackagedArtifactTest.java index 4c83036010..f0eb656a37 100644 --- a/VotingPlugin/src/test/java/com/bencodez/votingplugin/tests/packaging/PackagedArtifactTest.java +++ b/VotingPlugin/src/test/java/com/bencodez/votingplugin/tests/packaging/PackagedArtifactTest.java @@ -33,6 +33,9 @@ void containsOneRelocatedRuntimeWithoutUnusedHttpCrypto() throws Exception { assertNotNull(artifact.getEntry("com/bencodez/votingplugin/VotingPluginMain.class")); assertNotNull(artifact.getEntry("plugin.yml")); assertNotNull(artifact.getEntry("META-INF/neoforge.mods.toml")); + for (String name : java.util.List.of("Config.yml", "VoteSites.yml", "SpecialRewards.yml")) { + assertNotNull(artifact.getEntry(name)); + } String modMetadata = new String(artifact.getInputStream( artifact.getEntry("META-INF/neoforge.mods.toml")).readAllBytes(), StandardCharsets.UTF_8); assertTrue(modMetadata.contains("modId=\"votingplugin\"")); diff --git a/docs/neoforge-bootstrap.md b/docs/neoforge-bootstrap.md index 15a2ec9e8e..052772d905 100644 --- a/docs/neoforge-bootstrap.md +++ b/docs/neoforge-bootstrap.md @@ -2,7 +2,7 @@ The single `VotingPlugin.jar` contains an experimental NeoForge 21.1 entry point for Minecraft 1.21.1. Native vote ingress remains disabled. Bukkit and proxy behavior remains on its existing paths. -On server start, the entry point creates `config/votingplugin/`, installs the packaged `Config.yml`, `VoteSites.yml`, and `SpecialRewards.yml` only when missing, reads them, and opens the existing AdvancedCore SQLite user backend in `VotingPlugin.db`. The bootstrap currently accepts `DataStorage: SQLITE` only. Its separate `VotingPlugin_NeoForgeUsers` table stores the player name, all-time/monthly/daily/weekly totals, points, and per-site last-vote timestamps needed by the shared accounting step. Existing UUID-only bootstrap tables are extended in place. The accounting adapter is a storage foundation and is not wired to live vote ingress. The runtime closes the backend and clears queued tasks and online player identities on server stop. +On server start, the entry point creates `config/votingplugin/`, installs `Config.yml`, `VoteSites.yml`, and `SpecialRewards.yml` from the shared Bukkit templates only when each file is missing, reads them, and opens the existing AdvancedCore SQLite user backend in `VotingPlugin.db`. The bootstrap currently accepts `DataStorage: SQLITE` only. Its separate `VotingPlugin_NeoForgeUsers` table stores the player name, all-time/monthly/daily/weekly totals, points, and per-site last-vote timestamps needed by the shared accounting step. Existing UUID-only bootstrap tables are extended in place. The accounting adapter is a storage foundation and is not wired to live vote ingress. The runtime closes the backend and clears queued tasks and online player identities on server stop. The NeoForge bridge tracks login/logout identity and runs submitted bootstrap tasks on server ticks. Player identity access uses reflection because NeoForge's published universal Maven JAR does not include Minecraft classes on Maven's compile path; these method names were checked against the installed 1.21.1 server JAR. @@ -10,6 +10,14 @@ An internal synthetic vote boundary now supports identity and enabled-site resol Native Votifier ingress remains disabled. VotifierPlus's hardened packet handling is currently packaged with its Bukkit, BungeeCord, and Velocity plugin runtime rather than as a platform-neutral API that this single VotingPlugin artifact can reuse. Depending on that full plugin would pull unrelated platform code into VotingPlugin, while copying its security-sensitive protocol implementation would create a second implementation. +## First-run configuration + +A new NeoForge installation uses the same file names, keys and shared templates as Bukkit. Supported settings keep their shared values and parsing; only unsupported fresh-install behavior and example reward trees are adjusted. Bukkit and proxy defaults are unchanged. The starter disables inventory closing, streaks, local vote broadcasts, cooldown events, monthly vote limits, offline vote limits and special reward trees. The shared example sites remain disabled and contain one plain console command instead of a multi-action reward tree. Site-level `ForceOffline` and its legacy `GiveOffline` alias are explicitly `false`; an offline console reward remains pending until the player joins. Configure its `ServiceSite` to match the vote service, replace the example URL, and enable the site. Configure authenticated proxy delivery as described below; installation alone does not enable a listener. + +Keep `DataStorage: SQLITE`. Use at most one plain `Commands` action or one plain `Messages.Player` action per vote across the site and `EverySiteReward`. A player message always waits for the player to be online. As on Bukkit, site-level `ForceOffline` takes precedence over legacy `GiveOffline`, and omitting both defaults to `false`. An explicit administrator opt-in is preserved. These site settings are distinct from similarly named reward-level settings; no reward-level execution support is added here. Bukkit formatting, item rewards and multiple actions remain unsupported. Configuration edits take effect after a server restart. + +Upgrades preserve every existing file, including comments and explicitly enabled settings. No rewards, pending votes or completion receipts are removed. Startup checks unsupported global replay settings and names the first global blocker, explaining that affected votes remain pending. This is not a complete configuration check: site-specific settings such as `WaitUntilVoteDelay` and unsupported reward actions are checked during replay and may block a retained vote without a startup warning. Review that setting and the reward limitations before changing it; disabling unsupported settings does not retry quarantined uncertain actions. Monthly awards are a separate unsupported feature: fresh files set `EnableMonthlyAwards: false`, but an existing `true` value is preserved and does not itself block replay or produce this warning. NeoForge does not issue monthly awards even when that existing setting is enabled. No native player or administrator commands are added by this configuration change. + ## Proxy vote delivery NeoForge can receive real votes from ordinary VotingPlugin installations on BungeeCord and Velocity through the existing encrypted `SOCKETS` transport. Both proxy platforms use the same VotingPlugin proxy runtime and wire protocol. The backend durably retains a COMPLETE vote before sending its delivery acknowledgement; a duplicate stable vote ID is acknowledged idempotently and cannot create another pending occurrence or repeat an already completed vote. @@ -64,7 +72,7 @@ Current transport support is: Only the reward subset described below can complete. Votes requiring unsupported reward or post-vote semantics remain durable and observable instead of being acknowledged as fully processed and lost. -Deferred votes can now be claimed in memory and completed through one SQLite transaction that writes a completion receipt and removes the pending payload. An abandoned claim leaves the durable payload pending, while a committed transaction leaves no pending-without-receipt window. Completion receipts are bounded to 4,096 per player and 262,144 across the runtime. They are not evicted by age because no native ingress acknowledgement can yet prove that a sender has stopped retrying. If either receipt limit is full, completion stops and keeps the original pending payload. A later ingress handshake may add safe receipt release with a bounded post-release tombstone, following the existing proxy delivery pattern. A bounded replay worker now processes at most 16 retained votes per scan. It supports one existing inline `Messages.Player` or `Commands` action per vote. Player messages and console commands run on the NeoForge server tick lane; SQLite scans and completion writes remain on the replay worker. The worker validates the entire reward tree before running any action. A vote stays pending with an observable blocked or waiting result if it requires multiple or unsupported reward actions, `AnySiteRewards`, an offline player message, vote broadcasts, vote party, streaks, milestones, monthly vote limiting, cooldown events, `CloseInventoryOnVote`, or `WaitUntilVoteDelay` processing. An ambiguous external action or completion-write result is durably quarantined and remains fenced across restart for operator reconciliation. Legacy retained rows without an accepted accounting snapshot also remain blocked instead of being recalculated with newer configuration. The packaged defaults enable some unsupported features, so administrators must explicitly disable them before retained votes can complete. Configuration changes currently take effect after a server restart. +Deferred votes can now be claimed in memory and completed through one SQLite transaction that writes a completion receipt and removes the pending payload. An abandoned claim leaves the durable payload pending, while a committed transaction leaves no pending-without-receipt window. Completion receipts are bounded to 4,096 per player and 262,144 across the runtime. They are not evicted by age because no native ingress acknowledgement can yet prove that a sender has stopped retrying. If either receipt limit is full, completion stops and keeps the original pending payload. A later ingress handshake may add safe receipt release with a bounded post-release tombstone, following the existing proxy delivery pattern. A bounded replay worker now processes at most 16 retained votes per scan. It supports one existing inline `Messages.Player` or `Commands` action per vote. Player messages and console commands run on the NeoForge server tick lane; SQLite scans and completion writes remain on the replay worker. The worker validates the entire reward tree before running any action. A vote stays pending with an observable blocked or waiting result if it requires multiple or unsupported reward actions, `AnySiteRewards`, an offline player message, vote broadcasts, vote party, streaks, milestones, monthly vote limiting, cooldown events, `CloseInventoryOnVote`, or `WaitUntilVoteDelay` processing. An ambiguous external action or completion-write result is durably quarantined and remains fenced across restart for operator reconciliation. Legacy retained rows without an accepted accounting snapshot also remain blocked instead of being recalculated with newer configuration. Fresh NeoForge files disable unsupported global behavior and special rewards. Existing files are never rewritten; their configured unsupported behavior continues to keep affected votes pending. Configuration changes currently take effect after a server restart. Before a supported external action is dispatched, replay durably fences the pending occurrence. After the action succeeds, accounting, the completion receipt, and pending removal commit in one SQLite transaction. A completed vote ID remains fenced across restart and cannot rerun accounting. If the JVM or completion write fails after the pre-dispatch fence, automatic replay stays stopped for operator reconciliation, so it cannot blindly repeat a command or message. A crash between writing that fence and executing the action is indistinguishable from a crash immediately after execution and can therefore leave an action omitted unless an operator retries it; a manual retry after an uncertain outcome can instead duplicate it. The current reward APIs cannot make a Minecraft command and SQLite commit atomic, so this version does not claim exactly-once external side effects.