Class CachedFilterSelectorArgument

java.lang.Object
cn.nukkit.command.selector.args.CachedFilterSelectorArgument
All Implemented Interfaces:
ISelectorArgument, Comparable<ISelectorArgument>
Direct Known Subclasses:
C

@PowerNukkitXOnly @Since("1.19.60-r1") public abstract class CachedFilterSelectorArgument extends Object implements ISelectorArgument
CachedSimpleSelectorArgument类似,但是适用于过滤器模式。此处不做过多解释

See Also:
  • Constructor Details

    • CachedFilterSelectorArgument

      public CachedFilterSelectorArgument()
  • Method Details

    • getFilter

      public Function<List<Entity>,List<Entity>> getFilter(SelectorType selectorType, CommandSender sender, Location basePos, String... arguments) throws SelectorSyntaxException
      Description copied from interface: ISelectorArgument
      仅当方法isFilter()返回true时调用此方法

      方法返回的实体集合将传递到下一个参数

      Specified by:
      getFilter in interface ISelectorArgument
      Parameters:
      selectorType - 选择器类型
      sender - 命令发送者
      basePos - 若此参数解析需要用到相对坐标,则应该以此坐标为依据

      若此参数需要修改参照坐标(例如x,y,z参数),则应当在这个参数上修改

      在一条解析链上的参数只会使用一个Location对象

      arguments - 参数列表
      Returns:
      实体过滤器
      Throws:
      SelectorSyntaxException - 当解析出错
    • isFilter

      public boolean isFilter()
      Description copied from interface: ISelectorArgument
      是否启用过滤器模式

      若一个参数为过滤器模式,解析器将不会调用getPredicate()方法而是调用filter()方法

      这意味着参数将对到达此参数节点的所有实体进行检测,而不是相对于单个实体进行检测

      对于部分参数(例如"c"),需要启用此功能

      Specified by:
      isFilter in interface ISelectorArgument
      Returns:
      是否启用过滤器模式
    • cache

      protected abstract Function<List<Entity>,List<Entity>> cache(SelectorType selectorType, CommandSender sender, Location basePos, String... arguments) throws SelectorSyntaxException
      当未在缓存中找到解析结果时,则调用此方法对参数进行解析
      Throws:
      SelectorSyntaxException
    • provideCacheService

      protected com.github.benmanes.caffeine.cache.Cache<Set<String>,Function<List<Entity>,List<Entity>>> provideCacheService()
      初始化缓存时调用此方法

      若需要自己的缓存实现,则可覆写此方法

      Returns:
      Cache<Set<String>, Function<List<Entity>, List<Entity>>>