Added a few more passive types for passive skills.

You can also target event triggers by using @Trigger in the MM skill
This commit is contained in:
ASangarin 2020-10-31 22:41:26 +01:00
parent 93069c7d1a
commit 71b8183299
11 changed files with 211 additions and 120 deletions

View File

@ -68,7 +68,7 @@ public class MythicMobSkill extends Skill {
Optional<PassiveSkillType> passiveType = Enums.getIfPresent(PassiveSkillType.class, config.getString("passive-type").toUpperCase());
Validate.isTrue(passiveType.isPresent(), "Invalid passive skill type");
setPassive();
Bukkit.getPluginManager().registerEvents(passiveType.get().getListener(this), MMOCore.plugin);
Bukkit.getPluginManager().registerEvents(passiveType.get().getHandler(this), MMOCore.plugin);
}
// cast = config.getBoolean("target") ? (data, info) -> new

View File

@ -0,0 +1,41 @@
package net.Indyuce.mmocore.comp.mythicmobs.skill;
import java.util.Arrays;
import org.bukkit.entity.Entity;
import org.bukkit.event.Listener;
import io.lumine.xikage.mythicmobs.MythicMobs;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.skill.SkillResult;
public abstract class PassiveMythicMobSkillHandler implements Listener {
protected final MythicMobSkill skill;
/**
* Core class for all passive types
*/
protected PassiveMythicMobSkillHandler(MythicMobSkill skill) {
this.skill = skill;
}
public void castSkill(PlayerData data) {
castSkill(data, data.getPlayer());
}
public void castSkill(PlayerData data, Entity target) {
if (!data.getProfess().hasSkill(skill.getId()))
return;
SkillResult cast = data.cast(data.getProfess().getSkill(skill.getId()));
if (!cast.isSuccessful())
return;
data.getSkillData().cacheModifiers(skill.getInternalName(), cast);
if (MMOCore.plugin.hasAntiCheat())
MMOCore.plugin.antiCheatSupport.disableAntiCheat(data.getPlayer(), skill.getAntiCheat());
MythicMobs.inst().getAPIHelper().castSkill(data.getPlayer(), skill.getInternalName(), target, data.getPlayer().getEyeLocation(),
Arrays.asList(data.getPlayer()), null, 1);
}
}

View File

@ -1,16 +1,33 @@
package net.Indyuce.mmocore.comp.mythicmobs.skill;
import org.bukkit.event.Listener;
import net.Indyuce.mmocore.comp.mythicmobs.skill.handlers.EntityDeathSkillHandler;
import net.Indyuce.mmocore.comp.mythicmobs.skill.handlers.PlayerAttackSkillHandler;
import net.Indyuce.mmocore.comp.mythicmobs.skill.handlers.PlayerDamageByEntitySkillHandler;
import net.Indyuce.mmocore.comp.mythicmobs.skill.handlers.PlayerDamageSkillHandler;
import net.Indyuce.mmocore.comp.mythicmobs.skill.handlers.PlayerDeathSkillHandler;
import net.Indyuce.mmocore.comp.mythicmobs.skill.handlers.ShootBowSkillHandler;
public enum PassiveSkillType {
PLAYER_ATTACK,
PLAYER_DAMAGE;
PLAYER_DAMAGE,
PLAYER_DAMAGE_BY_ENTITY,
PLAYER_DEATH,
PLAYER_KILL_ENTITY,
SHOOT_BOW;
public Listener getListener(MythicMobSkill skill) {
public PassiveMythicMobSkillHandler getHandler(MythicMobSkill skill) {
if (this == PLAYER_ATTACK)
return new PlayerAttackSkillHandler(skill);
if (this == PLAYER_DAMAGE)
return new PlayerDamageSkillHandler(skill);
if (this == PLAYER_KILL_ENTITY)
return new EntityDeathSkillHandler(skill);
if (this == PLAYER_DAMAGE_BY_ENTITY)
return new PlayerDamageByEntitySkillHandler(skill);
if (this == PLAYER_DEATH)
return new PlayerDeathSkillHandler(skill);
if (this == SHOOT_BOW)
return new ShootBowSkillHandler(skill);
throw new NullPointerException();
}
}

View File

@ -1,62 +0,0 @@
package net.Indyuce.mmocore.comp.mythicmobs.skill;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import io.lumine.xikage.mythicmobs.MythicMobs;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.skill.SkillResult;
import net.mmogroup.mmolib.api.event.PlayerAttackEvent;
public class PlayerAttackSkillHandler implements Listener {
private final MythicMobSkill skill;
/**
* Used to handle passive skills which trigger when a player attacks another
* entity
*
* @param skill
* Passive skill info
*/
public PlayerAttackSkillHandler(MythicMobSkill skill) {
this.skill = skill;
}
@EventHandler
private void playerAttack(PlayerAttackEvent event) {
castSkill(event.getData().getMMOCore(), event.getEntity());
}
/**
* Has an extra parameter compared to PlayerDamageSkillHandler because the
* hit entity is added to the MythicMobs target list
*
* @param data
* Player casting the skill
* @param target
* Entity hit
*/
public void castSkill(PlayerData data, LivingEntity target) {
if (!data.getProfess().hasSkill(skill.getId()))
return;
SkillResult cast = data.cast(data.getProfess().getSkill(skill.getId()));
if (!cast.isSuccessful())
return;
data.getSkillData().cacheModifiers(skill.getInternalName(), cast);
if (MMOCore.plugin.hasAntiCheat())
MMOCore.plugin.antiCheatSupport.disableAntiCheat(data.getPlayer(), skill.getAntiCheat());
List<Entity> targets = new ArrayList<>();
targets.add(data.getPlayer());
targets.add(target);
MythicMobs.inst().getAPIHelper().castSkill(data.getPlayer(), skill.getInternalName(), data.getPlayer(), data.getPlayer().getEyeLocation(),
targets, null, 1);
}
}

View File

@ -1,54 +0,0 @@
package net.Indyuce.mmocore.comp.mythicmobs.skill;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;
import io.lumine.xikage.mythicmobs.MythicMobs;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.skill.SkillResult;
public class PlayerDamageSkillHandler implements Listener {
private final MythicMobSkill skill;
/**
* Used to handle passive skills which trigger when a player is attacked by
* another entity
*
* @param skill
* Passive skill info
*/
public PlayerDamageSkillHandler(MythicMobSkill skill) {
this.skill = skill;
}
@EventHandler
private void playerDamage(EntityDamageEvent event) {
if (event.getEntityType() == EntityType.PLAYER)
castSkill(PlayerData.get((Player) event.getEntity()));
}
public void castSkill(PlayerData data) {
if (!data.getProfess().hasSkill(skill.getId()))
return;
SkillResult cast = data.cast(data.getProfess().getSkill(skill.getId()));
if (!cast.isSuccessful())
return;
data.getSkillData().cacheModifiers(skill.getInternalName(), cast);
if (MMOCore.plugin.hasAntiCheat())
MMOCore.plugin.antiCheatSupport.disableAntiCheat(data.getPlayer(), skill.getAntiCheat());
List<Entity> targets = new ArrayList<>();
targets.add(data.getPlayer());
MythicMobs.inst().getAPIHelper().castSkill(data.getPlayer(), skill.getInternalName(), data.getPlayer(), data.getPlayer().getEyeLocation(),
targets, null, 1);
}
}

View File

@ -0,0 +1,26 @@
package net.Indyuce.mmocore.comp.mythicmobs.skill.handlers;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.comp.mythicmobs.skill.MythicMobSkill;
import net.Indyuce.mmocore.comp.mythicmobs.skill.PassiveMythicMobSkillHandler;
import net.mmogroup.mmolib.api.event.EntityKillEntityEvent;
public class EntityDeathSkillHandler extends PassiveMythicMobSkillHandler {
/**
* Used to handle passive skills which trigger when a player kills
* another entity
*/
public EntityDeathSkillHandler(MythicMobSkill skill) {
super(skill);
}
@EventHandler
private void event(EntityKillEntityEvent e) {
if (e.getEntity().getType() == EntityType.PLAYER)
castSkill(PlayerData.get((Player) e.getEntity()), e.getTarget());
}
}

View File

@ -0,0 +1,22 @@
package net.Indyuce.mmocore.comp.mythicmobs.skill.handlers;
import org.bukkit.event.EventHandler;
import net.Indyuce.mmocore.comp.mythicmobs.skill.MythicMobSkill;
import net.Indyuce.mmocore.comp.mythicmobs.skill.PassiveMythicMobSkillHandler;
import net.mmogroup.mmolib.api.event.PlayerAttackEvent;
public class PlayerAttackSkillHandler extends PassiveMythicMobSkillHandler {
/**
* Used to handle passive skills which trigger when a player attacks another
* entity
*/
public PlayerAttackSkillHandler(MythicMobSkill skill) {
super(skill);
}
@EventHandler
private void event(PlayerAttackEvent e) {
castSkill(e.getData().getMMOCore(), e.getEntity());
}
}

View File

@ -0,0 +1,26 @@
package net.Indyuce.mmocore.comp.mythicmobs.skill.handlers;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.comp.mythicmobs.skill.MythicMobSkill;
import net.Indyuce.mmocore.comp.mythicmobs.skill.PassiveMythicMobSkillHandler;
public class PlayerDamageByEntitySkillHandler extends PassiveMythicMobSkillHandler {
/**
* Used to handle passive skills which trigger when a player takes damage
* from another entity
*/
public PlayerDamageByEntitySkillHandler(MythicMobSkill skill) {
super(skill);
}
@EventHandler
private void event(EntityDamageByEntityEvent e) {
if (e.getEntity().getType() == EntityType.PLAYER)
castSkill(PlayerData.get((Player) e.getEntity()), e.getDamager());
}
}

View File

@ -0,0 +1,25 @@
package net.Indyuce.mmocore.comp.mythicmobs.skill.handlers;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageEvent;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.comp.mythicmobs.skill.MythicMobSkill;
import net.Indyuce.mmocore.comp.mythicmobs.skill.PassiveMythicMobSkillHandler;
public class PlayerDamageSkillHandler extends PassiveMythicMobSkillHandler {
/**
* Used to handle passive skills which trigger when a player takes damage
*/
public PlayerDamageSkillHandler(MythicMobSkill skill) {
super(skill);
}
@EventHandler
private void event(EntityDamageEvent e) {
if (e.getEntityType() == EntityType.PLAYER)
castSkill(PlayerData.get((Player) e.getEntity()));
}
}

View File

@ -0,0 +1,25 @@
package net.Indyuce.mmocore.comp.mythicmobs.skill.handlers;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDeathEvent;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.comp.mythicmobs.skill.MythicMobSkill;
import net.Indyuce.mmocore.comp.mythicmobs.skill.PassiveMythicMobSkillHandler;
public class PlayerDeathSkillHandler extends PassiveMythicMobSkillHandler {
/**
* Used to handle passive skills which trigger when a player dies
*/
public PlayerDeathSkillHandler(MythicMobSkill skill) {
super(skill);
}
@EventHandler
private void event(EntityDeathEvent e) {
if (e.getEntityType() == EntityType.PLAYER)
castSkill(PlayerData.get((Player) e.getEntity()));
}
}

View File

@ -0,0 +1,25 @@
package net.Indyuce.mmocore.comp.mythicmobs.skill.handlers;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityShootBowEvent;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.comp.mythicmobs.skill.MythicMobSkill;
import net.Indyuce.mmocore.comp.mythicmobs.skill.PassiveMythicMobSkillHandler;
public class ShootBowSkillHandler extends PassiveMythicMobSkillHandler {
/**
* Used to handle passive skills which trigger when a player shoots a bow
*/
public ShootBowSkillHandler(MythicMobSkill skill) {
super(skill);
}
@EventHandler
private void event(EntityShootBowEvent e) {
if(e.getEntity().getType() == EntityType.PLAYER)
castSkill(PlayerData.get((Player) e.getEntity()), e.getProjectile());
}
}