1.15.2 Best way to fetch what team a player is on?

Discussion in 'Spigot Plugin Development' started by buildoman, Jan 21, 2020.

  1. Hello,
    I've been trying recently to figure out which is the best way to create 2 teams then perform checks to see which team a player is on during an onPlayerPortal event. Ive been a little confused on it though, do you have to create it all through a scoreboard or is there a different way around it? I can go a little more into detail but the code i've done so far is pretty much useless.
  2. yeah teams are a part of scoreboards. unless you want to make up your own team-system you're not getting around using scoreboard related stuff
  3. Create a Team.class that contains data like the name of the team and a Set<UUID>
    If you want to add a player to the Team just add him to the Set. If you want to check if a player is part of this team just call contains() on this set.

    Its probably a good idea to also mirror the data.
    Meaning you should create a GamePlayer class that contains the team the player is currently in so you can check efficiently if a player already has a team or not.

    This whole information can be store for example in a TeamManager class like:
    Map<String, Team> teamMap; // Key = name, value = Team
    Map<UUID, GamePlayer> // Key = player UUID, value = team player