Minecraft 1.21.6-pre1 support
This commit is contained in:
parent
d8f9d81b30
commit
89e66ed648
@ -1,6 +1,6 @@
|
|||||||
package net.md_5.bungee.api.event;
|
package net.md_5.bungee.api.event;
|
||||||
|
|
||||||
import java.util.Map;
|
import com.google.gson.JsonElement;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
@ -34,19 +34,9 @@ public class CustomClickEvent extends Event implements Cancellable
|
|||||||
*/
|
*/
|
||||||
private final String id;
|
private final String id;
|
||||||
/**
|
/**
|
||||||
* The raw data as submitted.
|
* The data as submitted.
|
||||||
*/
|
*/
|
||||||
private final String rawData;
|
private final JsonElement data;
|
||||||
/**
|
|
||||||
* The parsed form data.
|
|
||||||
* <br>
|
|
||||||
* If a form submission, usually contains a
|
|
||||||
* {@code CustomClickEvent.ACTION_KEY} key with the ID of the relevant
|
|
||||||
* submission action.
|
|
||||||
* <br>
|
|
||||||
* If not a form submission, then may be null.
|
|
||||||
*/
|
|
||||||
private final Map<String, String> parsedData;
|
|
||||||
/**
|
/**
|
||||||
* Cancelled state.
|
* Cancelled state.
|
||||||
*/
|
*/
|
||||||
|
@ -6,7 +6,7 @@ import lombok.EqualsAndHashCode;
|
|||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
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.DialogAction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a simple dialog with text and two actions at the bottom (default:
|
* Represents a simple dialog with text and two actions at the bottom (default:
|
||||||
@ -26,11 +26,11 @@ public final class ConfirmationDialog implements Dialog
|
|||||||
/**
|
/**
|
||||||
* The "yes" click action / bottom (appears on the left).
|
* The "yes" click action / bottom (appears on the left).
|
||||||
*/
|
*/
|
||||||
private DialogClickAction yes;
|
private DialogAction yes;
|
||||||
/**
|
/**
|
||||||
* The "no" click action / bottom (appears on the right).
|
* The "no" click action / bottom (appears on the right).
|
||||||
*/
|
*/
|
||||||
private DialogClickAction no;
|
private DialogAction no;
|
||||||
|
|
||||||
public ConfirmationDialog(@NonNull DialogBase base)
|
public ConfirmationDialog(@NonNull DialogBase base)
|
||||||
{
|
{
|
||||||
|
@ -8,6 +8,7 @@ import lombok.NonNull;
|
|||||||
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;
|
import net.md_5.bungee.api.dialog.body.DialogBody;
|
||||||
|
import net.md_5.bungee.api.dialog.input.DialogInput;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the title and other options common to all dialogs.
|
* Represents the title and other options common to all dialogs.
|
||||||
@ -29,6 +30,10 @@ public final class DialogBase
|
|||||||
*/
|
*/
|
||||||
@SerializedName("external_title")
|
@SerializedName("external_title")
|
||||||
private BaseComponent externalTitle;
|
private BaseComponent externalTitle;
|
||||||
|
/**
|
||||||
|
* The inputs to the dialog.
|
||||||
|
*/
|
||||||
|
private List<DialogInput> inputs;
|
||||||
/**
|
/**
|
||||||
* The body elements which make up this dialog.
|
* The body elements which make up this dialog.
|
||||||
*/
|
*/
|
||||||
@ -38,9 +43,42 @@ public final class DialogBase
|
|||||||
*/
|
*/
|
||||||
@SerializedName("can_close_with_escape")
|
@SerializedName("can_close_with_escape")
|
||||||
private Boolean canCloseWithEscape;
|
private Boolean canCloseWithEscape;
|
||||||
|
/**
|
||||||
|
* Whether this dialog should pause the game in single-player mode (default:
|
||||||
|
* true).
|
||||||
|
*/
|
||||||
|
private Boolean pause;
|
||||||
|
/**
|
||||||
|
* Action to take after the a click or submit action is performed on the
|
||||||
|
* dialog (default: close).
|
||||||
|
*/
|
||||||
|
@SerializedName("after_action")
|
||||||
|
private AfterAction afterAction;
|
||||||
|
|
||||||
public DialogBase(@NonNull BaseComponent title)
|
public DialogBase(@NonNull BaseComponent title)
|
||||||
{
|
{
|
||||||
this( title, null, null, null );
|
this( title, null, null, null, null, null, null );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Types of action which may be taken after the dialog.
|
||||||
|
*/
|
||||||
|
public enum AfterAction
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Close the dialog.
|
||||||
|
*/
|
||||||
|
@SerializedName("close")
|
||||||
|
CLOSE,
|
||||||
|
/**
|
||||||
|
* Do nothing.
|
||||||
|
*/
|
||||||
|
@SerializedName("none")
|
||||||
|
NONE,
|
||||||
|
/**
|
||||||
|
* Show a waiting for response screen.
|
||||||
|
*/
|
||||||
|
@SerializedName("wait_for_response")
|
||||||
|
WAIT_FOR_RESPONSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import lombok.EqualsAndHashCode;
|
|||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import lombok.ToString;
|
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.dialog.action.DialogAction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a dialog which contains buttons that link to other dialogs.
|
* Represents a dialog which contains buttons that link to other dialogs.
|
||||||
@ -29,10 +29,10 @@ public final class DialogListDialog implements Dialog
|
|||||||
*/
|
*/
|
||||||
private List<Dialog> dialogs;
|
private List<Dialog> dialogs;
|
||||||
/**
|
/**
|
||||||
* The {@link ClickEvent} activated when the dialog is cancelled.
|
* The {@link DialogAction} activated when the dialog is exited.
|
||||||
*/
|
*/
|
||||||
@SerializedName("on_cancel")
|
@SerializedName("exit_action")
|
||||||
private ClickEvent onCancel;
|
private DialogAction exitAction;
|
||||||
/**
|
/**
|
||||||
* The number of columns for the dialog buttons (default: 2).
|
* The number of columns for the dialog buttons (default: 2).
|
||||||
*/
|
*/
|
||||||
@ -48,11 +48,11 @@ public final class DialogListDialog implements Dialog
|
|||||||
this( base, Arrays.asList( dialogs ), null, null, null );
|
this( base, Arrays.asList( dialogs ), null, null, null );
|
||||||
}
|
}
|
||||||
|
|
||||||
public DialogListDialog(@NonNull DialogBase base, List<Dialog> dialogs, ClickEvent onCancel, Integer columns, Integer buttonWidth)
|
public DialogListDialog(@NonNull DialogBase base, List<Dialog> dialogs, DialogAction exitAction, Integer columns, Integer buttonWidth)
|
||||||
{
|
{
|
||||||
this.base = base;
|
this.base = base;
|
||||||
this.dialogs = dialogs;
|
this.dialogs = dialogs;
|
||||||
this.onCancel = onCancel;
|
this.exitAction = exitAction;
|
||||||
columns( columns );
|
columns( columns );
|
||||||
buttonWidth( buttonWidth );
|
buttonWidth( buttonWidth );
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,7 @@ import lombok.EqualsAndHashCode;
|
|||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import lombok.ToString;
|
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.dialog.action.DialogAction;
|
||||||
import net.md_5.bungee.api.dialog.action.DialogClickAction;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a dialog with text a list of action buttons grouped into columns
|
* Represents a dialog with text a list of action buttons grouped into columns
|
||||||
@ -30,30 +29,30 @@ public final class MultiActionDialog implements Dialog
|
|||||||
* The action buttons in the dialog. At least one must be provided.
|
* The action buttons in the dialog. At least one must be provided.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
private List<DialogClickAction> actions;
|
private List<DialogAction> actions;
|
||||||
/**
|
/**
|
||||||
* The number of columns for the dialog buttons (default: 2).
|
* The number of columns for the dialog buttons (default: 2).
|
||||||
*/
|
*/
|
||||||
private Integer columns;
|
private Integer columns;
|
||||||
/**
|
/**
|
||||||
* The {@link ClickEvent} activated when the dialog is cancelled.
|
* The {@link DialogAction} activated when the dialog is exited.
|
||||||
*/
|
*/
|
||||||
@SerializedName("on_cancel")
|
@SerializedName("exit_action")
|
||||||
private ClickEvent onCancel;
|
private DialogAction exitAction;
|
||||||
|
|
||||||
public MultiActionDialog(@NonNull DialogBase base, @NonNull DialogClickAction... actions)
|
public MultiActionDialog(@NonNull DialogBase base, @NonNull DialogAction... actions)
|
||||||
{
|
{
|
||||||
this( base, Arrays.asList( actions ), null, null );
|
this( base, Arrays.asList( actions ), null, null );
|
||||||
}
|
}
|
||||||
|
|
||||||
public MultiActionDialog(@NonNull DialogBase base, @NonNull List<DialogClickAction> actions, Integer columns, ClickEvent onCancel)
|
public MultiActionDialog(@NonNull DialogBase base, @NonNull List<DialogAction> actions, Integer columns, DialogAction exitAction)
|
||||||
{
|
{
|
||||||
Preconditions.checkArgument( !actions.isEmpty(), "At least one action must be provided" );
|
Preconditions.checkArgument( !actions.isEmpty(), "At least one action must be provided" );
|
||||||
|
|
||||||
this.base = base;
|
this.base = base;
|
||||||
this.actions = actions;
|
this.actions = actions;
|
||||||
columns( columns );
|
columns( columns );
|
||||||
this.onCancel = onCancel;
|
this.exitAction = exitAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MultiActionDialog columns(Integer columns)
|
public MultiActionDialog columns(Integer columns)
|
||||||
|
@ -1,71 +0,0 @@
|
|||||||
package net.md_5.bungee.api.dialog;
|
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.NonNull;
|
|
||||||
import lombok.ToString;
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
import net.md_5.bungee.api.dialog.action.DialogSubmitAction;
|
|
||||||
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
|
|
||||||
@ToString
|
|
||||||
@EqualsAndHashCode
|
|
||||||
@Accessors(fluent = true)
|
|
||||||
public final class MultiActionInputFormDialog implements Dialog
|
|
||||||
{
|
|
||||||
|
|
||||||
@Accessors(fluent = false)
|
|
||||||
@NonNull
|
|
||||||
private DialogBase base;
|
|
||||||
/**
|
|
||||||
* The inputs to the dialog. At least one input must be provided.
|
|
||||||
*/
|
|
||||||
@NonNull
|
|
||||||
private List<DialogInput> inputs;
|
|
||||||
/**
|
|
||||||
* The action/submit buttons for the dialog. At least one action must be
|
|
||||||
* provided.
|
|
||||||
*/
|
|
||||||
@NonNull
|
|
||||||
private List<DialogSubmitAction> actions;
|
|
||||||
/**
|
|
||||||
* The amount of columns (default: 2)
|
|
||||||
*/
|
|
||||||
private Integer columns;
|
|
||||||
|
|
||||||
public MultiActionInputFormDialog(@NonNull DialogBase base, @NonNull DialogInput input, @NonNull DialogSubmitAction action)
|
|
||||||
{
|
|
||||||
this( base, Arrays.asList( input ), Arrays.asList( action ), null );
|
|
||||||
}
|
|
||||||
|
|
||||||
public MultiActionInputFormDialog(@NonNull DialogBase base, @NonNull DialogInput input, @NonNull DialogSubmitAction action, Integer columns)
|
|
||||||
{
|
|
||||||
this( base, Arrays.asList( input ), Arrays.asList( action ), columns );
|
|
||||||
}
|
|
||||||
|
|
||||||
public MultiActionInputFormDialog(@NonNull DialogBase base, @NonNull List<DialogInput> inputs, @NonNull List<DialogSubmitAction> actions, Integer columns)
|
|
||||||
{
|
|
||||||
Preconditions.checkArgument( !inputs.isEmpty(), "At least one input must be provided" );
|
|
||||||
Preconditions.checkArgument( !actions.isEmpty(), "At least one action must be provided" );
|
|
||||||
|
|
||||||
this.base = base;
|
|
||||||
this.inputs = inputs;
|
|
||||||
this.actions = actions;
|
|
||||||
columns( columns );
|
|
||||||
}
|
|
||||||
|
|
||||||
public MultiActionInputFormDialog columns(Integer columns)
|
|
||||||
{
|
|
||||||
Preconditions.checkArgument( columns == null || columns > 0, "At least one column is required" );
|
|
||||||
this.columns = columns;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
@ -6,7 +6,7 @@ import lombok.EqualsAndHashCode;
|
|||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
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.DialogAction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a simple dialog with text and one action at the bottom (default:
|
* Represents a simple dialog with text and one action at the bottom (default:
|
||||||
@ -26,7 +26,7 @@ public final class NoticeDialog implements Dialog
|
|||||||
/**
|
/**
|
||||||
* The "OK" action button for the dialog.
|
* The "OK" action button for the dialog.
|
||||||
*/
|
*/
|
||||||
private DialogClickAction action;
|
private DialogAction action;
|
||||||
|
|
||||||
public NoticeDialog(DialogBase base)
|
public NoticeDialog(DialogBase base)
|
||||||
{
|
{
|
||||||
|
@ -7,7 +7,7 @@ import lombok.EqualsAndHashCode;
|
|||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import lombok.ToString;
|
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.dialog.action.DialogAction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a dialog which shows the links configured/sent from the server.
|
* Represents a dialog which shows the links configured/sent from the server.
|
||||||
@ -19,15 +19,19 @@ import net.md_5.bungee.api.chat.ClickEvent;
|
|||||||
public final class ServerLinksDialog implements Dialog
|
public final class ServerLinksDialog implements Dialog
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Accessors(fluent = false)
|
@Accessors(fluent = false)
|
||||||
private DialogBase base;
|
private DialogBase base;
|
||||||
/**
|
/**
|
||||||
* The optional {@link ClickEvent} for this dialog.
|
* The optional {@link DialogAction} for this dialog.
|
||||||
*/
|
*/
|
||||||
@SerializedName("on_click")
|
@SerializedName("action")
|
||||||
private ClickEvent onClick;
|
private DialogAction action;
|
||||||
|
/**
|
||||||
|
* The {@link DialogAction} activated when the dialog is exited.
|
||||||
|
*/
|
||||||
|
@SerializedName("exit_action")
|
||||||
|
private DialogAction exitAction;
|
||||||
/**
|
/**
|
||||||
* The number of columns for the dialog buttons (default: 2).
|
* The number of columns for the dialog buttons (default: 2).
|
||||||
*/
|
*/
|
||||||
@ -43,10 +47,10 @@ public final class ServerLinksDialog implements Dialog
|
|||||||
this( base, null, null, null );
|
this( base, null, null, null );
|
||||||
}
|
}
|
||||||
|
|
||||||
public ServerLinksDialog(@NonNull DialogBase base, ClickEvent onClick, Integer columns, Integer buttonWidth)
|
public ServerLinksDialog(@NonNull DialogBase base, DialogAction action, Integer columns, Integer buttonWidth)
|
||||||
{
|
{
|
||||||
this.base = base;
|
this.base = base;
|
||||||
this.onClick = onClick;
|
this.action = action;
|
||||||
columns( columns );
|
columns( columns );
|
||||||
buttonWidth( buttonWidth );
|
buttonWidth( buttonWidth );
|
||||||
}
|
}
|
||||||
|
@ -1,56 +0,0 @@
|
|||||||
package net.md_5.bungee.api.dialog;
|
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.NonNull;
|
|
||||||
import lombok.ToString;
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
import net.md_5.bungee.api.dialog.action.DialogSubmitAction;
|
|
||||||
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
|
|
||||||
@ToString
|
|
||||||
@EqualsAndHashCode
|
|
||||||
@Accessors(fluent = true)
|
|
||||||
public final class SimpleInputFormDialog implements Dialog
|
|
||||||
{
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Accessors(fluent = false)
|
|
||||||
private DialogBase base;
|
|
||||||
/**
|
|
||||||
* The inputs to the dialog. At least one input must be provided.
|
|
||||||
*/
|
|
||||||
@NonNull
|
|
||||||
private List<DialogInput> inputs;
|
|
||||||
/**
|
|
||||||
* The action/submit buttons for the dialog.
|
|
||||||
*/
|
|
||||||
private DialogSubmitAction action;
|
|
||||||
|
|
||||||
public SimpleInputFormDialog(@NonNull DialogBase base, @NonNull DialogInput... inputs)
|
|
||||||
{
|
|
||||||
this( base, null, inputs );
|
|
||||||
}
|
|
||||||
|
|
||||||
public SimpleInputFormDialog(@NonNull DialogBase base, DialogSubmitAction action, @NonNull DialogInput... inputs)
|
|
||||||
{
|
|
||||||
this( base, action, Arrays.asList( inputs ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
public SimpleInputFormDialog(@NonNull DialogBase base, DialogSubmitAction action, @NonNull List<DialogInput> inputs)
|
|
||||||
{
|
|
||||||
Preconditions.checkArgument( !inputs.isEmpty(), "At least one input must be provided" );
|
|
||||||
|
|
||||||
this.base = base;
|
|
||||||
this.inputs = inputs;
|
|
||||||
this.action = action;
|
|
||||||
}
|
|
||||||
}
|
|
@ -11,7 +11,7 @@ import net.md_5.bungee.api.chat.BaseComponent;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Accessors(fluent = true)
|
@Accessors(fluent = true)
|
||||||
public class DialogAction
|
public abstract class DialogAction
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,43 +0,0 @@
|
|||||||
package net.md_5.bungee.api.dialog.action;
|
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.NonNull;
|
|
||||||
import lombok.ToString;
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
|
||||||
import net.md_5.bungee.api.chat.ClickEvent;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a button which may be clicked.
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@Accessors(fluent = true)
|
|
||||||
@ToString(callSuper = true)
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
public class DialogClickAction extends DialogAction
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The optional action to take on click.
|
|
||||||
*/
|
|
||||||
@SerializedName("on_click")
|
|
||||||
private ClickEvent onClick;
|
|
||||||
|
|
||||||
public DialogClickAction(@NonNull BaseComponent label)
|
|
||||||
{
|
|
||||||
this( null, label );
|
|
||||||
}
|
|
||||||
|
|
||||||
public DialogClickAction(ClickEvent onClick, @NonNull BaseComponent label)
|
|
||||||
{
|
|
||||||
this( onClick, label, null, null );
|
|
||||||
}
|
|
||||||
|
|
||||||
public DialogClickAction(ClickEvent onClick, @NonNull BaseComponent label, BaseComponent tooltip, Integer width)
|
|
||||||
{
|
|
||||||
super( label, tooltip, width );
|
|
||||||
this.onClick = onClick;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,47 +0,0 @@
|
|||||||
package net.md_5.bungee.api.dialog.action;
|
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.NonNull;
|
|
||||||
import lombok.ToString;
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
|
||||||
import net.md_5.bungee.api.dialog.submit.DialogSubmission;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a dialog button associated with the submission of a form dialog
|
|
||||||
* containing inputs.
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@Accessors(fluent = true)
|
|
||||||
@ToString(callSuper = true)
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
public class DialogSubmitAction extends DialogAction
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The ID of the button, used to distinguish submissions initiated via
|
|
||||||
* different buttons on the dialog.
|
|
||||||
*/
|
|
||||||
@NonNull
|
|
||||||
private String id;
|
|
||||||
/**
|
|
||||||
* The submission action to take.
|
|
||||||
*/
|
|
||||||
@NonNull
|
|
||||||
@SerializedName("on_submit")
|
|
||||||
private DialogSubmission onSubmit;
|
|
||||||
|
|
||||||
public DialogSubmitAction(@NonNull String id, @NonNull DialogSubmission onSubmit, @NonNull BaseComponent label)
|
|
||||||
{
|
|
||||||
this( id, onSubmit, label, null, null );
|
|
||||||
}
|
|
||||||
|
|
||||||
public DialogSubmitAction(@NonNull String id, @NonNull DialogSubmission onSubmit, @NonNull BaseComponent label, BaseComponent tooltip, Integer width)
|
|
||||||
{
|
|
||||||
super( label, tooltip, width );
|
|
||||||
this.id = id;
|
|
||||||
this.onSubmit = onSubmit;
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,35 @@
|
|||||||
|
package net.md_5.bungee.api.dialog.action;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NonNull;
|
||||||
|
import lombok.ToString;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
|
import net.md_5.bungee.api.dialog.dynamic.DynamicType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a static dialog action.
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Accessors(fluent = true)
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class DynamicAction extends DialogAction
|
||||||
|
{
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private DynamicType action;
|
||||||
|
|
||||||
|
public DynamicAction(@NonNull BaseComponent label, BaseComponent tooltip, Integer width, @NonNull DynamicType action)
|
||||||
|
{
|
||||||
|
super( label, tooltip, width );
|
||||||
|
this.action = action;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DynamicAction(@NonNull BaseComponent label, @NonNull DynamicType action)
|
||||||
|
{
|
||||||
|
super( label );
|
||||||
|
this.action = action;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
package net.md_5.bungee.api.dialog.action;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NonNull;
|
||||||
|
import lombok.ToString;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
|
import net.md_5.bungee.api.chat.ClickEvent;
|
||||||
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a static dialog action.
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Accessors(fluent = true)
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class StaticAction extends DialogAction
|
||||||
|
{
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private ChatClickEventWrapper action;
|
||||||
|
|
||||||
|
public StaticAction(@NonNull BaseComponent label, BaseComponent tooltip, Integer width, @NonNull ClickEvent action)
|
||||||
|
{
|
||||||
|
super( label, tooltip, width );
|
||||||
|
this.action = new ChatClickEventWrapper( action );
|
||||||
|
}
|
||||||
|
|
||||||
|
public StaticAction(@NonNull BaseComponent label, @NonNull ClickEvent action)
|
||||||
|
{
|
||||||
|
super( label );
|
||||||
|
this.action = new ChatClickEventWrapper( action );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@ApiStatus.Internal
|
||||||
|
public static final class ChatClickEventWrapper
|
||||||
|
{
|
||||||
|
|
||||||
|
private final ClickEvent event;
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package net.md_5.bungee.api.dialog.submit;
|
package net.md_5.bungee.api.dialog.dynamic;
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
@ -7,13 +8,13 @@ import lombok.ToString;
|
|||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Submits the form with the given ID and all values as a payload.
|
* Submits the dialog with the given ID and values as a payload.
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Accessors(fluent = true)
|
@Accessors(fluent = true)
|
||||||
@ToString(callSuper = true)
|
@ToString(callSuper = true)
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
public class CustomFormSubmission extends DialogSubmission
|
public class Custom extends DynamicType
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -21,10 +22,14 @@ public class CustomFormSubmission extends DialogSubmission
|
|||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
private String id;
|
private String id;
|
||||||
|
/**
|
||||||
|
* Fields to be added to the submission payload.
|
||||||
|
*/
|
||||||
|
private JsonElement additions;
|
||||||
|
|
||||||
public CustomFormSubmission(@NonNull String id)
|
public Custom(@NonNull String id)
|
||||||
{
|
{
|
||||||
super( "minecraft:custom_form" );
|
super( "dynamic/custom" );
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package net.md_5.bungee.api.dialog.submit;
|
package net.md_5.bungee.api.dialog.dynamic;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
@ -10,7 +10,7 @@ import org.jetbrains.annotations.ApiStatus;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Accessors(fluent = true)
|
@Accessors(fluent = true)
|
||||||
public class DialogSubmission
|
public class DynamicType
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
@ -1,4 +1,4 @@
|
|||||||
package net.md_5.bungee.api.dialog.submit;
|
package net.md_5.bungee.api.dialog.dynamic;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
@ -7,14 +7,14 @@ import lombok.ToString;
|
|||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes a command on form submission. If the command requires a permission
|
* Executes a command. If the command requires a permission
|
||||||
* higher than 0, a confirmation dialog will be shown by the client.
|
* higher than 0, a confirmation dialog will be shown by the client.
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Accessors(fluent = true)
|
@Accessors(fluent = true)
|
||||||
@ToString(callSuper = true)
|
@ToString(callSuper = true)
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
public class CommandTemplateSubmission extends DialogSubmission
|
public class RunCommand extends DynamicType
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,9 +28,9 @@ public class CommandTemplateSubmission extends DialogSubmission
|
|||||||
@NonNull
|
@NonNull
|
||||||
private String template;
|
private String template;
|
||||||
|
|
||||||
public CommandTemplateSubmission(@NonNull String template)
|
public RunCommand(@NonNull String template)
|
||||||
{
|
{
|
||||||
super( "minecraft:command_template" );
|
super( "dynamic/run_command" );
|
||||||
this.template = template;
|
this.template = template;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,4 @@
|
|||||||
|
/**
|
||||||
|
* Represents the various dynamic actions of dialogs.
|
||||||
|
*/
|
||||||
|
package net.md_5.bungee.api.dialog.dynamic;
|
@ -1,42 +0,0 @@
|
|||||||
package net.md_5.bungee.api.dialog.submit;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.NonNull;
|
|
||||||
import lombok.ToString;
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Submits the form with the given ID and a single payload specified by the
|
|
||||||
* template.
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@Accessors(fluent = true)
|
|
||||||
@ToString(callSuper = true)
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
public class CustomTemplateSubmission extends DialogSubmission
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The namespaced key of the submission.
|
|
||||||
*/
|
|
||||||
@NonNull
|
|
||||||
private String id;
|
|
||||||
/**
|
|
||||||
* The template to be applied, where variables of the form
|
|
||||||
* <code>$(key)</code> will be replaced by their
|
|
||||||
* {@link net.md_5.bungee.api.dialog.input.DialogInput#key} value.
|
|
||||||
* <br>
|
|
||||||
* The <code>action</code> key is special and will be replaced with the
|
|
||||||
* {@link net.md_5.bungee.api.dialog.action.DialogSubmitAction#id}.
|
|
||||||
*/
|
|
||||||
@NonNull
|
|
||||||
private String template;
|
|
||||||
|
|
||||||
public CustomTemplateSubmission(@NonNull String id, @NonNull String template)
|
|
||||||
{
|
|
||||||
super( "minecraft:custom_template" );
|
|
||||||
this.id = id;
|
|
||||||
this.template = template;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,4 +0,0 @@
|
|||||||
/**
|
|
||||||
* Represents the various submissions actions of form dialogs.
|
|
||||||
*/
|
|
||||||
package net.md_5.bungee.api.dialog.submit;
|
|
@ -50,7 +50,7 @@ public class ProtocolConstants
|
|||||||
public static final int MINECRAFT_1_21_2 = 768;
|
public static final int MINECRAFT_1_21_2 = 768;
|
||||||
public static final int MINECRAFT_1_21_4 = 769;
|
public static final int MINECRAFT_1_21_4 = 769;
|
||||||
public static final int MINECRAFT_1_21_5 = 770;
|
public static final int MINECRAFT_1_21_5 = 770;
|
||||||
public static final int MINECRAFT_1_21_6 = 1073742075;
|
public static final int MINECRAFT_1_21_6 = 1073742076;
|
||||||
public static final List<String> SUPPORTED_VERSIONS;
|
public static final List<String> SUPPORTED_VERSIONS;
|
||||||
public static final List<Integer> SUPPORTED_VERSION_IDS;
|
public static final List<Integer> SUPPORTED_VERSION_IDS;
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ import net.md_5.bungee.protocol.AbstractPacketHandler;
|
|||||||
import net.md_5.bungee.protocol.DefinedPacket;
|
import net.md_5.bungee.protocol.DefinedPacket;
|
||||||
import net.md_5.bungee.protocol.Protocol;
|
import net.md_5.bungee.protocol.Protocol;
|
||||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||||
|
import se.llbit.nbt.Tag;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@ -18,20 +19,20 @@ public class CustomClickAction extends DefinedPacket
|
|||||||
{
|
{
|
||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
private String data;
|
private Tag data;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(ByteBuf buf, Protocol protocol, ProtocolConstants.Direction direction, int protocolVersion)
|
public void read(ByteBuf buf, Protocol protocol, ProtocolConstants.Direction direction, int protocolVersion)
|
||||||
{
|
{
|
||||||
id = readString( buf );
|
id = readString( buf );
|
||||||
data = readNullable( DefinedPacket::readString, buf );
|
data = readNullable( (buf0) -> readTag( buf0, protocolVersion ), buf );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(ByteBuf buf, Protocol protocol, ProtocolConstants.Direction direction, int protocolVersion)
|
public void write(ByteBuf buf, Protocol protocol, ProtocolConstants.Direction direction, int protocolVersion)
|
||||||
{
|
{
|
||||||
writeString( id, buf );
|
writeString( id, buf );
|
||||||
writeNullable( data, DefinedPacket::writeString, buf );
|
writeNullable( data, (data0, buf0) -> writeTag( data0, buf0, protocolVersion ), buf );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package net.md_5.bungee.connection;
|
package net.md_5.bungee.connection;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.collect.ImmutableMap;
|
|
||||||
import com.mojang.brigadier.context.StringRange;
|
import com.mojang.brigadier.context.StringRange;
|
||||||
import com.mojang.brigadier.suggestion.Suggestion;
|
import com.mojang.brigadier.suggestion.Suggestion;
|
||||||
import com.mojang.brigadier.suggestion.Suggestions;
|
import com.mojang.brigadier.suggestion.Suggestions;
|
||||||
@ -9,7 +8,6 @@ import io.netty.channel.Channel;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import net.md_5.bungee.BungeeCord;
|
import net.md_5.bungee.BungeeCord;
|
||||||
import net.md_5.bungee.ServerConnection;
|
import net.md_5.bungee.ServerConnection;
|
||||||
@ -31,6 +29,7 @@ import net.md_5.bungee.netty.PacketHandler;
|
|||||||
import net.md_5.bungee.protocol.PacketWrapper;
|
import net.md_5.bungee.protocol.PacketWrapper;
|
||||||
import net.md_5.bungee.protocol.Protocol;
|
import net.md_5.bungee.protocol.Protocol;
|
||||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||||
|
import net.md_5.bungee.protocol.TagUtil;
|
||||||
import net.md_5.bungee.protocol.packet.Chat;
|
import net.md_5.bungee.protocol.packet.Chat;
|
||||||
import net.md_5.bungee.protocol.packet.ClientChat;
|
import net.md_5.bungee.protocol.packet.ClientChat;
|
||||||
import net.md_5.bungee.protocol.packet.ClientCommand;
|
import net.md_5.bungee.protocol.packet.ClientCommand;
|
||||||
@ -48,6 +47,7 @@ import net.md_5.bungee.protocol.packet.TabCompleteRequest;
|
|||||||
import net.md_5.bungee.protocol.packet.TabCompleteResponse;
|
import net.md_5.bungee.protocol.packet.TabCompleteResponse;
|
||||||
import net.md_5.bungee.protocol.packet.UnsignedClientCommand;
|
import net.md_5.bungee.protocol.packet.UnsignedClientCommand;
|
||||||
import net.md_5.bungee.util.AllowedCharacters;
|
import net.md_5.bungee.util.AllowedCharacters;
|
||||||
|
import se.llbit.nbt.SpecificTag;
|
||||||
|
|
||||||
public class UpstreamBridge extends PacketHandler
|
public class UpstreamBridge extends PacketHandler
|
||||||
{
|
{
|
||||||
@ -385,29 +385,7 @@ public class UpstreamBridge extends PacketHandler
|
|||||||
@Override
|
@Override
|
||||||
public void handle(CustomClickAction customClickAction) throws Exception
|
public void handle(CustomClickAction customClickAction) throws Exception
|
||||||
{
|
{
|
||||||
Map<String, String> data = null;
|
CustomClickEvent event = new CustomClickEvent( con, customClickAction.getId(), TagUtil.toJson( (SpecificTag) customClickAction.getData() ) );
|
||||||
if ( customClickAction.getData() != null )
|
|
||||||
{
|
|
||||||
ImmutableMap.Builder<String, String> parsed = ImmutableMap.builder();
|
|
||||||
|
|
||||||
String[] lines = customClickAction.getData().split( "\n" );
|
|
||||||
for ( String line : lines )
|
|
||||||
{
|
|
||||||
String[] split = line.split( "\t", 2 );
|
|
||||||
if ( split.length > 1 )
|
|
||||||
{
|
|
||||||
parsed.put( split[0], split[1] );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
data = parsed.buildOrThrow();
|
|
||||||
|
|
||||||
if ( data.isEmpty() )
|
|
||||||
{
|
|
||||||
data = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CustomClickEvent event = new CustomClickEvent( con, customClickAction.getId(), customClickAction.getData(), data );
|
|
||||||
if ( bungee.getPluginManager().callEvent( event ).isCancelled() )
|
if ( bungee.getPluginManager().callEvent( event ).isCancelled() )
|
||||||
{
|
{
|
||||||
throw CancelSendSignal.INSTANCE;
|
throw CancelSendSignal.INSTANCE;
|
||||||
|
@ -12,12 +12,9 @@ import java.util.IdentityHashMap;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
import net.md_5.bungee.api.chat.ClickEvent;
|
|
||||||
import net.md_5.bungee.api.chat.ClickEventCustom;
|
|
||||||
import net.md_5.bungee.api.chat.ComponentStyle;
|
import net.md_5.bungee.api.chat.ComponentStyle;
|
||||||
import net.md_5.bungee.api.chat.HoverEvent;
|
import net.md_5.bungee.api.chat.HoverEvent;
|
||||||
import net.md_5.bungee.api.chat.hover.content.Content;
|
import net.md_5.bungee.api.chat.hover.content.Content;
|
||||||
import net.md_5.bungee.api.dialog.chat.ShowDialogClickEvent;
|
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class BaseComponentSerializer
|
public class BaseComponentSerializer
|
||||||
@ -44,36 +41,12 @@ public class BaseComponentSerializer
|
|||||||
}
|
}
|
||||||
if ( clickEvent != null )
|
if ( clickEvent != null )
|
||||||
{
|
{
|
||||||
ClickEvent.Action action = ClickEvent.Action.valueOf( clickEvent.get( "action" ).getAsString().toUpperCase( Locale.ROOT ) );
|
|
||||||
if ( newClickEvent )
|
if ( newClickEvent )
|
||||||
{
|
{
|
||||||
switch ( action )
|
component.setClickEvent( ClickEventSerializer.NEW.deserialize( clickEvent, context ) );
|
||||||
{
|
|
||||||
case OPEN_URL:
|
|
||||||
component.setClickEvent( new ClickEvent( action, clickEvent.get( "url" ).getAsString() ) );
|
|
||||||
break;
|
|
||||||
case RUN_COMMAND:
|
|
||||||
case SUGGEST_COMMAND:
|
|
||||||
component.setClickEvent( new ClickEvent( action, clickEvent.get( "command" ).getAsString() ) );
|
|
||||||
break;
|
|
||||||
case CHANGE_PAGE:
|
|
||||||
int page = clickEvent.get( "page" ).getAsInt();
|
|
||||||
Preconditions.checkArgument( page >= 0, "Page number has to be positive" );
|
|
||||||
component.setClickEvent( new ClickEvent( action, Integer.toString( page ) ) );
|
|
||||||
break;
|
|
||||||
case SHOW_DIALOG:
|
|
||||||
component.setClickEvent( context.deserialize( clickEvent.get( "dialog" ), ShowDialogClickEvent.class ) );
|
|
||||||
break;
|
|
||||||
case CUSTOM:
|
|
||||||
component.setClickEvent( new ClickEventCustom( clickEvent.get( "id" ).getAsString(), ( clickEvent.has( "payload" ) ) ? clickEvent.get( "payload" ).getAsString() : null ) );
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
component.setClickEvent( new ClickEvent( action, ( clickEvent.has( "value" ) ) ? clickEvent.get( "value" ).getAsString() : "" ) );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
component.setClickEvent( new ClickEvent( action, ( clickEvent.has( "value" ) ) ? clickEvent.get( "value" ).getAsString() : "" ) );
|
component.setClickEvent( ClickEventSerializer.OLD.deserialize( clickEvent, context ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,50 +144,17 @@ public class BaseComponentSerializer
|
|||||||
//Events
|
//Events
|
||||||
if ( component.getClickEvent() != null )
|
if ( component.getClickEvent() != null )
|
||||||
{
|
{
|
||||||
JsonObject clickEvent = new JsonObject();
|
|
||||||
String actionName = component.getClickEvent().getAction().toString().toLowerCase( Locale.ROOT );
|
|
||||||
clickEvent.addProperty( "action", actionName.toLowerCase( Locale.ROOT ) );
|
|
||||||
switch ( serializer.getVersion() )
|
switch ( serializer.getVersion() )
|
||||||
{
|
{
|
||||||
case V1_21_5:
|
case V1_21_5:
|
||||||
ClickEvent.Action action = ClickEvent.Action.valueOf( actionName.toUpperCase( Locale.ROOT ) );
|
object.add( "click_event", ClickEventSerializer.NEW.serialize( component.getClickEvent(), context ) );
|
||||||
switch ( action )
|
|
||||||
{
|
|
||||||
case OPEN_URL:
|
|
||||||
clickEvent.addProperty( "url", component.getClickEvent().getValue() );
|
|
||||||
break;
|
|
||||||
case RUN_COMMAND:
|
|
||||||
case SUGGEST_COMMAND:
|
|
||||||
clickEvent.addProperty( "command", component.getClickEvent().getValue() );
|
|
||||||
break;
|
|
||||||
case CHANGE_PAGE:
|
|
||||||
clickEvent.addProperty( "page", Integer.parseInt( component.getClickEvent().getValue() ) );
|
|
||||||
break;
|
|
||||||
case SHOW_DIALOG:
|
|
||||||
clickEvent.add( "dialog", context.serialize( component.getClickEvent() ) );
|
|
||||||
break;
|
|
||||||
case CUSTOM:
|
|
||||||
ClickEventCustom custom = (ClickEventCustom) component.getClickEvent();
|
|
||||||
clickEvent.addProperty( "id", custom.getValue() );
|
|
||||||
if ( custom.getPayload() != null )
|
|
||||||
{
|
|
||||||
clickEvent.addProperty( "payload", custom.getPayload() );
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
clickEvent.addProperty( "value", component.getClickEvent().getValue() );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
object.add( "click_event", clickEvent );
|
|
||||||
break;
|
break;
|
||||||
case V1_16:
|
case V1_16:
|
||||||
clickEvent.addProperty( "value", component.getClickEvent().getValue() );
|
object.add( "clickEvent", ClickEventSerializer.OLD.serialize( component.getClickEvent(), context ) );
|
||||||
object.add( "clickEvent", clickEvent );
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException( "Unknown version " + serializer.getVersion() );
|
throw new IllegalArgumentException( "Unknown version " + serializer.getVersion() );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if ( component.getHoverEvent() != null )
|
if ( component.getHoverEvent() != null )
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,108 @@
|
|||||||
|
package net.md_5.bungee.chat;
|
||||||
|
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
|
import com.google.gson.JsonDeserializationContext;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParseException;
|
||||||
|
import com.google.gson.JsonSerializationContext;
|
||||||
|
import java.util.Locale;
|
||||||
|
import lombok.Data;
|
||||||
|
import net.md_5.bungee.api.chat.ClickEvent;
|
||||||
|
import net.md_5.bungee.api.chat.ClickEventCustom;
|
||||||
|
import net.md_5.bungee.api.dialog.chat.ShowDialogClickEvent;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ClickEventSerializer
|
||||||
|
{
|
||||||
|
|
||||||
|
public static final ClickEventSerializer OLD = new ClickEventSerializer( ClickType.OLD );
|
||||||
|
public static final ClickEventSerializer NEW = new ClickEventSerializer( ClickType.NEW );
|
||||||
|
public static final ClickEventSerializer DIALOG = new ClickEventSerializer( ClickType.DIALOG );
|
||||||
|
//
|
||||||
|
public enum ClickType
|
||||||
|
{
|
||||||
|
OLD, NEW, DIALOG;
|
||||||
|
}
|
||||||
|
private final ClickType type;
|
||||||
|
|
||||||
|
public ClickEvent deserialize(JsonObject clickEvent, JsonDeserializationContext context) throws JsonParseException
|
||||||
|
{
|
||||||
|
ClickEvent.Action action = ClickEvent.Action.valueOf( clickEvent.get( ( type == ClickType.DIALOG ) ? "type" : "action" ).getAsString().toUpperCase( Locale.ROOT ) );
|
||||||
|
switch ( type )
|
||||||
|
{
|
||||||
|
case NEW:
|
||||||
|
case DIALOG:
|
||||||
|
switch ( action )
|
||||||
|
{
|
||||||
|
case OPEN_URL:
|
||||||
|
return new ClickEvent( action, clickEvent.get( "url" ).getAsString() );
|
||||||
|
case RUN_COMMAND:
|
||||||
|
case SUGGEST_COMMAND:
|
||||||
|
return new ClickEvent( action, clickEvent.get( "command" ).getAsString() );
|
||||||
|
case CHANGE_PAGE:
|
||||||
|
int page = clickEvent.get( "page" ).getAsInt();
|
||||||
|
Preconditions.checkArgument( page >= 0, "Page number has to be positive" );
|
||||||
|
return new ClickEvent( action, Integer.toString( page ) );
|
||||||
|
case SHOW_DIALOG:
|
||||||
|
return context.deserialize( clickEvent.get( "dialog" ), ShowDialogClickEvent.class );
|
||||||
|
case CUSTOM:
|
||||||
|
return new ClickEventCustom( clickEvent.get( "id" ).getAsString(), ( clickEvent.has( "payload" ) ) ? clickEvent.get( "payload" ).getAsString() : null );
|
||||||
|
default:
|
||||||
|
return new ClickEvent( action, ( clickEvent.has( "value" ) ) ? clickEvent.get( "value" ).getAsString() : "" );
|
||||||
|
}
|
||||||
|
case OLD:
|
||||||
|
return new ClickEvent( action, ( clickEvent.has( "value" ) ) ? clickEvent.get( "value" ).getAsString() : "" );
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException( "Unknown serializer type" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonElement serialize(ClickEvent src, JsonSerializationContext context)
|
||||||
|
{
|
||||||
|
JsonObject clickEvent = new JsonObject();
|
||||||
|
String actionName = src.getAction().toString().toLowerCase( Locale.ROOT );
|
||||||
|
clickEvent.addProperty( ( type == ClickType.DIALOG ) ? "type" : "action", actionName.toLowerCase( Locale.ROOT ) );
|
||||||
|
switch ( type )
|
||||||
|
{
|
||||||
|
case NEW:
|
||||||
|
case DIALOG:
|
||||||
|
ClickEvent.Action action = ClickEvent.Action.valueOf( actionName.toUpperCase( Locale.ROOT ) );
|
||||||
|
switch ( action )
|
||||||
|
{
|
||||||
|
case OPEN_URL:
|
||||||
|
clickEvent.addProperty( "url", src.getValue() );
|
||||||
|
break;
|
||||||
|
case RUN_COMMAND:
|
||||||
|
case SUGGEST_COMMAND:
|
||||||
|
clickEvent.addProperty( "command", src.getValue() );
|
||||||
|
break;
|
||||||
|
case CHANGE_PAGE:
|
||||||
|
clickEvent.addProperty( "page", Integer.parseInt( src.getValue() ) );
|
||||||
|
break;
|
||||||
|
case SHOW_DIALOG:
|
||||||
|
clickEvent.add( "dialog", context.serialize( src ) );
|
||||||
|
break;
|
||||||
|
case CUSTOM:
|
||||||
|
ClickEventCustom custom = (ClickEventCustom) src;
|
||||||
|
clickEvent.addProperty( "id", custom.getValue() );
|
||||||
|
if ( custom.getPayload() != null )
|
||||||
|
{
|
||||||
|
clickEvent.addProperty( "payload", custom.getPayload() );
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
clickEvent.addProperty( "value", src.getValue() );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case OLD:
|
||||||
|
clickEvent.addProperty( "value", src.getValue() );
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException( "Unknown serializer type" );
|
||||||
|
}
|
||||||
|
|
||||||
|
return clickEvent;
|
||||||
|
}
|
||||||
|
}
|
@ -30,6 +30,7 @@ import net.md_5.bungee.api.chat.hover.content.Text;
|
|||||||
import net.md_5.bungee.api.chat.hover.content.TextSerializer;
|
import net.md_5.bungee.api.chat.hover.content.TextSerializer;
|
||||||
import net.md_5.bungee.api.dialog.Dialog;
|
import net.md_5.bungee.api.dialog.Dialog;
|
||||||
import net.md_5.bungee.api.dialog.chat.ShowDialogClickEvent;
|
import net.md_5.bungee.api.dialog.chat.ShowDialogClickEvent;
|
||||||
|
import net.md_5.bungee.dialog.ChatClickEventWrapperSerializer;
|
||||||
import net.md_5.bungee.dialog.DialogSerializer;
|
import net.md_5.bungee.dialog.DialogSerializer;
|
||||||
import net.md_5.bungee.dialog.ShowDialogClickEventSerializer;
|
import net.md_5.bungee.dialog.ShowDialogClickEventSerializer;
|
||||||
import org.jetbrains.annotations.ApiStatus;
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
@ -67,6 +68,7 @@ public class VersionedComponentSerializer implements JsonDeserializer<BaseCompon
|
|||||||
// Dialogs
|
// Dialogs
|
||||||
registerTypeAdapter( Dialog.class, dialogSerializer ).
|
registerTypeAdapter( Dialog.class, dialogSerializer ).
|
||||||
registerTypeAdapter( ShowDialogClickEvent.class, new ShowDialogClickEventSerializer() ).
|
registerTypeAdapter( ShowDialogClickEvent.class, new ShowDialogClickEventSerializer() ).
|
||||||
|
registerTypeAdapter( ChatClickEventWrapperSerializer.class, new ChatClickEventWrapperSerializer() ).
|
||||||
create();
|
create();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
package net.md_5.bungee.dialog;
|
||||||
|
|
||||||
|
import com.google.gson.JsonDeserializationContext;
|
||||||
|
import com.google.gson.JsonDeserializer;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonParseException;
|
||||||
|
import com.google.gson.JsonSerializationContext;
|
||||||
|
import com.google.gson.JsonSerializer;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import net.md_5.bungee.api.dialog.action.StaticAction;
|
||||||
|
import net.md_5.bungee.chat.ClickEventSerializer;
|
||||||
|
|
||||||
|
public class ChatClickEventWrapperSerializer implements JsonDeserializer<StaticAction.ChatClickEventWrapper>, JsonSerializer<StaticAction.ChatClickEventWrapper>
|
||||||
|
{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StaticAction.ChatClickEventWrapper deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||||
|
{
|
||||||
|
return new StaticAction.ChatClickEventWrapper( ClickEventSerializer.DIALOG.deserialize( json.getAsJsonObject(), context ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JsonElement serialize(StaticAction.ChatClickEventWrapper src, Type typeOfSrc, JsonSerializationContext context)
|
||||||
|
{
|
||||||
|
return ClickEventSerializer.DIALOG.serialize( src.event(), context );
|
||||||
|
}
|
||||||
|
}
|
@ -22,16 +22,14 @@ import net.md_5.bungee.api.dialog.Dialog;
|
|||||||
import net.md_5.bungee.api.dialog.DialogBase;
|
import net.md_5.bungee.api.dialog.DialogBase;
|
||||||
import net.md_5.bungee.api.dialog.DialogListDialog;
|
import net.md_5.bungee.api.dialog.DialogListDialog;
|
||||||
import net.md_5.bungee.api.dialog.MultiActionDialog;
|
import net.md_5.bungee.api.dialog.MultiActionDialog;
|
||||||
import net.md_5.bungee.api.dialog.MultiActionInputFormDialog;
|
|
||||||
import net.md_5.bungee.api.dialog.NoticeDialog;
|
import net.md_5.bungee.api.dialog.NoticeDialog;
|
||||||
import net.md_5.bungee.api.dialog.ServerLinksDialog;
|
import net.md_5.bungee.api.dialog.ServerLinksDialog;
|
||||||
import net.md_5.bungee.api.dialog.SimpleInputFormDialog;
|
|
||||||
import net.md_5.bungee.chat.VersionedComponentSerializer;
|
import net.md_5.bungee.chat.VersionedComponentSerializer;
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class DialogSerializer implements JsonDeserializer<Dialog>, JsonSerializer<Dialog>
|
public class DialogSerializer implements JsonDeserializer<Dialog>, JsonSerializer<Dialog>
|
||||||
{
|
{
|
||||||
private static final ThreadLocal<Set<Dialog>> serializedDialogs = new ThreadLocal<Set<Dialog>>();
|
private static final ThreadLocal<Set<Dialog>> serializedDialogs = new ThreadLocal<>();
|
||||||
private static final BiMap<String, Class<? extends Dialog>> TYPES;
|
private static final BiMap<String, Class<? extends Dialog>> TYPES;
|
||||||
private final VersionedComponentSerializer serializer;
|
private final VersionedComponentSerializer serializer;
|
||||||
|
|
||||||
@ -44,8 +42,6 @@ public class DialogSerializer implements JsonDeserializer<Dialog>, JsonSerialize
|
|||||||
builder.put( "minecraft:multi_action", MultiActionDialog.class );
|
builder.put( "minecraft:multi_action", MultiActionDialog.class );
|
||||||
builder.put( "minecraft:server_links", ServerLinksDialog.class );
|
builder.put( "minecraft:server_links", ServerLinksDialog.class );
|
||||||
builder.put( "minecraft:dialog_list", DialogListDialog.class );
|
builder.put( "minecraft:dialog_list", DialogListDialog.class );
|
||||||
builder.put( "minecraft:simple_input_form", SimpleInputFormDialog.class );
|
|
||||||
builder.put( "minecraft:multi_action_input_form", MultiActionInputFormDialog.class );
|
|
||||||
|
|
||||||
TYPES = builder.build();
|
TYPES = builder.build();
|
||||||
}
|
}
|
||||||
@ -108,7 +104,7 @@ public class DialogSerializer implements JsonDeserializer<Dialog>, JsonSerialize
|
|||||||
boolean first = serializedDialogs.get() == null;
|
boolean first = serializedDialogs.get() == null;
|
||||||
if ( first )
|
if ( first )
|
||||||
{
|
{
|
||||||
serializedDialogs.set( Collections.newSetFromMap( new IdentityHashMap<Dialog, Boolean>() ) );
|
serializedDialogs.set( Collections.newSetFromMap( new IdentityHashMap<>() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
|
Loading…
Reference in New Issue
Block a user