Solved Command not working

Discussion in 'Plugin Development' started by bodhistrontg, Nov 30, 2013.

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

    bodhistrontg

    Code:java
    1. ublic boolean onCommand(CommandSender sender, Command cmd,
    2. String commandLabel, String[] args) {
    3. Player player = (Player) sender;
    4. if (commandLabel.equalsIgnoreCase("test")) {
    5. Skeleton skeleton = (Skeleton) player.getLocation().getWorld()
    6. .spawn(player.getLocation(), Skeleton.class);
    7.  
    8. ItemStack axe = new ItemStack(Material.DIAMOND_AXE);
    9. skeleton.getEquipment().setItemInHand(axe);
    10. }
    11. return true;
    12. }

    The commands in my plugin never work but other commands in other plugins work all it is doing is running the usage thing in my plugin.yml it is happening with all the commands i have tryed
     
  2. Offline

    the_merciless

    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
     
            if (cmd.getName().equalsIgnoreCase("test")) {
               
                if (sender instanceof Player){
                    Player player = (Player) sender;
                   
                    Skeleton skeleton = (Skeleton) player.getLocation().getWorld().spawn(player.getLocation(), Skeleton.class);
                    ItemStack axe = new ItemStack(Material.DIAMOND_AXE);
                    skeleton.getEquipment().setItemInHand(axe);
                   
                }else{
                    sender.sendMessage("Only a player can use this command.");
                }
                return true;
            }           
            return false;         
        }          
     
  3. Offline

    bodhistrontg

    the_merciless now that i have
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    2.  
    3. if (cmd.getName().equalsIgnoreCase("test")) {
    4.  
    5. if (sender instanceof Player){
    6. Player player = (Player) sender;
    7.  
    8. Skeleton skeleton = (Skeleton) player.getLocation().getWorld().spawn(player.getLocation(), Skeleton.class);
    9. ItemStack axe = new ItemStack(Material.DIAMOND_AXE);
    10. skeleton.getEquipment().setItemInHand(axe);
    11.  
    12. }else{
    13. sender.sendMessage("Only a player can use this command.");
    14. }
    15. return true;
    16. }
    17. return false;
    18. }
    19. }

    It still just puts out the usage message.
     
  4. Offline

    the_merciless

    Paste any errors / paste plugin.yml
     
  5. Offline

    bodhistrontg

    Im not seeing any errors in the console also note when you do test in the consle it displays the usage message also

    plugin.yml
    Code:
    name: Mario
    main: me.bodhistrontg.Mairo.Main
    version: 1.7.2
    commands:
        test:
            usage: /test
            description: Spawns skeely with dAxe
     
  6. Offline

    the_merciless

    Hmm, Entire class please!
     
  7. Offline

    bodhistrontg

    I have 6 classes? you just want the one its in the_merciless
     
  8. Offline

    the_merciless

    and the main
     
  9. Offline

    bodhistrontg

    Class its in
    Code:java
    1. package me.bodhistrontg.Mario;
    2.  
    3. import org.bukkit.Location;
    4. import org.bukkit.Material;
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.entity.EntityType;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.entity.Skeleton;
    10. import org.bukkit.event.EventHandler;
    11. import org.bukkit.event.Listener;
    12. import org.bukkit.event.entity.ProjectileHitEvent;
    13. import org.bukkit.inventory.ItemStack;
    14.  
    15. public class Mobs
    16. implements Listener
    17. {
    18. public Mobs(Main pl)
    19. {
    20. }
    21.  
    22. @EventHandler
    23. public void onNoMoreBlockBreak(ProjectileHitEvent event)
    24. {
    25. if (event.getEntityType() == EntityType.FIREBALL) {
    26. Location fb = event.getEntity().getLocation();
    27. fb.getWorld().createExplosion(fb.getX(), fb.getY(), fb.getZ(), 2.0F, false, false);
    28. }
    29. }
    30. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    31.  
    32. if (cmd.getName().equalsIgnoreCase("test")) {
    33.  
    34. if (sender instanceof Player){
    35. Player player = (Player) sender;
    36.  
    37. Skeleton skeleton = (Skeleton) player.getLocation().getWorld().spawn(player.getLocation(), Skeleton.class);
    38. ItemStack axe = new ItemStack(Material.DIAMOND_AXE);
    39. skeleton.getEquipment().setItemInHand(axe);
    40.  
    41. }else{
    42. sender.sendMessage("Only a player can use this command.");
    43. }
    44. return true;
    45. }
    46. return false;
    47. }
    48. }


    Main class
    package me.bodhistrontg.Mario;

    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.entity.Fireball;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.util.Vector;

    public class Main extends JavaPlugin
    {
    int radius = 21;

    public void onDisable()
    {
    getLogger().info("Plugin has been Disabled");
    }

    public void onEnable()
    {
    getLogger().info("Plugin has been Enabled");
    getServer().getPluginManager().registerEvents(new Arena(this), this);
    getServer().getPluginManager().registerEvents(new TheScoreBoard(this), this);
    getServer().getPluginManager().registerEvents(new powerups(this), this);
    getServer().getPluginManager().registerEvents(new Mobs(this), this);
    getServer().getPluginManager().registerEvents(new Sage1Flag(this), this);

    Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    public void run() {
    for (Player o : Bukkit.getOnlinePlayers())
    for (int x = -Main.this.radius; x <= Main.this.radius; x++)
    for (int y = -Main.this.radius; y <= Main.this.radius; y++)
    for (int z = -Main.this.radius; z <= Main.this.radius; z++) {
    Location loc = o.getLocation().getBlock().getRelative(x, y, z).getLocation();
    Location l = o.getLocation().getBlock().getRelative(x, y + 2, z).getLocation();
    if (loc.getBlock().getType() == Material.DISPENSER) {
    Fireball fireball = (Fireball)Bukkit.getWorld("world").spawn(l, Fireball.class);
    Vector direction = new Vector(o.getLocation().getBlockX() - l.getBlockX(), o.getLocation().getBlockY() - l.getBlockY(), o.getLocation().getBlockZ() - l.getBlockZ());
    fireball.setDirection(direction);
    }
    }
    }
    }
    , 0L, 45L);
    }
    }
     
  10. Offline

    sgtcaze

    Mobs class has to implement command executor, and then you set it up in the onEnable method

    Code:java
    1. getCommand("test").setExecutor(new Mobs(this));
     
    bodhistrontg likes this.
  11. Offline

    the_merciless

    Change

    Code:
    public class Mobs implements Listener
    to

    Code:
    public class Mobs implements Listener, CommandExecutor
    and in your onEnable you need to add:

    Code:
    getCommand("test").setExecutor(new Mobs(this));
     
    bodhistrontg likes this.
Thread Status:
Not open for further replies.

Share This Page