Skip to content

Commit

Permalink
Implement ServerPlayerData#Keys.HAS_VIEWED_CREDITS (#3092)
Browse files Browse the repository at this point in the history
Supersedes #3068, credit to i509VCB for the work. This simply converts
it to the new data registration format.

Signed-off-by: Steven Downer <[email protected]>
  • Loading branch information
Grinch authored Jul 26, 2020
1 parent e4388c9 commit 6afa71c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@
public interface ServerPlayerEntityAccessor {

@Accessor("enteredNetherPosition") Vec3d accessor$getEnteredNetherPosition();

@Accessor("seenCredits") boolean accessor$getSeenCredits();

@Accessor("seenCredits") void accessor$setSeenCredits(boolean value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.spongepowered.api.entity.living.player.gamemode.GameMode;
import org.spongepowered.api.profile.property.ProfileProperty;
import org.spongepowered.api.statistic.Statistic;
import org.spongepowered.common.accessor.entity.player.ServerPlayerEntityAccessor;
import org.spongepowered.common.bridge.entity.player.ServerPlayerEntityBridge;
import org.spongepowered.common.bridge.stats.StatisticsManagerBridge;
import org.spongepowered.common.data.provider.DataProviderRegistrator;
Expand Down Expand Up @@ -60,6 +61,10 @@ public static void register(final DataProviderRegistrator registrator) {
.get(h -> ((StatisticsManagerBridge) 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())))
.asMutable(ServerPlayerEntityAccessor.class)
.create(Keys.HAS_VIEWED_CREDITS)
.get(ServerPlayerEntityAccessor::accessor$getSeenCredits)
.set(ServerPlayerEntityAccessor::accessor$setSeenCredits)
.asMutable(ServerPlayerEntityBridge.class)
.create(Keys.HEALTH_SCALE)
.defaultValue(Constants.Entity.Player.DEFAULT_HEALTH_SCALE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ public void setWorldBorder(@Nullable WorldBorder border) {
values.add(this.firstJoined().asImmutable());
values.add(this.lastPlayed().asImmutable());
values.add(this.sleepingIgnored().asImmutable());
values.add(this.hasViewedCredits().asImmutable());

// If getSpectatingEntity returns this player, then we are not spectating any other entity, so spectatorTarget would be an Optional.empty()
this.spectatorTarget().map(Value::asImmutable).ifPresent(values::add);
Expand Down

0 comments on commit 6afa71c

Please sign in to comment.