Skip to content

Commit

Permalink
Make obtaining a DisplaySlot by NamedTextColor static
Browse files Browse the repository at this point in the history
  • Loading branch information
dualspiral committed May 10, 2021
1 parent 384ff35 commit 2979759
Showing 1 changed file with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import net.kyori.adventure.text.format.NamedTextColor;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.registry.DefaultedRegistryValue;
import org.spongepowered.api.scoreboard.Team;
import org.spongepowered.api.util.annotation.CatalogedBy;
Expand All @@ -39,18 +40,37 @@
public interface DisplaySlot extends DefaultedRegistryValue {

/**
* Gets the display slot for the specified team color. Returns
* this if the color is the same or if colors aren't supported.
* Finds and retrieves the sidebar display slot for the specified
* {@link NamedTextColor} associated with a {@link Team}, if one exists.
*
* @param color The team color
* @return The display slot with the given team color
* @param color The {@link NamedTextColor}
* @return The slot, if one was found
*/
DisplaySlot withTeamColor(@Nullable NamedTextColor color);
static Optional<DisplaySlot> findByTeamColor(final NamedTextColor color) {
return Sponge.game().factoryProvider().provide(Factory.class).findByTeamColor(color);
}

/**
* Gets the {@link Team} color that this objective will display.
*
* @return The team color or {@link Optional#empty()} if not set
*/
Optional<NamedTextColor> teamColor();

/**
* Used to support {@link #findByTeamColor(NamedTextColor)}
*/
interface Factory {

/**
* Finds and retrieves the sidebar display slot for the specified
* {@link NamedTextColor} associated with a {@link Team}, if one exists.
*
* @param color The {@link NamedTextColor}
* @return The slot, if one was found
*/
Optional<DisplaySlot> findByTeamColor(NamedTextColor color);

}

}

0 comments on commit 2979759

Please sign in to comment.