Solved Kill Command (Can somewone check my code and tell me if it would work?)

Discussion in 'Plugin Development' started by NickDEV, Aug 8, 2015.

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

    NickDEV

    Hello. Im currently at the seaside and I can't test my plugins due "Unsupported minor version" problem. Can somebody just check if my code would work as it should?

    THANKS FOR HELPING :)



    Code:
    // KILL COMMAND
            if (cmd.getName().equalsIgnoreCase("kill")) {
                if (sender.hasPermission("healplusplusplus.kill")) {
                   
                    if (args.length == 0) {
                        if (!(sender instanceof Player)) {
                           
                            sender.sendMessage(ChatColor.RED + playersonly);
                           
                        } else {
                           
                            Player p = (Player) sender;
                            p.sendMessage(ChatColor.GREEN + "You have killed yourself.");
                            p.playSound(p.getLocation(), Sound.EXPLODE, 0.5f, 1);
                            p.setHealth(0D);
    
                           
                        }
                    }
                   
                    if (args.length == 1) {
                        if (sender.hasPermission("healplusplusplus.kill.other")) {
                        Player target = Bukkit.getServer().getPlayer(args[0]);
                        Player p  = (Player) sender;
                       
                        if (target == null) {
                            sender.sendMessage(ChatColor.RED + noplayer + target.getName());
                           
                        } else {
                           
                            p.sendMessage(ChatColor.GREEN + "You have killed " + ChatColor.GOLD + target.getName() + ".");
                            target.sendMessage(ChatColor.GREEN + "You have been killed by " + ChatColor.GOLD + p.getName() + ".");
                            target.setHealth(0D);
                            p.playSound(p.getLocation(), Sound.LEVEL_UP, 0.5f, 1);
                            target.playSound(target.getLocation(), Sound.EXPLODE, 0.5f, 1);
                       
                          }
                       
                        } else {
                           
                            sender.sendMessage(ChatColor.RED + nopermission);
                           
                        }
                    }
                   
                } else {
                   
                    sender.sendMessage(ChatColor.RED + nopermission);
                   
                }
            }
     
  2. Offline

    Rorooo

    Looks fine. :)
     
  3. Offline

    NickDEV

    @Rorooo Thanks for checking the code. Will wait for a few more.
     
  4. Offline

    bwfcwalshy Retired Staff

    @NickDEV A few minor issues you should address but nothing major.

    For example, why have the check after an argument, do it before that way you can access player in all the arguments without needing multiple checks and casts.
     
  5. Offline

    teej107

    The best way to see if code works is to try it out yourself. An unsupported minor version is an easy fix and there has been far too many threads on here about this one error. Looking for an answer on here won't be hard.
     
    Konato_K likes this.
  6. Offline

    xXCapzXx

    Error with this:
    Code:
    sender.sendMessage(ChatColor.RED+ playersonly);
    
    Your forgot the ""
    It is mean't t0 be like this for text.

    Code:
    sender.sendMessage(ChatColor.RED+ "Players only");
    
     
  7. Offline

    NickDEV

    @xXCapzXx Sorry, i didn't post the full code.

    playersonly is actually a string.
    Code:
    ( public static String playersonly = "This command is for players only"; )
    Thanks for help anyway.
     
  8. Offline

    mythbusterma

    @NickDEV

    You should make it final, and then make the name all upper case, as is convention for constants.
     
Thread Status:
Not open for further replies.

Share This Page