Add missing Range annotations to dialog types

Closes #12825
This commit is contained in:
Jake Potrebic
2025-07-12 09:01:09 -07:00
parent 25d358cf01
commit ba7c982605
6 changed files with 54 additions and 12 deletions

View File

@@ -29,8 +29,8 @@ public sealed interface DialogBody permits ItemDialogBody, PlainMessageDialogBod
final @Nullable PlainMessageDialogBody description,
final boolean showDecorations,
final boolean showTooltip,
final int width,
final int height
final @Range(from = 1, to = 256) int width,
final @Range(from = 1, to = 256) int height
) {
return item(item)
.description(description)

View File

@@ -52,7 +52,7 @@ public non-sealed interface ItemDialogBody extends DialogBody {
* @return the width
*/
@Contract(pure = true)
int width();
@Range(from = 1, to = 256) int width();
/**
* The height of the item body.
@@ -60,7 +60,7 @@ public non-sealed interface ItemDialogBody extends DialogBody {
* @return the height
*/
@Contract(pure = true)
int height();
@Range(from = 1, to = 256) int height();
/**
* A builder for an item dialog body.

View File

@@ -3,7 +3,9 @@ package io.papermc.paper.registry.data.dialog.input;
import io.papermc.paper.registry.data.dialog.DialogInstancesProvider;
import java.util.List;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.index.qual.Positive;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.Range;
import org.jspecify.annotations.Nullable;
/**
@@ -56,7 +58,16 @@ public sealed interface DialogInput permits BooleanDialogInput, NumberRangeDialo
* @return a new number range dialog input instance
*/
@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();
}
@@ -85,7 +96,13 @@ public sealed interface DialogInput permits BooleanDialogInput, NumberRangeDialo
* @return a new single option dialog input instance
*/
@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();
}
@@ -115,7 +132,15 @@ public sealed interface DialogInput permits BooleanDialogInput, NumberRangeDialo
* @return a new text dialog input instance
*/
@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();
}

View File

@@ -75,7 +75,10 @@ public non-sealed interface TextDialogInput extends DialogInput {
* @param height the height of the input, or null if not set
* @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);
}

View File

@@ -6,6 +6,7 @@ import io.papermc.paper.registry.data.dialog.DialogInstancesProvider;
import io.papermc.paper.registry.set.RegistrySet;
import java.util.List;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.Range;
import org.jspecify.annotations.Nullable;
/**
@@ -35,7 +36,12 @@ public sealed interface DialogType permits ConfirmationType, DialogListType, Mul
* @return a new instance
*/
@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();
}
@@ -59,7 +65,11 @@ public sealed interface DialogType permits ConfirmationType, DialogListType, Mul
* @return a new instance
*/
@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();
}
@@ -104,7 +114,11 @@ public sealed interface DialogType permits ConfirmationType, DialogListType, Mul
* @return a new instance
*/
@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);
}
}

View File

@@ -50,7 +50,7 @@ public record ItemDialogBodyImpl(
@Override
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;
return this;
}