66import org .bukkit .entity .Player ;
77import org .bukkit .plugin .Plugin ;
88
9+ import io .github .projectunified .unidialog .core .dialog .Dialog .AfterAction ;
910import io .github .projectunified .unidialog .core .payload .DialogPayload ;
1011import io .github .projectunified .unidialog .paper .PaperDialogManager ;
1112import io .github .projectunified .unidialog .paper .dialog .PaperConfirmationDialog ;
@@ -68,13 +69,18 @@ public void showNotice(Player player, UniDialogNoticeRequest request) {
6869 registerCustomAction (namespace , actionId , request .getCallback ());
6970 }
7071
71- PaperNoticeDialog dialog = manager .createNoticeDialog ().title (request .getTitle ())
72- .body (builder -> builder .text ().text (request .getBody ()));
72+ PaperNoticeDialog dialog = manager .createNoticeDialog ()
73+ .title (getTextOrDefault (request .getTitle (), "Dialog" ))
74+ .afterAction (AfterAction .CLOSE );
75+
76+ if (request .getBody () != null && !request .getBody ().isEmpty ()) {
77+ dialog .body (builder -> builder .text ().text (request .getBody ()));
78+ }
7379
7480 applyInputs (dialog , request .getInputs ());
7581
7682 dialog .action (action -> {
77- action .label (request .getButtonText ());
83+ action .label (getTextOrDefault ( request .getButtonText (), "Ok" ));
7884 action .dynamicCustom (namespace , actionId );
7985 });
8086
@@ -95,18 +101,23 @@ public void showConfirmation(Player player, UniDialogConfirmationRequest request
95101 registerCustomAction (namespace , noActionId , request .getNoCallback ());
96102 }
97103
98- PaperConfirmationDialog dialog = manager .createConfirmationDialog ().title (request .getTitle ())
99- .body (builder -> builder .text ().text (request .getBody ()));
104+ PaperConfirmationDialog dialog = manager .createConfirmationDialog ()
105+ .title (getTextOrDefault (request .getTitle (), "Confirm" ))
106+ .afterAction (AfterAction .CLOSE );
107+
108+ if (request .getBody () != null && !request .getBody ().isEmpty ()) {
109+ dialog .body (builder -> builder .text ().text (request .getBody ()));
110+ }
100111
101112 applyInputs (dialog , request .getInputs ());
102113
103114 dialog .yesAction (action -> {
104- action .label (request .getYesText ());
115+ action .label (getTextOrDefault ( request .getYesText (), "Yes" ));
105116 action .dynamicCustom (namespace , yesActionId );
106117 });
107118
108119 dialog .noAction (action -> {
109- action .label (request .getNoText ());
120+ action .label (getTextOrDefault ( request .getNoText (), "No" ));
110121 action .dynamicCustom (namespace , noActionId );
111122 });
112123
@@ -118,7 +129,8 @@ public void showMultiAction(Player player, UniDialogMultiActionRequest request)
118129 String namespace = resolveNamespace (request .getNamespace ());
119130
120131 PaperMultiActionDialog dialog = manager .createMultiActionDialog ()
121- .title (getTextOrEmpty (request .getTitle ()))
132+ .title (getTextOrDefault (request .getTitle (), "Select an action" ))
133+ .afterAction (AfterAction .CLOSE )
122134 .columns (Math .max (1 , request .getColumns ()));
123135
124136 if (request .getBody () != null && !request .getBody ().isEmpty ()) {
@@ -127,46 +139,36 @@ public void showMultiAction(Player player, UniDialogMultiActionRequest request)
127139
128140 applyInputs (dialog , request .getInputs ());
129141
130- if (request .getButtons () != null ) {
131- for (UniDialogButton button : request .getButtons ()) {
132- if (button == null ) {
133- continue ;
134- }
142+ for (UniDialogButton button : request .getButtons ()) {
143+ String actionId = resolveActionId (button .getActionId ());
135144
136- String actionId = resolveActionId (button .getActionId ());
137-
138- if (button .getCallback () != null ) {
139- registerCustomAction (namespace , actionId , button .getCallback ());
140- }
145+ if (button .getCallback () != null ) {
146+ registerCustomAction (namespace , actionId , button .getCallback ());
147+ }
141148
142- dialog .action (action -> {
143- action .label (getTextOrEmpty (button .getText ()));
149+ dialog .action (action -> {
150+ action .label (getTextOrDefault (button .getText (), "Action" ));
144151
145- if (button .getTooltip () != null && !button .getTooltip ().isEmpty ()) {
146- action .tooltip (button .getTooltip ());
147- }
152+ if (button .getTooltip () != null && !button .getTooltip ().isEmpty ()) {
153+ action .tooltip (button .getTooltip ());
154+ }
148155
149- Integer width = button .getWidth ();
150- if (width == null ) {
151- width = request .getButtonWidth ();
152- }
156+ Integer width = button .getWidth ();
157+ if (width == null ) {
158+ width = request .getButtonWidth ();
159+ }
153160
154- if (width != null && width . intValue () > 0 ) {
155- action .width (width .intValue ());
156- }
161+ if (width != null ) {
162+ action .width (width .intValue ());
163+ }
157164
158- action .dynamicCustom (namespace , actionId );
159- });
160- }
165+ action .dynamicCustom (namespace , actionId );
166+ });
161167 }
162168
163169 dialog .opener ().open (player .getUniqueId ());
164170 }
165171
166- private String getTextOrEmpty (String text ) {
167- return text == null ? "" : text ;
168- }
169-
170172 private void applyInputs (PaperNoticeDialog dialog , Iterable <UniDialogInput > inputs ) {
171173 if (inputs == null ) {
172174 return ;
@@ -255,6 +257,13 @@ private void applyInput(PaperMultiActionDialog dialog, UniDialogInput input) {
255257 });
256258 }
257259
260+ private String getTextOrDefault (String value , String defaultValue ) {
261+ if (value == null || value .isEmpty ()) {
262+ return defaultValue ;
263+ }
264+ return value ;
265+ }
266+
258267 private String getInputLabel (UniDialogInput input ) {
259268 String label = input .getLabel ();
260269
@@ -268,4 +277,4 @@ private String getInputLabel(UniDialogInput input) {
268277 private String getInputInitial (UniDialogInput input ) {
269278 return input .getInitialValue ();
270279 }
271- }
280+ }
0 commit comments