接口 ServicesManager

所有已知实现类:
SimpleServicesManager

public interface ServicesManager
管理服务和服务提供者. 服务是定义提供者必须实现的方法列表的接口. 提供者是这些服务的实现. 可以从服务管理器查询提供者以使用服务 (如果可用). 如果多个插件注册了同一服务, 则优先级最高的服务优先.
  • 方法详细资料

    • register

      <T> void register(@NotNull @NotNull Class<T> service, @NotNull T provider, @NotNull @NotNull Plugin plugin, @NotNull @NotNull ServicePriority priority)
      注册一个服务的提供者.

      原文: Register a provider of a service.

      类型参数:
      T - 提供者类型
      参数:
      service - 服务类
      provider - 要注册的提供者
      plugin - 拥有该提供者的插件
      priority - 提供者的优先级
    • unregisterAll

      void unregisterAll(@NotNull @NotNull Plugin plugin)
      注销特定插件注册的所有提供者.

      原文: Unregister all the providers registered by a particular plugin.

      参数:
      plugin - 要注销的插件
    • unregister

      void unregister(@NotNull @NotNull Class<?> service, @NotNull @NotNull Object provider)
      注销特定服务的特定提供者.

      原文: Unregister a particular provider for a particular service.

      参数:
      service - 服务接口
      provider - 服务提供者实现
    • unregister

      void unregister(@NotNull @NotNull Object provider)
      注销特定提供者.

      原文: Unregister a particular provider.

      参数:
      provider - 服务提供者实现
    • load

      @Nullable <T> T load(@NotNull @NotNull Class<T> service)
      查询提供者. 如果没有为服务注册提供者, 可能返回 null. 返回优先级最高的提供者.

      原文: Queries for a provider. This may return null if no provider has been registered for a service. The highest priority provider is returned.

      类型参数:
      T - 服务接口类型
      参数:
      service - 服务接口
      返回:
      提供者或 null
    • getRegistration

      @Nullable <T> @Nullable RegisteredServiceProvider<T> getRegistration(@NotNull @NotNull Class<T> service)
      查询提供者注册信息. 如果没有为服务注册提供者, 可能返回 null.

      原文: Queries for a provider registration. This may return null if no provider has been registered for a service.

      类型参数:
      T - 服务接口类型
      参数:
      service - 服务接口
      返回:
      提供者注册信息或 null
    • getRegistrations

      获取插件的提供者注册信息.

      原文: Get registrations of providers for a plugin.

      参数:
      plugin - 插件
      返回:
      提供者注册信息
    • getRegistrations

      获取服务的提供者注册信息. 返回的列表是不可修改的.

      原文: Get registrations of providers for a service. The returned list is unmodifiable.

      类型参数:
      T - 服务接口类型
      参数:
      service - 服务接口
      返回:
      注册信息列表
    • getKnownServices

      @NotNull @NotNull Collection<Class<?>> getKnownServices()
      获取已知服务列表. 如果服务有已注册的提供者, 则该服务是已知的.

      原文: Get a list of known services. A service is known if it has registered providers for it.

      返回:
      已知服务列表
    • isProvidedFor

      <T> boolean isProvidedFor(@NotNull @NotNull Class<T> service)
      返回是否已为服务注册了提供者. 不要先检查此方法然后再调用 load(service), 因为那将是非线程安全的情况.

      原文: Returns whether a provider has been registered for a service. Do not check this first only to call load(service) later, as that would be a non-thread safe situation.

      类型参数:
      T - 服务类型
      参数:
      service - 要检查的服务
      返回:
      是否有已注册的提供者