Document package net.md_5.bungee.api.dialog

This commit is contained in:
md_5 2025-05-20 21:37:03 +10:00
parent 53365e4b18
commit 75456b2c0a
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11
11 changed files with 148 additions and 16 deletions

View File

@ -7,17 +7,27 @@ import lombok.ToString;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import net.md_5.bungee.api.dialog.action.DialogClickAction; import net.md_5.bungee.api.dialog.action.DialogClickAction;
/**
* Represents a simple dialog with text and two actions at the bottom (default:
* "yes", "no").
*/
@Data @Data
@ToString @ToString
@EqualsAndHashCode @EqualsAndHashCode
@AllArgsConstructor @AllArgsConstructor
@Accessors(fluent = true) @Accessors(fluent = true)
public class ConfirmationDialog implements Dialog public final class ConfirmationDialog implements Dialog
{ {
@Accessors(fluent = false) @Accessors(fluent = false)
private DialogBase base; private DialogBase base;
/**
* The "yes" click action / bottom (appears on the left).
*/
private DialogClickAction yes; private DialogClickAction yes;
/**
* The "no" click action / bottom (appears on the right).
*/
private DialogClickAction no; private DialogClickAction no;
public ConfirmationDialog(DialogBase base) public ConfirmationDialog(DialogBase base)

View File

@ -1,9 +1,29 @@
package net.md_5.bungee.api.dialog; package net.md_5.bungee.api.dialog;
import org.jetbrains.annotations.ApiStatus;
/**
* Represents a dialog GUI.
*/
public interface Dialog public interface Dialog
{ {
/**
* Gets the dialog base which contains the dialog title and other options
* common to all types of dialogs.
*
* @return mutable reference to the dialog base
*/
DialogBase getBase(); DialogBase getBase();
/**
* Sets the dialog base.
* <br>
* For internal use only as this is mandatory and should be specified in the
* constructor.
*
* @param base the new dialog base
*/
@ApiStatus.Internal
void setBase(DialogBase base); void setBase(DialogBase base);
} }

View File

@ -6,16 +6,33 @@ import lombok.Data;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.dialog.body.DialogBody;
/**
* Represents the title and other options common to all dialogs.
*/
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@RequiredArgsConstructor @RequiredArgsConstructor
@Accessors(fluent = true) @Accessors(fluent = true)
public class DialogBase public final class DialogBase
{ {
/**
* The mandatory dialog title.
*/
private final BaseComponent title; private final BaseComponent title;
/**
* The name which is used for any buttons leading to this dialog (eg from a
* {@link DialogListDialog}). Otherwise defaults to {@link #title}.
*/
private BaseComponent externalTitle; private BaseComponent externalTitle;
private List<?> body; /**
* The body elements which make up this dialog.
*/
private List<DialogBody> body;
/**
* Whether this dialog can be closed with the escape key (default: true).
*/
private boolean canCloseWithEscape; private boolean canCloseWithEscape;
} }

View File

@ -9,19 +9,34 @@ import lombok.ToString;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ClickEvent;
/**
* Represents a dialog which contains buttons that link to other dialogs.
*/
@Data @Data
@ToString @ToString
@EqualsAndHashCode @EqualsAndHashCode
@Accessors(fluent = true) @Accessors(fluent = true)
public class DialogListDialog implements Dialog public final class DialogListDialog implements Dialog
{ {
@Accessors(fluent = false) @Accessors(fluent = false)
private DialogBase base; private DialogBase base;
/**
* The child dialogs behind each button.
*/
private List<Dialog> dialogs; private List<Dialog> dialogs;
/**
* The {@link ClickEvent} activated when the dialog is cancelled.
*/
@SerializedName("on_cancel") @SerializedName("on_cancel")
private ClickEvent onCancel; private ClickEvent onCancel;
/**
* The number of columns for the dialog buttons (default: 2).
*/
private int columns; private int columns;
/**
* The width of the dialog buttons (default: 150).
*/
@SerializedName("button_width") @SerializedName("button_width")
private int buttonWidth; private int buttonWidth;

View File

@ -11,17 +11,30 @@ import lombok.experimental.Accessors;
import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.dialog.action.DialogClickAction; import net.md_5.bungee.api.dialog.action.DialogClickAction;
/**
* Represents a dialog with text a list of action buttons grouped into columns
* and scrollable if necessary.
*/
@Data @Data
@ToString @ToString
@EqualsAndHashCode @EqualsAndHashCode
@Accessors(fluent = true) @Accessors(fluent = true)
public class MultiActionDialog implements Dialog public final class MultiActionDialog implements Dialog
{ {
@Accessors(fluent = false) @Accessors(fluent = false)
private DialogBase base; private DialogBase base;
/**
* The action buttons in the dialog. At least one must be provided.
*/
private List<DialogClickAction> actions; private List<DialogClickAction> actions;
/**
* The number of columns for the dialog buttons (default: 2).
*/
private int columns; private int columns;
/**
* The {@link ClickEvent} activated when the dialog is cancelled.
*/
@SerializedName("on_cancel") @SerializedName("on_cancel")
private ClickEvent onCancel; private ClickEvent onCancel;

View File

@ -1,29 +1,50 @@
package net.md_5.bungee.api.dialog; package net.md_5.bungee.api.dialog;
import com.google.common.base.Preconditions;
import java.util.Arrays;
import java.util.List; import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import net.md_5.bungee.api.dialog.action.DialogClickAction; import net.md_5.bungee.api.dialog.action.DialogSubmitAction;
import net.md_5.bungee.api.dialog.input.DialogInput; import net.md_5.bungee.api.dialog.input.DialogInput;
/**
* Represents a dialog which contains a variety of inputs and a multiple submit
* buttons at the bottom.
*/
@Data @Data
@ToString @ToString
@EqualsAndHashCode @EqualsAndHashCode
@AllArgsConstructor
@Accessors(fluent = true) @Accessors(fluent = true)
public class MultiActionInputFormDialog implements Dialog public final class MultiActionInputFormDialog implements Dialog
{ {
@Accessors(fluent = false) @Accessors(fluent = false)
private DialogBase base; private DialogBase base;
/**
* The inputs to the dialog. At least one input must be provided.
*/
private List<DialogInput> inputs; private List<DialogInput> inputs;
private List<DialogClickAction> actions; /**
* The action/submit buttons for the dialog. At least one action must be
* provided.
*/
private List<DialogSubmitAction> actions;
public MultiActionInputFormDialog(DialogBase base) public MultiActionInputFormDialog(DialogBase base, DialogInput input, DialogSubmitAction action)
{ {
this( base, null, null ); this( base, Arrays.asList( input ), Arrays.asList( action ) );
}
public MultiActionInputFormDialog(DialogBase base, List<DialogInput> inputs, List<DialogSubmitAction> actions)
{
Preconditions.checkArgument( inputs != null && !inputs.isEmpty(), "At least one input must be provided" );
Preconditions.checkArgument( actions != null && !actions.isEmpty(), "At least one action must be provided" );
this.base = base;
this.inputs = inputs;
this.actions = actions;
} }
} }

View File

@ -7,16 +7,23 @@ import lombok.ToString;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import net.md_5.bungee.api.dialog.action.DialogClickAction; import net.md_5.bungee.api.dialog.action.DialogClickAction;
/**
* Represents a simple dialog with text and one action at the bottom (default:
* "OK").
*/
@Data @Data
@ToString @ToString
@EqualsAndHashCode @EqualsAndHashCode
@AllArgsConstructor @AllArgsConstructor
@Accessors(fluent = true) @Accessors(fluent = true)
public class NoticeDialog implements Dialog public final class NoticeDialog implements Dialog
{ {
@Accessors(fluent = false) @Accessors(fluent = false)
private DialogBase base; private DialogBase base;
/**
* The "OK" action button for the dialog.
*/
private DialogClickAction action; private DialogClickAction action;
public NoticeDialog(DialogBase base) public NoticeDialog(DialogBase base)

View File

@ -8,19 +8,31 @@ import lombok.ToString;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ClickEvent;
/**
* Represents a dialog which shows the links configured/sent from the server.
*/
@Data @Data
@ToString @ToString
@EqualsAndHashCode @EqualsAndHashCode
@AllArgsConstructor @AllArgsConstructor
@Accessors(fluent = true) @Accessors(fluent = true)
public class ServerLinksDialog implements Dialog public final class ServerLinksDialog implements Dialog
{ {
@Accessors(fluent = false) @Accessors(fluent = false)
private DialogBase base; private DialogBase base;
/**
* The optional {@link ClickEvent} for this dialog.
*/
@SerializedName("on_click") @SerializedName("on_click")
private ClickEvent onClick; private ClickEvent onClick;
/**
* The number of columns for the dialog buttons (default: 2).
*/
private int columns; private int columns;
/**
* The width of the dialog buttons (default: 150).
*/
@SerializedName("button_width") @SerializedName("button_width")
private int buttonWidth; private int buttonWidth;

View File

@ -1,5 +1,6 @@
package net.md_5.bungee.api.dialog; package net.md_5.bungee.api.dialog;
import com.google.common.base.Preconditions;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import lombok.Data; import lombok.Data;
@ -9,16 +10,26 @@ import lombok.experimental.Accessors;
import net.md_5.bungee.api.dialog.action.DialogSubmitAction; import net.md_5.bungee.api.dialog.action.DialogSubmitAction;
import net.md_5.bungee.api.dialog.input.DialogInput; import net.md_5.bungee.api.dialog.input.DialogInput;
/**
* Represents a dialog which contains a variety of inputs and a single submit
* button at the bottom.
*/
@Data @Data
@ToString @ToString
@EqualsAndHashCode @EqualsAndHashCode
@Accessors(fluent = true) @Accessors(fluent = true)
public class SimpleInputFormDialog implements Dialog public final class SimpleInputFormDialog implements Dialog
{ {
@Accessors(fluent = false) @Accessors(fluent = false)
private DialogBase base; private DialogBase base;
/**
* The inputs to the dialog. At least one input must be provided.
*/
private List<DialogInput> inputs; private List<DialogInput> inputs;
/**
* The action/submit buttons for the dialog.
*/
private DialogSubmitAction action; private DialogSubmitAction action;
public SimpleInputFormDialog(DialogBase base, DialogInput... inputs) public SimpleInputFormDialog(DialogBase base, DialogInput... inputs)
@ -33,6 +44,8 @@ public class SimpleInputFormDialog implements Dialog
public SimpleInputFormDialog(DialogBase base, DialogSubmitAction action, List<DialogInput> inputs) public SimpleInputFormDialog(DialogBase base, DialogSubmitAction action, List<DialogInput> inputs)
{ {
Preconditions.checkArgument( inputs != null && !inputs.isEmpty(), "At least one input must be provided" );
this.base = base; this.base = base;
this.inputs = inputs; this.inputs = inputs;
this.action = action; this.action = action;

View File

@ -3,7 +3,7 @@ package net.md_5.bungee.api.dialog.body;
import lombok.Data; import lombok.Data;
@Data @Data
public class DialogBody public abstract class DialogBody
{ {
private final String type; private final String type;

View File

@ -0,0 +1,4 @@
/**
* Contains the core classes for the display of a {@link Dialog}.
*/
package net.md_5.bungee.api.dialog;