feat(command): get equipment command

This commit is contained in:
darksaid98 committed 2023-10-25 04:27:38 +02:00
1 parent 1cf01d691f
commit c4d2b6e967
2 files changed
+32 -1

No files matched your search

+1 -1
View File
@@ -6,7 +6,7 @@
<groupId>com.github.alathra</groupId> <groupId>com.github.alathra</groupId>
<artifactId>SiegeEngines</artifactId> <artifactId>SiegeEngines</artifactId>
<version>0.4.0</version> <version>0.5.0</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>SiegeEngines</name> <name>SiegeEngines</name>
@@ -30,6 +30,7 @@ public class SiegeEnginesCommand {
.withShortDescription("Example command.") .withShortDescription("Example command.")
.withPermission("siegeengines.command") .withPermission("siegeengines.command")
.withSubcommands( .withSubcommands(
commandGet(),
commandGetAll(), commandGetAll(),
commandReload() commandReload()
) )
@@ -41,6 +42,22 @@ public class SiegeEnginesCommand {
sender.sendMessage(ColorParser.of("<yellow>Incorrect usage, /SiegeEngines get, /SiegeEngines reload").build()); sender.sendMessage(ColorParser.of("<yellow>Incorrect usage, /SiegeEngines get, /SiegeEngines reload").build());
} }
private CommandAPICommand commandGet() {
return new CommandAPICommand("get")
.withPermission("siegeengines.command.get")
.withArguments(
new StringArgument("equipmentid")
.replaceSuggestions(
ArgumentSuggestions.strings(
DefinedEquipment.values().stream().map(gunnerEquipment -> gunnerEquipment.EquipmentId).toList()
)
),
new PlayerArgument("target")
.setOptional(true)
)
.executesPlayer(this::onGet);
}
private CommandAPICommand commandGetAll() { private CommandAPICommand commandGetAll() {
return new CommandAPICommand("getAll") return new CommandAPICommand("getAll")
.withPermission("siegeengines.command.getAll") .withPermission("siegeengines.command.getAll")
@@ -53,6 +70,20 @@ public class SiegeEnginesCommand {
.executesPlayer(this::onReload); .executesPlayer(this::onReload);
} }
private void onGet(CommandSender sender, CommandArguments args) throws WrapperCommandSyntaxException {
if (!(args.get("equipmentid") instanceof String equipmentId))
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>Invalid equipment id specified.").build());
Player player = (Player) args.getOptional("target").orElse(sender);
for (GunnerEquipment gunnerEquipment : DefinedEquipment.values()) {
if (gunnerEquipment.equals(equipmentId)) {
giveEquipment(player, gunnerEquipment);
break;
}
}
}
private void onGetAll(CommandSender sender, CommandArguments args) throws WrapperCommandSyntaxException { private void onGetAll(CommandSender sender, CommandArguments args) throws WrapperCommandSyntaxException {
if (!(sender instanceof Player player)) if (!(sender instanceof Player player))
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>Only players can use this command.").build()); throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>Only players can use this command.").build());