From ff79654444672428ef34eae5c30d9cf67021d4dc Mon Sep 17 00:00:00 2001 From: Ronan Date: Wed, 4 Nov 2026 15:32:36 +0100 Subject: [PATCH] removed same user restriction --- docs/web-editor.md | 10 +++---- .../references/web/editor/EditorBridge.java | 29 +++++++++++-------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/docs/web-editor.md b/docs/web-editor.md index a9b3ca6..0055952 100644 --- a/docs/web-editor.md +++ b/docs/web-editor.md @@ -8,7 +8,7 @@ 2. Install the matching plugin build and restart Minecraft. Normal builds target `https://minecentral.net`; staging builds target the test website below. There is no website setting or `editor.yml` resource. 3. As a player, run `/rtp editor` and open the private link. The website displays the target label and `config.yml` as read-only context. 4. Edit and click **Save and get sync command**. This stores an immutable version; nothing is applied to Minecraft yet. -5. Run `/betterrtp editorsync ` as the same player on the same server. The plugin downloads that version over HTTPS, checks permission again, validates it, backs up the current file, atomically replaces it, and reloads BetterRTP. +5. Run `/betterrtp editorsync ` as a player with editor permission on the same server. The plugin downloads that version over HTTPS, checks permission again, validates it, backs up the current file, atomically replaces it, and reloads BetterRTP. There are no inbound Minecraft connections and no automatic polling. Allow outbound HTTPS. TLS certificate validation remains enabled and redirects are refused. Never publish editor links or command tokens; Minecraft command logging plugins may capture sync commands. @@ -18,11 +18,11 @@ There are no inbound Minecraft connections and no automatic polling. Allow outbo - Expiring an editor stops new saves; existing save tokens retain their own deadlines. To replace the current session before its final tokens expire, its creator must use `/rtp editor cancel` first. Cancelling revokes all remaining tokens. - Session expiry preserves the browser text for download. The personal config library and Discord login are not implemented yet. - Tokens are consumed atomically when downloaded. If a response is lost, local validation fails, or the player disconnects before application, save again for a fresh token. The plugin does not retry writes. Minecraft reports the apply outcome; the website does not report generated commands as applied. -- The creator must still be online and hold `betterrtp.editor` at apply time. Restarting/disabling the plugin discards its in-memory session, so old tokens cannot be applied by that plugin instance after restart. +- The player running editorsync must still be online and hold `betterrtp.editor` at apply time. Restarting/disabling the plugin discards its in-memory session, so old tokens cannot be applied by that plugin instance after restart. - Invalid content is rejected before any file change. Validation preserves the existing setting structure and types, checks selected numeric ranges, blocks Language-File changes and unsafe Bukkit YAML constructs, and limits config size to 128 KiB. This is conservative validation, not a complete schema for every integration. - Intervening edits to the Minecraft config do not block syncing: applying a saved version can overwrite those edits. A backup of the current file is created in `plugins/BetterRTP/editor-backups/`; rotate backups as appropriate. - If writing succeeds but reload fails, the new file stays in place and a reload error is reported. There is no automatic rollback. Check Minecraft's console and reload after resolving the failure. -- The website trusts the plugin-supplied target label for display only. The private plugin-session capability and player UUID bind redemption to the original session; browser target fields cannot redirect a write. +- The website trusts the plugin-supplied target label for display only. The private plugin-session capability bind redemption to the original session; browser target fields cannot redirect a write. Protocol 1 automatic-apply clients are intentionally incompatible with protocol 2. The website migration closes existing protocol 1 sessions. Update website/database and plugin together for testing. @@ -36,6 +36,6 @@ The address is internal JAR build metadata, not a server configuration or enviro ## Validation -Run `mvn -f tests/editor/pom.xml test` for configuration validation/file-write tests and `mvn package -Pstaging` for the full staging plugin. The web repository's `pnpm test` exercises version isolation, atomic single-use redemption, creator/server binding, independent expiry, cancellation, validation, and limits against embedded PostgreSQL. +Run `mvn -f tests/editor/pom.xml test` for configuration validation/file-write tests and `mvn package -Pstaging` for the full staging plugin. The web repository's `pnpm test` exercises version isolation, atomic single-use redemption, server binding, independent expiry, cancellation, validation, and limits against embedded PostgreSQL. -Before production use, test the complete flow on the staging Minecraft server, including wrong-player denial, permission loss, disconnect, expiry, repeated saves, intervening local changes, reload errors, restart, and Folia scheduling if applicable. Local automated checks do not substitute for this staging run. +Before production use, test the complete flow on the staging Minecraft server, including permission denial, permission loss, disconnect, expiry, repeated saves, intervening local changes, reload errors, restart, and Folia scheduling if applicable. Local automated checks do not substitute for this staging run. diff --git a/src/main/java/me/SuperRonanCraft/BetterRTP/references/web/editor/EditorBridge.java b/src/main/java/me/SuperRonanCraft/BetterRTP/references/web/editor/EditorBridge.java index 3d7b661..357d28e 100644 --- a/src/main/java/me/SuperRonanCraft/BetterRTP/references/web/editor/EditorBridge.java +++ b/src/main/java/me/SuperRonanCraft/BetterRTP/references/web/editor/EditorBridge.java @@ -128,31 +128,37 @@ public final class EditorBridge { CommandSender sender = recipient(session); if (sender != null) sender.sendMessage("§eEditor: " + text); }); } + private void message(UUID playerId, String text) { + if (!stopped) sync.accept(() -> { + Player player = Bukkit.getPlayer(playerId); + if (player != null) player.sendMessage("§eEditor: " + text); + }); + } public void redeem(CommandSender sender, String token) { if (!allowed.test(sender)) return; Session session = current; - if (!(sender instanceof Player) || session == null || !session.player.equals(((Player) sender).getUniqueId())) { - sender.sendMessage("§cOnly the player who created this server's editor session can sync it."); return; + if (!(sender instanceof Player) || session == null) { + sender.sendMessage("§cRun this command as a player on the server with an active editor session."); return; } if (!token.matches("[a-f0-9]{64}")) { sender.sendMessage("§cInvalid sync token. Copy the command from the editor."); return; } if (session.pluginToken == null || session.applying) { sender.sendMessage("§eAn editor request is already in progress."); return; } if (System.currentTimeMillis() >= session.expires + 15 * 60 * 1000) { sender.sendMessage("§cSession expired. Run /rtp editor again."); return; } + final UUID executor = ((Player) sender).getUniqueId(); session.applying = true; sender.sendMessage("§7Downloading your saved configuration…"); worker.execute(() -> { try { JsonObject response = request(session, "GET", "/api/editor/sync", null, token); - if (!session.player.toString().equals(response.get("playerId").getAsString()) || - !"config.yml".equals(response.get("configFile").getAsString())) throw new IOException("Invalid sync target."); + if (!"config.yml".equals(response.get("configFile").getAsString())) throw new IOException("Invalid sync target."); String edited = response.get("content").getAsString(); long expires = response.get("expiresAt").getAsLong(); EditorConfig.validate(session.original, edited); - sync.accept(() -> apply(session, edited, expires)); + sync.accept(() -> apply(session, edited, expires, executor)); } catch (Exception error) { session.applying = false; - message(session, "Sync failed: " + safeError(error) + " Save online again for a new command if this token was consumed."); + message(executor, "Sync failed: " + safeError(error) + " Save online again for a new command if this token was consumed."); } }); } @@ -164,12 +170,12 @@ public final class EditorBridge { return "Request or validation failed (" + error.getClass().getSimpleName() + ")."; } - private void apply(Session session, String edited, long tokenExpires) { + private void apply(Session session, String edited, long tokenExpires, UUID executor) { try { if (stopped || current != session) return; if (System.currentTimeMillis() >= tokenExpires) throw new IOException("Sync token expired before apply."); - CommandSender sender = recipient(session); - if (sender == null || !allowed.test(sender)) throw new IOException("The session creator must be online and still have betterrtp.editor."); + CommandSender sender = Bukkit.getPlayer(executor); + if (sender == null || !allowed.test(sender)) throw new IOException("The syncing player must be online and still have betterrtp.editor."); Path backup = EditorConfig.apply(configPath(), session.bytes, edited, () -> { reload.accept(sender); String loaded = loadedConfig.get(); @@ -179,10 +185,10 @@ public final class EditorBridge { }); sender.sendMessage("§aEditor changes applied and reloaded. Backup: " + backup.getFileName()); } catch (EditorConfig.ReloadFailure error) { - message(session, "Configuration saved, but reload failed. The new file remains in place. Check the console and reload BetterRTP."); + message(executor, "Configuration saved, but reload failed. The new file remains in place. Check the console and reload BetterRTP."); plugin.getLogger().warning("Editor config was written but reload failed; no rollback was performed."); } catch (Exception error) { - message(session, "Sync not applied: " + error.getMessage()); + message(executor, "Sync not applied: " + error.getMessage()); } finally { session.applying = false; } } @@ -197,7 +203,6 @@ public final class EditorBridge { connection.setRequestProperty("User-Agent", "BetterRTP-Editor/2"); if (syncToken != null) { connection.setRequestProperty("X-Editor-Sync-Token", syncToken); - connection.setRequestProperty("X-Editor-Player", session.player.toString()); } if (session.pluginToken != null) connection.setRequestProperty("Authorization", "Bearer " + session.pluginToken); try {