mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2024-12-29 05:47:36 +01:00
Class stats now update when using /mmocore reload
This commit is contained in:
parent
63c837be2c
commit
8378babd83
@ -37,6 +37,7 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -104,6 +105,7 @@ public class PlayerData extends OfflinePlayerData {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
profess = profess == null ? null : MMOCore.plugin.classManager.get(profess.getId());
|
profess = profess == null ? null : MMOCore.plugin.classManager.get(profess.getId());
|
||||||
|
getStats().updateStats();
|
||||||
} catch (NullPointerException exception) {
|
} catch (NullPointerException exception) {
|
||||||
MMOCore.log(Level.SEVERE, "[Userdata] Could not find class " + getProfess().getId() + " while refreshing player data.");
|
MMOCore.log(Level.SEVERE, "[Userdata] Could not find class " + getProfess().getId() + " while refreshing player data.");
|
||||||
}
|
}
|
||||||
@ -516,6 +518,7 @@ public class PlayerData extends OfflinePlayerData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NotNull
|
||||||
public PlayerClass getProfess() {
|
public PlayerClass getProfess() {
|
||||||
return profess == null ? MMOCore.plugin.classManager.getDefaultClass() : profess;
|
return profess == null ? MMOCore.plugin.classManager.getDefaultClass() : profess;
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
package net.Indyuce.mmocore.api.player.stats;
|
package net.Indyuce.mmocore.api.player.stats;
|
||||||
|
|
||||||
import io.lumine.mythic.lib.MythicLib;
|
import io.lumine.mythic.lib.api.player.EquipmentSlot;
|
||||||
import io.lumine.mythic.lib.api.stat.StatInstance;
|
import io.lumine.mythic.lib.api.stat.StatInstance;
|
||||||
import io.lumine.mythic.lib.api.stat.StatMap;
|
import io.lumine.mythic.lib.api.stat.StatMap;
|
||||||
|
import io.lumine.mythic.lib.api.stat.modifier.ModifierSource;
|
||||||
|
import io.lumine.mythic.lib.api.stat.modifier.ModifierType;
|
||||||
import io.lumine.mythic.lib.api.stat.modifier.StatModifier;
|
import io.lumine.mythic.lib.api.stat.modifier.StatModifier;
|
||||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||||
|
|
||||||
@ -46,21 +48,28 @@ public class PlayerStats {
|
|||||||
stat.hasProfession() ? data.getCollectionSkills().getLevel(stat.getProfession()) : data.getLevel());
|
stat.hasProfession() ? data.getCollectionSkills().getLevel(stat.getProfession()) : data.getLevel());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* used to update MMOCore stat modifiers due to class and send them over to
|
* Used to update MMOCore stat modifiers due to class and send them over to
|
||||||
* MMOLib. must be ran everytime the player levels up or changes class.
|
* MMOLib. Must be ran everytime the player levels up or changes class.
|
||||||
|
* <p>
|
||||||
|
* This is also called when reloading the plugin to make class setup easier,
|
||||||
|
* see {@link PlayerData#update()} for more info
|
||||||
*/
|
*/
|
||||||
public synchronized void updateStats() {
|
public synchronized void updateStats() {
|
||||||
getMap().getInstances().forEach(ins -> ins.remove("mmocoreClass"));
|
|
||||||
|
|
||||||
for (StatType stat : StatType.values()) {
|
for (StatType stat : StatType.values()) {
|
||||||
StatInstance instance = getMap().getInstance(stat.name());
|
StatInstance instance = getMap().getInstance(stat.name());
|
||||||
|
StatInstance.ModifierPacket packet = instance.newPacket();
|
||||||
|
|
||||||
|
// Remove old stat modifiers
|
||||||
|
packet.removeIf(str -> str.equals("mmocoreClass"));
|
||||||
|
|
||||||
|
// Add newest one
|
||||||
double total = getBase(stat) - instance.getBase();
|
double total = getBase(stat) - instance.getBase();
|
||||||
|
|
||||||
if (total != 0)
|
if (total != 0)
|
||||||
instance.addModifier("mmocoreClass", new StatModifier(total));
|
packet.addModifier("mmocoreClass", new StatModifier(total, ModifierType.FLAT, EquipmentSlot.OTHER, ModifierSource.OTHER));
|
||||||
}
|
|
||||||
|
|
||||||
MythicLib.plugin.getStats().runUpdates(getMap());
|
// Then update the stat
|
||||||
|
packet.runUpdate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user