Paper icon indicating copy to clipboard operation
Paper copied to clipboard

Dialog registry API

Open Machine-Maker opened this issue 6 months ago • 6 comments

Adds 2 temporary methods to show/clear dialogs from a Player. Will be replaced by adventure methods.

Player#tempShowDialog and Player#tempClearDialog.

Machine-Maker avatar Jun 15 '25 00:06 Machine-Maker

Last updated for: ade079827c0165ac5b943f4fecc0f6c7370b4c6c.

Download the Paperclip jar for this pull request: paper-12671.zip

Maven Publication

The artifacts published by this PR:

Repository Declaration

In order to use the artifacts published by the PR, add the following repository to your buildscript:

repositories {
    maven("https://maven-prs.papermc.io/Paper/pr12671") {
        name = "Maven for PR #12671" // https://github.com/PaperMC/Paper/pull/12671
        mavenContent {
            includeModule("io.papermc.paper", "dev-bundle")
            includeModule("io.papermc.paper", "paper-api")
        }
    }
}

Something we need to decide is how to handle the "custom all" dialog action. This is the action that sends a full CompoundTag of all the input values back to the server using the new packet. Right now, there's no way to listen for these.

Do we just add an event for both config/game phase that includes the player its from, the id of the payload, and the BinaryTagHolder payload? Or do we do smth like adventure click callback provider?

Machine-Maker avatar Jun 19 '25 05:06 Machine-Maker

Do we just add an event for both config/game phase that includes the player its from, the id of the payload, and the BinaryTagHolder payload? Or do we do smth like adventure click callback provider?

I personally would prefer to at least have an event if that allows listening to arbitrary dialogs too but a way to directly react on some form of callback directly from the code that creates the dialog in a plugin would be nice too but I feel the event would be more important. Ideally the data would be in a format that can be easily read e.g. a key -> value map instead of raw NBT.

Phoenix616 avatar Jun 20 '25 13:06 Phoenix616

Width and height range

There really should be org.jetbrains.annotations.Range annotations or javadoc comments stating that the width and height parameters should be at least 1 and max of whatever it is, most commonly it's 1024, but there are exceptions where it's less. For example the width and height parameters for DialogBody.ItemBody have a max value of 256.

These numbers are from the minecraft wiki.

Default values

One other thing I'd like to see is default values being used. So you don't have to specify width/height and use the default.

Privatech38 avatar Jun 21 '25 20:06 Privatech38

Ok, I pushed a super duper rough concept of the PlayerCustomClickEvent which includes 2 methods to extract a dialog response. One method takes the dialog instance, and tries to validate its inputs against the received payload, returning null if its not valid. Of course you should be making the payload ids super unique so you know its your dialog.

The other is a raw response wrapper with methods to just get any bool, float, or string in the top level of the response payload (if the response payload exists and is a compound tag).

And of course you can get a BinaryTagHolder and parse it into NBT using whatever library you want.

Machine-Maker avatar Jun 22 '25 01:06 Machine-Maker

Ok, I added another approach. You can manually specify a callback that runs. Create it with DialogAction#customAll(Key, DialogActionCallback, ClickCallback$Options) and use it in the actions.

Machine-Maker avatar Jun 22 '25 04:06 Machine-Maker

Ok, I added another approach. You can manually specify a callback that runs. Create it with DialogAction#customAll(Key, DialogActionCallback, ClickCallback$Options) and use it in the actions.

why even add a key, feels like this should just create a key internally

Hugo5000 avatar Jun 27 '25 19:06 Hugo5000

Yeah, I think you're right. Will remove.

Machine-Maker avatar Jun 27 '25 21:06 Machine-Maker

I did not see a way to make a DialogAction close the dialog? Am I missing something or is that just not a thing? I'd be needed if you don't auto close it.

I know adventure will add a Audience#closeDialog but I'd feel like there should be a predefined DialogAction#close that removed the boiler plate of having do to a customClick

Hugo5000 avatar Jun 27 '25 22:06 Hugo5000

You don't have to specify any action. In say, a confirmation dialog, the dialog will follow the DialogAfterAction on any button click.

Machine-Maker avatar Jun 27 '25 23:06 Machine-Maker

Paasdag avatar Jul 05 '25 12:07 Paasdag