forked from Upstream/mmocore
More proxy profiles fixing
This commit is contained in:
parent
d050b708cc
commit
3efc5b86fb
@ -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) {
|
||||
|
@ -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
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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()) {
|
||||
|
@ -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)) {
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ public class KillMobExperienceSource extends SpecificExperienceSource<Entity> {
|
||||
|
||||
@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)
|
||||
|
@ -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();
|
||||
|
@ -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<String, String> 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();
|
||||
}
|
||||
|
@ -92,7 +92,8 @@ public class SQLDataHandler extends SQLSynchronizedDataHandler<PlayerData, Offli
|
||||
|
||||
@Override
|
||||
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);
|
||||
updater.addData("class_points", data.getClassPoints());
|
||||
@ -128,7 +129,7 @@ public class SQLDataHandler extends SQLSynchronizedDataHandler<PlayerData, Offli
|
||||
|
||||
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()));
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ public class DungeonPartiesPartyModule implements PartyModule, Listener {
|
||||
|
||||
for (AvalonPlayer member : party.getPlayers())
|
||||
try {
|
||||
list.add(PlayerData.get(member.getPlayer().getUniqueId()));
|
||||
list.add(PlayerData.get(member.getPlayer()));
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
|
@ -91,7 +91,7 @@ public class McMMOPartyModule implements PartyModule, Listener {
|
||||
List<PlayerData> list = new ArrayList<>();
|
||||
|
||||
for (Player online : party.getOnlineMembers())
|
||||
list.add(PlayerData.get(online.getUniqueId()));
|
||||
list.add(PlayerData.get(online));
|
||||
|
||||
return list;
|
||||
}
|
||||
|
@ -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) {
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -85,7 +85,7 @@ public class Ambers extends SkillHandler<SimpleSkillResult> 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);
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user