Whats wrong with my code

Discussion in 'Plugin Development' started by rocky101202, Aug 17, 2014.

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

    rocky101202

    So I am a new developer and I made 3 similer plugins and wanted to combine them so I just copied and pasted and I usume this isnt the right way to do it but I dont know any other way thank you for the help. Also if someone could tell me about 5 plugins I should make to get bukkit down since im new.

    Code:
    package me.rocky101202.rocko;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Killer extends JavaPlugin {
     
        @Override
        public void onEnable() {
        }
       
        @Override
        public void onDisable() {
           
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
           
            if (cmd.getName().equalsIgnoreCase("damage") && sender instanceof Player) {
               
                Player player = (Player) sender;
               
                int length = args.length;
               
                if (length == 1) {
                   
                    boolean playerFound = false;
                   
                    for (Player playerToDie : Bukkit.getServer().getOnlinePlayers()) {
                        if(playerToDie.getName().equalsIgnoreCase(args[0])) {
                            playerToDie.setHealth(10.0);
                            playerToDie.sendMessage(ChatColor.RED + "You have been damaged by " + player.getName() + "!");
                            player.sendMessage(ChatColor.GREEN + "You have damaged " + playerToDie.getName() + "!");
                            playerFound = true;
                            break;                   
                        }
                    }
                   
                    if (playerFound == false) {
                        player.sendMessage(ChatColor.RED + args[0] + " was not found!");
                    }
                   
                } else player.sendMessage(ChatColor.RED + "Incorrect usage! /damage (playername)");
               
       
                public boolean onCommand1(CommandSender sender, Command cmd, String label, String[] args) {
               
            if (cmd.getName().equalsIgnoreCase("healplayer") && sender instanceof Player) {
               
                Player player1 = (Player) sender;
               
                int length1 = args.length;
               
                if (length1 == 1) {
                   
                    boolean playerFound = false;
                   
                    for (Player playerToHeal : Bukkit.getServer().getOnlinePlayers()) {
                        if(playerToHeal.getName().equalsIgnoreCase(args[0])) {
                            playerToHeal.setHealth(20.0);
                            playerToHeal.sendMessage(ChatColor.GREEN + "You have been healed by " + player1.getName() + "!");
                            player1.sendMessage(ChatColor.AQUA + playerToHeal.getName() +  " was healed successfully!");
                            playerFound = true;
                            break;
                        }
                    }
                   
                    if (playerFound == false) {
                        player1.sendMessage(ChatColor.RED + args[0] + " was not found!");
                    }
                   
                } else player1.sendMessage(ChatColor.RED + "Incorrect usage! /healplayer (playername)");
               
        public boolean onCommand2(CommandSender sender, Command cmd, String label, String[] args) {
               
            if (cmd.getName().equalsIgnoreCase("playerkill") && sender instanceof Player) {
               
                Player player2 = (Player) sender;
               
                int length2 = args.length;
               
                if (length2 == 1) {
                   
                    boolean playerFound = false;
                   
                    for (Player playerToKill : Bukkit.getServer().getOnlinePlayers()) {
                        if(playerToKill.getName().equalsIgnoreCase(args[0])) {
                            playerToKill.setHealth(0.0);
                            playerToKill.sendMessage(ChatColor.RED + "You have been killed by " + player2.getName() + "!");
                            player2.sendMessage(ChatColor.GREEN + "You have killed " + playerToKill.getName() + "!");
                            playerFound = true;
                            break;                   
                        }
                    }
                   
                    if (playerFound == false) {
                        player2.sendMessage(ChatColor.RED + args[0] + " was not found!");
                    }
                   
                } else player2.sendMessage(ChatColor.RED + "Incorrect usage! /damage (playername)");           
               
                return true;
               
            }
           
            return false;           
           
            }
           
        }
       
            
     
  2. Offline

    Dinosaurs

    Well... for starters, can you tell us what is the desired results and what is the actual results?
     
    yewtree8 likes this.
  3. Offline

    AoH_Ruthless

    rocky101202
    How to get Bukkit down? Easy. Look at the Bukkit docs and understand every class and what it does, and how to use it.
     
  4. Offline

    rocky101202

    Sorry I forgot to put whats wrong .I am having these errors.I do what this tells me but it still has this error

    } else player1.sendMessage(ChatColor.RED + "Incorrect usage! /healplayer (playername)"); has a error after it saying Syntax error, insert "}" to complete MethodBody
    } else player.sendMessage(ChatColor.RED + "Incorrect usage! /damage (playername)"); has a error after it saying Syntax error, insert "}" to complete MethodBody
     
  5. Offline

    stormneo7

    You have about 3
    Code:java
    1. public boolean onCommand1(CommandSender sender, Command cmd, String label, String[] args) {
    2.  

    Only should have one per class m8.
     
  6. Offline

    Skionz

    when it tells you to insert } you should probably insert a }
     
    Totom3 likes this.
  7. Offline

    rocky101202

    If you would read what I said before you say something I did that and it didnt work
     
  8. Offline

    mythbusterma

    rocky101202

    No need to be cocky, your editor, and Skionz is right. You have incorrectly nested, or otherwise constructed improperly, your class. You should probably start over, noting that you should only have one onCommand(..) method per class and that you have to register your commands, which you haven't done.
     
  9. Offline

    rocky101202


    I know but what he said was not right he just said what I said wasnt working
     
  10. Offline

    Necrodoom

    rocky101202 you never explained what happens when you DO follow the instructions.
     
    mythbusterma likes this.
  11. Offline

    AronTheGamer

    Code:java
    1.  
    2. if( cmd.getName().equalsIgnoreCase( "damage" ) )
    3. {
    4. if( args.length > 0 && Bukkit.getPlayer( args[0] ) != null )
    5. Bukkit.getPlayer( args[0] ).setHealth( 10.0 );
    6. }


    Et cetera.
     
  12. Offline

    rocky101202

    Thanks guys fixed it
     
Thread Status:
Not open for further replies.

Share This Page