First step for party friendly fire

This commit is contained in:
Indyuce 2020-04-14 01:07:45 +02:00
parent 44a76e7dbb
commit 25b350c09a
6 changed files with 25 additions and 10 deletions

View File

@ -21,6 +21,7 @@ import org.bukkit.util.io.BukkitObjectOutputStream;
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder; import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.mmogroup.mmolib.MMOLib; import net.mmogroup.mmolib.MMOLib;
import net.mmogroup.mmolib.version.VersionMaterial; import net.mmogroup.mmolib.version.VersionMaterial;
@ -30,7 +31,8 @@ public class MMOCoreUtils {
} }
public static String displayName(ItemStack item) { public static String displayName(ItemStack item) {
return item.hasItemMeta() && item.getItemMeta().hasDisplayName() ? item.getItemMeta().getDisplayName() : caseOnWords(item.getType().name().replace("_", " ")); return item.hasItemMeta() && item.getItemMeta().hasDisplayName() ? item.getItemMeta().getDisplayName()
: caseOnWords(item.getType().name().replace("_", " "));
} }
public static String caseOnWords(String s) { public static String caseOnWords(String s) {
@ -58,7 +60,8 @@ public class MMOCoreUtils {
Validate.notNull(string, "String cannot be null"); Validate.notNull(string, "String cannot be null");
String[] split = string.split("\\:"); String[] split = string.split("\\:");
Material material = Material.valueOf(split[0].toUpperCase().replace("-", "_").replace(" ", "_")); Material material = Material.valueOf(split[0].toUpperCase().replace("-", "_").replace(" ", "_"));
return split.length > 1 ? MMOLib.plugin.getVersion().getWrapper().textureItem(material, Integer.parseInt(split[1])) : new ItemStack(material); return split.length > 1 ? MMOLib.plugin.getVersion().getWrapper().textureItem(material, Integer.parseInt(split[1]))
: new ItemStack(material);
} catch (IllegalArgumentException exception) { } catch (IllegalArgumentException exception) {
return new ItemStack(Material.BARRIER); return new ItemStack(Material.BARRIER);
} }
@ -154,8 +157,20 @@ public class MMOCoreUtils {
} }
// TODO worldguard flags support for no target // TODO worldguard flags support for no target
public static boolean canTarget(Player player, Entity target) { public static boolean canTarget(PlayerData player, Entity target) {
return !player.equals(target) && target instanceof LivingEntity && !target.isDead() && !MMOCore.plugin.entities.findCustom(target);
// basic checks
if (!(target instanceof LivingEntity) || player.getPlayer().equals(target) || target.isDead() || MMOCore.plugin.entities.findCustom(target))
return false;
// party check
if (target instanceof Player) {
PlayerData targetData = PlayerData.get((Player) target);
if (targetData.hasParty() && targetData.getParty().getMembers().has(player))
return false;
}
return true;
} }
public static void heal(LivingEntity target, double value) { public static void heal(LivingEntity target, double value) {

View File

@ -104,7 +104,7 @@ public class Empowered_Attack extends Skill {
Location src = target.getLocation().add(0, target.getHeight() / 2, 0); Location src = target.getLocation().add(0, target.getHeight() / 2, 0);
for (Entity entity : target.getNearbyEntities(rad, rad, rad)) for (Entity entity : target.getNearbyEntities(rad, rad, rad))
if (MMOCoreUtils.canTarget(player.getPlayer(), entity)) { if (MMOCoreUtils.canTarget(player, entity)) {
drawVector(src, entity.getLocation().add(0, entity.getHeight() / 2, 0).subtract(src).toVector()); drawVector(src, entity.getLocation().add(0, entity.getHeight() / 2, 0).subtract(src).toVector());
MMOLib.plugin.getDamage().damage(player.getPlayer(), (LivingEntity) entity, new AttackResult(sweep, DamageType.SKILL, DamageType.PHYSICAL)); MMOLib.plugin.getDamage().damage(player.getPlayer(), (LivingEntity) entity, new AttackResult(sweep, DamageType.SKILL, DamageType.PHYSICAL));
} }

View File

@ -131,7 +131,7 @@ public class Fire_Rage extends Skill {
loc.getWorld().spawnParticle(Particle.LAVA, loc, 0); loc.getWorld().spawnParticle(Particle.LAVA, loc, 0);
for (Entity target : MMOCoreUtils.getNearbyChunkEntities(loc)) for (Entity target : MMOCoreUtils.getNearbyChunkEntities(loc))
if (MMOLib.plugin.getNMS().isInBoundingBox(target, loc) && MMOCoreUtils.canTarget(data.getPlayer(), target)) { if (MMOLib.plugin.getNMS().isInBoundingBox(target, loc) && MMOCoreUtils.canTarget(data, target)) {
loc.getWorld().spawnParticle(Particle.LAVA, loc, 8); loc.getWorld().spawnParticle(Particle.LAVA, loc, 8);
loc.getWorld().spawnParticle(Particle.FLAME, loc, 32, 0, 0, 0, .1); loc.getWorld().spawnParticle(Particle.FLAME, loc, 32, 0, 0, 0, .1);
loc.getWorld().playSound(loc, Sound.ENTITY_BLAZE_HURT, 2, 1); loc.getWorld().playSound(loc, Sound.ENTITY_BLAZE_HURT, 2, 1);

View File

@ -60,7 +60,7 @@ public class Fireball extends Skill {
loc.getWorld().spawnParticle(Particle.LAVA, loc, 0); loc.getWorld().spawnParticle(Particle.LAVA, loc, 0);
for (Entity target : MMOCoreUtils.getNearbyChunkEntities(loc)) for (Entity target : MMOCoreUtils.getNearbyChunkEntities(loc))
if (MMOLib.plugin.getNMS().isInBoundingBox(target, loc) && MMOCoreUtils.canTarget(data.getPlayer(), target)) { if (MMOLib.plugin.getNMS().isInBoundingBox(target, loc) && MMOCoreUtils.canTarget(data, target)) {
loc.getWorld().spawnParticle(Particle.LAVA, loc, 8); loc.getWorld().spawnParticle(Particle.LAVA, loc, 8);
loc.getWorld().spawnParticle(Particle.FLAME, loc, 32, 0, 0, 0, .1); loc.getWorld().spawnParticle(Particle.FLAME, loc, 32, 0, 0, 0, .1);
loc.getWorld().playSound(loc, Sound.ENTITY_BLAZE_HURT, 2, 1); loc.getWorld().playSound(loc, Sound.ENTITY_BLAZE_HURT, 2, 1);
@ -82,7 +82,7 @@ public class Fireball extends Skill {
Vector dir = randomDirection(); Vector dir = randomDirection();
loc.getWorld().playSound(loc, Sound.ENTITY_BLAZE_HURT, 2, 1.5f); loc.getWorld().playSound(loc, Sound.ENTITY_BLAZE_HURT, 2, 1.5f);
MMORayTraceResult result = MMOLib.plugin.getVersion().getWrapper().rayTrace(loc, dir, range, entity -> MMOCoreUtils.canTarget(data.getPlayer(), entity)); MMORayTraceResult result = MMOLib.plugin.getVersion().getWrapper().rayTrace(loc, dir, range, entity -> MMOCoreUtils.canTarget(data, entity));
if (result.hasHit()) if (result.hasHit())
MMOLib.plugin.getDamage().damage(data.getPlayer(), result.getHit(), new AttackResult(damage, DamageType.SKILL, DamageType.PROJECTILE, DamageType.MAGIC)); MMOLib.plugin.getDamage().damage(data.getPlayer(), result.getHit(), new AttackResult(damage, DamageType.SKILL, DamageType.PROJECTILE, DamageType.MAGIC));
result.draw(loc.clone(), dir, 8, tick -> tick.getWorld().spawnParticle(Particle.FLAME, tick, 0)); result.draw(loc.clone(), dir, 8, tick -> tick.getWorld().spawnParticle(Particle.FLAME, tick, 0));

View File

@ -65,7 +65,7 @@ public class Ice_Spikes extends Skill {
Line3D line = new Line3D(loc.toVector(), loc.toVector().add(new Vector(0, 1, 0))); Line3D line = new Line3D(loc.toVector(), loc.toVector().add(new Vector(0, 1, 0)));
for (Entity entity : MMOCoreUtils.getNearbyChunkEntities(loc1)) for (Entity entity : MMOCoreUtils.getNearbyChunkEntities(loc1))
if (line.distanceSquared(entity.getLocation().toVector()) < radius && Math.abs(entity.getLocation().getY() - loc1.getY()) < 10 && MMOCoreUtils.canTarget(data.getPlayer(), entity)) { if (line.distanceSquared(entity.getLocation().toVector()) < radius && Math.abs(entity.getLocation().getY() - loc1.getY()) < 10 && MMOCoreUtils.canTarget(data, entity)) {
MMOLib.plugin.getDamage().damage(data.getPlayer(), (LivingEntity) entity, new AttackResult(damage, DamageType.SKILL, DamageType.MAGIC)); MMOLib.plugin.getDamage().damage(data.getPlayer(), (LivingEntity) entity, new AttackResult(damage, DamageType.SKILL, DamageType.MAGIC));
((LivingEntity) entity).addPotionEffect(new PotionEffect(PotionEffectType.SLOW, slow, 0)); ((LivingEntity) entity).addPotionEffect(new PotionEffect(PotionEffectType.SLOW, slow, 0));
} }

View File

@ -113,7 +113,7 @@ public class Power_Mark extends Skill implements Listener {
stun += Math.log(Math.max(1, accumulate - 10)) / 8; stun += Math.log(Math.max(1, accumulate - 10)) / 8;
for (Entity entity : MMOCoreUtils.getNearbyChunkEntities(loc)) for (Entity entity : MMOCoreUtils.getNearbyChunkEntities(loc))
if (entity.getLocation().distanceSquared(loc) < 25 && MMOCoreUtils.canTarget(data.getPlayer(), entity)) { if (entity.getLocation().distanceSquared(loc) < 25 && MMOCoreUtils.canTarget(data, entity)) {
((LivingEntity) entity).addPotionEffect(new PotionEffect(PotionEffectType.SLOW, (int) (stun * 20), 10, false, false)); ((LivingEntity) entity).addPotionEffect(new PotionEffect(PotionEffectType.SLOW, (int) (stun * 20), 10, false, false));
MMOLib.plugin.getDamage().damage(data.getPlayer(), (LivingEntity) entity, new AttackResult(accumulate, DamageType.SKILL, DamageType.MAGIC)); MMOLib.plugin.getDamage().damage(data.getPlayer(), (LivingEntity) entity, new AttackResult(accumulate, DamageType.SKILL, DamageType.MAGIC));
entity.setVelocity(format(entity.getLocation().subtract(loc).toVector().setY(0)).setY(.3)); entity.setVelocity(format(entity.getLocation().subtract(loc).toVector().setY(0)).setY(.3));