How do I check if a player is on a certain team?

Discussion in 'Spigot Plugin Development' started by Donkelyn, Sep 24, 2019.

  1. I'm working on a plugin and I need to figure out how to manipulate the minecraft /team commands.
    I cannot find the correct spigot usage to do code such as
    IF players team = team1 do

    and I can't figure out how to change a players team.
    Does anyone have any experience with this? Thanks!
  2. You're probably going to want to get the server's main scoreboard and then use Scoreboard#getTeam
  3. Here's my broken code

    Team Red = getTeam("Red");

    Team RedCheck = p.getScoreboard().getEntryTeam();

    if (Red == RedCheck) {

    shrineCapture = true;

    p.playSound(p.getLocation(), Sound.BLOCK_NOTE_BLOCK_BASS,1 ,1);

  4. Are you comparing two players? If you are just
    public boolean sameteam(Player p, player t)
    Team home = p.getSc
    Team away = t.getsc
    Home == away return true else return f

  5. what im trying to do is set it so when a player on team x is above an enchanting table, it activates another subprogram to tick down a counter. The issue is I cant detect if the player is on team x.
  6. Ive never used the team in the api, but how about you compare the team names and check if they equal eachother? If not then they're not on the same team. Maybe loop through all the teams? Im not sure im about to open my laptop and see check it out

  7. I'll write some pseudocode

    variable = player team
    theothervariable = red team
    if (variable == theothervariable)
    do thing

    I have no clue how the team API works so im struggling to figure out what to do here.
  8. Code (Text):
     public String getTeam(Player p) {
              for(Team t : Bukkit.getServer().getScoreboardManager().getMainScoreboard().getTeams()) {
                  if(t.hasPlayer(p))   return t.getName();
              return "none";

    I'm a little drunk but I think something like this? I don't have an ide with me so if anything is wrong sorry
    #8 SirJonn, Sep 24, 2019
    Last edited: Sep 24, 2019
  9. you can easily do something like this

    Code (Text):

    public final class Teams {

        private final Set<Teams> teamList = new HashSet<>();

        private final String teamList;
        private final UUID player;

        public Teams (String teamList, Player player) {
        this.teamList = teamList;
        this.player = player.getUniqueId();


    public final class TeamCheck {

        //Event or some method here

        teamList.add(new Teams("Red", player));

        //Checking if player is on red team
        if(teamList.contains(new Teams("Red", player)){
            player.sendMessage(ChatColor.RED + "You're on the red team");



    this though, if for a completely custom system anyways
    pseudo code so some stuff will be wrong and i have 3 minutes to get to school rn so yeah peace

  10. maybe use the list<UUID> and use if list.contains(p.getUniqueID()):