Mojira Archive
BDS-18964

Cannot call functions in a beforeEvent

Mojang please fix this, it is limiting us developers and causing immeasurable headaches. I'm tired of having to come up with dumb workarounds that bloats my code, wrapping my code in a system.run() that doesn't work half the time, and giving up on some projects because I'm unable to call some functions in a beforeEvent. 

 

Tested JS Code:
world.beforeEvents.playerLeave.subscribe(({ player }) =>

{ // teleporting a player back to spawn when they leave     player.teleport(new Vector(0, 0, 0)) }

)

 

Affects @minecraft/server version 1.3.0-beta and up
 
Expected Result: Player is teleported to 0, 0, 0 before they leave the realm.
Actual Result: [Scripting][error]-ReferenceError: Native function [Entity::teleport] does not have required privileges.    at <anonymous> (main.js:33)
 
Every function that sets something does not work in a beforeEvent.

Comments2

Is this only happening on a Dedicated Server, Featured Server, realms, multiplayer or singleplayer? What platform/device are you using?
This ticket will automatically reopen when you reply.

It's by design for now that in a before event you can't run essentially any "update functions" in a before event, because the rest of the Minecraft infra is in an un-ideal state to be able to process those changes.  The main thing is to wrap them in a system.run (which will typically run a half-tick later) in a before event, and you should ensure you "re-fetch" things like entity objects inside of that functions.. Definitely feel that this is somewhat painful..

History6

AncientNewJersey

Changed description:

Mojang please fix this, it is limiting us developers and causing immeasurable headaches. I'm tired of having to come up with dumb workarounds that bloats my code, wrapping my code in a system.run() that doesn't work half the time, and giving up on some projects because I'm unable to call some functions in a beforeEvent. 

0

 

0

Tested JS Code:
0world.beforeEvents.playerLeave.subscribe(({ player }) =>

0{0// teleporting a player back to spawn when they leave0    player.teleport(new Vector(0, 0, 0))0}0

)
0 
0Expected Result: Player is teleported to 0, 0, 0 before they leave the realm.
0Actual Result: [Scripting][error]-ReferenceError: Native function [Entity::teleport] does not have required privileges.    at <anonymous> (main.js:33)
0 
0Every function that sets something does not work in a beforeEvent.

Mojang please fix this, it is limiting us developers and causing immeasurable headaches. I'm tired of having to come up with dumb workarounds that bloats my code, wrapping my code in a system.run() that doesn't work half the time, and giving up on some projects because I'm unable to call some functions in a beforeEvent. 

0

 

0

Tested JS Code:
0world.beforeEvents.playerLeave.subscribe(({ player }) =>

00{ // teleporting a player back to spawn when they leave     player.teleport(new Vector(0, 0, 0)) }00

)

0

 

0

Affects @minecraft/server version 1.3.0-beta and up
0 
0Expected Result: Player is teleported to 0, 0, 0 before they leave the realm.
0Actual Result: [Scripting][error]-ReferenceError: Native function [Entity::teleport] does not have required privileges.    at <anonymous> (main.js:33)
0 
0Every function that sets something does not work in a beforeEvent.

AncientNewJersey

Removed attachment: image-2024-01-13-23-34-21-009.png

[Mod] Umija5895M

Key

Platform

project

Added affects versions: 1.20.51

Removed affects versions: 1.20.51

[MCQA] v-weszaj
[Bot] Arisa
[MCQA] v-weszaj
Awaiting Response
AncientNewJersey
1
0
Unconfirmed
1.20.51