use of org.spongepowered.api.event.entity.living.player.PlayerChangeClientSettingsEvent in project SpongeCommon by SpongePowered.
the class ServerPlayerMixin method impl$handleClientSettings.
@SuppressWarnings({ "ConstantConditions", "UnstableApiUsage" })
@Inject(method = "updateOptions", at = @At("HEAD"))
private void impl$handleClientSettings(final ServerboundClientInformationPacket packet, final CallbackInfo ci) {
if (!ShouldFire.PLAYER_CHANGE_CLIENT_SETTINGS_EVENT) {
return;
}
final ServerboundClientInformationPacketAccessor $packet = (ServerboundClientInformationPacketAccessor) packet;
final Locale newLocale = LocaleCache.getLocale($packet.accessor$language());
final ImmutableSet<SkinPart> skinParts = Sponge.game().registry(RegistryTypes.SKIN_PART).stream().map(part -> (SpongeSkinPart) part).filter(part -> part.test(packet.getModelCustomisation())).collect(ImmutableSet.toImmutableSet());
final int viewDistance = $packet.accessor$viewDistance();
// Post before the player values are updated
try (final CauseStackManager.StackFrame frame = PhaseTracker.getCauseStackManager().pushCauseFrame()) {
final ChatVisibility visibility = (ChatVisibility) (Object) packet.getChatVisibility();
final PlayerChangeClientSettingsEvent event = SpongeEventFactory.createPlayerChangeClientSettingsEvent(frame.currentCause(), visibility, skinParts, newLocale, (ServerPlayer) this, packet.getChatColors(), viewDistance);
SpongeCommon.post(event);
}
}
Aggregations