How would i check if the player is on this certain team

Discussion in 'Plugin Development' started by ahuby09, Apr 8, 2014.

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

    ahuby09

    Code:
    package me.blueninjn.minigame;
     
    import java.awt.List;
     
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class minigame extends JavaPlugin{
       String version = "0.1";
       List TeamBlue = new List();
       List TeamRed = new List();
    public void onEnable() {
    System.out.print("MiniGamePlugin" + version + "Enabled");
    }
    public void onDisable() {
    System.out.print("MiniGamePlugin" + version + "Disabled");
    }
    @Override
    public boolean onCommand(CommandSender sender, Command command, String label,
    String[] args) {
    Player player = (Player)sender;
    if(label.equalsIgnoreCase("blue")){
    if(!TeamRed.equals(player.getName())){
    TeamBlue.add(player.getName());
    player.sendMessage("you have been added to the blue team");
    }else{
    player.sendMessage("you are already in the red team !");
    }
    }
     
    if(label.equalsIgnoreCase("red")){
    if(!TeamBlue.equals(player.getName())){
    TeamRed.add(player.getName());
    player.sendMessage("you have been added to the red team");
    }else{
    player.sendMessage("you are already in team blue!");
    }
    }
     
    if(label.equalsIgnoreCase("whoisblue")){
    player.sendMessage(TeamBlue.getItems());
    }
    if(label.equalsIgnoreCase("whoisred")){
    player.sendMessage(TeamRed.getItems());
     
    }
    if(label.equalsIgnoreCase("MyTeam")){
    if(TeamBlue.toString().contains(player.getName())){
    player.sendMessage("you are in the blue team");
    }
    else if(TeamRed.toString().contains(player.getName())){
    player.sendMessage("you are in the red team");
    }else{
    player.sendMessage("you are not in a team");
    }
    }
    return false;
    }
     
     
       
    }
    
    I'm wanting to find out the player team so i want it to check whether it is red, blue or none and i cant seem to get this to work , as how i am doing it says i am not in a team even though i am
     
  2. Offline

    FlareLine

    Use
    Code:java
    1. List<String> TeamBlue = new List<String>();
    2.  
    3. if(TeamBlue.contains(player.getName())){
    4. doStuff();
    5. } else {
    6. doOtherStuff();
    7. }

    instead; this should help you find out what you need to do.
     
  3. Offline

    ahuby09

    i get a error saying remove type arguments and will not allow me to do that :(, any fixes for this
     
  4. Offline

    Dubehh

    ahuby09

    Code:java
    1.  
    2. ArrayList<Player> teamRed = new ArrayList<Player>();
    3. ArrayList<Player> teamBlue = new ArrayList<Player>();
    4.  
    5. if(label.equalsIgnoreCase("Blue"){
    6. Player player = (Player) sender;
    7. if(teamRed.contains(player)){
    8. return false;
    9. }else{
    10. teamBlue.add(player);
    11. }
    12. }
    13.  
    14.  
    15. else if(label.equalsIgnoreCase("Red"){
    16. Player player = (Player) sender;
    17. if(teamBlue.contains(player)){
    18. return false;
    19. }else{
    20. teamRed.add(player);
    21. }
    22. }

    Should work.
     
  5. Offline

    ahuby09

    Thanks gonna try it out now :)

    can you help me on this i put
    Code:
    player.sendMessage(TeamBlue.toString().split(", "));
    so it shows the blueteam but it gives a really long line like craftbukkit[playerName = blueninjn] how would i make it so it just said blueninjn

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

    Dubehh

    ahuby09

    Code:java
    1. if(label.equalsIgnoreCase("CheckTeam")){ //
    2. Player player = (Player) sender;
    3. if(redTeam.contains(player)){
    4. player.sendMessage(ChatColor.RED + "You are in the Red team!")
    5. }
    6. else if(blueTeam.contains(player)){
    7. player.sendMessage(ChatColor.BLUE + "You are in the Blue team!");
    8. }else{
    9. player.sendMessage(ChatColor.YELLOW + "You don't have a team :c");
    10. }


    If you mean that :)
     
  7. Next time you need help, please format your code better so it is easier for us to read. Your code looks revolting at the moment due to the lack of indentations.
     
  8. Offline

    ahuby09

    It is indented on my eclipse how would i do it on here ?

    No i mean it shows a long string when i just want it to show blueninjn and i want it for multiple players not me if you understand it very hard for me to explain , but thanks for trying to help :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  9. Replace TABS with Spaces.
    I prefer using [ code ] and not [ syntax ] anyway.
     
  10. Offline

    FlareLine

    KingFaris11 IMHO,
    Code:java
    1. is much better for beginners.
     
    KingFaris11 likes this.
  11. FlareLine
    We all have our own opinions. =) I mean, yes, syntax is better for line numbering but I just quote code and it helps people recognise code easily if I were to quote it (as they'd have to find it), hence proving your point about being better for beginners. I just like how
    Code:
    This is so clean.
     
  12. Offline

    FlareLine

Thread Status:
Not open for further replies.

Share This Page