forked from Upstream/mmocore
Revert "!Fixed: Player data wasn't loading. Added: Event when called when a player used an attribute."
This reverts commit 94968c4739
.
This commit is contained in:
parent
94968c4739
commit
7326cb482e
@ -1,22 +0,0 @@
|
|||||||
package net.Indyuce.mmocore.api.event;
|
|
||||||
|
|
||||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
|
|
||||||
public class PlayerAttributeUseEvent extends PlayerDataEvent{
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
|
|
||||||
public PlayerAttributeUseEvent(PlayerData playerData) {
|
|
||||||
super(playerData);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
}
|
|
@ -92,11 +92,16 @@ public class PlayerData extends OfflinePlayerData {
|
|||||||
this.questData = new PlayerQuests(this);
|
this.questData = new PlayerQuests(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* easily solves some issues where other plugins use PlayerData.get
|
||||||
|
*/
|
||||||
|
public static final PlayerData NOT_LOADED = new PlayerData();
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
private PlayerData() {
|
private PlayerData() {
|
||||||
super(UUID.randomUUID());
|
super(UUID.randomUUID());
|
||||||
|
|
||||||
mmoData = new MMOPlayerData();
|
mmoData = new MMOPlayerData(null, null);
|
||||||
playerStats = new PlayerStats(this);
|
playerStats = new PlayerStats(this);
|
||||||
questData = new PlayerQuests(this, null);
|
questData = new PlayerQuests(this, null);
|
||||||
}
|
}
|
||||||
@ -442,7 +447,7 @@ public class PlayerData extends OfflinePlayerData {
|
|||||||
*
|
*
|
||||||
* @param value Experience to give the player
|
* @param value Experience to give the player
|
||||||
* @param source How the player earned experience
|
* @param source How the player earned experience
|
||||||
* @param hologramLocation Location used to display the hologram. If it's null, no
|
* @param loc Location used to display the hologram. If it's null, no
|
||||||
* hologram will be displayed
|
* hologram will be displayed
|
||||||
*/
|
*/
|
||||||
public void giveExperience(int value, EXPSource source, @Nullable Location hologramLocation) {
|
public void giveExperience(int value, EXPSource source, @Nullable Location hologramLocation) {
|
||||||
@ -784,11 +789,6 @@ public class PlayerData extends OfflinePlayerData {
|
|||||||
return cast;
|
return cast;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return mmoData.hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
return obj instanceof PlayerData && ((PlayerData) obj).getUniqueId().equals(getUniqueId());
|
return obj instanceof PlayerData && ((PlayerData) obj).getUniqueId().equals(getUniqueId());
|
||||||
|
@ -13,6 +13,8 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.attribute.Attribute;
|
import org.bukkit.attribute.Attribute;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
|
||||||
public class RPGPlaceholders extends PlaceholderExpansion {
|
public class RPGPlaceholders extends PlaceholderExpansion {
|
||||||
@ -43,7 +45,7 @@ public class RPGPlaceholders extends PlaceholderExpansion {
|
|||||||
|
|
||||||
@SuppressWarnings("DuplicateExpressions")
|
@SuppressWarnings("DuplicateExpressions")
|
||||||
@Override
|
@Override
|
||||||
public String onRequest(OfflinePlayer player, String identifier) {
|
public String onRequest(@Nullable OfflinePlayer player, @NotNull String identifier) {
|
||||||
PlayerData playerData = PlayerData.get(player);
|
PlayerData playerData = PlayerData.get(player);
|
||||||
|
|
||||||
if (identifier.equals("mana_icon"))
|
if (identifier.equals("mana_icon"))
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package net.Indyuce.mmocore.gui;
|
package net.Indyuce.mmocore.gui;
|
||||||
|
|
||||||
import net.Indyuce.mmocore.api.event.PlayerAttributeUseEvent;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
|
||||||
@ -129,10 +127,6 @@ public class AttributeView extends EditableInventory {
|
|||||||
playerData.giveAttributePoints(-1);
|
playerData.giveAttributePoints(-1);
|
||||||
MMOCore.plugin.configManager.getSimpleMessage("attribute-level-up", "attribute", attribute.getName(), "level", "" + ins.getBase()).send(player);
|
MMOCore.plugin.configManager.getSimpleMessage("attribute-level-up", "attribute", attribute.getName(), "level", "" + ins.getBase()).send(player);
|
||||||
MMOCore.plugin.soundManager.play(getPlayer(), SoundManager.SoundEvent.LEVEL_ATTRIBUTE);
|
MMOCore.plugin.soundManager.play(getPlayer(), SoundManager.SoundEvent.LEVEL_ATTRIBUTE);
|
||||||
|
|
||||||
PlayerAttributeUseEvent playerAttributeUseEvent = new PlayerAttributeUseEvent(playerData);
|
|
||||||
Bukkit.getServer().getPluginManager().callEvent(playerAttributeUseEvent);
|
|
||||||
|
|
||||||
open();
|
open();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@ import org.bukkit.event.entity.EntityRegainHealthEvent;
|
|||||||
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
|
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||||
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
@ -21,21 +20,15 @@ import net.Indyuce.mmocore.api.event.PlayerRegenResourceEvent;
|
|||||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||||
import net.Indyuce.mmocore.api.player.profess.resource.PlayerResource;
|
import net.Indyuce.mmocore.api.player.profess.resource.PlayerResource;
|
||||||
import net.Indyuce.mmocore.gui.api.PluginInventory;
|
import net.Indyuce.mmocore.gui.api.PluginInventory;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener {
|
public class PlayerListener implements Listener {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
We load our player data.
|
* initialize player data
|
||||||
*/
|
*/
|
||||||
@EventHandler(priority = EventPriority.NORMAL)
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
public void playerLoadingEvent(PlayerJoinEvent e) {
|
public void a(PlayerJoinEvent event) {
|
||||||
new BukkitRunnable() {
|
MMOCore.plugin.dataProvider.getDataManager().setup(event.getPlayer().getUniqueId());
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
MMOCore.plugin.dataProvider.getDataManager().setup(e.getPlayer().getUniqueId());
|
|
||||||
}
|
|
||||||
}.runTaskAsynchronously(MMOCore.plugin);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package net.Indyuce.mmocore.manager.data;
|
package net.Indyuce.mmocore.manager.data;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
@ -11,11 +14,9 @@ import net.Indyuce.mmocore.api.event.PlayerDataLoadEvent;
|
|||||||
import net.Indyuce.mmocore.api.player.OfflinePlayerData;
|
import net.Indyuce.mmocore.api.player.OfflinePlayerData;
|
||||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||||
import io.lumine.mythic.lib.api.player.MMOPlayerData;
|
import io.lumine.mythic.lib.api.player.MMOPlayerData;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
|
||||||
|
|
||||||
public abstract class PlayerDataManager {
|
public abstract class PlayerDataManager {
|
||||||
private final static Map<UUID, PlayerData> data = Collections.synchronizedMap(new HashMap<>());
|
private final static Map<UUID, PlayerData> data = new HashMap<>();
|
||||||
|
|
||||||
private DefaultPlayerData defaultData = new DefaultPlayerData(1, 0, 0, 0, 0);
|
private DefaultPlayerData defaultData = new DefaultPlayerData(1, 0, 0, 0, 0);
|
||||||
|
|
||||||
public PlayerData get(OfflinePlayer player) {
|
public PlayerData get(OfflinePlayer player) {
|
||||||
@ -32,29 +33,34 @@ public abstract class PlayerDataManager {
|
|||||||
|
|
||||||
public abstract OfflinePlayerData getOffline(UUID uuid);
|
public abstract OfflinePlayerData getOffline(UUID uuid);
|
||||||
|
|
||||||
public PlayerData setup(UUID uniqueId) {
|
public PlayerData setup(UUID uuid) {
|
||||||
return data.compute(uniqueId, (uuid, searchData) -> {
|
/*
|
||||||
if (searchData == null) {
|
* Setup playerData based on loadData method to support both MySQL and
|
||||||
PlayerData playerData = new PlayerData(MMOPlayerData.get(uniqueId));
|
* YAML data storage
|
||||||
|
*/
|
||||||
|
PlayerData playerData = data.get(uuid);
|
||||||
|
if (playerData == null) {
|
||||||
|
playerData = data.put(uuid, new PlayerData(MMOPlayerData.get(uuid)));
|
||||||
|
|
||||||
loadData(playerData);
|
/*
|
||||||
playerData.getStats().updateStats();
|
* Loads player data and ONLY THEN refresh the player statistics and
|
||||||
|
* calls the load event on the MAIN thread
|
||||||
// We call the player data load event. TODO: Convert this event to async.
|
*/
|
||||||
new BukkitRunnable() {
|
Bukkit.getScheduler().runTaskAsynchronously(MMOCore.plugin, () -> {
|
||||||
@Override
|
PlayerData loaded = PlayerData.get(uuid);
|
||||||
public void run() {
|
if (!loaded.isOnline())
|
||||||
Bukkit.getPluginManager().callEvent(new PlayerDataLoadEvent(playerData));
|
return;
|
||||||
}
|
loadData(loaded);
|
||||||
}.runTask(MMOCore.plugin);
|
Bukkit.getScheduler().runTask(MMOCore.plugin, () -> {
|
||||||
|
if (loaded.isOnline())
|
||||||
return playerData;
|
Bukkit.getPluginManager().callEvent(new PlayerDataLoadEvent(loaded));
|
||||||
} else return searchData;
|
});
|
||||||
|
loaded.getStats().updateStats();
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
return playerData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public DefaultPlayerData getDefaultData() {
|
public DefaultPlayerData getDefaultData() {
|
||||||
return defaultData;
|
return defaultData;
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ main: net.Indyuce.mmocore.MMOCore
|
|||||||
author: Indyuce
|
author: Indyuce
|
||||||
description: ${project.description}
|
description: ${project.description}
|
||||||
loadbefore: [MMOItems]
|
loadbefore: [MMOItems]
|
||||||
depend: [MythicLib]
|
depend: [MMOLib]
|
||||||
softdepend: [Vault,MythicMobs,PlaceholderAPI,Residence]
|
softdepend: [Vault,MythicMobs,PlaceholderAPI,Residence]
|
||||||
api-version: 1.13
|
api-version: 1.13
|
||||||
commands:
|
commands:
|
||||||
|
Loading…
Reference in New Issue
Block a user