diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/experience/source/KillMobExperienceSource.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/experience/source/KillMobExperienceSource.java index 388a5b2c..70b29076 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/experience/source/KillMobExperienceSource.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/experience/source/KillMobExperienceSource.java @@ -1,12 +1,13 @@ package net.Indyuce.mmocore.experience.source; +import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.api.MMOLineConfig; import io.lumine.mythic.lib.api.event.PlayerKillEntityEvent; import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.player.PlayerData; -import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource; import net.Indyuce.mmocore.api.util.MMOCoreUtils; import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser; +import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource; import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager; import org.bukkit.Bukkit; import org.bukkit.NamespacedKey; @@ -16,23 +17,30 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.persistence.PersistentDataType; +import javax.annotation.Nullable; + public class KillMobExperienceSource extends SpecificExperienceSource { - public final EntityType type; + private final EntityType type; + + @Nullable + private final String displayName; public KillMobExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) { super(dispenser, config); - config.validate("type"); + config.validateKeys("type"); + displayName = config.contains("name") ? MythicLib.plugin.parseColors(config.getString("name")) : null; type = EntityType.valueOf(config.getString("type").toUpperCase().replace("-", "_").replace(" ", "_")); } @Override public ExperienceSourceManager newManager() { return new ExperienceSourceManager() { + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void a(PlayerKillEntityEvent event) { Bukkit.getScheduler().runTaskLater(MMOCore.plugin, () -> { - if (event.getTarget().isDead() && !event.getTarget().getPersistentDataContainer().has(new NamespacedKey(MMOCore.plugin,"spawner_spawned"),PersistentDataType.STRING)) { + if (event.getTarget().isDead() && !event.getTarget().getPersistentDataContainer().has(new NamespacedKey(MMOCore.plugin, "spawner_spawned"), PersistentDataType.STRING)) { PlayerData data = PlayerData.get(event.getPlayer()); for (KillMobExperienceSource source : getSources()) @@ -46,6 +54,6 @@ public class KillMobExperienceSource extends SpecificExperienceSource { @Override public boolean matchesParameter(PlayerData player, Entity obj) { - return obj.getType() == type; + return obj.getType() == type && (displayName == null || displayName.equals(obj.getCustomName())); } } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/experience/source/type/SpecificExperienceSource.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/experience/source/type/SpecificExperienceSource.java index d284bd36..2f725651 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/experience/source/type/SpecificExperienceSource.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/experience/source/type/SpecificExperienceSource.java @@ -10,7 +10,6 @@ import org.jetbrains.annotations.Nullable; public abstract class SpecificExperienceSource extends ExperienceSource { private final RandomAmount amount; - double counter = 0; /** * Used to register experience sources with SPECIFIC experience outputs. @@ -20,20 +19,21 @@ public abstract class SpecificExperienceSource extends ExperienceSource { public SpecificExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) { super(dispenser); - config.validate("amount"); + config.validateKeys("amount"); amount = new RandomAmount(config.getString("amount")); } /** * Used for FromExperienceSource + * * @param dispenser */ public SpecificExperienceSource(ExperienceDispenser dispenser) { super(dispenser); - amount=new RandomAmount(0,0); - } + amount = new RandomAmount(0, 0); + } public RandomAmount getAmount() { return amount;