/mm reload now reloads MMOCore skills

This commit is contained in:
Indyuce 2021-12-27 12:59:09 +01:00
parent 733f3c5239
commit 2b406e0cf5
2 changed files with 37 additions and 3 deletions

View File

@ -10,9 +10,14 @@ import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute;
import net.Indyuce.mmocore.api.player.attribute.PlayerAttributes;
import net.Indyuce.mmocore.comp.mythicmobs.load.CurrencyItemDrop;
import net.Indyuce.mmocore.comp.mythicmobs.load.GoldPouchDrop;
import net.Indyuce.mmocore.skill.Skill;
import org.apache.commons.lang.Validate;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import java.util.Optional;
import java.util.logging.Level;
public class MythicHook implements Listener {
public MythicHook() {
registerPlaceholders();
@ -34,10 +39,23 @@ public class MythicHook implements Listener {
event.register(new CurrencyItemDrop("NOTE", event.getConfig()));
}
// When MythicMobs is reloaded, the placeholders are emptied. Add them again
@EventHandler
public void b(MythicReloadedEvent event) {
// When MM is reloaded, reload placeholders because they are no longer registered
registerPlaceholders();
// Reload MMOCore skills as well
for (Skill skill : MMOCore.plugin.skillManager.getActive())
if (skill instanceof MythicSkill)
try {
String skillId = ((MythicSkill) skill).getSkill().getInternalName();
Optional<io.lumine.xikage.mythicmobs.skills.Skill> opt = MythicMobs.inst().getSkillManager().getSkill(skillId);
Validate.isTrue(opt.isPresent(), "Could not find skill with ID '" + skillId + "'");
((MythicSkill) skill).setSkill(opt.get());
} catch (RuntimeException exception) {
MMOCore.log(Level.WARNING, "Could not reload MM skill '" + skill.getId() + "': " + exception.getMessage());
}
}
private void registerPlaceholders() {

View File

@ -4,8 +4,8 @@ import io.lumine.mythic.lib.api.player.EquipmentSlot;
import io.lumine.mythic.lib.api.stat.modifier.ModifierSource;
import io.lumine.mythic.lib.api.util.EnumUtils;
import io.lumine.mythic.lib.player.cooldown.CooldownInfo;
import io.lumine.mythic.lib.skill.trigger.TriggerMetadata;
import io.lumine.mythic.lib.skill.trigger.PassiveSkill;
import io.lumine.mythic.lib.skill.trigger.TriggerMetadata;
import io.lumine.mythic.lib.skill.trigger.TriggerType;
import io.lumine.mythic.lib.skill.trigger.TriggeredSkill;
import io.lumine.xikage.mythicmobs.MythicMobs;
@ -32,6 +32,7 @@ import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.HashSet;
@ -40,10 +41,12 @@ import java.util.Optional;
import java.util.logging.Level;
public class MythicSkill extends Skill implements TriggeredSkill {
private final io.lumine.xikage.mythicmobs.skills.Skill skill;
private final Map<CheatType, Integer> antiCheat = new HashMap<>();
private final PassiveSkill mythicLibSkill;
// Not final so that it can be changed when MM is reloaded
private io.lumine.xikage.mythicmobs.skills.Skill skill;
public MythicSkill(String id, FileConfiguration config) {
super(id);
@ -93,6 +96,19 @@ public class MythicSkill extends Skill implements TriggeredSkill {
return skill;
}
/**
* Used when reloading MMOCore. Something convenient to do is to
* reload the MMOCore skills that are linked to a MM skill whenever
* MM is reloaded, so that changes to the skill are taken into account
* in MMOCore skills.
*
* @param skill Newest version of skill
*/
public void setSkill(@NotNull io.lumine.xikage.mythicmobs.skills.Skill skill) {
Validate.notNull(skill);
this.skill = skill;
}
public PassiveSkill toMythicLib() {
return mythicLibSkill;
}