### Cumulus 1.0 Response Handling Example Source: https://github.com/geysermc/cumulus/wiki/Updating-from-1.0-to-1.1-(and-2.0) This Java code demonstrates the manual response parsing required in Cumulus 1.0, showing how to build a custom form and handle responses using a custom handler. ```java CustomForm.builder() .title("geyser.auth.login.form.details.title") .label("geyser.auth.login.form.details.desc") .input("geyser.auth.login.form.details.email", "account@geysermc.org", "") .input("geyser.auth.login.form.details.pass", "123456", "") .responseHandler(responseData -> { CustomFormResponse response = form.parseResponse(responseData); if (!response.isCorrect()) { buildAndShowLoginDetailsWindow(session); return; } session.authenticate(response.next(), response.next()); })); ``` -------------------------------- ### Cumulus 2.0 Simplified Response Handling Example Source: https://github.com/geysermc/cumulus/wiki/Updating-from-1.0-to-1.1-(and-2.0) This Java code illustrates the improved response handling in Cumulus 2.0, utilizing new methods like closedOrInvalidResultHandler and validResultHandler for more streamlined processing. ```java CustomForm.builder() .title("geyser.auth.login.form.details.title") .label("geyser.auth.login.form.details.desc") .input("geyser.auth.login.form.details.email", "account@geysermc.org", "") .input("geyser.auth.login.form.details.pass", "123456", "") .closedOrInvalidResultHandler(() -> buildAndShowLoginDetailsWindow(session)) .validResultHandler(response -> session.authenticate(response.next(), response.next()))); ``` -------------------------------- ### Create a SimpleForm Source: https://github.com/geysermc/cumulus/wiki/Home Illustrates how to build a SimpleForm, offering more customization than ModalForm. It allows for multiple buttons, with or without images, using either URLs or local file paths. ```java SimpleForm.builder() .title("Title") .content("Content") .button("Button without an image") .button("Button with URL image", FormImage.Type.URL, "https://github.com/GeyserMC.png?size=200") .button("Button with path image", FormImage.Type.PATH, "textures/i/glyph_world_template.png") ``` -------------------------------- ### Create a ModalForm Source: https://github.com/geysermc/cumulus/wiki/Home Demonstrates the creation of a ModalForm, which includes a title, content, and two buttons. This is the simplest form type. ```java ModalForm.builder() .title("Title") .content("Content") .button1("Button 1") .button2("Button 2") ``` -------------------------------- ### Cumulus API: Optional Button Handling (Old vs New) Source: https://github.com/geysermc/cumulus/wiki/Updating-from-1.0-to-1.1-(and-2.0) Demonstrates the difference in handling optional buttons in the Cumulus API. The older version required manual checks for button IDs, while the new version guarantees sequential IDs, simplifying response handling. ```java SimpleForm.builder() .optionalButton("geyser.auth.login.form.notice.btn_login.mojang", isPasswordAuthEnabled) // is the id 0 or absent?? .button("geyser.auth.login.form.notice.btn_login.microsoft") // is the id 0 or 1?? .button("geyser.auth.login.form.notice.btn_disconnect") // is the id 1 or 2?? .validResponseHandler(response -> { if (isPasswordAuthEnabled && response.clickedButtonId() == 0) { session.setMicrosoftAccount(false); buildAndShowLoginDetailsWindow(session); return; } if (isPasswordAuthEnabled && response.clickedButtonId() == 1 || !isPasswordAuthEnabled && response.clickedButtonId() == 0) { session.setMicrosoftAccount(true); buildAndShowMicrosoftAuthenticationWindow(session); return; } session.disconnect(...) }) ``` ```java SimpleForm.builder() .optionalButton("geyser.auth.login.form.notice.btn_login.mojang", isPasswordAuthEnabled) // always 0 .button("geyser.auth.login.form.notice.btn_login.microsoft") // always 1 .button("geyser.auth.login.form.notice.btn_disconnect") // always 2 .validResponseHandler(response -> { if (response.clickedButtonId() == 0) { session.setMicrosoftAccount(false); buildAndShowLoginDetailsWindow(session); return; } if (response.clickedButtonId() == 1) { session.setMicrosoftAccount(true); buildAndShowMicrosoftAuthenticationWindow(session); return; } s session.disconnect(...) }) ``` -------------------------------- ### Create a CustomForm Source: https://github.com/geysermc/cumulus/wiki/Home Shows the creation of a CustomForm, the most customizable form type. It supports various components like dropdowns, inputs, toggles, and sliders. ```java CustomForm.builder() .title("Title") .dropdown("Text", "Option 1", "Option 2") .input("Input", "placeholder") .toggle("Toggle") .slider("Text", 0, 10, 1, 5) ``` -------------------------------- ### Handle ModalForm Response (Builder) Source: https://github.com/geysermc/cumulus/wiki/Home Demonstrates how to set a response handler directly within the ModalForm builder. This handler processes the player's response, checking if it's valid and acting upon the button clicked. ```java _Modal_Form.builder() .title("Feedback form") .content("We're asking for feedback, are you willing to enter some feedback to improve our server?") .button1("Yes") // id = 0 .button2("No") // id = 1 .responseHandler((form, responseData) -> { _Modal_FormResponse response = form.parseResponse(responseData); if (!response.isCorrect()) { // player closed the form or returned invalid info (see FormResponse) return; } // short version of getClickedButtonId == 0 if (response.getResult()) { System.out.println("Yay, he wants to give us feedback"); return; } System.out.println("No feedback for us :("); }); ``` -------------------------------- ### Translate form data using a separate method in Java Source: https://github.com/geysermc/cumulus/wiki/Home Demonstrates how to use the `translator` method with a separate method reference for translation. This approach is useful for complex translation logic encapsulated in a dedicated method. It takes the key and locale as arguments. ```java _Modal_Form form = _Modal_Form.builder() .translator(this::translate, userLanguage) .title("Title") .content("Content") .button1("translate.button1") .button2("translate.button2") .build(); public String translate(String key, String locale) { // this method will be called for every string, in this case, 4 times: // Title, Content, translate.button1, translate.button2 // your own translate logic here // return the value that replaces the key } ``` -------------------------------- ### Handle ModalForm Response (Setter) Source: https://github.com/geysermc/cumulus/wiki/Home Shows an alternative method for handling ModalForm responses by setting the response handler on an existing Form object, rather than during its creation. ```java _Modal_Form form = ...; form.setResponseHandler(responseData -> { _Modal_FormResponse response = form.parseResponse(responseData); if (!response.isCorrect()) { // player closed the form or returned invalid info (see FormResponse) return; } // short version of getClickedButtonId == 0 if (response.getResult()) { System.out.println("Yay, he wants to give us feedback"); return; } System.out.println("No feedback for us :("); }); ``` -------------------------------- ### Translate form data using an inline lambda in Java Source: https://github.com/geysermc/cumulus/wiki/Home Illustrates how to implement translation directly within the FormBuilder using an inline lambda expression. This is suitable for simpler translation logic that doesn't warrant a separate method. The lambda receives the key and an unused locale argument. ```java _Modal_Form form = _Modal_Form.builder() .translator((key, unused) -> { // this method will be called for every string, in this case, 4 times: // Title, Content, translate.button1, translate.button2 // since this isn't a separate method, you don't need the locale argument, so it's unused. // your own translate logic here // return the value that replaces the key }) .title("Title") .content("Content") .button1("translate.button1") .button2("translate.button2") .build(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.