Command Doesn't Do Anything

Discussion in 'Plugin Development' started by dotJar1, Nov 25, 2016.

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

    dotJar1

    So I wrote all of this out and whenever I do /prizewheel it doesn't work. What is supposed to happen is it generates a random number and depending on what number it is, you get certain items. But whenever I run the command in game it doesn't do anything, it doesn't even message me or do anything.

    Code:
    package terroristCommand.bukkit._Nich;
    
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class terroristCommand extends JavaPlugin {
        @Override
        public void onEnable() {
            getLogger().info("NichPrizes: onEnable has been now enabled");
        }
        @Override
        public void onDisable() {
           
        }
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
           
            if (cmd.getName().equalsIgnoreCase("prizewheel") && sender instanceof Player ){
                Player player = (Player) sender;
                String item = "";
                //player.setCanPickupItems(false);
                double random = Math.random();
                if(random > 0.0 && random < 0.1){
                    //give player ultra item
                    ItemStack[] items = {new ItemStack (Material.GOLD_INGOT, 7), new ItemStack (Material.IRON_INGOT, 7), new ItemStack (Material.DIAMOND, 5), new ItemStack (Material.EMERALD, 6)};
                    player.getInventory().addItem(items);
                    item = "n \u00A6\u00A7lULTRA";
                }
                if(random > 0.1 && random < 0.2){
                    //give player epic item
                    ItemStack[] items = {new ItemStack (Material.GOLD_INGOT, 7), new ItemStack (Material.IRON_INGOT, 6), new ItemStack (Material.EMERALD, 5)};
                    player.getInventory().addItem(items);
                    item = "n \u00Aa\u00A7lEPIC";
                }
                if(random > 0.2 && random < 0.3){
                    //give player epic item
                    ItemStack[] items = {new ItemStack (Material.GOLD_INGOT, 7), new ItemStack (Material.IRON_INGOT, 6), new ItemStack (Material.EMERALD, 5)};
                    player.getInventory().addItem(items);
                    item = "n \u00Aa\u00A7lEPIC";
                }
                if(random > 0.3 && random < 0.4){
                    //give player rare item
                    ItemStack[] items = {new ItemStack (Material.GOLD_INGOT, 6), new ItemStack (Material.IRON_INGOT, 5)};
                    player.getInventory().addItem(items);
                    item = "\u00A7brare";
                }
                if(random > 0.4 && random < 0.5){
                    //give player rare item
                    ItemStack[] items = {new ItemStack (Material.GOLD_INGOT, 6), new ItemStack (Material.IRON_INGOT, 5)};
                    player.getInventory().addItem(items);
                    item = "\u00A7brare";
                }
                if(random > 0.5 && random < 0.6){
                    //give player rare item
                    ItemStack[] items = {new ItemStack (Material.GOLD_INGOT, 6), new ItemStack (Material.IRON_INGOT, 5)};
                    player.getInventory().addItem(items);
                    item = "\u00A7brare";
                }
                if(random > 0.6 && random < 0.7){
                    //give player common item
                    ItemStack[] items = {new ItemStack (Material.GOLD_INGOT, 5)};
                    player.getInventory().addItem(items);
                    item = "\u00A78common";
                }
                if(random > 0.7 && random < 0.8){
                    //give player common item
                    ItemStack[] items = {new ItemStack (Material.GOLD_INGOT, 5)};
                    player.getInventory().addItem(items);
                    item = "\u00A78common";
                }
                if(random > 0.8 && random < 0.9){
                    //give player common item
                    ItemStack[] items = {new ItemStack (Material.GOLD_INGOT, 5)};
                    player.getInventory().addItem(items);
                    item = "\u00A78common";
                }
                if(random > 0.9 && random < 1){
                    //give player common item
                    ItemStack[] items = {new ItemStack (Material.GOLD_INGOT, 5)};
                    player.getInventory().addItem(items);
                    item = "\u00A78common";
                }
                ItemStack[] items = {new ItemStack (Material.GOLD_INGOT, 5)};
                player.getInventory().addItem(items);
                player.sendMessage("\u00A7a\u00A7lNichPrizes: \u00A77" + "You got a"  /*+ player.getName()*/ + item + "\u00A77item!");
               
               
                return true;
            }
           
           
           
            return false;
        }
    
       
       
    }
    

    Here is my .yml file:

    Code:
    name: TerroristCommands
    main: terroristCommand.bukkit._Nich.terroristCommand
    version: 1.0
    commands:
       prizewheel:
          description: Spin for your lucky prize!
    
     
  2. Offline

    808sFinest

    You forgot to register the command also implement CommandExecutor.
     
  3. Offline

    Zombie_Striker

    @808sFinest
    No, that is not his problem. The onCommand is in the main class so, since JavaPlugin already implements CommandExecutor, he does not need to do that.

    @dotJar1
    Remove the logger. Bukkit logs your plugins for you. Also, since your onDisable does nothing, remove it.

    Have you debugged? Does it work if you send a message before you create the "item" variable? What about the line below that? Continue moving down until the message no longer gets sent.
     
  4. Offline

    dotJar1

    @Zombie_Striker
    when I debug it I get this error.
    Error: Could not find or load main class org.bukkit.craftbukkit.libs.org.ibex.nestedvm.ClassFileCompiler
    what should I do and how do I fix this?
     
    Last edited: Nov 25, 2016
  5. Offline

    mythbusterma

    @dotJar1

    What do you mean by that? What do you do to get that error, because that looks like something that wouldn't be caused by your plugin.
     
  6. Offline

    MrGeneralQ

    I also see that you are not checking your sender instance before casting it to a player. Make sure to check that first or the plugin will generate errors.
     
  7. Offline

    DuaneTheDev_

    @dotJar1

    I grabbed the code to debug it. Works perfectly fine for me without changing anything. Did you make sure to refresh your plugin.yml before exporting?
     
  8. Offline

    projectwoosh

    The main class in plugin.yml must be the same as yout main class
     
  9. Offline

    dotJar1

    I tried running this on my desktop and everything was just fine... weird. Thank you everyone for your help, especially you @projectwoosh because I screwed around with the .yml file a little.
     
  10. Offline

    Zombie_Striker

    @dotJar1
    If your problem has been solved, mark this thread as solved.
     
  11. Offline

    projectwoosh

    No problem
     
Thread Status:
Not open for further replies.

Share This Page