Stop using deprecated ProjectileCollideEvent
This commit is contained in:
parent
a753380695
commit
7177cd1767
|
@ -11,11 +11,10 @@ import org.bukkit.entity.Projectile;
|
|||
import org.bukkit.entity.SpectralArrow;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.ProjectileHitEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import com.destroystokyo.paper.event.entity.ProjectileCollideEvent;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
|
||||
|
@ -64,20 +63,25 @@ public final class WeaponArcher implements Listener {
|
|||
|
||||
/* Make shooter invulnerable to weapon projectiles */
|
||||
@EventHandler
|
||||
private void onProjectileCollide(final ProjectileCollideEvent event) {
|
||||
if (event.getEntityType() == EntityType.SPECTRAL_ARROW) {
|
||||
final Projectile projectile = event.getEntity();
|
||||
private void onProjectileHit(final ProjectileHitEvent event) {
|
||||
if (event.getEntityType() != EntityType.SPECTRAL_ARROW) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Component.text("WeaponArcherArrow").equals(projectile.customName())) {
|
||||
final Entity collidedWith = event.getCollidedWith();
|
||||
final Projectile projectile = event.getEntity();
|
||||
|
||||
if (collidedWith.getType() == EntityType.PLAYER
|
||||
&& projectile.getShooter() instanceof Player
|
||||
&& ((Player) projectile.getShooter()).getUniqueId().equals(
|
||||
collidedWith.getUniqueId())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
if (!Component.text("WeaponArcherArrow").equals(projectile.customName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Entity collidedWith = event.getHitEntity();
|
||||
|
||||
if (collidedWith != null
|
||||
&& collidedWith.getType() == EntityType.PLAYER
|
||||
&& projectile.getShooter() instanceof Player
|
||||
&& ((Player) projectile.getShooter()).getUniqueId().equals(
|
||||
collidedWith.getUniqueId())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,11 +11,10 @@ import org.bukkit.entity.Player;
|
|||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.ProjectileHitEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import com.destroystokyo.paper.event.entity.ProjectileCollideEvent;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
|
||||
|
@ -69,21 +68,29 @@ public final class WeaponArmageddon implements Listener {
|
|||
/* Make shooter invulnerable to weapon projectiles, and prevent charges from
|
||||
colliding with each other */
|
||||
@EventHandler
|
||||
private void onProjectileCollide(final ProjectileCollideEvent event) {
|
||||
if (event.getEntityType() == EntityType.FIREBALL) {
|
||||
final Projectile projectile = event.getEntity();
|
||||
private void onProjectileHit(final ProjectileHitEvent event) {
|
||||
if (event.getEntityType() != EntityType.FIREBALL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Component.text("WeaponArmegaddonCharge").equals(projectile.customName())) {
|
||||
final Entity collidedWith = event.getCollidedWith();
|
||||
final Projectile projectile = event.getEntity();
|
||||
|
||||
if ((collidedWith.getType() == EntityType.PLAYER
|
||||
&& projectile.getShooter() instanceof Player
|
||||
&& ((Player) projectile.getShooter()).getUniqueId().equals(
|
||||
collidedWith.getUniqueId()))
|
||||
|| collidedWith.getType() == EntityType.FIREBALL) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
if (!Component.text("WeaponArmegaddonCharge").equals(projectile.customName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Entity collidedWith = event.getHitEntity();
|
||||
|
||||
if (collidedWith == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((collidedWith.getType() == EntityType.PLAYER
|
||||
&& projectile.getShooter() instanceof Player
|
||||
&& ((Player) projectile.getShooter()).getUniqueId().equals(
|
||||
collidedWith.getUniqueId())) {
|
||||
|| collidedWith.getType() == EntityType.FIREBALL) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@ import org.bukkit.potion.PotionEffect;
|
|||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import com.destroystokyo.paper.event.entity.ProjectileCollideEvent;
|
||||
import com.destroystokyo.paper.event.server.ServerTickStartEvent;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
@ -51,47 +50,46 @@ public final class WeaponMachineGun implements Listener {
|
|||
}
|
||||
|
||||
/* Make shooter invulnerable to weapon projectiles */
|
||||
@EventHandler
|
||||
private void onProjectileCollide(final ProjectileCollideEvent event) {
|
||||
if (event.getEntityType() == EntityType.ARROW) {
|
||||
final Projectile projectile = event.getEntity();
|
||||
|
||||
if (Component.text("WeaponMachineGunBullet").equals(projectile.customName())) {
|
||||
final Entity collidedWith = event.getCollidedWith();
|
||||
|
||||
if (collidedWith.getType() == EntityType.PLAYER
|
||||
&& projectile.getShooter() instanceof Player
|
||||
&& ((Player) projectile.getShooter()).getUniqueId().equals(
|
||||
collidedWith.getUniqueId())) {
|
||||
event.setCancelled(true);
|
||||
} else if (collidedWith instanceof LivingEntity) {
|
||||
final int duration = 90000;
|
||||
final int amplifier = 3;
|
||||
final boolean ambient = true;
|
||||
final boolean particles = false;
|
||||
|
||||
final PotionEffect harm = new PotionEffect(
|
||||
PotionEffectType.HARM,
|
||||
duration,
|
||||
amplifier,
|
||||
ambient,
|
||||
particles
|
||||
);
|
||||
|
||||
((LivingEntity) collidedWith).addPotionEffect(harm, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
private void onProjectileHit(final ProjectileHitEvent event) {
|
||||
if (event.getEntityType() == EntityType.ARROW) {
|
||||
final Projectile projectile = event.getEntity();
|
||||
if (event.getEntityType() != EntityType.ARROW) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Component.text("WeaponMachineGunBullet").equals(projectile.customName())) {
|
||||
projectile.remove();
|
||||
}
|
||||
final Projectile projectile = event.getEntity();
|
||||
|
||||
if (!Component.text("WeaponMachineGunBullet").equals(projectile.customName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Entity collidedWith = event.getHitEntity();
|
||||
projectile.remove();
|
||||
|
||||
if (collidedWith == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (collidedWith.getType() == EntityType.PLAYER
|
||||
&& projectile.getShooter() instanceof Player
|
||||
&& ((Player) projectile.getShooter()).getUniqueId().equals(
|
||||
collidedWith.getUniqueId())) {
|
||||
event.setCancelled(true);
|
||||
|
||||
} else if (collidedWith instanceof LivingEntity) {
|
||||
final int duration = 90000;
|
||||
final int amplifier = 3;
|
||||
final boolean ambient = true;
|
||||
final boolean particles = false;
|
||||
|
||||
final PotionEffect harm = new PotionEffect(
|
||||
PotionEffectType.HARM,
|
||||
duration,
|
||||
amplifier,
|
||||
ambient,
|
||||
particles
|
||||
);
|
||||
|
||||
((LivingEntity) collidedWith).addPotionEffect(harm, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -111,6 +109,7 @@ public final class WeaponMachineGun implements Listener {
|
|||
|
||||
if (player == null) {
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
final Location eyeLocation = player.getEyeLocation();
|
||||
|
|
Loading…
Reference in New Issue