9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-19 15:09:15 +00:00

Update DebugSpawnFurnitureCommand.java

This commit is contained in:
XiaoMoMi
2025-12-04 01:12:48 +08:00
parent 1d74e2764f
commit 7d2496b06d

View File

@@ -1,10 +1,16 @@
package net.momirealms.craftengine.bukkit.plugin.command.feature; 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.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.CraftEngine;
import net.momirealms.craftengine.core.plugin.command.CraftEngineCommandManager; import net.momirealms.craftengine.core.plugin.command.CraftEngineCommandManager;
import net.momirealms.craftengine.core.plugin.command.FlagKeys; 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.bukkit.command.CommandSender;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import org.incendo.cloud.Command; 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.bukkit.parser.location.LocationParser;
import org.incendo.cloud.context.CommandContext; import org.incendo.cloud.context.CommandContext;
import org.incendo.cloud.context.CommandInput; 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.Suggestion;
import org.incendo.cloud.suggestion.SuggestionProvider; import org.incendo.cloud.suggestion.SuggestionProvider;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
public class DebugSpawnFurnitureCommand extends BukkitCommandFeature<CommandSender> { public class DebugSpawnFurnitureCommand extends BukkitCommandFeature<CommandSender> {
@@ -24,7 +32,6 @@ public class DebugSpawnFurnitureCommand extends BukkitCommandFeature<CommandSend
super(commandManager, plugin); super(commandManager, plugin);
} }
@SuppressWarnings("deprecation")
@Override @Override
public Command.Builder<? extends CommandSender> assembleCommand(org.incendo.cloud.CommandManager<CommandSender> manager, Command.Builder<CommandSender> builder) { public Command.Builder<? extends CommandSender> assembleCommand(org.incendo.cloud.CommandManager<CommandSender> manager, Command.Builder<CommandSender> builder) {
return builder return builder
@@ -35,22 +42,30 @@ public class DebugSpawnFurnitureCommand extends BukkitCommandFeature<CommandSend
return CompletableFuture.completedFuture(plugin().furnitureManager().cachedSuggestions()); return CompletableFuture.completedFuture(plugin().furnitureManager().cachedSuggestions());
} }
})) }))
.optional("anchor-type", EnumParser.enumParser(AnchorType.class)) .optional("variant", StringParser.stringComponent().suggestionProvider(new SuggestionProvider<>() {
@Override
public @NonNull CompletableFuture<? extends @NonNull Iterable<? extends @NonNull Suggestion>> suggestionsFuture(@NonNull CommandContext<Object> context, @NonNull CommandInput input) {
NamespacedKey namespacedKey = context.get("id");
Key id = KeyUtils.namespacedKey2Key(namespacedKey);
BukkitFurnitureManager furnitureManager = BukkitFurnitureManager.instance();
Optional<FurnitureConfig> optionalCustomFurniture = furnitureManager.furnitureById(id);
return optionalCustomFurniture.<CompletableFuture<? extends Iterable<? extends Suggestion>>>map(config -> CompletableFuture.completedFuture(config.variants().keySet().stream().map(Suggestion::suggestion).toList())).orElseGet(() -> CompletableFuture.completedFuture(List.of()));
}
}))
.flag(FlagKeys.SILENT_FLAG) .flag(FlagKeys.SILENT_FLAG)
.handler(context -> { .handler(context -> {
// fixme 指令 NamespacedKey namespacedKey = context.get("id");
// NamespacedKey namespacedKey = context.get("id"); Key id = KeyUtils.namespacedKey2Key(namespacedKey);
// Key id = KeyUtils.namespacedKey2Key(namespacedKey); BukkitFurnitureManager furnitureManager = BukkitFurnitureManager.instance();
// BukkitFurnitureManager furnitureManager = BukkitFurnitureManager.instance(); Optional<FurnitureConfig> optionalCustomFurniture = furnitureManager.furnitureById(id);
// Optional<FurnitureConfig> optionalCustomFurniture = furnitureManager.furnitureById(id); if (optionalCustomFurniture.isEmpty()) {
// if (optionalCustomFurniture.isEmpty()) { return;
// return; }
// } Location location = context.get("location");
// Location location = context.get("location"); FurnitureConfig customFurniture = optionalCustomFurniture.get();
// FurnitureConfig customFurniture = optionalCustomFurniture.get(); String variant = (String) context.optional("variant").orElse(customFurniture.anyVariantName());
// AnchorType anchorType = (AnchorType) context.optional("anchor-type").orElse(customFurniture.getAnyAnchorType()); boolean playSound = context.flags().hasFlag("silent");
// boolean playSound = context.flags().hasFlag("silent"); CraftEngineFurniture.place(location, customFurniture, variant, playSound);
// CraftEngineFurniture.place(location, customFurniture, anchorType, playSound);
}); });
} }