Skip to content

Add Post Effect API - #14267

Open
Doc94 wants to merge 4 commits into
PaperMC:dev/26.3from
Doc94:feature/post-effect-api
Open

Doc94 wants to merge 4 commits into
PaperMC:dev/26.3from
Doc94:feature/post-effect-api

Conversation

@Doc94

@Doc94 Doc94 commented Sep 16, 2026

Copy link
Copy Markdown
Member

This PR add support for the server-side implementation for send/remove post effects.

@Doc94
Doc94 requested a review from a team as a code owner September 16, 2026 12:47
@github-project-automation github-project-automation Bot moved this to Awaiting review in Paper PR Queue Sep 16, 2026
@GliczDev

GliczDev commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Post effects are order dependent, imo the API should expose something like setPostEffects rather than add/remove methods

@Doc94
Doc94 force-pushed the feature/post-effect-api branch from e6eb04c to 632cee2 Compare September 16, 2026 13:47
@Doc94

Doc94 commented Sep 16, 2026

Copy link
Copy Markdown
Member Author

Post effects are order dependent, imo the API should expose something like setPostEffects rather than add/remove methods

True... i just try to mirror the vanillla command, but override the order directly can be good for the API.
added to the PR.

@Override
public boolean setPostEffects(final List<Key> postEffects) {
Preconditions.checkArgument(postEffects != null, "postEffects cannot be null");
return this.getHandle().setPostEffects(postEffects.stream().filter(Objects::nonNull).map(PaperAdventure::asVanilla).distinct().toList());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Wouldn't it make more sense to throw on nulls and dublicates instead of silently ignoring those?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I try to mirror vanilla and also try to reduce the implementation to just silently remove inconsistences rather than check all the list for Preconditions and save again for send.
and this only cover server-side effects... client can still has a few (like when you spectate a creeper) effects so not sure if is necesary throws rather than non-null list

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

and save again for send.

Well with something like

    public boolean setPostEffects(final List<Key> postEffects) {
        Preconditions.checkArgument(postEffects != null, "postEffects cannot be null");
        LinkedHashSet<Identifier> ids = new LinkedHashSet<>(postEffects.size());
        for (Key effect : postEffects) {
            Preconditions.checkArgument(effect != null, "effects cannot be null");
            Preconditions.checkArgument(ids.add(PaperAdventure.asVanilla(effect)), "effects cannot be duplicate");
        }
        return this.getHandle().setPostEffects(ids);
    }

And

+    public boolean setPostEffects(final Collection<Identifier> postEffects) {
+        if (com.google.common.collect.Iterables.elementsEqual(this.postEffects, postEffects)) {
+            return false;
+        }

The resave etc shouldn't really impact anything. Just silently stripping invalid part of the input isn't consistent with other methods in same class like sendEquipmentChange or give

But for clientside behavior you're right that it's indeed a bit different than what command presents, as even ClientboundPostEffectsPacket and its handlers accepts duplicate post effects which should in theory work together, but I still don't think that silent ignore would be good

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

okay that looks fine to me... im going to include this.

Co-authored-by: mastermc05 <63639746+mastermc05@users.noreply.github.com>
@Lulu13022002 Lulu13022002 added the dev/next Changes related to the snapshot / next branch label Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dev/next Changes related to the snapshot / next branch

Projects

Status: Awaiting review

Development

Successfully merging this pull request may close these issues.

4 participants