3
0
Mirror von https://github.com/ViaVersion/ViaBackwards.git synchronisiert 2024-11-17 13:30:14 +01:00

Fix long scoreboard objective names for <1.18 clients

Dieser Commit ist enthalten in:
Nassim Jahnke 2022-03-06 15:41:51 +01:00
Ursprung aa35ace816
Commit 539c4e696a
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B

Datei anzeigen

@ -26,6 +26,7 @@ import com.viaversion.viabackwards.protocol.protocol1_17_1to1_18.packets.EntityP
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.RegistryType;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_17Types;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
@ -88,6 +89,49 @@ public final class Protocol1_17_1To1_18 extends BackwardsProtocol<ClientboundPac
create(Type.BOOLEAN, true); // Allow listing in server list preview
}
});
registerClientbound(ClientboundPackets1_18.SCOREBOARD_OBJECTIVE, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.STRING); // Name
handler(cutName(0, 16));
}
});
registerClientbound(ClientboundPackets1_18.DISPLAY_SCOREBOARD, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.BYTE); // Slot
map(Type.STRING); // Name
handler(cutName(0, 16));
}
});
registerClientbound(ClientboundPackets1_18.TEAMS, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.STRING); // Name
handler(cutName(0, 16));
}
});
registerClientbound(ClientboundPackets1_18.UPDATE_SCORE, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.STRING); // Owner
map(Type.VAR_INT); // Method
map(Type.STRING); // Name
handler(cutName(0, 40));
handler(cutName(1, 16));
}
});
}
private PacketHandler cutName(final int index, final int maxLength) {
// May in some case cause clashes or bad ordering, but nothing we can do about that
return wrapper -> {
final String s = wrapper.get(Type.STRING, index);
if (s.length() > maxLength) {
wrapper.set(Type.STRING, index, s.substring(0, maxLength));
}
};
}
@Override