forked from Upstream/mmocore
mana/stamina/stellium saved when relogging
This commit is contained in:
parent
a8ffe80e50
commit
d3edab7687
@ -1,6 +1,7 @@
|
||||
package net.Indyuce.mmocore.api.player;
|
||||
|
||||
import io.lumine.mythic.lib.api.player.MMOPlayerData;
|
||||
import io.lumine.mythic.lib.player.TemporaryPlayerData;
|
||||
import io.lumine.mythic.lib.player.cooldown.CooldownInfo;
|
||||
import io.lumine.mythic.lib.player.cooldown.CooldownMap;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
@ -98,6 +99,14 @@ public class PlayerData extends OfflinePlayerData implements Closable {
|
||||
this.questData = new PlayerQuests(this);
|
||||
}
|
||||
|
||||
public PlayerData(MMOPlayerData mmoData, TemporaryPlayerData tempData) {
|
||||
this(mmoData);
|
||||
|
||||
mana = tempData.getDouble("mana");
|
||||
stamina = tempData.getDouble("stamina");
|
||||
stellium = tempData.getDouble("stellium");
|
||||
}
|
||||
|
||||
/**
|
||||
* Update all references after /mmocore reload so there can be garbage
|
||||
* collection with old plugin objects like class or skill instances.
|
||||
@ -908,7 +917,7 @@ public class PlayerData extends OfflinePlayerData implements Closable {
|
||||
* @return If player data for that player is loaded
|
||||
*/
|
||||
public static boolean has(Player player) {
|
||||
return has(player.getUniqueId());
|
||||
return has(player.getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,8 @@
|
||||
|
||||
package net.Indyuce.mmocore.listener;
|
||||
|
||||
import io.lumine.mythic.lib.api.event.TemporaryDataSavedEvent;
|
||||
import io.lumine.mythic.lib.player.TemporaryPlayerData;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.event.PlayerResourceUpdateEvent;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
@ -89,4 +91,19 @@ public class PlayerListener implements Listener {
|
||||
event.setAmount(bukkitEvent.getAmount());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* See {@link TemporaryPlayerData} and {@link TemporaryDataSavedEvent}
|
||||
* <p>
|
||||
* This temporarily saves:
|
||||
* - player resources including mana, stamina and stellium
|
||||
*/
|
||||
@EventHandler
|
||||
public void h(TemporaryDataSavedEvent event) {
|
||||
TemporaryPlayerData temp = event.getTemporaryData();
|
||||
PlayerData playerData = PlayerData.get(event.getPlayer().getUniqueId());
|
||||
temp.set("mana", playerData.getMana());
|
||||
temp.set("stamina", playerData.getStamina());
|
||||
temp.set("stellium", playerData.getStellium());
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.Indyuce.mmocore.manager.data;
|
||||
|
||||
import io.lumine.mythic.lib.api.player.MMOPlayerData;
|
||||
import io.lumine.mythic.lib.player.TemporaryPlayerData;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.event.AsyncPlayerDataLoadEvent;
|
||||
import net.Indyuce.mmocore.api.event.PlayerDataLoadEvent;
|
||||
@ -87,7 +88,7 @@ public abstract class PlayerDataManager {
|
||||
|
||||
// Load player data if it does not exist
|
||||
if (!data.containsKey(uniqueId)) {
|
||||
PlayerData newData = new PlayerData(MMOPlayerData.get(uniqueId));
|
||||
PlayerData newData = TemporaryPlayerData.has(uniqueId) ? new PlayerData(MMOPlayerData.get(uniqueId), TemporaryPlayerData.get(uniqueId)) : new PlayerData(MMOPlayerData.get(uniqueId));
|
||||
|
||||
// Schedule async data loading
|
||||
Bukkit.getScheduler().runTaskAsynchronously(MMOCore.plugin, () -> {
|
||||
|
Loading…
Reference in New Issue
Block a user