Class BukkitPlayerSource<K>

java.lang.Object
io.github.projectunified.valuevenue.bukkit.BukkitPlayerSource<K>
Type Parameters:
K - type of the key
All Implemented Interfaces:
ValueSource<K,org.bukkit.OfflinePlayer>, Function<K,List<org.bukkit.OfflinePlayer>>

public class BukkitPlayerSource<K> extends Object implements ValueSource<K,org.bukkit.OfflinePlayer>
A ValueSource whose values are the players of the server.

<key> resolves to the name of the player, and <key>_<variable> is delegated to replaceVariable(String, OfflinePlayer), which returns null by default. Override it to resolve the player variables of the owner, calling the default for the rest.

Whether a player is active is decided by its own filter, which is refreshed by the update of the generator. Which players a key may see is decided by the key filter, which gets both the player and the key, so the source does not have to know what a key is.

  • Field Details

  • Constructor Details

    • BukkitPlayerSource

      public BukkitPlayerSource(boolean viewOffline)
      Creates the source with DEFAULT_KEY, without a filter.
      Parameters:
      viewOffline - whether offline players are included
    • BukkitPlayerSource

      public BukkitPlayerSource(boolean viewOffline, BiPredicate<org.bukkit.OfflinePlayer,K> playerFilter)
      Creates the source with DEFAULT_KEY.
      Parameters:
      viewOffline - whether offline players are included
      playerFilter - filter a player has to pass to be exposed for a key, or null to expose every player
    • BukkitPlayerSource

      public BukkitPlayerSource(boolean viewOffline, Predicate<org.bukkit.OfflinePlayer> activatedFilter, BiPredicate<org.bukkit.OfflinePlayer,K> playerFilter)
      Creates the source with DEFAULT_KEY.
      Parameters:
      viewOffline - whether offline players are included
      activatedFilter - filter a player has to pass to be active, or null to activate every player
      playerFilter - filter a player has to pass to be exposed for a key, or null to expose every player
    • BukkitPlayerSource

      public BukkitPlayerSource(String key, boolean viewOffline, Predicate<org.bukkit.OfflinePlayer> activatedFilter, BiPredicate<org.bukkit.OfflinePlayer,K> playerFilter)
      Creates the source.
      Parameters:
      key - name of the variable holding the player itself, without the trailing underscore
      viewOffline - whether offline players are included
      activatedFilter - filter a player has to pass to be active, or null to activate every player
      playerFilter - filter a player has to pass to be exposed for a key, or null to expose every player
  • Method Details

    • replace

      public Object replace(String input, org.bukkit.OfflinePlayer value)
      Description copied from interface: ValueSource
      Resolves a variable of the source value.
      Specified by:
      replace in interface ValueSource<K,org.bukkit.OfflinePlayer>
      Parameters:
      input - name of the variable, without its markers
      value - source value the variable is resolved for
      Returns:
      the replacement, or null if the variable is not known
    • replaceVariable

      protected Object replaceVariable(String variable, org.bukkit.OfflinePlayer value)
      Resolves a player variable, the part of <key>_<variable> after the prefix.
      Parameters:
      variable - name of the variable
      value - player the variable is resolved for
      Returns:
      the replacement, or null if the variable is not known
    • isSourceValueActivated

      public boolean isSourceValueActivated(org.bukkit.OfflinePlayer value)
      Description copied from interface: ValueSource
      Whether a source value is currently active.
      Specified by:
      isSourceValueActivated in interface ValueSource<K,org.bukkit.OfflinePlayer>
      Parameters:
      value - source value to check
      Returns:
      true if the value may be exposed
    • getSourceValueStream

      public Stream<org.bukkit.OfflinePlayer> getSourceValueStream()
      Description copied from interface: ValueSource
      All source values that do not depend on a key.

      Empty by default: a source that only knows its values through ValueSource.getSourceValueStream(Object) needs no override.

      Specified by:
      getSourceValueStream in interface ValueSource<K,org.bukkit.OfflinePlayer>
      Returns:
      stream of every key-independent source value
    • getSourceValueStream

      public Stream<org.bukkit.OfflinePlayer> getSourceValueStream(K key)
      Description copied from interface: ValueSource
      Source values to expose for the given key. Defaults to ValueSource.getSourceValueStream().
      Specified by:
      getSourceValueStream in interface ValueSource<K,org.bukkit.OfflinePlayer>
      Parameters:
      key - key whose source values are requested
      Returns:
      stream of source values for the key
    • filter

      protected Stream<org.bukkit.OfflinePlayer> filter(Stream<org.bukkit.OfflinePlayer> players, K key)
      Applies the filter of the source to the players of the key.
      Parameters:
      players - the players to filter
      key - the key they are exposed for
      Returns:
      stream of the players the key may see