Command Not Registering

Discussion in 'Plugin Development' started by videogamemasta1, Jan 18, 2014.

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

    videogamemasta1

    I made a test plugin which is very basic, all it does is heal and i decided to also throw in a line that only allows op's to use it. and when i put it on my server and start it up, all is well until i actually try to use it. When i do the command /ophealme which is the command to heal myself, nothing happens. it doesn't heal me nor does it give me the message that says it heals me. although it does say i did do it in the console without error.

    Class
    Code:java
    1. package main;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.material.Command;
    9. import org.bukkit.plugin.PluginDescriptionFile;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11.  
    12. public class Function extends JavaPlugin {
    13. public static Function plugin;
    14. public final Logger logger = Logger.getLogger("Minecraft");
    15.  
    16. @Override
    17. public void onDisable() {
    18. PluginDescriptionFile pdfFile = this.getDescription();
    19. this.logger.info(pdfFile.getName() + "Has Been Disabled!");
    20. }
    21.  
    22. @Override
    23. public void onEnable() {
    24. PluginDescriptionFile pdfFile = this.getDescription();
    25. this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + "Has Been Enabled");
    26. }
    27. public boolean onCommand(CommandSender sender, Command cmd, String commandlabel, String[] args){
    28. Player player = (Player) sender;
    29. if(commandlabel.equalsIgnoreCase("ophealme")){
    30. if(args.length == 0){
    31. player.sendMessage("Invalid Input");
    32. }else{
    33. player.setHealth(20.0);
    34. player.setFireTicks(0);
    35. player.sendMessage(ChatColor.GOLD + "You Have Been Healed So Awesomely Because Your An Op!");
    36. }
    37. if(player.isOp() == false){
    38. player.sendMessage("You Are Not Op!");
    39. }
    40. }
    41. return false;
    42. }
    43. }
    44.  


    Plugin.YML
    Code:
    name: opheal
    main: main.Function
    version: 1.0
    description: >
                Healing For Operators!.
    commands:
      ophealme:
        description: Healing For Operators!
     
  2. Offline

    Blingdaddy1

    First off, do not use commandLabel do
    if (cmd.getName().equalsIGnoreCase("ophealme")) {

    also change if (player.isOp() == false) { to
    if (!(player.isOp() {

    also, return true; one bracket above return false;
     
  3. Offline

    Mattigins

    Implemented everything that Blingdaddy1 said and also fixed the "you're*"

    Code:java
    1. package main;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.material.Command;
    9. import org.bukkit.plugin.PluginDescriptionFile;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11.  
    12. public class Function extends JavaPlugin {
    13. public static Function plugin;
    14. public final Logger logger = Logger.getLogger("Minecraft");
    15.  
    16. @Override
    17. public void onDisable() {
    18. PluginDescriptionFile pdfFile = this.getDescription();
    19. this.logger.info(pdfFile.getName() + "Has Been Disabled!");
    20. }
    21.  
    22. @Override
    23. public void onEnable() {
    24. PluginDescriptionFile pdfFile = this.getDescription();
    25. this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + "Has Been Enabled");
    26. }
    27. public boolean onCommand(CommandSender sender, Command cmd, String commandlabel, String[] args){
    28. Player player = (Player) sender;
    29. if (cmd.getName().equalsIgnoreCase("ophealme")){
    30. if(args.length == 0){
    31. player.sendMessage("Invalid Input");
    32. }else{
    33. player.setHealth(20.0);
    34. player.setFireTicks(0);
    35. player.sendMessage(ChatColor.GOLD + "You Have Been Healed So Awesomely Because You're An Op!");
    36. }
    37. if(!player.isOp()){
    38. player.sendMessage("You Are Not Op!");
    39. }
    40. return true;
    41. }
    42. return false;
    43. }
    44. }
     
  4. Offline

    videogamemasta1

    It didn't work when i did what u told me to do.
     
  5. Offline

    Mattigins

    I can't see anything else wrong with it. But just so you know. The way you have it now, if you're not an OP you will get healed and then it will tell you you aren't an OP
     
  6. Offline

    videogamemasta1

    I am op though. Im really confused right now.
     
  7. check this line: if args.length==0
     
  8. Offline

    videogamemasta1

    theres no errors according to eclipse.
     
  9. Offline

    Blingdaddy1

    Here's how I would make my command
    Code:java
    1. if (cmd.getName().equalsIgnoreCase("ophealme")) {
    2. Player player = (Player) sender;
    3. if (!(player.isOp())) {
    4. player.sendMessage(ChatColor.RED + "No perms");
    5. }
    6. else if (player.isOp()) {
    7. // do stuff
    8. }
    9. return true;
    10. }
     
  10. Offline

    videogamemasta1

    Blingdaddy1 the method getname() is undefined for the type command
     
  11. Offline

    Blingdaddy1

    ... What? I've never heard of that error before.

    OH! You have this under your imports:
    org.bukkit.material.Command ?
    change it to this
    org.bukkit.command.Command

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

    videogamemasta1

    it still doesn't do the command for some reason
     
  13. Offline

    Blingdaddy1

    Can you take a screen-cap of the errors and such?
    Also, use my command template
     
  14. Offline

    videogamemasta1

  15. Offline

    Mattigins

    You aren't telling it to do anything when you have the permission..
     
  16. Offline

    videogamemasta1

    ah i see. now how would i begin to fix that?
     
  17. Offline

    AnOrangeGamer


    Code:java
    1. else if (player.isOp()) {
    2. player.setHealth(20);
    3. player.setFireTicks(0);
    4. player.sendMessage("You have been healed.");
    5. }
     
  18. Offline

    Blingdaddy1

    I dont think there needs to be a permission for commands...
     
  19. Offline

    videogamemasta1

  20. Offline

    Monkey_Swag

    videogamemasta1 are you watching BCBroz tutorials? If so, stop. They're outdated and will teach you wrong.
     
  21. Offline

    Blingdaddy1

    ^Yeah. I've learned from Skatedog27 and PogoStick29 :D
     
Thread Status:
Not open for further replies.

Share This Page