#ctx.source.player is undefined

3 messages · Page 1 of 1 (latest)

pliant axle
#

i'm on kubejs 1802.5.5, trying to make a simple command that just teleports you to spawn:

  const { commands: Commands } = event;

  event.register(Commands.literal('spawn')
    .executes(ctx => {
      let player = ctx.source.player;
      console.info('hi');
      console.info(ctx);
      console.info(player);
      
      player.teleportTo('minecraft:overworld', 0, 100, 0, player.yaw, player.pitch);
      player.displayClientMessage(Component.green('Teleported to spawn!'), true);
      return 1;
    })
  );
});```

when i run the command, my logs show this:
```[Server thread] [KubeJS Server/INFO]: hi
[Server thread] [KubeJS Server/INFO]: com.mojang.brigadier.context.CommandContext@c27a2f62 [com.mojang.brigadier.context.CommandContext]
[Server thread] [KubeJS Server/INFO]: undefined
[Render thread] [net.minecraft.client.gui.components.ChatComponent/INFO]: [CHAT] An unexpected error occurred trying to execute that command```

as you can see, ctx.source.player is undefined even though the docs say thats what i should use, am i doing something wrong?
plucky sinewBOT
#

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

pliant axle
#

i found out that ctx.source.entity returns ServerPlayer['sylqui'/237, l='ServerLevel[world]', x=-136.38, y=63.00, z=248.25] [net.minecraft.server.level.ServerPlayer], is there a way i can use this to run the teleport?