SIsilicon / WorldEdit-BE

A Minecraft Bedrock addon port of the famous WorldEdit mod for Minecraft: Java Edition.
GNU General Public License v3.0
292 stars 34 forks source link

Gametest Simulated Players cause many TypeErrors #286

Open ForestOfLight opened 3 months ago

ForestOfLight commented 3 months ago

Is there an existing issue for this?

Current behaviour

I'm currently developing a Simulated Players BP using the @minecraft/server-gametest module. I've run into this issue trying to use them in conjunction with my other addons. Whenever the Script API gets a list of the online players, any SimulatedPlayers will be included but undefined. This includes any event that might have a player or entity object. This results in lots of TypeErrors due to the Script API trying to get properties on undefined.

TypeError: cannot not read property 'foo' of undefined or Function doesn't exist on object. Etc.

Expected behaviour

The fix for this is not too difficult, just adding a simple undefined check to each getPlayers(), getAllPlayers(), and events where the event has an entity property will do the trick.

if (!event.entity) return;

Steps to reproduce

  1. Download Canopy & Understudy (both packs work together): https://github.com/ForestOfLight/Canopy, https://github.com/ForestOfLight/Understudy
  2. Add WorldEdit-BE, Canopy, and Understudy to a world.
  3. Give yourself the worldedit tag & CanopyAdmin tag.
  4. Run ./canopy commandPlayer true to enable the ./player command for spawning SimulatedPlayers.
  5. Run ./player <name> join to spawn a new SimulatedPlayer.

Content logs

[2024-08-20 11:53:13:348 ERROR] [Scripting] TypeError: cannot read property 'dimension' of undefined at isHotbarStashed (server/modules/player_util.js:114) at (server/index.is: 38) at (library/classes/eventEmitter. js:60) at forEach (native) at emit (library/classes/eventEmitter. js:59) at (library/Minecraft. js:148)

Minecraft version

1.21.21

Device and operating system

Windows 10

Additional info

No response