use of org.spongepowered.api.entity.living.player.chat.ChatVisibility 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);
}
}
use of org.spongepowered.api.entity.living.player.chat.ChatVisibility in project SpongeCommon by SpongePowered.
the class ServerPlayerData method register.
// @formatter:off
public static void register(final DataProviderRegistrator registrator) {
registrator.asMutable(ServerPlayer.class).create(Keys.GAME_MODE).get(h -> (GameMode) (Object) h.gameMode.getGameModeForPlayer()).set((h, v) -> h.setGameMode((GameType) (Object) v)).create(Keys.SKIN_PROFILE_PROPERTY).get(h -> {
final Collection<Property> properties = h.getGameProfile().getProperties().get(ProfileProperty.TEXTURES);
if (properties.isEmpty()) {
return null;
}
return new SpongeProfileProperty(properties.iterator().next());
}).create(Keys.SPECTATOR_TARGET).get(h -> (Entity) h.getCamera()).set((h, v) -> h.setCamera((net.minecraft.world.entity.Entity) v)).delete(h -> h.setCamera(null)).create(Keys.STATISTICS).get(h -> ((StatsCounterBridge) h.getStats()).bridge$getStatsData().entrySet().stream().collect(Collectors.toMap(e -> (Statistic) e.getKey(), e -> e.getValue().longValue()))).set((h, v) -> v.forEach((ik, iv) -> h.getStats().setValue(h, (Stat<?>) ik, iv.intValue()))).create(Keys.CHAT_VISIBILITY).get(h -> {
final ChatVisibility visibility = (ChatVisibility) (Object) h.getChatVisibility();
if (visibility == null) {
return ChatVisibilities.FULL.get();
}
return visibility;
}).asMutable(ServerPlayerAccessor.class).create(Keys.HAS_VIEWED_CREDITS).get(ServerPlayerAccessor::accessor$seenCredits).set(ServerPlayerAccessor::accessor$seenCredits).create(Keys.CHAT_COLORS_ENABLED).get(ServerPlayerAccessor::accessor$canChatColor).asMutable(ServerPlayerBridge.class).create(Keys.LOCALE).get(ServerPlayerBridge::bridge$getLanguage).create(Keys.HEALTH_SCALE).get(ServerPlayerEntityHealthScaleBridge::bridge$getHealthScale).setAnd((h, v) -> {
if (v < 1f || v > Float.MAX_VALUE) {
return false;
}
h.bridge$setHealthScale(v);
return true;
}).delete(b -> b.bridge$setHealthScale(null)).create(Keys.VIEW_DISTANCE).get(ServerPlayerBridge::bridge$getViewDistance).create(Keys.SKIN_PARTS).get(ServerPlayerBridge::bridge$getSkinParts).create(Keys.IS_SLEEPING_IGNORED).get(ServerPlayerBridge::bridge$sleepingIgnored).set(ServerPlayerBridge::bridge$setSleepingIgnored);
registrator.spongeDataStore(Keys.HEALTH_SCALE.key(), ServerPlayerEntityHealthScaleBridge.class, Keys.HEALTH_SCALE);
SpongeDataManager.INSTANCE.registerLegacySpongeData(Constants.Sponge.Entity.Player.HEALTH_SCALE, Keys.HEALTH_SCALE.key(), Keys.HEALTH_SCALE);
}
Aggregations