Skip to content

Commit

Permalink
fix: actionbars sent from proxy to 1.10 and older clients without col…
Browse files Browse the repository at this point in the history
…or (#305)
  • Loading branch information
diogotcorreia authored May 21, 2023
1 parent fc0d70e commit c49c9db
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,15 @@ private boolean handleChat(DefinedPacket packet) {
Triton.get().getConf().getChatSyntax() : Triton.get().getConf().getActionbarSyntax(), text);
if (text == null)
return false;
p.setMessage(ComponentSerializer.toString(text));

if (type == 2 && protocolVersion <= ProtocolConstants.MINECRAFT_1_10) {
// The Notchian client does not support true JSON messages on actionbars
// on 1.10 and below. Therefore, we must convert to a legacy string inside
// a TextComponent.
p.setMessage(ComponentSerializer.toString(new TextComponent(TextComponent.toLegacyText(text))));
} else {
p.setMessage(ComponentSerializer.toString(text));
}
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.comphenix.protocol.reflect.accessors.Accessors;
import com.comphenix.protocol.reflect.accessors.MethodAccessor;
import com.comphenix.protocol.utility.MinecraftReflection;
import com.comphenix.protocol.utility.MinecraftVersion;
import com.comphenix.protocol.wrappers.BlockPosition;
import com.comphenix.protocol.wrappers.BukkitConverters;
import com.comphenix.protocol.wrappers.EnumWrappers;
Expand Down Expand Up @@ -218,8 +219,14 @@ private void handleChat(PacketEvent packet, SpigotLanguagePlayer languagePlayer)
return;
}

// Flatten action bar's json
baseComponentModifier.writeSafely(0, ab && getMCVersion() < 16 ? ComponentUtils.mergeComponents(result) : result);
if (ab && !MinecraftVersion.EXPLORATION_UPDATE.atOrAbove()) {
// The Notchian client does not support true JSON messages on actionbars
// on 1.10 and below. Therefore, we must convert to a legacy string inside
// a TextComponent.
baseComponentModifier.writeSafely(0, ComponentUtils.mergeComponents(result));
} else {
baseComponentModifier.writeSafely(0, result);
}
}

/**
Expand Down

0 comments on commit c49c9db

Please sign in to comment.