diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/MMOCoreAPI.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/MMOCoreAPI.java index a4d398b2..29b281e8 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/MMOCoreAPI.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/MMOCoreAPI.java @@ -25,7 +25,7 @@ public class MMOCoreAPI { } public PlayerData getPlayerData(OfflinePlayer player) { - return PlayerData.get(player.getUniqueId()); + return PlayerData.get(player); } public boolean isInSameParty(Player player1, Player player2) { diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/event/PlayerEnterCastingModeEvent.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/event/PlayerEnterCastingModeEvent.java index bc40bd99..857fdc5e 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/event/PlayerEnterCastingModeEvent.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/event/PlayerEnterCastingModeEvent.java @@ -11,7 +11,7 @@ public class PlayerEnterCastingModeEvent extends PlayerDataEvent implements Canc private boolean cancelled = false; public PlayerEnterCastingModeEvent(@NotNull Player who) { - super(PlayerData.get(who.getUniqueId())); + super(PlayerData.get(who)); } @Override diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/event/PlayerExitCastingModeEvent.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/event/PlayerExitCastingModeEvent.java index 6f859a32..0dbfb910 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/event/PlayerExitCastingModeEvent.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/event/PlayerExitCastingModeEvent.java @@ -12,7 +12,7 @@ public class PlayerExitCastingModeEvent extends PlayerDataEvent implements Cance private boolean cancelled = false; public PlayerExitCastingModeEvent(@NotNull Player who) { - super(PlayerData.get(who.getUniqueId())); + super(PlayerData.get(who)); } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java index bb20021f..e75449dc 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java @@ -1252,11 +1252,15 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD return getMMOPlayerData().hashCode(); } - public static PlayerData get(OfflinePlayer player) { + public static PlayerData get(@NotNull MMOPlayerData playerData) { + return get(playerData.getPlayer()); + } + + public static PlayerData get(@NotNull OfflinePlayer player) { return get(player.getUniqueId()); } - public static PlayerData get(UUID uuid) { + public static PlayerData get(@NotNull UUID uuid) { return MMOCore.plugin.dataProvider.getDataManager().get(uuid); } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/attribute/AttributeModifier.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/attribute/AttributeModifier.java index 7dd53051..fb171884 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/attribute/AttributeModifier.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/attribute/AttributeModifier.java @@ -107,13 +107,13 @@ public class AttributeModifier extends PlayerModifier { @Override public void register(MMOPlayerData mmoPlayerData) { - PlayerData playerData = PlayerData.get(mmoPlayerData.getUniqueId()); + PlayerData playerData = PlayerData.get(mmoPlayerData); playerData.getAttributes().getInstance(attribute).addModifier(this); } @Override public void unregister(MMOPlayerData mmoPlayerData) { - PlayerData playerData = PlayerData.get(mmoPlayerData.getUniqueId()); + PlayerData playerData = PlayerData.get(mmoPlayerData); playerData.getAttributes().getInstance(attribute).removeModifier(getKey()); } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/attribute/MMOCoreAttributeStatHandler.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/attribute/MMOCoreAttributeStatHandler.java index 8cebc77b..841b494f 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/attribute/MMOCoreAttributeStatHandler.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/attribute/MMOCoreAttributeStatHandler.java @@ -30,7 +30,7 @@ public class MMOCoreAttributeStatHandler extends StatHandler { @Override public void runUpdate(StatInstance instance) { try { - final PlayerData playerData = MMOCore.plugin.dataProvider.getDataManager().get(instance.getMap().getPlayerData().getUniqueId()); + final PlayerData playerData = PlayerData.get(instance.getMap().getPlayerData()); playerData.getAttributes().getInstance(attr).updateStats(); } catch (NullPointerException exception) { // Player data is not loaded yet so there's nothing to update. diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/event/trigger/AttackEventTrigger.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/event/trigger/AttackEventTrigger.java index 87f2e978..6c611bd3 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/event/trigger/AttackEventTrigger.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/event/trigger/AttackEventTrigger.java @@ -21,7 +21,7 @@ public class AttackEventTrigger implements EventTriggerHandler { // We don't want players dying by themselves when using an enderpearl. if (event.getPlayer().equals(event.getEntity())) return; - PlayerData player = PlayerData.get(event.getData().getUniqueId()); + PlayerData player = PlayerData.get(event.getData()); PlayerClass profess = player.getProfess(); for (DamageType type : event.getAttack().getDamage().collectTypes()) { diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/PvpModeCommand.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/PvpModeCommand.java index 029c6917..6f6a79e9 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/PvpModeCommand.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/PvpModeCommand.java @@ -30,7 +30,7 @@ public class PvpModeCommand extends RegisteredCommand { return false; } - final PlayerData playerData = PlayerData.get(((Player) sender).getUniqueId()); + final PlayerData playerData = PlayerData.get((Player) sender); // Command cooldown if (playerData.getCooldownMap().isOnCooldown(COOLDOWN_KEY)) { diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/comp/profile/ForceClassProfileDataModule.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/comp/profile/ForceClassProfileDataModule.java index 43d84994..d69f2c80 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/comp/profile/ForceClassProfileDataModule.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/comp/profile/ForceClassProfileDataModule.java @@ -46,7 +46,7 @@ public class ForceClassProfileDataModule implements ProfileDataModule, Listener return; } - final PlayerData playerData = PlayerData.get(event.getPlayerData().getUniqueId()); + final PlayerData playerData = PlayerData.get(event.getPlayerData().getPlayer()); InventoryManager.CLASS_SELECT.newInventory(playerData, () -> event.validate(this)).open(); } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/experience/source/KillMobExperienceSource.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/experience/source/KillMobExperienceSource.java index 7a72c5b8..a27b9e91 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/experience/source/KillMobExperienceSource.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/experience/source/KillMobExperienceSource.java @@ -53,7 +53,7 @@ public class KillMobExperienceSource extends SpecificExperienceSource { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void registerLastAttacker(PlayerAttackEvent event) { - registry.getRegistry().put(event.getEntity().getUniqueId(), event.getAttacker().getData().getUniqueId()); + registry.getRegistry().put(event.getEntity().getUniqueId(), event.getAttacker().getPlayer().getUniqueId()); } @EventHandler(priority = EventPriority.MONITOR) diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java index 14a5ccf7..a5855bf7 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java @@ -240,7 +240,7 @@ public class ConfigManager { String msg = hasPlaceholders ? MMOCore.plugin.placeholderParser.parse(player, message) : message; if (!msg.isEmpty()) { - if (actionbar) PlayerData.get(player.getUniqueId()).displayActionBar(msg); + if (actionbar) PlayerData.get(player).displayActionBar(msg); else player.sendMessage(msg); } return !msg.isEmpty(); diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/sql/PlayerDataTableUpdater.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/sql/PlayerDataTableUpdater.java index 2b744abb..2088093e 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/sql/PlayerDataTableUpdater.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/sql/PlayerDataTableUpdater.java @@ -12,10 +12,7 @@ import org.jetbrains.annotations.Nullable; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.logging.Level; /** @@ -25,16 +22,18 @@ import java.util.logging.Level; public class PlayerDataTableUpdater { private final PlayerData playerData; private final SQLDataSource provider; + private final UUID effectiveId; private final Map requestMap = new HashMap<>(); public PlayerDataTableUpdater(SQLDataSource provider, PlayerData playerData) { this.playerData = playerData; this.provider = provider; + this.effectiveId = playerData.getEffectiveId(); } public void executeRequest(boolean autosave) { final String request = "INSERT INTO mmocore_playerdata(uuid, " + formatCollection(requestMap.keySet(), false) - + ") VALUES('" + playerData.getProfileId() + "'," + formatCollection(requestMap.values(), true) + ")" + + + ") VALUES('" + effectiveId + "'," + formatCollection(requestMap.values(), true) + ")" + " ON DUPLICATE KEY UPDATE " + formatMap() + ";"; try { @@ -44,21 +43,21 @@ public class PlayerDataTableUpdater { try { statement.executeUpdate(); } catch (SQLException exception) { - MMOCore.log(Level.WARNING, "Could not save player data of " + playerData.getProfileId() + ", saving through YAML instead"); + MMOCore.log(Level.WARNING, "Could not save player data of " + effectiveId + ", saving through YAML instead"); new YAMLPlayerDataHandler(MMOCore.plugin).saveData(playerData, autosave); exception.printStackTrace(); } finally { statement.close(); } } catch (SQLException exception) { - MMOCore.log(Level.WARNING, "Could not save player data of " + playerData.getProfileId() + ", saving through YAML instead"); + MMOCore.log(Level.WARNING, "Could not save player data of " + effectiveId + ", saving through YAML instead"); new YAMLPlayerDataHandler(MMOCore.plugin).saveData(playerData, autosave); exception.printStackTrace(); } finally { connection.close(); } } catch (SQLException exception) { - MMOCore.log(Level.WARNING, "Could not save player data of " + playerData.getProfileId() + ", saving through YAML instead"); + MMOCore.log(Level.WARNING, "Could not save player data of " + effectiveId + ", saving through YAML instead"); new YAMLPlayerDataHandler(MMOCore.plugin).saveData(playerData, autosave); exception.printStackTrace(); } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/sql/SQLDataHandler.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/sql/SQLDataHandler.java index edfe5733..d0bbda26 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/sql/SQLDataHandler.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/sql/SQLDataHandler.java @@ -92,7 +92,8 @@ public class SQLDataHandler extends SQLSynchronizedDataHandler list = new ArrayList<>(); for (Player online : party.getOnlineMembers()) - list.add(PlayerData.get(online.getUniqueId())); + list.add(PlayerData.get(online)); return list; } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/compat/OBTeamPartyModule.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/compat/OBTeamPartyModule.java index 72217bc3..f5fd7c5f 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/compat/OBTeamPartyModule.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/compat/OBTeamPartyModule.java @@ -44,7 +44,7 @@ public class OBTeamPartyModule implements PartyModule, Listener { for (TeamMember member : team.getMembersAndOwner()) try { - list.add(PlayerData.get(member.getOfflinePlayer().getUniqueId())); + list.add(PlayerData.get(member.getOfflinePlayer())); } catch (Exception ignored) { } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/compat/PartiesPartyModule.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/compat/PartiesPartyModule.java index 07edf5da..37a0fa16 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/compat/PartiesPartyModule.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/compat/PartiesPartyModule.java @@ -19,16 +19,16 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; -public class PartiesPartyModule implements PartyModule,Listener { +public class PartiesPartyModule implements PartyModule, Listener { - public PartiesPartyModule(){ - Bukkit.getPluginManager().registerEvents(this,MMOCore.plugin); + public PartiesPartyModule() { + Bukkit.getPluginManager().registerEvents(this, MMOCore.plugin); } @Nullable @Override public AbstractParty getParty(PlayerData playerData) { - PartiesAPI api= Parties.getApi(); + PartiesAPI api = Parties.getApi(); PartyPlayer partyPlayer = api.getPartyPlayer(playerData.getUniqueId()); Party party = api.getParty(partyPlayer.getPartyId()); return party == null ? null : new CustomParty(party); @@ -36,23 +36,24 @@ public class PartiesPartyModule implements PartyModule,Listener { @EventHandler - public void onPlayerJoin(BukkitPartiesPlayerPostJoinEvent event){ - int membersSize=event.getParty().getMembers().size(); + public void onPlayerJoin(BukkitPartiesPlayerPostJoinEvent event) { + int membersSize = event.getParty().getMembers().size(); event.getParty().getOnlineMembers() - .forEach(p-> applyStatBonuses(PlayerData.get(p.getPlayerUUID()),membersSize)); + .forEach(p -> applyStatBonuses(PlayerData.get(p.getPlayerUUID()), membersSize)); } + @EventHandler - public void onPlayerLeave(BukkitPartiesPlayerPostLeaveEvent event){ - int membersSize=event.getParty().getMembers().size(); + public void onPlayerLeave(BukkitPartiesPlayerPostLeaveEvent event) { + int membersSize = event.getParty().getMembers().size(); clearStatBonuses(PlayerData.get(event.getPartyPlayer().getPlayerUUID())); event.getParty().getOnlineMembers() - .forEach(p-> applyStatBonuses(PlayerData.get(p.getPlayerUUID()),membersSize)); + .forEach(p -> applyStatBonuses(PlayerData.get(p.getPlayerUUID()), membersSize)); } /** * Applies party stat bonuses to a specific player */ - private void applyStatBonuses(PlayerData player,int membersSize) { + private void applyStatBonuses(PlayerData player, int membersSize) { MMOCore.plugin.partyManager.getBonuses().forEach(buff -> buff.multiply(membersSize - 1).register(player.getMMOPlayerData())); } @@ -63,7 +64,7 @@ public class PartiesPartyModule implements PartyModule,Listener { MMOCore.plugin.partyManager.getBonuses().forEach(buff -> buff.unregister(player.getMMOPlayerData())); } - class CustomParty implements AbstractParty { + class CustomParty implements AbstractParty { private final Party party; public CustomParty(Party party) { diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/CastableSkill.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/CastableSkill.java index c3c410bf..ff7192c1 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/CastableSkill.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/CastableSkill.java @@ -44,7 +44,7 @@ public class CastableSkill extends Skill { @Override public boolean getResult(SkillMetadata skillMeta) { - PlayerData playerData = PlayerData.get(skillMeta.getCaster().getData().getUniqueId()); + PlayerData playerData = PlayerData.get(skillMeta.getCaster().getData()); boolean loud = !getTrigger().isSilent(); // Skill is not usable yet @@ -88,7 +88,7 @@ public class CastableSkill extends Skill { @Override public void whenCast(SkillMetadata skillMeta) { - PlayerData casterData = PlayerData.get(skillMeta.getCaster().getData().getUniqueId()); + PlayerData casterData = PlayerData.get(skillMeta.getCaster().getData()); // Apply cooldown, mana and stamina costs if (!casterData.noCooldown) { diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/KeyCombos.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/KeyCombos.java index 8f780afe..e67a6310 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/KeyCombos.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/KeyCombos.java @@ -155,7 +155,7 @@ public class KeyCombos implements SkillCastingListener { @EventHandler public void ignoreOtherSkills(PlayerCastSkillEvent event) { TriggerType triggerType = event.getCast().getTrigger(); - if (IGNORED_WHEN_CASTING.contains(triggerType) && PlayerData.get(event.getData().getUniqueId()).isCasting()) + if (IGNORED_WHEN_CASTING.contains(triggerType) && PlayerData.get(event.getData()).isCasting()) event.setCancelled(true); } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/list/Ambers.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/list/Ambers.java index de1551a4..4efa9664 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/list/Ambers.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/list/Ambers.java @@ -85,7 +85,7 @@ public class Ambers extends SkillHandler implements Listener // data.getSkillData().ambers++; // Give mana back - PlayerData playerData = PlayerData.get(data.getUniqueId()); + PlayerData playerData = PlayerData.get(data); double missingMana = data.getStatMap().getStat("MAX_MANA") - playerData.getMana(); playerData.giveMana(missingMana * percent, PlayerResourceUpdateEvent.UpdateReason.SKILL_REGENERATION); diff --git a/MMOCore-Dist/src/main/java/net/Indyuce/mmocore/listener/PlayerListener.java b/MMOCore-Dist/src/main/java/net/Indyuce/mmocore/listener/PlayerListener.java index 96c03714..0e7d9faa 100644 --- a/MMOCore-Dist/src/main/java/net/Indyuce/mmocore/listener/PlayerListener.java +++ b/MMOCore-Dist/src/main/java/net/Indyuce/mmocore/listener/PlayerListener.java @@ -10,6 +10,7 @@ import net.Indyuce.mmocore.api.player.profess.resource.PlayerResource; import net.Indyuce.mmocore.gui.api.InventoryClickContext; import net.Indyuce.mmocore.gui.api.PluginInventory; import org.bukkit.Bukkit; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -55,7 +56,7 @@ public class PlayerListener implements Listener { public void updateCombat(EntityDamageEvent event) { if (UtilityMethods.isFakeEvent(event)) return; if (UtilityMethods.isRealPlayer(event.getEntity()) && MMOCore.plugin.configManager.combatLogDamageCauses.contains(event.getCause())) - PlayerData.get(event.getEntity().getUniqueId()).getCombat().update(); + PlayerData.get((Player) event.getEntity()).getCombat().update(); } /** diff --git a/MMOCore-Dist/src/main/java/net/Indyuce/mmocore/listener/option/PlayerProfileCheck.java b/MMOCore-Dist/src/main/java/net/Indyuce/mmocore/listener/option/PlayerProfileCheck.java index 52b5cbc1..dcdc5f37 100644 --- a/MMOCore-Dist/src/main/java/net/Indyuce/mmocore/listener/option/PlayerProfileCheck.java +++ b/MMOCore-Dist/src/main/java/net/Indyuce/mmocore/listener/option/PlayerProfileCheck.java @@ -5,6 +5,7 @@ import io.lumine.mythic.lib.comp.interaction.InteractionType; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.manager.InventoryManager; import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerInteractEntityEvent; @@ -16,6 +17,6 @@ public class PlayerProfileCheck implements Listener { if (event.getRightClicked().getType() != EntityType.PLAYER || !event.getPlayer().isSneaking() || !MythicLib.plugin.getEntities().canTarget(event.getPlayer(), event.getRightClicked(), InteractionType.SUPPORT_ACTION)) return; - InventoryManager.PLAYER_STATS.newInventory(PlayerData.get(event.getRightClicked().getUniqueId()), PlayerData.get(event.getPlayer())).open(); + InventoryManager.PLAYER_STATS.newInventory(PlayerData.get((Player) event.getRightClicked()), PlayerData.get(event.getPlayer())).open(); } }