Skip to content

export player.NewContext function - #1358

Open
FDUTCH wants to merge 2 commits into
df-mc:masterfrom
FDUTCH:feat/export_newctx
Open

export player.NewContext function #1358
FDUTCH wants to merge 2 commits into
df-mc:masterfrom
FDUTCH:feat/export_newctx

Conversation

@FDUTCH

@FDUTCH FDUTCH commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@RestartFU RestartFU left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious, what do you need that for?

@FDUTCH

FDUTCH commented Jul 25, 2026

Copy link
Copy Markdown
Contributor Author

just curious, what do you need that for?

one of projects that I'm working on heavily relies on player.Context (for handling some stuff), it is useful cause you can call handler from other places

@HashimTheArab

Copy link
Copy Markdown
Collaborator

can you show an example of this usecase

@FDUTCH

FDUTCH commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

can you show an example of this usecase

seriously, what the hell are you even asking? didn't I explain clearly how this could be useful? or are you trying to teach me how to code?
or do you want me to start explaining my architectural decisions to you?

why am I the only one who gets questions like this? am I really that bad?

@HashimTheArab

Copy link
Copy Markdown
Collaborator

dude you need to calm down i just wanted to see if this is something that can be solved a better way instead of exposing that internal method

if you would rather have me not review your prs then ill let them sit, why are you being hostile over a simple question

@FDUTCH

FDUTCH commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

dude you need to calm down i just wanted to see if this is something that can be solved a better way instead of exposing that internal method

if you would rather have me not review your prs then ill let them sit, why are you being hostile over a simple question

okay simple answer:
I want to call player handler methods

@FDUTCH

FDUTCH commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

why are you being hostile over a simple question?
because I get asked it too often, and I've already answered it above

@HashimTheArab

Copy link
Copy Markdown
Collaborator

okay this might need a different api which is why i asked for an example

I've already answered it above
my question was different from the one above

// Context is the context passed to player event callbacks. It embeds the
// world Context, so world operations and Cancel are available directly, and
// adds the Player the event concerns. It is valid only during the callback.
type Context struct {
*world.Context
p *Player
}
// NewContext returns a Context for one event dispatch concerning p.
func NewContext(p *Player) *Context {
return &Context{Context: p.tx.Event(), p: p}
}

NewContext captures the transaction of the player, exposing it introduces footguns such as capturing the transaction of a stale player which will only panic once you call something like ctx.Block(..), and conflicts with "player.Context is valid only during its callback" which we documented. This was an explicit part of the new api design.

A better design to expose might be NewEventContext(tx *world.Tx, p *Player) *Context

@FDUTCH

FDUTCH commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

A better design to expose might be NewEventContext(tx *world.Tx, p *Player) *Context

we might call it NewEventContext, but passing world.Tx looks silly to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants