mirror of
https://github.com/PaperMC/Paper.git
synced 2025-07-26 09:42:06 -07:00
@@ -29,8 +29,8 @@ public sealed interface DialogBody permits ItemDialogBody, PlainMessageDialogBod
|
|||||||
final @Nullable PlainMessageDialogBody description,
|
final @Nullable PlainMessageDialogBody description,
|
||||||
final boolean showDecorations,
|
final boolean showDecorations,
|
||||||
final boolean showTooltip,
|
final boolean showTooltip,
|
||||||
final int width,
|
final @Range(from = 1, to = 256) int width,
|
||||||
final int height
|
final @Range(from = 1, to = 256) int height
|
||||||
) {
|
) {
|
||||||
return item(item)
|
return item(item)
|
||||||
.description(description)
|
.description(description)
|
||||||
|
@@ -52,7 +52,7 @@ public non-sealed interface ItemDialogBody extends DialogBody {
|
|||||||
* @return the width
|
* @return the width
|
||||||
*/
|
*/
|
||||||
@Contract(pure = true)
|
@Contract(pure = true)
|
||||||
int width();
|
@Range(from = 1, to = 256) int width();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The height of the item body.
|
* The height of the item body.
|
||||||
@@ -60,7 +60,7 @@ public non-sealed interface ItemDialogBody extends DialogBody {
|
|||||||
* @return the height
|
* @return the height
|
||||||
*/
|
*/
|
||||||
@Contract(pure = true)
|
@Contract(pure = true)
|
||||||
int height();
|
@Range(from = 1, to = 256) int height();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A builder for an item dialog body.
|
* A builder for an item dialog body.
|
||||||
|
@@ -3,7 +3,9 @@ package io.papermc.paper.registry.data.dialog.input;
|
|||||||
import io.papermc.paper.registry.data.dialog.DialogInstancesProvider;
|
import io.papermc.paper.registry.data.dialog.DialogInstancesProvider;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.checkerframework.checker.index.qual.Positive;
|
||||||
import org.jetbrains.annotations.Contract;
|
import org.jetbrains.annotations.Contract;
|
||||||
|
import org.jetbrains.annotations.Range;
|
||||||
import org.jspecify.annotations.Nullable;
|
import org.jspecify.annotations.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -56,7 +58,16 @@ public sealed interface DialogInput permits BooleanDialogInput, NumberRangeDialo
|
|||||||
* @return a new number range dialog input instance
|
* @return a new number range dialog input instance
|
||||||
*/
|
*/
|
||||||
@Contract(pure = true, value = "_, _, _, _, _, _, _, _ -> new")
|
@Contract(pure = true, value = "_, _, _, _, _, _, _, _ -> new")
|
||||||
static NumberRangeDialogInput numberRange(final String key, final int width, final Component label, final String labelFormat, final float start, final float end, final @Nullable Float initial, final @Nullable Float step) {
|
static NumberRangeDialogInput numberRange(
|
||||||
|
final String key,
|
||||||
|
final @Range(from = 1, to = 1024) int width,
|
||||||
|
final Component label,
|
||||||
|
final String labelFormat,
|
||||||
|
final float start,
|
||||||
|
final float end,
|
||||||
|
final @Nullable Float initial,
|
||||||
|
final @Positive @Nullable Float step
|
||||||
|
) {
|
||||||
return numberRange(key, label, start, end).width(width).labelFormat(labelFormat).initial(initial).step(step).build();
|
return numberRange(key, label, start, end).width(width).labelFormat(labelFormat).initial(initial).step(step).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,7 +96,13 @@ public sealed interface DialogInput permits BooleanDialogInput, NumberRangeDialo
|
|||||||
* @return a new single option dialog input instance
|
* @return a new single option dialog input instance
|
||||||
*/
|
*/
|
||||||
@Contract(pure = true, value = "_, _, _, _, _ -> new")
|
@Contract(pure = true, value = "_, _, _, _, _ -> new")
|
||||||
static SingleOptionDialogInput singleOption(final String key, final int width, final List<SingleOptionDialogInput.OptionEntry> entries, final Component label, final boolean labelVisible) {
|
static SingleOptionDialogInput singleOption(
|
||||||
|
final String key,
|
||||||
|
final @Range(from = 1, to = 1024) int width,
|
||||||
|
final List<SingleOptionDialogInput.OptionEntry> entries,
|
||||||
|
final Component label,
|
||||||
|
final boolean labelVisible
|
||||||
|
) {
|
||||||
return singleOption(key, label, entries).width(width).labelVisible(labelVisible).build();
|
return singleOption(key, label, entries).width(width).labelVisible(labelVisible).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,7 +132,15 @@ public sealed interface DialogInput permits BooleanDialogInput, NumberRangeDialo
|
|||||||
* @return a new text dialog input instance
|
* @return a new text dialog input instance
|
||||||
*/
|
*/
|
||||||
@Contract(pure = true, value = "_, _, _, _, _, _, _ -> new")
|
@Contract(pure = true, value = "_, _, _, _, _, _, _ -> new")
|
||||||
static TextDialogInput text(final String key, final int width, final Component label, final boolean labelVisible, final String initial, final int maxLength, final TextDialogInput.@Nullable MultilineOptions multilineOptions) {
|
static TextDialogInput text(
|
||||||
|
final String key,
|
||||||
|
final @Range(from = 1, to = 1024) int width,
|
||||||
|
final Component label,
|
||||||
|
final boolean labelVisible,
|
||||||
|
final String initial,
|
||||||
|
final @Range(from = 1, to = Integer.MAX_VALUE) int maxLength,
|
||||||
|
final TextDialogInput.@Nullable MultilineOptions multilineOptions
|
||||||
|
) {
|
||||||
return text(key, label).width(width).labelVisible(labelVisible).initial(initial).maxLength(maxLength).multiline(multilineOptions).build();
|
return text(key, label).width(width).labelVisible(labelVisible).initial(initial).maxLength(maxLength).multiline(multilineOptions).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -75,7 +75,10 @@ public non-sealed interface TextDialogInput extends DialogInput {
|
|||||||
* @param height the height of the input, or null if not set
|
* @param height the height of the input, or null if not set
|
||||||
* @return a new MultilineOptions instance
|
* @return a new MultilineOptions instance
|
||||||
*/
|
*/
|
||||||
static MultilineOptions create(final @Nullable Integer maxLines, final @Nullable Integer height) {
|
static MultilineOptions create(
|
||||||
|
final @Range(from = 1, to = Integer.MAX_VALUE) @Nullable Integer maxLines,
|
||||||
|
final @Range(from = 1, to = 512) @Nullable Integer height
|
||||||
|
) {
|
||||||
return DialogInstancesProvider.instance().multilineOptions(maxLines, height);
|
return DialogInstancesProvider.instance().multilineOptions(maxLines, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -6,6 +6,7 @@ import io.papermc.paper.registry.data.dialog.DialogInstancesProvider;
|
|||||||
import io.papermc.paper.registry.set.RegistrySet;
|
import io.papermc.paper.registry.set.RegistrySet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.jetbrains.annotations.Contract;
|
import org.jetbrains.annotations.Contract;
|
||||||
|
import org.jetbrains.annotations.Range;
|
||||||
import org.jspecify.annotations.Nullable;
|
import org.jspecify.annotations.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,7 +36,12 @@ public sealed interface DialogType permits ConfirmationType, DialogListType, Mul
|
|||||||
* @return a new instance
|
* @return a new instance
|
||||||
*/
|
*/
|
||||||
@Contract(value = "_, _, _, _ -> new", pure = true)
|
@Contract(value = "_, _, _, _ -> new", pure = true)
|
||||||
static DialogListType dialogList(final RegistrySet<Dialog> dialogs, final @Nullable ActionButton exitAction, final int columns, final int buttonWidth) {
|
static DialogListType dialogList(
|
||||||
|
final RegistrySet<Dialog> dialogs,
|
||||||
|
final @Nullable ActionButton exitAction,
|
||||||
|
final @Range(from = 1, to = Integer.MAX_VALUE) int columns,
|
||||||
|
final @Range(from = 1, to = 1024) int buttonWidth
|
||||||
|
) {
|
||||||
return dialogList(dialogs).exitAction(exitAction).columns(columns).buttonWidth(buttonWidth).build();
|
return dialogList(dialogs).exitAction(exitAction).columns(columns).buttonWidth(buttonWidth).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,7 +65,11 @@ public sealed interface DialogType permits ConfirmationType, DialogListType, Mul
|
|||||||
* @return a new instance
|
* @return a new instance
|
||||||
*/
|
*/
|
||||||
@Contract(value = "_, _, _ -> new", pure = true)
|
@Contract(value = "_, _, _ -> new", pure = true)
|
||||||
static MultiActionType multiAction(final List<ActionButton> actions, final @Nullable ActionButton exitAction, final int columns) {
|
static MultiActionType multiAction(
|
||||||
|
final List<ActionButton> actions,
|
||||||
|
final @Nullable ActionButton exitAction,
|
||||||
|
final @Range(from = 1, to = Integer.MAX_VALUE) int columns
|
||||||
|
) {
|
||||||
return multiAction(actions).exitAction(exitAction).columns(columns).build();
|
return multiAction(actions).exitAction(exitAction).columns(columns).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +114,11 @@ public sealed interface DialogType permits ConfirmationType, DialogListType, Mul
|
|||||||
* @return a new instance
|
* @return a new instance
|
||||||
*/
|
*/
|
||||||
@Contract(value = "_, _, _ -> new", pure = true)
|
@Contract(value = "_, _, _ -> new", pure = true)
|
||||||
static ServerLinksType serverLinks(final @Nullable ActionButton exitAction, final int columns, final int buttonWidth) {
|
static ServerLinksType serverLinks(
|
||||||
|
final @Nullable ActionButton exitAction,
|
||||||
|
final @Range(from = 1, to = Integer.MAX_VALUE) int columns,
|
||||||
|
final @Range(from = 1, to = 1024) int buttonWidth
|
||||||
|
) {
|
||||||
return DialogInstancesProvider.instance().serverLinks(exitAction, columns, buttonWidth);
|
return DialogInstancesProvider.instance().serverLinks(exitAction, columns, buttonWidth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -50,7 +50,7 @@ public record ItemDialogBodyImpl(
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemDialogBody.Builder height(final int height) {
|
public ItemDialogBody.Builder height(final int height) {
|
||||||
Preconditions.checkArgument(this.width >= 1 && this.width <= 256, "Width must be between 1 and 256");
|
Preconditions.checkArgument(height >= 1 && height <= 256, "Height must be between 1 and 256");
|
||||||
this.height = height;
|
this.height = height;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user