1.21.5
Co-authored-by: Bjarne Koll <git@lynxplay.dev> Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com> Co-authored-by: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com> Co-authored-by: MiniDigger | Martin <admin@minidigger.dev> Co-authored-by: Nassim Jahnke <nassim@njahnke.dev> Co-authored-by: Noah van der Aa <ndvdaa@gmail.com> Co-authored-by: Owen1212055 <23108066+Owen1212055@users.noreply.github.com> Co-authored-by: Shane Freeder <theboyetronic@gmail.com> Co-authored-by: Spottedleaf <Spottedleaf@users.noreply.github.com> Co-authored-by: Tamion <70228790+notTamion@users.noreply.github.com> Co-authored-by: Warrior <50800980+Warriorrrr@users.noreply.github.com>
This commit is contained in:
@@ -11,11 +11,13 @@ import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import net.minecraft.core.GlobalPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.NbtOps;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.players.UserWhiteListEntry;
|
||||
import net.minecraft.stats.ServerStatsCounter;
|
||||
import net.minecraft.world.level.storage.PlayerDataStorage;
|
||||
import net.minecraft.world.phys.Vec2;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.bukkit.BanEntry;
|
||||
import org.bukkit.BanList;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -24,20 +26,18 @@ import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.Statistic;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.ban.ProfileBanList;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.bukkit.configuration.serialization.SerializableAs;
|
||||
import org.bukkit.craftbukkit.entity.memory.CraftMemoryMapper;
|
||||
import org.bukkit.craftbukkit.profile.CraftPlayerProfile;
|
||||
import org.bukkit.craftbukkit.util.CraftLocation;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.profile.PlayerProfile;
|
||||
|
||||
@SerializableAs("Player")
|
||||
public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializable {
|
||||
private static final org.slf4j.Logger LOGGER = com.mojang.logging.LogUtils.getLogger(); // Paper
|
||||
private final GameProfile profile;
|
||||
private final CraftServer server;
|
||||
private final PlayerDataStorage storage;
|
||||
@@ -46,7 +46,6 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
|
||||
this.server = server;
|
||||
this.profile = profile;
|
||||
this.storage = server.console.playerDataStorage;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -54,12 +53,10 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
|
||||
return this.getPlayer() != null;
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public boolean isConnected() {
|
||||
return false;
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
@@ -76,9 +73,7 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
|
||||
CompoundTag data = this.getBukkitData();
|
||||
|
||||
if (data != null) {
|
||||
if (data.contains("lastKnownName")) {
|
||||
return data.getString("lastKnownName");
|
||||
}
|
||||
return data.getString("lastKnownName").orElse(null);
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -192,17 +187,14 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((this.getUniqueId() == null) || (other.getUniqueId() == null)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.getUniqueId().equals(other.getUniqueId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 5;
|
||||
hash = 97 * hash + (this.getUniqueId() != null ? this.getUniqueId().hashCode() : 0);
|
||||
|
||||
hash = 97 * hash + this.getUniqueId().hashCode();
|
||||
return hash;
|
||||
}
|
||||
|
||||
@@ -214,10 +206,7 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
|
||||
CompoundTag result = this.getData();
|
||||
|
||||
if (result != null) {
|
||||
if (!result.contains("bukkit")) {
|
||||
result.put("bukkit", new CompoundTag());
|
||||
}
|
||||
result = result.getCompound("bukkit");
|
||||
result = result.getCompound("bukkit").orElse(null);
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -235,12 +224,10 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
|
||||
CompoundTag data = this.getBukkitData();
|
||||
|
||||
if (data != null) {
|
||||
if (data.contains("firstPlayed")) {
|
||||
return data.getLong("firstPlayed");
|
||||
} else {
|
||||
return data.getLong("firstPlayed").orElseGet(() -> {
|
||||
File file = this.getDataFile();
|
||||
return file.lastModified();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
@@ -254,12 +241,10 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
|
||||
CompoundTag data = this.getBukkitData();
|
||||
|
||||
if (data != null) {
|
||||
if (data.contains("lastPlayed")) {
|
||||
return data.getLong("lastPlayed");
|
||||
} else {
|
||||
return data.getLong("lastPlayed").orElseGet(() -> {
|
||||
File file = this.getDataFile();
|
||||
return file.lastModified();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
@@ -270,22 +255,19 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
|
||||
return this.getData() != null;
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public long getLastLogin() {
|
||||
Player player = getPlayer();
|
||||
Player player = this.getPlayer();
|
||||
if (player != null) return player.getLastLogin();
|
||||
|
||||
CompoundTag data = getPaperData();
|
||||
CompoundTag data = this.getPaperData();
|
||||
|
||||
if (data != null) {
|
||||
if (data.contains("LastLogin")) {
|
||||
return data.getLong("LastLogin");
|
||||
} else {
|
||||
return data.getLong("LastLogin").orElseGet(() -> {
|
||||
// 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;
|
||||
}
|
||||
@@ -293,39 +275,32 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
|
||||
|
||||
@Override
|
||||
public long getLastSeen() {
|
||||
Player player = getPlayer();
|
||||
Player player = this.getPlayer();
|
||||
if (player != null) return player.getLastSeen();
|
||||
|
||||
CompoundTag data = getPaperData();
|
||||
CompoundTag data = this.getPaperData();
|
||||
|
||||
if (data != null) {
|
||||
if (data.contains("LastSeen")) {
|
||||
return data.getLong("LastSeen");
|
||||
} else {
|
||||
return data.getLong("LastSeen").orElseGet(() -> {
|
||||
// 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();
|
||||
CompoundTag result = this.getData();
|
||||
|
||||
if (result != null) {
|
||||
if (!result.contains("Paper")) {
|
||||
result.put("Paper", new CompoundTag());
|
||||
}
|
||||
result = result.getCompound("Paper");
|
||||
result = result.getCompound("Paper").orElse(null);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
// Paper end
|
||||
|
||||
// Paper start - Add Offline PDC API
|
||||
private static final org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry DATA_TYPE_REGISTRY = new org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry();
|
||||
private io.papermc.paper.persistence.@org.checkerframework.checker.nullness.qual.MonotonicNonNull PersistentDataContainerView persistentDataContainerView;
|
||||
|
||||
@@ -335,7 +310,7 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
|
||||
this.persistentDataContainerView = new io.papermc.paper.persistence.PaperPersistentDataContainerView(DATA_TYPE_REGISTRY) {
|
||||
|
||||
private CompoundTag getPersistentTag() {
|
||||
return net.minecraft.Optionull.map(CraftOfflinePlayer.this.getData(), data -> data.getCompound("BukkitValues"));
|
||||
return net.minecraft.Optionull.map(CraftOfflinePlayer.this.getData(), data -> data.getCompound("BukkitValues").orElse(null));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -351,14 +326,15 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
|
||||
}
|
||||
return this.persistentDataContainerView;
|
||||
}
|
||||
// Paper end - Add Offline PDC API
|
||||
|
||||
@Override
|
||||
public Location getLastDeathLocation() {
|
||||
if (this.getData().contains("LastDeathLocation", 10)) {
|
||||
return GlobalPos.CODEC.parse(NbtOps.INSTANCE, this.getData().get("LastDeathLocation")).result().map(CraftMemoryMapper::fromNms).orElse(null);
|
||||
CompoundTag data = this.getData();
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
|
||||
return data.read("LastDeathLocation", GlobalPos.CODEC).map(CraftLocation::fromGlobalPos).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -368,69 +344,38 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
|
||||
return null;
|
||||
}
|
||||
|
||||
if (data.contains("Pos") && data.contains("Rotation")) {
|
||||
ListTag position = (ListTag) data.get("Pos");
|
||||
ListTag rotation = (ListTag) data.get("Rotation");
|
||||
Vec3 pos = data.read("Pos", Vec3.CODEC).orElse(null);
|
||||
Vec2 rot = data.read("Rotation", Vec2.CODEC).orElse(null);
|
||||
if (pos != null && rot != null) {
|
||||
Long msb = data.getLong("WorldUUIDMost").orElse(null);
|
||||
Long lsb = data.getLong("WorldUUIDLeast").orElse(null);
|
||||
World world = msb != null && lsb != null ? this.server.getWorld(new UUID(msb, lsb)) : null;
|
||||
|
||||
UUID uuid = new UUID(data.getLong("WorldUUIDMost"), data.getLong("WorldUUIDLeast"));
|
||||
|
||||
return new Location(this.server.getWorld(uuid),
|
||||
position.getDouble(0),
|
||||
position.getDouble(1),
|
||||
position.getDouble(2),
|
||||
rotation.getFloat(0),
|
||||
rotation.getFloat(1)
|
||||
return new Location(
|
||||
world,
|
||||
pos.x(), pos.y(), pos.z(),
|
||||
rot.x, rot.y
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getBedSpawnLocation() {
|
||||
return this.getRespawnLocation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getRespawnLocation() {
|
||||
CompoundTag data = this.getData();
|
||||
if (data == null) return null;
|
||||
|
||||
if (data.contains("SpawnX") && data.contains("SpawnY") && data.contains("SpawnZ")) {
|
||||
// Paper start - fix wrong world
|
||||
final float respawnAngle = data.getFloat("SpawnAngle");
|
||||
org.bukkit.World spawnWorld = this.server.getWorld(data.getString("SpawnWorld")); // legacy
|
||||
if (data.contains("SpawnDimension")) {
|
||||
com.mojang.serialization.DataResult<net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level>> result = net.minecraft.world.level.Level.RESOURCE_KEY_CODEC.parse(net.minecraft.nbt.NbtOps.INSTANCE, data.get("SpawnDimension"));
|
||||
net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> levelKey = result.resultOrPartial(LOGGER::error).orElse(net.minecraft.world.level.Level.OVERWORLD);
|
||||
net.minecraft.server.level.ServerLevel level = this.server.console.getLevel(levelKey);
|
||||
spawnWorld = level != null ? level.getWorld() : spawnWorld;
|
||||
final ServerPlayer.RespawnConfig respawnConfig = data.read("respawn", ServerPlayer.RespawnConfig.CODEC).orElse(null);
|
||||
if (respawnConfig != null) {
|
||||
final ServerLevel level = this.server.console.getLevel(respawnConfig.dimension());
|
||||
if (level != null) {
|
||||
return CraftLocation.toBukkit(respawnConfig.pos(), level.getWorld(), respawnConfig.angle(), 0);
|
||||
}
|
||||
if (spawnWorld == null) {
|
||||
return null;
|
||||
}
|
||||
return new Location(spawnWorld, data.getInt("SpawnX"), data.getInt("SpawnY"), data.getInt("SpawnZ"), respawnAngle, 0);
|
||||
// Paper end
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setMetadata(String metadataKey, MetadataValue metadataValue) {
|
||||
this.server.getPlayerMetadata().setMetadata(this, metadataKey, metadataValue);
|
||||
}
|
||||
|
||||
public List<MetadataValue> getMetadata(String metadataKey) {
|
||||
return this.server.getPlayerMetadata().getMetadata(this, metadataKey);
|
||||
}
|
||||
|
||||
public boolean hasMetadata(String metadataKey) {
|
||||
return this.server.getPlayerMetadata().hasMetadata(this, metadataKey);
|
||||
}
|
||||
|
||||
public void removeMetadata(String metadataKey, Plugin plugin) {
|
||||
this.server.getPlayerMetadata().removeMetadata(this, metadataKey, plugin);
|
||||
}
|
||||
|
||||
private ServerStatsCounter getStatisticManager() {
|
||||
return this.server.getHandle().getPlayerStats(this.getUniqueId(), this.getName());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user