|
13 | 13 | import net.thenextlvl.service.hologram.HologramController; |
14 | 14 | import net.thenextlvl.service.permission.PermissionController; |
15 | 15 | import net.thenextlvl.service.plugin.ServicePlugin; |
| 16 | +import net.thenextlvl.service.plugin.commands.arguments.ControllerArgumentType; |
16 | 17 | import net.thenextlvl.service.plugin.commands.brigadier.BrigadierCommand; |
17 | 18 | import net.thenextlvl.service.plugin.commands.test.CharacterTestSuite; |
18 | 19 | import net.thenextlvl.service.plugin.commands.test.ChatTestSuite; |
@@ -48,24 +49,34 @@ public static LiteralArgumentBuilder<CommandSourceStack> create(final ServicePlu |
48 | 49 | } |
49 | 50 |
|
50 | 51 | private <C extends Controller> LiteralArgumentBuilder<CommandSourceStack> buildSuite(final String name, final TestSuite.Entry<C> entry) { |
51 | | - return Commands.literal(name).executes(context -> { |
| 52 | + final var argument = new ControllerArgumentType<>(plugin, entry.controllerType(), (context, controller) -> true); |
| 53 | + final var provider = Commands.argument("provider", argument); |
| 54 | + return Commands.literal(name).then(provider.executes(context -> { |
| 55 | + final var controller = context.getArgument("provider", entry.controllerType()); |
| 56 | + return runSuite(context.getSource(), entry, controller); |
| 57 | + })).executes(context -> { |
52 | 58 | final var sender = context.getSource().getSender(); |
53 | 59 | final var controller = plugin.getServer().getServicesManager().load(entry.controllerType()); |
54 | 60 | final var displayName = ServiceInfoCommand.translate(plugin, sender, entry.controllerType()); |
55 | 61 |
|
56 | | - if (controller == null) { |
57 | | - plugin.bundle().sendMessage(sender, "service.missing", Placeholder.component("service", displayName)); |
58 | | - return 0; |
59 | | - } |
| 62 | + if (controller != null) return runSuite(context.getSource(), entry, controller); |
| 63 | + |
| 64 | + plugin.bundle().sendMessage(sender, "service.missing", Placeholder.component("service", displayName)); |
| 65 | + return 0; |
60 | 66 |
|
61 | | - plugin.bundle().sendMessage(sender, "service.test.started", |
62 | | - Placeholder.component("service", displayName), |
63 | | - Placeholder.parsed("provider", controller.getName())); |
64 | | - entry.factory().create(plugin, context.getSource(), controller).execute(); |
65 | | - plugin.bundle().sendMessage(sender, "service.test.completed", |
66 | | - Placeholder.component("service", displayName), |
67 | | - Placeholder.parsed("provider", controller.getName())); |
68 | | - return Command.SINGLE_SUCCESS; |
69 | 67 | }); |
70 | 68 | } |
| 69 | + |
| 70 | + private <C extends Controller> int runSuite(final CommandSourceStack source, final TestSuite.Entry<C> entry, final C controller) { |
| 71 | + final var displayName = ServiceInfoCommand.translate(plugin, source.getSender(), entry.controllerType()); |
| 72 | + |
| 73 | + plugin.bundle().sendMessage(source.getSender(), "service.test.started", |
| 74 | + Placeholder.component("service", displayName), |
| 75 | + Placeholder.parsed("provider", controller.getName())); |
| 76 | + entry.factory().create(plugin, source, controller).execute(); |
| 77 | + plugin.bundle().sendMessage(source.getSender(), "service.test.completed", |
| 78 | + Placeholder.component("service", displayName), |
| 79 | + Placeholder.parsed("provider", controller.getName())); |
| 80 | + return Command.SINGLE_SUCCESS; |
| 81 | + } |
71 | 82 | } |
0 commit comments