Skip to content

Commit

Permalink
Custom chat types at login are valid
Browse files Browse the repository at this point in the history
  • Loading branch information
Camotoy committed Jun 15, 2022
1 parent aa097ec commit ddd2262
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
<dependency>
<groupId>com.github.GeyserMC</groupId>
<artifactId>MCProtocolLib</artifactId>
<version>bb2b414</version>
<version>54fc9f0</version>
<scope>compile</scope>
<exclusions>
<exclusion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
import lombok.AccessLevel;
Expand Down Expand Up @@ -499,7 +501,7 @@ public class GeyserSession implements GeyserConnection, CommandSender {
* Stores a map of all statistics sent from the server.
* The server only sends new statistics back to us, so in order to show all statistics we need to cache existing ones.
*/
private final Map<Statistic, Integer> statistics = new HashMap<>();
private final Object2IntMap<Statistic> statistics = new Object2IntOpenHashMap<>(0);

/**
* Whether we're expecting statistics to be sent back to us.
Expand Down Expand Up @@ -1688,7 +1690,7 @@ public int getNextSequence() {
*
* @param statistics Updated statistics values
*/
public void updateStatistics(@NonNull Map<Statistic, Integer> statistics) {
public void updateStatistics(@Nonnull Object2IntMap<Statistic> statistics) {
if (this.statistics.isEmpty()) {
// Initialize custom statistics to 0, so that they appear in the form
for (CustomStatistic customStatistic : CustomStatistic.values()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

package org.geysermc.geyser.translator.protocol.java;

import com.github.steveice10.mc.protocol.data.game.MessageType;
import com.github.steveice10.mc.protocol.data.game.BuiltinChatType;
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundLoginPacket;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundCustomPayloadPacket;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
Expand Down Expand Up @@ -82,14 +82,15 @@ public void translate(GeyserSession session, ClientboundLoginPacket packet) {
textDecoration = new TextDecoration(decorationTag);
}
}
MessageType type = MessageType.from(((StringTag) tag.get("name")).getValue());
BuiltinChatType type = BuiltinChatType.from(((StringTag) tag.get("name")).getValue());
// TODO new types?
TextPacket.Type bedrockType = switch (type) {
// The built-in type can be null if custom plugins/mods add in new types
TextPacket.Type bedrockType = type != null ? switch (type) {
case CHAT -> TextPacket.Type.CHAT;
case SYSTEM -> TextPacket.Type.SYSTEM;
case GAME_INFO -> TextPacket.Type.TIP;
default -> TextPacket.Type.RAW;
};
} : TextPacket.Type.RAW;
chatTypes.put(id, new ChatTypeEntry(bedrockType, textDecoration));
}

Expand Down

0 comments on commit ddd2262

Please sign in to comment.