Commands dont run in game! HELP!

Discussion in 'Plugin Development' started by kiritai, Mar 2, 2014.

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

    kiritai

    I have been trying to develop a plugin that allows scratch cards. but when I run the command in game nothing happens what so ever. please help.

    package me.blackOps.ScratchCards;


    import org.bukkit.Material;

    import org.bukkit.ChatColor;

    import org.bukkit.command.Command;

    import org.bukkit.command.CommandSender;

    import org.bukkit.entity.Player;

    import org.bukkit.plugin.RegisteredServiceProvider;

    import org.bukkit.plugin.java.JavaPlugin;

    import org.bukkit.inventory.ItemStack;

    import org.bukkit.enchantments.Enchantment;


    import net.milkbowl.vault.economy.Economy;

    import java.util.Random;


    publicclass ScratchCards extends JavaPlugin{


    publicstatic Economy econ = null;


    @Override

    publicvoid onDisable() {

    getLogger().info(String.format("[%s] Disabled Version %s", getDescription().getName(), getDescription().getVersion()));


    }



    @Override

    publicvoid onEnable() {

    getLogger().info("ScratchCards " + getDescription().getVersion() + " is enabled!");

    if (!setupEconomy() ) {

    getLogger().severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));

    getServer().getPluginManager().disablePlugin(this);

    return;


    }

    }



    privateboolean setupEconomy() {

    if (getServer().getPluginManager().getPlugin("Vault") == null) {

    returnfalse;


    }

    RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);

    if (rsp == null) {

    returnfalse;


    }

    econ = rsp.getProvider();

    returnecon != null;


    }



    @SuppressWarnings("deprecation")

    publicboolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {


    Player player = (Player) sender;

    if(commandLabel.equalsIgnoreCase("scratchcards")){

    player.sendMessage(ChatColor.RED + "Available Cards: ");

    player.sendMessage(ChatColor.GREEN + "1) 64 Golden Apples - 20% chance to win!");

    player.sendMessage(ChatColor.BLUE + "2) 64 Emerald Blocks - 15% chance to win!");

    player.sendMessage(ChatColor.YELLOW + "3) Semi-Op pickaxe - 5% chance to win!");

    player.sendMessage(ChatColor.AQUA + "4) Op pickaxe - 1% chance to win!");




    }



    if(commandLabel.equalsIgnoreCase("scratchbuy1")){

    if(econ.hasAccount(null)){

    econ.withdrawPlayer(player.getName(), 1000);

    econ.bankWithdraw(player.getName(), 1000);

    Random random = new Random();

    int max1 = 100;

    if(random.nextInt(max1) < 20){

    player.getInventory().addItem(new ItemStack(Material.GOLDEN_APPLE, 64));


    player.updateInventory();



    }else{

    player.sendMessage(ChatColor.RED + "You Lost! Better luck next time!");




    }



    }

    }









    if(commandLabel.equalsIgnoreCase("scratchbuy2")){

    if(econ.hasAccount(null)){

    econ.withdrawPlayer(player.getName(), 1000);

    econ.bankWithdraw(player.getName(), 1000);

    Random random = new Random();

    int max2 = 100;

    if(random.nextInt(max2) < 15){

    player.sendMessage(ChatColor.BLUE + "You won 64 Emerald Blocks!");

    player.getInventory().addItem(new ItemStack(Material.EMERALD_BLOCK, 64));


    player.updateInventory();

    }else{

    player.sendMessage(ChatColor.RED + "You Lost! Better luck next time!");


    }

    }

    }





    if(commandLabel.equalsIgnoreCase("scratchbuy3")){

    if(econ.hasAccount(null)){

    econ.withdrawPlayer(player.getName(), 1000);

    econ.bankWithdraw(player.getName(), 1000);

    Random random = new Random();

    int max3 = 100;

    if(random.nextInt(max3) < 5){

    ItemStack dpick = new ItemStack(Material.DIAMOND_PICKAXE);

    dpick.addEnchantment(Enchantment.DIG_SPEED, 5);

    dpick.addEnchantment(Enchantment.LOOT_BONUS_BLOCKS, 5);

    dpick.addEnchantment(Enchantment.DURABILITY, 5);

    player.getInventory().addItem(new ItemStack(dpick));


    player.updateInventory();

    }else{

    player.sendMessage(ChatColor.RED + "You Lost! Better luck next time!");




    }

    }



    }





    if(commandLabel.equalsIgnoreCase("scratchbuy4")){

    if(econ.hasAccount(null)){

    econ.withdrawPlayer(player.getName(), 1000);

    econ.bankWithdraw(player.getName(), 1000);

    Random random = new Random();

    int max1 = 5000;

    if(random.nextInt(max1) < 1){

    ItemStack dpick = new ItemStack(Material.DIAMOND_PICKAXE);

    dpick.addEnchantment(Enchantment.DIG_SPEED, 15);

    dpick.addEnchantment(Enchantment.LOOT_BONUS_BLOCKS, 15);

    dpick.addEnchantment(Enchantment.DURABILITY, 15);

    player.getInventory().addItem(new ItemStack(dpick));


    player.updateInventory();



    }else{

    player.sendMessage(ChatColor.RED + "You Lost! Better luck next time!");




    }



    }



    }

    returnfalse;


    }



    }
     
  2. Offline

    caseif

    Please don't give us several hundred lines of code and a ridiculously broad problem description and expect us to fix it for you. Do some debugging. Put messages at key points in your code to see where it stops executing.
     
  3. Offline

    Barinade

  4. Offline

    Minesuchtiiii

    kiritai
    Look in the server log if there's a problem.
    If yes would be good if you post it here!
    Else: do you have add the command in the plugin.yml?
     
Thread Status:
Not open for further replies.

Share This Page