Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-08 17:20:24 +01:00
Make 1.19 chat decoration method public
Dieser Commit ist enthalten in:
Ursprung
b032a868bb
Commit
2b735172bd
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||||
|
* Copyright (C) 2016-2022 ViaVersion and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.viaversion.viaversion.protocols.protocol1_19_1to1_19;
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
|
||||||
|
public final class ChatDecorationResult {
|
||||||
|
|
||||||
|
private final JsonElement content;
|
||||||
|
private final boolean overlay;
|
||||||
|
|
||||||
|
public ChatDecorationResult(final JsonElement content, final boolean overlay) {
|
||||||
|
this.content = content;
|
||||||
|
this.overlay = overlay;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonElement content() {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean overlay() {
|
||||||
|
return overlay;
|
||||||
|
}
|
||||||
|
}
|
@ -116,14 +116,20 @@ public final class Protocol1_19_1To1_19 extends AbstractProtocol<ClientboundPack
|
|||||||
// Back to system chat
|
// Back to system chat
|
||||||
final JsonElement signedContent = wrapper.read(Type.COMPONENT);
|
final JsonElement signedContent = wrapper.read(Type.COMPONENT);
|
||||||
final JsonElement unsignedContent = wrapper.read(Type.OPTIONAL_COMPONENT);
|
final JsonElement unsignedContent = wrapper.read(Type.OPTIONAL_COMPONENT);
|
||||||
final int chatType = wrapper.read(Type.VAR_INT);
|
final int chatTypeId = wrapper.read(Type.VAR_INT);
|
||||||
|
|
||||||
wrapper.read(Type.UUID); // Sender UUID
|
wrapper.read(Type.UUID); // Sender UUID
|
||||||
final JsonElement senderName = wrapper.read(Type.COMPONENT);
|
final JsonElement senderName = wrapper.read(Type.COMPONENT);
|
||||||
final JsonElement teamName = wrapper.read(Type.OPTIONAL_COMPONENT);
|
final JsonElement teamName = wrapper.read(Type.OPTIONAL_COMPONENT);
|
||||||
if (!decorateChatMessage(wrapper, chatType, senderName, teamName, unsignedContent != null ? unsignedContent : signedContent)) {
|
|
||||||
|
final CompoundTag chatType = wrapper.user().get(ChatTypeStorage.class).chatType(chatTypeId);
|
||||||
|
final ChatDecorationResult decorationResult = decorateChatMessage(chatType, chatTypeId, senderName, teamName, unsignedContent != null ? unsignedContent : signedContent);
|
||||||
|
if (decorationResult == null) {
|
||||||
wrapper.cancel();
|
wrapper.cancel();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wrapper.write(Type.COMPONENT, decorationResult.content());
|
||||||
|
wrapper.write(Type.BOOLEAN, decorationResult.overlay());
|
||||||
});
|
});
|
||||||
read(Type.LONG); // Timestamp
|
read(Type.LONG); // Timestamp
|
||||||
read(Type.LONG); // Salt
|
read(Type.LONG); // Salt
|
||||||
@ -281,11 +287,10 @@ public final class Protocol1_19_1To1_19 extends AbstractProtocol<ClientboundPack
|
|||||||
connection.put(new ChatTypeStorage());
|
connection.put(new ChatTypeStorage());
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean decorateChatMessage(final PacketWrapper wrapper, final int chatTypeId, final JsonElement senderName, @Nullable final JsonElement teamName, final JsonElement message) {
|
public static @Nullable ChatDecorationResult decorateChatMessage(final CompoundTag chatType, final int chatTypeId, final JsonElement senderName, @Nullable final JsonElement teamName, final JsonElement message) {
|
||||||
final CompoundTag chatType = wrapper.user().get(ChatTypeStorage.class).chatType(chatTypeId);
|
|
||||||
if (chatType == null) {
|
if (chatType == null) {
|
||||||
Via.getPlatform().getLogger().warning("Chat message has unknown chat type id " + chatTypeId + ". Message: " + message);
|
Via.getPlatform().getLogger().warning("Chat message has unknown chat type id " + chatTypeId + ". Message: " + message);
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
CompoundTag chatData = chatType.<CompoundTag>get("element").get("chat");
|
CompoundTag chatData = chatType.<CompoundTag>get("element").get("chat");
|
||||||
@ -294,7 +299,7 @@ public final class Protocol1_19_1To1_19 extends AbstractProtocol<ClientboundPack
|
|||||||
chatData = chatType.<CompoundTag>get("element").get("overlay");
|
chatData = chatType.<CompoundTag>get("element").get("overlay");
|
||||||
if (chatData == null) {
|
if (chatData == null) {
|
||||||
// Either narration or something we don't know
|
// Either narration or something we don't know
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
overlay = true;
|
overlay = true;
|
||||||
@ -302,9 +307,7 @@ public final class Protocol1_19_1To1_19 extends AbstractProtocol<ClientboundPack
|
|||||||
|
|
||||||
final CompoundTag decoaration = chatData.get("decoration");
|
final CompoundTag decoaration = chatData.get("decoration");
|
||||||
if (decoaration == null) {
|
if (decoaration == null) {
|
||||||
wrapper.write(Type.COMPONENT, message);
|
return new ChatDecorationResult(message, overlay);
|
||||||
wrapper.write(Type.BOOLEAN, overlay);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final String translationKey = (String) decoaration.get("translation_key").getValue();
|
final String translationKey = (String) decoaration.get("translation_key").getValue();
|
||||||
@ -356,9 +359,6 @@ public final class Protocol1_19_1To1_19 extends AbstractProtocol<ClientboundPack
|
|||||||
}
|
}
|
||||||
componentBuilder.args(arguments);
|
componentBuilder.args(arguments);
|
||||||
}
|
}
|
||||||
|
return new ChatDecorationResult(GsonComponentSerializer.gson().serializeToTree(componentBuilder.build()), overlay);
|
||||||
wrapper.write(Type.COMPONENT, GsonComponentSerializer.gson().serializeToTree(componentBuilder.build()));
|
|
||||||
wrapper.write(Type.BOOLEAN, overlay);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren