Solved Need help with -Giving player items

Discussion in 'Plugin Development' started by Conor015, Jul 14, 2017.

Thread Status:
Not open for further replies.
  1. Offline


    Hey, i was trying to make a plugin with a command that will give you an item. For example, i want to make a command /shockwavegive and then the player who does the command will get a diamond pick.

    Im am not sure how to do this. Does anyone have a code or something that they could share with me to help please.

    My code i have now :

    public class ShockwaveGiveCommand implements CommandExecutor {

    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (label.equalsIgnoreCase("item")) {
    Player player = (Player) sender;
    PlayerInventory inventory = player.getInventory();
    inventory.addItem(new ItemStack(Material.DIAMOND_PICKAXE));
    return true;
    return false;
    No errors occure in the software im using. But when i go ingame and do /shockwavegive is doesnt give me it. It just says this in chat.

    Last edited: Jul 14, 2017
  2. Offline

    timtower Administrator Administrator Moderator

    Moved to plugin development.
    @Conor015 Get the inventory of the player.
    Call the add method with the itemstack for a diamond pickaxe.
    Update the inventory.
  3. Offline


    I was working on the plugin and this is what happens now ^ stated in post now @timtower
    I am new to making plugins and i dont really know much about it.
  4. Offline

    timtower Administrator Administrator Moderator

    @Conor015 Check the command, not the label.
    And please don't edit your main post, just add the updated code in your reply if needed.
  5. Offline


    What do you mean? as i said, im new to all this developing and making my own plugin. Would you be able to tell me what part of the code i need to change to make it work. Thanks
  6. Offline

    timtower Administrator Administrator Moderator

    @Conor015 Please learn the basics of Java first then.
    And just like I said, check the command using Command#getName()
  7. Offline


    Can anyone else help me? Or even give me a link to someone who has a tread on how to make a basic plugin or a YouTube channel that has tutorials. Thanks
  8. Offline


    Learn Java first as Tim said. You can't run before you can walk - You can do plugin development before you know Java.
  9. Offline


    I know spoon feeding isn't welcomed here, but I'll try my best not to.
    First, you gotta check if the sender is a player. If so, create an inventory, not a player inventory, and refer it to sender.getInventory().
    Then create an itemstack using ItemStack (name) = new ItemStack(Material.<material name>);
    Now, add the itemstack to the inventory.
Thread Status:
Not open for further replies.

Share This Page