Selectors

Minecraft target selectors choose players or entities without hardcoding a UUID or exact player name. Kore exposes them as typed builders, so you can compose filters in Kotlin instead of manually writing @e[...] strings.

For the vanilla syntax reference, see the Minecraft Wiki target selectors page.

Base selector helpers

Kore provides helpers for the common Java Edition selector bases:

  • allPlayers() -> @a
  • allEntities() -> @e
  • nearestPlayer() -> @p
  • nearestEntity() -> @n
  • randomPlayer() -> @r
  • self() -> @s
  • player("Name") -> player-name-filtered @a[...]
val everyone = allPlayers()
val executor = self()
val nearest = nearestPlayer()
Kotlin

Filtering targets

Each selector helper accepts a SelectorArguments builder.

val nearbyZombies = allEntities {
	type = EntityTypes.ZOMBIE
	distance = rangeOrIntEnd(16)
	sort = Sort.NEAREST
	limit = 5
}
Kotlin

This generates a selector equivalent to:

@e[type=minecraft:zombie,distance=..16,sort=nearest,limit=5]
Mcfunction

Common selector arguments

Kore exposes the main Java Edition selector filters directly as mutable properties.

  • position: x, y, z
  • volume: dx, dy, dz
  • distance: distance
  • scoreboard filters: scores
  • advancement filters: advancements
  • sort and cap: sort, limit
  • player/entity metadata: name, team, tag, gamemode, type, predicate, nbt
  • rotations: xRotation, yRotation

Example with position and volume:

val entitiesInRoom = allEntities {
	x = 10.0
	y = 64.0
	z = -4.0
	dx = 8.0
	dy = 4.0
	dz = 8.0
}
Kotlin

Score-based filtering

Selectors integrate nicely with Scoreboards and other scoreboard-driven logic.

val activePlayers = allPlayers {
	scores = scores {
		"round" greaterThanOrEqualTo 1
		"lives" greaterThan 0
	}
}
Kotlin

That is especially useful in execute, timers, game loops, and mini-game state tracking.

Inverting filters

Several selector filters support inversion.

val nonSpectators = allPlayers {
	gamemode = !Gamemode.SPECTATOR
	team = !"admins"
}
Kotlin

You can also invert type, predicate, and nbt filters.

Limit and sorting

Kore keeps the vanilla sort + limit pattern explicit.

val oneRandomPlayer = allPlayers {
	sort = Sort.RANDOM
	limit = 1
}

val nearestMarkedEntity = allEntities(limitToOne = true) {
	tag = "arena_marker"
	sort = Sort.NEAREST
}
Kotlin

Use limitToOne = true when you want a concise single-target selector without repeating limit = 1.

Parsing selector strings

You can build a selector from its vanilla command representation with the selector(String) overload, then optionally refine it with the regular builder.

val fighters = selector("@a[tag=fighter,gamemode=!spectator]")

val nearbyFighters = selector("@a[tag=fighter]") {
  distance = rangeOrIntEnd(16)
}
Kotlin

Lower-level entry points are also available: Selector.fromString("@e[limit=1]") returns a Selector, and SelectorArguments.fromString("limit=1,tag=!foo") parses only the bracket content. All selector arguments are supported, including nested scores, advancements, and SNBT nbt filters.

Using selectors in commands

Selectors can be reused anywhere an EntityArgument, DataArgument, PossessorArgument, or ScoreHolderArgument is accepted, so they show up naturally across the Commands and Functions APIs.

val fighters = allPlayers {
	tag = "fighter"
}

function("round_start") {
	effect(fighters) { give(Effects.SPEED, duration = 10, amplifier = 1) }
	tellraw(fighters, textComponent("Fight!"))
	scoreboard.players.set(fighters, "combo", 0)
}
Kotlin

Practical tips

  • Prefer reusable selector values when the same filter appears in several functions.
  • Use self() when logic should apply to the current execution context.
  • Use generated entity types and predicates instead of raw strings whenever possible.
  • Keep complex filters readable by assigning them to vals before entering large command blocks, and check the Cookbook if you want to turn those values into reusable helpers.

See also