Hi, I’m using this code to execute a give command through the console. The itemname and quantity arguments are both set in the initialization command. Whenever I run my plugin, everything works fine except for this command. Any ideas on why it does not work???
As I linked in nearly a duplicate thread (are you guys clones?), Java’s still Java. Local variables don’t appear out of thin air, no matter what function you call. In this case, the CommandContext object, which you have named args, is what you’re looking for here.
And by the way, if you’re literally looking for item names, instead of GenericArguments.string, try GenericArguments.catalogedElement with ItemType.class. Sponge will parse it, provide relevant auto completes, and you can then retrieve it with args.<ItemType>getOne("itemname").get().