#Getting a player's entity data during a spawn event

3 messages · Page 1 of 1 (latest)

prime cradle
#

Hello. First time trying KubeJs! Im trying to get a player's entity data. Specifically a modded value.

The value is "apotheosis:world_tier" which using /data. I got to see my current value is:
"apotheosis:world_tier": "haven".

Im trying to use it to disable mob spawns depending on this value. However. Im not sure if I can access the player's data during these events.

Here's what I have tried so far:

EntityEvents.spawned("minecraft:zombie", event =>{
    // Get the player's WorldTier
    var nbt = event.player.getCompound(world_tier)
    let playerTier = event.player.world_tier;

    event.server.tell('worldTier: ' + playerTier);
    console.log('log test');
    if(playerTier == 'haven'){
        event.cancel();
    }  
});

However. it errors at trying to use the object event.player since that value is null:
Error in 'EntityEvents.spawned': dev.latvian.mods.rhino.EcmaError: TypeError: Cannot call method "getCompound" of null
Im assuming thats not how I access the player object. Any tips?

rigid shoreBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

runic slate
#

There is no player provided by the EntityEvents.spawned event, you would have to get the player through event.server.players, which returns a list of all players on the server.
You could then iterate through that list to find the highest value or instead just take the value from the first player.

Also just a heads up, you can treat player nbt like a js Object: player.nbt.somePathTo.someKey will return the value at {somePathTo:{someKey:<the value>}}