mirror of
https://github.com/darksaid98/SiegeEngines.git
synced 2026-12-01 22:22:10 +00:00
feat(command): get equipment command
This commit is contained in:
2 files changed
+32
-1
No files matched your search
@@ -30,6 +30,7 @@ public class SiegeEnginesCommand {
|
||||
.withShortDescription("Example command.")
|
||||
.withPermission("siegeengines.command")
|
||||
.withSubcommands(
|
||||
commandGet(),
|
||||
commandGetAll(),
|
||||
commandReload()
|
||||
)
|
||||
@@ -41,6 +42,22 @@ public class SiegeEnginesCommand {
|
||||
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() {
|
||||
return new CommandAPICommand("getAll")
|
||||
.withPermission("siegeengines.command.getAll")
|
||||
@@ -53,6 +70,20 @@ public class SiegeEnginesCommand {
|
||||
.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 {
|
||||
if (!(sender instanceof Player player))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>Only players can use this command.").build());
|
||||
|
||||
Reference in new issue
Block a user