Skip to content

PacketEvents

Huynh Tien edited this page Jul 8, 2025 · 2 revisions

Add dependency

Add io.github.projectunified:uni-dialog-packetevents to your build tools

For example, here is the dependency for Maven:

<dependency>
    <groupId>io.github.projectunified</groupId>
    <artifactId>uni-dialog-packetevents</artifactId>
    <version>VERSION</version>
</dependency>

Check here for more information on other build tools

Check here for the JavaDoc

Basic Usage

Create a Dialog Manager

Create a PocketEventsDialogManager like this:

String defaultNamespace = "testdialogs";
PocketEventsDialogManager dialogManager = new PocketEventsDialogManager(defaultNamespace) {
    @Override
    protected @Nullable Object getPlayer(UUID uuid) {
        return null; // Return an object representing the player (must be supported by PacketEvents)
    }

    @Override
    protected UUID getPlayerId(Object player) {
        return null; // Return an UUID of the player
    }
};

Implement the required methods getPlayer and getPlayerId

For example, here is how to do it in Spigot:

String defaultNamespace = "testdialogs";
PocketEventsDialogManager dialogManager = new PocketEventsDialogManager(defaultNamespace) {
    @Override
    protected @Nullable Player getPlayer(UUID uuid) {
        return Bukkit.getPlayer(uuid);
    }

    @Override
    protected UUID getPlayerId(Object player) {
        Player p = (Player) player;
        return p.getUniqueId();
    }
};

Register the Dialog Manager

Simply call the register method

dialogManager.register()

Create a Dialog

The preferred way is to construct a Dialog and call its opener to get the DialogOpener. The DialogOpener is preserved and used to open the dialog for the player.

DialogOpener dialogOpener = dialogManager.createConfirmationDialog()
        .title("Sample Dialog")
        .canCloseWithEscape(true)
        .afterAction(Dialog.AfterAction.CLOSE)
        .body(builder -> builder.text().text("This is a sample dialog. Do you want to proceed?"))
        .input("name", builder -> builder.textInput().label("Enter your name:"))
        .yesAction(builder -> builder.label("Confirm"))
        .noAction(builder -> builder.label("Cancel"))
        .opener();

Open the Dialog

UUID playerUUID;
dialogOpener.open(playerUUID);

Known limitation

  • ItemBody only display the material of the item and not its components

Clone this wiki locally