Players and entities
Look up and move players, change what one of them sees, and work with mobs, mannequins and other entities from your script.
Players who are offline
server.get_offline_player_by_name(name) and server.get_offline_player_by_uuid(id) find a player who has joined this server, online or not (Paper's Bukkit.getOfflinePlayer with hasPlayedBefore). A player who never joined gives none. The name matches in any letter case.
The answer is an OfflinePlayer:
id: the player's UUID;name: the name the player last joined with;first_joined: the first join, which can be none;last_seen: the last join or leave.
Times are Unix time in milliseconds (UTC). The server keeps the 20,000 players it saw last and answers from memory, so commands like /seen, mail, friends or ban lists need no table of their own. The lookup does not say whether the player is online: use get_player_by_uuid for that.
Join and leave messages
A join or leave line goes to every player who may see the player, and to the console. To send no line, set cancelled in the handler of PlayerJoinEvent or PlayerLeaveEvent, or set join_message or leave_message to an empty text (TextComponent::text(""), no style, no children). Nobody gets a line then, the console included, and the join or leave itself goes on. A text of a single space is still a line.
Teleport players
player.teleport, player.teleport_world, player.change_world and entity.teleport move a player or an entity. In PlayerTeleportEvent, events::event_teleport_cause() says why; these calls give the cause Plugin.
Teleport with a cause
teleport::teleport_player(&player, &world, position, yaw, pitch, cause) moves a player to a position in a world (the one the player is in, or another one), and the teleport event names the cause you pass (Paper's Entity#teleport(Location, TeleportCause)). An anti-cheat that undoes an impossible move passes TeleportCause::Unknown, so that a /back, a region or a log script does not take the setback for a trip the player meant.
The answers are those of player.change_world:
- a full world answers
WorldFulland nothing moves; - a script that cancels the teleport event keeps the player in place and the call answers
Ok; - so does a position that is not a finite number.
What a teleport does
- A position with an infinite or NaN coordinate is refused: nothing moves and no teleport event fires. A handler that sets such a
tokeeps the player in place. - A teleport takes a rider off its vehicle, for players and mobs:
/tp, an ender pearl, a script's teleport and a teleport into another world. The teleport event fires first, then the dismount event (causeteleport) and the vehicle exit event. Cancel the teleport event and the rider stays on the vehicle. - A Nether portal carries a player through with their boat, and
/rotateonly turns the player. - Handlers that cancel teleports or spawn point changes (
PlayerSpawnChangeEvent: beds, respawn anchors,/spawnpoint) are asked even while a player is changing world. If the server cannot ask them, the teleport or change does not happen. /spawnpointreports only the players whose change went through. A respawn whose bed or anchor is gone asks scripts before it clears the player's spawn point.
Where a player looks
PlayerMoveEvent and PlayerTeleportEvent carry the look before the event and the look it brings (Paper's getFrom() and getTo()):
events::move_from_look()andevents::move_to_look()give aLook { yaw, pitch }, and none for other events.events::set_move_to_look(look), from a blocking handler, sets the look the player gets instead.
A move event whose to differs from what the client sent, in position or in look, teleports the player there (cause Plugin) instead of taking the client's move. A look that is not a finite number is ignored, and a player who leaves a vehicle keeps their look.
A move that only turns the player fires the move event too; its position is where the player stands. Inside a move or teleport handler, player.get_yaw and player.get_pitch give the look before the move, so read move_to_look for the new one.
Waking up
A player who wakes up fires PlayerTeleportEvent with the cause ExitBed. from and to are the spot beside the bed where the player stands up, with the look of the player's head and the look towards the bed. The event does not fire when the two looks are the same. Cancel it and the player stays at that spot with the old look; change the destination and the player goes there.
Change what one player sees
These calls change one player's view only. The world, the entities and the other players stay as they are. For fake blocks and biomes, see Blocks, drops and explosions; for a colour over the whole screen, see Resource packs.
Time and weather
player.set_player_time(time, relative) gives one player their own time:
- with
relative = falsethe sky stands still at that time.timecounts whole days too, so it sets the moon phase (day count modulo 8; day 4 is the new moon); - with
relative = truethe player's time follows the world withtimeas an offset.
player.set_player_weather(weather) with PlayerWeather::Clear or Downfall shows the player their own weather and hides the world's rain and thunder until reset_player_weather. Take the time back with reset_player_time. Both end when the player leaves, and a change of the world's time does not replace them.
Sounds
player.stop_sound(sound, category) stops sounds for one player. The two filters combine like this:
- neither: every sound stops;
- a sound only: that sound stops in every category;
- a category only: every sound of that category stops;
- both: only that sound in that category stops.
On Bedrock the client stops sounds by name only, so a category alone stops nothing.
A sound can follow an entity as it moves (Paper's playSound(Entity, ...)): for one player with player.play_sound_on_entity or play_custom_sound_on_entity, or for everyone who sees the entity with world.play_sound_on_entity or play_custom_sound_on_entity. A looped sound on the player's own entity stays with them as they walk and turn.
A player who does not see the entity hears nothing. A removed entity, a volume or pitch that is not a number, a sound key that is not a key and, for the world calls, an entity of another world return an error and play nothing. A Bedrock player hears the sound once, where the entity is.
Armour and held items
player.send_equipment_change(&entity, changes) shows one player different armour or held items on an entity; an empty stack hides the slot. The entity's real equipment does not change, and the next real change, or the entity returning into sight, shows the real items again. For a look that stays until you clear it, use living_entity.set_equipment_look; Bedrock players get that look in the hand slots only.
Another coat on a mob
mob.set_variant_look(viewers, name) shows one player, or every player, another coat on a wolf, cat, frog, pig, cow or chicken: a vanilla variant, or one from your own data pack ("mypack:coat"). The animal's real variant, which the server saves, breeds and reports, stays. clear_variant_look takes the look back and get_variant_look reads what a player is shown. Bedrock players see the real variant.
Hidden players and entities
player.hide_player(other) and player.hide_entity(entity_id) hide someone from one player; show_player and show_entity undo it, and can_see and can_see_entity read it.
While you hide a player, the particles the server makes for that player do not reach the viewer: the sweep of an attack, enchantment particles, the splash and smoke of a water bottle or bucket used on a block. Particles the client draws from the player's own entity (a totem, a critical hit, eating) go with the entity. Particles you spawn yourself are yours.
A reload of your script, by hot reload or by the restart after a failure, keeps its hides: nothing is shown at the reload, and the new instance can take them back. They are shown only when the script is unloaded or its new instance does not load.
Hidden cosmetics
player.set_cosmetics_hidden(viewers, true) hides a player's Play Strawberry cosmetics (the hat) from the players you choose, for example in a minigame. They see the real head slot until you pass false, your script unloads or the player leaves. get_cosmetics_hidden(viewer) reads it. A script can only hide cosmetics: it never gives, changes or takes one.
Items in hand
For a player, the main hand of get_equipment and set_equipment is the selected hotbar slot, the same as inventory.set_item on that slot: the player and the players around see the change at once. Armour, the off hand and every entity that is not a player use their own equipment.
PlayerItemConsumeEvent fires when a player finishes eating or drinking. Cancel it and the item is kept. See also Events and commands.
Poses and sleeping
Hold a player lying down
player.set_pose(EntityPose::Swimming, true) holds a player lying, also on the player's own screen: the server shows that client invisible barriers just above, moves them with the player and takes them away when you release the pose, the player dies or your script unloads. The call fails when the player is dead or asleep, when there is no room, or when a script cancels the pose change.
Leave a player out of the sleep count
player.set_sleeping_ignored(true) leaves a player out of the players who must sleep for the night to pass, and player.is_sleeping_ignored() reads it (Paper's Player#setSleepingIgnored). Use it for a player who is away or a hidden staff member.
- The player stays left out while at least one script asks for it. When your script is unloaded, its own wish is taken back, and a player who joins again is counted again.
- A player left out counts as one who sleeps, and the night passes only while somebody really sleeps.
Compasses
player.set_compass_target(pos) points a player's compass at a position in the world the player is in, on Java and on Bedrock. It points there only while the player stays in that world: a respawn or a world change ends it. player.get_compass_target() gives the position the client was told last. Beds, respawn anchors and /spawnpoint set the respawn point without moving the compass.
To aim one compass item at a place, whatever world its holder is in, use item_stack.set_lodestone_target(Some(...)) with a LodestoneTarget { world_key, pos, tracked }, and read it with get_lodestone_target():
tracked: falsepoints at the position whatever block is there;tracked: truebinds the compass to a lodestone: when no lodestone stands there, it loses the target. A target in another world or in a chunk that is not loaded is kept;Nonemakes it a plain compass again;- a
world_keythat is not anamespace:pathkey is refused.
Get the key with world.get_key(): minecraft:overworld for the server's overworld, minecraft:<name> for a world a script made (the name in lower case, spaces as _), and the data pack's own key for its dimension. world.get_id and world.get_name give the world's name, and world.get_dimension its dimension type; none of them is the key a client uses.
Client features of Strawberry Core
A server owner can forbid Strawberry Core features. player.set_client_rules(forbidden) forbids one player more of them, for example zoom inside a PvP arena. forbidden is a set of bits; it replaces what your script forbade that player before, and 0 forbids nothing more.
- bit 0 Fullbright, 1 zoom, 2 perspective, 3 hitbox, 4 reach display, 5 combo display, 6 damage indicator, 7 jump reset;
- bit 12 time changer, 13 weather changer, 14 camera distance, 15 clear fluid fog.
get_client_rules reads your script's bits, and server.client_rules() reads the owner's set. A script can never allow what the owner forbade. Your bits end when your script unloads or the player leaves. Only a Strawberry Core client follows them.
Advancements
server.get_advancement(id) and the player's advancement calls (progress, award, revoke, has and select tab) find the game's advancements and those of the server's data packs. Write a data pack id as in the pack (quests:first) and a game one bare (story/root) or with minecraft:. When a pack and the game use the same id, the pack's advancement is found. An unknown id finds nothing, answers false or changes nothing.
server.get_all_advancement_ids() lists every advancement of the server, each once, in the order of the advancement tree.
Find entities
chunk.get_entities() lists the entities of one chunk (Paper's Chunk#getEntities), and world.get_entities_in_box(corner_a, corner_b) those of a box with sides of at most 200 blocks (World#getNearbyEntities). Neither loads a chunk: a chunk whose entities are not loaded gives an empty list.
Remove an entity
entity.remove() removes the whole entity, whichever handle you hold. On a player it does nothing: a player leaves through a kick or a disconnect.
entity.try_remove() removes the entity and returns true only for the call that removed it. When two players take the same mob in the same tick, only one of them gets it.
EntityRemoveEvent fires when an entity other than a player leaves the world. It is for monitoring: cancelling it does nothing. Its cause is DEATH, DISCARD, UNLOAD, PLAYER_QUIT, PLUGIN, or a finer reason: DESPAWN, PICKUP, MERGE, HIT, DROP, EXPLODE, OUT_OF_WORLD or TRANSFORMATION.
Keep an entity as a snapshot
entity.snapshot() returns everything the entity is saved with, as at most 64 KiB of bytes that you can keep in an item or a file (Paper's Entity#createSnapshot). For a villager that is its profession, level, trades with their uses, gossip, memories and age; for every entity its health, name, effects, tags and script data. The UUID, the position, the riders and the leash are left out. Players, lightning bolts, fishing bobbers, leash knots and removed entities give no snapshot.
world.spawn_entity_from_snapshot(&bytes, pos) makes a new entity from those bytes at pos, with a UUID of its own. The spawn event fires as for spawn_entity.
The bytes are checked as untrusted data, because a player may have changed the item that holds them. Bytes that are too large or broken, an unknown entity type, a value that is not a finite number, a snapshot from a newer server or one with riders is refused with a SnapshotError (TooLarge, Malformed, NotAllowed, Cancelled), and nothing is spawned.
For a mob catcher: take the snapshot, then call try_remove(), and give the item only when it returned true.
How mobs come into the world
For mobs that turn into other mobs, see AI goals.
Spawn reason
entity.get_spawn_reason() tells how an entity came into the world (Paper's Entity#getEntitySpawnReason). A SpawnReason is one of Natural, ChunkGeneration, Spawner, TrialSpawner, SpawnerEgg, DispenseEgg, Egg, Bucket, Breeding, Command, Conversion, Reinforcements, Jockey, Rehydration, NetherPortal, Plugin, Other (a reason Paper names that this list does not) or Unknown.
The reason is saved with the entity, so it survives a chunk reload and a restart. An entity the server spawned without a reason (a player, a dropped item, a projectile) reads Unknown. For a rule such as "no reward for a spawner's mob", read EntityDeathEvent::spawn_reason() in the death event.
Natural spawns
The mobs that appear around players by themselves fire the creature spawn event before they are added, with the spawn reason natural and no player. Cancel it and the mob is not added, and it does not count against the mob caps. Use it to keep mobs out of a lobby or a region, or to count spawns.
Monster spawners
The extension event "pre-spawner-spawn" (events::PRE_SPAWNER_SPAWN) fires before a spawner creates its mob. Read the spot, the mob type and the spawner with event.pre_spawner_spawn(). Cancel it to skip the attempt (the spawner still waits for its next delay), and call event.set_abort_spawn(true) to end the rest of that tick's attempts. Register it as blocking with context.register_extension_event_handler.
Potion effects
EntityPotionEffectEvent fires whenever an effect is added, changed, removed or cleared on a living entity (Paper's EntityPotionEffectEvent). In a handler:
EntityPotionEffectEvent::action()returnsAdded,Changed(the entity already had an effect of that type),Cleared(all effects go: milk,/effect clear, a totem, a death; one event for each effect) orRemoved(one effect goes: it runs out,/effect clear <effect>, your ownremove_effect).EntityPotionEffectEvent::cause()returns theEffectCause:AreaEffectCloud,Arrow,Attack,Axolotl,Beacon,Command,Conduit,Conversion,Death,Dolphin,Expiration,Food(a honey bottle too),Illusion,Milk,Nautilus,Plugin(your ownadd_effect,remove_effectandclear_effects),PotionDrink,PotionSplash,SpiderSpawn,Totem,VillagerTrade,Warden,WitherRoseorUnknown.
The list also holds PatrolCaptain and TurtleHelmet, which the server does not send. The event names the effect concerned. Cancel it and things stay as they were; a death clears the effects whatever a handler answers. The same values come from events::event_effect_action() and events::event_effect_cause().
Villagers
merchant::trading_player(&entity) gives the player who has the trading window of a villager or wandering trader open, or none.
Mannequins
A mannequin is a player figure you set up from your script:
entity.set_mannequin_label(Some(text))shows your text under the figure, andset_mannequin_label(None)hides the label that a vanilla client shows ("NPC") when nothing is set.entity.set_mannequin_immovable(true)makes it stand still: players and entities do not push it, and it does not fall or drift in water.entity.set_pose(pose, fixed)takesStanding,Crouching,Swimming,FallFlyingandSleepingand refuses any other pose with the reason. The box follows the pose, so a lying figure is low. Withfixedthe game does not change the pose until you set another one.entity.set_mannequin_profile(profile)gives it the skin of a player account (by name or id) or a skin from your resource pack (namespace:pathofassets/<namespace>/textures/<path>.png), with the wide or slim arm model.get_mannequin_profilereads it. A script gives no cape or elytra texture.
The label and the immovable calls return an error for an entity that is not a mannequin. A Bedrock player sees a mannequin as a player with no label under it; see What Bedrock players see.
entity.set_pose also poses any other entity that is not a player (a player has player.set_pose). entity.set_head_yaw(degrees) turns the head of a living entity alone; set_rotation turns head and body together again.