diff --git a/src/main/java/org/geysermc/cumulus/form/SimpleForm.java b/src/main/java/org/geysermc/cumulus/form/SimpleForm.java index 72599d7..cf609b6 100644 --- a/src/main/java/org/geysermc/cumulus/form/SimpleForm.java +++ b/src/main/java/org/geysermc/cumulus/form/SimpleForm.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2023 GeyserMC + * Copyright (c) 2020-2024 GeyserMC * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -153,5 +153,15 @@ interface Builder extends FormBuilder { * @since 1.1 */ @This Builder optionalButton(@NonNull String text, boolean shouldAdd); + + /** + * Adds a button to the Form, but only when shouldAdd is true. + * + * @param button the button to add + * @param shouldAdd if the button should be added + * @return the form builder + * @since 1.2 + */ + @This Builder optionalButton(@NonNull ButtonComponent button, boolean shouldAdd); } } diff --git a/src/main/java/org/geysermc/cumulus/form/impl/simple/SimpleFormImpl.java b/src/main/java/org/geysermc/cumulus/form/impl/simple/SimpleFormImpl.java index ea5c2ac..7a9fbc9 100644 --- a/src/main/java/org/geysermc/cumulus/form/impl/simple/SimpleFormImpl.java +++ b/src/main/java/org/geysermc/cumulus/form/impl/simple/SimpleFormImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2023 GeyserMC + * Copyright (c) 2020-2024 GeyserMC * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -30,6 +30,7 @@ import java.util.Objects; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; +import org.checkerframework.common.returnsreceiver.qual.This; import org.geysermc.cumulus.component.ButtonComponent; import org.geysermc.cumulus.form.SimpleForm; import org.geysermc.cumulus.form.impl.FormImpl; @@ -124,6 +125,15 @@ public Builder optionalButton(@NonNull String text, boolean shouldAdd) { return addNullButton(); } + @Override + public SimpleForm.@This Builder optionalButton( + @NonNull ButtonComponent button, boolean shouldAdd) { + if (shouldAdd) { + return button(button); + } + return addNullButton(); + } + @Override public @NonNull SimpleForm build() { SimpleFormImpl form = new SimpleFormImpl(title, content, buttons);