Player Doesn't Recieve The ItemStack

Discussion in 'Plugin Development' started by KingOfTheEast01, Jan 15, 2017.

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


    Hey guys, my name is Lucas. I am somewhat new to Bukkit Coding, but have the basics down, so don't worry about explaining anything too in depth to me. Anyways, here's my problem. I can't seem to get my plugin to give me the item I want it to. Basically, I'm trying to give a player who runs the command /vam money voucher (amount) a voucher with a specific display name and item meta that I've specified. For some reason, the command registers, but no error is given, nor do I receive the item. The last error I got from the code told me there was an error in the line of code where I added the specified ItemStack to the player's inventory. What can I do to fix my problem? Thank you guys for any help you can provide. :D

    Here's my code now:

    My main class:

    package com.thechocolatedev;
    public class VAMFront extends JavaPlugin {
        public void onEnable() {
            getServer().getPluginManager().registerEvents(new MoneyRedeem(), this);
            getCommand("vam").setExecutor(new MoneyVouchCom());
    My command class:

    package com.thechocolatedev;
    import java.util.Arrays;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    public class MoneyVouchCom implements CommandExecutor{
        public boolean onCommand(CommandSender sender, Command com, String label, String[] args) {
            //An if statement checking to see if the sender is a player or not
            if(!(sender instanceof Player)) {
                //Warn the command executor they are using the command in the wrong place
                sender.sendMessage("This command cannot be executed by console personnel. Please try again in-game");
            else {
                //An if statement to check to see if the command and args are correct
                //Command: /vam. Arg 1: money. Arg 2: voucher Arg 3: (Amount of money to be on the voucher).
                if(com.getName().equalsIgnoreCase("vam") && args.length == 3 && args[0].equalsIgnoreCase("money") && args[1].equalsIgnoreCase("voucher")) {
                    //Set a player variable as the sender
                    Player player = (Player) sender;
                    //A debug test
                    player.sendMessage("Test Complete");
                    /* Create the material of the voucher and set an amount for the item stack
                    and create a new item stack based off of those variables */
                    Material material = Material.PAPER;
                    int amount = 0;
                    ItemStack moneyVouch = new ItemStack(material, amount);
                    //Get the item meta and change the name and lore
                    ItemMeta mvMeta = moneyVouch.getItemMeta();
                    mvMeta.setDisplayName(ChatColor.GREEN + "Money" + ChatColor.YELLOW + "Voucher");
                    mvMeta.setLore(Arrays.asList(ChatColor.DARK_AQUA + "Right-click to redeem", ChatColor.GREEN + "$" + args[2]));
                    //Get the player's inventory and put the money voucher in the next available slot
                    Inventory playerInv = player.getInventory();
            return false;
    My plugin.yml:

    name: VAM
    version: 1.0
    main: com.thechocolatedev.VAMFront
    author: CallMeFilmsTCD
      description: Lists all VAM commands
  2. Offline


    Return false if this is the case. Currently, this sends the message if the sender is not a player, but then does nothing about it and continues.

    Do you receive the "Test worked" message?
  3. Offline


    Yes, I do receive the test message. In fact, I actually got an error before telling me the line containing
    playerInv.addItem(moneyVouch); was the problem, but I changed a little since then. However, I am still convinced the changing of the inventory is the problem. I also got an error before about the item itself. I don't know what exactly is the problem, but I'm sure it has to do with either creating the ItemStack or putting it in the inventory.
Thread Status:
Not open for further replies.

Share This Page