mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2024-11-30 01:13:38 +01:00
New disp name option for killmob exp source
This commit is contained in:
parent
bd1b40f1da
commit
95ea032dfa
@ -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<Entity> {
|
||||
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<KillMobExperienceSource> newManager() {
|
||||
return new ExperienceSourceManager<KillMobExperienceSource>() {
|
||||
|
||||
@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<Entity> {
|
||||
|
||||
@Override
|
||||
public boolean matchesParameter(PlayerData player, Entity obj) {
|
||||
return obj.getType() == type;
|
||||
return obj.getType() == type && (displayName == null || displayName.equals(obj.getCustomName()));
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public abstract class SpecificExperienceSource<T> extends ExperienceSource<T> {
|
||||
private final RandomAmount amount;
|
||||
double counter = 0;
|
||||
|
||||
/**
|
||||
* Used to register experience sources with SPECIFIC experience outputs.
|
||||
@ -20,20 +19,21 @@ public abstract class SpecificExperienceSource<T> extends ExperienceSource<T> {
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user