9
0
mirror of https://github.com/WiIIiam278/HuskSync.git synced 2025-12-26 18:19:10 +00:00

Now fully reliable and added support for health, max health, etc

This commit is contained in:
William
2021-10-21 02:18:26 +01:00
parent ec6f85250d
commit ba8e4ee175
21 changed files with 281 additions and 155 deletions

View File

@@ -15,41 +15,59 @@ public class PlayerData implements Serializable {
*/
private final UUID dataVersionUUID;
/**
* Serialized inventory data
*/
private final String serializedInventory;
/**
* Serialized ender chest data
*/
// Player data
private final String serializedInventory;
private final String serializedEnderChest;
private final double health;
private final double maxHealth;
private final int hunger;
private final float saturation;
private final int selectedSlot;
private final String serializedEffectData;
/**
* Create a new PlayerData object; a random data version UUID will be selected.
*
* @param playerUUID The UUID of the player
* @param serializedInventory The player's serialized inventory data
* @param playerUUID UUID of the player
* @param serializedInventory Serialized inventory data
* @param serializedEnderChest Serialized ender chest data
* @param health Player health
* @param maxHealth Player max health
* @param hunger Player hunger
* @param saturation Player saturation
* @param selectedSlot Player selected slot
* @param serializedStatusEffects Serialized status effect data
*/
//todo add more stuff, like player health, max health, hunger, saturation and status effects
public PlayerData(UUID playerUUID, String serializedInventory, String serializedEnderChest) {
public PlayerData(UUID playerUUID, String serializedInventory, String serializedEnderChest, double health, double maxHealth, int hunger, float saturation, int selectedSlot, String serializedStatusEffects) {
this.dataVersionUUID = UUID.randomUUID();
this.playerUUID = playerUUID;
this.serializedInventory = serializedInventory;
this.serializedEnderChest = serializedEnderChest;
this.health = health;
this.maxHealth = maxHealth;
this.hunger = hunger;
this.saturation = saturation;
this.selectedSlot = selectedSlot;
this.serializedEffectData = serializedStatusEffects;
}
public PlayerData(UUID playerUUID, UUID dataVersionUUID, String serializedInventory, String serializedEnderChest, double health, double maxHealth, double hunger, double saturation, String serializedStatusEffects) {
public PlayerData(UUID playerUUID, UUID dataVersionUUID, String serializedInventory, String serializedEnderChest, double health, double maxHealth, int hunger, float saturation, int selectedSlot, String serializedStatusEffects) {
this.playerUUID = playerUUID;
this.dataVersionUUID = dataVersionUUID;
this.serializedInventory = serializedInventory;
this.serializedEnderChest = serializedEnderChest;
//todo Incorporate more of these
this.health = health;
this.maxHealth = maxHealth;
this.hunger = hunger;
this.saturation = saturation;
this.selectedSlot = selectedSlot;
this.serializedEffectData = serializedStatusEffects;
}
public static PlayerData EMPTY_PLAYER_DATA(UUID playerUUID) {
return new PlayerData(playerUUID, "", "");
return new PlayerData(playerUUID, "", "", 20,
20, 20, 20, 0, "");
}
public UUID getPlayerUUID() {
@@ -67,4 +85,28 @@ public class PlayerData implements Serializable {
public String getSerializedEnderChest() {
return serializedEnderChest;
}
public double getHealth() {
return health;
}
public double getMaxHealth() {
return maxHealth;
}
public int getHunger() {
return hunger;
}
public float getSaturation() {
return saturation;
}
public int getSelectedSlot() {
return selectedSlot;
}
public String getSerializedEffectData() {
return serializedEffectData;
}
}

View File

@@ -71,10 +71,6 @@ public class RedisMessage {
}
}
public String[] getMessageDataSeparated() {
return messageData.split(MESSAGE_DATA_SEPARATOR);
}
public String getMessageData() {
return messageData;
}
@@ -90,7 +86,7 @@ public class RedisMessage {
/**
* Defines the type of the message
*/
public enum MessageType {
public enum MessageType implements Serializable {
/**
* Sent by Bukkit servers to proxy when a player disconnects with a player's updated data, alongside the UUID of the last loaded {@link PlayerData} for the user
*/
@@ -111,7 +107,7 @@ public class RedisMessage {
* A record that defines the target of a plugin message; a spigot server or the proxy server(s).
* For Bukkit servers, the name of the server must also be specified
*/
public record MessageTarget(Settings.ServerType targetServerType, UUID targetPlayerName) implements Serializable { }
public record MessageTarget(Settings.ServerType targetServerType, UUID targetPlayerUUID) implements Serializable { }
/**
* Deserialize an object from a Base64 string