[Help] What's wrong with this code ?

Discussion in 'Plugin Development' started by q8minecraft, Oct 6, 2014.

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

    q8minecraft

    I am new to making plugins and coding. And I got the idea from a thread in another forums. Can someone tell me whats wrong with the code please ? I can't seem to find any errors and it won't start on my server..
    Code:
    package me.q8minecraft.heal;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Effect;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Heal extends JavaPlugin {
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String args[]){;
        if (commandLabel.equalsIgnoreCase("Heal")){
            Player player = (Player) sender;
            player.sendMessage(ChatColor.AQUA + "This " + ChatColor.AQUA + "is" + ChatColor.AQUA + " a" + ChatColor.AQUA + "test!");
            player.setHealth(20F);
            player.setFoodLevel(20);
            player.setFireTicks(0);
            player.playEffect(player.getLocation(), Effect.POTION_BREAK, 16421);
        }
        return false;
        }
     
    }
    
     
  2. Offline

    CraftCreeper6

    q8minecraft
    Have you put your command in your plugin.yml?
     
  3. Offline

    DevSock

    There are quite a few things wrong with your code.
    1. You're casting a player to the sender without checking if the sender is indeed a player.
    2. Your boolean will always return false because within your first if statement you don't have a return statement.
    3. Typically you shouldn't have casing within an equalsIgnoreCase check.
    4. You've got a semicolon after your first curly brace with your onCommand boolean.


    If fixing these didn't solve your issue, please post the console error log when it tries to load the command.
     
  4. Offline

    fireblast709

    q8minecraft have you registered heal as command in plugin.yml? Also:
    • Use cmd.getName() rather than commandLabel for alias support
    • Check if sender instanceof Player before casting to Player
     
  5. Offline

    q8minecraft

    I've put this
    Code:
    name: Heal
    main: me.q8minercaft.heal
    version: 1.0
    commands:/heal
      heal:
          description: Heal and feed the player.
          usage: /heal
     
  6. Offline

    Minesuchtiiii

    Should look like this

    Code:
    name: Heal
    main: me.q8minercaft.heal
    version: 1.0
    commands:/heal
      heal:
        description: Heal and feed the player.
        usage: /heal
    And BTW you don't need after every new String to put a color code, you can change it to:

    Code:java
    1. player.sendMessage(ChatColor.AQUA + "This is a test!");
     
  7. Offline

    fireblast709

    q8minecraft remove the /heal after 'commands:'. Moreover, your main only contains your package, and lacks your main class. It has to be 'me.q8minercraft.heal.Heal'
     
    q8minecraft likes this.
  8. Offline

    q8minecraft

    Alright! Thanks! Can you just fix it and send to me ? Just to see what mistakes I did. It would be awesome! But if you can't its okay. I'll try to do it myself!
     
  9. Offline

    ChipDev

    commands:/heal
    the command in chat would be //heal, if you have /heal
     
  10. Offline

    q8minecraft

    Yea I've deleted it.
     
  11. Offline

    ChipDev

    Ok.
     
  12. Offline

    FabeGabeMC

    q8minecraft That would be spoonfeeding you the code, which will teach you nothing.
     
Thread Status:
Not open for further replies.

Share This Page