Skip to content

Commit

Permalink
disable pvp on pets
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeTheTech committed Nov 22, 2023
1 parent a6cc529 commit d69c79b
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/main/java/lee/code/pets/listeners/PetListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityPortalEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.entity.*;
import org.bukkit.event.player.*;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
Expand Down Expand Up @@ -159,4 +156,28 @@ public void onEntityPortal(EntityPortalEvent e) {
if (e.isCancelled()) return;
if (pets.getPetManager().isPet(e.getEntity())) e.setCancelled(true);
}

@EventHandler
public void onDamagePlayerOnPet(EntityDamageByEntityEvent e) {
if (e.getDamager() instanceof Player attacker && e.getEntity() instanceof Player victim) {
if (attacker.getVehicle() != null) {
if (pets.getPetManager().isPet(attacker.getVehicle())) e.setCancelled(true);
}
if (victim.getVehicle() != null) {
if (pets.getPetManager().isPet(victim.getVehicle())) e.setCancelled(true);
}
}
}

@EventHandler
public void onShootPlayerOnPet(ProjectileHitEvent e) {
if (e.getEntity().getShooter() instanceof Player attacker && e.getHitEntity() instanceof Player victim) {
if (attacker.getVehicle() != null) {
if (pets.getPetManager().isPet(attacker.getVehicle())) e.setCancelled(true);
}
if (victim.getVehicle() != null) {
if (pets.getPetManager().isPet(victim.getVehicle())) e.setCancelled(true);
}
}
}
}

0 comments on commit d69c79b

Please sign in to comment.