Command not working?

Discussion in 'Plugin Development' started by 1Camer0471, Jan 3, 2015.

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

    1Camer0471

    So I'm trying to make a command that allows you to give players and itemstack called tokens, here is the code I am using:
    Code (open)

    if (args.length == 1 && args[0].equalsIgnoreCase("give")) {
    final Player player = (Player) sender;

    boolean playerFound = false;

    for (Player playertogive : Bukkit.getOnlinePlayers()) {
    if (playertogive.getName().equalsIgnoreCase(args[1])) {
    //Get the amount of tokens from the third argument
    int amount = Integer.parseInt(args[2]);


    ItemStack token = new ItemStack(Material.MAGMA_CREAM, amount);
    ItemMeta meta = token.getItemMeta();
    meta.setDisplayName(ChatColor.AQUA + "" + ChatColor.BOLD + "TOKEN");
    ArrayList <String> lore = new ArrayList<String>();
    lore.add(ChatColor.GREEN + "Used to purchase items from " + ChatColor.LIGHT_PURPLE + "" + ChatColor.ITALIC + " /token shop");
    meta.setLore(lore);
    token.setItemMeta(meta);
    playertogive.getInventory().addItem(token);

    break;
    }}
    if (playerFound = false) {

    player.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "That Player was not found!");

    }



    I am not getting an errors in my console, it just says:
    [14:19:55 INFO]: Camer047 issued server command: /token give Camer047 1
    But nothing happens.
    Help?
     
  2. Offline

    ColaCraft

    Use .equals(1) and not == 1, and also, is the command registered in your plugin.yml?
     
    1Camer0471 likes this.
  3. Offline

    1Camer0471

    Yes, the command "token" is registered, this command is an arg (/token give <player> <amount>)
     
  4. Offline

    ColaCraft

    Do you return true after the args?
     
    1Camer0471 likes this.
  5. Offline

    1Camer0471

    .equals changed nothing

    I returned true at the end of the command boolean, you don't have to after every arg

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 31, 2016
  6. Offline

    adam753

    The command "/token give Camer047 1" has more than 1 arg..
     
    1Camer0471 likes this.
  7. Offline

    ColaCraft

    1Camer0471 likes this.
  8. Offline

    adam753

    He's checking args[1] and args[2] later with no more length checks, so my guess is he meant "== 3".
     
    1Camer0471 likes this.
Thread Status:
Not open for further replies.

Share This Page