From 7d2496b06d663ddc435259ed4d4e263c727c985a Mon Sep 17 00:00:00 2001 From: XiaoMoMi Date: Thu, 4 Dec 2025 01:12:48 +0800 Subject: [PATCH] Update DebugSpawnFurnitureCommand.java --- .../feature/DebugSpawnFurnitureCommand.java | 49 ++++++++++++------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/DebugSpawnFurnitureCommand.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/DebugSpawnFurnitureCommand.java index 7b32aeba1..832a1c40e 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/DebugSpawnFurnitureCommand.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/DebugSpawnFurnitureCommand.java @@ -1,10 +1,16 @@ package net.momirealms.craftengine.bukkit.plugin.command.feature; +import net.momirealms.craftengine.bukkit.api.CraftEngineFurniture; +import net.momirealms.craftengine.bukkit.entity.furniture.BukkitFurnitureManager; import net.momirealms.craftengine.bukkit.plugin.command.BukkitCommandFeature; -import net.momirealms.craftengine.core.entity.furniture.AnchorType; +import net.momirealms.craftengine.bukkit.util.KeyUtils; +import net.momirealms.craftengine.core.entity.furniture.FurnitureConfig; import net.momirealms.craftengine.core.plugin.CraftEngine; import net.momirealms.craftengine.core.plugin.command.CraftEngineCommandManager; import net.momirealms.craftengine.core.plugin.command.FlagKeys; +import net.momirealms.craftengine.core.util.Key; +import org.bukkit.Location; +import org.bukkit.NamespacedKey; import org.bukkit.command.CommandSender; import org.checkerframework.checker.nullness.qual.NonNull; import org.incendo.cloud.Command; @@ -12,10 +18,12 @@ import org.incendo.cloud.bukkit.parser.NamespacedKeyParser; import org.incendo.cloud.bukkit.parser.location.LocationParser; import org.incendo.cloud.context.CommandContext; import org.incendo.cloud.context.CommandInput; -import org.incendo.cloud.parser.standard.EnumParser; +import org.incendo.cloud.parser.standard.StringParser; import org.incendo.cloud.suggestion.Suggestion; import org.incendo.cloud.suggestion.SuggestionProvider; +import java.util.List; +import java.util.Optional; import java.util.concurrent.CompletableFuture; public class DebugSpawnFurnitureCommand extends BukkitCommandFeature { @@ -24,7 +32,6 @@ public class DebugSpawnFurnitureCommand extends BukkitCommandFeature assembleCommand(org.incendo.cloud.CommandManager manager, Command.Builder builder) { return builder @@ -35,22 +42,30 @@ public class DebugSpawnFurnitureCommand extends BukkitCommandFeature() { + @Override + public @NonNull CompletableFuture> suggestionsFuture(@NonNull CommandContext context, @NonNull CommandInput input) { + NamespacedKey namespacedKey = context.get("id"); + Key id = KeyUtils.namespacedKey2Key(namespacedKey); + BukkitFurnitureManager furnitureManager = BukkitFurnitureManager.instance(); + Optional optionalCustomFurniture = furnitureManager.furnitureById(id); + return optionalCustomFurniture.>>map(config -> CompletableFuture.completedFuture(config.variants().keySet().stream().map(Suggestion::suggestion).toList())).orElseGet(() -> CompletableFuture.completedFuture(List.of())); + } + })) .flag(FlagKeys.SILENT_FLAG) .handler(context -> { - // fixme 指令 -// NamespacedKey namespacedKey = context.get("id"); -// Key id = KeyUtils.namespacedKey2Key(namespacedKey); -// BukkitFurnitureManager furnitureManager = BukkitFurnitureManager.instance(); -// Optional optionalCustomFurniture = furnitureManager.furnitureById(id); -// if (optionalCustomFurniture.isEmpty()) { -// return; -// } -// Location location = context.get("location"); -// FurnitureConfig customFurniture = optionalCustomFurniture.get(); -// AnchorType anchorType = (AnchorType) context.optional("anchor-type").orElse(customFurniture.getAnyAnchorType()); -// boolean playSound = context.flags().hasFlag("silent"); -// CraftEngineFurniture.place(location, customFurniture, anchorType, playSound); + NamespacedKey namespacedKey = context.get("id"); + Key id = KeyUtils.namespacedKey2Key(namespacedKey); + BukkitFurnitureManager furnitureManager = BukkitFurnitureManager.instance(); + Optional optionalCustomFurniture = furnitureManager.furnitureById(id); + if (optionalCustomFurniture.isEmpty()) { + return; + } + Location location = context.get("location"); + FurnitureConfig customFurniture = optionalCustomFurniture.get(); + String variant = (String) context.optional("variant").orElse(customFurniture.anyVariantName()); + boolean playSound = context.flags().hasFlag("silent"); + CraftEngineFurniture.place(location, customFurniture, variant, playSound); }); }