mirror of
https://github.com/WiIIiam278/HuskSync.git
synced 2025-12-26 01:59:20 +00:00
Make synchronisation much smoother, add Statistics and fix experience syncing
This commit is contained in:
@@ -2,7 +2,7 @@ package me.william278.crossserversync;
|
||||
|
||||
public class MessageStrings {
|
||||
|
||||
public static final StringBuilder PLUGIN_INFORMATION = new StringBuilder().append("[CrossServerSync](#00fb9a bold) [| %proxy_brand% Version %proxy_version% | %bukkit_brand% Version %bukkit_version%](#00fb9a)\n")
|
||||
public static final StringBuilder PLUGIN_INFORMATION = new StringBuilder().append("[CrossServerSync](#00fb9a bold) [| %proxy_brand% Version %proxy_version% (%bukkit_brand% v%bukkit_version%)](#00fb9a)\n")
|
||||
.append("[%plugin_description%](gray)\n")
|
||||
.append("[• Author:](white) [William278](gray show_text=&7Click to pay a visit open_url=https://youtube.com/William27528)\n")
|
||||
.append("[• Help Wiki:](white) [[Link]](#00fb9a show_text=&7Click to open link open_url=https://github.com/WiIIiam278/CrossServerSync/wiki/)\n")
|
||||
@@ -11,4 +11,6 @@ public class MessageStrings {
|
||||
|
||||
public static final String ERROR_INVALID_SYNTAX = "[Error:](#ff3300) [Incorrect syntax. Usage: %1%](#ff7e5e)";
|
||||
|
||||
public static final String SYNCHRONISATION_COMPLETE = "[Data synchronised!](#00fb9a)";
|
||||
|
||||
}
|
||||
@@ -15,6 +15,8 @@ public class PlayerData implements Serializable {
|
||||
*/
|
||||
private final UUID dataVersionUUID;
|
||||
|
||||
// Flag to indicate if the Bukkit server should use default data
|
||||
private boolean useDefaultData = false;
|
||||
|
||||
// Player data
|
||||
private final String serializedInventory;
|
||||
@@ -26,21 +28,31 @@ public class PlayerData implements Serializable {
|
||||
private final float saturationExhaustion;
|
||||
private final int selectedSlot;
|
||||
private final String serializedEffectData;
|
||||
private final int experience;
|
||||
private final int totalExperience;
|
||||
private final int expLevel;
|
||||
private final float expProgress;
|
||||
private final String gameMode;
|
||||
private final String serializedStatistics;
|
||||
|
||||
/**
|
||||
* Create a new PlayerData object; a random data version UUID will be selected.
|
||||
* @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
|
||||
* Constructor to create new PlayerData from a bukkit {@code Player}'s data
|
||||
* @param playerUUID The Player's UUID
|
||||
* @param serializedInventory Their serialized inventory
|
||||
* @param serializedEnderChest Their serialized ender chest
|
||||
* @param health Their health
|
||||
* @param maxHealth Their max health
|
||||
* @param hunger Their hunger
|
||||
* @param saturation Their saturation
|
||||
* @param saturationExhaustion Their saturation exhaustion
|
||||
* @param selectedSlot Their selected hot bar slot
|
||||
* @param serializedStatusEffects Their serialized status effects
|
||||
* @param totalExperience Their total experience points ("Score")
|
||||
* @param expLevel Their exp level
|
||||
* @param expProgress Their exp progress to the next level
|
||||
* @param gameMode Their game mode ({@code SURVIVAL}, {@code CREATIVE}, etc)
|
||||
* @param serializedStatistics Their serialized statistics data (Displayed in Statistics menu in ESC menu)
|
||||
*/
|
||||
public PlayerData(UUID playerUUID, String serializedInventory, String serializedEnderChest, double health, double maxHealth, int hunger, float saturation, float saturationExhaustion, int selectedSlot, String serializedStatusEffects, int experience) {
|
||||
public PlayerData(UUID playerUUID, String serializedInventory, String serializedEnderChest, double health, double maxHealth, int hunger, float saturation, float saturationExhaustion, int selectedSlot, String serializedStatusEffects, int totalExperience, int expLevel, float expProgress, String gameMode, String serializedStatistics) {
|
||||
this.dataVersionUUID = UUID.randomUUID();
|
||||
this.playerUUID = playerUUID;
|
||||
this.serializedInventory = serializedInventory;
|
||||
@@ -52,10 +64,33 @@ public class PlayerData implements Serializable {
|
||||
this.saturationExhaustion = saturationExhaustion;
|
||||
this.selectedSlot = selectedSlot;
|
||||
this.serializedEffectData = serializedStatusEffects;
|
||||
this.experience = experience;
|
||||
this.totalExperience = totalExperience;
|
||||
this.expLevel = expLevel;
|
||||
this.expProgress = expProgress;
|
||||
this.gameMode = gameMode;
|
||||
this.serializedStatistics = serializedStatistics;
|
||||
}
|
||||
|
||||
public PlayerData(UUID playerUUID, UUID dataVersionUUID, String serializedInventory, String serializedEnderChest, double health, double maxHealth, int hunger, float saturation, float saturationExhaustion, int selectedSlot, String serializedStatusEffects, int experience) {
|
||||
/**
|
||||
* Constructor for a PlayerData object from an existing object that was stored in SQL
|
||||
* @param playerUUID The player whose data this is' UUID
|
||||
* @param dataVersionUUID The PlayerData version UUID
|
||||
* @param serializedInventory Their serialized inventory
|
||||
* @param serializedEnderChest Their serialized ender chest
|
||||
* @param health Their health
|
||||
* @param maxHealth Their max health
|
||||
* @param hunger Their hunger
|
||||
* @param saturation Their saturation
|
||||
* @param saturationExhaustion Their saturation exhaustion
|
||||
* @param selectedSlot Their selected hot bar slot
|
||||
* @param serializedStatusEffects Their serialized status effects
|
||||
* @param totalExperience Their total experience points ("Score")
|
||||
* @param expLevel Their exp level
|
||||
* @param expProgress Their exp progress to the next level
|
||||
* @param gameMode Their game mode ({@code SURVIVAL}, {@code CREATIVE}, etc)
|
||||
* @param serializedStatistics Their serialized statistics data (Displayed in Statistics menu in ESC menu)
|
||||
*/
|
||||
public PlayerData(UUID playerUUID, UUID dataVersionUUID, String serializedInventory, String serializedEnderChest, double health, double maxHealth, int hunger, float saturation, float saturationExhaustion, int selectedSlot, String serializedStatusEffects, int totalExperience, int expLevel, float expProgress, String gameMode, String serializedStatistics) {
|
||||
this.playerUUID = playerUUID;
|
||||
this.dataVersionUUID = dataVersionUUID;
|
||||
this.serializedInventory = serializedInventory;
|
||||
@@ -67,12 +102,24 @@ public class PlayerData implements Serializable {
|
||||
this.saturationExhaustion = saturationExhaustion;
|
||||
this.selectedSlot = selectedSlot;
|
||||
this.serializedEffectData = serializedStatusEffects;
|
||||
this.experience = experience;
|
||||
this.totalExperience = totalExperience;
|
||||
this.expLevel = expLevel;
|
||||
this.expProgress = expProgress;
|
||||
this.gameMode = gameMode;
|
||||
this.serializedStatistics = serializedStatistics;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default PlayerData for a new user
|
||||
* @param playerUUID The bukkit Player's UUID
|
||||
* @return Default {@link PlayerData}
|
||||
*/
|
||||
public static PlayerData DEFAULT_PLAYER_DATA(UUID playerUUID) {
|
||||
return new PlayerData(playerUUID, "", "", 20,
|
||||
20, 20, 10, 1, 0, "", 0);
|
||||
PlayerData data = new PlayerData(playerUUID, "", "", 20,
|
||||
20, 20, 10, 1, 0,
|
||||
"", 0, 0, 0, "SURVIVAL", "");
|
||||
data.useDefaultData = true;
|
||||
return data;
|
||||
}
|
||||
|
||||
public UUID getPlayerUUID() {
|
||||
@@ -107,7 +154,9 @@ public class PlayerData implements Serializable {
|
||||
return saturation;
|
||||
}
|
||||
|
||||
public float getSaturationExhaustion() { return saturationExhaustion; }
|
||||
public float getSaturationExhaustion() {
|
||||
return saturationExhaustion;
|
||||
}
|
||||
|
||||
public int getSelectedSlot() {
|
||||
return selectedSlot;
|
||||
@@ -117,5 +166,27 @@ public class PlayerData implements Serializable {
|
||||
return serializedEffectData;
|
||||
}
|
||||
|
||||
public int getExperience() { return experience; }
|
||||
public int getTotalExperience() {
|
||||
return totalExperience;
|
||||
}
|
||||
|
||||
public String getSerializedStatistics() {
|
||||
return serializedStatistics;
|
||||
}
|
||||
|
||||
public int getExpLevel() {
|
||||
return expLevel;
|
||||
}
|
||||
|
||||
public float getExpProgress() {
|
||||
return expProgress;
|
||||
}
|
||||
|
||||
public String getGameMode() {
|
||||
return gameMode;
|
||||
}
|
||||
|
||||
public boolean isUseDefaultData() {
|
||||
return useDefaultData;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,8 @@ public class Settings {
|
||||
public static boolean syncHunger;
|
||||
public static boolean syncExperience;
|
||||
public static boolean syncPotionEffects;
|
||||
public static boolean syncStatistics;
|
||||
public static boolean syncGameMode;
|
||||
|
||||
/*
|
||||
* Enum definitions
|
||||
|
||||
@@ -95,7 +95,7 @@ public class RedisMessage {
|
||||
PLAYER_DATA_UPDATE,
|
||||
|
||||
/**
|
||||
* Sent by Bukkit servers to proxy to request {@link PlayerData} from the proxy.
|
||||
* Sent by Bukkit servers to proxy to request {@link PlayerData} from the proxy if they are set as needing to request data on join.
|
||||
*/
|
||||
PLAYER_DATA_REQUEST,
|
||||
|
||||
@@ -104,12 +104,22 @@ public class RedisMessage {
|
||||
*/
|
||||
PLAYER_DATA_SET,
|
||||
|
||||
/**
|
||||
* Sent by the proxy to a Bukkit server to have them request data on join; contains no data otherwise
|
||||
*/
|
||||
REQUEST_DATA_ON_JOIN,
|
||||
|
||||
/**
|
||||
* Sent by the proxy to ask the Bukkit server to send the full plugin information, contains information about the proxy brand and version
|
||||
*/
|
||||
SEND_PLUGIN_INFORMATION
|
||||
}
|
||||
|
||||
public enum RequestOnJoinUpdateType {
|
||||
ADD_REQUESTER,
|
||||
REMOVE_REQUESTER
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
||||
Reference in New Issue
Block a user