Plugin Help Additional classes for commands, command isn't working properly

Discussion in 'Plugin Help/Development/Requests' started by Alj23, Nov 30, 2014.

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

    Alj23

    Hi there! My name is Alj23, and I'm new to the Java and Bukkit world. I have a Foundations of Programming class at school that teaches that class with Java, so I figured why not take it a step further, and apply it to learning Bukkit and coding plugins!

    With that being said, the answer to this problem is probably really obvious, but since I'm still a noob, I just can't figure it out.

    I'm creating a plugin, because along with video tutorials, just doing the coding and figuring out why it works/doesn't work is the best way for me to learn.

    I'm using multiple classes for multiple commands. I've set up the first command class with CommandExecutor, etc etc. It works fine, as in it realizes that the command I'm trying to type is a command, so no problems there. What the problem is, is that when I run the command, it does nothing. It's suppose to send the player a message saying "placeholder!" (currently just a short text till I get it working properly.) I don't know why it isn't working. The command runs, so I know the command is there and is being called, but nothing happens? I have the command written down in my plugin.yml, so no issues there. I get no errors from my plugin in the console when I start the server either. I am at a complete loss :(

    Since I'm still new to this and all, I imagine I'm making some dumb mistake, but for the life of me cannot figure it out. For the longest time I thought I was doing the CommandExecutor and all associated code wrong, but then I realized that it was running the command, just something wasn't happening like I wanted it to.

    Also, if you notice me doing something I don't need to, or something that isn't general practice, feel free to bring it up and suggest a change. Still new to this and learning :)

    Possible problematic code:
    Code:java
    1. @Override
    2. public boolean onCommand(CommandSender sender, Command cmd,String commandLabel, String[] args) {
    3. if (sender instanceof Player)
    4. {
    5. Player p = (Player) sender;
    6. sender.sendMessage("placeholder!");
    7. }
    8. else
    9. {
    10. sender.sendMessage("This command can only be executed by a player!");
    11. return false;
    12. }
    13.  
    14. return false;
    15. }
    16.  
    17. }



    Main class:
    Code:java
    1. package me.Alj23.RPGClasses;
    2.  
    3. import java.util.logging.Logger;
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.plugin.java.JavaPlugin;
    6.  
    7. public class RPGClassesMain extends JavaPlugin
    8. {
    9. Logger logger = Bukkit.getLogger();
    10.  
    11. public void OnEnable()
    12. {
    13. this.getCommand("warrior").setExecutor(new WarriorInfo(this));
    14. this.logger.info("RPGClasses has been enabled!");
    15. }
    16.  
    17. public void OnDisable()
    18. {
    19. this.logger.info("RPGClass has been disabled!");
    20.  
    21.  
    22. }
    23.  
    24.  


    WarriorInfo class:
    Code:java
    1. package me.Alj23.RPGClasses;
    2.  
    3. import org.bukkit.command.Command;
    4. import org.bukkit.command.CommandExecutor;
    5. import org.bukkit.command.CommandSender;
    6. import org.bukkit.entity.Player;
    7.  
    8. public class WarriorInfo implements CommandExecutor
    9. {
    10. private final RPGClassesMain plugin;
    11.  
    12. public WarriorInfo(RPGClassesMain plugin)
    13. {
    14. this.plugin = plugin;
    15. }
    16.  
    17. @Override
    18. public boolean onCommand(CommandSender sender, Command cmd,String commandLabel, String[] args) {
    19. if (sender instanceof Player)
    20. {
    21. Player p = (Player) sender;
    22. sender.sendMessage("placeholder!");
    23. }
    24. else
    25. {
    26. sender.sendMessage("This command can only be executed by a player!");
    27. return false;
    28. }
    29.  
    30. return false;
    31. }
    32.  
    33. }
    34.  

     
  2. Offline

    haussik

    @ Alj23

    if(cmd.getName().equalsIgnoreCase("your command"){
    //do something
    }

    Did you forgot it ?

    Code:java
    1. @Override
    2. public boolean onCommand(CommandSender sender, Command cmd,String commandLabel, String[] args) {
    3. if(cmd.getName().equalsIgnoreCase("warrior"){
    4. if (sender instanceof Player)
    5. {
    6. Player p = (Player) sender;
    7. sender.sendMessage("placeholder!");
    8. }
    9. else
    10. {
    11. sender.sendMessage("This command can only be executed by a player!");
    12. return false;
    13. }
    14. }


    try this

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

    Alj23

    Nope. Neither of these worked. Funnily enough, I swear, that in almost ever tutorial I've read or video I watched, the whole cmd.getName part in the command class is non-existent. That's why I never had it to start with. I think it's not there because the command is referenced here in the main class:
    Code:java
    1. this.getCommand("warrior").setExecutor(new WarriorInfo(this));
     
  4. Offline

    haussik

    The simpliest code, if that doesnt work i don't know ._.

    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label,String[] args) {
    2.  
    3. if (cmd.getName().equalsIgnoreCase("warrior")){
    4. if(!(sender instanceof Player)){
    5.  
    6. System.out.println("No!");
    7.  
    8. }else{
    9.  
    10. Player player = (Player) sender; sender.sendMessage("HI");
    11.  
    12. return true;
    13.  
    14. }
    15. }
    16. return true;
    17. }
    18. }
     
  5. Offline

    Alj23

    Didn't work :(
    I have no clue why. Everything appears to be right, although it's obvious we're still missing something.
     
  6. Offline

    haussik

    Alj23
    Show me your plugin.yml
     
  7. Offline

    Alj23

    Here it is. Unless I'm completely unaware of something you have to do once you start utilizing other classes, everything here is fine.

    Code:
    name: RPGClasses
    version: 1.0
    main: me.Alj23.RPGClasses.RPGClassesMain
    description: Choose beyond a wide scope of classes!
    commands:
      warrior:
        description: Shows info on the warrior class!
    
     
  8. Offline

    haussik

    Wierd.. your code work fine on my side, sorry i don't know ^^
     
  9. Offline

    Alj23

    You got it to run perfectly fine? Could you possibly post it here?
     
  10. Offline

    haussik

    I did the same as you did, everything work, go follow some tutorial on youtube :p
     
  11. Offline

    Alj23

    The exact same code? Can you just post it here please?

    Fixed. I had typed OnEnable and OnDisable, instead of onEnable and onDisable. Simple case mistake. Thanks for the help guys!

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

    mrCookieSlime

    Locked on Request.
     
Thread Status:
Not open for further replies.

Share This Page