How to check all players what used command

Discussion in 'Plugin Development' started by Plugers11, Apr 20, 2014.

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

    Plugers11

    I want to create minigame
    And i want to use all was do command : /join red or /join blue
    If they use : /join red
    Then teleport to redspawn

    If they use : /join blue
    Then teleport to bluespawn

    Anybody can help ?
     
  2. Offline

    Konkz

  3. Offline

    Plugers11

    Konkz
    And what film ?


    Ok i know
     
  4. Offline

    Konkz

    Learn Java. What you are trying to do is actually simple, just need basic knowledge.
     
  5. Offline

    Badeye

    Plugers11 I am not going to "spoonfeed" you, but basicly what you want is having the onCommand method, check for the input string (so if the user has typed in /join), then you check for the arguments (everything after /join, for example /join blue, the first argument would now be blue).

    Now you just have a couple of if statements and if the first argument MATCHES (!) blue, you teleport the palyer to the location for team blue (look into the bukkit reference how to teleport someone). You also have to check if the sender (the one who typed the command) is a player, otherwise you would try to teleport the console (hehe). Just check it like this:
    Code:java
    1. if(sender instanceof Player)

    And remember, no EventHandler over the onCommand method, it is not an actual Event!
     
  6. Offline

    MrInspector

    I would actually do it with a PlayerCommandPreprocessEvent, then check if the command he performed was /join or somthing, then do whatever he wants with it.

    EDIT: I'm confused, are you trying to check what command they used or make a command?
     
  7. Offline

    Plugers11

    I want to have list or something like this
    And if i do command : maybe /teleportteams

    Then teleports red team do redloc and blue team to blueloc

    Or something like thix
     
  8. Offline

    Badeye

    MrInspector check what they have typed and execute it. So check it. Like
    Code:java
    1. if(cmd.getName().equalsIgnoreCase("join")){
    2. if(sender instanceof Player && args.length > 0){
    3. if (args[1].matches("blue"))
    4. sender.teleport(new Location(sender.getWorld(), -20, 20, -20));
    5. else if (args[1].matches("red"))
    6. sender.teleport(new Location(sender.getWorld(), 20, 20, 20));;
    7. }
    8. }


    Plugers11 That can be done, but where do you define who is in which team?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  9. Offline

    Plugers11

    I want
    to maybe 2 hashmaps or arraylist (i don't know)
    And if player do /join red
    Then put or add him to hashmap or arraylist (i don't know)
    And if i do command : /start
    Then teleport redTeam to redLoc
    And teleport blueTeam to blueLoc
     
  10. Offline

    Badeye

    Plugers11 Ah okay i got it. So if you go with the hashmap you would have a key that defines the team and the objects are the players. When you go with a list you have two lists, one for team blue and one for team red. It doesn't realy matter but for beginners i'd go with the list.
    My question is, how do the people get added to the list? Are they being added randomly when they type in the command or is it pre defined? Well you have to add them somehow, but if that is done you could just check it like this(example with string lists):
    Code:java
    1. List<String> redList;
    2. List<String> blueList;
    3.  
    4. if(cmd.getName().equalsIgnoreCase("join")){
    5. if(sender instanceof Player && args.length > 0){
    6. if (args[1].matches("blue") && blueList.contains(sender.getName()))
    7. sender.teleport(new Location(sender.getWorld(), -20, 20, -20));
    8. else if (args[1].matches("red") && redList.contains(sender.getName())
    9. sender.teleport(new Location(sender.getWorld(), 20, 20, 20));;
    10. }
    11. }

    But again, you somehow have to add elements to the list. In this case i assumed you have added the player names. It is a difference between a Player and trhe player name, if you add the player to the list something like Craftplayer@sdadja gets added, so you have to add teh players name.
     
Thread Status:
Not open for further replies.

Share This Page