|
21 | 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
22 | 22 | // SOFTWARE. |
23 | 23 | // |
24 | | -package cloud.commandframework.examples.sponge; |
| 24 | +package org.incendo.cloud.examples.sponge; |
25 | 25 |
|
26 | 26 | import com.google.inject.Inject; |
27 | 27 | import com.google.inject.Injector; |
|
40 | 40 | import org.incendo.cloud.description.Description; |
41 | 41 | import org.incendo.cloud.execution.ExecutionCoordinator; |
42 | 42 | import org.incendo.cloud.minecraft.extras.MinecraftExceptionHandler; |
| 43 | +import org.incendo.cloud.parser.ArgumentParseResult; |
43 | 44 | import org.incendo.cloud.parser.standard.StringParser; |
44 | 45 | import org.incendo.cloud.permission.PredicatePermission; |
45 | 46 | import org.incendo.cloud.sponge.CloudInjectionModule; |
|
50 | 51 | import org.incendo.cloud.sponge.data.MultipleEntitySelector; |
51 | 52 | import org.incendo.cloud.sponge.data.ProtoItemStack; |
52 | 53 | import org.incendo.cloud.sponge.data.SinglePlayerSelector; |
53 | | -import org.incendo.cloud.type.tuple.Pair; |
| 54 | +import org.incendo.cloud.sponge.exception.ComponentMessageRuntimeException; |
54 | 55 | import org.spongepowered.api.ResourceKey; |
55 | 56 | import org.spongepowered.api.Sponge; |
56 | 57 | import org.spongepowered.api.command.CommandCause; |
@@ -403,12 +404,16 @@ private void registerCommands() { |
403 | 404 | .requiredArgumentPair( |
404 | 405 | "itemstack", |
405 | 406 | TypeToken.get(ItemStack.class), |
406 | | - Pair.of("item", "amount"), |
407 | | - Pair.of(ProtoItemStack.class, Integer.class), |
408 | | - (sender, pair) -> { |
409 | | - final ProtoItemStack proto = pair.first(); |
410 | | - final int amount = pair.second(); |
411 | | - return proto.createItemStack(amount, true); |
| 407 | + "item", protoItemStackParser(), |
| 408 | + "amount", integerParser(), |
| 409 | + (sender, proto, amount) -> { |
| 410 | + try { |
| 411 | + return ArgumentParseResult.successFuture( |
| 412 | + proto.createItemStack(amount, true) |
| 413 | + ); |
| 414 | + } catch (final ComponentMessageRuntimeException e) { |
| 415 | + return ArgumentParseResult.failureFuture(e); |
| 416 | + } |
412 | 417 | }, |
413 | 418 | Description.of("The ItemStack to give") |
414 | 419 | ) |
|
0 commit comments