How to check/get player's team name?

Discussion in 'Plugin Development' started by PlayFriik, Dec 28, 2014.

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

    PlayFriik

    Hello. First of all, I am using this teams system: http://bukkit.org/threads/tutorial-teams-with-names-armor-colors.292535/

    But I have problem.. How I would check or get the player's team name?

    I am not gonna post these team class files, because you can easily get them from his thread.
    I hope someone can figure it out..
    I have tried this, but it just ignores it/can't get the name:
    Code:
    @EventHandler
        public void onPlayerRespawn(PlayerRespawnEvent e) {
            Player player = e.getPlayer();
            Team teamName = Team.getTeam(player);
            if (teamName.equals("Red")) {
                player.sendMessage("You are on Red team!"); // debug
            }
            if (teamName.equals("Green")) {
                player.sendMessage("You are on Green team!"); //debug
            }
        }
    Also, I have registered my events.
     
  2. Offline

    mythbusterma

    @PlayFriik

    It seems like you've got working code there, unless your String matching is botched (which, since you're not using constants for it, is entirely likely). It's also quite likely said player is on neither team.
     
  3. Offline

    PlayFriik

    @mythbusterma

    The player has to have a team, because I did this, before game started:
    Code:
                        int i = 0;
                        for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
                            if (i < Bukkit.getOnlinePlayers().size() / 2) {
                                Team.getTeam("Green").getPlayers().add(onlinePlayer.getUniqueId());
                                onlinePlayer.setCustomName("§a" + onlinePlayer.getName() + "§f");
                                onlinePlayer.setDisplayName("§a" + onlinePlayer.getName() + "§f");
                                onlinePlayer.setPlayerListName("§a" + onlinePlayer.getName() + "§f");
                                onlinePlayer.sendMessage("§7Added to §aGreen§7 team.");
                            } else {
                                Team.getTeam("Red").getPlayers().add(onlinePlayer.getUniqueId());
                                onlinePlayer.setCustomName("§c" + onlinePlayer.getName() + "§f");
                                onlinePlayer.setDisplayName("§c" + onlinePlayer.getName() + "§f");
                                onlinePlayer.setPlayerListName("§c" + onlinePlayer.getName() + "§f");
                                onlinePlayer.sendMessage("§7Added to §cRed§7 team.");
                            }
                            i++;
                        }
    Also I set the plugin to "isRunning = true" and kicked out players who wanted to login after the team adding stuff was completed.
     
  4. Offline

    mythbusterma

    @PlayFriik

    Print the contents of every team when that event gets called. Make sure you're in it.
     
  5. Offline

    PlayFriik

    @mythbusterma

    I printed out the number of the teams, and there was 1 and 0, that is correct, I was on red team, so it was 1.
    But still, I think I am just using wrongly these things, I mean I am using:
    Code:
            if (Team.getTeam(player).equals("Red")) {
                player.sendMessage("Red team?");
            }
    But that seems to be wrong.
    I did another else after that to and it printed out the last else, so it cant find any of those teams.. :/
     
    Last edited: Dec 28, 2014
  6. Offline

    mythbusterma

    @PlayFriik

    So print out the return value of Team.getTeam(), what does that return?
     
  7. Offline

    PlayFriik

    Fixed!

    I just added .getName() after getTeam(player):
    Code:
    if (Team.getTeam(player).getName().equals("Red")) {
    //....
     
Thread Status:
Not open for further replies.

Share This Page