Interface ContextManager


public interface ContextManager
Manages ContextCalculators, and calculates applicable contexts for a given type.

This interface accepts Object types as a parameter to avoid having to depend on specific server implementations. In all cases, the "player" or "subject" type for the platform must be used.

Specifically:

  • org.bukkit.entity.Player
  • net.md_5.bungee.api.connection.ProxiedPlayer
  • org.spongepowered.api.service.permission.Subject
  • net.minecraft.server.network.ServerPlayerEntity (Fabric)
  • cn.nukkit.Player
  • com.velocitypowered.api.proxy.Player
  • Method Details

    • getContext

      Queries the ContextManager for current context values for the subject.
      Parameters:
      subject - the subject
      Returns:
      the applicable context for the subject
    • getContext

      Queries the ContextManager for current context values for the given User.

      This will only return a value if the player corresponding to the User is online.

      If you need to obtain a ImmutableContextSet instance regardless, you should initially try this method, and then fallback on getStaticContext().

      Parameters:
      user - the user
      Returns:
      the applicable context for the subject
    • getStaticContext

      @NonNull ImmutableContextSet getStaticContext()
      Gets the contexts from the static calculators in this manager.

      Static calculators provide the same context for all subjects, and are marked as such when registered.

      Returns:
      the current active static contexts
    • queryOptionsBuilder

      @NonNull QueryOptions.Builder queryOptionsBuilder(@NonNull QueryMode mode)
      Creates a new QueryOptions.Builder.
      Parameters:
      mode - the mode
      Returns:
      a new query options builder
    • getQueryOptions

      @NonNull QueryOptions getQueryOptions(@NonNull Object subject)
      Obtains current QueryOptions for the subject.
      Parameters:
      subject - the subject
      Returns:
      the query options for the subject
    • getQueryOptions

      @NonNull Optional<QueryOptions> getQueryOptions(@NonNull User user)
      Obtains current QueryOptions for the given User.

      This will only return a value if the player corresponding to the User is online.

      If you need to obtain a QueryOptions instance regardless, you should initially try this method, and then fallback on getStaticQueryOptions().

      Parameters:
      user - the user
      Returns:
      the query options for the subject
    • getStaticQueryOptions

      @NonNull QueryOptions getStaticQueryOptions()
      Gets the static query options, using the registered static context calculators.
      Returns:
      the current static query options
    • registerCalculator

      void registerCalculator(@NonNull ContextCalculator<?> calculator)
      Registers a context calculator with the manager.
      Parameters:
      calculator - the calculator
    • unregisterCalculator

      void unregisterCalculator(@NonNull ContextCalculator<?> calculator)
      Unregisters a context calculator with the manager.
      Parameters:
      calculator - the calculator
    • signalContextUpdate

      void signalContextUpdate(@NonNull Object subject)
      Signal to the ContextManager that a subjects current contexts have changed.

      It is not strictly necessary to make a call to this method every time a context changes.

      Parameters:
      subject - the subject
      Since:
      5.2
    • getContextSetFactory

      @Internal @NonNull ContextSetFactory getContextSetFactory()
      Gets the ContextSetFactory, responsible for creating ContextSet instances.
      Returns:
      the context set factory
    • invalidateCache

      @Deprecated default void invalidateCache(@NonNull Object subject)
      Deprecated.
      Invalidates the lookup cache for a given subject
      Parameters:
      subject - the subject