Package me.deecaad.core.commands
Class CustomMapArgument
java.lang.Object
dev.jorel.commandapi.AbstractArgumentTree<dev.jorel.commandapi.arguments.Argument<Map<String,Object>>,dev.jorel.commandapi.arguments.Argument<?>,org.bukkit.command.CommandSender>
- All Implemented Interfaces:
dev.jorel.commandapi.BukkitExecutable<dev.jorel.commandapi.arguments.Argument<Map<String,,Object>>> dev.jorel.commandapi.ChainableBuilder<dev.jorel.commandapi.arguments.Argument<Map<String,,Object>>> dev.jorel.commandapi.PlatformExecutable<dev.jorel.commandapi.arguments.Argument<Map<String,Object>>, org.bukkit.command.CommandSender>
public class CustomMapArgument
extends dev.jorel.commandapi.arguments.CustomArgument<Map<String,Object>,String>
A CustomArgument for parsing a single argument that contains multiple key-value pairs (a
"map"). Each key must be known ahead of time, and each key is handled by a
SimpleSerializer for type-checking and deserialization.
Example usage (registering the argument):
// 1) Build known types for each "key"
Map<String, SimpleSerializer<?>>> weaponDataMap = new HashMap<>();
weaponDataMap.put("ammo", new IntSerializer(1, 64));
weaponDataMap.put("firemode", new IntSerializer(0, 2));
weaponDataMap.put("skipMainhand", new BooleanSerializer());
weaponDataMap.put("skin", new StringSerializer());
// 2) Create the custom argument
Argument<Map<String, Object>> dataArg = new CustomMapArgument("data", weaponDataMap)
.setDefault(Collections.emptyMap()); // make it optional
// 3) Use it in a CommandAPICommand
new CommandAPICommand("give")
.withArguments(dataArg)
.executesPlayer((player, args) -> {
Map<String, Object> data = (Map<String, Object>) args.get("data");
// e.g. data.get("ammo") -> Integer
})
.register();
This class automatically handles:
- Splitting the user input on commas (and optional braces '{' / '}')
- Validating each key, using your
SimpleSerializer - Providing tab-completions for keys and values, based on each serializer's
SimpleSerializer.examples()
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class dev.jorel.commandapi.arguments.CustomArgument
dev.jorel.commandapi.arguments.CustomArgument.CustomArgumentException, dev.jorel.commandapi.arguments.CustomArgument.CustomArgumentInfo<B>, dev.jorel.commandapi.arguments.CustomArgument.CustomArgumentInfoParser<T,B>, dev.jorel.commandapi.arguments.CustomArgument.MessageBuilder -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected dev.jorel.commandapi.CommandAPIExecutor<org.bukkit.command.CommandSender, dev.jorel.commandapi.commandsenders.AbstractCommandSender<? extends org.bukkit.command.CommandSender>> -
Constructor Summary
ConstructorsConstructorDescriptionCustomMapArgument(String nodeName, Map<String, SimpleSerializer<?>> knownTypes) Creates a newCustomMapArgumentthat parses a map of key-value pairs from a single argument. -
Method Summary
Modifier and TypeMethodDescriptiondev.jorel.commandapi.CommandAPIExecutor<org.bukkit.command.CommandSender, dev.jorel.commandapi.commandsenders.AbstractCommandSender<? extends org.bukkit.command.CommandSender>> voidsetExecutor(dev.jorel.commandapi.CommandAPIExecutor<org.bukkit.command.CommandSender, dev.jorel.commandapi.commandsenders.AbstractCommandSender<? extends org.bukkit.command.CommandSender>> arg0) Methods inherited from class dev.jorel.commandapi.arguments.CustomArgument
getArgumentType, getPrimitiveType, parseArgumentMethods inherited from class dev.jorel.commandapi.arguments.Argument
instanceMethods inherited from class dev.jorel.commandapi.arguments.AbstractArgument
combineWith, copyPermissionsAndRequirements, getArgumentPermission, getCombinedArguments, getEntityNames, getHelpString, getIncludedSuggestions, getNodeName, getOverriddenSuggestions, getRawType, getRequirements, hasCombinedArguments, includeSuggestions, isListed, isOptional, replaceSuggestions, setListed, setOptional, toString, withPermission, withPermission, withRequirementMethods inherited from class dev.jorel.commandapi.AbstractArgumentTree
then, thenNested, thenNestedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface dev.jorel.commandapi.BukkitExecutable
executes, executes, executes, executes, executesCommandBlock, executesCommandBlock, executesCommandBlock, executesCommandBlock, executesConsole, executesConsole, executesConsole, executesConsole, executesEntity, executesEntity, executesEntity, executesEntity, executesFeedbackForwarding, executesFeedbackForwarding, executesFeedbackForwarding, executesFeedbackForwarding, executesNative, executesNative, executesNative, executesNative, executesPlayer, executesPlayer, executesPlayer, executesPlayer, executesProxy, executesProxy, executesProxy, executesProxy, executesRemoteConsole, executesRemoteConsole, executesRemoteConsole, executesRemoteConsoleMethods inherited from interface dev.jorel.commandapi.PlatformExecutable
getExecutor
-
Field Details
-
executor
protected dev.jorel.commandapi.CommandAPIExecutor<org.bukkit.command.CommandSender,dev.jorel.commandapi.commandsenders.AbstractCommandSender<? extends org.bukkit.command.CommandSender>> executor
-
-
Constructor Details
-
CustomMapArgument
Creates a new
CustomMapArgumentthat parses a map of key-value pairs from a single argument. This uses aGreedyStringArgumentas the base, so the user can type something like:/mycommand {ammo:5,firemode:2,skipMainhand:false}Each key must be present in
knownTypes, and its value is parsed by the correspondingSimpleSerializer.- Parameters:
nodeName- The name (identifier) for this argumentknownTypes- A map fromkey -> SimpleSerializer<?>.
-
-
Method Details
-
getExecutor
public dev.jorel.commandapi.CommandAPIExecutor<org.bukkit.command.CommandSender,dev.jorel.commandapi.commandsenders.AbstractCommandSender<? extends org.bukkit.command.CommandSender>> getExecutor() -
setExecutor
public void setExecutor(dev.jorel.commandapi.CommandAPIExecutor<org.bukkit.command.CommandSender, dev.jorel.commandapi.commandsenders.AbstractCommandSender<? extends org.bukkit.command.CommandSender>> arg0) -
clearExecutors
-