labelResponses;
-}
diff --git a/common/src/main/java/org/geysermc/common/window/response/FormResponseData.java b/common/src/main/java/org/geysermc/common/window/response/FormResponseData.java
deleted file mode 100644
index fd40be0fb..000000000
--- a/common/src/main/java/org/geysermc/common/window/response/FormResponseData.java
+++ /dev/null
@@ -1,37 +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.window.response;
-
-import lombok.AllArgsConstructor;
-import lombok.Getter;
-
-@AllArgsConstructor
-@Getter
-public class FormResponseData {
-
- private int elementID;
- private String elementContent;
-}
diff --git a/common/src/main/java/org/geysermc/common/window/response/ModalFormResponse.java b/common/src/main/java/org/geysermc/common/window/response/ModalFormResponse.java
deleted file mode 100644
index e1a14039d..000000000
--- a/common/src/main/java/org/geysermc/common/window/response/ModalFormResponse.java
+++ /dev/null
@@ -1,38 +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.window.response;
-
-import lombok.AllArgsConstructor;
-import lombok.Getter;
-import org.geysermc.common.window.response.FormResponse;
-
-@Getter
-@AllArgsConstructor
-public class ModalFormResponse implements FormResponse {
-
- private int clickedButtonId;
- private String clickedButtonText;
-}
diff --git a/common/src/main/java/org/geysermc/common/window/response/SimpleFormResponse.java b/common/src/main/java/org/geysermc/common/window/response/SimpleFormResponse.java
deleted file mode 100644
index e80d58e78..000000000
--- a/common/src/main/java/org/geysermc/common/window/response/SimpleFormResponse.java
+++ /dev/null
@@ -1,39 +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.window.response;
-
-import lombok.AllArgsConstructor;
-import lombok.Getter;
-import org.geysermc.common.window.button.FormButton;
-import org.geysermc.common.window.response.FormResponse;
-
-@Getter
-@AllArgsConstructor
-public class SimpleFormResponse implements FormResponse {
-
- private int clickedButtonId;
- private FormButton clickedButton;
-}
diff --git a/connector/src/main/java/org/geysermc/connector/network/UpstreamPacketHandler.java b/connector/src/main/java/org/geysermc/connector/network/UpstreamPacketHandler.java
index 7e97d4298..9f6a88e18 100644
--- a/connector/src/main/java/org/geysermc/connector/network/UpstreamPacketHandler.java
+++ b/connector/src/main/java/org/geysermc/connector/network/UpstreamPacketHandler.java
@@ -39,7 +39,6 @@ import org.geysermc.connector.utils.LoginEncryptionUtils;
import org.geysermc.connector.utils.MathUtils;
import org.geysermc.connector.utils.ResourcePack;
import org.geysermc.connector.utils.ResourcePackManifest;
-import org.geysermc.connector.utils.SettingsUtils;
import java.io.FileInputStream;
import java.io.InputStream;
@@ -139,11 +138,8 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
@Override
public boolean handle(ModalFormResponsePacket packet) {
- if (packet.getFormId() == SettingsUtils.SETTINGS_FORM_ID) {
- return SettingsUtils.handleSettingsForm(session, packet.getFormData());
- }
-
- return LoginEncryptionUtils.authenticateFromForm(session, connector, packet.getFormId(), packet.getFormData());
+ session.getFormCache().handleResponse(packet);
+ return true;
}
private boolean couldLoginUserByName(String bedrockUsername) {
@@ -170,7 +166,7 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
if (!session.isLoggedIn() && !session.isLoggingIn() && session.getConnector().getAuthType() == AuthType.ONLINE) {
// TODO it is safer to key authentication on something that won't change (UUID, not username)
if (!couldLoginUserByName(session.getAuthData().getName())) {
- LoginEncryptionUtils.showLoginWindow(session);
+ LoginEncryptionUtils.buildAndShowLoginWindow(session);
}
// else we were able to log the user in
}
diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java
index 42c2f2437..ec8c7f0ee 100644
--- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java
+++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java
@@ -55,8 +55,7 @@ import it.unimi.dsi.fastutil.objects.Object2LongMap;
import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap;
import lombok.Getter;
import lombok.Setter;
-import org.geysermc.common.window.CustomFormWindow;
-import org.geysermc.common.window.FormWindow;
+import org.geysermc.common.form.Form;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.command.CommandSender;
import org.geysermc.connector.common.AuthType;
@@ -101,7 +100,7 @@ public class GeyserSession implements CommandSender {
private EntityCache entityCache;
private InventoryCache inventoryCache;
private WorldCache worldCache;
- private WindowCache windowCache;
+ private FormCache formCache;
@Setter
private TeleportCache teleportCache;
@@ -192,9 +191,6 @@ public class GeyserSession implements CommandSender {
private boolean reducedDebugInfo = false;
- @Setter
- private CustomFormWindow settingsForm;
-
/**
* The op permission level set by the server
*/
@@ -239,7 +235,7 @@ public class GeyserSession implements CommandSender {
/**
* Stores the last text inputted into a sign.
- *
+ *
* Bedrock sends packets every time you update the sign, Java only wants the final packet.
* Until we determine that the user has finished editing, we save the sign's current status.
*/
@@ -256,7 +252,7 @@ public class GeyserSession implements CommandSender {
this.entityCache = new EntityCache(this);
this.inventoryCache = new InventoryCache(this);
this.worldCache = new WorldCache(this);
- this.windowCache = new WindowCache(this);
+ this.formCache = new FormCache(this);
this.playerEntity = new PlayerEntity(new GameProfile(UUID.randomUUID(), "unknown"), 1, 1, Vector3f.ZERO, Vector3f.ZERO, Vector3f.ZERO);
this.inventory = new PlayerInventory();
@@ -497,7 +493,7 @@ public class GeyserSession implements CommandSender {
this.entityCache = null;
this.worldCache = null;
this.inventoryCache = null;
- this.windowCache = null;
+ this.formCache = null;
closed = true;
}
@@ -533,10 +529,6 @@ public class GeyserSession implements CommandSender {
return false;
}
- public void sendForm(FormWindow window, int id) {
- windowCache.showWindow(window, id);
- }
-
public void setRenderDistance(int renderDistance) {
renderDistance = GenericMath.ceil(++renderDistance * MathUtils.SQRT_OF_TWO); //square to circle
if (renderDistance > 32) renderDistance = 32; // <3 u ViaVersion but I don't like crashing clients x)
@@ -551,8 +543,12 @@ public class GeyserSession implements CommandSender {
return this.upstream.getAddress();
}
- public void sendForm(FormWindow window) {
- windowCache.showWindow(window);
+ public void sendForm(Form form) {
+ formCache.showForm(form);
+ }
+
+ public void sendForm(Form.Builder, ?> formBuilder) {
+ formCache.showForm(formBuilder.build());
}
private void startGame() {
@@ -678,7 +674,7 @@ public class GeyserSession implements CommandSender {
* Send a gamerule value to the client
*
* @param gameRule The gamerule to send
- * @param value The value of the gamerule
+ * @param value The value of the gamerule
*/
public void sendGameRule(String gameRule, Object value) {
GameRulesChangedPacket gameRulesChangedPacket = new GameRulesChangedPacket();
diff --git a/connector/src/main/java/org/geysermc/connector/network/session/cache/WindowCache.java b/connector/src/main/java/org/geysermc/connector/network/session/cache/FormCache.java
similarity index 56%
rename from connector/src/main/java/org/geysermc/connector/network/session/cache/WindowCache.java
rename to connector/src/main/java/org/geysermc/connector/network/session/cache/FormCache.java
index 15b9a7705..20ade2869 100644
--- a/connector/src/main/java/org/geysermc/connector/network/session/cache/WindowCache.java
+++ b/connector/src/main/java/org/geysermc/connector/network/session/cache/FormCache.java
@@ -26,56 +26,54 @@
package org.geysermc.connector.network.session.cache;
import com.nukkitx.protocol.bedrock.packet.ModalFormRequestPacket;
-
+import com.nukkitx.protocol.bedrock.packet.ModalFormResponsePacket;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
-
-import lombok.Getter;
-
-import org.geysermc.common.window.FormWindow;
+import lombok.RequiredArgsConstructor;
+import org.geysermc.common.form.Form;
import org.geysermc.connector.network.session.GeyserSession;
-public class WindowCache {
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Consumer;
- private GeyserSession session;
+@RequiredArgsConstructor
+public class FormCache {
+ private final AtomicInteger formId = new AtomicInteger(0);
+ private final Int2ObjectMap