Skip to content

Commit

Permalink
enhance: 使ValueMapArgumentType可以根据提供的属性Map来进行补全
Browse files Browse the repository at this point in the history
  - Honestly I'm not very clear about what I'm doing in ValueMapArgumentType... Let's hope it works!
  • Loading branch information
MATRIX-feather committed Dec 31, 2024
1 parent 2a9cabb commit 91b6718
Show file tree
Hide file tree
Showing 2 changed files with 279 additions and 76 deletions.
34 changes: 10 additions & 24 deletions src/main/java/xyz/nifeather/morph/commands/MorphCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.kyori.adventure.key.Key;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import xiamomc.pluginbase.Annotations.Initializer;
import xiamomc.pluginbase.Annotations.Resolved;
import xiamomc.pluginbase.Messages.FormattableMessage;
import xyz.nifeather.morph.MorphManager;
Expand All @@ -25,6 +26,7 @@
import xyz.nifeather.morph.misc.DisguiseMeta;
import xyz.nifeather.morph.misc.gui.DisguiseSelectScreenWrapper;

import java.util.List;
import java.util.concurrent.CompletableFuture;

@SuppressWarnings("UnstableApiUsage")
Expand All @@ -42,6 +44,8 @@ public class MorphCommand extends MorphPluginObject implements IConvertibleBriga
@Resolved
private MorphManager morphs;

private final ValueMapArgumentType propertyArgument = new ValueMapArgumentType();

@Override
public boolean register(Commands dispatcher)
{
Expand All @@ -53,32 +57,23 @@ public boolean register(Commands dispatcher)
.suggests(this::suggestID)
.executes(this::execWithID)
//.then(
// Commands.argument("properties", new ValueMapArgumentType())
// Commands.argument("properties", propertyArgument)
// .executes(this::execExperimental)
// .then(
// Commands.argument("extra", IntegerArgumentType.integer())
// .executes(this::execExperimentala)
// )
//)
)
.build());

return true;
}

private int execExperimental(CommandContext<CommandSourceStack> context)
@Initializer
private void load()
{
var input = ValueMapArgumentType.get("properties", context);

input.forEach((k, v) ->
{
context.getSource().getSender().sendMessage("Key '%s', Value '%s'".formatted(k, v));
});

return 1;
this.propertyArgument.setProperty("morph:frog_variant", List.of("cold", "warm"));
this.propertyArgument.setProperty("morph:cat_variant", List.of("tabby", "black"));
}

private int execExperimentala(CommandContext<CommandSourceStack> context)
private int execExperimental(CommandContext<CommandSourceStack> context)
{
var input = ValueMapArgumentType.get("properties", context);

Expand All @@ -87,15 +82,6 @@ private int execExperimentala(CommandContext<CommandSourceStack> context)
context.getSource().getSender().sendMessage("Key '%s', Value '%s'".formatted(k, v));
});

try
{
context.getSource().getSender().sendPlainMessage("Extra is " + IntegerArgumentType.getInteger(context, "extra"));
}
catch (Throwable t)
{
context.getSource().getSender().sendPlainMessage("No extra: " + t.getMessage());
}

return 1;
}

Expand Down
Loading

0 comments on commit 91b6718

Please sign in to comment.