mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2025-02-01 11:11:23 +01:00
Fixed MMOInv health buffs not working on login
This commit is contained in:
parent
3962c73515
commit
991397606f
@ -178,30 +178,6 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
|
||||
getStats().updateStats();
|
||||
}
|
||||
|
||||
/**
|
||||
* This script is called when the player data has been successfully
|
||||
* loaded from the SQL/local text database.
|
||||
*/
|
||||
@Override
|
||||
public void markAsSynchronized() {
|
||||
setupSkillTree();
|
||||
applyTemporaryTriggers();
|
||||
getStats().updateStats(true);
|
||||
|
||||
/*
|
||||
* If the player is not dead and the health is 0, this means that the data was
|
||||
* missing from the database and it gives full health to the player. If the
|
||||
* player is dead however, it must not account for that subtle edge case.
|
||||
*/
|
||||
if (isOnline() && !getPlayer().isDead()) {
|
||||
final double effectiveHealth = Math.max(getPlayer().getHealth(), getHealth());
|
||||
getPlayer().setHealth(MMOCoreUtils.fixResource(effectiveHealth, getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()));
|
||||
}
|
||||
|
||||
// Finally mark synchronized
|
||||
super.markAsSynchronized();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setupRemovableTrigger() {
|
||||
applyTemporaryTriggers();
|
||||
@ -999,9 +975,10 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
|
||||
stellium = Math.max(0, Math.min(stellium + event.getAmount(), max));
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public double getHealth() {
|
||||
return isSynchronized() && isOnline() ? getPlayer().getHealth() : health;
|
||||
return isOnline() ? getPlayer().getHealth() : health;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1018,6 +995,10 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
|
||||
return stellium;
|
||||
}
|
||||
|
||||
public double getCachedHealth() {
|
||||
return health;
|
||||
}
|
||||
|
||||
public PlayerStats getStats() {
|
||||
return playerStats;
|
||||
}
|
||||
|
@ -1,15 +1,17 @@
|
||||
|
||||
package net.Indyuce.mmocore.listener;
|
||||
|
||||
import io.lumine.mythic.lib.UtilityMethods;
|
||||
import io.lumine.mythic.lib.api.event.PlayerAttackEvent;
|
||||
import io.lumine.mythic.lib.api.event.SynchronizedDataLoadEvent;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.event.PlayerResourceUpdateEvent;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.player.profess.resource.PlayerResource;
|
||||
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
|
||||
import net.Indyuce.mmocore.gui.api.InventoryClickContext;
|
||||
import net.Indyuce.mmocore.gui.api.PluginInventory;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -22,6 +24,35 @@ import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
|
||||
public class PlayerListener implements Listener {
|
||||
|
||||
/**
|
||||
* Script ran when the full MMO plugin data is synchronized. Player Health
|
||||
* is only updated now otherwise other MMO plugins would not have the time
|
||||
* to register their stats beforehand.
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void a(SynchronizedDataLoadEvent event) {
|
||||
if (event.syncIsFull()) {
|
||||
final PlayerData playerData = PlayerData.get(event.getHolder().getUniqueId());
|
||||
final Player player = playerData.getPlayer();
|
||||
|
||||
playerData.setupSkillTree();
|
||||
playerData.applyTemporaryTriggers();
|
||||
playerData.getStats().updateStats(true); // TODO maybe duplicate?
|
||||
|
||||
/*
|
||||
* If the player is not dead and the health is 0, this means that the data was
|
||||
* missing from the database, and it should give full health to the player. It
|
||||
* must account for the edge case where the player is dead.
|
||||
*/
|
||||
if (playerData.isOnline() && !player.isDead()) {
|
||||
final double cachedHealth = playerData.getCachedHealth(),
|
||||
maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(),
|
||||
fixedHealth = MMOCoreUtils.fixResource(cachedHealth, maxHealth);
|
||||
player.setHealth(fixedHealth);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register custom inventory clicks
|
||||
*/
|
||||
@ -54,7 +85,7 @@ public class PlayerListener implements Listener {
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void updateCombat(EntityDamageEvent event) {
|
||||
if (UtilityMethods.isFakeEvent(event)) return;
|
||||
if (UtilityMethods.isFake(event)) return;
|
||||
if (UtilityMethods.isRealPlayer(event.getEntity()) && MMOCore.plugin.configManager.combatLogDamageCauses.contains(event.getCause()))
|
||||
PlayerData.get((Player) event.getEntity()).getCombat().update();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user