Solved command arguments

Discussion in 'Plugin Development' started by pipo3090, Feb 1, 2015.

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

    pipo3090

    hey guys!
    I'm new in developing a plugin, so i need your help!
    I want to make a troll plugin, but i've got to know how to make that all the player's health is being set to 1/20 of it, but that you can also choose one player to 'hit'!
    i already have this:
    Code:
    package me.pipo3090.PPC;
    
    import java.util.logging.Logger;
    
    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 PPC extends JavaPlugin {
        public static Logger logger = Logger.getLogger("Minecraft");
        public static PPC plugin;
    
      
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            Player player = (Player) sender;
            if(commandLabel.equalsIgnoreCase("ppc")) {
                player.sendMessage(ChatColor.GREEN + "PRETPARKCRAFT IS AWESOME");
          
                if(commandLabel.equalsIgnoreCase("troll") || commandLabel.equalsIgnoreCase("trololo")){
                    if(args.length == 0){
                        //heal = 0 args /heal pipo309 = 1 args
                        player.setHealth(1);
                    }else if (args.lenght == 1){
                    if  
                    }
                }
            }
            return false;
        }
    }
    you can find other stuff in it, don't mind that
    can you guys help me?

    greetings,
    pipo3090
     
  2. Offline

    CheesyFreezy

    Cast the second argument as a player like this:
    Code:
    Player target = Bukkit.getServer().getPlayer(args[0]);
    //args[0] is the second argument of a command
    now check if the target is an existing player and if the player is online:
    Code:
    if(target != null || target.isValid) {
       //the player exists
    }
    Code:
    if(target.isOnline()) {
       //the player is online
    }
    What you want to do now is simply set the health to 1 of the target player:
    Code:
    target.setHealth(1);
    Now you're done!

     
  3. Offline

    pipo3090

    thanks, but i need 1 thing (1d style, i hate it!) more: all players!
     
  4. Offline

    nverdier

    @pipo3090 Bukkit#getOnlinePlayers() should work, yes?
     
  5. Offline

    pipo3090

    i cant do the commands. anyone know somthing to solve it?
     
  6. Offline

    pipo3090

  7. Offline

    nverdier

    It's the official one, so I'd hope so!
     
Thread Status:
Not open for further replies.

Share This Page