|
20 | 20 |
|
21 | 21 | import com.google.common.collect.HashBasedTable; |
22 | 22 | import com.google.common.collect.Table; |
23 | | -import lombok.Getter; |
24 | | -import lombok.Setter; |
25 | | -import lombok.ToString; |
26 | 23 | import org.bukkit.GameMode; |
27 | 24 | import org.bukkit.Material; |
28 | 25 | import org.bukkit.Statistic; |
29 | | -import org.bukkit.attribute.Attribute; |
30 | 26 | import org.bukkit.entity.Player; |
31 | 27 | import org.bukkit.inventory.ItemStack; |
32 | 28 | import org.bukkit.inventory.meta.ItemMeta; |
|
43 | 39 | import java.util.Set; |
44 | 40 | import java.util.UUID; |
45 | 41 |
|
46 | | -@ToString |
47 | | -@Getter |
48 | | -@Setter |
49 | | -public class PlayerData implements Serializable { |
50 | | - private static final long serialVersionUID = -5703536933548893803L; |
51 | | - private final long timeStamp = System.currentTimeMillis(); |
52 | | - private final int dataVersion; |
53 | | - private final UUID playerId; |
54 | | - private final String playerName; |
55 | | - private final GameMode gamemode; |
56 | | - private final int totalExperience; |
57 | | - private final int level; |
58 | | - private final float exp; |
59 | | - private final byte[][] inventory; |
60 | | - private final byte[][] enderchest; |
61 | | - private final Collection<PotionEffect> potionEffects; |
62 | | - private final Set<MapData> maps = new HashSet<>(); |
63 | | - private final double maxHealth; |
64 | | - private final double health; |
65 | | - private final boolean isHealthScaled; |
66 | | - private final double healthScale; |
67 | | - private final int foodLevel; |
68 | | - private final float saturation; |
69 | | - private final float exhaustion; |
70 | | - private final int maxAir; |
71 | | - private final int remainingAir; |
72 | | - private final int fireTicks; |
73 | | - private final int maxNoDamageTicks; |
74 | | - private final int noDamageTicks; |
75 | | - private final float fallDistance; |
76 | | - private final Vector velocity; |
77 | | - private final int heldItemSlot; |
78 | | - private byte[] persistentData = null; |
79 | | - private final Map<String, Map<String, Long>> advancementProgress = new HashMap<>(); |
80 | | - private final Table<Statistic, String, Integer> statistics = HashBasedTable.create(); |
81 | | - private final long lastSeen; |
| 42 | +public record PlayerData(long timeStamp, int dataVersion, UUID playerId, String playerName, GameMode gamemode, |
| 43 | + int totalExperience, int level, float exp, byte[][] inventory, byte[][] enderchest, |
| 44 | + Collection<PotionEffect> potionEffects, Set<MapData> maps, double maxHealth, double health, |
| 45 | + boolean isHealthScaled, double healthScale, int foodLevel, float saturation, float exhaustion, |
| 46 | + int maxAir, int remainingAir, int fireTicks, int maxNoDamageTicks, int noDamageTicks, |
| 47 | + float fallDistance, Vector velocity, int heldItemSlot, byte[] persistentData, |
| 48 | + Map<String, Map<String, Long>> advancementProgress, |
| 49 | + Table<Statistic, String, Integer> statistics, long lastSeen) implements Serializable { |
82 | 50 |
|
83 | | - PlayerData(Player player, long lastSeen) { |
84 | | - this.dataVersion = player.getServer().getUnsafe().getDataVersion(); |
85 | | - this.playerId = player.getUniqueId(); |
86 | | - this.playerName = player.getName(); |
87 | | - this.gamemode = player.getGameMode(); |
88 | | - this.totalExperience = player.getTotalExperience(); |
89 | | - this.level = player.getLevel(); |
90 | | - this.exp = player.getExp(); |
91 | | - this.inventory = serializeItems(player.getInventory().getContents()); |
92 | | - this.enderchest = serializeItems(player.getEnderChest().getContents()); |
93 | | - this.potionEffects = player.getActivePotionEffects(); |
94 | | - this.maxHealth = player.getMaxHealth(); |
95 | | - this.health = player.getHealth(); |
96 | | - this.isHealthScaled = player.isHealthScaled(); |
97 | | - this.healthScale = player.getHealthScale(); |
98 | | - this.foodLevel = player.getFoodLevel(); |
99 | | - this.saturation = player.getSaturation(); |
100 | | - this.exhaustion = player.getExhaustion(); |
101 | | - this.maxAir = player.getMaximumAir(); |
102 | | - this.remainingAir = player.getRemainingAir(); |
103 | | - this.fireTicks = player.getFireTicks(); |
104 | | - this.maxNoDamageTicks = player.getMaximumNoDamageTicks(); |
105 | | - this.noDamageTicks = player.getNoDamageTicks(); |
106 | | - this.velocity = player.getVelocity(); |
107 | | - this.fallDistance = player.getFallDistance(); |
108 | | - this.heldItemSlot = player.getInventory().getHeldItemSlot(); |
109 | | - this.lastSeen = lastSeen; |
| 51 | + public static PlayerData create(Player player, long lastSeen, byte[] persistentData) { |
| 52 | + return new PlayerData( |
| 53 | + System.currentTimeMillis(), |
| 54 | + player.getServer().getUnsafe().getDataVersion(), |
| 55 | + player.getUniqueId(), |
| 56 | + player.getName(), |
| 57 | + player.getGameMode(), |
| 58 | + player.getTotalExperience(), |
| 59 | + player.getLevel(), |
| 60 | + player.getExp(), |
| 61 | + serializeItems(player.getInventory().getContents()), |
| 62 | + serializeItems(player.getEnderChest().getContents()), |
| 63 | + player.getActivePotionEffects(), |
| 64 | + new HashSet<>(), |
| 65 | + player.getMaxHealth(), |
| 66 | + player.getHealth(), |
| 67 | + player.isHealthScaled(), |
| 68 | + player.getHealthScale(), |
| 69 | + player.getFoodLevel(), |
| 70 | + player.getSaturation(), |
| 71 | + player.getExhaustion(), |
| 72 | + player.getMaximumAir(), |
| 73 | + player.getRemainingAir(), |
| 74 | + player.getFireTicks(), |
| 75 | + player.getMaximumNoDamageTicks(), |
| 76 | + player.getNoDamageTicks(), |
| 77 | + player.getFallDistance(), |
| 78 | + player.getVelocity(), |
| 79 | + player.getInventory().getHeldItemSlot(), |
| 80 | + persistentData, |
| 81 | + new HashMap<>(), |
| 82 | + HashBasedTable.create(), |
| 83 | + lastSeen |
| 84 | + ); |
110 | 85 | } |
111 | 86 |
|
112 | 87 | public ItemStack[] getInventoryContents() { |
|
0 commit comments