Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-11-15 12:30:06 +01:00
c0936a71bd
Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 01aa02eb PR-858: Add LivingEntity#playHurtAnimation() 9421320f PR-884: Refinements to new ban API for improved compatibility and correctness 37a60b45 SPIGOT-6455, SPIGOT-7030, PR-750: Improve ban API 4eeb174b All smithing inventories are now the new smithing inventory f2bb168e PR-880: Add methods to get/set FallingBlock CancelDrop e7a807fa PR-879: Add Player#sendHealthUpdate() 692b8e96 SPIGOT-7370: Remove float value conversion in plugin.yml 2d033390 SPIGOT-7403: Add direct API for waxed signs 16a08373 PR-876: Add missing Raider API and 'no action ticks' CraftBukkit Changes: b60a95c8c PR-1189: Add LivingEntity#playHurtAnimation() 95c335c63 PR-1226: Fix VehicleEnterEvent not being called for certain entities 0a0fc3bee PR-1227: Refinements to new ban API for improved compatibility and correctness 0d0b1e5dc Revert bad change to PathfinderGoalSit causing all cats to sit 648196070 SPIGOT-6455, SPIGOT-7030, PR-1054: Improve ban API 31fe848d6 All smithing inventories are now the new smithing inventory 9a919a143 SPIGOT-7416: SmithItemEvent not firing in Smithing Table 9f64f0d22 PR-1221: Add methods to get/set FallingBlock CancelDrop 3be9ac171 PR-1220: Add Player#sendHealthUpdate() c1279f775 PR-1209: Clean up various patches c432e4397 Fix Raider#setCelebrating() implementation 504d96665 SPIGOT-7403: Add direct API for waxed signs c68c1f1b3 PR-1216: Add missing Raider API and 'no action ticks' 85b89c3dd Increase outdated build delay Spigot Changes: 9ebce8af Rebuild patches 64b565e6 Rebuild patches
165 Zeilen
6.9 KiB
Diff
165 Zeilen
6.9 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Zach Brown <zach@zachbr.io>
|
|
Date: Wed, 2 Jan 2019 00:35:43 -0600
|
|
Subject: [PATCH] Add APIs to 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.
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
index 56a9cfdb9dc24bd5bda2818b9f59d1a31dfe9265..7cb4f05a8d23a60a89dd4934ccb99bb89bb44141 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -243,6 +243,7 @@ public class ServerPlayer extends Player {
|
|
public int latency;
|
|
public boolean wonGame;
|
|
private int containerUpdateDelay; // Paper
|
|
+ public long loginTime; // Paper
|
|
// Paper start - cancellable death event
|
|
public boolean queueHealthUpdatePacket = false;
|
|
public net.minecraft.network.protocol.game.ClientboundSetHealthPacket queuedHealthUpdatePacket;
|
|
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
index 2bccba03bb12cf17a82c1e54c2bb10535b7c8964..5657493e215a17f3132f9d411424875160fda6d9 100644
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
@@ -189,6 +189,7 @@ public abstract class PlayerList {
|
|
|
|
public void placeNewPlayer(Connection connection, ServerPlayer player) {
|
|
player.isRealPlayer = true; // Paper
|
|
+ player.loginTime = System.currentTimeMillis(); // Paper
|
|
GameProfile gameprofile = player.getGameProfile();
|
|
GameProfileCache usercache = this.server.getProfileCache();
|
|
String s;
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java b/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java
|
|
index 712006c27570dcbcefe173484e74d1bb0763e926..ef48315b98aa39ed245fb7619cf594bfb767931a 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java
|
|
@@ -249,6 +249,61 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
|
|
return this.getData() != null;
|
|
}
|
|
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public long getLastLogin() {
|
|
+ Player player = getPlayer();
|
|
+ if (player != null) return player.getLastLogin();
|
|
+
|
|
+ CompoundTag data = getPaperData();
|
|
+
|
|
+ if (data != null) {
|
|
+ if (data.contains("LastLogin")) {
|
|
+ return data.getLong("LastLogin");
|
|
+ } else {
|
|
+ // if the player file cannot provide accurate data, this is probably the closest we can approximate
|
|
+ File file = getDataFile();
|
|
+ return file.lastModified();
|
|
+ }
|
|
+ } else {
|
|
+ return 0;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public long getLastSeen() {
|
|
+ Player player = getPlayer();
|
|
+ if (player != null) return player.getLastSeen();
|
|
+
|
|
+ CompoundTag data = getPaperData();
|
|
+
|
|
+ if (data != null) {
|
|
+ if (data.contains("LastSeen")) {
|
|
+ return data.getLong("LastSeen");
|
|
+ } else {
|
|
+ // if the player file cannot provide accurate data, this is probably the closest we can approximate
|
|
+ File file = getDataFile();
|
|
+ return file.lastModified();
|
|
+ }
|
|
+ } else {
|
|
+ return 0;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ private CompoundTag getPaperData() {
|
|
+ CompoundTag result = getData();
|
|
+
|
|
+ if (result != null) {
|
|
+ if (!result.contains("Paper")) {
|
|
+ result.put("Paper", new CompoundTag());
|
|
+ }
|
|
+ result = result.getCompound("Paper");
|
|
+ }
|
|
+
|
|
+ return result;
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
@Override
|
|
public Location getLastDeathLocation() {
|
|
if (this.getData().contains("LastDeathLocation", 10)) {
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
index 7db1f6ae9ee30293086f6b0d5fe86965f278c87e..7afaa37d1d6d98fa79f91493897cfe68daf4698c 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
@@ -192,6 +192,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
private org.bukkit.event.player.PlayerResourcePackStatusEvent.Status resourcePackStatus;
|
|
private String resourcePackHash;
|
|
private static final boolean DISABLE_CHANNEL_LIMIT = System.getProperty("paper.disableChannelLimit") != null; // Paper - add a flag to disable the channel limit
|
|
+ private long lastSaveTime;
|
|
// Paper end
|
|
|
|
public CraftPlayer(CraftServer server, ServerPlayer entity) {
|
|
@@ -1903,6 +1904,18 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
this.firstPlayed = firstPlayed;
|
|
}
|
|
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public long getLastLogin() {
|
|
+ return getHandle().loginTime;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public long getLastSeen() {
|
|
+ return isOnline() ? System.currentTimeMillis() : this.lastSaveTime;
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
public void readExtraData(CompoundTag nbttagcompound) {
|
|
this.hasPlayedBefore = true;
|
|
if (nbttagcompound.contains("bukkit")) {
|
|
@@ -1925,6 +1938,8 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
}
|
|
|
|
public void setExtraData(CompoundTag nbttagcompound) {
|
|
+ this.lastSaveTime = System.currentTimeMillis(); // Paper
|
|
+
|
|
if (!nbttagcompound.contains("bukkit")) {
|
|
nbttagcompound.put("bukkit", new CompoundTag());
|
|
}
|
|
@@ -1939,6 +1954,16 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
data.putLong("firstPlayed", this.getFirstPlayed());
|
|
data.putLong("lastPlayed", System.currentTimeMillis());
|
|
data.putString("lastKnownName", handle.getScoreboardName());
|
|
+
|
|
+ // Paper start - persist for use in offline save data
|
|
+ if (!nbttagcompound.contains("Paper")) {
|
|
+ nbttagcompound.put("Paper", new CompoundTag());
|
|
+ }
|
|
+
|
|
+ CompoundTag paper = nbttagcompound.getCompound("Paper");
|
|
+ paper.putLong("LastLogin", handle.loginTime);
|
|
+ paper.putLong("LastSeen", System.currentTimeMillis());
|
|
+ // Paper end
|
|
}
|
|
|
|
@Override
|