Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-11-03 14:50:19 +01:00
Fixed remaining merge conflicts
Dieser Commit ist enthalten in:
Ursprung
5ad2510b87
Commit
cf149b58e0
@ -53,7 +53,7 @@ public abstract class CommandManager {
|
||||
registerCommand(new VersionCommand(connector, "version", "geyser.commands.version.desc", "geyser.command.version"));
|
||||
registerCommand(new SettingsCommand(connector, "settings", "geyser.commands.settings.desc", "geyser.command.settings"));
|
||||
registerCommand(new StatisticsCommand(connector, "statistics", "geyser.commands.statistics.desc", "geyser.command.statistics"));
|
||||
registerCommand(new AdvancementsCommand(connector, "advancements", "geyser.commands.advancements.desc", "geyser.command.advancements"));
|
||||
registerCommand(new AdvancementsCommand( "advancements", "geyser.commands.advancements.desc", "geyser.command.advancements"));
|
||||
}
|
||||
|
||||
public void registerCommand(GeyserCommand command) {
|
||||
|
@ -25,25 +25,20 @@
|
||||
|
||||
package org.geysermc.connector.command.defaults;
|
||||
|
||||
import org.geysermc.common.window.SimpleFormWindow;
|
||||
import org.geysermc.connector.GeyserConnector;
|
||||
import org.geysermc.connector.command.CommandSender;
|
||||
import org.geysermc.connector.command.GeyserCommand;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
import org.geysermc.connector.network.session.cache.AdvancementsCache;
|
||||
|
||||
public class AdvancementsCommand extends GeyserCommand {
|
||||
|
||||
public AdvancementsCommand(GeyserConnector connector, String name, String description, String permission) {
|
||||
public AdvancementsCommand(String name, String description, String permission) {
|
||||
super(name, description, permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(GeyserSession session, CommandSender sender, String[] args) {
|
||||
if (session == null) return;
|
||||
|
||||
SimpleFormWindow window = session.getAdvancementsCache().buildMenuForm();
|
||||
session.sendForm(window, AdvancementsCache.ADVANCEMENTS_MENU_FORM_ID);
|
||||
if (session != null) {
|
||||
session.getAdvancementsCache().buildAndShowMenuForm();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -489,7 +489,7 @@ public class GeyserSession implements CommandSender {
|
||||
MsaAuthenticationService msaAuthenticationService = new MsaAuthenticationService(GeyserConnector.OAUTH_CLIENT_ID);
|
||||
|
||||
MsaAuthenticationService.MsCodeResponse response = msaAuthenticationService.getAuthCode();
|
||||
LoginEncryptionUtils.showMicrosoftCodeWindow(this, response);
|
||||
LoginEncryptionUtils.buildAndShowMicrosoftCodeWindow(this, response);
|
||||
|
||||
// This just looks cool
|
||||
SetTimePacket packet = new SetTimePacket();
|
||||
@ -605,7 +605,7 @@ public class GeyserSession implements CommandSender {
|
||||
|
||||
// Let the user know there locale may take some time to download
|
||||
// as it has to be extracted from a JAR
|
||||
if (locale.toLowerCase().equals("en_us") && !LocaleUtils.LOCALE_MAPPINGS.containsKey("en_us")) {
|
||||
if (locale.equalsIgnoreCase("en_us") && !LocaleUtils.LOCALE_MAPPINGS.containsKey("en_us")) {
|
||||
// This should probably be left hardcoded as it will only show for en_us clients
|
||||
sendMessage("Loading your locale (en_us); if this isn't already downloaded, this may take some time");
|
||||
}
|
||||
|
@ -29,26 +29,20 @@ import com.github.steveice10.mc.protocol.data.game.advancement.Advancement;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientAdvancementTabPacket;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.geysermc.common.window.SimpleFormWindow;
|
||||
import org.geysermc.common.window.button.FormButton;
|
||||
import org.geysermc.common.window.response.SimpleFormResponse;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
import org.geysermc.connector.network.translators.chat.MessageTranslator;
|
||||
import org.geysermc.connector.utils.GeyserAdvancement;
|
||||
import org.geysermc.connector.utils.LanguageUtils;
|
||||
import org.geysermc.connector.utils.LocaleUtils;
|
||||
import org.geysermc.cumulus.SimpleForm;
|
||||
import org.geysermc.cumulus.response.SimpleFormResponse;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class AdvancementsCache {
|
||||
|
||||
// Different form IDs
|
||||
public static final int ADVANCEMENTS_MENU_FORM_ID = 1341;
|
||||
public static final int ADVANCEMENTS_LIST_FORM_ID = 1342;
|
||||
public static final int ADVANCEMENT_INFO_FORM_ID = 1343;
|
||||
|
||||
/**
|
||||
* Stores the player's advancement progress
|
||||
*/
|
||||
@ -64,7 +58,7 @@ public class AdvancementsCache {
|
||||
/**
|
||||
* Stores player's chosen advancement's ID and title for use in form creators.
|
||||
*/
|
||||
@Setter
|
||||
@Setter @Accessors(chain = true)
|
||||
private String currentAdvancementCategoryId = null;
|
||||
|
||||
private final GeyserSession session;
|
||||
@ -74,73 +68,128 @@ public class AdvancementsCache {
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a form with all advancement categories
|
||||
*
|
||||
* @return The built advancement category menu
|
||||
* Build and send a form with all advancement categories
|
||||
*/
|
||||
public SimpleFormWindow buildMenuForm() {
|
||||
// Cache the language for cleaner access
|
||||
String language = session.getClientData().getLanguageCode();
|
||||
public void buildAndShowMenuForm() {
|
||||
SimpleForm.Builder builder =
|
||||
SimpleForm.builder()
|
||||
.translator(LocaleUtils::getLocaleString, session.getLocale())
|
||||
.title("gui.advancements");
|
||||
|
||||
// Created menu window for advancement categories
|
||||
SimpleFormWindow window = new SimpleFormWindow(LocaleUtils.getLocaleString("gui.advancements", language), "");
|
||||
boolean hasAdvancements = false;
|
||||
for (Map.Entry<String, GeyserAdvancement> advancement : storedAdvancements.entrySet()) {
|
||||
if (advancement.getValue().getParentId() == null) { // No parent means this is a root advancement
|
||||
window.getButtons().add(new FormButton(MessageTranslator.convertMessage(advancement.getValue().getDisplayData().getTitle(), language)));
|
||||
hasAdvancements = true;
|
||||
builder.button(MessageTranslator.convertMessage(advancement.getValue().getDisplayData().getTitle(), session.getLocale()));
|
||||
}
|
||||
}
|
||||
|
||||
if (window.getButtons().isEmpty()) {
|
||||
window.setContent(LocaleUtils.getLocaleString("advancements.empty", language));
|
||||
if (!hasAdvancements) {
|
||||
builder.content("advancements.empty");
|
||||
}
|
||||
|
||||
return window;
|
||||
builder.responseHandler((form, responseData) -> {
|
||||
SimpleFormResponse response = form.parseResponse(responseData);
|
||||
if (!response.isCorrect()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String id = "";
|
||||
|
||||
int advancementIndex = 0;
|
||||
for (Map.Entry<String, GeyserAdvancement> advancement : storedAdvancements.entrySet()) {
|
||||
if (advancement.getValue().getParentId() == null) { // Root advancement
|
||||
if (advancementIndex == response.getClickedButtonId()) {
|
||||
id = advancement.getKey();
|
||||
break;
|
||||
} else {
|
||||
advancementIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!id.equals("")) {
|
||||
if (id.equals(currentAdvancementCategoryId)) {
|
||||
// The server thinks we are already on this tab
|
||||
buildAndShowListForm();
|
||||
} else {
|
||||
// Send a packet indicating that we intend to open this particular advancement window
|
||||
ClientAdvancementTabPacket packet = new ClientAdvancementTabPacket(id);
|
||||
session.sendDownstreamPacket(packet);
|
||||
// Wait for a response there
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
session.sendForm(builder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the list of advancements
|
||||
*
|
||||
* @return The built list form
|
||||
* Build and send the list of advancements
|
||||
*/
|
||||
public SimpleFormWindow buildListForm() {
|
||||
// Cache the language for easier access
|
||||
String language = session.getLocale();
|
||||
String id = currentAdvancementCategoryId;
|
||||
public void buildAndShowListForm() {
|
||||
GeyserAdvancement categoryAdvancement = storedAdvancements.get(currentAdvancementCategoryId);
|
||||
String language = session.getLocale();
|
||||
|
||||
// Create the window
|
||||
SimpleFormWindow window = new SimpleFormWindow(MessageTranslator.convertMessage(categoryAdvancement.getDisplayData().getTitle(), language),
|
||||
MessageTranslator.convertMessage(categoryAdvancement.getDisplayData().getDescription(), language));
|
||||
SimpleForm.Builder builder =
|
||||
SimpleForm.builder()
|
||||
.title(MessageTranslator.convertMessage(categoryAdvancement.getDisplayData().getTitle(), language))
|
||||
.content(MessageTranslator.convertMessage(categoryAdvancement.getDisplayData().getDescription(), language));
|
||||
|
||||
if (id != null) {
|
||||
for (Map.Entry<String, GeyserAdvancement> advancementEntry : storedAdvancements.entrySet()) {
|
||||
GeyserAdvancement advancement = advancementEntry.getValue();
|
||||
if (currentAdvancementCategoryId != null) {
|
||||
for (GeyserAdvancement advancement : storedAdvancements.values()) {
|
||||
if (advancement != null) {
|
||||
if (advancement.getParentId() != null && currentAdvancementCategoryId.equals(advancement.getRootId(this))) {
|
||||
boolean earned = isEarned(advancement);
|
||||
boolean color = isEarned(advancement) || !advancement.getDisplayData().isShowToast();
|
||||
builder.button((color ? "§6" : "") + MessageTranslator.convertMessage(advancement.getDisplayData().getTitle()) + '\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (earned || !advancement.getDisplayData().isShowToast()) {
|
||||
window.getButtons().add(new FormButton("§6" + MessageTranslator.convertMessage(advancementEntry.getValue().getDisplayData().getTitle()) + "\n"));
|
||||
builder.button(LanguageUtils.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 ClientAdvancementTabPacket());
|
||||
return;
|
||||
}
|
||||
|
||||
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()) {
|
||||
advancement = advancementEntry;
|
||||
break;
|
||||
} else {
|
||||
window.getButtons().add(new FormButton(MessageTranslator.convertMessage(advancementEntry.getValue().getDisplayData().getTitle()) + "\n"));
|
||||
}
|
||||
}
|
||||
advancementIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.getButtons().add(new FormButton(LanguageUtils.getPlayerLocaleString("gui.back", language)));
|
||||
if (advancement != null) {
|
||||
buildAndShowInfoForm(advancement);
|
||||
} else {
|
||||
buildAndShowMenuForm();
|
||||
// Indicate that we have closed the current advancement tab
|
||||
session.sendDownstreamPacket(new ClientAdvancementTabPacket());
|
||||
}
|
||||
});
|
||||
|
||||
return window;
|
||||
session.sendForm(builder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the advancement display info based on the chosen category
|
||||
*
|
||||
* @param advancement The advancement used to create the info display
|
||||
* @return The information for the chosen advancement
|
||||
*/
|
||||
public SimpleFormWindow buildInfoForm(GeyserAdvancement advancement) {
|
||||
public void buildAndShowInfoForm(GeyserAdvancement advancement) {
|
||||
// Cache language for easier access
|
||||
String language = session.getLocale();
|
||||
|
||||
@ -160,16 +209,24 @@ public class AdvancementsCache {
|
||||
Parent Advancement: Minecraft // If relevant
|
||||
*/
|
||||
|
||||
String content = description + "\n\n§f" +
|
||||
earnedString + "\n";
|
||||
String content = description + "\n\n§f" + earnedString + "\n";
|
||||
if (!currentAdvancementCategoryId.equals(advancement.getParentId())) {
|
||||
// Only display the parent if it is not the category
|
||||
content += LanguageUtils.getPlayerLocaleString("geyser.advancements.parentid", language, MessageTranslator.convertMessage(storedAdvancements.get(advancement.getParentId()).getDisplayData().getTitle(), language));
|
||||
}
|
||||
SimpleFormWindow window = new SimpleFormWindow(MessageTranslator.convertMessage(advancement.getDisplayData().getTitle()), content);
|
||||
window.getButtons().add(new FormButton(LanguageUtils.getPlayerLocaleString("gui.back", language)));
|
||||
|
||||
return window;
|
||||
session.sendForm(
|
||||
SimpleForm.builder()
|
||||
.title(MessageTranslator.convertMessage(advancement.getDisplayData().getTitle()))
|
||||
.content(content)
|
||||
.button(LanguageUtils.getPlayerLocaleString("gui.back", language))
|
||||
.responseHandler((form, responseData) -> {
|
||||
SimpleFormResponse response = form.parseResponse(responseData);
|
||||
if (response.isCorrect()) {
|
||||
buildAndShowListForm();
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -209,108 +266,6 @@ public class AdvancementsCache {
|
||||
return earned;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the menu form response
|
||||
*
|
||||
* @param response The response string to parse
|
||||
* @return True if the form was parsed correctly, false if not
|
||||
*/
|
||||
public boolean handleMenuForm(String response) {
|
||||
SimpleFormWindow menuForm = (SimpleFormWindow) session.getWindowCache().getWindows().get(ADVANCEMENTS_MENU_FORM_ID);
|
||||
menuForm.setResponse(response);
|
||||
|
||||
SimpleFormResponse formResponse = (SimpleFormResponse) menuForm.getResponse();
|
||||
|
||||
String id = "";
|
||||
if (formResponse != null && formResponse.getClickedButton() != null) {
|
||||
int advancementIndex = 0;
|
||||
for (Map.Entry<String, GeyserAdvancement> advancement : storedAdvancements.entrySet()) {
|
||||
if (advancement.getValue().getParentId() == null) { // Root advancement
|
||||
if (advancementIndex == formResponse.getClickedButtonId()) {
|
||||
id = advancement.getKey();
|
||||
break;
|
||||
} else {
|
||||
advancementIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!id.equals("")) {
|
||||
if (id.equals(currentAdvancementCategoryId)) {
|
||||
// The server thinks we are already on this tab
|
||||
session.sendForm(buildListForm(), ADVANCEMENTS_LIST_FORM_ID);
|
||||
} else {
|
||||
// Send a packet indicating that we intend to open this particular advancement window
|
||||
ClientAdvancementTabPacket packet = new ClientAdvancementTabPacket(id);
|
||||
session.sendDownstreamPacket(packet);
|
||||
// Wait for a response there
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the list form response (Advancement category choice)
|
||||
*
|
||||
* @param response The response string to parse
|
||||
* @return True if the form was parsed correctly, false if not
|
||||
*/
|
||||
public boolean handleListForm(String response) {
|
||||
SimpleFormWindow listForm = (SimpleFormWindow) session.getWindowCache().getWindows().get(ADVANCEMENTS_LIST_FORM_ID);
|
||||
listForm.setResponse(response);
|
||||
|
||||
SimpleFormResponse formResponse = (SimpleFormResponse) listForm.getResponse();
|
||||
|
||||
if (!listForm.isClosed() && formResponse != null && formResponse.getClickedButton() != null) {
|
||||
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 == formResponse.getClickedButtonId()) {
|
||||
advancement = advancementEntry;
|
||||
break;
|
||||
} else {
|
||||
advancementIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (advancement != null) {
|
||||
session.sendForm(buildInfoForm(advancement), ADVANCEMENT_INFO_FORM_ID);
|
||||
} else {
|
||||
session.sendForm(buildMenuForm(), ADVANCEMENTS_MENU_FORM_ID);
|
||||
// Indicate that we have closed the current advancement tab
|
||||
session.sendDownstreamPacket(new ClientAdvancementTabPacket());
|
||||
}
|
||||
} else {
|
||||
// Indicate that we have closed the current advancement tab
|
||||
session.sendDownstreamPacket(new ClientAdvancementTabPacket());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the info form response
|
||||
*
|
||||
* @param response The response string to parse
|
||||
* @return True if the form was parsed correctly, false if not
|
||||
*/
|
||||
public boolean handleInfoForm(String response) {
|
||||
SimpleFormWindow listForm = (SimpleFormWindow) session.getWindowCache().getWindows().get(ADVANCEMENT_INFO_FORM_ID);
|
||||
listForm.setResponse(response);
|
||||
|
||||
SimpleFormResponse formResponse = (SimpleFormResponse) listForm.getResponse();
|
||||
|
||||
if (!listForm.isClosed() && formResponse != null && formResponse.getClickedButton() != null) {
|
||||
session.sendForm(buildListForm(), ADVANCEMENTS_LIST_FORM_ID);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getColorFromAdvancementFrameType(GeyserAdvancement advancement) {
|
||||
String base = "\u00a7";
|
||||
if (advancement.getDisplayData().getFrameType() == Advancement.DisplayData.FrameType.CHALLENGE) {
|
||||
|
@ -27,7 +27,6 @@ package org.geysermc.connector.network.translators.java;
|
||||
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerAdvancementTabPacket;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
import org.geysermc.connector.network.session.cache.AdvancementsCache;
|
||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||
import org.geysermc.connector.network.translators.Translator;
|
||||
|
||||
@ -36,10 +35,10 @@ import org.geysermc.connector.network.translators.Translator;
|
||||
*/
|
||||
@Translator(packet = ServerAdvancementTabPacket.class)
|
||||
public class JavaAdvancementsTabTranslator extends PacketTranslator<ServerAdvancementTabPacket> {
|
||||
|
||||
@Override
|
||||
public void translate(ServerAdvancementTabPacket packet, GeyserSession session) {
|
||||
session.getAdvancementsCache().setCurrentAdvancementCategoryId(packet.getTabId());
|
||||
session.sendForm(session.getAdvancementsCache().buildListForm(), AdvancementsCache.ADVANCEMENTS_LIST_FORM_ID);
|
||||
session.getAdvancementsCache()
|
||||
.setCurrentAdvancementCategoryId(packet.getTabId())
|
||||
.buildAndShowListForm();
|
||||
}
|
||||
}
|
||||
|
@ -169,7 +169,7 @@ public class LoginEncryptionUtils {
|
||||
.translator(LanguageUtils::getPlayerLocaleString, session.getLocale())
|
||||
.title("geyser.auth.login.form.notice.title")
|
||||
.content("geyser.auth.login.form.notice.desc")
|
||||
.button("geyser.auth.login.form.notice.btn_login.mojang") //todo optional
|
||||
.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) -> {
|
||||
@ -179,9 +179,6 @@ public class LoginEncryptionUtils {
|
||||
return;
|
||||
}
|
||||
|
||||
int microsoftButton = isPasswordAuthentication ? 1 : 0;
|
||||
int disconnectButton = isPasswordAuthentication ? 2 : 1;
|
||||
|
||||
if (isPasswordAuthEnabled && response.getClickedButtonId() == 0) {
|
||||
session.setMicrosoftAccount(false);
|
||||
buildAndShowLoginDetailsWindow(session);
|
||||
@ -272,6 +269,6 @@ public class LoginEncryptionUtils {
|
||||
session.disconnect(LanguageUtils.getPlayerLocaleString("geyser.auth.login.form.disconnect", session.getLocale()));
|
||||
}
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren