mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2024-12-23 04:47:34 +01:00
!Made most ability listeners temporary
This commit is contained in:
parent
7c150de7de
commit
91e5d6fad0
@ -1,12 +1,15 @@
|
||||
package net.Indyuce.mmoitems.ability;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Snowball;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
@ -16,11 +19,13 @@ import net.Indyuce.mmoitems.api.ability.Ability;
|
||||
import net.Indyuce.mmoitems.api.ability.AbilityResult;
|
||||
import net.Indyuce.mmoitems.api.ability.SimpleAbilityResult;
|
||||
import net.Indyuce.mmoitems.api.player.PlayerStats.CachedStats;
|
||||
import net.Indyuce.mmoitems.api.util.TemporaryListener;
|
||||
import net.Indyuce.mmoitems.stat.data.AbilityData;
|
||||
|
||||
public class Blizzard extends Ability implements Listener {
|
||||
public class Blizzard extends Ability {
|
||||
public Blizzard() {
|
||||
super(CastingMode.ON_HIT, CastingMode.WHEN_HIT, CastingMode.LEFT_CLICK, CastingMode.RIGHT_CLICK, CastingMode.SHIFT_LEFT_CLICK, CastingMode.SHIFT_RIGHT_CLICK);
|
||||
super(CastingMode.ON_HIT, CastingMode.WHEN_HIT, CastingMode.LEFT_CLICK, CastingMode.RIGHT_CLICK, CastingMode.SHIFT_LEFT_CLICK,
|
||||
CastingMode.SHIFT_RIGHT_CLICK);
|
||||
|
||||
addModifier("duration", 2.5);
|
||||
addModifier("damage", 2);
|
||||
@ -44,12 +49,14 @@ public class Blizzard extends Ability implements Listener {
|
||||
|
||||
new BukkitRunnable() {
|
||||
int j = 0;
|
||||
double damage = ability.getModifier("damage");
|
||||
SnowballThrower handler = new SnowballThrower(ability.getModifier("damage"));
|
||||
|
||||
public void run() {
|
||||
j++;
|
||||
if (j > duration)
|
||||
if (j++ > duration) {
|
||||
handler.close(5 * 20);
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
Location loc = stats.getPlayer().getEyeLocation();
|
||||
loc.setPitch((float) (loc.getPitch() + (random.nextDouble() - .5) * inaccuracy));
|
||||
@ -58,18 +65,25 @@ public class Blizzard extends Ability implements Listener {
|
||||
loc.getWorld().playSound(loc, Sound.ENTITY_SNOWBALL_THROW, 1, 1);
|
||||
Snowball snowball = stats.getPlayer().launchProjectile(Snowball.class);
|
||||
snowball.setVelocity(loc.getDirection().multiply(1.3 * force));
|
||||
MMOItems.plugin.getEntities().registerCustomEntity(snowball, damage);
|
||||
handler.entities.add(snowball.getUniqueId());
|
||||
}
|
||||
}.runTaskTimer(MMOItems.plugin, 0, 2);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void a(EntityDamageByEntityEvent event) {
|
||||
if (!(event.getDamager() instanceof Snowball))
|
||||
return;
|
||||
public class SnowballThrower extends TemporaryListener {
|
||||
private final List<UUID> entities = new ArrayList<>();
|
||||
private final double damage;
|
||||
|
||||
Snowball snowball = (Snowball) event.getDamager();
|
||||
if (MMOItems.plugin.getEntities().isCustomEntity(snowball))
|
||||
event.setDamage((double) MMOItems.plugin.getEntities().getEntityData(snowball)[0]);
|
||||
public SnowballThrower(double damage) {
|
||||
super(EntityDamageByEntityEvent.getHandlerList());
|
||||
|
||||
this.damage = damage;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void a(EntityDamageByEntityEvent event) {
|
||||
if (entities.contains(event.getDamager().getUniqueId()))
|
||||
event.setDamage(damage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,11 @@
|
||||
package net.Indyuce.mmoitems.ability;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
@ -19,14 +16,14 @@ import net.Indyuce.mmoitems.api.ability.Ability;
|
||||
import net.Indyuce.mmoitems.api.ability.AbilityResult;
|
||||
import net.Indyuce.mmoitems.api.ability.SimpleAbilityResult;
|
||||
import net.Indyuce.mmoitems.api.player.PlayerStats.CachedStats;
|
||||
import net.Indyuce.mmoitems.api.util.TemporaryListener;
|
||||
import net.Indyuce.mmoitems.stat.data.AbilityData;
|
||||
import net.mmogroup.mmolib.version.VersionSound;
|
||||
|
||||
public class Bunny_Mode extends Ability implements Listener {
|
||||
private Map<UUID, Long> fallDamage = new HashMap<UUID, Long>();
|
||||
|
||||
public class Bunny_Mode extends Ability {
|
||||
public Bunny_Mode() {
|
||||
super(CastingMode.ON_HIT, CastingMode.WHEN_HIT, CastingMode.LEFT_CLICK, CastingMode.RIGHT_CLICK, CastingMode.SHIFT_LEFT_CLICK, CastingMode.SHIFT_RIGHT_CLICK);
|
||||
super(CastingMode.ON_HIT, CastingMode.WHEN_HIT, CastingMode.LEFT_CLICK, CastingMode.RIGHT_CLICK, CastingMode.SHIFT_LEFT_CLICK,
|
||||
CastingMode.SHIFT_RIGHT_CLICK);
|
||||
|
||||
addModifier("duration", 20);
|
||||
addModifier("jump-force", 1);
|
||||
@ -49,39 +46,43 @@ public class Bunny_Mode extends Ability implements Listener {
|
||||
|
||||
new BukkitRunnable() {
|
||||
int j = 0;
|
||||
BunnyHandler handler = new BunnyHandler(stats.getPlayer(), duration);
|
||||
|
||||
public void run() {
|
||||
j++;
|
||||
if (j > duration)
|
||||
if (j++ > duration) {
|
||||
handler.close(3 * 20);
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
if (stats.getPlayer().getLocation().add(0, -.5, 0).getBlock().getType().isSolid()) {
|
||||
stats.getPlayer().setVelocity(stats.getPlayer().getEyeLocation().getDirection().setY(0).normalize().multiply(.8 * xz).setY(0.5 * y / xz));
|
||||
stats.getPlayer()
|
||||
.setVelocity(stats.getPlayer().getEyeLocation().getDirection().setY(0).normalize().multiply(.8 * xz).setY(0.5 * y / xz));
|
||||
stats.getPlayer().getWorld().playSound(stats.getPlayer().getLocation(), VersionSound.ENTITY_ENDER_DRAGON_FLAP.toSound(), 2, 1);
|
||||
for (double a = 0; a < Math.PI * 2; a += Math.PI / 12)
|
||||
stats.getPlayer().getWorld().spawnParticle(Particle.CLOUD, stats.getPlayer().getLocation(), 0, Math.cos(a), 0, Math.sin(a), .2);
|
||||
stats.getPlayer().getWorld().spawnParticle(Particle.CLOUD, stats.getPlayer().getLocation(), 0, Math.cos(a), 0, Math.sin(a),
|
||||
.2);
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(MMOItems.plugin, 0, 1);
|
||||
|
||||
fallDamage.put(stats.getPlayer().getUniqueId(), (long) (System.currentTimeMillis() + duration * 100 + 3000));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void a(EntityDamageEvent event) {
|
||||
if (!(event.getEntity() instanceof Player) || event.getCause() != DamageCause.FALL)
|
||||
return;
|
||||
public class BunnyHandler extends TemporaryListener {
|
||||
private final Player player;
|
||||
|
||||
Player player = (Player) event.getEntity();
|
||||
if (!fallDamage.containsKey(player.getUniqueId()))
|
||||
return;
|
||||
public BunnyHandler(Player player, double duration) {
|
||||
super(EntityDamageEvent.getHandlerList());
|
||||
|
||||
if (fallDamage.get(player.getUniqueId()) > System.currentTimeMillis()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
this.player = player;
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(MMOItems.plugin, () -> close(), (long) (duration * 20));
|
||||
}
|
||||
|
||||
// clear player from map not to overload memory
|
||||
fallDamage.remove(player.getUniqueId());
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void a(EntityDamageEvent event) {
|
||||
if (event.getEntity().equals(player) && event.getCause() == DamageCause.FALL)
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import org.bukkit.Particle;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
@ -20,9 +19,10 @@ import net.Indyuce.mmoitems.stat.data.AbilityData;
|
||||
import net.mmogroup.mmolib.api.AttackResult;
|
||||
import net.mmogroup.mmolib.api.DamageType;
|
||||
|
||||
public class Burning_Hands extends Ability implements Listener {
|
||||
public class Burning_Hands extends Ability {
|
||||
public Burning_Hands() {
|
||||
super(CastingMode.ON_HIT, CastingMode.WHEN_HIT, CastingMode.LEFT_CLICK, CastingMode.RIGHT_CLICK, CastingMode.SHIFT_LEFT_CLICK, CastingMode.SHIFT_RIGHT_CLICK);
|
||||
super(CastingMode.ON_HIT, CastingMode.WHEN_HIT, CastingMode.LEFT_CLICK, CastingMode.RIGHT_CLICK, CastingMode.SHIFT_LEFT_CLICK,
|
||||
CastingMode.SHIFT_RIGHT_CLICK);
|
||||
|
||||
addModifier("duration", 3);
|
||||
addModifier("damage", 2);
|
||||
@ -45,8 +45,7 @@ public class Burning_Hands extends Ability implements Listener {
|
||||
int j = 0;
|
||||
|
||||
public void run() {
|
||||
j++;
|
||||
if (j > duration)
|
||||
if (j++ > duration)
|
||||
cancel();
|
||||
|
||||
Location loc = stats.getPlayer().getLocation().add(0, 1.2, 0);
|
||||
@ -63,7 +62,10 @@ public class Burning_Hands extends Ability implements Listener {
|
||||
|
||||
if (j % 5 == 0)
|
||||
for (Entity entity : MMOUtils.getNearbyChunkEntities(loc))
|
||||
if (entity.getLocation().distanceSquared(loc) < 60 && stats.getPlayer().getEyeLocation().getDirection().angle(entity.getLocation().toVector().subtract(stats.getPlayer().getLocation().toVector())) < Math.PI / 6 && MMOUtils.canDamage(stats.getPlayer(), entity))
|
||||
if (entity.getLocation().distanceSquared(loc) < 60
|
||||
&& stats.getPlayer().getEyeLocation().getDirection()
|
||||
.angle(entity.getLocation().toVector().subtract(stats.getPlayer().getLocation().toVector())) < Math.PI / 6
|
||||
&& MMOUtils.canDamage(stats.getPlayer(), entity))
|
||||
new AttackResult(damage, DamageType.SKILL, DamageType.MAGIC).damage(stats.getPlayer(), (LivingEntity) entity);
|
||||
|
||||
}
|
||||
|
@ -1,11 +1,14 @@
|
||||
package net.Indyuce.mmoitems.ability;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Egg;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
@ -15,11 +18,13 @@ import net.Indyuce.mmoitems.api.ability.Ability;
|
||||
import net.Indyuce.mmoitems.api.ability.AbilityResult;
|
||||
import net.Indyuce.mmoitems.api.ability.SimpleAbilityResult;
|
||||
import net.Indyuce.mmoitems.api.player.PlayerStats.CachedStats;
|
||||
import net.Indyuce.mmoitems.api.util.TemporaryListener;
|
||||
import net.Indyuce.mmoitems.stat.data.AbilityData;
|
||||
|
||||
public class Chicken_Wraith extends Ability implements Listener {
|
||||
public class Chicken_Wraith extends Ability {
|
||||
public Chicken_Wraith() {
|
||||
super(CastingMode.ON_HIT, CastingMode.WHEN_HIT, CastingMode.LEFT_CLICK, CastingMode.RIGHT_CLICK, CastingMode.SHIFT_LEFT_CLICK, CastingMode.SHIFT_RIGHT_CLICK);
|
||||
super(CastingMode.ON_HIT, CastingMode.WHEN_HIT, CastingMode.LEFT_CLICK, CastingMode.RIGHT_CLICK, CastingMode.SHIFT_LEFT_CLICK,
|
||||
CastingMode.SHIFT_RIGHT_CLICK);
|
||||
|
||||
addModifier("duration", 2.5);
|
||||
addModifier("damage", 2);
|
||||
@ -43,32 +48,42 @@ public class Chicken_Wraith extends Ability implements Listener {
|
||||
|
||||
new BukkitRunnable() {
|
||||
int j = 0;
|
||||
double damage = ability.getModifier("damage");
|
||||
EggHandler handler = new EggHandler(ability.getModifier("damage"));
|
||||
|
||||
public void run() {
|
||||
j++;
|
||||
if (j > duration)
|
||||
if (j++ > duration) {
|
||||
handler.close(5 * 20);
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
Location loc = stats.getPlayer().getEyeLocation();
|
||||
loc.setPitch((float) (loc.getPitch() + (random.nextDouble() - .5) * inaccuracy));
|
||||
loc.setYaw((float) (loc.getYaw() + (random.nextDouble() - .5) * inaccuracy));
|
||||
|
||||
loc.getWorld().playSound(loc, Sound.ENTITY_CHICKEN_EGG, 1, 1);
|
||||
Egg snowball = stats.getPlayer().launchProjectile(Egg.class);
|
||||
snowball.setVelocity(loc.getDirection().multiply(1.3 * force));
|
||||
MMOItems.plugin.getEntities().registerCustomEntity(snowball, damage);
|
||||
Egg egg = stats.getPlayer().launchProjectile(Egg.class);
|
||||
egg.setVelocity(loc.getDirection().multiply(1.3 * force));
|
||||
|
||||
handler.entities.add(egg.getEntityId());
|
||||
}
|
||||
}.runTaskTimer(MMOItems.plugin, 0, 2);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void a(EntityDamageByEntityEvent event) {
|
||||
if (!(event.getDamager() instanceof Egg))
|
||||
return;
|
||||
public class EggHandler extends TemporaryListener {
|
||||
private final List<Integer> entities = new ArrayList<>();
|
||||
private final double damage;
|
||||
|
||||
Egg egg = (Egg) event.getDamager();
|
||||
if (MMOItems.plugin.getEntities().isCustomEntity(egg))
|
||||
event.setDamage((double) MMOItems.plugin.getEntities().getEntityData(egg)[0]);
|
||||
public EggHandler(double damage) {
|
||||
super(EntityDamageByEntityEvent.getHandlerList());
|
||||
|
||||
this.damage = damage;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void a(EntityDamageByEntityEvent event) {
|
||||
if (entities.contains(event.getDamager().getEntityId()))
|
||||
event.setDamage(damage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
package net.Indyuce.mmoitems.ability;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.EntityType;
|
||||
@ -18,13 +21,15 @@ import net.Indyuce.mmoitems.api.ability.Ability;
|
||||
import net.Indyuce.mmoitems.api.ability.AbilityResult;
|
||||
import net.Indyuce.mmoitems.api.ability.VectorAbilityResult;
|
||||
import net.Indyuce.mmoitems.api.player.PlayerStats.CachedStats;
|
||||
import net.Indyuce.mmoitems.api.util.TemporaryListener;
|
||||
import net.Indyuce.mmoitems.stat.data.AbilityData;
|
||||
import net.mmogroup.mmolib.api.AttackResult;
|
||||
import net.mmogroup.mmolib.api.DamageType;
|
||||
|
||||
public class Corrupted_Fangs extends Ability implements Listener {
|
||||
public Corrupted_Fangs() {
|
||||
super(CastingMode.ON_HIT, CastingMode.WHEN_HIT, CastingMode.LEFT_CLICK, CastingMode.RIGHT_CLICK, CastingMode.SHIFT_LEFT_CLICK, CastingMode.SHIFT_RIGHT_CLICK);
|
||||
super(CastingMode.ON_HIT, CastingMode.WHEN_HIT, CastingMode.LEFT_CLICK, CastingMode.RIGHT_CLICK, CastingMode.SHIFT_LEFT_CLICK,
|
||||
CastingMode.SHIFT_RIGHT_CLICK);
|
||||
|
||||
addModifier("damage", 5);
|
||||
addModifier("cooldown", 12);
|
||||
@ -39,39 +44,45 @@ public class Corrupted_Fangs extends Ability implements Listener {
|
||||
|
||||
@Override
|
||||
public void whenCast(CachedStats stats, AbilityResult ability, ItemAttackResult result) {
|
||||
double damage = ability.getModifier("damage");
|
||||
|
||||
stats.getPlayer().getWorld().playSound(stats.getPlayer().getLocation(), Sound.ENTITY_WITHER_SHOOT, 2, 2);
|
||||
new BukkitRunnable() {
|
||||
Vector vec = ((VectorAbilityResult) ability).getTarget().setY(0).multiply(2);
|
||||
Location loc = stats.getPlayer().getLocation();
|
||||
double ti = 0;
|
||||
FangsHandler handler = new FangsHandler(stats, ability.getModifier("damage"));
|
||||
|
||||
public void run() {
|
||||
ti += 2;
|
||||
loc.add(vec);
|
||||
|
||||
EvokerFangs evokerFangs = (EvokerFangs) stats.getPlayer().getWorld().spawnEntity(loc, EntityType.EVOKER_FANGS);
|
||||
MMOItems.plugin.getEntities().registerCustomEntity(evokerFangs, stats, damage);
|
||||
|
||||
if (ti > 12)
|
||||
if (ti++ > 6) {
|
||||
handler.close(3 * 20);
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
loc.add(vec);
|
||||
EvokerFangs evokerFangs = (EvokerFangs) stats.getPlayer().getWorld().spawnEntity(loc, EntityType.EVOKER_FANGS);
|
||||
handler.entities.add(evokerFangs.getEntityId());
|
||||
}
|
||||
}.runTaskTimer(MMOItems.plugin, 0, 1);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void a(EntityDamageByEntityEvent event) {
|
||||
if (event.getDamager() instanceof EvokerFangs && event.getEntity() instanceof LivingEntity) {
|
||||
EvokerFangs damager = (EvokerFangs) event.getDamager();
|
||||
if (!MMOItems.plugin.getEntities().isCustomEntity(damager))
|
||||
return;
|
||||
public class FangsHandler extends TemporaryListener {
|
||||
private final List<Integer> entities = new ArrayList<>();
|
||||
private final CachedStats stats;
|
||||
private final double damage;
|
||||
|
||||
event.setCancelled(true);
|
||||
Object[] data = MMOItems.plugin.getEntities().getEntityData(damager);
|
||||
CachedStats stats = (CachedStats) data[0];
|
||||
if (MMOUtils.canDamage(stats.getPlayer(), event.getEntity()))
|
||||
new AttackResult((double) data[1], DamageType.SKILL, DamageType.MAGIC).damage(stats.getPlayer(), (LivingEntity) event.getEntity());
|
||||
public FangsHandler(CachedStats stats, double damage) {
|
||||
super(EntityDamageByEntityEvent.getHandlerList());
|
||||
|
||||
this.stats = stats;
|
||||
this.damage = damage;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void a(EntityDamageByEntityEvent event) {
|
||||
if (event.getDamager() instanceof EvokerFangs && entities.contains(event.getDamager().getEntityId())
|
||||
&& MMOUtils.canDamage(stats.getPlayer(), event.getEntity()))
|
||||
new AttackResult(damage, DamageType.SKILL, DamageType.MAGIC).damage(stats.getPlayer(), (LivingEntity) event.getEntity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,13 +20,15 @@ import net.Indyuce.mmoitems.api.ability.Ability;
|
||||
import net.Indyuce.mmoitems.api.ability.AbilityResult;
|
||||
import net.Indyuce.mmoitems.api.ability.SimpleAbilityResult;
|
||||
import net.Indyuce.mmoitems.api.player.PlayerStats.CachedStats;
|
||||
import net.Indyuce.mmoitems.api.util.TemporaryListener;
|
||||
import net.Indyuce.mmoitems.stat.data.AbilityData;
|
||||
import net.mmogroup.mmolib.api.AttackResult;
|
||||
import net.mmogroup.mmolib.api.DamageType;
|
||||
|
||||
public class Explosive_Turkey extends Ability implements Listener {
|
||||
public Explosive_Turkey() {
|
||||
super(CastingMode.ON_HIT, CastingMode.WHEN_HIT, CastingMode.LEFT_CLICK, CastingMode.RIGHT_CLICK, CastingMode.SHIFT_LEFT_CLICK, CastingMode.SHIFT_RIGHT_CLICK);
|
||||
super(CastingMode.ON_HIT, CastingMode.WHEN_HIT, CastingMode.LEFT_CLICK, CastingMode.RIGHT_CLICK, CastingMode.SHIFT_LEFT_CLICK,
|
||||
CastingMode.SHIFT_RIGHT_CLICK);
|
||||
|
||||
addModifier("damage", 6);
|
||||
addModifier("radius", 4);
|
||||
@ -37,8 +39,6 @@ public class Explosive_Turkey extends Ability implements Listener {
|
||||
addModifier("stamina", 0);
|
||||
}
|
||||
|
||||
Chicken chicken = null;
|
||||
|
||||
@Override
|
||||
public AbilityResult whenRan(CachedStats stats, LivingEntity target, AbilityData ability, ItemAttackResult result) {
|
||||
return new SimpleAbilityResult(ability);
|
||||
@ -53,16 +53,20 @@ public class Explosive_Turkey extends Ability implements Listener {
|
||||
|
||||
Vector vec = stats.getPlayer().getEyeLocation().getDirection().clone().multiply(.6);
|
||||
|
||||
chicken = (Chicken) stats.getPlayer().getWorld().spawnEntity(stats.getPlayer().getLocation().add(0, 1.3, 0).add(vec), EntityType.CHICKEN);
|
||||
Chicken chicken = (Chicken) stats.getPlayer().getWorld().spawnEntity(stats.getPlayer().getLocation().add(0, 1.3, 0).add(vec),
|
||||
EntityType.CHICKEN);
|
||||
ChickenHandler chickenHandler = new ChickenHandler(chicken);
|
||||
chicken.setInvulnerable(true);
|
||||
chicken.setSilent(true);
|
||||
|
||||
/*
|
||||
* Sets the health to 2048 (Default max Spigot value)
|
||||
* which stops the bug where you can kill the chicken for a brief
|
||||
* few ticks after it spawns in!
|
||||
* Sets the health to 2048 (Default max Spigot value) which stops the
|
||||
* bug where you can kill the chicken for a brief few ticks after it
|
||||
* spawns in!
|
||||
*/
|
||||
chicken.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(2048);
|
||||
chicken.setHealth(2048);
|
||||
|
||||
/*
|
||||
* when items are moving through the air, they loose a percent of their
|
||||
* velocity proportionally to their coordinates in each axis. this means
|
||||
@ -75,47 +79,71 @@ public class Explosive_Turkey extends Ability implements Listener {
|
||||
final double trajRatio = chicken.getVelocity().getX() / chicken.getVelocity().getZ();
|
||||
|
||||
new BukkitRunnable() {
|
||||
double ti = 0;
|
||||
int ti = 0;
|
||||
|
||||
public void run() {
|
||||
if (ti++ > duration || chicken.isDead() || chicken == null) {
|
||||
chicken.remove();
|
||||
if (ti++ > duration || chicken.isDead()) {
|
||||
chickenHandler.close();
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
chicken.setVelocity(vec);
|
||||
if (ti % 4 == 0)
|
||||
chicken.getWorld().playSound(chicken.getLocation(), Sound.ENTITY_CHICKEN_HURT, 2, 1);
|
||||
chicken.getWorld().spawnParticle(Particle.EXPLOSION_NORMAL, chicken.getLocation().add(0, .3, 0), 0);
|
||||
chicken.getWorld().spawnParticle(Particle.FIREWORKS_SPARK, chicken.getLocation().add(0, .3, 0), 1, 0, 0, 0, .05);
|
||||
double currentTrajRatio = chicken.getVelocity().getX() / chicken.getVelocity().getZ();
|
||||
if (chicken.isOnGround() || Math.abs(trajRatio - currentTrajRatio) > .1) {
|
||||
chicken.remove();
|
||||
|
||||
chickenHandler.close();
|
||||
cancel();
|
||||
|
||||
chicken.getWorld().spawnParticle(Particle.FIREWORKS_SPARK, chicken.getLocation().add(0, .3, 0), 128, 0, 0, 0, .25);
|
||||
chicken.getWorld().spawnParticle(Particle.EXPLOSION_NORMAL, chicken.getLocation().add(0, .3, 0), 24, 0, 0, 0, .25);
|
||||
chicken.getWorld().playSound(chicken.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 2, 1.5f);
|
||||
for (Entity entity : MMOUtils.getNearbyChunkEntities(chicken.getLocation()))
|
||||
if (!entity.isDead() && entity.getLocation().distanceSquared(chicken.getLocation()) < radiusSquared && MMOUtils.canDamage(stats.getPlayer(), entity)) {
|
||||
new AttackResult(damage, DamageType.SKILL, DamageType.MAGIC, DamageType.PROJECTILE).damage(stats.getPlayer(), (LivingEntity) entity);
|
||||
entity.setVelocity(entity.getLocation().toVector().subtract(chicken.getLocation().toVector()).multiply(.1 * knockback).setY(.4 * knockback));
|
||||
if (!entity.isDead() && entity.getLocation().distanceSquared(chicken.getLocation()) < radiusSquared
|
||||
&& MMOUtils.canDamage(stats.getPlayer(), entity)) {
|
||||
new AttackResult(damage, DamageType.SKILL, DamageType.MAGIC, DamageType.PROJECTILE).damage(stats.getPlayer(),
|
||||
(LivingEntity) entity);
|
||||
entity.setVelocity(entity.getLocation().toVector().subtract(chicken.getLocation().toVector()).multiply(.1 * knockback)
|
||||
.setY(.4 * knockback));
|
||||
}
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
chicken.setVelocity(vec);
|
||||
}
|
||||
}.runTaskTimer(MMOItems.plugin, 0, 1);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void a(EntityDeathEvent event) {
|
||||
if (event.getEntity() == null || !event.getEntityType().equals(EntityType.CHICKEN))
|
||||
return;
|
||||
/*
|
||||
* this fixes an issue where chickens sometimes drop
|
||||
*/
|
||||
public class ChickenHandler extends TemporaryListener {
|
||||
private final Chicken chicken;
|
||||
|
||||
if (event.getEntity().equals(chicken)) {
|
||||
event.getDrops().clear();
|
||||
event.setDroppedExp(0);
|
||||
public ChickenHandler(Chicken chicken) {
|
||||
super(EntityDeathEvent.getHandlerList());
|
||||
|
||||
this.chicken = chicken;
|
||||
}
|
||||
|
||||
/*
|
||||
* make sure the chicken is ALWAYS killed, this class really uses
|
||||
* overkill methods but there are plently issues with chickens remaining
|
||||
*/
|
||||
@Override
|
||||
public void close() {
|
||||
chicken.remove();
|
||||
super.close();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void a(EntityDeathEvent event) {
|
||||
if (event.getEntity().equals(chicken)) {
|
||||
event.getDrops().clear();
|
||||
event.setDroppedExp(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,5 @@
|
||||
package net.Indyuce.mmoitems.ability;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
@ -26,10 +22,9 @@ import net.Indyuce.mmoitems.stat.data.AbilityData;
|
||||
import net.mmogroup.mmolib.version.VersionSound;
|
||||
|
||||
public class Shadow_Veil extends Ability implements Listener {
|
||||
public final List<UUID> shadowVeil = new ArrayList<>();
|
||||
|
||||
public Shadow_Veil() {
|
||||
super(CastingMode.ON_HIT, CastingMode.WHEN_HIT, CastingMode.LEFT_CLICK, CastingMode.RIGHT_CLICK, CastingMode.SHIFT_LEFT_CLICK, CastingMode.SHIFT_RIGHT_CLICK);
|
||||
super(CastingMode.ON_HIT, CastingMode.WHEN_HIT, CastingMode.LEFT_CLICK, CastingMode.RIGHT_CLICK, CastingMode.SHIFT_LEFT_CLICK,
|
||||
CastingMode.SHIFT_RIGHT_CLICK);
|
||||
|
||||
addModifier("cooldown", 35);
|
||||
addModifier("duration", 5);
|
||||
@ -46,69 +41,85 @@ public class Shadow_Veil extends Ability implements Listener {
|
||||
public void whenCast(CachedStats stats, AbilityResult ability, ItemAttackResult result) {
|
||||
double duration = ability.getModifier("duration");
|
||||
|
||||
shadowVeil.add(stats.getPlayer().getUniqueId());
|
||||
stats.getPlayer().getWorld().playSound(stats.getPlayer().getLocation(), VersionSound.ENTITY_ENDERMAN_TELEPORT.toSound(), 3, 0);
|
||||
for (Player online : Bukkit.getOnlinePlayers())
|
||||
online.hidePlayer(MMOItems.plugin, stats.getPlayer());
|
||||
|
||||
/*
|
||||
* clears the target of any entity around the player
|
||||
*/
|
||||
for (Mob serverEntities : stats.getPlayer().getWorld().getEntitiesByClass(Mob.class))
|
||||
if (serverEntities.getTarget() != null && serverEntities.getTarget().equals(stats.getPlayer()))
|
||||
serverEntities.setTarget(null);
|
||||
new BukkitRunnable() {
|
||||
double ti = 0;
|
||||
double y = 0;
|
||||
Location loc = stats.getPlayer().getLocation();
|
||||
|
||||
public void run() {
|
||||
ti++;
|
||||
if (ti > duration * 20) {
|
||||
for (Player online : Bukkit.getOnlinePlayers())
|
||||
online.showPlayer(MMOItems.plugin, stats.getPlayer());
|
||||
new ShadowVeilHandler(stats.getPlayer(), duration);
|
||||
}
|
||||
|
||||
shadowVeil.remove(stats.getPlayer().getUniqueId());
|
||||
stats.getPlayer().getWorld().spawnParticle(Particle.SMOKE_LARGE, stats.getPlayer().getLocation().add(0, 1, 0), 32, 0, 0, 0, .13);
|
||||
stats.getPlayer().getWorld().playSound(stats.getPlayer().getLocation(), VersionSound.ENTITY_ENDERMAN_TELEPORT.toSound(), 3, 0);
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
public class ShadowVeilHandler extends BukkitRunnable implements Listener {
|
||||
private final Player player;
|
||||
private final double duration;
|
||||
private final Location loc;
|
||||
|
||||
if (!shadowVeil.contains(stats.getPlayer().getUniqueId())) {
|
||||
for (Player online : Bukkit.getOnlinePlayers())
|
||||
online.showPlayer(MMOItems.plugin, stats.getPlayer());
|
||||
double ti = 0;
|
||||
double y = 0;
|
||||
boolean cancelled;
|
||||
|
||||
stats.getPlayer().getWorld().spawnParticle(Particle.SMOKE_LARGE, stats.getPlayer().getLocation().add(0, 1, 0), 32, 0, 0, 0, .13);
|
||||
stats.getPlayer().getWorld().playSound(stats.getPlayer().getLocation(), VersionSound.ENTITY_ENDERMAN_TELEPORT.toSound(), 3, 0);
|
||||
cancel();
|
||||
}
|
||||
public ShadowVeilHandler(Player player, double duration) {
|
||||
this.player = player;
|
||||
this.duration = duration;
|
||||
this.loc = player.getLocation();
|
||||
|
||||
if (y < 4)
|
||||
for (int j1 = 0; j1 < 5; j1++) {
|
||||
y += .04;
|
||||
for (int j = 0; j < 4; j++) {
|
||||
double xz = y * Math.PI * .8 + (j * Math.PI / 2);
|
||||
stats.getPlayer().getWorld().spawnParticle(Particle.SMOKE_LARGE, loc.clone().add(Math.cos(xz) * 2.5, y, Math.sin(xz) * 2.5), 0);
|
||||
}
|
||||
}
|
||||
runTaskTimer(MMOItems.plugin, 0, 1);
|
||||
Bukkit.getPluginManager().registerEvents(this, MMOItems.plugin);
|
||||
}
|
||||
|
||||
private void close() {
|
||||
if (ti < 0)
|
||||
return;
|
||||
|
||||
player.getWorld().spawnParticle(Particle.SMOKE_LARGE, player.getLocation().add(0, 1, 0), 32, 0, 0, 0, .13);
|
||||
player.getWorld().playSound(player.getLocation(), VersionSound.ENTITY_ENDERMAN_TELEPORT.toSound(), 3, 0);
|
||||
|
||||
// sets time to -1 so that next calls know the handler has already
|
||||
// been closed
|
||||
ti = -1;
|
||||
EntityDamageByEntityEvent.getHandlerList().unregister(this);
|
||||
EntityTargetEvent.getHandlerList().unregister(this);
|
||||
|
||||
for (Player online : Bukkit.getOnlinePlayers())
|
||||
online.showPlayer(MMOItems.plugin, player);
|
||||
|
||||
cancel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (ti++ > duration * 20 || !player.isOnline()) {
|
||||
close();
|
||||
return;
|
||||
}
|
||||
}.runTaskTimer(MMOItems.plugin, 0, 1);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void a(EntityDamageByEntityEvent event) {
|
||||
if (!(event.getDamager() instanceof Player))
|
||||
return;
|
||||
if (y < 4)
|
||||
for (int j1 = 0; j1 < 5; j1++) {
|
||||
y += .04;
|
||||
for (int j = 0; j < 4; j++) {
|
||||
double a = y * Math.PI * .8 + (j * Math.PI / 2);
|
||||
player.getWorld().spawnParticle(Particle.SMOKE_LARGE, loc.clone().add(Math.cos(a) * 2.5, y, Math.sin(a) * 2.5), 0);
|
||||
}
|
||||
}
|
||||
|
||||
Player player = (Player) event.getDamager();
|
||||
if (shadowVeil.contains(player.getUniqueId()))
|
||||
shadowVeil.remove(player.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void b(EntityTargetEvent event) {
|
||||
if (!(event.getTarget() instanceof Player))
|
||||
return;
|
||||
@EventHandler
|
||||
public void cancelShadowVeil(EntityDamageByEntityEvent event) {
|
||||
if (event.getDamager().equals(player))
|
||||
close();
|
||||
}
|
||||
|
||||
Player player = (Player) event.getTarget();
|
||||
if (shadowVeil.contains(player.getUniqueId()))
|
||||
event.setCancelled(true);
|
||||
@EventHandler
|
||||
public void cancelMobTarget(EntityTargetEvent event) {
|
||||
if (event.getTarget().equals(player))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,8 @@ import net.mmogroup.mmolib.api.item.NBTItem;
|
||||
|
||||
public class Shulker_Missile extends Ability implements Listener {
|
||||
public Shulker_Missile() {
|
||||
super(CastingMode.ON_HIT, CastingMode.WHEN_HIT, CastingMode.LEFT_CLICK, CastingMode.RIGHT_CLICK, CastingMode.SHIFT_LEFT_CLICK, CastingMode.SHIFT_RIGHT_CLICK);
|
||||
super(CastingMode.ON_HIT, CastingMode.WHEN_HIT, CastingMode.LEFT_CLICK, CastingMode.RIGHT_CLICK, CastingMode.SHIFT_LEFT_CLICK,
|
||||
CastingMode.SHIFT_RIGHT_CLICK);
|
||||
|
||||
addModifier("cooldown", 12);
|
||||
addModifier("damage", 5);
|
||||
@ -53,16 +54,19 @@ public class Shulker_Missile extends Ability implements Listener {
|
||||
double n = 0;
|
||||
|
||||
public void run() {
|
||||
n++;
|
||||
if (n > 3) {
|
||||
if (n++ > 3) {
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
Vector vec = ((VectorAbilityResult) ability).getTarget();
|
||||
stats.getPlayer().getWorld().playSound(stats.getPlayer().getLocation(), Sound.ENTITY_WITHER_SHOOT, 2, 2);
|
||||
ShulkerBullet shulkerBullet = (ShulkerBullet) stats.getPlayer().getWorld().spawnEntity(stats.getPlayer().getLocation().add(0, 1, 0), EntityType.SHULKER_BULLET);
|
||||
ShulkerBullet shulkerBullet = (ShulkerBullet) stats.getPlayer().getWorld().spawnEntity(stats.getPlayer().getLocation().add(0, 1, 0),
|
||||
EntityType.SHULKER_BULLET);
|
||||
shulkerBullet.setShooter(stats.getPlayer());
|
||||
MMOItems.plugin.getEntities().registerCustomEntity(shulkerBullet, new AttackResult(ability.getModifier("damage"), DamageType.SKILL, DamageType.MAGIC, DamageType.PROJECTILE), ability.getModifier("effect-duration"));
|
||||
MMOItems.plugin.getEntities().registerCustomEntity(shulkerBullet,
|
||||
new AttackResult(ability.getModifier("damage"), DamageType.SKILL, DamageType.MAGIC, DamageType.PROJECTILE),
|
||||
ability.getModifier("effect-duration"));
|
||||
new BukkitRunnable() {
|
||||
double ti = 0;
|
||||
|
||||
@ -117,7 +121,8 @@ public class Shulker_Missile extends Ability implements Listener {
|
||||
y += .04;
|
||||
for (int j = 0; j < 2; j++) {
|
||||
double xz = y * Math.PI * 1.3 + (j * Math.PI);
|
||||
MMOLib.plugin.getVersion().getWrapper().spawnParticle(Particle.REDSTONE, loc.clone().add(Math.cos(xz), y, Math.sin(xz)), Color.MAROON);
|
||||
MMOLib.plugin.getVersion().getWrapper().spawnParticle(Particle.REDSTONE, loc.clone().add(Math.cos(xz), y, Math.sin(xz)),
|
||||
Color.MAROON);
|
||||
}
|
||||
}
|
||||
if (y >= 2)
|
||||
|
@ -1,5 +1,9 @@
|
||||
package net.Indyuce.mmoitems.ability;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Sound;
|
||||
@ -8,6 +12,9 @@ import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Snowball;
|
||||
import org.bukkit.entity.Snowman;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
@ -19,12 +26,14 @@ import net.Indyuce.mmoitems.api.ability.Ability;
|
||||
import net.Indyuce.mmoitems.api.ability.AbilityResult;
|
||||
import net.Indyuce.mmoitems.api.ability.LocationAbilityResult;
|
||||
import net.Indyuce.mmoitems.api.player.PlayerStats.CachedStats;
|
||||
import net.Indyuce.mmoitems.api.util.TemporaryListener;
|
||||
import net.Indyuce.mmoitems.stat.data.AbilityData;
|
||||
import net.mmogroup.mmolib.version.VersionSound;
|
||||
|
||||
public class Snowman_Turret extends Ability {
|
||||
public Snowman_Turret() {
|
||||
super(CastingMode.ON_HIT, CastingMode.WHEN_HIT, CastingMode.LEFT_CLICK, CastingMode.RIGHT_CLICK, CastingMode.SHIFT_LEFT_CLICK, CastingMode.SHIFT_RIGHT_CLICK);
|
||||
super(CastingMode.ON_HIT, CastingMode.WHEN_HIT, CastingMode.LEFT_CLICK, CastingMode.RIGHT_CLICK, CastingMode.SHIFT_LEFT_CLICK,
|
||||
CastingMode.SHIFT_RIGHT_CLICK);
|
||||
|
||||
addModifier("duration", 6);
|
||||
addModifier("cooldown", 35);
|
||||
@ -44,7 +53,6 @@ public class Snowman_Turret extends Ability {
|
||||
Location loc = ((LocationAbilityResult) ability).getTarget();
|
||||
double duration = Math.min(ability.getModifier("duration") * 20, 300);
|
||||
double radiusSquared = Math.pow(ability.getModifier("radius"), 2);
|
||||
double damage1 = ability.getModifier("damage");
|
||||
|
||||
loc.getWorld().playSound(loc, VersionSound.ENTITY_ENDERMAN_TELEPORT.toSound(), 2, 1);
|
||||
final Snowman snowman = (Snowman) loc.getWorld().spawnEntity(loc.add(0, 1, 0), EntityType.SNOWMAN);
|
||||
@ -53,28 +61,50 @@ public class Snowman_Turret extends Ability {
|
||||
new BukkitRunnable() {
|
||||
int ti = 0;
|
||||
double j = 0;
|
||||
TurretHandler turret = new TurretHandler(ability.getModifier("damage"));
|
||||
|
||||
public void run() {
|
||||
if (ti++ > duration || stats.getPlayer().isDead() || snowman == null || snowman.isDead()) {
|
||||
turret.close(3 * 20);
|
||||
snowman.remove();
|
||||
cancel();
|
||||
}
|
||||
|
||||
j += Math.PI / 24 % (2 * Math.PI);
|
||||
for (double k = 0; k < 3; k++)
|
||||
snowman.getWorld().spawnParticle(Particle.SPELL_INSTANT, snowman.getLocation().add(Math.cos(j + k / 3 * 2 * Math.PI) * 1.3, 1, Math.sin(j + k / 3 * 2 * Math.PI) * 1.3), 0);
|
||||
snowman.getWorld().spawnParticle(Particle.SPELL_INSTANT,
|
||||
snowman.getLocation().add(Math.cos(j + k / 3 * 2 * Math.PI) * 1.3, 1, Math.sin(j + k / 3 * 2 * Math.PI) * 1.3), 0);
|
||||
snowman.getWorld().spawnParticle(Particle.SPELL_INSTANT, snowman.getLocation().add(0, 1, 0), 1, 0, 0, 0, .2);
|
||||
|
||||
if (ti % 2 == 0)
|
||||
for (Entity entity : snowman.getWorld().getEntities())
|
||||
if (!entity.equals(snowman) && MMOUtils.canDamage(stats.getPlayer(), entity) && entity.getLocation().distanceSquared(snowman.getLocation()) < radiusSquared) {
|
||||
for (Entity entity : MMOUtils.getNearbyChunkEntities(snowman.getLocation()))
|
||||
if (!entity.equals(snowman) && MMOUtils.canDamage(stats.getPlayer(), entity)
|
||||
&& entity.getLocation().distanceSquared(snowman.getLocation()) < radiusSquared) {
|
||||
snowman.getWorld().playSound(snowman.getLocation(), Sound.ENTITY_SNOWBALL_THROW, 1, 1.3f);
|
||||
Snowball snowball = snowman.launchProjectile(Snowball.class);
|
||||
snowball.setVelocity(entity.getLocation().add(0, entity.getHeight() / 2, 0).toVector().subtract(snowman.getLocation().add(0, 1, 0).toVector()).normalize().multiply(1.3));
|
||||
MMOItems.plugin.getEntities().registerCustomEntity(snowball, damage1);
|
||||
snowball.setVelocity(entity.getLocation().add(0, entity.getHeight() / 2, 0).toVector()
|
||||
.subtract(snowman.getLocation().add(0, 1, 0).toVector()).normalize().multiply(1.3));
|
||||
turret.entities.add(snowball.getUniqueId());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(MMOItems.plugin, 0, 1);
|
||||
}
|
||||
|
||||
public class TurretHandler extends TemporaryListener {
|
||||
private final List<UUID> entities = new ArrayList<>();
|
||||
private final double damage;
|
||||
|
||||
public TurretHandler(double damage) {
|
||||
super(EntityDamageByEntityEvent.getHandlerList());
|
||||
|
||||
this.damage = damage;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void a(EntityDamageByEntityEvent event) {
|
||||
if (entities.contains(event.getDamager().getUniqueId()))
|
||||
event.setDamage(damage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,27 +2,29 @@ package net.Indyuce.mmoitems.ability;
|
||||
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.MMOUtils;
|
||||
import net.Indyuce.mmoitems.api.ItemAttackResult;
|
||||
import net.Indyuce.mmoitems.api.ability.Ability;
|
||||
import net.Indyuce.mmoitems.api.ability.AbilityResult;
|
||||
import net.Indyuce.mmoitems.api.ability.VectorAbilityResult;
|
||||
import net.Indyuce.mmoitems.api.player.PlayerStats.CachedStats;
|
||||
import net.Indyuce.mmoitems.api.util.TemporaryListener;
|
||||
import net.Indyuce.mmoitems.stat.data.AbilityData;
|
||||
|
||||
public class TNT_Throw extends Ability implements Listener {
|
||||
public TNT_Throw() {
|
||||
super(CastingMode.ON_HIT, CastingMode.WHEN_HIT, CastingMode.LEFT_CLICK, CastingMode.RIGHT_CLICK, CastingMode.SHIFT_LEFT_CLICK, CastingMode.SHIFT_RIGHT_CLICK);
|
||||
super(CastingMode.ON_HIT, CastingMode.WHEN_HIT, CastingMode.LEFT_CLICK, CastingMode.RIGHT_CLICK, CastingMode.SHIFT_LEFT_CLICK,
|
||||
CastingMode.SHIFT_RIGHT_CLICK);
|
||||
|
||||
addModifier("cooldown", 10);
|
||||
addModifier("force", 1);
|
||||
@ -41,18 +43,31 @@ public class TNT_Throw extends Ability implements Listener {
|
||||
TNTPrimed tnt = (TNTPrimed) stats.getPlayer().getWorld().spawnEntity(stats.getPlayer().getLocation().add(0, 1, 0), EntityType.PRIMED_TNT);
|
||||
tnt.setFuseTicks(80);
|
||||
tnt.setVelocity(vec);
|
||||
MMOItems.plugin.getEntities().registerCustomEntity(tnt);
|
||||
new CancelTeamDamage(stats.getPlayer(), tnt);
|
||||
stats.getPlayer().getWorld().playSound(stats.getPlayer().getLocation(), Sound.ENTITY_SNOWBALL_THROW, 1, 0);
|
||||
stats.getPlayer().getWorld().spawnParticle(Particle.EXPLOSION_NORMAL, stats.getPlayer().getLocation().add(0, 1, 0), 12, 0, 0, 0, .1);
|
||||
}
|
||||
|
||||
/*
|
||||
* used to cancel team damage and other things
|
||||
*/
|
||||
public class CancelTeamDamage extends TemporaryListener {
|
||||
private final Player player;
|
||||
private final TNTPrimed tnt;
|
||||
|
||||
@EventHandler
|
||||
public void a(EntityDamageByEntityEvent event) {
|
||||
Entity damager = event.getDamager();
|
||||
if (damager instanceof TNTPrimed)
|
||||
if (MMOItems.plugin.getEntities().isCustomEntity(damager))
|
||||
if (!MMOUtils.canDamage(event.getEntity()))
|
||||
event.setCancelled(true);
|
||||
public CancelTeamDamage(Player player, TNTPrimed tnt) {
|
||||
super(EntityDamageByEntityEvent.getHandlerList());
|
||||
|
||||
this.player = player;
|
||||
this.tnt = tnt;
|
||||
|
||||
close(100);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void a(EntityDamageByEntityEvent event) {
|
||||
if (event.getDamager().equals(tnt) && !MMOUtils.canDamage(player, event.getEntity()))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -115,8 +115,8 @@ public class Weaken_Target extends Ability implements Listener {
|
||||
}
|
||||
|
||||
public class WeakenedInfo {
|
||||
private long date = System.currentTimeMillis();
|
||||
private double extraDamage;
|
||||
private final long date = System.currentTimeMillis();
|
||||
private final double extraDamage;
|
||||
|
||||
public WeakenedInfo(double extraDamage) {
|
||||
this.extraDamage = extraDamage / 100;
|
||||
|
@ -0,0 +1,43 @@
|
||||
package net.Indyuce.mmoitems.api.util;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
|
||||
public abstract class TemporaryListener implements Listener {
|
||||
|
||||
/*
|
||||
* handler lists which must be called when the temporary listener is closed
|
||||
* so that the listener is entirely unregistered.
|
||||
*/
|
||||
private final HandlerList[] lists;
|
||||
|
||||
/*
|
||||
* sometimes the close method is called twice because of a safe delayed task
|
||||
* not being cancelled when the listener is closed.
|
||||
*/
|
||||
private boolean closed;
|
||||
|
||||
public TemporaryListener(HandlerList... events) {
|
||||
lists = events;
|
||||
Bukkit.getPluginManager().registerEvents(this, MMOItems.plugin);
|
||||
}
|
||||
|
||||
/*
|
||||
* used to close the temporary listener after some delay
|
||||
*/
|
||||
public void close(long duration) {
|
||||
Bukkit.getScheduler().runTaskLater(MMOItems.plugin, () -> close(), duration);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
if (closed)
|
||||
return;
|
||||
|
||||
closed = true;
|
||||
for (HandlerList list : lists)
|
||||
list.unregister(this);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user