forked from Upstream/mmocore
A new xp source and quest objective: killmythicfaction
Format: '- {killmythicfaction{name=factionname;amount=x}'
This commit is contained in:
parent
12e7da53a7
commit
7e81f1a3bc
@ -7,6 +7,8 @@ import net.Indyuce.mmocore.api.experience.source.type.ExperienceSource;
|
||||
import net.Indyuce.mmocore.api.load.MMOLoader;
|
||||
import net.Indyuce.mmocore.api.quest.objective.Objective;
|
||||
import net.Indyuce.mmocore.api.quest.trigger.Trigger;
|
||||
import net.Indyuce.mmocore.comp.mythicmobs.load.KillMythicFactionExperienceSource;
|
||||
import net.Indyuce.mmocore.comp.mythicmobs.load.KillMythicFactionObjective;
|
||||
import net.Indyuce.mmocore.comp.mythicmobs.load.KillMythicMobExperienceSource;
|
||||
import net.Indyuce.mmocore.comp.mythicmobs.load.KillMythicMobObjective;
|
||||
import net.Indyuce.mmocore.comp.mythicmobs.load.MythicMobSkillTrigger;
|
||||
@ -28,6 +30,8 @@ public class MythicMobsMMOLoader extends MMOLoader {
|
||||
|
||||
if (config.getKey().equalsIgnoreCase("killmythicmob"))
|
||||
return new KillMythicMobObjective(section, config);
|
||||
if (config.getKey().equalsIgnoreCase("killmythicfaction"))
|
||||
return new KillMythicFactionObjective(section, config);
|
||||
|
||||
return null;
|
||||
}
|
||||
@ -37,6 +41,8 @@ public class MythicMobsMMOLoader extends MMOLoader {
|
||||
|
||||
if (config.getKey().equalsIgnoreCase("killmythicmob"))
|
||||
return new KillMythicMobExperienceSource(profession, config);
|
||||
if (config.getKey().equalsIgnoreCase("killmythicfaction"))
|
||||
return new KillMythicFactionExperienceSource(profession, config);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
@ -0,0 +1,51 @@
|
||||
package net.Indyuce.mmocore.comp.mythicmobs.load;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
||||
import io.lumine.xikage.mythicmobs.api.bukkit.events.MythicMobDeathEvent;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.experience.Profession;
|
||||
import net.Indyuce.mmocore.api.experience.source.type.SpecificExperienceSource;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.manager.profession.ExperienceManager;
|
||||
import net.mmogroup.mmolib.api.MMOLineConfig;
|
||||
|
||||
public class KillMythicFactionExperienceSource extends SpecificExperienceSource<String> {
|
||||
private final String factionName;
|
||||
|
||||
public KillMythicFactionExperienceSource(Profession profession, MMOLineConfig config) {
|
||||
super(profession, config);
|
||||
|
||||
config.validate("name");
|
||||
factionName = config.getString("name");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExperienceManager<KillMythicFactionExperienceSource> newManager() {
|
||||
return new ExperienceManager<KillMythicFactionExperienceSource>() {
|
||||
@EventHandler
|
||||
public void a(MythicMobDeathEvent event) {
|
||||
Bukkit.getScheduler().runTaskLater(MMOCore.plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!event.getEntity().isDead()) return;
|
||||
if (!event.getMob().hasFaction()) return;
|
||||
if (!(event.getKiller() instanceof Player) || event.getKiller().hasMetadata("NPC")) return;
|
||||
|
||||
PlayerData data = PlayerData.get((Player) event.getKiller());
|
||||
for (KillMythicFactionExperienceSource source : getSources())
|
||||
if (source.matches(data, event.getMob().getFaction()))
|
||||
source.giveExperience(data, event.getEntity().getLocation());
|
||||
}
|
||||
}, 2);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(PlayerData player, String name) {
|
||||
return hasRightClass(player) && name.equals(factionName);
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package net.Indyuce.mmocore.comp.mythicmobs.load;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import io.lumine.xikage.mythicmobs.api.bukkit.events.MythicMobDeathEvent;
|
||||
import net.Indyuce.mmocore.api.quest.ObjectiveProgress;
|
||||
import net.Indyuce.mmocore.api.quest.QuestProgress;
|
||||
import net.Indyuce.mmocore.api.quest.objective.Objective;
|
||||
import net.mmogroup.mmolib.api.MMOLineConfig;
|
||||
|
||||
public class KillMythicFactionObjective extends Objective {
|
||||
private final String factionName;
|
||||
private final int required;
|
||||
|
||||
public KillMythicFactionObjective(ConfigurationSection section, MMOLineConfig config) {
|
||||
super(section);
|
||||
|
||||
config.validate("amount", "name");
|
||||
|
||||
factionName = config.getString("name");
|
||||
required = config.getInt("amount");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectiveProgress newProgress(QuestProgress questProgress) {
|
||||
return new KillFactionProgress(questProgress, this);
|
||||
}
|
||||
|
||||
public class KillFactionProgress extends ObjectiveProgress implements Listener {
|
||||
private int count;
|
||||
|
||||
public KillFactionProgress(QuestProgress questProgress, Objective objective) {
|
||||
super(questProgress, objective);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void a(MythicMobDeathEvent event) {
|
||||
if (event.getKiller() instanceof Player
|
||||
&& event.getKiller().equals(getQuestProgress().getPlayer().getPlayer())
|
||||
&& event.getMob().hasFaction() && event.getMob().getFaction().equals(factionName)) {
|
||||
count++;
|
||||
getQuestProgress().getPlayer().getQuestData().updateBossBar();
|
||||
if (count >= required)
|
||||
getQuestProgress().completeObjective();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatLore(String lore) {
|
||||
return lore.replace("{left}", "" + (required - count));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user