Added an event when PlayerData is loaded

This commit is contained in:
Indyuce 2020-04-25 15:51:16 +02:00
parent 00571e12fe
commit 2a64aae0f4
2 changed files with 26 additions and 1 deletions

View File

@ -0,0 +1,22 @@
package net.Indyuce.mmocore.api.event;
import org.bukkit.event.HandlerList;
import net.Indyuce.mmocore.api.player.PlayerData;
public class PlayerDataLoadEvent extends PlayerDataEvent {
private static final HandlerList handlers = new HandlerList();
public PlayerDataLoadEvent(PlayerData playerData) {
super(playerData);
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@ -10,6 +10,7 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.event.PlayerDataLoadEvent;
import net.Indyuce.mmocore.api.player.OfflinePlayerData;
import net.Indyuce.mmocore.api.player.PlayerData;
@ -37,10 +38,12 @@ public abstract class PlayerDataManager {
map.put(player.getUniqueId(), generated);
/*
* loads player data and ONLY THEN refresh the player statistics
* loads player data and ONLY THEN refresh the player statistics and
* calls the load event on the MAIN thread
*/
Bukkit.getScheduler().runTaskAsynchronously(MMOCore.plugin, () -> {
loadData(generated);
Bukkit.getScheduler().runTask(MMOCore.plugin, () -> Bukkit.getPluginManager().callEvent(new PlayerDataLoadEvent(generated)));
generated.getStats().updateStats();
});
}