Class Team

java.lang.Object
net.mathias2246.buildmc.util.MetadataHolder
net.mathias2246.buildmc.api.team.Team
All Implemented Interfaces:
Cloneable, Iterable<UUID>, net.kyori.adventure.audience.Audience, net.kyori.adventure.audience.ForwardingAudience, net.kyori.adventure.pointer.Pointered

public class Team extends MetadataHolder implements Iterable<UUID>, net.kyori.adventure.pointer.Pointered, net.kyori.adventure.audience.Audience, net.kyori.adventure.audience.ForwardingAudience, Cloneable
A custom team implementation.

This team implementation is required on Folia servers, because there the vanilla team system is disabled.

When creating a team instance, you can manually register it in a TeamManager.
E.g. via BuildMcAPI.getTeamManager().
When adding members to an unregistered team, nothing else (e.g. the server or the added members) is informed that the team exists.
Once a team is registered, an uncancellable TeamMemberAddEvent is fired retroactively for each of its current members.

A team is a collection of members. A member is represented as a UUID, not a Player or Entity directly - the UUID does not need to correspond to an existing entity.

Like Bukkit's own Team, this team is also an Adventure Audience and ForwardingAudience.

See Also:
  • Bukkit Teams
  • Nested Class Summary

    Nested classes/interfaces inherited from interface net.kyori.adventure.audience.ForwardingAudience

    net.kyori.adventure.audience.ForwardingAudience.Single
  • Constructor Summary

    Constructors
    Constructor
    Description
    Team(@NotNull String name)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    addMember(@NotNull UUID uuid)
    Adds a member by his UUID to this team.
    boolean
    addMember(@NotNull UUID uuid, boolean cancellable, boolean fireEvent)
    Adds a member by his UUID to this team.
    boolean
    addMember(@NotNull org.bukkit.entity.Entity entity)
    Adds a Entity as a member to this team.
    @NonNull Iterable<? extends net.kyori.adventure.audience.Audience>
     
    Creates a clone of this team.
    void
    Removes all members from this team.
    boolean
     
    void
    forEach(Consumer<? super UUID> action)
    Iterates over all members on this team, and apply an action on each member.
    @Nullable net.kyori.adventure.text.format.TextColor
     
    @Nullable net.kyori.adventure.text.Component
     
    @NotNull String
     
    @Nullable TeamManager
    Returns the TeamManager this team is registered in.
    int
     
    boolean
    Checks if there are any members on this team.
    boolean
    isMember(@NotNull UUID uuid)
     
    boolean
    isMember(@NotNull org.bukkit.entity.Entity entity)
     
    @NonNull Iterator<UUID>
    Used to iterate over all members on this team.
    @NotNull Stream<UUID>
    Gets a Stream of all members on the team.
    void
    register(@NotNull TeamManager manager, boolean persist)
     
    boolean
    removeMember(@NotNull UUID uuid)
    Removes a member from this team by his UUID.
    boolean
    removeMember(@NotNull org.bukkit.entity.Entity entity)
    Removes an Entity from this team.
    void
    setColor(@Nullable net.kyori.adventure.text.format.TextColor color)
     
    void
    setDisplayName(@Nullable net.kyori.adventure.text.Component displayName)
     
     
    void
     

    Methods inherited from class Object

    finalize, getClass, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface net.kyori.adventure.audience.Audience

    deleteMessage, openBook, openBook, removeResourcePacks, removeResourcePacks, removeResourcePacks, sendActionBar, sendMessage, sendMessage, sendPlayerListFooter, sendPlayerListHeader, sendPlayerListHeaderAndFooter, sendResourcePacks, sendResourcePacks, showTitle, stopSound

    Methods inherited from interface net.kyori.adventure.audience.ForwardingAudience

    clearResourcePacks, clearTitle, closeDialog, deleteMessage, filterAudience, forEachAudience, hideBossBar, openBook, playSound, playSound, playSound, pointers, removeResourcePacks, removeResourcePacks, resetTitle, sendActionBar, sendMessage, sendMessage, sendMessage, sendPlayerListFooter, sendPlayerListHeader, sendPlayerListHeaderAndFooter, sendResourcePacks, sendTitlePart, showBossBar, showDialog, stopSound

    Methods inherited from interface net.kyori.adventure.pointer.Pointered

    get, getOrDefault, getOrDefaultFrom
  • Constructor Details

    • Team

      public Team(@NotNull @NotNull String name)
  • Method Details

    • getColor

      @Nullable public @Nullable net.kyori.adventure.text.format.TextColor getColor()
    • setColor

      public void setColor(@Nullable @Nullable net.kyori.adventure.text.format.TextColor color)
    • getDisplayName

      @Nullable public @Nullable net.kyori.adventure.text.Component getDisplayName()
    • setDisplayName

      public void setDisplayName(@Nullable @Nullable net.kyori.adventure.text.Component displayName)
    • getName

      @NotNull public @NotNull String getName()
    • register

      public void register(@NotNull @NotNull TeamManager manager, boolean persist)
    • unregister

      public void unregister()
    • members

      @Contract(pure=true) @NotNull public @NotNull Stream<UUID> members()
      Gets a Stream of all members on the team.
    • getTeamManager

      @Nullable public @Nullable TeamManager getTeamManager()
      Returns the TeamManager this team is registered in.
      Returns:
      The TeamManager this team is registered in, or null if not registered.
    • isMember

      @Contract(value="_ -> _", pure=true) public boolean isMember(@NotNull @NotNull org.bukkit.entity.Entity entity)
    • isMember

      @Contract(value="_ -> _", pure=true) public boolean isMember(@NotNull @NotNull UUID uuid)
    • addMember

      public boolean addMember(@NotNull @NotNull org.bukkit.entity.Entity entity)
      Adds a Entity as a member to this team.
      Returns:
      true if the entities UUID wasn't already present in this team.
    • addMember

      public boolean addMember(@NotNull @NotNull UUID uuid, boolean cancellable, boolean fireEvent)
      Adds a member by his UUID to this team. (Optionally) Fires a cancellable TeamMemberAddEvent. If cancelled is set to true and the event is cancelled, the member will not be added to the team.
      Parameters:
      uuid - The UUID of the member to try to add
      cancellable - If true, this action can be cancelled by event handlers.
      fireEvent - If a TeamMemberAddEvent should be fired
      Returns:
      true if the UUID if the member wasn't added.
      See Also:
    • isEmpty

      public boolean isEmpty()
      Checks if there are any members on this team.
      Returns:
      true if there is at least one member on this team.
      See Also:
    • empty

      public void empty()
      Removes all members from this team. This will fire a TeamMemberRemovedEvent for each member.
      See Also:
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • addMember

      public boolean addMember(@NotNull @NotNull UUID uuid)
      Adds a member by his UUID to this team. Fires an uncancellable TeamMemberAddEvent.
      Parameters:
      uuid - The UUID of the member to try to add
      Returns:
      true if the UUID if the member wasn't added.
      See Also:
    • removeMember

      public boolean removeMember(@NotNull @NotNull org.bukkit.entity.Entity entity)
      Removes an Entity from this team. This will fire a TeamMemberRemovedEvent when the member was successfully removed.
      Returns:
      true if the entities UUID was present and removed successfully.
      See Also:
    • removeMember

      public boolean removeMember(@NotNull @NotNull UUID uuid)
      Removes a member from this team by his UUID. This will fire a TeamMemberRemovedEvent when the member was successfully removed.
      Returns:
      true if the UUID was present and removed successfully.
      See Also:
    • iterator

      public @NonNull Iterator<UUID> iterator()
      Used to iterate over all members on this team.
      Specified by:
      iterator in interface Iterable<UUID>
    • forEach

      public void forEach(Consumer<? super UUID> action)
      Iterates over all members on this team, and apply an action on each member.
      Specified by:
      forEach in interface Iterable<UUID>
      Parameters:
      action - The action to apply on each member UUID
    • spliterator

      public Spliterator<UUID> spliterator()
      Specified by:
      spliterator in interface Iterable<UUID>
    • audiences

      public @NonNull Iterable<? extends net.kyori.adventure.audience.Audience> audiences()
      Specified by:
      audiences in interface net.kyori.adventure.audience.ForwardingAudience
    • clone

      public Team clone()
      Creates a clone of this team.

      A new clone will not be automatically registered inside a TeamManager.

      Overrides:
      clone in class Object