Really simple help, please.

Discussion in 'Plugin Development' started by joaogl, Mar 21, 2012.

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

    joaogl

    Hello if we do:
    Code:
            if(commandLabel.equalsIgnoreCase("hello")){
                        player.sendMessage("Hello ");
            }    
    he just send that message but how can i do some think like, if we do /hello joao are
    and he save "joao" as a StringA and "are" as StringB then he do this:


    Code:
    player.sendMessage("Hello " + StringA + " " + Stringb);
     
  2. Offline

    Tzeentchful

    args[] contains all the words after the command.

    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
      if (sender instanceof Player == true){
        Player player = (Player) sender;
        if (cmd.getName().equalsIgnoreCase("hello")){
          String stringA = args[0];
            String stringb = args[1];
            player.sendMessage("Hello " + stringA + " " + stringb);
            return true;
        }
      }
    }
     
  3. Offline

    joaogl

    Code:
        public boolean onCommand1(CommandSender sender, Command cmd, String label, int args){
              if (sender instanceof Player == true){
                Player player = (Player) sender;
                if(cmd.getName().equalsIgnoreCase("life")){
                    if(player.isOp() || player.hasPermission("event.vida")){
                          f = args;
     
                    }else{
                        player.sendMessage("Nao tem permissao para este comando.");
                    }
                }
                if(cmd.getName().equalsIgnoreCase("Food")){
                    if(player.isOp() || player.hasPermission("event.fome")){
                        f = args;
                    }else{
                        player.sendMessage("Nao tem permissao para este comando.");
                    }
                }
              }
              return false;
            }


    why does't work?

    in this case we right /life 10 than when i do this

    Code:
    if(commandLabel.equalsIgnoreCase("apply")){
    if(ev == 1){
    PlayerInventory inventory = player.getInventory();
    inventory.clear();
    player.setFoodLevel(f);
    player.setHealth(l);
    }else{
    player.sendMessage("Nao esta nenhum evento a decorrer!");
    }
    }
    i should apply it no?
     
  4. Offline

    Tzeentchful

    you havent put any
    if it was succesful
    return true;
     
  5. Offline

    joaogl

    like this?

    Code:
        public boolean onCommand1(CommandSender sender, Command cmd, String label, int args){
              if (sender instanceof Player == true){
                Player player = (Player) sender;
                if(cmd.getName().equalsIgnoreCase("vida")){
                    if(player.isOp() || player.hasPermission("event.vida")){
                          v = args;
     
                    }else{
                        player.sendMessage("Nao tem permissao para este comando.");
                    }
                }   
                if(cmd.getName().equalsIgnoreCase("fome")){
                    if(player.isOp() || player.hasPermission("event.fome")){
                        f = args;
                    }else{
                        player.sendMessage("Nao tem permissao para este comando.");
                    }
                }   
              }
              return true;
            }
     
  6. Offline

    Tzeentchful

  7. Offline

    joaogl

    Please help me i already read that but i dont know were is the error....
     
  8. Offline

    Tzeentchful

    ok first your method decration is wrong
    Code:
    public boolean onCommand1(CommandSender sender, Command cmd, String label, int args){
    it should be this
    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    and every time you have a if(cmd.getName().equalsIgnoreCase("some command"))
    you need have have a
    return true;
    at the end
    eg:
    Code:
    if (cmd.getName().equalsIgnoreCase("help")){
      player.sendMessage("help menu")                       
      return true;
    }//end help
     
  9. Offline

    joaogl

    yes but in this case im using numbers so i should use int:
    Code:
    [FONT=Consolas]public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, int args){[/FONT]

    or no?
     
  10. Offline

    Tzeentchful

    no the onCommand only returns a String array. you can just use
    Code:
    Integer.parseInt(arg[0]);
     
  11. Offline

    joaogl

    ok so with
    Code:
    Integer.parseInt(arg[0]);
    what i need to do to get the number after the /life and set that number to "int l;" ?

    basically i just want to do a /give.
    im creating e Event system and the admin just type /Setlife [num] and he save in "Int l" /SetFood [num] and he save in "Int f" /setobject [id] [numer] and he save in "obid" and "obnun" then i will get the player Loc whit this :
    Code:
                    Int LocX
                    Int LocY
                    Int LocZ
                    Player player = event.getPlayer();
                    Location playerLoc = player.getLocation();
                    LocX = playerLoc.getX());
                    LocY = playerLoc.getY());
                    LocZ = playerLoc.getZ());
    then the player right /goevent and he teleport the player to that coordinates i dont know how yet but i will discover and he will clear the inventery give to the player the life food and objects i only dont know yet how to do the /SetLife /SetFood /SetObject and how to teleport the player.

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

    joaogl

    please.......
     
  13. Offline

    Lolmewn

    I've got no clue what you're talking about :)

    Try adding @Override to the method.
     
  14. Offline

    joaogl

    i just want to do a command like this /howoldareyou [age]
    how can i get the age to a int?
     
  15. Offline

    hpdvs2

    Your asking about 6 different things here, how to teleport, how to give food, how to give life, how to give objects and how to get the age, but all you were originally asking was how to concatenate a string array.

    Your post is getting confusing, and I recommend that you split each question to its own thread. This will make it easier for us to understand what you want, and for you to get your answers.
     
  16. Offline

    joaogl

    Im not asking for 6 different things i just give a lot of exemples...

    I only need to know 2 things.

    first how can i get a int: exemple /howoldareyou [age] i just want to get the [age] and set it to a int.
    secound how can i teleport a player like this.

    Player number one right /setloc
    Player 2 right /goloc
    than the Player2 go the the loc is not to the Player Loc is to the loc.
    is like
    Player ok so now im here and i do /setloc now i can go any were if the other players do /goloc they are teleported to here and not to me.....



    Ok?
    to get the player loc i think is like this:

    Code:
    [FONT=Consolas]                Int LocX
                    Int LocY
                    Int LocZ
                    Player player = event.getPlayer();
                    Location playerLoc = player.getLocation();
                    LocX = playerLoc.getX());
                    LocY = playerLoc.getY());
                    LocZ = playerLoc.getZ());[/FONT]
    [FONT=Consolas]
    [/FONT]
     
  17. Offline

    joaogl

    did you understand now?
     
Thread Status:
Not open for further replies.

Share This Page