Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-28 09:00:09 +01:00
Ignore invalid names in the data component for hover events as well
Dieser Commit ist enthalten in:
Ursprung
8e63fd635b
Commit
a1c182f291
@ -1203,10 +1203,15 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
|||||||
private void updateProfile(final StructuredDataContainer data, final Tag skullOwnerTag) {
|
private void updateProfile(final StructuredDataContainer data, final Tag skullOwnerTag) {
|
||||||
if (skullOwnerTag instanceof StringTag) {
|
if (skullOwnerTag instanceof StringTag) {
|
||||||
final String name = ((StringTag) skullOwnerTag).getValue();
|
final String name = ((StringTag) skullOwnerTag).getValue();
|
||||||
|
if (isValidName(name)) {
|
||||||
data.set(StructuredDataKey.PROFILE, new GameProfile(name, null, EMPTY_PROPERTIES));
|
data.set(StructuredDataKey.PROFILE, new GameProfile(name, null, EMPTY_PROPERTIES));
|
||||||
|
}
|
||||||
} else if (skullOwnerTag instanceof CompoundTag) {
|
} else if (skullOwnerTag instanceof CompoundTag) {
|
||||||
final CompoundTag skullOwner = (CompoundTag) skullOwnerTag;
|
final CompoundTag skullOwner = (CompoundTag) skullOwnerTag;
|
||||||
final String name = skullOwner.getString("Name", "");
|
String name = skullOwner.getString("Name", "");
|
||||||
|
if (!isValidName(name)) {
|
||||||
|
name = null;
|
||||||
|
}
|
||||||
|
|
||||||
final IntArrayTag idTag = skullOwner.getIntArrayTag("Id");
|
final IntArrayTag idTag = skullOwner.getIntArrayTag("Id");
|
||||||
UUID uuid = null;
|
UUID uuid = null;
|
||||||
@ -1219,7 +1224,8 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
|||||||
if (propertiesTag != null) {
|
if (propertiesTag != null) {
|
||||||
updateProperties(propertiesTag, properties);
|
updateProperties(propertiesTag, properties);
|
||||||
}
|
}
|
||||||
data.set(StructuredDataKey.PROFILE, new GameProfile(limit(name, 16), uuid, properties.toArray(EMPTY_PROPERTIES)));
|
|
||||||
|
data.set(StructuredDataKey.PROFILE, new GameProfile(name, uuid, properties.toArray(EMPTY_PROPERTIES)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1440,7 +1446,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
|||||||
tag.put("profile", profileTag);
|
tag.put("profile", profileTag);
|
||||||
|
|
||||||
final String name = skullOwnerTag.getString("Name");
|
final String name = skullOwnerTag.getString("Name");
|
||||||
if (name != null && name.length() <= 16 && name.indexOf(' ') == -1) { // Ignore invalid names
|
if (name != null && isValidName(name)) {
|
||||||
profileTag.putString("name", name);
|
profileTag.putString("name", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1481,4 +1487,20 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
|||||||
|
|
||||||
profileTag.put("properties", propertiesListTag);
|
profileTag.put("properties", propertiesListTag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isValidName(final String name) {
|
||||||
|
// Ignore invalid player profile names
|
||||||
|
if (name.length() > 16) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0, len = name.length(); i < len; ++i) {
|
||||||
|
final char c = name.charAt(i);
|
||||||
|
if (c < '!' || c > '~') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
@ -167,7 +167,9 @@ public class ComponentRewriter1_20_5 extends ComponentRewriter<ClientboundPacket
|
|||||||
@Override
|
@Override
|
||||||
protected void handleHoverEvent(final UserConnection connection, final CompoundTag hoverEventTag) {
|
protected void handleHoverEvent(final UserConnection connection, final CompoundTag hoverEventTag) {
|
||||||
final StringTag actionTag = hoverEventTag.getStringTag("action");
|
final StringTag actionTag = hoverEventTag.getStringTag("action");
|
||||||
if (actionTag == null) return;
|
if (actionTag == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (actionTag.getValue().equals("show_item")) {
|
if (actionTag.getValue().equals("show_item")) {
|
||||||
final Tag valueTag = hoverEventTag.remove("value");
|
final Tag valueTag = hoverEventTag.remove("value");
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren