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;
|
package net.Indyuce.mmoitems.ability;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Snowball;
|
import org.bukkit.entity.Snowball;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
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.AbilityResult;
|
||||||
import net.Indyuce.mmoitems.api.ability.SimpleAbilityResult;
|
import net.Indyuce.mmoitems.api.ability.SimpleAbilityResult;
|
||||||
import net.Indyuce.mmoitems.api.player.PlayerStats.CachedStats;
|
import net.Indyuce.mmoitems.api.player.PlayerStats.CachedStats;
|
||||||
|
import net.Indyuce.mmoitems.api.util.TemporaryListener;
|
||||||
import net.Indyuce.mmoitems.stat.data.AbilityData;
|
import net.Indyuce.mmoitems.stat.data.AbilityData;
|
||||||
|
|
||||||
public class Blizzard extends Ability implements Listener {
|
public class Blizzard extends Ability {
|
||||||
public Blizzard() {
|
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("duration", 2.5);
|
||||||
addModifier("damage", 2);
|
addModifier("damage", 2);
|
||||||
@ -44,12 +49,14 @@ public class Blizzard extends Ability implements Listener {
|
|||||||
|
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
int j = 0;
|
int j = 0;
|
||||||
double damage = ability.getModifier("damage");
|
SnowballThrower handler = new SnowballThrower(ability.getModifier("damage"));
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
j++;
|
if (j++ > duration) {
|
||||||
if (j > duration)
|
handler.close(5 * 20);
|
||||||
cancel();
|
cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Location loc = stats.getPlayer().getEyeLocation();
|
Location loc = stats.getPlayer().getEyeLocation();
|
||||||
loc.setPitch((float) (loc.getPitch() + (random.nextDouble() - .5) * inaccuracy));
|
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);
|
loc.getWorld().playSound(loc, Sound.ENTITY_SNOWBALL_THROW, 1, 1);
|
||||||
Snowball snowball = stats.getPlayer().launchProjectile(Snowball.class);
|
Snowball snowball = stats.getPlayer().launchProjectile(Snowball.class);
|
||||||
snowball.setVelocity(loc.getDirection().multiply(1.3 * force));
|
snowball.setVelocity(loc.getDirection().multiply(1.3 * force));
|
||||||
MMOItems.plugin.getEntities().registerCustomEntity(snowball, damage);
|
handler.entities.add(snowball.getUniqueId());
|
||||||
}
|
}
|
||||||
}.runTaskTimer(MMOItems.plugin, 0, 2);
|
}.runTaskTimer(MMOItems.plugin, 0, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
public class SnowballThrower extends TemporaryListener {
|
||||||
public void a(EntityDamageByEntityEvent event) {
|
private final List<UUID> entities = new ArrayList<>();
|
||||||
if (!(event.getDamager() instanceof Snowball))
|
private final double damage;
|
||||||
return;
|
|
||||||
|
|
||||||
Snowball snowball = (Snowball) event.getDamager();
|
public SnowballThrower(double damage) {
|
||||||
if (MMOItems.plugin.getEntities().isCustomEntity(snowball))
|
super(EntityDamageByEntityEvent.getHandlerList());
|
||||||
event.setDamage((double) MMOItems.plugin.getEntities().getEntityData(snowball)[0]);
|
|
||||||
|
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;
|
package net.Indyuce.mmoitems.ability;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import org.bukkit.Bukkit;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.bukkit.Particle;
|
import org.bukkit.Particle;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
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;
|
||||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
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.AbilityResult;
|
||||||
import net.Indyuce.mmoitems.api.ability.SimpleAbilityResult;
|
import net.Indyuce.mmoitems.api.ability.SimpleAbilityResult;
|
||||||
import net.Indyuce.mmoitems.api.player.PlayerStats.CachedStats;
|
import net.Indyuce.mmoitems.api.player.PlayerStats.CachedStats;
|
||||||
|
import net.Indyuce.mmoitems.api.util.TemporaryListener;
|
||||||
import net.Indyuce.mmoitems.stat.data.AbilityData;
|
import net.Indyuce.mmoitems.stat.data.AbilityData;
|
||||||
import net.mmogroup.mmolib.version.VersionSound;
|
import net.mmogroup.mmolib.version.VersionSound;
|
||||||
|
|
||||||
public class Bunny_Mode extends Ability implements Listener {
|
public class Bunny_Mode extends Ability {
|
||||||
private Map<UUID, Long> fallDamage = new HashMap<UUID, Long>();
|
|
||||||
|
|
||||||
public Bunny_Mode() {
|
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("duration", 20);
|
||||||
addModifier("jump-force", 1);
|
addModifier("jump-force", 1);
|
||||||
@ -49,39 +46,43 @@ public class Bunny_Mode extends Ability implements Listener {
|
|||||||
|
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
int j = 0;
|
int j = 0;
|
||||||
|
BunnyHandler handler = new BunnyHandler(stats.getPlayer(), duration);
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
j++;
|
if (j++ > duration) {
|
||||||
if (j > duration)
|
handler.close(3 * 20);
|
||||||
cancel();
|
cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (stats.getPlayer().getLocation().add(0, -.5, 0).getBlock().getType().isSolid()) {
|
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);
|
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)
|
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);
|
}.runTaskTimer(MMOItems.plugin, 0, 1);
|
||||||
|
|
||||||
fallDamage.put(stats.getPlayer().getUniqueId(), (long) (System.currentTimeMillis() + duration * 100 + 3000));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
public class BunnyHandler extends TemporaryListener {
|
||||||
public void a(EntityDamageEvent event) {
|
private final Player player;
|
||||||
if (!(event.getEntity() instanceof Player) || event.getCause() != DamageCause.FALL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Player player = (Player) event.getEntity();
|
public BunnyHandler(Player player, double duration) {
|
||||||
if (!fallDamage.containsKey(player.getUniqueId()))
|
super(EntityDamageEvent.getHandlerList());
|
||||||
return;
|
|
||||||
|
|
||||||
if (fallDamage.get(player.getUniqueId()) > System.currentTimeMillis()) {
|
this.player = player;
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
Bukkit.getScheduler().runTaskLater(MMOItems.plugin, () -> close(), (long) (duration * 20));
|
||||||
}
|
}
|
||||||
|
|
||||||
// clear player from map not to overload memory
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
fallDamage.remove(player.getUniqueId());
|
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.Sound;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
import org.bukkit.util.Vector;
|
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.AttackResult;
|
||||||
import net.mmogroup.mmolib.api.DamageType;
|
import net.mmogroup.mmolib.api.DamageType;
|
||||||
|
|
||||||
public class Burning_Hands extends Ability implements Listener {
|
public class Burning_Hands extends Ability {
|
||||||
public Burning_Hands() {
|
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("duration", 3);
|
||||||
addModifier("damage", 2);
|
addModifier("damage", 2);
|
||||||
@ -45,8 +45,7 @@ public class Burning_Hands extends Ability implements Listener {
|
|||||||
int j = 0;
|
int j = 0;
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
j++;
|
if (j++ > duration)
|
||||||
if (j > duration)
|
|
||||||
cancel();
|
cancel();
|
||||||
|
|
||||||
Location loc = stats.getPlayer().getLocation().add(0, 1.2, 0);
|
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)
|
if (j % 5 == 0)
|
||||||
for (Entity entity : MMOUtils.getNearbyChunkEntities(loc))
|
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);
|
new AttackResult(damage, DamageType.SKILL, DamageType.MAGIC).damage(stats.getPlayer(), (LivingEntity) entity);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
package net.Indyuce.mmoitems.ability;
|
package net.Indyuce.mmoitems.ability;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.Egg;
|
import org.bukkit.entity.Egg;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
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.AbilityResult;
|
||||||
import net.Indyuce.mmoitems.api.ability.SimpleAbilityResult;
|
import net.Indyuce.mmoitems.api.ability.SimpleAbilityResult;
|
||||||
import net.Indyuce.mmoitems.api.player.PlayerStats.CachedStats;
|
import net.Indyuce.mmoitems.api.player.PlayerStats.CachedStats;
|
||||||
|
import net.Indyuce.mmoitems.api.util.TemporaryListener;
|
||||||
import net.Indyuce.mmoitems.stat.data.AbilityData;
|
import net.Indyuce.mmoitems.stat.data.AbilityData;
|
||||||
|
|
||||||
public class Chicken_Wraith extends Ability implements Listener {
|
public class Chicken_Wraith extends Ability {
|
||||||
public Chicken_Wraith() {
|
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("duration", 2.5);
|
||||||
addModifier("damage", 2);
|
addModifier("damage", 2);
|
||||||
@ -43,32 +48,42 @@ public class Chicken_Wraith extends Ability implements Listener {
|
|||||||
|
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
int j = 0;
|
int j = 0;
|
||||||
double damage = ability.getModifier("damage");
|
EggHandler handler = new EggHandler(ability.getModifier("damage"));
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
j++;
|
if (j++ > duration) {
|
||||||
if (j > duration)
|
handler.close(5 * 20);
|
||||||
cancel();
|
cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Location loc = stats.getPlayer().getEyeLocation();
|
Location loc = stats.getPlayer().getEyeLocation();
|
||||||
loc.setPitch((float) (loc.getPitch() + (random.nextDouble() - .5) * inaccuracy));
|
loc.setPitch((float) (loc.getPitch() + (random.nextDouble() - .5) * inaccuracy));
|
||||||
loc.setYaw((float) (loc.getYaw() + (random.nextDouble() - .5) * inaccuracy));
|
loc.setYaw((float) (loc.getYaw() + (random.nextDouble() - .5) * inaccuracy));
|
||||||
|
|
||||||
loc.getWorld().playSound(loc, Sound.ENTITY_CHICKEN_EGG, 1, 1);
|
loc.getWorld().playSound(loc, Sound.ENTITY_CHICKEN_EGG, 1, 1);
|
||||||
Egg snowball = stats.getPlayer().launchProjectile(Egg.class);
|
Egg egg = stats.getPlayer().launchProjectile(Egg.class);
|
||||||
snowball.setVelocity(loc.getDirection().multiply(1.3 * force));
|
egg.setVelocity(loc.getDirection().multiply(1.3 * force));
|
||||||
MMOItems.plugin.getEntities().registerCustomEntity(snowball, damage);
|
|
||||||
|
handler.entities.add(egg.getEntityId());
|
||||||
}
|
}
|
||||||
}.runTaskTimer(MMOItems.plugin, 0, 2);
|
}.runTaskTimer(MMOItems.plugin, 0, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
public class EggHandler extends TemporaryListener {
|
||||||
public void a(EntityDamageByEntityEvent event) {
|
private final List<Integer> entities = new ArrayList<>();
|
||||||
if (!(event.getDamager() instanceof Egg))
|
private final double damage;
|
||||||
return;
|
|
||||||
|
|
||||||
Egg egg = (Egg) event.getDamager();
|
public EggHandler(double damage) {
|
||||||
if (MMOItems.plugin.getEntities().isCustomEntity(egg))
|
super(EntityDamageByEntityEvent.getHandlerList());
|
||||||
event.setDamage((double) MMOItems.plugin.getEntities().getEntityData(egg)[0]);
|
|
||||||
|
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;
|
package net.Indyuce.mmoitems.ability;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.EntityType;
|
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.AbilityResult;
|
||||||
import net.Indyuce.mmoitems.api.ability.VectorAbilityResult;
|
import net.Indyuce.mmoitems.api.ability.VectorAbilityResult;
|
||||||
import net.Indyuce.mmoitems.api.player.PlayerStats.CachedStats;
|
import net.Indyuce.mmoitems.api.player.PlayerStats.CachedStats;
|
||||||
|
import net.Indyuce.mmoitems.api.util.TemporaryListener;
|
||||||
import net.Indyuce.mmoitems.stat.data.AbilityData;
|
import net.Indyuce.mmoitems.stat.data.AbilityData;
|
||||||
import net.mmogroup.mmolib.api.AttackResult;
|
import net.mmogroup.mmolib.api.AttackResult;
|
||||||
import net.mmogroup.mmolib.api.DamageType;
|
import net.mmogroup.mmolib.api.DamageType;
|
||||||
|
|
||||||
public class Corrupted_Fangs extends Ability implements Listener {
|
public class Corrupted_Fangs extends Ability implements Listener {
|
||||||
public Corrupted_Fangs() {
|
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("damage", 5);
|
||||||
addModifier("cooldown", 12);
|
addModifier("cooldown", 12);
|
||||||
@ -39,39 +44,45 @@ public class Corrupted_Fangs extends Ability implements Listener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void whenCast(CachedStats stats, AbilityResult ability, ItemAttackResult result) {
|
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);
|
stats.getPlayer().getWorld().playSound(stats.getPlayer().getLocation(), Sound.ENTITY_WITHER_SHOOT, 2, 2);
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
Vector vec = ((VectorAbilityResult) ability).getTarget().setY(0).multiply(2);
|
Vector vec = ((VectorAbilityResult) ability).getTarget().setY(0).multiply(2);
|
||||||
Location loc = stats.getPlayer().getLocation();
|
Location loc = stats.getPlayer().getLocation();
|
||||||
double ti = 0;
|
double ti = 0;
|
||||||
|
FangsHandler handler = new FangsHandler(stats, ability.getModifier("damage"));
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
ti += 2;
|
if (ti++ > 6) {
|
||||||
loc.add(vec);
|
handler.close(3 * 20);
|
||||||
|
|
||||||
EvokerFangs evokerFangs = (EvokerFangs) stats.getPlayer().getWorld().spawnEntity(loc, EntityType.EVOKER_FANGS);
|
|
||||||
MMOItems.plugin.getEntities().registerCustomEntity(evokerFangs, stats, damage);
|
|
||||||
|
|
||||||
if (ti > 12)
|
|
||||||
cancel();
|
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);
|
}.runTaskTimer(MMOItems.plugin, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
public class FangsHandler extends TemporaryListener {
|
||||||
public void a(EntityDamageByEntityEvent event) {
|
private final List<Integer> entities = new ArrayList<>();
|
||||||
if (event.getDamager() instanceof EvokerFangs && event.getEntity() instanceof LivingEntity) {
|
private final CachedStats stats;
|
||||||
EvokerFangs damager = (EvokerFangs) event.getDamager();
|
private final double damage;
|
||||||
if (!MMOItems.plugin.getEntities().isCustomEntity(damager))
|
|
||||||
return;
|
|
||||||
|
|
||||||
event.setCancelled(true);
|
public FangsHandler(CachedStats stats, double damage) {
|
||||||
Object[] data = MMOItems.plugin.getEntities().getEntityData(damager);
|
super(EntityDamageByEntityEvent.getHandlerList());
|
||||||
CachedStats stats = (CachedStats) data[0];
|
|
||||||
if (MMOUtils.canDamage(stats.getPlayer(), event.getEntity()))
|
this.stats = stats;
|
||||||
new AttackResult((double) data[1], DamageType.SKILL, DamageType.MAGIC).damage(stats.getPlayer(), (LivingEntity) event.getEntity());
|
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.AbilityResult;
|
||||||
import net.Indyuce.mmoitems.api.ability.SimpleAbilityResult;
|
import net.Indyuce.mmoitems.api.ability.SimpleAbilityResult;
|
||||||
import net.Indyuce.mmoitems.api.player.PlayerStats.CachedStats;
|
import net.Indyuce.mmoitems.api.player.PlayerStats.CachedStats;
|
||||||
|
import net.Indyuce.mmoitems.api.util.TemporaryListener;
|
||||||
import net.Indyuce.mmoitems.stat.data.AbilityData;
|
import net.Indyuce.mmoitems.stat.data.AbilityData;
|
||||||
import net.mmogroup.mmolib.api.AttackResult;
|
import net.mmogroup.mmolib.api.AttackResult;
|
||||||
import net.mmogroup.mmolib.api.DamageType;
|
import net.mmogroup.mmolib.api.DamageType;
|
||||||
|
|
||||||
public class Explosive_Turkey extends Ability implements Listener {
|
public class Explosive_Turkey extends Ability implements Listener {
|
||||||
public Explosive_Turkey() {
|
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("damage", 6);
|
||||||
addModifier("radius", 4);
|
addModifier("radius", 4);
|
||||||
@ -36,8 +38,6 @@ public class Explosive_Turkey extends Ability implements Listener {
|
|||||||
addModifier("mana", 0);
|
addModifier("mana", 0);
|
||||||
addModifier("stamina", 0);
|
addModifier("stamina", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Chicken chicken = null;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AbilityResult whenRan(CachedStats stats, LivingEntity target, AbilityData ability, ItemAttackResult result) {
|
public AbilityResult whenRan(CachedStats stats, LivingEntity target, AbilityData ability, ItemAttackResult result) {
|
||||||
@ -50,19 +50,23 @@ public class Explosive_Turkey extends Ability implements Listener {
|
|||||||
double damage = ability.getModifier("damage");
|
double damage = ability.getModifier("damage");
|
||||||
double radiusSquared = Math.pow(ability.getModifier("radius"), 2);
|
double radiusSquared = Math.pow(ability.getModifier("radius"), 2);
|
||||||
double knockback = ability.getModifier("knockback");
|
double knockback = ability.getModifier("knockback");
|
||||||
|
|
||||||
Vector vec = stats.getPlayer().getEyeLocation().getDirection().clone().multiply(.6);
|
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.setInvulnerable(true);
|
||||||
chicken.setSilent(true);
|
chicken.setSilent(true);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sets the health to 2048 (Default max Spigot value)
|
* Sets the health to 2048 (Default max Spigot value) which stops the
|
||||||
* which stops the bug where you can kill the chicken for a brief
|
* bug where you can kill the chicken for a brief few ticks after it
|
||||||
* few ticks after it spawns in!
|
* spawns in!
|
||||||
*/
|
*/
|
||||||
chicken.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(2048);
|
chicken.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(2048);
|
||||||
chicken.setHealth(2048);
|
chicken.setHealth(2048);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* when items are moving through the air, they loose a percent of their
|
* when items are moving through the air, they loose a percent of their
|
||||||
* velocity proportionally to their coordinates in each axis. this means
|
* velocity proportionally to their coordinates in each axis. this means
|
||||||
@ -71,51 +75,75 @@ public class Explosive_Turkey extends Ability implements Listener {
|
|||||||
* trajectory change
|
* trajectory change
|
||||||
*/
|
*/
|
||||||
chicken.setVelocity(vec);
|
chicken.setVelocity(vec);
|
||||||
|
|
||||||
final double trajRatio = chicken.getVelocity().getX() / chicken.getVelocity().getZ();
|
final double trajRatio = chicken.getVelocity().getX() / chicken.getVelocity().getZ();
|
||||||
|
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
double ti = 0;
|
int ti = 0;
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
if (ti++ > duration || chicken.isDead() || chicken == null) {
|
if (ti++ > duration || chicken.isDead()) {
|
||||||
chicken.remove();
|
chickenHandler.close();
|
||||||
cancel();
|
cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
chicken.setVelocity(vec);
|
||||||
if (ti % 4 == 0)
|
if (ti % 4 == 0)
|
||||||
chicken.getWorld().playSound(chicken.getLocation(), Sound.ENTITY_CHICKEN_HURT, 2, 1);
|
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.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);
|
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();
|
double currentTrajRatio = chicken.getVelocity().getX() / chicken.getVelocity().getZ();
|
||||||
if (chicken.isOnGround() || Math.abs(trajRatio - currentTrajRatio) > .1) {
|
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.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().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);
|
chicken.getWorld().playSound(chicken.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 2, 1.5f);
|
||||||
for (Entity entity : MMOUtils.getNearbyChunkEntities(chicken.getLocation()))
|
for (Entity entity : MMOUtils.getNearbyChunkEntities(chicken.getLocation()))
|
||||||
if (!entity.isDead() && entity.getLocation().distanceSquared(chicken.getLocation()) < radiusSquared && MMOUtils.canDamage(stats.getPlayer(), entity)) {
|
if (!entity.isDead() && entity.getLocation().distanceSquared(chicken.getLocation()) < radiusSquared
|
||||||
new AttackResult(damage, DamageType.SKILL, DamageType.MAGIC, DamageType.PROJECTILE).damage(stats.getPlayer(), (LivingEntity) entity);
|
&& MMOUtils.canDamage(stats.getPlayer(), entity)) {
|
||||||
entity.setVelocity(entity.getLocation().toVector().subtract(chicken.getLocation().toVector()).multiply(.1 * knockback).setY(.4 * knockback));
|
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;
|
return;
|
||||||
}
|
}
|
||||||
chicken.setVelocity(vec);
|
|
||||||
}
|
}
|
||||||
}.runTaskTimer(MMOItems.plugin, 0, 1);
|
}.runTaskTimer(MMOItems.plugin, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
/*
|
||||||
public void a(EntityDeathEvent event) {
|
* this fixes an issue where chickens sometimes drop
|
||||||
if (event.getEntity() == null || !event.getEntityType().equals(EntityType.CHICKEN))
|
*/
|
||||||
return;
|
public class ChickenHandler extends TemporaryListener {
|
||||||
|
private final Chicken chicken;
|
||||||
if (event.getEntity().equals(chicken)) {
|
|
||||||
event.getDrops().clear();
|
public ChickenHandler(Chicken chicken) {
|
||||||
event.setDroppedExp(0);
|
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;
|
package net.Indyuce.mmoitems.ability;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Particle;
|
import org.bukkit.Particle;
|
||||||
@ -26,10 +22,9 @@ import net.Indyuce.mmoitems.stat.data.AbilityData;
|
|||||||
import net.mmogroup.mmolib.version.VersionSound;
|
import net.mmogroup.mmolib.version.VersionSound;
|
||||||
|
|
||||||
public class Shadow_Veil extends Ability implements Listener {
|
public class Shadow_Veil extends Ability implements Listener {
|
||||||
public final List<UUID> shadowVeil = new ArrayList<>();
|
|
||||||
|
|
||||||
public Shadow_Veil() {
|
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("cooldown", 35);
|
||||||
addModifier("duration", 5);
|
addModifier("duration", 5);
|
||||||
@ -46,69 +41,85 @@ public class Shadow_Veil extends Ability implements Listener {
|
|||||||
public void whenCast(CachedStats stats, AbilityResult ability, ItemAttackResult result) {
|
public void whenCast(CachedStats stats, AbilityResult ability, ItemAttackResult result) {
|
||||||
double duration = ability.getModifier("duration");
|
double duration = ability.getModifier("duration");
|
||||||
|
|
||||||
shadowVeil.add(stats.getPlayer().getUniqueId());
|
|
||||||
stats.getPlayer().getWorld().playSound(stats.getPlayer().getLocation(), VersionSound.ENTITY_ENDERMAN_TELEPORT.toSound(), 3, 0);
|
stats.getPlayer().getWorld().playSound(stats.getPlayer().getLocation(), VersionSound.ENTITY_ENDERMAN_TELEPORT.toSound(), 3, 0);
|
||||||
for (Player online : Bukkit.getOnlinePlayers())
|
for (Player online : Bukkit.getOnlinePlayers())
|
||||||
online.hidePlayer(MMOItems.plugin, stats.getPlayer());
|
online.hidePlayer(MMOItems.plugin, stats.getPlayer());
|
||||||
|
|
||||||
|
/*
|
||||||
|
* clears the target of any entity around the player
|
||||||
|
*/
|
||||||
for (Mob serverEntities : stats.getPlayer().getWorld().getEntitiesByClass(Mob.class))
|
for (Mob serverEntities : stats.getPlayer().getWorld().getEntitiesByClass(Mob.class))
|
||||||
if (serverEntities.getTarget() != null && serverEntities.getTarget().equals(stats.getPlayer()))
|
if (serverEntities.getTarget() != null && serverEntities.getTarget().equals(stats.getPlayer()))
|
||||||
serverEntities.setTarget(null);
|
serverEntities.setTarget(null);
|
||||||
new BukkitRunnable() {
|
|
||||||
double ti = 0;
|
|
||||||
double y = 0;
|
|
||||||
Location loc = stats.getPlayer().getLocation();
|
|
||||||
|
|
||||||
public void run() {
|
new ShadowVeilHandler(stats.getPlayer(), duration);
|
||||||
ti++;
|
}
|
||||||
if (ti > duration * 20) {
|
|
||||||
for (Player online : Bukkit.getOnlinePlayers())
|
|
||||||
online.showPlayer(MMOItems.plugin, stats.getPlayer());
|
|
||||||
|
|
||||||
shadowVeil.remove(stats.getPlayer().getUniqueId());
|
public class ShadowVeilHandler extends BukkitRunnable implements Listener {
|
||||||
stats.getPlayer().getWorld().spawnParticle(Particle.SMOKE_LARGE, stats.getPlayer().getLocation().add(0, 1, 0), 32, 0, 0, 0, .13);
|
private final Player player;
|
||||||
stats.getPlayer().getWorld().playSound(stats.getPlayer().getLocation(), VersionSound.ENTITY_ENDERMAN_TELEPORT.toSound(), 3, 0);
|
private final double duration;
|
||||||
cancel();
|
private final Location loc;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!shadowVeil.contains(stats.getPlayer().getUniqueId())) {
|
double ti = 0;
|
||||||
for (Player online : Bukkit.getOnlinePlayers())
|
double y = 0;
|
||||||
online.showPlayer(MMOItems.plugin, stats.getPlayer());
|
boolean cancelled;
|
||||||
|
|
||||||
stats.getPlayer().getWorld().spawnParticle(Particle.SMOKE_LARGE, stats.getPlayer().getLocation().add(0, 1, 0), 32, 0, 0, 0, .13);
|
public ShadowVeilHandler(Player player, double duration) {
|
||||||
stats.getPlayer().getWorld().playSound(stats.getPlayer().getLocation(), VersionSound.ENTITY_ENDERMAN_TELEPORT.toSound(), 3, 0);
|
this.player = player;
|
||||||
cancel();
|
this.duration = duration;
|
||||||
}
|
this.loc = player.getLocation();
|
||||||
|
|
||||||
if (y < 4)
|
runTaskTimer(MMOItems.plugin, 0, 1);
|
||||||
for (int j1 = 0; j1 < 5; j1++) {
|
Bukkit.getPluginManager().registerEvents(this, MMOItems.plugin);
|
||||||
y += .04;
|
}
|
||||||
for (int j = 0; j < 4; j++) {
|
|
||||||
double xz = y * Math.PI * .8 + (j * Math.PI / 2);
|
private void close() {
|
||||||
stats.getPlayer().getWorld().spawnParticle(Particle.SMOKE_LARGE, loc.clone().add(Math.cos(xz) * 2.5, y, Math.sin(xz) * 2.5), 0);
|
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
|
if (y < 4)
|
||||||
public void a(EntityDamageByEntityEvent event) {
|
for (int j1 = 0; j1 < 5; j1++) {
|
||||||
if (!(event.getDamager() instanceof Player))
|
y += .04;
|
||||||
return;
|
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
|
@EventHandler
|
||||||
public void b(EntityTargetEvent event) {
|
public void cancelShadowVeil(EntityDamageByEntityEvent event) {
|
||||||
if (!(event.getTarget() instanceof Player))
|
if (event.getDamager().equals(player))
|
||||||
return;
|
close();
|
||||||
|
}
|
||||||
|
|
||||||
Player player = (Player) event.getTarget();
|
@EventHandler
|
||||||
if (shadowVeil.contains(player.getUniqueId()))
|
public void cancelMobTarget(EntityTargetEvent event) {
|
||||||
event.setCancelled(true);
|
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 class Shulker_Missile extends Ability implements Listener {
|
||||||
public Shulker_Missile() {
|
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("cooldown", 12);
|
||||||
addModifier("damage", 5);
|
addModifier("damage", 5);
|
||||||
@ -53,16 +54,19 @@ public class Shulker_Missile extends Ability implements Listener {
|
|||||||
double n = 0;
|
double n = 0;
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
n++;
|
if (n++ > 3) {
|
||||||
if (n > 3) {
|
|
||||||
cancel();
|
cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector vec = ((VectorAbilityResult) ability).getTarget();
|
Vector vec = ((VectorAbilityResult) ability).getTarget();
|
||||||
stats.getPlayer().getWorld().playSound(stats.getPlayer().getLocation(), Sound.ENTITY_WITHER_SHOOT, 2, 2);
|
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());
|
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() {
|
new BukkitRunnable() {
|
||||||
double ti = 0;
|
double ti = 0;
|
||||||
|
|
||||||
@ -117,7 +121,8 @@ public class Shulker_Missile extends Ability implements Listener {
|
|||||||
y += .04;
|
y += .04;
|
||||||
for (int j = 0; j < 2; j++) {
|
for (int j = 0; j < 2; j++) {
|
||||||
double xz = y * Math.PI * 1.3 + (j * Math.PI);
|
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)
|
if (y >= 2)
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
package net.Indyuce.mmoitems.ability;
|
package net.Indyuce.mmoitems.ability;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Particle;
|
import org.bukkit.Particle;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
@ -8,6 +12,9 @@ import org.bukkit.entity.EntityType;
|
|||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Snowball;
|
import org.bukkit.entity.Snowball;
|
||||||
import org.bukkit.entity.Snowman;
|
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.PotionEffect;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
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.AbilityResult;
|
||||||
import net.Indyuce.mmoitems.api.ability.LocationAbilityResult;
|
import net.Indyuce.mmoitems.api.ability.LocationAbilityResult;
|
||||||
import net.Indyuce.mmoitems.api.player.PlayerStats.CachedStats;
|
import net.Indyuce.mmoitems.api.player.PlayerStats.CachedStats;
|
||||||
|
import net.Indyuce.mmoitems.api.util.TemporaryListener;
|
||||||
import net.Indyuce.mmoitems.stat.data.AbilityData;
|
import net.Indyuce.mmoitems.stat.data.AbilityData;
|
||||||
import net.mmogroup.mmolib.version.VersionSound;
|
import net.mmogroup.mmolib.version.VersionSound;
|
||||||
|
|
||||||
public class Snowman_Turret extends Ability {
|
public class Snowman_Turret extends Ability {
|
||||||
public Snowman_Turret() {
|
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("duration", 6);
|
||||||
addModifier("cooldown", 35);
|
addModifier("cooldown", 35);
|
||||||
@ -44,7 +53,6 @@ public class Snowman_Turret extends Ability {
|
|||||||
Location loc = ((LocationAbilityResult) ability).getTarget();
|
Location loc = ((LocationAbilityResult) ability).getTarget();
|
||||||
double duration = Math.min(ability.getModifier("duration") * 20, 300);
|
double duration = Math.min(ability.getModifier("duration") * 20, 300);
|
||||||
double radiusSquared = Math.pow(ability.getModifier("radius"), 2);
|
double radiusSquared = Math.pow(ability.getModifier("radius"), 2);
|
||||||
double damage1 = ability.getModifier("damage");
|
|
||||||
|
|
||||||
loc.getWorld().playSound(loc, VersionSound.ENTITY_ENDERMAN_TELEPORT.toSound(), 2, 1);
|
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);
|
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() {
|
new BukkitRunnable() {
|
||||||
int ti = 0;
|
int ti = 0;
|
||||||
double j = 0;
|
double j = 0;
|
||||||
|
TurretHandler turret = new TurretHandler(ability.getModifier("damage"));
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
if (ti++ > duration || stats.getPlayer().isDead() || snowman == null || snowman.isDead()) {
|
if (ti++ > duration || stats.getPlayer().isDead() || snowman == null || snowman.isDead()) {
|
||||||
|
turret.close(3 * 20);
|
||||||
snowman.remove();
|
snowman.remove();
|
||||||
cancel();
|
cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
j += Math.PI / 24 % (2 * Math.PI);
|
j += Math.PI / 24 % (2 * Math.PI);
|
||||||
for (double k = 0; k < 3; k++)
|
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);
|
snowman.getWorld().spawnParticle(Particle.SPELL_INSTANT, snowman.getLocation().add(0, 1, 0), 1, 0, 0, 0, .2);
|
||||||
|
|
||||||
if (ti % 2 == 0)
|
if (ti % 2 == 0)
|
||||||
for (Entity entity : snowman.getWorld().getEntities())
|
for (Entity entity : MMOUtils.getNearbyChunkEntities(snowman.getLocation()))
|
||||||
if (!entity.equals(snowman) && MMOUtils.canDamage(stats.getPlayer(), entity) && entity.getLocation().distanceSquared(snowman.getLocation()) < radiusSquared) {
|
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);
|
snowman.getWorld().playSound(snowman.getLocation(), Sound.ENTITY_SNOWBALL_THROW, 1, 1.3f);
|
||||||
Snowball snowball = snowman.launchProjectile(Snowball.class);
|
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));
|
snowball.setVelocity(entity.getLocation().add(0, entity.getHeight() / 2, 0).toVector()
|
||||||
MMOItems.plugin.getEntities().registerCustomEntity(snowball, damage1);
|
.subtract(snowman.getLocation().add(0, 1, 0).toVector()).normalize().multiply(1.3));
|
||||||
|
turret.entities.add(snowball.getUniqueId());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.runTaskTimer(MMOItems.plugin, 0, 1);
|
}.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.Particle;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.TNTPrimed;
|
import org.bukkit.entity.TNTPrimed;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import net.Indyuce.mmoitems.MMOItems;
|
|
||||||
import net.Indyuce.mmoitems.MMOUtils;
|
import net.Indyuce.mmoitems.MMOUtils;
|
||||||
import net.Indyuce.mmoitems.api.ItemAttackResult;
|
import net.Indyuce.mmoitems.api.ItemAttackResult;
|
||||||
import net.Indyuce.mmoitems.api.ability.Ability;
|
import net.Indyuce.mmoitems.api.ability.Ability;
|
||||||
import net.Indyuce.mmoitems.api.ability.AbilityResult;
|
import net.Indyuce.mmoitems.api.ability.AbilityResult;
|
||||||
import net.Indyuce.mmoitems.api.ability.VectorAbilityResult;
|
import net.Indyuce.mmoitems.api.ability.VectorAbilityResult;
|
||||||
import net.Indyuce.mmoitems.api.player.PlayerStats.CachedStats;
|
import net.Indyuce.mmoitems.api.player.PlayerStats.CachedStats;
|
||||||
|
import net.Indyuce.mmoitems.api.util.TemporaryListener;
|
||||||
import net.Indyuce.mmoitems.stat.data.AbilityData;
|
import net.Indyuce.mmoitems.stat.data.AbilityData;
|
||||||
|
|
||||||
public class TNT_Throw extends Ability implements Listener {
|
public class TNT_Throw extends Ability implements Listener {
|
||||||
public TNT_Throw() {
|
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("cooldown", 10);
|
||||||
addModifier("force", 1);
|
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);
|
TNTPrimed tnt = (TNTPrimed) stats.getPlayer().getWorld().spawnEntity(stats.getPlayer().getLocation().add(0, 1, 0), EntityType.PRIMED_TNT);
|
||||||
tnt.setFuseTicks(80);
|
tnt.setFuseTicks(80);
|
||||||
tnt.setVelocity(vec);
|
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().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);
|
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 CancelTeamDamage(Player player, TNTPrimed tnt) {
|
||||||
public void a(EntityDamageByEntityEvent event) {
|
super(EntityDamageByEntityEvent.getHandlerList());
|
||||||
Entity damager = event.getDamager();
|
|
||||||
if (damager instanceof TNTPrimed)
|
this.player = player;
|
||||||
if (MMOItems.plugin.getEntities().isCustomEntity(damager))
|
this.tnt = tnt;
|
||||||
if (!MMOUtils.canDamage(event.getEntity()))
|
|
||||||
event.setCancelled(true);
|
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 {
|
public class WeakenedInfo {
|
||||||
private long date = System.currentTimeMillis();
|
private final long date = System.currentTimeMillis();
|
||||||
private double extraDamage;
|
private final double extraDamage;
|
||||||
|
|
||||||
public WeakenedInfo(double extraDamage) {
|
public WeakenedInfo(double extraDamage) {
|
||||||
this.extraDamage = extraDamage / 100;
|
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