Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-11-19 14:30:17 +01:00
Anvil renaming
Dieser Commit ist enthalten in:
Ursprung
c963503fef
Commit
dacacc6df8
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
package org.geysermc.geyser.inventory;
|
package org.geysermc.geyser.inventory;
|
||||||
|
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.inventory.ContainerType;
|
import org.geysermc.mcprotocollib.protocol.data.game.inventory.ContainerType;
|
||||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundRenameItemPacket;
|
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundRenameItemPacket;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@ -72,10 +73,9 @@ public class AnvilContainer extends Container {
|
|||||||
String correctRename;
|
String correctRename;
|
||||||
newName = rename;
|
newName = rename;
|
||||||
|
|
||||||
// TODO 1.20.5 fix properly - this name is apparently nullable??
|
Component originalName = ItemUtils.getCustomName(getInput().getComponents());
|
||||||
String originalName = MessageTranslator.convertMessage(ItemUtils.getCustomName(getInput().getComponents()));
|
|
||||||
|
|
||||||
String plainOriginalName = MessageTranslator.convertToPlainTextLenient(originalName, session.locale());
|
String plainOriginalName = MessageTranslator.convertToPlainText(originalName, session.locale());
|
||||||
String plainNewName = MessageTranslator.convertToPlainText(rename);
|
String plainNewName = MessageTranslator.convertToPlainText(rename);
|
||||||
if (!plainOriginalName.equals(plainNewName)) {
|
if (!plainOriginalName.equals(plainNewName)) {
|
||||||
// Strip out formatting since Java Edition does not allow it
|
// Strip out formatting since Java Edition does not allow it
|
||||||
@ -85,7 +85,7 @@ public class AnvilContainer extends Container {
|
|||||||
session.sendDownstreamGamePacket(renameItemPacket);
|
session.sendDownstreamGamePacket(renameItemPacket);
|
||||||
} else {
|
} else {
|
||||||
// Restore formatting for item since we're not renaming
|
// Restore formatting for item since we're not renaming
|
||||||
correctRename = MessageTranslator.convertMessageLenient(originalName);
|
correctRename = MessageTranslator.convertMessage(originalName, session.locale());
|
||||||
// Java Edition sends the original custom name when not renaming,
|
// Java Edition sends the original custom name when not renaming,
|
||||||
// if there isn't a custom name an empty string is sent
|
// if there isn't a custom name an empty string is sent
|
||||||
ServerboundRenameItemPacket renameItemPacket = new ServerboundRenameItemPacket(plainOriginalName);
|
ServerboundRenameItemPacket renameItemPacket = new ServerboundRenameItemPacket(plainOriginalName);
|
||||||
|
@ -118,8 +118,7 @@ public class AnvilInventoryUpdater extends InventoryUpdater {
|
|||||||
|
|
||||||
// Changing the item in the input slot resets the name field on Bedrock, but
|
// Changing the item in the input slot resets the name field on Bedrock, but
|
||||||
// does not result in a FilterTextPacket
|
// does not result in a FilterTextPacket
|
||||||
// TODO test
|
String originalName = MessageTranslator.convertToPlainText(ItemUtils.getCustomName(input.getComponents()), session.locale());
|
||||||
String originalName = MessageTranslator.convertToPlainText(ItemUtils.getCustomName(input.getComponents()));
|
|
||||||
ServerboundRenameItemPacket renameItemPacket = new ServerboundRenameItemPacket(originalName);
|
ServerboundRenameItemPacket renameItemPacket = new ServerboundRenameItemPacket(originalName);
|
||||||
session.sendDownstreamGamePacket(renameItemPacket);
|
session.sendDownstreamGamePacket(renameItemPacket);
|
||||||
|
|
||||||
|
@ -260,13 +260,17 @@ public class MessageTranslator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert legacy format message to plain text
|
* Convert a Java message to plain text
|
||||||
*
|
*
|
||||||
* @param message Message to convert
|
* @param message Message to convert
|
||||||
|
* @param locale Locale to use for translation strings
|
||||||
* @return The plain text of the message
|
* @return The plain text of the message
|
||||||
*/
|
*/
|
||||||
public static String convertToPlainText(Component message) {
|
public static String convertToPlainText(Component message, String locale) {
|
||||||
return PlainTextComponentSerializer.plainText().serialize(message);
|
if (message == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return PlainTextComponentSerializer.plainText().serialize(RENDERER.render(message, locale));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -15,7 +15,7 @@ protocol-connection = "3.0.0.Beta1-20240411.165033-128"
|
|||||||
raknet = "1.0.0.CR3-20240416.144209-1"
|
raknet = "1.0.0.CR3-20240416.144209-1"
|
||||||
blockstateupdater="1.20.80-20240411.142413-1"
|
blockstateupdater="1.20.80-20240411.142413-1"
|
||||||
mcauthlib = "d9d773e"
|
mcauthlib = "d9d773e"
|
||||||
mcprotocollib = "400f1b4" # Revert from jitpack after release
|
mcprotocollib = "bc8526b" # Revert from jitpack after release
|
||||||
adventure = "4.14.0"
|
adventure = "4.14.0"
|
||||||
adventure-platform = "4.3.0"
|
adventure-platform = "4.3.0"
|
||||||
junit = "5.9.2"
|
junit = "5.9.2"
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren