Search in sources :

Example 1 with Statistic

use of org.spongepowered.api.statistic.Statistic in project SpongeCommon by SpongePowered.

the class StatisticDataProcessor method set.

@Override
protected boolean set(EntityPlayerMP player, Map<Statistic, Long> statMap) {
    checkNotNull(player, "null player");
    checkNotNull(statMap, "null stat map");
    StatisticsManagerServer stats = player.getStatFile();
    for (Entry<Statistic, Long> statEntry : statMap.entrySet()) {
        Long value = statEntry.getValue();
        StatBase stat = (StatBase) statEntry.getKey();
        int currentValue = stats.readStat(stat);
        if (value != null) {
            stats.increaseStat(player, (StatBase) statEntry.getKey(), (int) (value - currentValue));
        }
    }
    return true;
}
Also used : Statistic(org.spongepowered.api.statistic.Statistic) StatisticsManagerServer(net.minecraft.stats.StatisticsManagerServer) StatBase(net.minecraft.stats.StatBase)

Example 2 with Statistic

use of org.spongepowered.api.statistic.Statistic in project SpongeCommon by SpongePowered.

the class StatisticDataProcessor method getVal.

@Override
protected Optional<Map<Statistic, Long>> getVal(EntityPlayerMP player) {
    checkNotNull(player, "null player");
    StatisticsManagerServer stats = player.getStatFile();
    Map<StatBase, TupleIntJsonSerializable> data = ((IMixinStatisticsManager) stats).getStatsData();
    Map<Statistic, Long> statMap = Maps.newHashMap();
    for (Entry<StatBase, TupleIntJsonSerializable> statEntry : data.entrySet()) {
        statMap.put((Statistic) statEntry.getKey(), (long) statEntry.getValue().getIntegerValue());
    }
    return Optional.of(statMap);
}
Also used : TupleIntJsonSerializable(net.minecraft.util.TupleIntJsonSerializable) IMixinStatisticsManager(org.spongepowered.common.interfaces.statistic.IMixinStatisticsManager) Statistic(org.spongepowered.api.statistic.Statistic) StatisticsManagerServer(net.minecraft.stats.StatisticsManagerServer) StatBase(net.minecraft.stats.StatBase)

Example 3 with Statistic

use of org.spongepowered.api.statistic.Statistic 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

Statistic (org.spongepowered.api.statistic.Statistic)3 StatBase (net.minecraft.stats.StatBase)2 StatisticsManagerServer (net.minecraft.stats.StatisticsManagerServer)2 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 TupleIntJsonSerializable (net.minecraft.util.TupleIntJsonSerializable)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 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