fixed citizens compatibility with passive skills

This commit is contained in:
Indyuce 2021-08-20 12:00:14 +02:00
parent dc351ed10f
commit 564a5dede3
3 changed files with 15 additions and 20 deletions

View File

@ -170,8 +170,7 @@ public class MMOCoreUtils {
/**
* @param player Player casting a spell/basic attack
* @param target The target entity
* @return If the player can target the entity given the attack type
* (buff or attack)
* @return If the player can attack the entity
*/
public static boolean canTarget(PlayerData player, Entity target) {
return canTarget(player, target, false);
@ -188,15 +187,12 @@ public class MMOCoreUtils {
*/
// TODO worldguard flags support for no target
public static boolean canTarget(PlayerData player, Entity target, boolean buff) {
if (!player.isOnline())
// Basic checks
if (!player.isOnline() || !(target instanceof LivingEntity) || player.getPlayer().equals(target) || target.isDead() || MythicLib.plugin.getEntities().findCustom(target))
return false;
// basic checks
if (!(target instanceof LivingEntity) || player.getPlayer().equals(target) || target.isDead()
|| MythicLib.plugin.getEntities().findCustom(target))
return false;
// party check
// Party check
if (!buff && target instanceof Player) {
PlayerData targetData = PlayerData.get((Player) target);
return !targetData.hasParty() || !targetData.getParty().getMembers().has(player);

View File

@ -1,14 +1,14 @@
package net.Indyuce.mmocore.comp.mythicmobs.skill.handlers;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import net.Indyuce.mmocore.comp.mythicmobs.skill.MythicMobSkill;
import net.Indyuce.mmocore.comp.mythicmobs.skill.PassiveMythicMobSkillHandler;
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
@ -19,8 +19,8 @@ public class PlayerDamageByEntitySkillHandler extends PassiveMythicMobSkillHandl
}
@EventHandler
private void event(EntityDamageByEntityEvent e) {
if (e.getEntity().getType() == EntityType.PLAYER)
castSkill(PlayerData.get((Player) e.getEntity()), e.getDamager());
private void a(EntityDamageByEntityEvent event) {
if (event.getEntity().getType() == EntityType.PLAYER && MMOCoreUtils.canTarget(PlayerData.get(event.getEntity().getUniqueId()), event.getDamager()))
castSkill(PlayerData.get((Player) event.getEntity()), event.getDamager());
}
}

View File

@ -32,8 +32,7 @@ public abstract class PlayerDataManager {
* @return Player data, if it's loaded
*/
public PlayerData get(UUID uuid) {
Validate.isTrue(data.containsKey(uuid), "Player data is not loaded");
return data.get(uuid);
return Objects.requireNonNull(data.get(uuid), "Player data is not loaded");
}
public void remove(UUID uuid) {