mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Update Geyser to use the latest features of Cumulus 1.1
This commit is contained in:
parent
f702fb45b4
commit
3011d89db6
9 changed files with 82 additions and 124 deletions
|
@ -20,7 +20,7 @@
|
|||
<dependency>
|
||||
<groupId>org.geysermc.cumulus</groupId>
|
||||
<artifactId>cumulus</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<version>1.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
|
|
|
@ -76,7 +76,7 @@ import lombok.Getter;
|
|||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import org.geysermc.common.PlatformType;
|
||||
import org.geysermc.cumulus.Form;
|
||||
import org.geysermc.cumulus.form.Form;
|
||||
import org.geysermc.cumulus.util.FormBuilder;
|
||||
import org.geysermc.floodgate.crypto.FloodgateCipher;
|
||||
import org.geysermc.floodgate.util.BedrockData;
|
||||
|
@ -1183,7 +1183,7 @@ public class GeyserSession implements GeyserConnection, CommandSender {
|
|||
formCache.showForm(form);
|
||||
}
|
||||
|
||||
public void sendForm(FormBuilder<?, ?> formBuilder) {
|
||||
public void sendForm(FormBuilder<?, ?, ?> formBuilder) {
|
||||
formCache.showForm(formBuilder.build());
|
||||
}
|
||||
|
||||
|
|
|
@ -29,13 +29,12 @@ import com.github.steveice10.mc.protocol.data.game.advancement.Advancement;
|
|||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundSeenAdvancementsPacket;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
import org.geysermc.geyser.translator.text.MessageTranslator;
|
||||
import org.geysermc.cumulus.form.SimpleForm;
|
||||
import org.geysermc.geyser.level.GeyserAdvancement;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
import org.geysermc.geyser.text.GeyserLocale;
|
||||
import org.geysermc.geyser.text.MinecraftLocale;
|
||||
import org.geysermc.cumulus.SimpleForm;
|
||||
import org.geysermc.cumulus.response.SimpleFormResponse;
|
||||
import org.geysermc.geyser.translator.text.MessageTranslator;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -87,18 +86,13 @@ public class AdvancementsCache {
|
|||
builder.content("advancements.empty");
|
||||
}
|
||||
|
||||
builder.responseHandler((form, responseData) -> {
|
||||
SimpleFormResponse response = form.parseResponse(responseData);
|
||||
if (!response.isCorrect()) {
|
||||
return;
|
||||
}
|
||||
|
||||
builder.validResultHandler((form, response) -> {
|
||||
String id = "";
|
||||
|
||||
int advancementIndex = 0;
|
||||
for (Map.Entry<String, GeyserAdvancement> advancement : storedAdvancements.entrySet()) {
|
||||
if (advancement.getValue().getParentId() == null) { // Root advancement
|
||||
if (advancementIndex == response.getClickedButtonId()) {
|
||||
if (advancementIndex == response.clickedButtonId()) {
|
||||
id = advancement.getKey();
|
||||
break;
|
||||
} else {
|
||||
|
@ -148,21 +142,18 @@ public class AdvancementsCache {
|
|||
|
||||
builder.button(GeyserLocale.getPlayerLocaleString("gui.back", language));
|
||||
|
||||
builder.responseHandler((form, responseData) -> {
|
||||
SimpleFormResponse response = form.parseResponse(responseData);
|
||||
if (!response.isCorrect()) {
|
||||
// Indicate that we have closed the current advancement tab
|
||||
session.sendDownstreamPacket(new ServerboundSeenAdvancementsPacket());
|
||||
return;
|
||||
}
|
||||
builder.closedResultHandler(form -> {
|
||||
// Indicate that we have closed the current advancement tab
|
||||
session.sendDownstreamPacket(new ServerboundSeenAdvancementsPacket());
|
||||
|
||||
}).validResultHandler((form, response) -> {
|
||||
GeyserAdvancement advancement = null;
|
||||
int advancementIndex = 0;
|
||||
// Loop around to find the advancement that the client pressed
|
||||
for (GeyserAdvancement advancementEntry : storedAdvancements.values()) {
|
||||
if (advancementEntry.getParentId() != null &&
|
||||
currentAdvancementCategoryId.equals(advancementEntry.getRootId(this))) {
|
||||
if (advancementIndex == response.getClickedButtonId()) {
|
||||
if (advancementIndex == response.clickedButtonId()) {
|
||||
advancement = advancementEntry;
|
||||
break;
|
||||
} else {
|
||||
|
@ -219,12 +210,7 @@ public class AdvancementsCache {
|
|||
.title(MessageTranslator.convertMessage(advancement.getDisplayData().getTitle()))
|
||||
.content(content)
|
||||
.button(GeyserLocale.getPlayerLocaleString("gui.back", language))
|
||||
.responseHandler((form, responseData) -> {
|
||||
SimpleFormResponse response = form.parseResponse(responseData);
|
||||
if (response.isCorrect()) {
|
||||
buildAndShowListForm();
|
||||
}
|
||||
})
|
||||
.validResultHandler((form, response) -> buildAndShowListForm())
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -31,17 +31,18 @@ import com.nukkitx.protocol.bedrock.packet.NetworkStackLatencyPacket;
|
|||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.geysermc.cumulus.form.Form;
|
||||
import org.geysermc.cumulus.form.SimpleForm;
|
||||
import org.geysermc.cumulus.form.impl.FormDefinitions;
|
||||
import org.geysermc.geyser.GeyserImpl;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
import org.geysermc.cumulus.Form;
|
||||
import org.geysermc.cumulus.SimpleForm;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class FormCache {
|
||||
private final FormDefinitions formDefinitions = FormDefinitions.instance();
|
||||
private final AtomicInteger formId = new AtomicInteger(0);
|
||||
private final Int2ObjectMap<Form> forms = new Int2ObjectOpenHashMap<>();
|
||||
private final GeyserSession session;
|
||||
|
@ -61,9 +62,11 @@ public class FormCache {
|
|||
}
|
||||
|
||||
private void sendForm(int windowId, Form form) {
|
||||
String jsonData = formDefinitions.codecFor(form).jsonData(form);
|
||||
|
||||
ModalFormRequestPacket formRequestPacket = new ModalFormRequestPacket();
|
||||
formRequestPacket.setFormId(windowId);
|
||||
formRequestPacket.setFormData(form.getJsonData());
|
||||
formRequestPacket.setFormData(jsonData);
|
||||
session.sendUpstreamPacket(formRequestPacket);
|
||||
|
||||
// Hack to fix the (url) image loading bug
|
||||
|
@ -88,17 +91,11 @@ public class FormCache {
|
|||
return;
|
||||
}
|
||||
|
||||
Consumer<String> responseConsumer = form.getResponseHandler();
|
||||
if (responseConsumer != null) {
|
||||
try {
|
||||
responseConsumer.accept(response.getFormData());
|
||||
} catch (Exception e) {
|
||||
GeyserImpl.getInstance().getLogger().error("Error while processing form response!", e);
|
||||
}
|
||||
try {
|
||||
formDefinitions.definitionFor(form)
|
||||
.handleFormResponse(form, response.getFormData());
|
||||
} catch (Exception e) {
|
||||
GeyserImpl.getInstance().getLogger().error("Error while processing form response!", e);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean removeWindow(int id) {
|
||||
return forms.remove(id) != null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,26 +27,31 @@ package org.geysermc.geyser.translator.protocol.bedrock;
|
|||
|
||||
import com.nukkitx.protocol.bedrock.packet.ServerSettingsRequestPacket;
|
||||
import com.nukkitx.protocol.bedrock.packet.ServerSettingsResponsePacket;
|
||||
import org.geysermc.cumulus.form.CustomForm;
|
||||
import org.geysermc.cumulus.form.impl.FormDefinitions;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
import org.geysermc.geyser.translator.protocol.PacketTranslator;
|
||||
import org.geysermc.geyser.translator.protocol.Translator;
|
||||
import org.geysermc.geyser.util.SettingsUtils;
|
||||
import org.geysermc.cumulus.CustomForm;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Translator(packet = ServerSettingsRequestPacket.class)
|
||||
public class BedrockServerSettingsRequestTranslator extends PacketTranslator<ServerSettingsRequestPacket> {
|
||||
private final FormDefinitions formDefinitions = FormDefinitions.instance();
|
||||
|
||||
@Override
|
||||
public void translate(GeyserSession session, ServerSettingsRequestPacket packet) {
|
||||
CustomForm window = SettingsUtils.buildForm(session);
|
||||
int windowId = session.getFormCache().addForm(window);
|
||||
CustomForm form = SettingsUtils.buildForm(session);
|
||||
int formId = session.getFormCache().addForm(form);
|
||||
|
||||
String jsonData = formDefinitions.codecFor(form).jsonData(form);
|
||||
|
||||
// Fixes https://bugs.mojang.com/browse/MCPE-94012 because of the delay
|
||||
session.scheduleInEventLoop(() -> {
|
||||
ServerSettingsResponsePacket serverSettingsResponsePacket = new ServerSettingsResponsePacket();
|
||||
serverSettingsResponsePacket.setFormData(window.getJsonData());
|
||||
serverSettingsResponsePacket.setFormId(windowId);
|
||||
serverSettingsResponsePacket.setFormData(jsonData);
|
||||
serverSettingsResponsePacket.setFormId(formId);
|
||||
session.sendUpstreamPacket(serverSettingsResponsePacket);
|
||||
}, 1, TimeUnit.SECONDS);
|
||||
}
|
||||
|
|
|
@ -25,19 +25,19 @@
|
|||
|
||||
package org.geysermc.geyser.translator.protocol.java;
|
||||
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundCustomPayloadPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundCustomPayloadPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundCustomPayloadPacket;
|
||||
import com.google.common.base.Charsets;
|
||||
import com.nukkitx.protocol.bedrock.packet.TransferPacket;
|
||||
import org.geysermc.cumulus.Forms;
|
||||
import org.geysermc.cumulus.form.Form;
|
||||
import org.geysermc.cumulus.util.FormType;
|
||||
import org.geysermc.geyser.GeyserImpl;
|
||||
import org.geysermc.geyser.GeyserLogger;
|
||||
import org.geysermc.geyser.session.auth.AuthType;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
import org.geysermc.geyser.session.auth.AuthType;
|
||||
import org.geysermc.geyser.translator.protocol.PacketTranslator;
|
||||
import org.geysermc.geyser.translator.protocol.Translator;
|
||||
import org.geysermc.cumulus.Form;
|
||||
import org.geysermc.cumulus.Forms;
|
||||
import org.geysermc.cumulus.util.FormType;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
|
@ -68,8 +68,7 @@ public class JavaCustomPayloadTranslator extends PacketTranslator<ClientboundCus
|
|||
|
||||
String dataString = new String(data, 3, data.length - 3, Charsets.UTF_8);
|
||||
|
||||
Form form = Forms.fromJson(dataString, type);
|
||||
form.setResponseHandler(response -> {
|
||||
Form form = Forms.fromJson(dataString, type, (ignored, response) -> {
|
||||
byte[] raw = response.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] finalData = new byte[raw.length + 2];
|
||||
|
||||
|
|
|
@ -37,17 +37,15 @@ import com.nukkitx.network.util.Preconditions;
|
|||
import com.nukkitx.protocol.bedrock.packet.LoginPacket;
|
||||
import com.nukkitx.protocol.bedrock.packet.ServerToClientHandshakePacket;
|
||||
import com.nukkitx.protocol.bedrock.util.EncryptionUtils;
|
||||
import org.geysermc.cumulus.form.CustomForm;
|
||||
import org.geysermc.cumulus.form.ModalForm;
|
||||
import org.geysermc.cumulus.form.SimpleForm;
|
||||
import org.geysermc.cumulus.response.result.ResultType;
|
||||
import org.geysermc.geyser.GeyserImpl;
|
||||
import org.geysermc.geyser.configuration.GeyserConfiguration;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
import org.geysermc.geyser.session.auth.AuthData;
|
||||
import org.geysermc.geyser.session.auth.BedrockClientData;
|
||||
import org.geysermc.cumulus.CustomForm;
|
||||
import org.geysermc.cumulus.ModalForm;
|
||||
import org.geysermc.cumulus.SimpleForm;
|
||||
import org.geysermc.cumulus.response.CustomFormResponse;
|
||||
import org.geysermc.cumulus.response.ModalFormResponse;
|
||||
import org.geysermc.cumulus.response.SimpleFormResponse;
|
||||
import org.geysermc.geyser.text.GeyserLocale;
|
||||
|
||||
import javax.crypto.SecretKey;
|
||||
|
@ -232,26 +230,24 @@ public class LoginEncryptionUtils {
|
|||
.optionalButton("geyser.auth.login.form.notice.btn_login.mojang", isPasswordAuthEnabled)
|
||||
.button("geyser.auth.login.form.notice.btn_login.microsoft")
|
||||
.button("geyser.auth.login.form.notice.btn_disconnect")
|
||||
.responseHandler((form, responseData) -> {
|
||||
SimpleFormResponse response = form.parseResponse(responseData);
|
||||
if (!response.isCorrect()) {
|
||||
buildAndShowLoginWindow(session);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isPasswordAuthEnabled && response.getClickedButtonId() == 0) {
|
||||
.resultHandler(
|
||||
(form, result) -> buildAndShowLoginWindow(session),
|
||||
ResultType.CLOSED, ResultType.INVALID
|
||||
)
|
||||
.validResultHandler((form, response) -> {
|
||||
if (isPasswordAuthEnabled && response.clickedButtonId() == 0) {
|
||||
session.setMicrosoftAccount(false);
|
||||
buildAndShowLoginDetailsWindow(session);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isPasswordAuthEnabled && response.getClickedButtonId() == 1) {
|
||||
if (isPasswordAuthEnabled && response.clickedButtonId() == 1) {
|
||||
session.setMicrosoftAccount(true);
|
||||
buildAndShowMicrosoftAuthenticationWindow(session);
|
||||
return;
|
||||
}
|
||||
|
||||
if (response.getClickedButtonId() == 0) {
|
||||
if (response.clickedButtonId() == 0) {
|
||||
// Just show the OAuth code
|
||||
session.authenticateWithMicrosoftCode();
|
||||
return;
|
||||
|
@ -269,15 +265,11 @@ public class LoginEncryptionUtils {
|
|||
.label("geyser.auth.login.form.details.desc")
|
||||
.input("geyser.auth.login.form.details.email", "account@geysermc.org", "")
|
||||
.input("geyser.auth.login.form.details.pass", "123456", "")
|
||||
.responseHandler((form, responseData) -> {
|
||||
CustomFormResponse response = form.parseResponse(responseData);
|
||||
if (!response.isCorrect()) {
|
||||
buildAndShowLoginDetailsWindow(session);
|
||||
return;
|
||||
}
|
||||
|
||||
session.authenticate(response.next(), response.next());
|
||||
}));
|
||||
.resultHandler(
|
||||
(form, result) -> buildAndShowLoginDetailsWindow(session),
|
||||
ResultType.CLOSED, ResultType.INVALID
|
||||
)
|
||||
.validResultHandler((form, response) -> session.authenticate(response.next(), response.next())));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -291,16 +283,14 @@ public class LoginEncryptionUtils {
|
|||
.button("geyser.auth.login.method.browser")
|
||||
.button("geyser.auth.login.method.password")
|
||||
.button("geyser.auth.login.form.notice.btn_disconnect")
|
||||
.responseHandler((form, responseData) -> {
|
||||
SimpleFormResponse response = form.parseResponse(responseData);
|
||||
if (!response.isCorrect()) {
|
||||
buildAndShowLoginWindow(session);
|
||||
return;
|
||||
}
|
||||
|
||||
if (response.getClickedButtonId() == 0) {
|
||||
.resultHandler(
|
||||
(form, result) -> buildAndShowLoginWindow(session),
|
||||
ResultType.CLOSED, ResultType.INVALID
|
||||
)
|
||||
.validResultHandler((form, response) -> {
|
||||
if (response.clickedButtonId() == 0) {
|
||||
session.authenticateWithMicrosoftCode();
|
||||
} else if (response.getClickedButtonId() == 1) {
|
||||
} else if (response.clickedButtonId() == 1) {
|
||||
buildAndShowLoginDetailsWindow(session);
|
||||
} else {
|
||||
session.disconnect(GeyserLocale.getPlayerLocaleString("geyser.auth.login.form.disconnect", session.getLocale()));
|
||||
|
@ -318,14 +308,12 @@ public class LoginEncryptionUtils {
|
|||
.content("%xbox.signin.website\n%xbox.signin.url\n%xbox.signin.enterCode\n" + msCode.user_code)
|
||||
.button1("%gui.done")
|
||||
.button2("%menu.disconnect")
|
||||
.responseHandler((form, responseData) -> {
|
||||
ModalFormResponse response = form.parseResponse(responseData);
|
||||
if (!response.isCorrect()) {
|
||||
buildAndShowMicrosoftAuthenticationWindow(session);
|
||||
return;
|
||||
}
|
||||
|
||||
if (response.getClickedButtonId() == 1) {
|
||||
.resultHandler(
|
||||
(form, result) -> buildAndShowMicrosoftAuthenticationWindow(session),
|
||||
ResultType.CLOSED, ResultType.INVALID
|
||||
)
|
||||
.validResultHandler((form, response) -> {
|
||||
if (response.clickedButtonId() == 1) {
|
||||
session.disconnect(GeyserLocale.getPlayerLocaleString("geyser.auth.login.form.disconnect", session.getLocale()));
|
||||
}
|
||||
})
|
||||
|
|
|
@ -27,13 +27,12 @@ package org.geysermc.geyser.util;
|
|||
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
|
||||
import com.github.steveice10.mc.protocol.data.game.setting.Difficulty;
|
||||
import org.geysermc.cumulus.component.DropdownComponent;
|
||||
import org.geysermc.cumulus.form.CustomForm;
|
||||
import org.geysermc.geyser.GeyserImpl;
|
||||
import org.geysermc.geyser.level.GameRule;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
import org.geysermc.geyser.level.WorldManager;
|
||||
import org.geysermc.cumulus.CustomForm;
|
||||
import org.geysermc.cumulus.component.DropdownComponent;
|
||||
import org.geysermc.cumulus.response.CustomFormResponse;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
import org.geysermc.geyser.text.GeyserLocale;
|
||||
import org.geysermc.geyser.text.MinecraftLocale;
|
||||
|
||||
|
@ -115,12 +114,7 @@ public class SettingsUtils {
|
|||
}
|
||||
}
|
||||
|
||||
builder.responseHandler((form, responseData) -> {
|
||||
CustomFormResponse response = form.parseResponse(responseData);
|
||||
if (response.isClosed() || response.isInvalid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
builder.validResultHandler((form, response) -> {
|
||||
if (showClientSettings) {
|
||||
// Client can only see its coordinates if reducedDebugInfo is disabled and coordinates are enabled in geyser config.
|
||||
if (session.getPreferencesCache().isAllowShowCoordinates()) {
|
||||
|
|
|
@ -26,12 +26,11 @@
|
|||
package org.geysermc.geyser.util;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.game.statistic.*;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
import org.geysermc.cumulus.form.SimpleForm;
|
||||
import org.geysermc.cumulus.util.FormImage;
|
||||
import org.geysermc.geyser.registry.BlockRegistries;
|
||||
import org.geysermc.geyser.registry.type.ItemMappings;
|
||||
import org.geysermc.cumulus.SimpleForm;
|
||||
import org.geysermc.cumulus.response.SimpleFormResponse;
|
||||
import org.geysermc.cumulus.util.FormImage;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
import org.geysermc.geyser.text.GeyserLocale;
|
||||
import org.geysermc.geyser.text.MinecraftLocale;
|
||||
|
||||
|
@ -68,12 +67,7 @@ public class StatisticsUtils {
|
|||
.button("stat.itemsButton - stat_type.minecraft.dropped", FormImage.Type.PATH, "textures/ui/trash_default")
|
||||
.button("stat.mobsButton - geyser.statistics.killed", FormImage.Type.PATH, "textures/items/diamond_sword")
|
||||
.button("stat.mobsButton - geyser.statistics.killed_by", FormImage.Type.PATH, "textures/ui/wither_heart_flash")
|
||||
.responseHandler((form, responseData) -> {
|
||||
SimpleFormResponse response = form.parseResponse(responseData);
|
||||
if (!response.isCorrect()) {
|
||||
return;
|
||||
}
|
||||
|
||||
.validResultHandler((form, response) -> {
|
||||
SimpleForm.Builder builder =
|
||||
SimpleForm.builder()
|
||||
.translator(StatisticsUtils::translate, language);
|
||||
|
@ -81,7 +75,7 @@ public class StatisticsUtils {
|
|||
List<String> content = new ArrayList<>();
|
||||
|
||||
ItemMappings mappings = session.getItemMappings();
|
||||
switch (response.getClickedButtonId()) {
|
||||
switch (response.clickedButtonId()) {
|
||||
case 0:
|
||||
builder.title("stat.generalButton");
|
||||
|
||||
|
@ -202,12 +196,7 @@ public class StatisticsUtils {
|
|||
session.sendForm(
|
||||
builder.content(assembledContent.toString())
|
||||
.button("gui.back", FormImage.Type.PATH, "textures/gui/newgui/undo")
|
||||
.responseHandler((form1, subFormResponseData) -> {
|
||||
SimpleFormResponse response1 = form.parseResponse(subFormResponseData);
|
||||
if (response1.isCorrect()) {
|
||||
buildAndSendStatisticsMenu(session);
|
||||
}
|
||||
}));
|
||||
.validResultHandler((form1, response1) -> buildAndSendStatisticsMenu(session)));
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue