Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Allow setting optional buttons with a ButtonComponent #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/main/java/org/geysermc/cumulus/form/SimpleForm.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -153,5 +153,15 @@ interface Builder extends FormBuilder<Builder, SimpleForm, SimpleFormResponse> {
* @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);
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Loading