Search in sources :

Example 1 with SpongeProfileProperty

use of org.spongepowered.common.profile.SpongeProfileProperty 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);
}
Also used : Stat(net.minecraft.stats.Stat) Statistic(org.spongepowered.api.statistic.Statistic) ProfileProperty(org.spongepowered.api.profile.property.ProfileProperty) ChatVisibilities(org.spongepowered.api.entity.living.player.chat.ChatVisibilities) Constants(org.spongepowered.common.util.Constants) Collection(java.util.Collection) ServerPlayerEntityHealthScaleBridge(org.spongepowered.common.bridge.server.level.ServerPlayerEntityHealthScaleBridge) SpongeProfileProperty(org.spongepowered.common.profile.SpongeProfileProperty) Entity(org.spongepowered.api.entity.Entity) Collectors(java.util.stream.Collectors) SpongeDataManager(org.spongepowered.common.data.SpongeDataManager) StatsCounterBridge(org.spongepowered.common.bridge.stats.StatsCounterBridge) ServerPlayer(net.minecraft.server.level.ServerPlayer) ChatVisibility(org.spongepowered.api.entity.living.player.chat.ChatVisibility) Keys(org.spongepowered.api.data.Keys) GameMode(org.spongepowered.api.entity.living.player.gamemode.GameMode) DataProviderRegistrator(org.spongepowered.common.data.provider.DataProviderRegistrator) Property(com.mojang.authlib.properties.Property) ServerPlayerAccessor(org.spongepowered.common.accessor.server.level.ServerPlayerAccessor) ServerPlayerBridge(org.spongepowered.common.bridge.server.level.ServerPlayerBridge) GameType(net.minecraft.world.level.GameType) Entity(org.spongepowered.api.entity.Entity) SpongeProfileProperty(org.spongepowered.common.profile.SpongeProfileProperty) Statistic(org.spongepowered.api.statistic.Statistic) ChatVisibility(org.spongepowered.api.entity.living.player.chat.ChatVisibility) Collection(java.util.Collection) ServerPlayerAccessor(org.spongepowered.common.accessor.server.level.ServerPlayerAccessor) ServerPlayerBridge(org.spongepowered.common.bridge.server.level.ServerPlayerBridge)

Aggregations

Property (com.mojang.authlib.properties.Property)1 Collection (java.util.Collection)1 Collectors (java.util.stream.Collectors)1 ServerPlayer (net.minecraft.server.level.ServerPlayer)1 Stat (net.minecraft.stats.Stat)1 GameType (net.minecraft.world.level.GameType)1 Keys (org.spongepowered.api.data.Keys)1 Entity (org.spongepowered.api.entity.Entity)1 ChatVisibilities (org.spongepowered.api.entity.living.player.chat.ChatVisibilities)1 ChatVisibility (org.spongepowered.api.entity.living.player.chat.ChatVisibility)1 GameMode (org.spongepowered.api.entity.living.player.gamemode.GameMode)1 ProfileProperty (org.spongepowered.api.profile.property.ProfileProperty)1 Statistic (org.spongepowered.api.statistic.Statistic)1 ServerPlayerAccessor (org.spongepowered.common.accessor.server.level.ServerPlayerAccessor)1 ServerPlayerBridge (org.spongepowered.common.bridge.server.level.ServerPlayerBridge)1 ServerPlayerEntityHealthScaleBridge (org.spongepowered.common.bridge.server.level.ServerPlayerEntityHealthScaleBridge)1 StatsCounterBridge (org.spongepowered.common.bridge.stats.StatsCounterBridge)1 SpongeDataManager (org.spongepowered.common.data.SpongeDataManager)1 DataProviderRegistrator (org.spongepowered.common.data.provider.DataProviderRegistrator)1 SpongeProfileProperty (org.spongepowered.common.profile.SpongeProfileProperty)1