Replace OfflinePlayer#getLastPlayed

Currently OfflinePlayer#getLastPlayed could more accurately be described
as "OfflinePlayer#getLastTimeTheirDataWasSaved".

The API doc says it should return the last time the server "witnessed"
the player, whilst also saying it should return the last time they
logged in. The current implementation does neither.

Given this interesting contradiction in the API documentation and the
current defacto implementation, I've elected to deprecate (with no
intent to remove) and replace it with two new methods, clearly named and
documented as to their purpose.
This commit is contained in:
Zach Brown
2019-01-02 00:35:43 -06:00
parent f5226d3739
commit f1f016dd5e
4 changed files with 181 additions and 98 deletions

View File

@@ -114,11 +114,12 @@
@Nullable
private Vec3 startingToFallPosition;
@Nullable
@@ -258,7 +293,31 @@
@@ -258,7 +293,32 @@
private final CommandSource commandSource;
private int containerCounter;
public boolean wonGame;
+ private int containerUpdateDelay; // Paper - Configurable container update tick rate
+ public long loginTime; // Paper - Replace OfflinePlayer#getLastPlayed
+ // Paper start - cancellable death event
+ public boolean queueHealthUpdatePacket;
+ public net.minecraft.network.protocol.game.ClientboundSetHealthPacket queuedHealthUpdatePacket;
@@ -146,7 +147,7 @@
public ServerPlayer(MinecraftServer server, ServerLevel world, GameProfile profile, ClientInformation clientOptions) {
super(world, world.getSharedSpawnPos(), world.getSharedSpawnAngle(), profile);
this.chatVisibility = ChatVisiblity.FULL;
@@ -266,7 +325,7 @@
@@ -266,7 +326,7 @@
this.canChatColor = true;
this.lastActionTime = Util.getMillis();
this.requestedViewDistance = 2;
@@ -155,7 +156,7 @@
this.lastSectionPos = SectionPos.of(0, 0, 0);
this.chunkTrackingView = ChunkTrackingView.EMPTY;
this.respawnDimension = Level.OVERWORLD;
@@ -340,6 +399,13 @@
@@ -340,6 +400,13 @@
public void sendSystemMessage(Component message) {
ServerPlayer.this.sendSystemMessage(message);
}
@@ -169,7 +170,7 @@
};
this.textFilter = server.createTextFilterForPlayer(this);
this.gameMode = server.createGameModeForPlayer(this);
@@ -352,14 +418,68 @@
@@ -352,14 +419,68 @@
this.moveTo(this.adjustSpawnLocation(world, world.getSharedSpawnPos()).getBottomCenter(), 0.0F, 0.0F);
this.updateOptions(clientOptions);
this.object = null;
@@ -239,7 +240,7 @@
int i = Math.max(0, this.server.getSpawnRadius(world));
int j = Mth.floor(world.getWorldBorder().getDistanceToBorder((double) basePos.getX(), (double) basePos.getZ()));
@@ -395,14 +515,20 @@
@@ -395,14 +516,20 @@
Objects.requireNonNull(basePos);
crashreportsystemdetails.setDetail("Origin", basePos::toString);
@@ -262,7 +263,7 @@
});
throw new ReportedException(crashreport);
}
@@ -440,7 +566,7 @@
@@ -440,7 +567,7 @@
dataresult = WardenSpawnTracker.CODEC.parse(new Dynamic(NbtOps.INSTANCE, nbt.get("warden_spawn_tracker")));
logger = ServerPlayer.LOGGER;
Objects.requireNonNull(logger);
@@ -271,7 +272,7 @@
this.wardenSpawnTracker = wardenspawntracker;
});
}
@@ -457,17 +583,26 @@
@@ -457,17 +584,26 @@
return this.server.getRecipeManager().byKey(resourcekey).isPresent();
});
}
@@ -299,7 +300,7 @@
Logger logger1 = ServerPlayer.LOGGER;
Objects.requireNonNull(logger1);
@@ -482,7 +617,7 @@
@@ -482,7 +618,7 @@
dataresult = BlockPos.CODEC.parse(NbtOps.INSTANCE, nbtbase);
logger = ServerPlayer.LOGGER;
Objects.requireNonNull(logger);
@@ -308,7 +309,7 @@
this.raidOmenPosition = blockposition;
});
}
@@ -492,7 +627,7 @@
@@ -492,7 +628,7 @@
@Override
public void addAdditionalSaveData(CompoundTag nbt) {
super.addAdditionalSaveData(nbt);
@@ -317,7 +318,7 @@
Logger logger = ServerPlayer.LOGGER;
Objects.requireNonNull(logger);
@@ -526,6 +661,7 @@
@@ -526,6 +662,7 @@
nbt.put("SpawnDimension", nbtbase);
});
}
@@ -325,7 +326,7 @@
nbt.putBoolean("spawn_extra_particles_on_fall", this.spawnExtraParticlesOnFall);
if (this.raidOmenPosition != null) {
@@ -544,7 +680,20 @@
@@ -544,7 +681,20 @@
Entity entity = this.getRootVehicle();
Entity entity1 = this.getVehicle();
@@ -347,7 +348,7 @@
CompoundTag nbttagcompound1 = new CompoundTag();
CompoundTag nbttagcompound2 = new CompoundTag();
@@ -598,12 +747,12 @@
@@ -598,12 +748,12 @@
if (!this.isPassenger()) {
ServerPlayer.LOGGER.warn("Couldn't reattach entity to player");
@@ -362,7 +363,7 @@
}
}
}
@@ -625,7 +774,7 @@
@@ -625,7 +775,7 @@
CompoundTag nbttagcompound1 = new CompoundTag();
entityenderpearl.save(nbttagcompound1);
@@ -371,7 +372,7 @@
Logger logger = ServerPlayer.LOGGER;
Objects.requireNonNull(logger);
@@ -651,7 +800,7 @@
@@ -651,7 +801,7 @@
nbttaglist.forEach((nbtbase1) -> {
if (nbtbase1 instanceof CompoundTag nbttagcompound) {
if (nbttagcompound.contains("ender_pearl_dimension")) {
@@ -380,7 +381,7 @@
Logger logger = ServerPlayer.LOGGER;
Objects.requireNonNull(logger);
@@ -684,7 +833,30 @@
@@ -684,7 +834,30 @@
}
}
@@ -411,7 +412,7 @@
public void setExperiencePoints(int points) {
float f = (float) this.getXpNeededForNextLevel();
@@ -744,6 +916,11 @@
@@ -744,6 +917,11 @@
@Override
public void tick() {
@@ -423,7 +424,7 @@
this.tickClientLoadTimeout();
this.gameMode.tick();
this.wardenSpawnTracker.tick();
@@ -751,9 +928,13 @@
@@ -751,9 +929,13 @@
--this.invulnerableTime;
}
@@ -439,7 +440,7 @@
this.containerMenu = this.inventoryMenu;
}
@@ -820,7 +1001,7 @@
@@ -820,7 +1002,7 @@
}
if (this.getHealth() != this.lastSentHealth || this.lastSentFood != this.foodData.getFoodLevel() || this.foodData.getSaturationLevel() == 0.0F != this.lastFoodSaturationZero) {
@@ -448,7 +449,7 @@
this.lastSentHealth = this.getHealth();
this.lastSentFood = this.foodData.getFoodLevel();
this.lastFoodSaturationZero = this.foodData.getSaturationLevel() == 0.0F;
@@ -851,6 +1032,12 @@
@@ -851,6 +1033,12 @@
this.updateScoreForCriteria(ObjectiveCriteria.EXPERIENCE, Mth.ceil((float) this.lastRecordedExperience));
}
@@ -461,7 +462,7 @@
if (this.experienceLevel != this.lastRecordedLevel) {
this.lastRecordedLevel = this.experienceLevel;
this.updateScoreForCriteria(ObjectiveCriteria.LEVEL, Mth.ceil((float) this.lastRecordedLevel));
@@ -865,6 +1052,20 @@
@@ -865,6 +1053,20 @@
CriteriaTriggers.LOCATION.trigger(this);
}
@@ -482,7 +483,7 @@
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Ticking player");
CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Player being ticked");
@@ -893,7 +1094,7 @@
@@ -893,7 +1095,7 @@
if (this.level().getDifficulty() == Difficulty.PEACEFUL && this.serverLevel().getGameRules().getBoolean(GameRules.RULE_NATURAL_REGENERATION)) {
if (this.tickCount % 20 == 0) {
if (this.getHealth() < this.getMaxHealth()) {
@@ -491,7 +492,7 @@
}
float f = this.foodData.getSaturationLevel();
@@ -946,19 +1147,63 @@
@@ -946,19 +1148,63 @@
}
private void updateScoreForCriteria(ObjectiveCriteria criterion, int score) {
@@ -559,7 +560,7 @@
this.connection.send(new ClientboundPlayerCombatKillPacket(this.getId(), ichatbasecomponent), PacketSendListener.exceptionallySend(() -> {
boolean flag1 = true;
String s = ichatbasecomponent.getString(256);
@@ -988,12 +1233,18 @@
@@ -988,12 +1234,18 @@
if (this.serverLevel().getGameRules().getBoolean(GameRules.RULE_FORGIVE_DEAD_PLAYERS)) {
this.tellNeutralMobsThatIDied();
}
@@ -582,7 +583,7 @@
LivingEntity entityliving = this.getKillCredit();
if (entityliving != null) {
@@ -1028,10 +1279,12 @@
@@ -1028,10 +1280,12 @@
public void awardKillScore(Entity entityKilled, DamageSource damageSource) {
if (entityKilled != this) {
super.awardKillScore(entityKilled, damageSource);
@@ -598,7 +599,7 @@
} else {
this.awardStat(Stats.MOB_KILLS);
}
@@ -1049,7 +1302,8 @@
@@ -1049,7 +1303,8 @@
int i = scoreboardteam.getColor().getId();
if (i >= 0 && i < criterions.length) {
@@ -608,7 +609,7 @@
}
}
@@ -1062,8 +1316,8 @@
@@ -1062,8 +1317,8 @@
} else {
Entity entity = source.getEntity();
@@ -619,7 +620,7 @@
if (!this.canHarmPlayer(entityhuman)) {
return false;
@@ -1074,8 +1328,8 @@
@@ -1074,8 +1329,8 @@
AbstractArrow entityarrow = (AbstractArrow) entity;
Entity entity1 = entityarrow.getOwner();
@@ -630,7 +631,7 @@
if (!this.canHarmPlayer(entityhuman1)) {
return false;
@@ -1083,38 +1337,78 @@
@@ -1083,38 +1338,78 @@
}
}
@@ -717,7 +718,7 @@
}
public static Optional<ServerPlayer.RespawnPosAngle> findRespawnAndUseSpawnBlock(ServerLevel world, BlockPos pos, float spawnAngle, boolean spawnForced, boolean alive) {
@@ -1129,11 +1423,11 @@
@@ -1129,11 +1424,11 @@
}
return optional.map((vec3d) -> {
@@ -731,7 +732,7 @@
});
} else if (!spawnForced) {
return Optional.empty();
@@ -1142,7 +1436,7 @@
@@ -1142,7 +1437,7 @@
BlockState iblockdata1 = world.getBlockState(pos.above());
boolean flag3 = iblockdata1.getBlock().isPossibleToRespawnInThis(iblockdata1);
@@ -740,7 +741,7 @@
}
}
@@ -1160,6 +1454,7 @@
@@ -1160,6 +1455,7 @@
@Nullable
@Override
public ServerPlayer teleport(TeleportTransition teleportTarget) {
@@ -748,7 +749,7 @@
if (this.isRemoved()) {
return null;
} else {
@@ -1169,39 +1464,78 @@
@@ -1169,39 +1465,78 @@
ServerLevel worldserver = teleportTarget.newLevel();
ServerLevel worldserver1 = this.serverLevel();
@@ -835,7 +836,7 @@
this.connection.resetPosition();
worldserver.addDuringTeleport(this);
gameprofilerfiller.pop();
@@ -1215,10 +1549,28 @@
@@ -1215,12 +1550,30 @@
this.lastSentExp = -1;
this.lastSentHealth = -1.0F;
this.lastSentFood = -1;
@@ -847,10 +848,10 @@
return this;
}
}
+ }
+
}
+ // CraftBukkit start
+ @Override
@Override
+ public CraftPortalEvent callPortalEvent(Entity entity, Location exit, TeleportCause cause, int searchRadius, int creationRadius) {
+ Location enter = this.getBukkitEntity().getLocation();
+ PlayerPortalEvent event = new PlayerPortalEvent(this.getBukkitEntity(), enter, exit, cause, searchRadius, true, creationRadius);
@@ -859,12 +860,14 @@
+ return null;
+ }
+ return new CraftPortalEvent(event);
}
+ }
+ // CraftBukkit end
@Override
+
+ @Override
public void forceSetRotation(float yaw, float pitch) {
@@ -1228,13 +1580,21 @@
this.connection.send(new ClientboundPlayerRotationPacket(yaw, pitch));
}
@@ -1228,13 +1581,21 @@
public void triggerDimensionChangeTriggers(ServerLevel origin) {
ResourceKey<Level> resourcekey = origin.dimension();
ResourceKey<Level> resourcekey1 = this.level().dimension();
@@ -889,7 +892,7 @@
this.enteredNetherPosition = null;
}
@@ -1251,36 +1611,63 @@
@@ -1251,36 +1612,63 @@
this.containerMenu.broadcastChanges();
}
@@ -968,7 +971,7 @@
this.awardStat(Stats.SLEEP_IN_BED);
CriteriaTriggers.SLEPT_IN_BED.trigger(this);
});
@@ -1293,9 +1680,8 @@
@@ -1293,9 +1681,8 @@
return either;
}
}
@@ -979,7 +982,7 @@
}
@Override
@@ -1322,13 +1708,31 @@
@@ -1322,13 +1709,31 @@
@Override
public void stopSleepInBed(boolean skipSleepTimer, boolean updateSleepingPlayers) {
@@ -1012,7 +1015,7 @@
}
}
@@ -1387,8 +1791,9 @@
@@ -1387,8 +1792,9 @@
this.connection.send(new ClientboundOpenSignEditorPacket(sign.getBlockPos(), front));
}
@@ -1023,7 +1026,7 @@
}
@Override
@@ -1396,13 +1801,35 @@
@@ -1396,13 +1802,35 @@
if (factory == null) {
return OptionalInt.empty();
} else {
@@ -1059,7 +1062,7 @@
if (container == null) {
if (this.isSpectator()) {
this.displayClientMessage(Component.translatable("container.spectatorCantOpen").withStyle(ChatFormatting.RED), true);
@@ -1410,9 +1837,11 @@
@@ -1410,9 +1838,11 @@
return OptionalInt.empty();
} else {
@@ -1073,7 +1076,7 @@
return OptionalInt.of(this.containerCounter);
}
}
@@ -1425,15 +1854,26 @@
@@ -1425,15 +1855,26 @@
@Override
public void openHorseInventory(AbstractHorse horse, Container inventory) {
@@ -1103,7 +1106,7 @@
this.initMenu(this.containerMenu);
}
@@ -1456,6 +1896,13 @@
@@ -1456,6 +1897,13 @@
@Override
public void closeContainer() {
@@ -1117,7 +1120,7 @@
this.connection.send(new ClientboundContainerClosePacket(this.containerMenu.containerId));
this.doCloseContainer();
}
@@ -1485,19 +1932,19 @@
@@ -1485,19 +1933,19 @@
i = Math.round((float) Math.sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ) * 100.0F);
if (i > 0) {
this.awardStat(Stats.SWIM_ONE_CM, i);
@@ -1140,7 +1143,7 @@
}
} else if (this.onClimbable()) {
if (deltaY > 0.0D) {
@@ -1508,13 +1955,13 @@
@@ -1508,13 +1956,13 @@
if (i > 0) {
if (this.isSprinting()) {
this.awardStat(Stats.SPRINT_ONE_CM, i);
@@ -1157,7 +1160,7 @@
}
}
} else if (this.isFallFlying()) {
@@ -1557,7 +2004,7 @@
@@ -1557,7 +2005,7 @@
@Override
public void awardStat(Stat<?> stat, int amount) {
this.stats.increment(this, stat, amount);
@@ -1166,7 +1169,7 @@
scoreaccess.add(amount);
});
}
@@ -1565,7 +2012,7 @@
@@ -1565,7 +2013,7 @@
@Override
public void resetStat(Stat<?> stat) {
this.stats.setValue(this, stat, 0);
@@ -1175,7 +1178,7 @@
}
@Override
@@ -1597,9 +2044,9 @@
@@ -1597,9 +2045,9 @@
super.jumpFromGround();
this.awardStat(Stats.JUMP);
if (this.isSprinting()) {
@@ -1187,7 +1190,7 @@
}
}
@@ -1625,6 +2072,7 @@
@@ -1625,6 +2073,7 @@
public void resetSentInfo() {
this.lastSentHealth = -1.0E8F;
@@ -1195,7 +1198,7 @@
}
@Override
@@ -1661,7 +2109,7 @@
@@ -1661,7 +2110,7 @@
this.onUpdateAbilities();
if (alive) {
this.getAttributes().assignBaseValues(oldPlayer.getAttributes());
@@ -1204,7 +1207,7 @@
this.setHealth(oldPlayer.getHealth());
this.foodData = oldPlayer.foodData;
Iterator iterator = oldPlayer.getActiveEffects().iterator();
@@ -1669,7 +2117,7 @@
@@ -1669,7 +2118,7 @@
while (iterator.hasNext()) {
MobEffectInstance mobeffect = (MobEffectInstance) iterator.next();
@@ -1213,7 +1216,7 @@
}
this.getInventory().replaceWith(oldPlayer.getInventory());
@@ -1680,7 +2128,7 @@
@@ -1680,7 +2129,7 @@
this.portalProcess = oldPlayer.portalProcess;
} else {
this.getAttributes().assignBaseValues(oldPlayer.getAttributes());
@@ -1222,7 +1225,7 @@
if (this.serverLevel().getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY) || oldPlayer.isSpectator()) {
this.getInventory().replaceWith(oldPlayer.getInventory());
this.experienceLevel = oldPlayer.experienceLevel;
@@ -1696,7 +2144,7 @@
@@ -1696,7 +2145,7 @@
this.lastSentExp = -1;
this.lastSentHealth = -1.0F;
this.lastSentFood = -1;
@@ -1231,7 +1234,7 @@
this.seenCredits = oldPlayer.seenCredits;
this.enteredNetherPosition = oldPlayer.enteredNetherPosition;
this.chunkTrackingView = oldPlayer.chunkTrackingView;
@@ -1752,19 +2200,19 @@
@@ -1752,19 +2201,19 @@
}
@Override
@@ -1255,7 +1258,7 @@
}
return flag1;
@@ -1861,8 +2309,13 @@
@@ -1861,8 +2310,13 @@
}
public void sendChatMessage(OutgoingChatMessage message, boolean filterMaskEnabled, ChatType.Bound params) {
@@ -1270,7 +1273,7 @@
}
}
@@ -1878,7 +2331,18 @@
@@ -1878,7 +2332,18 @@
}
public void updateOptions(ClientInformation clientOptions) {
@@ -1289,7 +1292,7 @@
this.requestedViewDistance = clientOptions.viewDistance();
this.chatVisibility = clientOptions.chatVisibility();
this.canChatColor = clientOptions.chatColors();
@@ -1957,12 +2421,27 @@
@@ -1957,12 +2422,27 @@
this.camera = (Entity) (entity == null ? this : entity);
if (entity1 != this.camera) {
@@ -1318,7 +1321,7 @@
}
if (entity != null) {
@@ -1999,11 +2478,11 @@
@@ -1999,11 +2479,11 @@
@Nullable
public Component getTabListDisplayName() {
@@ -1332,7 +1335,7 @@
}
@Override
@@ -2046,17 +2525,43 @@
@@ -2046,17 +2526,43 @@
}
public void setRespawnPosition(ResourceKey<Level> dimension, @Nullable BlockPos pos, float angle, boolean forced, boolean sendMessage) {
@@ -1383,7 +1386,7 @@
} else {
this.respawnPosition = null;
this.respawnDimension = Level.OVERWORLD;
@@ -2088,18 +2593,44 @@
@@ -2088,18 +2594,44 @@
}
@Override
@@ -1432,7 +1435,7 @@
}
this.awardStat(Stats.DROP);
@@ -2275,9 +2806,15 @@
@@ -2275,9 +2807,15 @@
@Override
public void stopRiding() {
@@ -1449,7 +1452,7 @@
if (entity instanceof LivingEntity entityliving) {
Iterator iterator = entityliving.getActiveEffects().iterator();
@@ -2375,16 +2912,161 @@
@@ -2375,16 +2913,161 @@
return TicketType.ENDER_PEARL.timeout();
}