Skip to content

Add PlayerCodeOfConductSendEvent - #13512

Merged
Warriorrrr merged 5 commits into
PaperMC:mainfrom
mbax:conductivity
Jul 26, 2026
Merged

Add PlayerCodeOfConductSendEvent#13512
Warriorrrr merged 5 commits into
PaperMC:mainfrom
mbax:conductivity

Conversation

@mbax

@mbax mbax commented Jan 5, 2026

Copy link
Copy Markdown
Member

Enables customizing the code of conduct per send.

Just throwing the idea out there. Draft because I'm not sure we even want this and because I haven't bothered to test it yet (but I can't see it blowing up).

Possible uses:

  1. Presently, code of conduct attempts to be based on user locale, then defaults to en_us. Perhaps someone would want to try some other locales first based on their locale.
  2. Separate code of conduct for users once they're staff.
  3. Separate code of conduct for visitors vs members in a "greylist" server.
  4. Forcing users to always accept the code of conduct each join, or every X days, by adding a unique value to the end of the code of conduct.

Comment thread paper-api/src/main/java/org/bukkit/event/player/PlayerCodeOfConductSendEvent.java Outdated
Comment thread paper-api/src/main/java/org/bukkit/event/player/PlayerCodeOfConductSendEvent.java Outdated
@mbax
mbax force-pushed the conductivity branch 2 times, most recently from 8279814 to 7c093bd Compare January 12, 2026 02:41

@Warriorrrr Warriorrrr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems like fine API to have to me, and does already work when tested. One important thing that will either need to be documented or addressed is that the event won't be fired if the server doesn't have code of conducts enabled, or has no txt files configured in the codeofconduct folder.

@Warriorrrr Warriorrrr added type: feature Request for a new Feature. scope: api labels Jul 11, 2026
@mbax

mbax commented Jul 11, 2026

Copy link
Copy Markdown
Member Author

One important thing that will either need to be documented or addressed is that the event won't be fired if the server doesn't have code of conducts enabled, or has no txt files configured in the codeofconduct folder.

Would it be worth looking into firing it cancelled, making it possible to uncancel in those situations? Like, would that behavior match how other events work or would it be considered a problem for server admins wanting to disable it?

@electronicboy

Copy link
Copy Markdown
Member

I feel that pre-cancelled events are generally more of a legacy compat behavioral hack of "we're firing this when it really shouldn't, this is cancelled because no side-effects will occur from this, we just want to let you know" - I guess you could argue that applies here, but I think the reality is that the intent works just fine here, the intent is to send it unless something cancels it, it will just do nothing if there is no data to send, etc

@mbax

mbax commented Jul 11, 2026

Copy link
Copy Markdown
Member Author

I was viewing it as a "this is where I'd put my code of conduct, IF I HAD ONE!" opportunity for plugins to define their own so server admins don't have to define a dummy one just to get their pre-player code of conduct plugin to work.

@electronicboy

Copy link
Copy Markdown
Member

Yea, I understand that, my thought was more "empty by default rather than a cancelled boolean", or something to that effect; cancellation to me always felt like it should be more plugin driven rather than api caller driven

@mbax

mbax commented Jul 11, 2026

Copy link
Copy Markdown
Member Author

Ah, so empty message doesn't send, like the join/quit event messages? That seems reasonable.

@electronicboy

Copy link
Copy Markdown
Member

Yes

@mbax

mbax commented Jul 11, 2026

Copy link
Copy Markdown
Member Author

Updated to always fire!

@NonSwag

NonSwag commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

I fail to understand why this event would even fire empty if there was no code of conduct.
Is there no API to send a code of conduct?

@electronicboy

Copy link
Copy Markdown
Member

You can only send the COC inside of configuration mode which is generally a chore for plugins to deal with the whole rigamarole of when the server is already there with the handling for this process anyways

@electronicboy electronicboy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Flow, etc, looks fine to me

@mbax
mbax marked this pull request as ready for review July 11, 2026 17:43
@mbax
mbax requested a review from a team as a code owner July 11, 2026 17:43
@mbax

mbax commented Jul 11, 2026

Copy link
Copy Markdown
Member Author

Pushed this diff at the advice of @Warriorrrr

-+        if (true || !codeOfConducts.isEmpty()) { // Always fire the task
++        if (io.papermc.paper.event.player.PlayerCodeOfConductSendEvent.getHandlerList().getRegisteredListeners().length > 0 || !codeOfConducts.isEmpty()) { // Fire even if empty, if there are event listeners to potentially send one

@Owen1212055

Copy link
Copy Markdown
Member

These paper comments dont properly wrap the diff

@mbax

mbax commented Jul 11, 2026

Copy link
Copy Markdown
Member Author

These paper comments dont properly wrap the diff

Took me forever to notice the single linebreak at the bottom. Next time please share the specific issue! 😭

Fires even if the player was not about to receive one, so any player can
receive one even if default disabled. Setting to null cancels sending.
@papermc-projects papermc-projects Bot moved this from Awaiting review to Full approval in Paper PR Queue Jul 26, 2026
@Warriorrrr
Warriorrrr enabled auto-merge (squash) July 26, 2026 18:07
@Warriorrrr
Warriorrrr merged commit 26e81c4 into PaperMC:main Jul 26, 2026
2 checks passed
@github-project-automation github-project-automation Bot moved this from Full approval to Merged in Paper PR Queue Jul 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: api type: feature Request for a new Feature.

Projects

Status: Merged

Development

Successfully merging this pull request may close these issues.

7 participants