🐛 Fix argument flags
This commit is contained in:
parent
2bad5759c6
commit
63dce244aa
4 changed files with 29 additions and 1 deletions
|
|
@ -163,6 +163,7 @@ public final class FlagArgument<C> extends CommandArgument<C, Object> {
|
||||||
final CommandFlag erasedFlag = currentFlag;
|
final CommandFlag erasedFlag = currentFlag;
|
||||||
final Object value = result.getParsedValue().get();
|
final Object value = result.getParsedValue().get();
|
||||||
commandContext.flags().addValueFlag(erasedFlag, value);
|
commandContext.flags().addValueFlag(erasedFlag, value);
|
||||||
|
currentFlag = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ package cloud.commandframework;
|
||||||
|
|
||||||
import cloud.commandframework.arguments.CommandArgument;
|
import cloud.commandframework.arguments.CommandArgument;
|
||||||
import cloud.commandframework.arguments.compound.ArgumentPair;
|
import cloud.commandframework.arguments.compound.ArgumentPair;
|
||||||
|
import cloud.commandframework.arguments.standard.EnumArgument;
|
||||||
import cloud.commandframework.arguments.standard.IntegerArgument;
|
import cloud.commandframework.arguments.standard.IntegerArgument;
|
||||||
import cloud.commandframework.arguments.standard.StringArgument;
|
import cloud.commandframework.arguments.standard.StringArgument;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
|
|
@ -117,9 +118,12 @@ class CommandTreeTest {
|
||||||
.build())
|
.build())
|
||||||
.flag(manager.flagBuilder("num")
|
.flag(manager.flagBuilder("num")
|
||||||
.withArgument(IntegerArgument.of("num")).build())
|
.withArgument(IntegerArgument.of("num")).build())
|
||||||
|
.flag(manager.flagBuilder("enum")
|
||||||
|
.withArgument(EnumArgument.of(FlagEnum.class, "enum")))
|
||||||
.handler(c -> {
|
.handler(c -> {
|
||||||
System.out.println("Flag present? " + c.flags().isPresent("test"));
|
System.out.println("Flag present? " + c.flags().isPresent("test"));
|
||||||
System.out.println("Numerical flag: " + c.flags().getValue("num", -10));
|
System.out.println("Numerical flag: " + c.flags().getValue("num", -10));
|
||||||
|
System.out.println("Enum: " + c.flags().getValue("enum", FlagEnum.PROXI));
|
||||||
})
|
})
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
@ -222,7 +226,8 @@ class CommandTreeTest {
|
||||||
manager.executeCommand(new TestCommandSender(), "flags --test --test2").join();
|
manager.executeCommand(new TestCommandSender(), "flags --test --test2").join();
|
||||||
Assertions.assertThrows(CompletionException.class, () ->
|
Assertions.assertThrows(CompletionException.class, () ->
|
||||||
manager.executeCommand(new TestCommandSender(), "flags --test test2").join());
|
manager.executeCommand(new TestCommandSender(), "flags --test test2").join());
|
||||||
manager.executeCommand(new TestCommandSender(), "flags --num 500");
|
manager.executeCommand(new TestCommandSender(), "flags --num 500").join();
|
||||||
|
manager.executeCommand(new TestCommandSender(), "flags --num 63 --enum potato --test").join();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -259,4 +264,12 @@ class CommandTreeTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public enum FlagEnum {
|
||||||
|
POTATO,
|
||||||
|
CARROT,
|
||||||
|
ONION,
|
||||||
|
PROXI
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,8 @@ import cloud.commandframework.annotations.specifier.Greedy;
|
||||||
import cloud.commandframework.arguments.CommandArgument;
|
import cloud.commandframework.arguments.CommandArgument;
|
||||||
import cloud.commandframework.arguments.parser.ParserParameters;
|
import cloud.commandframework.arguments.parser.ParserParameters;
|
||||||
import cloud.commandframework.arguments.parser.StandardParameters;
|
import cloud.commandframework.arguments.parser.StandardParameters;
|
||||||
|
import cloud.commandframework.arguments.standard.EnumArgument;
|
||||||
|
import cloud.commandframework.arguments.standard.IntegerArgument;
|
||||||
import cloud.commandframework.bukkit.BukkitCommandManager;
|
import cloud.commandframework.bukkit.BukkitCommandManager;
|
||||||
import cloud.commandframework.bukkit.BukkitCommandMetaBuilder;
|
import cloud.commandframework.bukkit.BukkitCommandMetaBuilder;
|
||||||
import cloud.commandframework.bukkit.CloudBukkitCapabilities;
|
import cloud.commandframework.bukkit.CloudBukkitCapabilities;
|
||||||
|
|
@ -254,6 +256,17 @@ public final class ExamplePlugin extends JavaPlugin {
|
||||||
})
|
})
|
||||||
.execute(() -> context.getSender().sendMessage("DONE!"))
|
.execute(() -> context.getSender().sendMessage("DONE!"))
|
||||||
));
|
));
|
||||||
|
manager.command(manager.commandBuilder("give")
|
||||||
|
.senderType(Player.class)
|
||||||
|
.argument(EnumArgument.of(Material.class, "material"))
|
||||||
|
.argument(IntegerArgument.of("amount"))
|
||||||
|
.handler(c -> {
|
||||||
|
final Material material = c.get("material");
|
||||||
|
final int amount = c.get("amount");
|
||||||
|
final ItemStack itemStack = new ItemStack(material, amount);
|
||||||
|
((Player) c.getSender()).getInventory().addItem(itemStack);
|
||||||
|
c.getSender().sendMessage("You've been given stuff, bro.");
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@CommandMethod("example help [query]")
|
@CommandMethod("example help [query]")
|
||||||
|
|
|
||||||
|
|
@ -2,3 +2,4 @@ name: ExamplePlugin
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
api-version: 1.13
|
api-version: 1.13
|
||||||
main: cloud.commandframework.examples.bukkit.ExamplePlugin
|
main: cloud.commandframework.examples.bukkit.ExamplePlugin
|
||||||
|
depends: [Essentials]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue