Use Cumulus as form library

This commit is contained in:
Tim203 2020-12-10 22:57:48 +01:00
parent f7d2378845
commit 45596a87a9
No known key found for this signature in database
GPG key ID: 064EE9F5BF7C3EE8
47 changed files with 30 additions and 2694 deletions

View file

@ -11,11 +11,15 @@
<artifactId>common</artifactId> <artifactId>common</artifactId>
<dependencies> <dependencies>
<dependency>
<groupId>org.geysermc.cumulus</groupId>
<artifactId>cumulus</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency> <dependency>
<groupId>com.google.code.gson</groupId> <groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId> <artifactId>gson</artifactId>
<version>2.8.5</version> <version>2.8.6</version>
<scope>compile</scope>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

View file

@ -1,86 +0,0 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.common.form;
import org.geysermc.common.form.component.Component;
import org.geysermc.common.form.component.DropdownComponent;
import org.geysermc.common.form.component.StepSliderComponent;
import org.geysermc.common.form.impl.CustomFormImpl;
import org.geysermc.common.form.response.CustomFormResponse;
import java.util.List;
public interface CustomForm extends Form<CustomFormResponse> {
static CustomForm.Builder builder() {
return new CustomFormImpl.Builder();
}
static CustomForm of(String title, FormImage icon, List<Component> content) {
return CustomFormImpl.of(title, icon, content);
}
interface Builder extends FormBuilder<Builder, CustomForm> {
Builder icon(FormImage.Type type, String data);
Builder iconPath(String path);
Builder iconUrl(String url);
Builder component(Component component);
Builder dropdown(DropdownComponent.Builder dropdownBuilder);
Builder dropdown(String text, int defaultOption, String... options);
Builder dropdown(String text, String... options);
Builder input(String text, String placeholder, String defaultText);
Builder input(String text, String placeholder);
Builder input(String text);
Builder label(String text);
Builder slider(String text, float min, float max, int step, float defaultValue);
Builder slider(String text, float min, float max, int step);
Builder slider(String text, float min, float max, float defaultValue);
Builder slider(String text, float min, float max);
Builder stepSlider(StepSliderComponent.Builder stepSliderBuilder);
Builder stepSlider(String text, int defaultStep, String... steps);
Builder stepSlider(String text, String... steps);
Builder toggle(String text, boolean defaultValue);
Builder toggle(String text);
}
}

View file

@ -1,83 +0,0 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.common.form;
import org.geysermc.common.form.response.FormResponse;
import java.util.function.Consumer;
/**
* Base class of all Forms. While it can be used it doesn't contain every data you could get when
* using the specific class of the form type.
*
* @param <T> class provided by the specific form type. It understands the response data and makes
* the data easily accessible
*/
public interface Form<T extends FormResponse> {
/**
* Returns the form type of this specific instance. The valid form types can be found {@link
* FormType in the FormType class}
*/
FormType getType();
/**
* Returns the data that will be sent by Geyser to the Bedrock client
*/
String getJsonData();
/**
* Returns the handler that will be invoked once the form got a response from the Bedrock
* client
*/
Consumer<String> getResponseHandler();
/**
* Sets the handler that will be invoked once the form got a response from the Bedrock client.
* This handler contains the raw data sent by the Bedrock client. See {@link
* #parseResponse(String)} if you want to turn the given data into something that's easier to
* handle.
*
* @param responseHandler the response handler
*/
void setResponseHandler(Consumer<String> responseHandler);
/**
* Parses the method into something provided by the form implementation, which will make the
* data given by the Bedrock client easier to handle.
*
* @param response the raw data given by the Bedrock client
* @return the data in an easy-to-handle class
*/
T parseResponse(String response);
/**
* Checks if the given data by the Bedrock client is saying that the client closed the form.
*
* @param response the raw data given by the Bedrock client
* @return true if the raw data implies that the Bedrock client closed the form
*/
boolean isClosed(String response);
}

View file

@ -1,44 +0,0 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.common.form;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Consumer;
public interface FormBuilder<T extends FormBuilder<T, F>, F extends Form<?>> {
T title(String title);
T translator(BiFunction<String, String, String> translator, String locale);
T translator(BiFunction<String, String, String> translator);
T responseHandler(BiConsumer<F, String> responseHandler);
T responseHandler(Consumer<String> responseHandler);
F build();
}

View file

@ -1,62 +0,0 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.common.form;
import com.google.gson.annotations.SerializedName;
import lombok.RequiredArgsConstructor;
import org.geysermc.common.form.impl.util.FormImageImpl;
public interface FormImage {
static FormImage of(Type type, String data) {
return FormImageImpl.of(type, data);
}
static FormImage of(String type, String data) {
return FormImageImpl.of(type, data);
}
Type getType();
String getData();
@RequiredArgsConstructor
enum Type {
@SerializedName("path") PATH,
@SerializedName("url") URL;
private static final Type[] VALUES = values();
public static Type getByName(String name) {
String upper = name.toUpperCase();
for (Type value : VALUES) {
if (value.name().equals(upper)) {
return value;
}
}
return null;
}
}
}

View file

@ -1,51 +0,0 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.common.form;
import com.google.gson.annotations.SerializedName;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.geysermc.common.form.impl.CustomFormImpl;
import org.geysermc.common.form.impl.ModalFormImpl;
import org.geysermc.common.form.impl.SimpleFormImpl;
@Getter
@RequiredArgsConstructor
public enum FormType {
@SerializedName("form")
SIMPLE_FORM(SimpleFormImpl.class),
@SerializedName("modal")
MODAL_FORM(ModalFormImpl.class),
@SerializedName("custom_form")
CUSTOM_FORM(CustomFormImpl.class);
private static final FormType[] VALUES = values();
private final Class<? extends Form> typeClass;
public static FormType getByOrdinal(int ordinal) {
return ordinal < VALUES.length ? VALUES[ordinal] : null;
}
}

View file

@ -1,46 +0,0 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.common.form;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.geysermc.common.form.impl.FormImpl;
import org.geysermc.common.form.impl.util.FormAdaptor;
public final class Forms {
private static final Gson GSON =
new GsonBuilder()
.registerTypeAdapter(FormImpl.class, new FormAdaptor())
.create();
public static Gson getGson() {
return GSON;
}
public static <T extends Form<?>> T fromJson(String json, Class<T> formClass) {
return GSON.fromJson(json, formClass);
}
}

View file

@ -1,47 +0,0 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.common.form;
import org.geysermc.common.form.impl.ModalFormImpl;
import org.geysermc.common.form.response.ModalFormResponse;
public interface ModalForm extends Form<ModalFormResponse> {
static Builder builder() {
return new ModalFormImpl.Builder();
}
static ModalForm of(String title, String content, String button1, String button2) {
return ModalFormImpl.of(title, content, button1, button2);
}
interface Builder extends FormBuilder<Builder, ModalForm> {
Builder content(String content);
Builder button1(String button1);
Builder button2(String button2);
}
}

View file

@ -1,61 +0,0 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.common.form;
import org.geysermc.common.form.component.ButtonComponent;
import org.geysermc.common.form.impl.SimpleFormImpl;
import org.geysermc.common.form.response.SimpleFormResponse;
import java.util.List;
/**
*
*/
public interface SimpleForm extends Form<SimpleFormResponse> {
static Builder builder() {
return new SimpleFormImpl.Builder();
}
static SimpleForm of(String title, String content, List<ButtonComponent> buttons) {
return SimpleFormImpl.of(title, content, buttons);
}
String getTitle();
String getContent();
List<ButtonComponent> getButtons();
interface Builder extends FormBuilder<Builder, SimpleForm> {
Builder content(String content);
Builder button(String text, FormImage.Type type, String data);
Builder button(String text, FormImage image);
Builder button(String text);
}
}

View file

@ -1,47 +0,0 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.common.form.component;
import org.geysermc.common.form.FormImage;
import org.geysermc.common.form.impl.component.ButtonComponentImpl;
public interface ButtonComponent {
static ButtonComponent of(String text, FormImage image) {
return ButtonComponentImpl.of(text, image);
}
static ButtonComponent of(String text, FormImage.Type type, String data) {
return ButtonComponentImpl.of(text, type, data);
}
static ButtonComponent of(String text) {
return of(text, null);
}
String getText();
FormImage getImage();
}

View file

@ -1,32 +0,0 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.common.form.component;
public interface Component {
ComponentType getType();
String getText();
}

View file

@ -1,61 +0,0 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.common.form.component;
import com.google.gson.annotations.SerializedName;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@Getter
@RequiredArgsConstructor
public enum ComponentType {
@SerializedName("dropdown")
DROPDOWN(DropdownComponent.class),
@SerializedName("input")
INPUT(InputComponent.class),
@SerializedName("label")
LABEL(LabelComponent.class),
@SerializedName("slider")
SLIDER(SliderComponent.class),
@SerializedName("step_slider")
STEP_SLIDER(StepSliderComponent.class),
@SerializedName("toggle")
TOGGLE(ToggleComponent.class);
private static final ComponentType[] VALUES = values();
private final String name = name().toLowerCase();
private final Class<? extends Component> componentClass;
public static ComponentType getByName(String name) {
for (ComponentType type : VALUES) {
if (type.name.equals(name)) {
return type;
}
}
return null;
}
}

View file

@ -1,63 +0,0 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.common.form.component;
import org.geysermc.common.form.impl.component.DropdownComponentImpl;
import java.util.List;
import java.util.function.Function;
public interface DropdownComponent extends Component {
static DropdownComponent of(String text, List<String> options, int defaultOption) {
return DropdownComponentImpl.of(text, options, defaultOption);
}
static Builder builder() {
return new DropdownComponentImpl.Builder();
}
static Builder builder(String text) {
return builder().text(text);
}
List<String> getOptions();
int getDefaultOption();
interface Builder {
Builder text(String text);
Builder option(String option, boolean isDefault);
Builder option(String option);
Builder defaultOption(int defaultOption);
DropdownComponent build();
DropdownComponent translateAndBuild(Function<String, String> translator);
}
}

View file

@ -1,46 +0,0 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.common.form.component;
import org.geysermc.common.form.impl.component.InputComponentImpl;
public interface InputComponent extends Component {
static InputComponent of(String text, String placeholder, String defaultText) {
return InputComponentImpl.of(text, placeholder, defaultText);
}
static InputComponent of(String text, String placeholder) {
return InputComponentImpl.of(text, placeholder, "");
}
static InputComponent of(String text) {
return InputComponentImpl.of(text, "", "");
}
String getPlaceholder();
String getDefaultText();
}

View file

@ -1,34 +0,0 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.common.form.component;
import org.geysermc.common.form.impl.component.LabelComponentImpl;
public interface LabelComponent extends Component {
static LabelComponent of(String text) {
return LabelComponentImpl.of(text);
}
}

View file

@ -1,54 +0,0 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.common.form.component;
import org.geysermc.common.form.impl.component.SliderComponentImpl;
public interface SliderComponent extends Component {
static SliderComponent of(String text, float min, float max, int step, float defaultValue) {
return SliderComponentImpl.of(text, min, max, step, defaultValue);
}
static SliderComponent of(String text, float min, float max, int step) {
return SliderComponentImpl.of(text, min, max, step);
}
static SliderComponent of(String text, float min, float max, float defaultValue) {
return SliderComponentImpl.of(text, min, max, defaultValue);
}
static SliderComponent of(String text, float min, float max) {
return SliderComponentImpl.of(text, min, max);
}
float getMin();
float getMax();
int getStep();
float getDefaultValue();
}

View file

@ -1,71 +0,0 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.common.form.component;
import org.geysermc.common.form.impl.component.StepSliderComponentImpl;
import java.util.List;
import java.util.function.Function;
public interface StepSliderComponent extends Component {
static StepSliderComponent of(String text, List<String> steps, int defaultStep) {
return StepSliderComponentImpl.of(text, steps, defaultStep);
}
static StepSliderComponent of(String text, int defaultStep, String... steps) {
return StepSliderComponentImpl.of(text, defaultStep, steps);
}
static StepSliderComponent of(String text, String... steps) {
return StepSliderComponentImpl.of(text, steps);
}
static Builder builder() {
return new StepSliderComponentImpl.Builder();
}
static Builder builder(String text) {
return builder().text(text);
}
List<String> getSteps();
int getDefaultStep();
interface Builder {
Builder text(String text);
Builder step(String step, boolean defaultStep);
Builder step(String step);
Builder defaultStep(int defaultStep);
StepSliderComponent build();
StepSliderComponent translateAndBuild(Function<String, String> translator);
}
}

View file

@ -1,40 +0,0 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.common.form.component;
import org.geysermc.common.form.impl.component.ToggleComponentImpl;
public interface ToggleComponent extends Component {
static ToggleComponent of(String text, boolean defaultValue) {
return ToggleComponentImpl.of(text, defaultValue);
}
static ToggleComponent of(String text) {
return ToggleComponentImpl.of(text);
}
boolean getDefaultValue();
}

View file

@ -1,179 +0,0 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.common.form.impl;
import com.google.gson.annotations.JsonAdapter;
import lombok.Getter;
import org.geysermc.common.form.CustomForm;
import org.geysermc.common.form.FormImage;
import org.geysermc.common.form.FormType;
import org.geysermc.common.form.component.*;
import org.geysermc.common.form.impl.response.CustomFormResponseImpl;
import org.geysermc.common.form.impl.util.FormAdaptor;
import org.geysermc.common.form.impl.util.FormImageImpl;
import org.geysermc.common.form.response.CustomFormResponse;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@Getter
@JsonAdapter(FormAdaptor.class)
public final class CustomFormImpl extends FormImpl<CustomFormResponse> implements CustomForm {
private final String title;
private final FormImage icon;
private final List<Component> content;
private CustomFormImpl(String title, FormImage icon, List<Component> content) {
super(FormType.CUSTOM_FORM);
this.title = title;
this.icon = icon;
this.content = Collections.unmodifiableList(content);
}
public static CustomFormImpl of(String title, FormImage icon, List<Component> content) {
return new CustomFormImpl(title, icon, content);
}
public CustomFormResponseImpl parseResponse(String data) {
if (isClosed(data)) {
return CustomFormResponseImpl.closed();
}
return CustomFormResponseImpl.of(this, data);
}
public static final class Builder extends FormImpl.Builder<CustomForm.Builder, CustomForm>
implements CustomForm.Builder {
private final List<Component> components = new ArrayList<>();
private FormImage icon;
public Builder icon(FormImage.Type type, String data) {
icon = FormImageImpl.of(type, data);
return this;
}
public Builder iconPath(String path) {
return icon(FormImage.Type.PATH, path);
}
public Builder iconUrl(String url) {
return icon(FormImage.Type.URL, url);
}
public Builder component(Component component) {
components.add(component);
return this;
}
public Builder dropdown(DropdownComponent.Builder dropdownBuilder) {
return component(dropdownBuilder.translateAndBuild(this::translate));
}
public Builder dropdown(String text, int defaultOption, String... options) {
List<String> optionsList = new ArrayList<>();
for (String option : options) {
optionsList.add(translate(option));
}
return component(DropdownComponent.of(translate(text), optionsList, defaultOption));
}
public Builder dropdown(String text, String... options) {
return dropdown(text, -1, options);
}
public Builder input(String text, String placeholder, String defaultText) {
return component(InputComponent.of(
translate(text), translate(placeholder), translate(defaultText)
));
}
public Builder input(String text, String placeholder) {
return component(InputComponent.of(translate(text), translate(placeholder)));
}
public Builder input(String text) {
return component(InputComponent.of(translate(text)));
}
public Builder label(String text) {
return component(LabelComponent.of(translate(text)));
}
public Builder slider(String text, float min, float max, int step, float defaultValue) {
return component(SliderComponent.of(text, min, max, step, defaultValue));
}
public Builder slider(String text, float min, float max, int step) {
return slider(text, min, max, step, -1);
}
public Builder slider(String text, float min, float max, float defaultValue) {
return slider(text, min, max, -1, defaultValue);
}
public Builder slider(String text, float min, float max) {
return slider(text, min, max, -1, -1);
}
public Builder stepSlider(StepSliderComponent.Builder stepSliderBuilder) {
return component(stepSliderBuilder.translateAndBuild(this::translate));
}
public Builder stepSlider(String text, int defaultStep, String... steps) {
List<String> stepsList = new ArrayList<>();
for (String option : steps) {
stepsList.add(translate(option));
}
return component(StepSliderComponent.of(translate(text), stepsList, defaultStep));
}
public Builder stepSlider(String text, String... steps) {
return stepSlider(text, -1, steps);
}
public Builder toggle(String text, boolean defaultValue) {
return component(ToggleComponent.of(translate(text), defaultValue));
}
public Builder toggle(String text) {
return component(ToggleComponent.of(translate(text)));
}
@Override
public CustomFormImpl build() {
CustomFormImpl form = of(title, icon, components);
if (biResponseHandler != null) {
form.setResponseHandler(response -> biResponseHandler.accept(form, response));
return form;
}
form.setResponseHandler(responseHandler);
return form;
}
}
}

View file

@ -1,121 +0,0 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.common.form.impl;
import com.google.gson.Gson;
import lombok.Getter;
import lombok.Setter;
import org.geysermc.common.form.Form;
import org.geysermc.common.form.FormBuilder;
import org.geysermc.common.form.FormType;
import org.geysermc.common.form.Forms;
import org.geysermc.common.form.response.FormResponse;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Consumer;
@Getter
public abstract class FormImpl<T extends FormResponse> implements Form<T> {
protected static final Gson GSON = Forms.getGson();
private final FormType type;
protected String hardcodedJsonData = null;
@Setter protected Consumer<String> responseHandler;
public FormImpl(FormType type) {
this.type = type;
}
@Override
public String getJsonData() {
if (hardcodedJsonData != null) {
return hardcodedJsonData;
}
return GSON.toJson(this);
}
@Override
public boolean isClosed(String response) {
return response == null || response.isEmpty() || response.equalsIgnoreCase("null");
}
public static abstract class Builder<T extends FormBuilder<T, F>, F extends Form<?>>
implements FormBuilder<T, F> {
protected String title = "";
protected BiFunction<String, String, String> translationHandler = null;
protected BiConsumer<F, String> biResponseHandler;
protected Consumer<String> responseHandler;
protected String locale;
@Override
public T title(String title) {
this.title = translate(title);
return self();
}
@Override
public T translator(BiFunction<String, String, String> translator, String locale) {
this.translationHandler = translator;
this.locale = locale;
return title(title);
}
@Override
public T translator(BiFunction<String, String, String> translator) {
return translator(translator, locale);
}
@Override
public T responseHandler(BiConsumer<F, String> responseHandler) {
biResponseHandler = responseHandler;
return self();
}
@Override
public T responseHandler(Consumer<String> responseHandler) {
this.responseHandler = responseHandler;
return self();
}
@Override
public abstract F build();
protected String translate(String text) {
if (translationHandler != null && text != null && !text.isEmpty()) {
return translationHandler.apply(text, locale);
}
return text;
}
@SuppressWarnings("unchecked")
protected T self() {
return (T) this;
}
}
}

View file

@ -1,105 +0,0 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.common.form.impl;
import com.google.gson.annotations.JsonAdapter;
import lombok.Getter;
import org.geysermc.common.form.FormType;
import org.geysermc.common.form.ModalForm;
import org.geysermc.common.form.impl.response.ModalFormResponseImpl;
import org.geysermc.common.form.impl.util.FormAdaptor;
import org.geysermc.common.form.response.ModalFormResponse;
@Getter
@JsonAdapter(FormAdaptor.class)
public final class ModalFormImpl extends FormImpl<ModalFormResponse> implements ModalForm {
private final String title;
private final String content;
private final String button1;
private final String button2;
private ModalFormImpl(String title, String content, String button1, String button2) {
super(FormType.MODAL_FORM);
this.title = title;
this.content = content;
this.button1 = button1;
this.button2 = button2;
}
public static ModalFormImpl of(String title, String content, String button1, String button2) {
return new ModalFormImpl(title, content, button1, button2);
}
public ModalFormResponse parseResponse(String data) {
if (isClosed(data)) {
return ModalFormResponseImpl.closed();
}
data = data.trim();
if ("true".equals(data)) {
return ModalFormResponseImpl.of(0, button1);
} else if ("false".equals(data)) {
return ModalFormResponseImpl.of(1, button2);
}
return ModalFormResponseImpl.invalid();
}
public static final class Builder extends FormImpl.Builder<ModalForm.Builder, ModalForm>
implements ModalForm.Builder {
private String content = "";
private String button1 = "";
private String button2 = "";
public Builder content(String content) {
this.content = translate(content);
return this;
}
public Builder button1(String button1) {
this.button1 = translate(button1);
return this;
}
public Builder button2(String button2) {
this.button2 = translate(button2);
return this;
}
@Override
public ModalForm build() {
ModalFormImpl form = of(title, content, button1, button2);
if (biResponseHandler != null) {
form.setResponseHandler(response -> biResponseHandler.accept(form, response));
return form;
}
form.setResponseHandler(responseHandler);
return form;
}
}
}

View file

@ -1,120 +0,0 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.common.form.impl;
import com.google.gson.annotations.JsonAdapter;
import lombok.Getter;
import org.geysermc.common.form.FormImage;
import org.geysermc.common.form.FormType;
import org.geysermc.common.form.SimpleForm;
import org.geysermc.common.form.component.ButtonComponent;
import org.geysermc.common.form.impl.component.ButtonComponentImpl;
import org.geysermc.common.form.impl.response.SimpleFormResponseImpl;
import org.geysermc.common.form.impl.util.FormAdaptor;
import org.geysermc.common.form.response.SimpleFormResponse;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@Getter
@JsonAdapter(FormAdaptor.class)
public final class SimpleFormImpl extends FormImpl<SimpleFormResponse> implements SimpleForm {
private final String title;
private final String content;
private final List<ButtonComponent> buttons;
private SimpleFormImpl(String title, String content, List<ButtonComponent> buttons) {
super(FormType.SIMPLE_FORM);
this.title = title;
this.content = content;
this.buttons = Collections.unmodifiableList(buttons);
}
public static SimpleFormImpl of(String title, String content, List<ButtonComponent> buttons) {
return new SimpleFormImpl(title, content, buttons);
}
public SimpleFormResponse parseResponse(String data) {
if (isClosed(data)) {
return SimpleFormResponseImpl.closed();
}
data = data.trim();
int buttonId;
try {
buttonId = Integer.parseInt(data);
} catch (Exception exception) {
return SimpleFormResponseImpl.invalid();
}
if (buttonId >= buttons.size()) {
return SimpleFormResponseImpl.invalid();
}
return SimpleFormResponseImpl.of(buttonId, buttons.get(buttonId));
}
public static final class Builder extends FormImpl.Builder<SimpleForm.Builder, SimpleForm>
implements SimpleForm.Builder {
private final List<ButtonComponent> buttons = new ArrayList<>();
private String content = "";
public Builder content(String content) {
this.content = translate(content);
return this;
}
public Builder button(String text, FormImage.Type type, String data) {
buttons.add(ButtonComponentImpl.of(translate(text), type, data));
return this;
}
public Builder button(String text, FormImage image) {
buttons.add(ButtonComponentImpl.of(translate(text), image));
return this;
}
public Builder button(String text) {
buttons.add(ButtonComponentImpl.of(translate(text)));
return this;
}
@Override
public SimpleForm build() {
SimpleFormImpl form = of(title, content, buttons);
if (biResponseHandler != null) {
form.setResponseHandler(response -> biResponseHandler.accept(form, response));
return form;
}
form.setResponseHandler(responseHandler);
return form;
}
}
}

View file

@ -1,52 +0,0 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.common.form.impl.component;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.geysermc.common.form.FormImage;
import org.geysermc.common.form.component.ButtonComponent;
import org.geysermc.common.form.impl.util.FormImageImpl;
@Getter
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public final class ButtonComponentImpl implements ButtonComponent {
private final String text;
private final FormImageImpl image;
public static ButtonComponentImpl of(String text, FormImage image) {
return new ButtonComponentImpl(text, (FormImageImpl) image);
}
public static ButtonComponentImpl of(String text, FormImage.Type type, String data) {
return of(text, FormImageImpl.of(type, data));
}
public static ButtonComponentImpl of(String text) {
return of(text, null);
}
}

View file

@ -1,45 +0,0 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.common.form.impl.component;
import lombok.Getter;
import org.geysermc.common.form.component.ComponentType;
import java.util.Objects;
@Getter
public abstract class Component {
private final ComponentType type;
private final String text;
Component(ComponentType type, String text) {
Objects.requireNonNull(type, "Type cannot be null");
Objects.requireNonNull(text, "Text cannot be null");
this.type = type;
this.text = text;
}
}

View file

@ -1,102 +0,0 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.common.form.impl.component;
import com.google.gson.annotations.SerializedName;
import lombok.Getter;
import org.geysermc.common.form.component.ComponentType;
import org.geysermc.common.form.component.DropdownComponent;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
@Getter
public final class DropdownComponentImpl extends Component implements DropdownComponent {
private final List<String> options;
@SerializedName("default")
private final int defaultOption;
private DropdownComponentImpl(String text, List<String> options, int defaultOption) {
super(ComponentType.DROPDOWN, text);
this.options = Collections.unmodifiableList(options);
this.defaultOption = defaultOption;
}
public static DropdownComponentImpl of(String text, List<String> options, int defaultOption) {
if (defaultOption == -1 || defaultOption >= options.size()) {
defaultOption = 0;
}
return new DropdownComponentImpl(text, options, defaultOption);
}
public static class Builder implements DropdownComponent.Builder {
private final List<String> options = new ArrayList<>();
private String text;
private int defaultOption = 0;
@Override
public Builder text(String text) {
this.text = text;
return this;
}
@Override
public Builder option(String option, boolean isDefault) {
options.add(option);
if (isDefault) {
defaultOption = options.size() - 1;
}
return this;
}
@Override
public Builder option(String option) {
return option(option, false);
}
@Override
public Builder defaultOption(int defaultOption) {
this.defaultOption = defaultOption;
return this;
}
@Override
public DropdownComponentImpl build() {
return of(text, options, defaultOption);
}
@Override
public DropdownComponentImpl translateAndBuild(Function<String, String> translator) {
for (int i = 0; i < options.size(); i++) {
options.set(i, translator.apply(options.get(i)));
}
return of(translator.apply(text), options, defaultOption);
}
}
}

View file

@ -1,56 +0,0 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.common.form.impl.component;
import com.google.gson.annotations.SerializedName;
import lombok.Getter;
import org.geysermc.common.form.component.ComponentType;
import org.geysermc.common.form.component.InputComponent;
@Getter
public final class InputComponentImpl extends Component implements InputComponent {
private final String placeholder;
@SerializedName("default")
private final String defaultText;
private InputComponentImpl(String text, String placeholder, String defaultText) {
super(ComponentType.INPUT, text);
this.placeholder = placeholder;
this.defaultText = defaultText;
}
public static InputComponentImpl of(String text, String placeholder, String defaultText) {
return new InputComponentImpl(text, placeholder, defaultText);
}
public static InputComponentImpl of(String text, String placeholder) {
return new InputComponentImpl(text, placeholder, "");
}
public static InputComponentImpl of(String text) {
return new InputComponentImpl(text, "", "");
}
}

View file

@ -1,41 +0,0 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.common.form.impl.component;
import lombok.Getter;
import org.geysermc.common.form.component.ComponentType;
import org.geysermc.common.form.component.LabelComponent;
@Getter
public final class LabelComponentImpl extends Component implements LabelComponent {
private LabelComponentImpl(String text) {
super(ComponentType.LABEL, text);
}
public static LabelComponentImpl of(String text) {
return new LabelComponentImpl(text);
}
}

View file

@ -1,76 +0,0 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.common.form.impl.component;
import com.google.gson.annotations.SerializedName;
import lombok.Getter;
import org.geysermc.common.form.component.ComponentType;
import org.geysermc.common.form.component.SliderComponent;
@Getter
public final class SliderComponentImpl extends Component implements SliderComponent {
private final float min;
private final float max;
private final int step;
@SerializedName("default")
private final float defaultValue;
private SliderComponentImpl(String text, float min, float max, int step, float defaultValue) {
super(ComponentType.SLIDER, text);
this.min = min;
this.max = max;
this.step = step;
this.defaultValue = defaultValue;
}
public static SliderComponentImpl of(String text, float min, float max, int step,
float defaultValue) {
min = Math.max(min, 0f);
max = Math.max(max, min);
if (step < 1) {
step = 1;
}
if (defaultValue == -1f) {
defaultValue = (int) Math.floor(min + max / 2D);
}
return new SliderComponentImpl(text, min, max, step, defaultValue);
}
public static SliderComponentImpl of(String text, float min, float max, int step) {
return of(text, min, max, step, -1);
}
public static SliderComponentImpl of(String text, float min, float max, float defaultValue) {
return of(text, min, max, -1, defaultValue);
}
public static SliderComponentImpl of(String text, float min, float max) {
return of(text, min, max, -1, -1);
}
}

View file

@ -1,118 +0,0 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.common.form.impl.component;
import com.google.gson.annotations.SerializedName;
import lombok.Getter;
import org.geysermc.common.form.component.ComponentType;
import org.geysermc.common.form.component.StepSliderComponent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
@Getter
public final class StepSliderComponentImpl extends Component implements StepSliderComponent {
private final List<String> steps;
@SerializedName("default")
private final int defaultStep;
private StepSliderComponentImpl(String text, List<String> steps, int defaultStep) {
super(ComponentType.STEP_SLIDER, text);
this.steps = Collections.unmodifiableList(steps);
this.defaultStep = defaultStep;
}
public static StepSliderComponentImpl of(String text, List<String> steps, int defaultStep) {
if (text == null) {
text = "";
}
if (defaultStep >= steps.size() || defaultStep == -1) {
defaultStep = 0;
}
return new StepSliderComponentImpl(text, steps, defaultStep);
}
public static StepSliderComponentImpl of(String text, int defaultStep, String... steps) {
return of(text, Arrays.asList(steps), defaultStep);
}
public static StepSliderComponentImpl of(String text, String... steps) {
return of(text, 0, steps);
}
public static Builder builder() {
return new Builder();
}
public static Builder builder(String text) {
return builder().text(text);
}
public static final class Builder implements StepSliderComponent.Builder {
private final List<String> steps = new ArrayList<>();
private String text;
private int defaultStep;
public Builder text(String text) {
this.text = text;
return this;
}
public Builder step(String step, boolean defaultStep) {
steps.add(step);
if (defaultStep) {
this.defaultStep = steps.size() - 1;
}
return this;
}
public Builder step(String step) {
return step(step, false);
}
public Builder defaultStep(int defaultStep) {
this.defaultStep = defaultStep;
return this;
}
public StepSliderComponentImpl build() {
return of(text, steps, defaultStep);
}
public StepSliderComponentImpl translateAndBuild(Function<String, String> translator) {
for (int i = 0; i < steps.size(); i++) {
steps.set(i, translator.apply(steps.get(i)));
}
return of(translator.apply(text), steps, defaultStep);
}
}
}

View file

@ -1,52 +0,0 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.common.form.impl.component;
import com.google.gson.annotations.SerializedName;
import org.geysermc.common.form.component.ComponentType;
import org.geysermc.common.form.component.ToggleComponent;
public final class ToggleComponentImpl extends Component implements ToggleComponent {
@SerializedName("default")
private final boolean defaultValue;
private ToggleComponentImpl(String text, boolean defaultValue) {
super(ComponentType.TOGGLE, text);
this.defaultValue = defaultValue;
}
public static ToggleComponentImpl of(String text, boolean defaultValue) {
return new ToggleComponentImpl(text, defaultValue);
}
public static ToggleComponentImpl of(String text) {
return of(text, false);
}
public boolean getDefaultValue() {
return defaultValue;
}
}

View file

@ -1,207 +0,0 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.common.form.impl.response;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonPrimitive;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import org.geysermc.common.form.component.Component;
import org.geysermc.common.form.component.ComponentType;
import org.geysermc.common.form.impl.CustomFormImpl;
import org.geysermc.common.form.response.CustomFormResponse;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@Getter
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
@ToString
public final class CustomFormResponseImpl implements CustomFormResponse {
private static final Gson GSON = new Gson();
private static final CustomFormResponseImpl CLOSED =
new CustomFormResponseImpl(true, false, null, null);
private static final CustomFormResponseImpl INVALID =
new CustomFormResponseImpl(false, true, null, null);
private final boolean closed;
private final boolean invalid;
private final JsonArray responses;
private final List<ComponentType> componentTypes;
private int index = -1;
public static CustomFormResponseImpl closed() {
return CLOSED;
}
public static CustomFormResponseImpl invalid() {
return INVALID;
}
public static CustomFormResponseImpl of(CustomFormImpl form, String responseData) {
JsonArray responses = GSON.fromJson(responseData, JsonArray.class);
List<ComponentType> types = new ArrayList<>();
for (Component component : form.getContent()) {
types.add(component.getType());
}
return of(types, responses);
}
public static CustomFormResponseImpl of(List<ComponentType> componentTypes,
JsonArray responses) {
if (componentTypes.size() != responses.size()) {
return invalid();
}
return new CustomFormResponseImpl(false, false, responses,
Collections.unmodifiableList(componentTypes));
}
@Override
@SuppressWarnings("unchecked")
public <T> T next(boolean includeLabels) {
if (!hasNext()) {
return null;
}
while (++index < responses.size()) {
ComponentType type = componentTypes.get(index);
if (type == ComponentType.LABEL && !includeLabels) {
continue;
}
return (T) getDataFromType(type, index);
}
return null; // we don't have anything to check anymore
}
@Override
public <T> T next() {
return next(false);
}
@Override
public void skip(int amount) {
index += amount;
}
@Override
public void skip() {
skip(1);
}
@Override
public void index(int index) {
this.index = index;
}
@Override
public boolean hasNext() {
return responses.size() > index + 1;
}
@Override
public JsonPrimitive get(int index) {
try {
return responses.get(index).getAsJsonPrimitive();
} catch (IllegalStateException exception) {
wrongType(index, "a primitive");
return null;
}
}
@Override
public int getDropdown(int index) {
JsonPrimitive primitive = get(index);
if (!primitive.isNumber()) {
wrongType(index, "dropdown");
}
return primitive.getAsInt();
}
@Override
public String getInput(int index) {
JsonPrimitive primitive = get(index);
if (!primitive.isString()) {
wrongType(index, "input");
}
return primitive.getAsString();
}
@Override
public float getSlider(int index) {
JsonPrimitive primitive = get(index);
if (!primitive.isNumber()) {
wrongType(index, "slider");
}
return primitive.getAsFloat();
}
@Override
public int getStepSlide(int index) {
JsonPrimitive primitive = get(index);
if (!primitive.isNumber()) {
wrongType(index, "step slider");
}
return primitive.getAsInt();
}
@Override
public boolean getToggle(int index) {
JsonPrimitive primitive = get(index);
if (!primitive.isBoolean()) {
wrongType(index, "toggle");
}
return primitive.getAsBoolean();
}
private Object getDataFromType(ComponentType type, int index) {
switch (type) {
case DROPDOWN:
return getDropdown(index);
case INPUT:
return getInput(index);
case SLIDER:
return getSlider(index);
case STEP_SLIDER:
return getStepSlide(index);
case TOGGLE:
return getToggle(index);
default:
return null; // label e.g. is always null
}
}
private void wrongType(int index, String expected) {
throw new IllegalStateException(String.format(
"Expected %s on %s, got %s",
expected, index, responses.get(index).toString()));
}
}

View file

@ -1,62 +0,0 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.common.form.impl.response;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.geysermc.common.form.response.FormResponse;
import org.geysermc.common.form.response.ModalFormResponse;
@Getter
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public final class ModalFormResponseImpl implements ModalFormResponse {
private static final ModalFormResponseImpl CLOSED =
new ModalFormResponseImpl(true, false, -1, null);
private static final ModalFormResponseImpl INVALID =
new ModalFormResponseImpl(false, true, -1, null);
private final boolean closed;
private final boolean invalid;
private final int clickedButtonId;
private final String clickedButtonText;
public static ModalFormResponseImpl closed() {
return CLOSED;
}
public static ModalFormResponseImpl invalid() {
return INVALID;
}
public static ModalFormResponseImpl of(int clickedButtonId, String clickedButtonText) {
return new ModalFormResponseImpl(false, false, clickedButtonId, clickedButtonText);
}
public boolean getResult() {
return clickedButtonId == 0;
}
}

View file

@ -1,62 +0,0 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.common.form.impl.response;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.geysermc.common.form.component.ButtonComponent;
import org.geysermc.common.form.response.SimpleFormResponse;
@Getter
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public final class SimpleFormResponseImpl implements SimpleFormResponse {
private static final SimpleFormResponseImpl CLOSED =
new SimpleFormResponseImpl(true, false, -1, null);
private static final SimpleFormResponseImpl INVALID =
new SimpleFormResponseImpl(false, true, -1, null);
private final boolean closed;
private final boolean invalid;
private final int clickedButtonId;
private final ButtonComponent clickedButton;
public static SimpleFormResponseImpl closed() {
return CLOSED;
}
public static SimpleFormResponseImpl invalid() {
return INVALID;
}
public static SimpleFormResponseImpl of(int clickedButtonId, ButtonComponent clickedButton) {
return new SimpleFormResponseImpl(false, false, clickedButtonId, clickedButton);
}
public String getClickedButtonText() {
return clickedButton.getText();
}
}

View file

@ -1,129 +0,0 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.common.form.impl.util;
import com.google.gson.*;
import com.google.gson.reflect.TypeToken;
import org.geysermc.common.form.FormImage;
import org.geysermc.common.form.component.ButtonComponent;
import org.geysermc.common.form.component.Component;
import org.geysermc.common.form.component.ComponentType;
import org.geysermc.common.form.impl.CustomFormImpl;
import org.geysermc.common.form.impl.FormImpl;
import org.geysermc.common.form.impl.ModalFormImpl;
import org.geysermc.common.form.impl.SimpleFormImpl;
import org.geysermc.common.form.impl.component.ButtonComponentImpl;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
public final class FormAdaptor implements JsonDeserializer<FormImpl<?>>, JsonSerializer<FormImpl<?>> {
private static final Type LIST_BUTTON_TYPE =
new TypeToken<List<ButtonComponentImpl>>() {}.getType();
@Override
public FormImpl<?> deserialize(JsonElement jsonElement, Type typeOfT,
JsonDeserializationContext context)
throws JsonParseException {
if (!jsonElement.isJsonObject()) {
throw new JsonParseException("Form has to be a JsonObject");
}
JsonObject json = jsonElement.getAsJsonObject();
if (typeOfT == SimpleFormImpl.class) {
String title = json.get("title").getAsString();
String content = json.get("content").getAsString();
List<ButtonComponent> buttons = context
.deserialize(json.get("buttons"), LIST_BUTTON_TYPE);
return SimpleFormImpl.of(title, content, buttons);
}
if (typeOfT == ModalFormImpl.class) {
String title = json.get("title").getAsString();
String content = json.get("content").getAsString();
String button1 = json.get("button1").getAsString();
String button2 = json.get("button2").getAsString();
return ModalFormImpl.of(title, content, button1, button2);
}
if (typeOfT == CustomFormImpl.class) {
String title = json.get("title").getAsString();
FormImage icon = context.deserialize(json.get("icon"), FormImageImpl.class);
List<Component> content = new ArrayList<>();
JsonArray contentArray = json.getAsJsonArray("content");
for (JsonElement contentElement : contentArray) {
String typeName = contentElement.getAsJsonObject().get("type").getAsString();
ComponentType type = ComponentType.getByName(typeName);
if (type == null) {
throw new JsonParseException("Failed to find Component type " + typeName);
}
content.add(context.deserialize(contentElement, type.getComponentClass()));
}
return CustomFormImpl.of(title, icon, content);
}
return null;
}
@Override
public JsonElement serialize(FormImpl src, Type typeOfSrc, JsonSerializationContext context) {
JsonObject result = new JsonObject();
result.add("type", context.serialize(src.getType()));
if (typeOfSrc == SimpleFormImpl.class) {
SimpleFormImpl form = (SimpleFormImpl) src;
result.addProperty("title", form.getTitle());
result.addProperty("content", form.getContent());
result.add("buttons", context.serialize(form.getButtons(), LIST_BUTTON_TYPE));
return result;
}
if (typeOfSrc == ModalFormImpl.class) {
ModalFormImpl form = (ModalFormImpl) src;
result.addProperty("title", form.getTitle());
result.addProperty("content", form.getContent());
result.addProperty("button1", form.getButton1());
result.addProperty("button2", form.getButton2());
return result;
}
if (typeOfSrc == CustomFormImpl.class) {
CustomFormImpl form = (CustomFormImpl) src;
result.addProperty("title", form.getTitle());
result.add("icon", context.serialize(form.getIcon()));
result.add("content", context.serialize(form.getContent()));
return result;
}
return null;
}
}

View file

@ -1,46 +0,0 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.common.form.impl.util;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.geysermc.common.form.FormImage;
@Getter
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public final class FormImageImpl implements FormImage {
private final Type type;
private final String data;
public static FormImageImpl of(Type type, String data) {
return new FormImageImpl(type, data);
}
public static FormImageImpl of(String type, String data) {
return of(Type.getByName(type), data);
}
}

View file

@ -1,62 +0,0 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.common.form.response;
import com.google.gson.JsonArray;
import com.google.gson.JsonPrimitive;
import org.geysermc.common.form.component.ComponentType;
import java.util.List;
public interface CustomFormResponse extends FormResponse {
JsonArray getResponses();
List<ComponentType> getComponentTypes();
<T> T next(boolean includeLabels);
<T> T next();
void skip(int amount);
void skip();
void index(int index);
boolean hasNext();
JsonPrimitive get(int index);
int getDropdown(int index);
String getInput(int index);
float getSlider(int index);
int getStepSlide(int index);
boolean getToggle(int index);
}

View file

@ -1,35 +0,0 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.common.form.response;
public interface FormResponse {
boolean isClosed();
boolean isInvalid();
default boolean isCorrect() {
return !isClosed() && !isInvalid();
}
}

View file

@ -1,34 +0,0 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.common.form.response;
public interface ModalFormResponse extends FormResponse {
int getClickedButtonId();
String getClickedButtonText();
boolean getResult();
}

View file

@ -1,34 +0,0 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.common.form.response;
import org.geysermc.common.form.component.ButtonComponent;
public interface SimpleFormResponse extends FormResponse {
int getClickedButtonId();
ButtonComponent getClickedButton();
}

View file

@ -15,7 +15,6 @@
<groupId>org.geysermc</groupId> <groupId>org.geysermc</groupId>
<artifactId>common</artifactId> <artifactId>common</artifactId>
<version>1.2.0-SNAPSHOT</version> <version>1.2.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId> <groupId>com.fasterxml.jackson.dataformat</groupId>

View file

@ -57,8 +57,6 @@ import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap;
import lombok.Getter; import lombok.Getter;
import lombok.NonNull; import lombok.NonNull;
import lombok.Setter; import lombok.Setter;
import org.geysermc.common.form.Form;
import org.geysermc.common.form.FormBuilder;
import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.command.CommandSender; import org.geysermc.connector.command.CommandSender;
import org.geysermc.connector.common.AuthType; import org.geysermc.connector.common.AuthType;
@ -76,6 +74,8 @@ import org.geysermc.connector.network.translators.chat.MessageTranslator;
import org.geysermc.connector.network.translators.inventory.EnchantmentInventoryTranslator; import org.geysermc.connector.network.translators.inventory.EnchantmentInventoryTranslator;
import org.geysermc.connector.network.translators.item.ItemRegistry; import org.geysermc.connector.network.translators.item.ItemRegistry;
import org.geysermc.connector.utils.*; import org.geysermc.connector.utils.*;
import org.geysermc.cumulus.Form;
import org.geysermc.cumulus.util.FormBuilder;
import org.geysermc.floodgate.crypto.FloodgateCipher; import org.geysermc.floodgate.crypto.FloodgateCipher;
import org.geysermc.floodgate.util.BedrockData; import org.geysermc.floodgate.util.BedrockData;
@ -607,7 +607,7 @@ public class GeyserSession implements CommandSender {
return this.upstream.getAddress(); return this.upstream.getAddress();
} }
public void sendForm(Form<?> form) { public void sendForm(Form form) {
formCache.showForm(form); formCache.showForm(form);
} }

View file

@ -31,8 +31,8 @@ import com.nukkitx.protocol.bedrock.packet.NetworkStackLatencyPacket;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.geysermc.common.form.Form;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.cumulus.Form;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
@ -41,16 +41,16 @@ import java.util.function.Consumer;
@RequiredArgsConstructor @RequiredArgsConstructor
public class FormCache { public class FormCache {
private final AtomicInteger formId = new AtomicInteger(0); private final AtomicInteger formId = new AtomicInteger(0);
private final Int2ObjectMap<Form<?>> forms = new Int2ObjectOpenHashMap<>(); private final Int2ObjectMap<Form> forms = new Int2ObjectOpenHashMap<>();
private final GeyserSession session; private final GeyserSession session;
public int addForm(Form<?> form) { public int addForm(Form form) {
int windowId = formId.getAndIncrement(); int windowId = formId.getAndIncrement();
forms.put(windowId, form); forms.put(windowId, form);
return windowId; return windowId;
} }
public int showForm(Form<?> form) { public int showForm(Form form) {
int windowId = addForm(form); int windowId = addForm(form);
ModalFormRequestPacket formRequestPacket = new ModalFormRequestPacket(); ModalFormRequestPacket formRequestPacket = new ModalFormRequestPacket();
@ -62,15 +62,15 @@ public class FormCache {
NetworkStackLatencyPacket latencyPacket = new NetworkStackLatencyPacket(); NetworkStackLatencyPacket latencyPacket = new NetworkStackLatencyPacket();
latencyPacket.setFromServer(true); latencyPacket.setFromServer(true);
latencyPacket.setTimestamp(-System.currentTimeMillis()); latencyPacket.setTimestamp(-System.currentTimeMillis());
session.getConnector().getGeneralThreadPool().schedule(() -> session.getConnector().getGeneralThreadPool().schedule(
session.sendUpstreamPacket(latencyPacket), () -> session.sendUpstreamPacket(latencyPacket),
500, TimeUnit.MILLISECONDS); 500, TimeUnit.MILLISECONDS);
return windowId; return windowId;
} }
public void handleResponse(ModalFormResponsePacket response) { public void handleResponse(ModalFormResponsePacket response) {
Form<?> form = forms.get(response.getFormId()); Form form = forms.get(response.getFormId());
if (form == null) { if (form == null) {
return; return;
} }

View file

@ -27,15 +27,14 @@ package org.geysermc.connector.network.translators.bedrock;
import com.nukkitx.protocol.bedrock.packet.ServerSettingsRequestPacket; import com.nukkitx.protocol.bedrock.packet.ServerSettingsRequestPacket;
import com.nukkitx.protocol.bedrock.packet.ServerSettingsResponsePacket; import com.nukkitx.protocol.bedrock.packet.ServerSettingsResponsePacket;
import org.geysermc.common.form.CustomForm;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator; import org.geysermc.connector.network.translators.Translator;
import org.geysermc.connector.utils.SettingsUtils; import org.geysermc.connector.utils.SettingsUtils;
import org.geysermc.cumulus.CustomForm;
@Translator(packet = ServerSettingsRequestPacket.class) @Translator(packet = ServerSettingsRequestPacket.class)
public class BedrockServerSettingsRequestTranslator extends PacketTranslator<ServerSettingsRequestPacket> { public class BedrockServerSettingsRequestTranslator extends PacketTranslator<ServerSettingsRequestPacket> {
@Override @Override
public void translate(ServerSettingsRequestPacket packet, GeyserSession session) { public void translate(ServerSettingsRequestPacket packet, GeyserSession session) {
CustomForm window = SettingsUtils.buildForm(session); CustomForm window = SettingsUtils.buildForm(session);

View file

@ -28,13 +28,13 @@ package org.geysermc.connector.network.translators.java;
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientPluginMessagePacket; import com.github.steveice10.mc.protocol.packet.ingame.client.ClientPluginMessagePacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerPluginMessagePacket; import com.github.steveice10.mc.protocol.packet.ingame.server.ServerPluginMessagePacket;
import com.google.common.base.Charsets; import com.google.common.base.Charsets;
import org.geysermc.common.form.Form;
import org.geysermc.common.form.FormType;
import org.geysermc.common.form.Forms;
import org.geysermc.connector.common.AuthType; import org.geysermc.connector.common.AuthType;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator; import org.geysermc.connector.network.translators.Translator;
import org.geysermc.cumulus.Form;
import org.geysermc.cumulus.Forms;
import org.geysermc.cumulus.util.FormType;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -63,7 +63,7 @@ public class JavaPluginMessageTranslator extends PacketTranslator<ServerPluginMe
String dataString = new String(data, 3, data.length - 3, Charsets.UTF_8); String dataString = new String(data, 3, data.length - 3, Charsets.UTF_8);
Form<?> form = Forms.fromJson(dataString, type.getTypeClass()); Form form = Forms.fromJson(dataString, type);
form.setResponseHandler(response -> { form.setResponseHandler(response -> {
byte[] raw = response.getBytes(StandardCharsets.UTF_8); byte[] raw = response.getBytes(StandardCharsets.UTF_8);
byte[] finalData = new byte[raw.length + 2]; byte[] finalData = new byte[raw.length + 2];

View file

@ -34,14 +34,14 @@ import com.nukkitx.network.util.Preconditions;
import com.nukkitx.protocol.bedrock.packet.LoginPacket; import com.nukkitx.protocol.bedrock.packet.LoginPacket;
import com.nukkitx.protocol.bedrock.packet.ServerToClientHandshakePacket; import com.nukkitx.protocol.bedrock.packet.ServerToClientHandshakePacket;
import com.nukkitx.protocol.bedrock.util.EncryptionUtils; import com.nukkitx.protocol.bedrock.util.EncryptionUtils;
import org.geysermc.common.form.CustomForm;
import org.geysermc.common.form.SimpleForm;
import org.geysermc.common.form.response.CustomFormResponse;
import org.geysermc.common.form.response.SimpleFormResponse;
import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.session.auth.AuthData; import org.geysermc.connector.network.session.auth.AuthData;
import org.geysermc.connector.network.session.auth.BedrockClientData; import org.geysermc.connector.network.session.auth.BedrockClientData;
import org.geysermc.cumulus.CustomForm;
import org.geysermc.cumulus.SimpleForm;
import org.geysermc.cumulus.response.CustomFormResponse;
import org.geysermc.cumulus.response.SimpleFormResponse;
import javax.crypto.SecretKey; import javax.crypto.SecretKey;
import java.io.IOException; import java.io.IOException;

View file

@ -27,12 +27,12 @@ package org.geysermc.connector.utils;
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode; import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
import com.github.steveice10.mc.protocol.data.game.setting.Difficulty; import com.github.steveice10.mc.protocol.data.game.setting.Difficulty;
import org.geysermc.common.form.CustomForm;
import org.geysermc.common.form.component.DropdownComponent;
import org.geysermc.common.form.response.CustomFormResponse;
import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.world.WorldManager; import org.geysermc.connector.network.translators.world.WorldManager;
import org.geysermc.cumulus.CustomForm;
import org.geysermc.cumulus.component.DropdownComponent;
import org.geysermc.cumulus.response.CustomFormResponse;
public class SettingsUtils { public class SettingsUtils {

View file

@ -28,11 +28,11 @@ package org.geysermc.connector.utils;
import com.github.steveice10.mc.protocol.data.MagicValues; import com.github.steveice10.mc.protocol.data.MagicValues;
import com.github.steveice10.mc.protocol.data.game.entity.type.EntityType; import com.github.steveice10.mc.protocol.data.game.entity.type.EntityType;
import com.github.steveice10.mc.protocol.data.game.statistic.*; import com.github.steveice10.mc.protocol.data.game.statistic.*;
import org.geysermc.common.form.SimpleForm;
import org.geysermc.common.form.response.SimpleFormResponse;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.item.ItemRegistry; import org.geysermc.connector.network.translators.item.ItemRegistry;
import org.geysermc.connector.network.translators.world.block.BlockTranslator; import org.geysermc.connector.network.translators.world.block.BlockTranslator;
import org.geysermc.cumulus.SimpleForm;
import org.geysermc.cumulus.response.SimpleFormResponse;
import java.util.Map; import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;