From 7e6b79a13e8e2ed5d3c5aafab07b5aa86e6a321c Mon Sep 17 00:00:00 2001 From: Crosis47 Date: Fri, 20 Nov 2026 09:21:44 -0500 Subject: [PATCH 1/2] Add Bedrock support for SmartPack 2.2.0 --- CHANGELOG.md | 15 + README.md | 124 ++-- pom.xml | 2 +- .../minecraft/smartpack/SmartPack.java | 41 +- .../smartpack/commands/PackCommand.java | 610 +++++++++++++----- .../smartpack/compatibility/BedrockForms.java | 101 +++ .../compatibility/BedrockPlayerDetector.java | 51 ++ src/main/resources/config.yml | 6 +- src/main/resources/plugin.yml | 7 +- .../compatibility/CompatibilityProbe.java | 114 +++- .../compatibility/ExclusionMenuProbe.java | 326 ++++++++++ .../compatibility/SmartPackerProbe.java | 332 ++++++++++ 12 files changed, 1489 insertions(+), 240 deletions(-) create mode 100644 src/main/java/crosis47/minecraft/smartpack/compatibility/BedrockForms.java create mode 100644 src/main/java/crosis47/minecraft/smartpack/compatibility/BedrockPlayerDetector.java create mode 100644 src/test/java/crosis47/minecraft/smartpack/compatibility/ExclusionMenuProbe.java create mode 100644 src/test/java/crosis47/minecraft/smartpack/compatibility/SmartPackerProbe.java diff --git a/CHANGELOG.md b/CHANGELOG.md index ff8ccc8..def714f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/). ## [Unreleased] +## [2.2.0] - 2026-11-20 + +### Added + +- Added optional Bedrock detection through Geyser-Spigot or Floodgate, including support for linked accounts. +- Bedrock players can hold a SmartPacker and use it on a block to open a native form for inventory packing, chest packing, and toggling auto mode. A chest-style menu provides the same actions if the form is unavailable. +- The Bedrock exclusion menu has an Edit Mode control for next-run skips and permanent exclusions. Both actions use the same click or tap. + +### Fixed + +- `/pack` autocomplete suggests subcommands based on the player's permissions and the server's settings on both Java and Bedrock. +- Exclusion chat messages report only the final changes when edits are applied. Canceled edits produce no item change messages. +- SmartPacker lore shows the carrying player's controls and auto-mode status. Auto-mode controls and hints are hidden when the server disables auto-pack or uses cooldown mode. +- Java players can now use shift-right-click on the SmartPacker to turn auto mode on or off. + --- ## [2.1.0] - 2026-10-27 diff --git a/README.md b/README.md index ce62555..cebeaca 100644 --- a/README.md +++ b/README.md @@ -23,22 +23,11 @@ SmartPack packs configured inventory materials into compact storage forms, such - Optional Smart Packer cooldown mode with live tooltip updates and a ready ActionBar notice. - Chest inventory packing through `/pack chest` or the Smart Packer item. - Per-player material exclusions through `/pack exclude`. +- Bedrock SmartPacker actions and exclusion controls for servers using Geyser. - Configurable crafting-table requirements. - Reversible-recipe warnings and optional strict disabling. - Inventory-full feedback with extra-slot estimates. -## Documentation - -The full setup and usage guide lives in the GitHub Wiki: - -- [SmartPack Wiki](https://github.com/Crosis47/SmartPack/wiki) -- [Installation](https://github.com/Crosis47/SmartPack/wiki/Installation) -- [Commands and Permissions](https://github.com/Crosis47/SmartPack/wiki/Commands-and-Permissions) -- [Configuration](https://github.com/Crosis47/SmartPack/wiki/Configuration) -- [Chest Packing](https://github.com/Crosis47/SmartPack/wiki/Chest-Packing) -- [Recipe Configuration](https://github.com/Crosis47/SmartPack/wiki/Recipe-Configuration) -- [Troubleshooting](https://github.com/Crosis47/SmartPack/wiki/Troubleshooting) - ## Requirements - Target compatibility: Paper 1.21.11 through 26.3 (one plugin JAR) @@ -51,12 +40,77 @@ minimum server API, not the newest supported server. SmartPack uses public Bukkit/Paper APIs and does not depend on Minecraft internals or remapping. Versions below 1.21.11 are not supported. -Validation for 2.1.0: compilation passed against the 1.21.11, 26.1.2, and 26.3 -APIs, with Java 21 bytecode verified. The identical 26.3-built JAR passed the -server compatibility probe on Paper 1.21.11 (build 131), 26.1.2 (build 53), and -26.3 (build 227), running locally with JDK 26. CI additionally targets the -Java 21/25 runtimes listed below. Player-driven interactions still need the -in-game checks described below. +## Install + +1. Download the SmartPack JAR from [GitHub Releases](https://github.com/Crosis47/SmartPack/releases) and put it in your Paper server's `plugins/` directory. +2. Start the server once to generate `plugins/SmartPack/config.yml`. +3. Run `/pack` to pack inventory materials, or `/pack exclude` to choose materials to skip. If `/pack` asks for a crafting table, stand near one and try again. +4. After changing the config, run `/pack reload` with `smartpack.reload` permission. + +### Bedrock setup + +SmartPack detects Bedrock sessions through Geyser-Spigot or Floodgate on the +Paper server, including linked accounts. If Geyser runs on a proxy, install +Floodgate on the Paper backend and configure +[Floodgate data forwarding](https://geysermc.org/wiki/floodgate/api/#using-the-api-on-backend-servers). + +## Commands + +| Command | What it does | Permission | +| --- | --- | --- | +| `/pack` | Pack configured inventory materials | `smartpack.use` | +| `/pack chest` | Pack the chest you are looking at in command mode | `smartpack.chest` | +| `/pack exclude` | Choose materials to skip | `smartpack.use` | +| `/pack auto` | Toggle automatic packing in command mode | `smartpack.auto` | +| `/pack reload` | Reload the config | `smartpack.reload` | + +All `/pack` subcommands require `smartpack.use`. Type `/pack` followed by a +space to see the subcommands available to you. On Bedrock, command suggestions +must be enabled in Geyser. + +### SmartPacker on Java and Bedrock + +With `activation.mode: SMART_PACKER_ITEM`, Java players right-click the +SmartPacker in their inventory to pack, or shift-right-click to toggle auto mode. +Right-clicking it while a chest is open packs that chest. + +Detected Bedrock players hold the SmartPacker and use it on a block to open its +action form. Select **Pack Inventory**, **Pack Chest**, or **Enable Auto** / +**Disable Auto**. For chest packing, use the held SmartPacker on the chest +before selecting **Pack Chest**. If the server cannot send a form, the +chest-style action menu provides the same actions. + +The Bedrock form and the item lore show whether auto mode is enabled for your +account. The form only offers the action if you have `smartpack.auto` and the +server allows auto-pack. In cooldown mode, the item shows the cooldown in place +of auto-mode instructions. + +### Exclusions on Java and Bedrock + +Open `/pack exclude`. Java players left-click materials for next-run skips and +right-click for permanent exclusions. Their menu has no mode button. + +On Bedrock, use **Edit Mode** in the bottom row to switch between **Next Run +Only** and **Permanent**, then click or tap the materials you want to change. +The menu opens in Next Run Only mode. Your selected mode stays active as you +change pages. + +Permanent exclusions survive server restarts. **Apply Changes** or closing the +menu keeps edits; **Cancel Changes** restores the settings from when it opened. +Item-change messages appear when edits are applied, reporting only the final +changes. Editing the menu is silent, and canceled edits are not announced. + +## Documentation + +The full setup and usage guide lives in the GitHub Wiki: + +- [SmartPack Wiki](https://github.com/Crosis47/SmartPack/wiki) +- [Installation](https://github.com/Crosis47/SmartPack/wiki/Installation) +- [Commands and Permissions](https://github.com/Crosis47/SmartPack/wiki/Commands-and-Permissions) +- [Configuration](https://github.com/Crosis47/SmartPack/wiki/Configuration) +- [Chest Packing](https://github.com/Crosis47/SmartPack/wiki/Chest-Packing) +- [Recipe Configuration](https://github.com/Crosis47/SmartPack/wiki/Recipe-Configuration) +- [Troubleshooting](https://github.com/Crosis47/SmartPack/wiki/Troubleshooting) ## Build @@ -92,6 +146,9 @@ The Paper Compatibility workflow also runs the same 26.3-built JAR on Paper server checks plugin startup, command registration/reload, SQLite exclusions and auto-pack preferences, tiered chest inventory packing, full-inventory safety, Smart Packer item metadata, recipe registration, and cooldown tooltip updates. +The probe also checks command visibility, exclusion editing, pagination, Apply +and Cancel, and the SmartPacker's auto-mode controls. Test actual Bedrock menus +and autocomplete in a Bedrock client connected through Geyser. The server probe lives under `src/test/` and is packaged separately for CI; it is never included in the production JAR. Console logs are retained as artifacts. @@ -102,13 +159,9 @@ not establish runtime compatibility; the server matrix must pass as well. ## Release -GitHub Actions publishes releases automatically when a push to `master` changes -the Maven project version in `pom.xml`. Update `pom.xml` and `CHANGELOG.md`, -commit the version bump, and push: - -```bash -git push origin master -``` +GitHub Actions publishes a release when a version bump in `pom.xml` reaches +`master`. Include the `pom.xml` change and matching `CHANGELOG.md` entry in the +release PR. The workflow builds with Java 25, verifies that the tag matches the Maven version, creates `v` after the build passes, and uploads @@ -117,8 +170,8 @@ version, creates `v` after the build passes, and uploads Releases can still be created by pushing a version tag directly: ```bash -git tag v2.1.0 -git push origin v2.1.0 +git tag v2.2.0 +git push origin v2.2.0 ``` The workflow can also be run manually from the Actions tab with either `X.Y.Z` @@ -138,23 +191,6 @@ Each build creates a historical prerelease tag named replacing older builds. These builds are for testing and do not replace the stable `master` version-bump release flow. -## Install - -1. Place the jar in your server's `plugins/` directory. -2. Start the server once to generate `plugins/SmartPack/config.yml`. -3. Adjust the config. -4. Run `/pack reload`. - -## Commands - -| Command | Description | -| --- | --- | -| `/pack` | Pack configured materials | -| `/pack chest` | Pack the chest you are looking at | -| `/pack exclude` | Choose materials to skip | -| `/pack auto` | Toggle automatic packing | -| `/pack reload` | Reload the config | - ## License SmartPack is licensed under the GNU General Public License v3.0. See [License.md](License.md). diff --git a/pom.xml b/pom.xml index 7c235f5..eddc2e0 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ crosis47.minecraft smartpack - 2.1.0 + 2.2.0 jar SmartPack diff --git a/src/main/java/crosis47/minecraft/smartpack/SmartPack.java b/src/main/java/crosis47/minecraft/smartpack/SmartPack.java index 9b12b91..4239309 100644 --- a/src/main/java/crosis47/minecraft/smartpack/SmartPack.java +++ b/src/main/java/crosis47/minecraft/smartpack/SmartPack.java @@ -1,6 +1,7 @@ package crosis47.minecraft.smartpack; import crosis47.minecraft.smartpack.commands.PackCommand; +import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents; import crosis47.minecraft.smartpack.storage.PlayerExclusionStore; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; @@ -12,7 +13,6 @@ import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.NamespacedKey; -import org.bukkit.command.PluginCommand; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; @@ -40,7 +40,6 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; -import java.util.Objects; import java.util.Set; import java.util.UUID; import java.util.Map; @@ -83,14 +82,10 @@ public void onEnable() { return; } - PluginCommand packCommand = Objects.requireNonNull( - getCommand("pack"), - "Command 'pack' is missing from plugin.yml" - ); - PackCommand commandHandler = new PackCommand(this); - packCommand.setExecutor(commandHandler); - packCommand.setTabCompleter(commandHandler); + getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS, event -> + event.registrar().register(commandHandler.createCommand(), + "Pack configured materials into compact storage forms")); getServer().getPluginManager().registerEvents(commandHandler, this); refreshSmartPackerRecipe(); @@ -218,6 +213,7 @@ public void reloadPluginConfig() { reloadPersistentAutoPackPreferencesFromStore(); refreshSmartPackerRecipe(); cleanupSmartPackerItemsForOnlinePlayers(); + Bukkit.getOnlinePlayers().forEach(Player::updateCommands); } public boolean isPackInputDisabled(final Material material) { @@ -514,6 +510,19 @@ public ItemStack createSmartPackerItem() { } public boolean updateSmartPackerItemLore(final ItemStack item, final long remainingCooldownTicks) { + return updateSmartPackerItemLore(item, remainingCooldownTicks, false); + } + + public boolean updateSmartPackerItemLore( + final ItemStack item, final long remainingCooldownTicks, final boolean bedrock + ) { + return updateSmartPackerItemLore(item, remainingCooldownTicks, bedrock, + getConfig().getBoolean("auto_pack.default_enabled", false)); + } + + public boolean updateSmartPackerItemLore( + final ItemStack item, final long remainingCooldownTicks, final boolean bedrock, final boolean autoPackEnabled + ) { if (item == null || item.getType() != Material.CRAFTING_TABLE) { return false; } @@ -527,15 +536,21 @@ public boolean updateSmartPackerItemLore(final ItemStack item, final long remain .decoration(TextDecoration.ITALIC, false)); List lore = new ArrayList<>(); - lore.add(Component.text("Right-click to pack now.", NamedTextColor.GRAY) + lore.add(Component.text(bedrock ? "Hold and use on a block to open actions." : "Right-click to pack now.", NamedTextColor.GRAY) .decoration(TextDecoration.ITALIC, false)); - lore.add(Component.text("Open a chest to pack that chest instead.", NamedTextColor.GRAY) + lore.add(Component.text(bedrock ? "For chest packing, use on the chest." : "Open a chest to pack that chest instead.", NamedTextColor.GRAY) .decoration(TextDecoration.ITALIC, false)); if (isSmartPackerCooldownModeEnabled()) { lore.add(buildSmartPackerCooldownLore(remainingCooldownTicks)); - } else { - lore.add(Component.text("Auto mode: shift-right-click to enable.", NamedTextColor.GRAY) + } else if (getConfig().getBoolean("auto_pack.enabled", false)) { + lore.add(Component.text("Auto mode: ", NamedTextColor.GRAY) + .append(Component.text(autoPackEnabled ? "Enabled" : "Disabled", + autoPackEnabled ? NamedTextColor.GREEN : NamedTextColor.RED)) + .decoration(TextDecoration.ITALIC, false)); + lore.add(Component.text(bedrock + ? "Open SmartPacker actions to change auto mode." + : "Auto mode: shift-right-click to toggle.", NamedTextColor.GRAY) .decoration(TextDecoration.ITALIC, false)); lore.add(Component.text("Auto mode packs after item pickups.", NamedTextColor.DARK_GRAY) .decoration(TextDecoration.ITALIC, false)); diff --git a/src/main/java/crosis47/minecraft/smartpack/commands/PackCommand.java b/src/main/java/crosis47/minecraft/smartpack/commands/PackCommand.java index d96565f..dea890f 100644 --- a/src/main/java/crosis47/minecraft/smartpack/commands/PackCommand.java +++ b/src/main/java/crosis47/minecraft/smartpack/commands/PackCommand.java @@ -1,7 +1,13 @@ package crosis47.minecraft.smartpack.commands; import crosis47.minecraft.smartpack.SmartPack; +import crosis47.minecraft.smartpack.compatibility.BedrockForms; +import crosis47.minecraft.smartpack.compatibility.BedrockPlayerDetector; import crosis47.minecraft.smartpack.requirements.CraftingTableMode; +import com.mojang.brigadier.Command; +import com.mojang.brigadier.tree.LiteralCommandNode; +import io.papermc.paper.command.brigadier.CommandSourceStack; +import io.papermc.paper.command.brigadier.Commands; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.TextDecoration; @@ -18,29 +24,29 @@ import org.bukkit.block.Block; import org.bukkit.block.Chest; import org.bukkit.block.DoubleChest; -import org.bukkit.command.Command; import org.bukkit.command.CommandSender; -import org.bukkit.command.TabExecutor; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Item; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.EntityPickupItemEvent; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.inventory.InventoryDragEvent; import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.util.RayTraceResult; -import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Collections; @@ -56,20 +62,30 @@ import java.util.Set; import java.util.StringJoiner; import java.util.UUID; +import java.util.function.Predicate; +import java.util.function.Supplier; -public final class PackCommand implements TabExecutor, Listener { +public final class PackCommand implements Listener { private static final int EXCLUDE_MENU_SIZE = 54; private static final int EXCLUDE_MENU_CONTENT_SIZE = 45; private static final int EXCLUDE_MENU_PREVIOUS_SLOT = 45; + private static final int EXCLUDE_MENU_MODE_SLOT = 47; private static final int EXCLUDE_MENU_INFO_SLOT = 49; private static final int EXCLUDE_MENU_NEXT_SLOT = 50; private static final int EXCLUDE_MENU_APPLY_SLOT = 52; private static final int EXCLUDE_MENU_CANCEL_SLOT = 53; + private static final int SMART_PACKER_INVENTORY_SLOT = 11; + private static final int SMART_PACKER_CHEST_SLOT = 13; + private static final int SMART_PACKER_AUTO_SLOT = 15; + private static final int SMART_PACKER_CLOSE_SLOT = 22; private static final long PACK_PASS_DELAY_TICKS = 1L; private static final int PACK_SETTLE_TICKS = 10; private final SmartPack plugin; + private final Predicate isBedrockPlayer; + private final BedrockForms bedrockForms; + private final Map openSmartPackerForms = new HashMap<>(); private final Map excludeMenuSessions = new HashMap<>(); private final Set packInProgress = new HashSet<>(); private final Set pendingAutoPack = new HashSet<>(); @@ -78,7 +94,13 @@ public final class PackCommand implements TabExecutor, Listener { private final Map smartPackerCooldownUntilTicks = new HashMap<>(); public PackCommand(final SmartPack plugin) { + this(plugin, new BedrockPlayerDetector(plugin)::isBedrockPlayer); + } + + PackCommand(final SmartPack plugin, final Predicate isBedrockPlayer) { this.plugin = plugin; + this.isBedrockPlayer = isBedrockPlayer; + this.bedrockForms = new BedrockForms(plugin); Bukkit.getScheduler().runTaskTimer( plugin, this::refreshSmartPackerCooldownTooltips, @@ -87,13 +109,31 @@ public PackCommand(final SmartPack plugin) { ); } - @Override - public boolean onCommand( - @NotNull CommandSender sender, - @NotNull Command command, - @NotNull String label, - @NotNull String[] args - ) { + public LiteralCommandNode createCommand() { + return Commands.literal("pack") + .requires(source -> source.getSender().hasPermission("smartpack.use")) + .executes(context -> runCommand(context.getSource().getSender())) + .then(Commands.literal("exclude") + .executes(context -> runCommand(context.getSource().getSender(), "exclude"))) + .then(Commands.literal("chest") + .requires(source -> !plugin.isSmartPackerItemModeEnabled() && isChestPackCommandEnabled() + && source.getSender().hasPermission("smartpack.chest")) + .executes(context -> runCommand(context.getSource().getSender(), "chest"))) + .then(Commands.literal("auto") + .requires(source -> !plugin.isSmartPackerItemModeEnabled() && isAutoPackAvailableInCurrentMode() + && hasAutoPackPermission(source.getSender())) + .executes(context -> runCommand(context.getSource().getSender(), "auto"))) + .then(Commands.literal("reload") + .requires(source -> source.getSender().hasPermission("smartpack.reload")) + .executes(context -> runCommand(context.getSource().getSender(), "reload"))) + .build(); + } + + private int runCommand(final CommandSender sender, final String... args) { + return executeCommand(sender, args) ? Command.SINGLE_SUCCESS : 0; + } + + private boolean executeCommand(final CommandSender sender, final String[] args) { if (args.length > 0) { if (args[0].equalsIgnoreCase("reload")) { if (!sender.hasPermission("smartpack.reload")) { @@ -173,8 +213,11 @@ public boolean onCommand( if (plugin.isSmartPackerItemModeEnabled()) { if (!plugin.isSmartPackerCommandAllowed()) { player.sendMessage(getMessage( - "message.info.use_smart_packer_item", - "Use a Smart Packer from your inventory to pack materials." + isBedrockPlayer.test(player.getUniqueId()) + ? "message.info.use_smart_packer_item_bedrock" : "message.info.use_smart_packer_item", + isBedrockPlayer.test(player.getUniqueId()) + ? "Hold a SmartPacker and use it on a block to open its actions." + : "Use a Smart Packer from your inventory to pack materials." )); return true; } @@ -199,8 +242,11 @@ public boolean onCommand( private void handleChestPackCommand(final Player player) { if (plugin.isSmartPackerItemModeEnabled()) { player.sendMessage(getMessage( - "message.info.chest_pack_command_mode_required", - "Use the Smart Packer item while a chest is open to pack chest inventories." + isBedrockPlayer.test(player.getUniqueId()) + ? "message.info.chest_pack_command_mode_required_bedrock" : "message.info.chest_pack_command_mode_required", + isBedrockPlayer.test(player.getUniqueId()) + ? "Use a held SmartPacker on the chest, then select Pack Chest." + : "Use the Smart Packer item while a chest is open to pack chest inventories." )); return; } @@ -232,6 +278,10 @@ private void handleChestPackCommand(final Player player) { @EventHandler(ignoreCancelled = true) public void onInventoryClick(final InventoryClickEvent event) { + if (event.getView().getTopInventory().getHolder() instanceof SmartPackerMenuHolder holder) { + handleSmartPackerMenuClick(event, holder); + return; + } if (event.getView().getTopInventory().getHolder() instanceof ExcludeMenuHolder holder) { handleExcludeMenuClick(event, holder); return; @@ -245,6 +295,11 @@ public void onInventoryClick(final InventoryClickEvent event) { return; } + // Bedrock inventory clicks must remain available for moving the item. + if (isBedrockPlayer.test(player.getUniqueId())) { + return; + } + if (!(event.getClickedInventory() instanceof PlayerInventory)) { return; } @@ -259,49 +314,201 @@ public void onInventoryClick(final InventoryClickEvent event) { event.setCancelled(true); - boolean enableAutoPack = event.getClick().isShiftClick(); + boolean toggleAutoPack = event.getClick().isShiftClick(); Bukkit.getScheduler().runTask(plugin, () -> { if (!player.isOnline()) { return; } + Inventory chestInventory = toggleAutoPack ? null : getOpenChestInventory(player); + useSmartPacker(player, toggleAutoPack, + isChestPackSmartPackerItemEnabled() ? chestInventory : null); + }); + } - if (enableAutoPack) { - enableAutoPackFromSmartPackerItem(player); - return; + @EventHandler + public void onPlayerInteract(final PlayerInteractEvent event) { + if (!plugin.isSmartPackerItemModeEnabled() + || event.getHand() != EquipmentSlot.HAND + || (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.RIGHT_CLICK_AIR) + || !plugin.isSmartPackerItem(event.getItem()) + || !isBedrockPlayer.test(event.getPlayer().getUniqueId())) { + return; + } + // Air interactions can be pre-cancelled by vanilla. Never place the SmartPacker + // or activate the clicked block while opening its action menu. + event.setCancelled(true); + Player player = event.getPlayer(); + Bukkit.getScheduler().runTask(plugin, () -> { + if (canUseBedrockSmartPacker(player) + && !openSmartPackerForms.containsKey(player.getUniqueId()) + && !(player.getOpenInventory().getTopInventory().getHolder() instanceof SmartPackerMenuHolder)) { + if (!openSmartPackerForm(player)) { + openSmartPackerMenu(player); + } } + }); + } - if (!player.hasPermission("smartpack.use")) { - player.sendMessage(getMessage( - "message.error.no_permission", - "You do not have permission to use this command." - )); - return; - } + private boolean canUseBedrockSmartPacker(final Player player) { + return player.isOnline() && plugin.isSmartPackerItemModeEnabled() + && isBedrockPlayer.test(player.getUniqueId()) + && plugin.hasSmartPackerItem(player.getInventory().getStorageContents()); + } - Inventory chestInventory = getOpenChestInventory(player); - if (chestInventory != null && isChestPackSmartPackerItemEnabled()) { - if (!player.hasPermission("smartpack.chest")) { - player.sendMessage(getMessage( - "message.error.no_permission", - "You do not have permission to use this command." - )); - return; - } + private SmartPackerForm createSmartPackerForm(final Player player) { + UUID playerId = player.getUniqueId(); + boolean showAuto = isAutoPackAvailableInCurrentMode() && hasAutoPackPermission(player); + boolean autoEnabled = showAuto && plugin.isAutoPackEnabledForPlayer(playerId); + String content = "Choose what to pack."; + Map buttons = new LinkedHashMap<>(); + buttons.put(SMART_PACKER_INVENTORY_SLOT, new BedrockForms.Button("Pack Inventory", "textures/items/bundle")); + buttons.put(SMART_PACKER_CHEST_SLOT, new BedrockForms.Button("Pack Chest", "textures/blocks/chest_front")); + if (showAuto) { + content = "Auto mode: " + (autoEnabled ? "Enabled" : "Disabled") + "\n" + content; + buttons.put(SMART_PACKER_AUTO_SLOT, autoEnabled + ? new BedrockForms.Button("Disable Auto", "textures/items/dye_powder_red") + : new BedrockForms.Button("Enable Auto", "textures/items/dye_powder_lime")); + } + buttons.put(SMART_PACKER_CLOSE_SLOT, new BedrockForms.Button("Close", "textures/ui/cancel")); + return new SmartPackerForm(content, List.copyOf(buttons.keySet()), List.copyOf(buttons.values()), autoEnabled); + } + + private boolean openSmartPackerForm(final Player player) { + UUID playerId = player.getUniqueId(); + SmartPackerForm form = createSmartPackerForm(player); + Block originalTarget = getLookedAtBlock(player); + // Form callbacks can arrive off the server thread. Only the current form can act. + Object session = new Object(); + openSmartPackerForms.put(playerId, session); + boolean sent = bedrockForms.sendSimpleForm(playerId, "SmartPacker", form.content(), form.buttons(), + selection -> { + if (!plugin.isEnabled()) { + return; + } + Bukkit.getScheduler().runTask(plugin, () -> { + if (!openSmartPackerForms.remove(playerId, session) || !canUseBedrockSmartPacker(player) + || selection < 0 || selection >= form.actions().size()) { + return; + } + int action = form.actions().get(selection); + if (action == SMART_PACKER_AUTO_SLOT) { + setSmartPackerAutoMode(player, !form.autoEnabled()); + return; + } + runSmartPackerAction(player, action, () -> { + Block target = getLookedAtBlock(player); + return Objects.equals(originalTarget, target) ? getChestBlockInventory(target) : null; + }); + }); + }, () -> { + if (plugin.isEnabled()) { + Bukkit.getScheduler().runTask(plugin, () -> openSmartPackerForms.remove(playerId, session)); + } + }); + if (!sent) { + openSmartPackerForms.remove(playerId, session); + } + return sent; + } - if (!tryStartSmartPackerCooldown(player, true)) { - return; - } + private void openSmartPackerMenu(final Player player) { + SmartPackerMenuHolder holder = new SmartPackerMenuHolder(player.getUniqueId()); + Inventory inventory = Bukkit.createInventory(holder, 27, Component.text("SmartPacker", NamedTextColor.DARK_GREEN)); + holder.inventory = inventory; + for (int slot = 0; slot < inventory.getSize(); slot++) { + inventory.setItem(slot, createMenuFillerItem()); + } + inventory.setItem(SMART_PACKER_INVENTORY_SLOT, + createMenuControlItem(Material.CRAFTING_TABLE, "Pack Inventory", NamedTextColor.GREEN)); + inventory.setItem(SMART_PACKER_CHEST_SLOT, createMenuControlItem(Material.CHEST, + "Pack Chest", NamedTextColor.GREEN, List.of( + Component.text("Look at a chest before opening this menu.", NamedTextColor.GRAY) + .decoration(TextDecoration.ITALIC, false)))); + if (isAutoPackAvailableInCurrentMode()) { + boolean autoEnabled = plugin.isAutoPackEnabledForPlayer(player.getUniqueId()); + inventory.setItem(SMART_PACKER_AUTO_SLOT, createMenuControlItem( + autoEnabled ? Material.LIME_DYE : Material.GRAY_DYE, + autoEnabled ? "Disable Auto" : "Enable Auto", + autoEnabled ? NamedTextColor.RED : NamedTextColor.GREEN, + List.of( + Component.text("Auto mode: " + (autoEnabled ? "Enabled" : "Disabled"), + autoEnabled ? NamedTextColor.GREEN : NamedTextColor.RED) + .decoration(TextDecoration.ITALIC, false), + Component.text("Click to " + (autoEnabled ? "disable" : "enable") + " auto-pack.", NamedTextColor.GRAY) + .decoration(TextDecoration.ITALIC, false) + ))); + } + inventory.setItem(SMART_PACKER_CLOSE_SLOT, + createMenuControlItem(Material.BARRIER, "Close", NamedTextColor.RED)); + player.openInventory(inventory); + } - executePack(player, PackRequest.chest(chestInventory)); + private void handleSmartPackerMenuClick(final InventoryClickEvent event, final SmartPackerMenuHolder holder) { + event.setCancelled(true); + if (!(event.getWhoClicked() instanceof Player player) + || !holder.playerId.equals(player.getUniqueId()) + || holder.actionPending + || !event.getClick().isLeftClick() && !event.getClick().isRightClick()) { + return; + } + int slot = event.getRawSlot(); + if (slot != SMART_PACKER_INVENTORY_SLOT && slot != SMART_PACKER_CHEST_SLOT + && slot != SMART_PACKER_AUTO_SLOT && slot != SMART_PACKER_CLOSE_SLOT) { + return; + } + if (slot == SMART_PACKER_AUTO_SLOT && !isAutoPackAvailableInCurrentMode()) { + return; + } + holder.actionPending = true; + Bukkit.getScheduler().runTask(plugin, () -> { + if (!player.isOnline() || player.getOpenInventory().getTopInventory() != holder.inventory) { return; } + player.closeInventory(); + runSmartPackerAction(player, slot, () -> getLookedAtChestInventory(player)); + }); + } - if (!tryStartSmartPackerCooldown(player, true)) { + private void runSmartPackerAction(final Player player, final int slot, final Supplier chestTarget) { + if (slot == SMART_PACKER_CLOSE_SLOT || !canUseBedrockSmartPacker(player)) { + return; + } + Inventory chest = null; + if (slot == SMART_PACKER_CHEST_SLOT) { + if (!isChestPackSmartPackerItemEnabled()) { + sendChestPackDisabledMessage(player); + return; + } + chest = chestTarget.get(); + if (chest == null) { + player.sendMessage(getMessage("message.error.no_chest_target", "Look at a chest within reach.")); return; } + } + useSmartPacker(player, slot == SMART_PACKER_AUTO_SLOT, chest); + } + private void useSmartPacker(final Player player, final boolean toggleAutoPack, final Inventory chestInventory) { + if (toggleAutoPack) { + toggleAutoPackFromSmartPackerItem(player); + return; + } + if (!player.hasPermission("smartpack.use") + || (chestInventory != null && !player.hasPermission("smartpack.chest"))) { + player.sendMessage(getMessage( + "message.error.no_permission", + "You do not have permission to use this command." + )); + return; + } + if (!tryStartSmartPackerCooldown(player, true)) { + return; + } + if (chestInventory != null) { + executePack(player, PackRequest.chest(chestInventory)); + } else { executePack(player); - }); + } } private boolean isChestPackEnabled() { @@ -324,17 +531,12 @@ private void sendChestPackDisabledMessage(final Player player) { } private Inventory getLookedAtChestInventory(final Player player) { - RayTraceResult result = player.rayTraceBlocks(getBlockInteractionRange(player), FluidCollisionMode.NEVER); - if (result == null) { - return null; - } - - Block block = result.getHitBlock(); - if (block == null) { - return null; - } + return getChestBlockInventory(getLookedAtBlock(player)); + } - return getChestBlockInventory(block); + private Block getLookedAtBlock(final Player player) { + RayTraceResult result = player.rayTraceBlocks(getBlockInteractionRange(player), FluidCollisionMode.NEVER); + return result == null ? null : result.getHitBlock(); } private double getBlockInteractionRange(final Player player) { @@ -466,6 +668,8 @@ private void refreshSmartPackerItems(final Player player) { ? 0L : getRemainingSmartPackerCooldownTicks(player.getUniqueId()); boolean updated = false; + boolean bedrock = isBedrockPlayer.test(player.getUniqueId()); + boolean autoPackEnabled = plugin.isAutoPackEnabledForPlayer(player.getUniqueId()); PlayerInventory inventory = player.getInventory(); ItemStack[] contents = inventory.getContents(); @@ -475,7 +679,7 @@ private void refreshSmartPackerItems(final Player player) { continue; } - if (plugin.updateSmartPackerItemLore(item, remainingTicks)) { + if (plugin.updateSmartPackerItemLore(item, remainingTicks, bedrock, autoPackEnabled)) { inventory.setItem(slot, item); updated = true; } @@ -483,7 +687,7 @@ private void refreshSmartPackerItems(final Player player) { ItemStack cursorItem = player.getItemOnCursor(); if (plugin.isSmartPackerItem(cursorItem)) { - updated |= plugin.updateSmartPackerItemLore(cursorItem, remainingTicks); + updated |= plugin.updateSmartPackerItemLore(cursorItem, remainingTicks, bedrock, autoPackEnabled); player.setItemOnCursor(cursorItem); } @@ -518,7 +722,8 @@ public void onEntityPickupItem(final EntityPickupItemEvent event) { @EventHandler(ignoreCancelled = true) public void onInventoryDrag(final InventoryDragEvent event) { - if (!(event.getView().getTopInventory().getHolder() instanceof ExcludeMenuHolder)) { + InventoryHolder holder = event.getView().getTopInventory().getHolder(); + if (!(holder instanceof ExcludeMenuHolder) && !(holder instanceof SmartPackerMenuHolder)) { return; } @@ -542,8 +747,7 @@ public void onInventoryClose(final InventoryCloseEvent event) { } if (event.getPlayer() instanceof Player player) { - persistPersistentExclusionsIfChanged(player, session); - sendExclusionChangesAppliedMessage(player); + applyExcludeMenuChanges(player, session); } } @@ -594,6 +798,7 @@ public void onPlayerJoin(final PlayerJoinEvent event) { @EventHandler public void onPlayerQuit(final PlayerQuitEvent event) { UUID playerId = event.getPlayer().getUniqueId(); + openSmartPackerForms.remove(playerId); pendingAutoPack.remove(playerId); lastAutoPackTicks.remove(playerId); lastAutoInventoryFullMessageTicks.remove(playerId); @@ -841,25 +1046,38 @@ private boolean shouldCheckNearbyCraftingTableAutoTrigger( return false; } - private void enableAutoPackFromSmartPackerItem(final Player player) { - if (!player.hasPermission("smartpack.use") || !player.hasPermission("smartpack.auto")) { + private void toggleAutoPackFromSmartPackerItem(final Player player) { + setSmartPackerAutoMode(player, !plugin.isAutoPackEnabledForPlayer(player.getUniqueId())); + } + + private void setSmartPackerAutoMode(final Player player, final boolean enabled) { + if (!canChangeSmartPackerAutoMode(player) || plugin.isAutoPackEnabledForPlayer(player.getUniqueId()) == enabled) { + return; + } + plugin.setAutoPackEnabledForPlayer(player.getUniqueId(), enabled); + refreshSmartPackerItems(player); + sendAutoPackToggleMessage(player, enabled); + } + + private boolean canChangeSmartPackerAutoMode(final Player player) { + if (!hasAutoPackPermission(player)) { player.sendMessage(getMessage( "message.error.no_permission", "You do not have permission to use this command." )); - return; + return false; } if (!isAutoPackAvailableInCurrentMode()) { sendAutoPackUnavailable(player); - return; + return false; } - plugin.setAutoPackEnabledForPlayer(player.getUniqueId(), true); - player.sendMessage(getMessage( - "message.info.auto_pack_enabled", - "Auto-pack enabled." - )); + return true; + } + + private boolean hasAutoPackPermission(final CommandSender sender) { + return sender.hasPermission("smartpack.use") && sender.hasPermission("smartpack.auto"); } private boolean isAutoPackAvailableInCurrentMode() { @@ -937,41 +1155,6 @@ private void markAutoPackRun(final UUID playerId) { lastAutoPackTicks.put(playerId, (long) Bukkit.getCurrentTick()); } - @Override - public List onTabComplete( - @NotNull CommandSender sender, - @NotNull Command command, - @NotNull String alias, - @NotNull String[] args - ) { - if (args.length == 1) { - String input = args[0].toLowerCase(Locale.ROOT); - List completions = new ArrayList<>(); - - if ("exclude".startsWith(input)) { - completions.add("exclude"); - } - if (!plugin.isSmartPackerItemModeEnabled() - && isChestPackCommandEnabled() - && sender.hasPermission("smartpack.chest") - && "chest".startsWith(input)) { - completions.add("chest"); - } - if (!plugin.isSmartPackerItemModeEnabled() - && sender.hasPermission("smartpack.auto") - && "auto".startsWith(input)) { - completions.add("auto"); - } - if (sender.hasPermission("smartpack.reload") && "reload".startsWith(input)) { - completions.add("reload"); - } - - return completions; - } - - return Collections.emptyList(); - } - private CraftingRequirementState getCraftingRequirementState(final Player player) { if (plugin.isSmartPackerItemModeEnabled()) { return new CraftingRequirementState( @@ -1738,6 +1921,39 @@ private void sendExclusionChangesAppliedMessage(final Player player) { player.sendMessage(Component.text("Exclusion changes applied.", NamedTextColor.GREEN)); } + private void applyExcludeMenuChanges(final Player player, final ExcludeMenuSession session) { + persistPersistentExclusionsIfChanged(player, session); + + Set currentPersistent = plugin.getPackInputExcludedPersistentSnapshot(player.getUniqueId()); + Set currentNextRun = plugin.getPackInputExcludedNextRunSnapshot(player.getUniqueId()); + Set materials = new HashSet<>(session.initialPersistentExclusions()); + materials.addAll(session.initialNextRunExclusions()); + materials.addAll(currentPersistent); + materials.addAll(currentNextRun); + List sortedMaterials = new ArrayList<>(materials); + sortedMaterials.sort(Comparator.comparing(this::getItemName)); + + // Report only the final changes, not intermediate toggles or discarded edits. + for (Material material : sortedMaterials) { + boolean persistent = currentPersistent.contains(material); + if (persistent != session.initialPersistentExclusions().contains(material)) { + player.sendMessage(Component.text(getItemName(material), persistent ? NamedTextColor.RED : NamedTextColor.GREEN) + .append(Component.text(persistent + ? " is now persistently excluded from packing." + : " is no longer persistently excluded.", NamedTextColor.GRAY))); + } + if (!persistent && currentNextRun.contains(material) != session.initialNextRunExclusions().contains(material)) { + boolean nextRun = currentNextRun.contains(material); + player.sendMessage(Component.text(getItemName(material), nextRun ? NamedTextColor.YELLOW : NamedTextColor.GREEN) + .append(Component.text(nextRun + ? " will be skipped on the next pack run only." + : " will no longer be skipped on the next pack run.", NamedTextColor.GRAY))); + } + } + + sendExclusionChangesAppliedMessage(player); + } + private void persistPersistentExclusionsIfChanged( final Player player, final ExcludeMenuSession session @@ -2096,7 +2312,9 @@ private void openExcludeMenu(final Player player, final int page) { ) ); - ExcludeMenuHolder holder = new ExcludeMenuHolder(player.getUniqueId(), safePage); + ExcludeMenuHolder holder = new ExcludeMenuHolder( + player.getUniqueId(), safePage, isBedrockPlayer.test(player.getUniqueId()) + ); Inventory inventory = Bukkit.createInventory( holder, EXCLUDE_MENU_SIZE, @@ -2118,10 +2336,21 @@ private void handleExcludeMenuClick(final InventoryClickEvent event, final Exclu if (rawSlot < 0 || rawSlot >= event.getView().getTopInventory().getSize()) { return; } + if (!event.getClick().isLeftClick() && !event.getClick().isRightClick()) { + return; + } List configuredInputs = getConfiguredInputMaterials(); int totalPages = getExcludeMenuPageCount(configuredInputs.size()); + if (rawSlot == EXCLUDE_MENU_MODE_SLOT) { + if (holder.bedrock) { + holder.persistentEditMode = !holder.persistentEditMode; + renderCurrentExcludeMenu(event.getView().getTopInventory(), player, holder, holder.page(), totalPages); + } + return; + } + if (rawSlot < EXCLUDE_MENU_CONTENT_SIZE) { int materialIndex = (holder.page() * EXCLUDE_MENU_CONTENT_SIZE) + rawSlot; if (materialIndex >= configuredInputs.size()) { @@ -2129,52 +2358,23 @@ private void handleExcludeMenuClick(final InventoryClickEvent event, final Exclu } Material material = configuredInputs.get(materialIndex); - if (event.getClick().isRightClick()) { - boolean excluded = plugin.togglePackInputExcluded(player.getUniqueId(), material); + // Geyser cannot reliably distinguish left/right inventory clicks. + // The mode button makes both actions available through ordinary clicks. + if (holder.bedrock ? holder.persistentEditMode : event.getClick().isRightClick()) { + plugin.togglePackInputExcluded(player.getUniqueId(), material); plugin.clearPackInputExcludedNextRun(player.getUniqueId(), material); - refreshExcludeMenuItem(event, rawSlot, player, material, holder.page(), totalPages); + refreshExcludeMenuItem(event, rawSlot, player, material, holder, totalPages); - if (excluded) { - player.sendMessage( - Component.text(getItemName(material), NamedTextColor.RED) - .append(Component.text(" is now persistently excluded from packing.", NamedTextColor.GRAY)) - ); - } else { - player.sendMessage( - Component.text(getItemName(material), NamedTextColor.GREEN) - .append(Component.text(" is no longer persistently excluded.", NamedTextColor.GRAY)) - ); - } - return; - } - - if (!event.getClick().isLeftClick()) { return; } if (plugin.isPackInputExcluded(player.getUniqueId(), material)) { - player.sendMessage( - Component.text(getItemName(material), NamedTextColor.RED) - .append(Component.text(" is already persistently excluded. Right-click it to re-include.", NamedTextColor.GRAY)) - ); return; } - boolean excluded = plugin.togglePackInputExcludedNextRun(player.getUniqueId(), material); - refreshExcludeMenuItem(event, rawSlot, player, material, holder.page(), totalPages); - - if (excluded) { - player.sendMessage( - Component.text(getItemName(material), NamedTextColor.YELLOW) - .append(Component.text(" will be skipped on the next pack run only.", NamedTextColor.GRAY)) - ); - } else { - player.sendMessage( - Component.text(getItemName(material), NamedTextColor.GREEN) - .append(Component.text(" will no longer be skipped on the next pack run.", NamedTextColor.GRAY)) - ); - } + plugin.togglePackInputExcludedNextRun(player.getUniqueId(), material); + refreshExcludeMenuItem(event, rawSlot, player, material, holder, totalPages); return; } @@ -2208,9 +2408,8 @@ private void handleExcludeMenuClick(final InventoryClickEvent event, final Exclu if (rawSlot == EXCLUDE_MENU_APPLY_SLOT) { ExcludeMenuSession session = excludeMenuSessions.remove(player.getUniqueId()); if (session != null) { - persistPersistentExclusionsIfChanged(player, session); + applyExcludeMenuChanges(player, session); } - sendExclusionChangesAppliedMessage(player); Bukkit.getScheduler().runTask(plugin, () -> player.closeInventory()); return; } @@ -2225,12 +2424,36 @@ private void handleExcludeMenuClick(final InventoryClickEvent event, final Exclu } } - private void fillExcludeMenuControls(final Inventory inventory, final int page, final int totalPages) { - for (int slot = EXCLUDE_MENU_CONTENT_SIZE; slot < EXCLUDE_MENU_SIZE; slot++) { - inventory.setItem(slot, createMenuFillerItem()); + private void fillExcludeMenuControls( + final Inventory inventory, + final int page, + final int totalPages, + final ExcludeMenuHolder holder + ) { + if (!holder.bedrock) { + for (int slot = EXCLUDE_MENU_CONTENT_SIZE; slot < EXCLUDE_MENU_SIZE; slot++) { + inventory.setItem(slot, createMenuFillerItem()); + } } - inventory.setItem(EXCLUDE_MENU_INFO_SLOT, createExcludeMenuInfoItem(page, totalPages)); + inventory.setItem(EXCLUDE_MENU_INFO_SLOT, createExcludeMenuInfoItem(page, totalPages, holder)); + if (holder.bedrock) { + boolean persistentEditMode = holder.persistentEditMode; + inventory.setItem( + EXCLUDE_MENU_MODE_SLOT, + createMenuControlItem( + persistentEditMode ? Material.REDSTONE_TORCH : Material.CLOCK, + "Edit Mode: " + (persistentEditMode ? "Permanent" : "Next Run Only"), + persistentEditMode ? NamedTextColor.RED : NamedTextColor.YELLOW, + List.of( + Component.text("Select items to toggle " + (persistentEditMode ? "permanent exclusions." : "one-time skips."), NamedTextColor.GRAY) + .decoration(TextDecoration.ITALIC, false), + Component.text("Click to switch to " + (persistentEditMode ? "Next Run Only." : "Permanent."), NamedTextColor.GRAY) + .decoration(TextDecoration.ITALIC, false) + ) + ) + ); + } if (page > 0) { inventory.setItem( @@ -2273,7 +2496,11 @@ private void fillExcludeMenuControls(final Inventory inventory, final int page, ); } - private ItemStack createExcludeMenuItem(final Player player, final Material material) { + private ItemStack createExcludeMenuItem( + final Player player, + final Material material, + final ExcludeMenuHolder holder + ) { ItemStack item = new ItemStack(material); ItemMeta meta = item.getItemMeta(); @@ -2291,44 +2518,61 @@ private ItemStack createExcludeMenuItem(final Player player, final Material mate meta.setEnchantmentGlintOverride(persistentExcluded || nextRunExcluded); meta.displayName(statusPrefix.append(materialName).decoration(TextDecoration.ITALIC, false)); + List lore = new ArrayList<>(); if (persistentExcluded) { - meta.lore(List.of( + lore.addAll(List.of( Component.text("Persistent exclusion is active.", NamedTextColor.RED) .decoration(TextDecoration.ITALIC, false), Component.text("This slot glows to show an active exclusion.", NamedTextColor.DARK_RED) .decoration(TextDecoration.ITALIC, false), - Component.text("Right-click to include this item again.", NamedTextColor.GRAY) - .decoration(TextDecoration.ITALIC, false), - Component.text("Left-click is unavailable while persistent exclusion is active.", NamedTextColor.DARK_GRAY) + Component.text(holder.bedrock + ? holder.persistentEditMode ? "Click to include this item again." + : "Select Permanent mode to include this item again." + : "Right-click to include this item again.", NamedTextColor.GRAY) .decoration(TextDecoration.ITALIC, false) )); + if (!holder.bedrock) { + lore.add(Component.text("Left-click is unavailable while persistent exclusion is active.", NamedTextColor.DARK_GRAY) + .decoration(TextDecoration.ITALIC, false)); + } } else if (nextRunExcluded) { - meta.lore(List.of( + lore.addAll(List.of( Component.text("This item will be skipped on the next pack run only.", NamedTextColor.YELLOW) .decoration(TextDecoration.ITALIC, false), Component.text("The slot glow marks a temporary exclusion.", NamedTextColor.GOLD) .decoration(TextDecoration.ITALIC, false), - Component.text("Left-click to remove the one-time skip.", NamedTextColor.GRAY) - .decoration(TextDecoration.ITALIC, false), - Component.text("Right-click to make the exclusion persistent.", NamedTextColor.GRAY) + Component.text(holder.bedrock + ? holder.persistentEditMode ? "Click to make the exclusion permanent." + : "Click to remove the one-time skip." + : "Left-click to remove the one-time skip.", NamedTextColor.GRAY) .decoration(TextDecoration.ITALIC, false) )); + if (!holder.bedrock) { + lore.add(Component.text("Right-click to make the exclusion persistent.", NamedTextColor.GRAY) + .decoration(TextDecoration.ITALIC, false)); + } } else { - meta.lore(List.of( + lore.addAll(List.of( Component.text("No exclusion is active.", NamedTextColor.GREEN) .decoration(TextDecoration.ITALIC, false), - Component.text("Left-click to skip it on the next run only.", NamedTextColor.GRAY) - .decoration(TextDecoration.ITALIC, false), - Component.text("Right-click to exclude it persistently.", NamedTextColor.GRAY) + Component.text(holder.bedrock + ? holder.persistentEditMode ? "Click to exclude it permanently." + : "Click to skip it on the next run only." + : "Left-click to skip it on the next run only.", NamedTextColor.GRAY) .decoration(TextDecoration.ITALIC, false) )); + if (!holder.bedrock) { + lore.add(Component.text("Right-click to exclude it persistently.", NamedTextColor.GRAY) + .decoration(TextDecoration.ITALIC, false)); + } } + meta.lore(lore); item.setItemMeta(meta); return item; } - private ItemStack createExcludeMenuInfoItem(final int page, final int totalPages) { + private ItemStack createExcludeMenuInfoItem(final int page, final int totalPages, final ExcludeMenuHolder holder) { ItemStack item = new ItemStack(Material.BOOK); ItemMeta meta = item.getItemMeta(); @@ -2336,11 +2580,19 @@ private ItemStack createExcludeMenuInfoItem(final int page, final int totalPages Component.text("Exclusion Help", NamedTextColor.GOLD) .decoration(TextDecoration.ITALIC, false) ); - meta.lore(List.of( - Component.text("Left-click: skip on the next pack run only.", NamedTextColor.GRAY) - .decoration(TextDecoration.ITALIC, false), - Component.text("Right-click: toggle a persistent exclusion.", NamedTextColor.GRAY) - .decoration(TextDecoration.ITALIC, false), + List lore = new ArrayList<>(); + if (holder.bedrock) { + lore.add(Component.text("Edit mode: " + (holder.persistentEditMode ? "Permanent" : "Next Run Only"), NamedTextColor.YELLOW) + .decoration(TextDecoration.ITALIC, false)); + lore.add(Component.text("Click the mode button to switch, then select items.", NamedTextColor.GRAY) + .decoration(TextDecoration.ITALIC, false)); + } else { + lore.add(Component.text("Left-click: skip on the next pack run only.", NamedTextColor.GRAY) + .decoration(TextDecoration.ITALIC, false)); + lore.add(Component.text("Right-click: toggle a persistent exclusion.", NamedTextColor.GRAY) + .decoration(TextDecoration.ITALIC, false)); + } + lore.addAll(List.of( Component.text("Glowing slots have an active exclusion.", NamedTextColor.GRAY) .decoration(TextDecoration.ITALIC, false), Component.text("Red X = persistent, yellow ! = next run only.", NamedTextColor.GRAY) @@ -2353,6 +2605,7 @@ private ItemStack createExcludeMenuInfoItem(final int page, final int totalPages .decoration(TextDecoration.ITALIC, false) )); + meta.lore(lore); item.setItemMeta(meta); return item; } @@ -2452,10 +2705,10 @@ private void renderExcludeMenu( break; } - inventory.setItem(slot, createExcludeMenuItem(player, configuredInputs.get(materialIndex))); + inventory.setItem(slot, createExcludeMenuItem(player, configuredInputs.get(materialIndex), holder)); } - fillExcludeMenuControls(inventory, page, totalPages); + fillExcludeMenuControls(inventory, page, totalPages, holder); } private void refreshExcludeMenuItem( @@ -2463,13 +2716,13 @@ private void refreshExcludeMenuItem( final int rawSlot, final Player player, final Material material, - final int page, + final ExcludeMenuHolder holder, final int totalPages ) { - event.getView().getTopInventory().setItem(rawSlot, createExcludeMenuItem(player, material)); + event.getView().getTopInventory().setItem(rawSlot, createExcludeMenuItem(player, material, holder)); event.getView().getTopInventory().setItem( EXCLUDE_MENU_INFO_SLOT, - createExcludeMenuInfoItem(page, totalPages) + createExcludeMenuInfoItem(holder.page(), totalPages, holder) ); } @@ -3037,15 +3290,36 @@ private void consumeSettleTick() { } } + private record SmartPackerForm(String content, List actions, List buttons, + boolean autoEnabled) { } + + private static final class SmartPackerMenuHolder implements InventoryHolder { + private final UUID playerId; + private Inventory inventory; + private boolean actionPending; + + private SmartPackerMenuHolder(final UUID playerId) { + this.playerId = playerId; + } + + @Override + public Inventory getInventory() { + return inventory; + } + } + private static final class ExcludeMenuHolder implements InventoryHolder { private final UUID playerId; + private final boolean bedrock; private int page; + private boolean persistentEditMode; private Inventory inventory; - private ExcludeMenuHolder(final UUID playerId, final int page) { + private ExcludeMenuHolder(final UUID playerId, final int page, final boolean bedrock) { this.playerId = playerId; this.page = page; + this.bedrock = bedrock; } @Override diff --git a/src/main/java/crosis47/minecraft/smartpack/compatibility/BedrockForms.java b/src/main/java/crosis47/minecraft/smartpack/compatibility/BedrockForms.java new file mode 100644 index 0000000..a881abc --- /dev/null +++ b/src/main/java/crosis47/minecraft/smartpack/compatibility/BedrockForms.java @@ -0,0 +1,101 @@ +package crosis47.minecraft.smartpack.compatibility; + +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; + +import java.lang.reflect.Method; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.UUID; +import java.util.function.Consumer; +import java.util.function.IntConsumer; + +/** Uses the Cumulus API supplied by the installed form provider. */ +public final class BedrockForms { + public record Button(String label, String texturePath) { } + + private final JavaPlugin plugin; + private final Set warnedProviders = new HashSet<>(); + + public BedrockForms(final JavaPlugin plugin) { + this.plugin = plugin; + } + + public boolean sendSimpleForm( + final UUID playerId, final String title, final String content, final List