Multiple Commands, Something i can never figure out...

Discussion in 'Plugin Development' started by yewtree8, Feb 24, 2014.

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

    yewtree8

    So it says it all in the title, if tried all sorts of things like else { and else if { but it just gives me erors, and when i just do nif for the second time, it sends me both messages in the plugin, apparently i need executors? can someone give me an example and explain to me how i would do this successfully?
    person to answer will get a like.

    Thanks

    - Mat
     
  2. Offline

    ImPhantom

    Would you mind posting some Example code? I'm not quite sure what your getting at here.
     
  3. Offline

    sockmonkey1

    Make another command file and in the onenable put
    getCommand("command").setExecutor(new commandFile());
     
  4. Offline

    yewtree8


    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    2. if(commandLabel.equalsIgnoreCase("first"));
    3. Player player = (Player) sender;{
    4. player.sendMessage("this command worked");
    5. }
    6.  
    7. if(commandLabel.equalsIgnoreCase("second")); {
    8. player.sendMessage("This second command worked");
    9. }
    10.  
    11. return false;



    when i do the second command both messages come up? could you fix this code so it would work?
     
  5. Offline

    GriffinPvP

    You need to stop the code below the first command from running, like so:

    Code:java
    1. public boolean onCommand(CommandSender sender, Command command, String name, String[] args) {
    2. if(command.getName().equalsIgnoreCase("first")) {
    3. //Your code here.
    4. return true; // This is very important, it basically stops anything below it from running.
    5. }
    6. if(command.getName().equalsIgnoreCase("second")) {
    7. //More code.
    8. return true;
    9. }
    10. if(command.getName().equalsIgnoreCase("third")) {
    11. //... You get the idea
    12. }
    13. return true;
    14. }
     
    yewtree8 likes this.
  6. Offline

    yewtree8

    I FREAKING LOVE YOU
     
  7. Offline

    GriffinPvP

  8. Offline

    1Rogue

    alternatively from using numerous return statements, just use an else-if
     
  9. Offline

    Sagacious_Zed Bukkit Docs

    Adding the return statements isn't what fixed it, Fixing the semicolons on the if statement is what fixed it.
     
    1Rogue likes this.
Thread Status:
Not open for further replies.

Share This Page