More proxy profiles fixing

This commit is contained in:
Jules 2023-08-27 22:26:04 +02:00
parent d050b708cc
commit 3efc5b86fb
22 changed files with 51 additions and 44 deletions

View File

@ -25,7 +25,7 @@ public class MMOCoreAPI {
} }
public PlayerData getPlayerData(OfflinePlayer player) { public PlayerData getPlayerData(OfflinePlayer player) {
return PlayerData.get(player.getUniqueId()); return PlayerData.get(player);
} }
public boolean isInSameParty(Player player1, Player player2) { public boolean isInSameParty(Player player1, Player player2) {

View File

@ -11,7 +11,7 @@ public class PlayerEnterCastingModeEvent extends PlayerDataEvent implements Canc
private boolean cancelled = false; private boolean cancelled = false;
public PlayerEnterCastingModeEvent(@NotNull Player who) { public PlayerEnterCastingModeEvent(@NotNull Player who) {
super(PlayerData.get(who.getUniqueId())); super(PlayerData.get(who));
} }
@Override @Override

View File

@ -12,7 +12,7 @@ public class PlayerExitCastingModeEvent extends PlayerDataEvent implements Cance
private boolean cancelled = false; private boolean cancelled = false;
public PlayerExitCastingModeEvent(@NotNull Player who) { public PlayerExitCastingModeEvent(@NotNull Player who) {
super(PlayerData.get(who.getUniqueId())); super(PlayerData.get(who));
} }

View File

@ -1252,11 +1252,15 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
return getMMOPlayerData().hashCode(); 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()); return get(player.getUniqueId());
} }
public static PlayerData get(UUID uuid) { public static PlayerData get(@NotNull UUID uuid) {
return MMOCore.plugin.dataProvider.getDataManager().get(uuid); return MMOCore.plugin.dataProvider.getDataManager().get(uuid);
} }

View File

@ -107,13 +107,13 @@ public class AttributeModifier extends PlayerModifier {
@Override @Override
public void register(MMOPlayerData mmoPlayerData) { public void register(MMOPlayerData mmoPlayerData) {
PlayerData playerData = PlayerData.get(mmoPlayerData.getUniqueId()); PlayerData playerData = PlayerData.get(mmoPlayerData);
playerData.getAttributes().getInstance(attribute).addModifier(this); playerData.getAttributes().getInstance(attribute).addModifier(this);
} }
@Override @Override
public void unregister(MMOPlayerData mmoPlayerData) { public void unregister(MMOPlayerData mmoPlayerData) {
PlayerData playerData = PlayerData.get(mmoPlayerData.getUniqueId()); PlayerData playerData = PlayerData.get(mmoPlayerData);
playerData.getAttributes().getInstance(attribute).removeModifier(getKey()); playerData.getAttributes().getInstance(attribute).removeModifier(getKey());
} }

View File

@ -30,7 +30,7 @@ public class MMOCoreAttributeStatHandler extends StatHandler {
@Override @Override
public void runUpdate(StatInstance instance) { public void runUpdate(StatInstance instance) {
try { 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(); playerData.getAttributes().getInstance(attr).updateStats();
} catch (NullPointerException exception) { } catch (NullPointerException exception) {
// Player data is not loaded yet so there's nothing to update. // Player data is not loaded yet so there's nothing to update.

View File

@ -21,7 +21,7 @@ public class AttackEventTrigger implements EventTriggerHandler {
// We don't want players dying by themselves when using an enderpearl. // We don't want players dying by themselves when using an enderpearl.
if (event.getPlayer().equals(event.getEntity())) return; if (event.getPlayer().equals(event.getEntity())) return;
PlayerData player = PlayerData.get(event.getData().getUniqueId()); PlayerData player = PlayerData.get(event.getData());
PlayerClass profess = player.getProfess(); PlayerClass profess = player.getProfess();
for (DamageType type : event.getAttack().getDamage().collectTypes()) { for (DamageType type : event.getAttack().getDamage().collectTypes()) {

View File

@ -30,7 +30,7 @@ public class PvpModeCommand extends RegisteredCommand {
return false; return false;
} }
final PlayerData playerData = PlayerData.get(((Player) sender).getUniqueId()); final PlayerData playerData = PlayerData.get((Player) sender);
// Command cooldown // Command cooldown
if (playerData.getCooldownMap().isOnCooldown(COOLDOWN_KEY)) { if (playerData.getCooldownMap().isOnCooldown(COOLDOWN_KEY)) {

View File

@ -46,7 +46,7 @@ public class ForceClassProfileDataModule implements ProfileDataModule, Listener
return; 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(); InventoryManager.CLASS_SELECT.newInventory(playerData, () -> event.validate(this)).open();
} }

View File

@ -53,7 +53,7 @@ public class KillMobExperienceSource extends SpecificExperienceSource<Entity> {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void registerLastAttacker(PlayerAttackEvent event) { 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) @EventHandler(priority = EventPriority.MONITOR)

View File

@ -240,7 +240,7 @@ public class ConfigManager {
String msg = hasPlaceholders ? MMOCore.plugin.placeholderParser.parse(player, message) : message; String msg = hasPlaceholders ? MMOCore.plugin.placeholderParser.parse(player, message) : message;
if (!msg.isEmpty()) { if (!msg.isEmpty()) {
if (actionbar) PlayerData.get(player.getUniqueId()).displayActionBar(msg); if (actionbar) PlayerData.get(player).displayActionBar(msg);
else player.sendMessage(msg); else player.sendMessage(msg);
} }
return !msg.isEmpty(); return !msg.isEmpty();

View File

@ -12,10 +12,7 @@ import org.jetbrains.annotations.Nullable;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Collection; import java.util.*;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
/** /**
@ -25,16 +22,18 @@ import java.util.logging.Level;
public class PlayerDataTableUpdater { public class PlayerDataTableUpdater {
private final PlayerData playerData; private final PlayerData playerData;
private final SQLDataSource provider; private final SQLDataSource provider;
private final UUID effectiveId;
private final Map<String, String> requestMap = new HashMap<>(); private final Map<String, String> requestMap = new HashMap<>();
public PlayerDataTableUpdater(SQLDataSource provider, PlayerData playerData) { public PlayerDataTableUpdater(SQLDataSource provider, PlayerData playerData) {
this.playerData = playerData; this.playerData = playerData;
this.provider = provider; this.provider = provider;
this.effectiveId = playerData.getEffectiveId();
} }
public void executeRequest(boolean autosave) { public void executeRequest(boolean autosave) {
final String request = "INSERT INTO mmocore_playerdata(uuid, " + formatCollection(requestMap.keySet(), false) 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() + ";"; " ON DUPLICATE KEY UPDATE " + formatMap() + ";";
try { try {
@ -44,21 +43,21 @@ public class PlayerDataTableUpdater {
try { try {
statement.executeUpdate(); statement.executeUpdate();
} catch (SQLException exception) { } 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); new YAMLPlayerDataHandler(MMOCore.plugin).saveData(playerData, autosave);
exception.printStackTrace(); exception.printStackTrace();
} finally { } finally {
statement.close(); statement.close();
} }
} catch (SQLException exception) { } 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); new YAMLPlayerDataHandler(MMOCore.plugin).saveData(playerData, autosave);
exception.printStackTrace(); exception.printStackTrace();
} finally { } finally {
connection.close(); connection.close();
} }
} catch (SQLException exception) { } 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); new YAMLPlayerDataHandler(MMOCore.plugin).saveData(playerData, autosave);
exception.printStackTrace(); exception.printStackTrace();
} }

View File

@ -92,7 +92,8 @@ public class SQLDataHandler extends SQLSynchronizedDataHandler<PlayerData, Offli
@Override @Override
public void saveData(PlayerData data, boolean autosave) { public void saveData(PlayerData data, boolean autosave) {
UtilityMethods.debug(MMOCore.plugin, "SQL", "Saving data for: '" + data.getProfileId() + "'..."); final UUID effectiveId = data.getEffectiveId();
UtilityMethods.debug(MMOCore.plugin, "SQL", "Saving data for: '" + effectiveId + "'...");
final PlayerDataTableUpdater updater = new PlayerDataTableUpdater(getDataSource(), data); final PlayerDataTableUpdater updater = new PlayerDataTableUpdater(getDataSource(), data);
updater.addData("class_points", data.getClassPoints()); updater.addData("class_points", data.getClassPoints());
@ -128,7 +129,7 @@ public class SQLDataHandler extends SQLSynchronizedDataHandler<PlayerData, Offli
updater.executeRequest(autosave); updater.executeRequest(autosave);
UtilityMethods.debug(MMOCore.plugin, "SQL", "Saved data for: " + data.getProfileId()); UtilityMethods.debug(MMOCore.plugin, "SQL", "Saved data for: " + effectiveId);
UtilityMethods.debug(MMOCore.plugin, "SQL", String.format("{ class: %s, level: %d }", data.getProfess().getId(), data.getLevel())); UtilityMethods.debug(MMOCore.plugin, "SQL", String.format("{ class: %s, level: %d }", data.getProfess().getId(), data.getLevel()));
} }

View File

@ -42,7 +42,7 @@ public class DungeonPartiesPartyModule implements PartyModule, Listener {
for (AvalonPlayer member : party.getPlayers()) for (AvalonPlayer member : party.getPlayers())
try { try {
list.add(PlayerData.get(member.getPlayer().getUniqueId())); list.add(PlayerData.get(member.getPlayer()));
} catch (Exception ignored) { } catch (Exception ignored) {
} }

View File

@ -91,7 +91,7 @@ public class McMMOPartyModule implements PartyModule, Listener {
List<PlayerData> list = new ArrayList<>(); List<PlayerData> list = new ArrayList<>();
for (Player online : party.getOnlineMembers()) for (Player online : party.getOnlineMembers())
list.add(PlayerData.get(online.getUniqueId())); list.add(PlayerData.get(online));
return list; return list;
} }

View File

@ -44,7 +44,7 @@ public class OBTeamPartyModule implements PartyModule, Listener {
for (TeamMember member : team.getMembersAndOwner()) for (TeamMember member : team.getMembersAndOwner())
try { try {
list.add(PlayerData.get(member.getOfflinePlayer().getUniqueId())); list.add(PlayerData.get(member.getOfflinePlayer()));
} catch (Exception ignored) { } catch (Exception ignored) {
} }

View File

@ -41,6 +41,7 @@ public class PartiesPartyModule implements PartyModule,Listener {
event.getParty().getOnlineMembers() event.getParty().getOnlineMembers()
.forEach(p -> applyStatBonuses(PlayerData.get(p.getPlayerUUID()), membersSize)); .forEach(p -> applyStatBonuses(PlayerData.get(p.getPlayerUUID()), membersSize));
} }
@EventHandler @EventHandler
public void onPlayerLeave(BukkitPartiesPlayerPostLeaveEvent event) { public void onPlayerLeave(BukkitPartiesPlayerPostLeaveEvent event) {
int membersSize = event.getParty().getMembers().size(); int membersSize = event.getParty().getMembers().size();

View File

@ -44,7 +44,7 @@ public class CastableSkill extends Skill {
@Override @Override
public boolean getResult(SkillMetadata skillMeta) { public boolean getResult(SkillMetadata skillMeta) {
PlayerData playerData = PlayerData.get(skillMeta.getCaster().getData().getUniqueId()); PlayerData playerData = PlayerData.get(skillMeta.getCaster().getData());
boolean loud = !getTrigger().isSilent(); boolean loud = !getTrigger().isSilent();
// Skill is not usable yet // Skill is not usable yet
@ -88,7 +88,7 @@ public class CastableSkill extends Skill {
@Override @Override
public void whenCast(SkillMetadata skillMeta) { 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 // Apply cooldown, mana and stamina costs
if (!casterData.noCooldown) { if (!casterData.noCooldown) {

View File

@ -155,7 +155,7 @@ public class KeyCombos implements SkillCastingListener {
@EventHandler @EventHandler
public void ignoreOtherSkills(PlayerCastSkillEvent event) { public void ignoreOtherSkills(PlayerCastSkillEvent event) {
TriggerType triggerType = event.getCast().getTrigger(); 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); event.setCancelled(true);
} }

View File

@ -85,7 +85,7 @@ public class Ambers extends SkillHandler<SimpleSkillResult> implements Listener
// data.getSkillData().ambers++; // data.getSkillData().ambers++;
// Give mana back // Give mana back
PlayerData playerData = PlayerData.get(data.getUniqueId()); PlayerData playerData = PlayerData.get(data);
double missingMana = data.getStatMap().getStat("MAX_MANA") - playerData.getMana(); double missingMana = data.getStatMap().getStat("MAX_MANA") - playerData.getMana();
playerData.giveMana(missingMana * percent, PlayerResourceUpdateEvent.UpdateReason.SKILL_REGENERATION); playerData.giveMana(missingMana * percent, PlayerResourceUpdateEvent.UpdateReason.SKILL_REGENERATION);

View File

@ -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.InventoryClickContext;
import net.Indyuce.mmocore.gui.api.PluginInventory; import net.Indyuce.mmocore.gui.api.PluginInventory;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -55,7 +56,7 @@ public class PlayerListener implements Listener {
public void updateCombat(EntityDamageEvent event) { public void updateCombat(EntityDamageEvent event) {
if (UtilityMethods.isFakeEvent(event)) return; if (UtilityMethods.isFakeEvent(event)) return;
if (UtilityMethods.isRealPlayer(event.getEntity()) && MMOCore.plugin.configManager.combatLogDamageCauses.contains(event.getCause())) 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();
} }
/** /**

View File

@ -5,6 +5,7 @@ import io.lumine.mythic.lib.comp.interaction.InteractionType;
import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.manager.InventoryManager; import net.Indyuce.mmocore.manager.InventoryManager;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEntityEvent; 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)) if (event.getRightClicked().getType() != EntityType.PLAYER || !event.getPlayer().isSneaking() || !MythicLib.plugin.getEntities().canTarget(event.getPlayer(), event.getRightClicked(), InteractionType.SUPPORT_ACTION))
return; 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();
} }
} }