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;
}
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);
}
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);
}
Aggregations