Added Synchronisation options

feat/data-edit-commands
William 3 years ago
parent 99ce0898da
commit dee8747041

@ -2,6 +2,7 @@ package me.william278.crossserversync.bukkit;
import me.william278.crossserversync.CrossServerSyncBukkit;
import me.william278.crossserversync.PlayerData;
import me.william278.crossserversync.Settings;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
@ -21,18 +22,29 @@ public class PlayerSetter {
*/
public static void setPlayerFrom(Player player, PlayerData data) {
try {
setPlayerInventory(player, DataSerializer.itemStackArrayFromBase64(data.getSerializedInventory()));
setPlayerEnderChest(player, DataSerializer.itemStackArrayFromBase64(data.getSerializedEnderChest()));
player.setHealth(data.getHealth());
player.setMaxHealth(data.getMaxHealth());
player.setFoodLevel(data.getHunger());
player.setSaturation(data.getSaturation());
player.setExhaustion(data.getSaturationExhaustion());
player.getInventory().setHeldItemSlot(data.getSelectedSlot());
player.setTotalExperience(data.getExperience());
//todo potion effects not working
setPlayerPotionEffects(player, DataSerializer.potionEffectArrayFromBase64(data.getSerializedEffectData()));
if (Settings.syncInventories) {
setPlayerInventory(player, DataSerializer.itemStackArrayFromBase64(data.getSerializedInventory()));
player.getInventory().setHeldItemSlot(data.getSelectedSlot());
}
if (Settings.syncEnderChests) {
setPlayerEnderChest(player, DataSerializer.itemStackArrayFromBase64(data.getSerializedEnderChest()));
}
if (Settings.syncHealth) {
player.setHealth(data.getHealth());
player.setMaxHealth(data.getMaxHealth());
}
if (Settings.syncHunger) {
player.setFoodLevel(data.getHunger());
player.setSaturation(data.getSaturation());
player.setExhaustion(data.getSaturationExhaustion());
}
if (Settings.syncExperience) {
player.setTotalExperience(data.getExperience());
}
if (Settings.syncPotionEffects) {
// todo not working ?
setPlayerPotionEffects(player, DataSerializer.potionEffectArrayFromBase64(data.getSerializedEffectData()));
}
} catch (IOException e) {
plugin.getLogger().log(Level.SEVERE, "Failed to deserialize PlayerData", e);
}

@ -10,6 +10,13 @@ public class ConfigLoader {
Settings.redisHost = config.getString("redis_settings.host", "localhost");
Settings.redisPort = config.getInt("redis_settings.port", 6379);
Settings.redisPassword = config.getString("redis_settings.password", "");
Settings.syncInventories = config.getBoolean("synchronisation_settings.inventories", true);
Settings.syncEnderChests = config.getBoolean("synchronisation_settings.ender_chests", true);
Settings.syncHealth = config.getBoolean("synchronisation_settings.health", true);
Settings.syncHunger = config.getBoolean("synchronisation_settings.hunger", true);
Settings.syncExperience = config.getBoolean("synchronisation_settings.experience", true);
Settings.syncPotionEffects = config.getBoolean("synchronisation_settings.potion_effects", true);
}
}

@ -1,4 +1,11 @@
redis_settings:
host: 'localhost'
port: 6379
password: ''
password: ''
synchronisation_settings:
inventories: true
ender_chests: true
health: true
hunger: true
experience: true
potion_effects: true

@ -36,6 +36,18 @@ public class Settings {
public static long hikariKeepAliveTime;
public static long hikariConnectionTimeOut;
/*
* Bukkit server-only settings
*/
// Synchronisation options
public static boolean syncInventories;
public static boolean syncEnderChests;
public static boolean syncHealth;
public static boolean syncHunger;
public static boolean syncExperience;
public static boolean syncPotionEffects;
/*
* Enum definitions
*/

Loading…
Cancel
Save