Merge branch 'develop' of https://github.com/BentoBoxWorld/BentoBox.git into develop

This commit is contained in:
tastybento 2024-06-29 15:44:56 -07:00
commit 59fd8d94b5
4 changed files with 32 additions and 17 deletions

View File

@ -51,7 +51,10 @@ public class HurtingListener extends FlagListener {
public void onEntityDamage(final EntityDamageByEntityEvent e) public void onEntityDamage(final EntityDamageByEntityEvent e)
{ {
// Mobs being hurt // Mobs being hurt
if (Util.isPassiveEntity(e.getEntity())) if (Util.isTamableEntity(e.getEntity())) {
this.respond(e, e.getDamager(), Flags.HURT_TAMED_ANIMALS);
}
else if (Util.isPassiveEntity(e.getEntity()))
{ {
this.respond(e, e.getDamager(), Flags.HURT_ANIMALS); this.respond(e, e.getDamager(), Flags.HURT_ANIMALS);
} }
@ -92,7 +95,8 @@ public class HurtingListener extends FlagListener {
return; return;
} }
if ((Util.isPassiveEntity(e.getCaught()) && checkIsland(e, e.getPlayer(), e.getCaught().getLocation(), Flags.HURT_ANIMALS)) if ((Util.isTamableEntity(e.getCaught()) && checkIsland(e, e.getPlayer(), e.getCaught().getLocation(), Flags.HURT_TAMED_ANIMALS))
|| (Util.isPassiveEntity(e.getCaught()) && checkIsland(e, e.getPlayer(), e.getCaught().getLocation(), Flags.HURT_ANIMALS))
|| (Util.isHostileEntity(e.getCaught()) && checkIsland(e, e.getPlayer(), e.getCaught().getLocation(), Flags.HURT_MONSTERS)) || (Util.isHostileEntity(e.getCaught()) && checkIsland(e, e.getPlayer(), e.getCaught().getLocation(), Flags.HURT_MONSTERS))
|| (e.getCaught() instanceof AbstractVillager && checkIsland(e, e.getPlayer(), e.getCaught().getLocation(), Flags.HURT_VILLAGERS))) { || (e.getCaught() instanceof AbstractVillager && checkIsland(e, e.getPlayer(), e.getCaught().getLocation(), Flags.HURT_VILLAGERS))) {
e.getHook().remove(); e.getHook().remove();
@ -113,9 +117,13 @@ public class HurtingListener extends FlagListener {
if (e.getRightClicked() instanceof Parrot if (e.getRightClicked() instanceof Parrot
&& (e.getHand().equals(EquipmentSlot.HAND) && e.getPlayer().getInventory().getItemInMainHand().getType().equals(Material.COOKIE)) && (e.getHand().equals(EquipmentSlot.HAND) && e.getPlayer().getInventory().getItemInMainHand().getType().equals(Material.COOKIE))
|| (e.getHand().equals(EquipmentSlot.OFF_HAND) && e.getPlayer().getInventory().getItemInOffHand().getType().equals(Material.COOKIE))) { || (e.getHand().equals(EquipmentSlot.OFF_HAND) && e.getPlayer().getInventory().getItemInOffHand().getType().equals(Material.COOKIE))) {
if (((Parrot) e.getRightClicked()).isTamed()) {
checkIsland(e, e.getPlayer(), e.getRightClicked().getLocation(), Flags.HURT_TAMED_ANIMALS);
} else {
checkIsland(e, e.getPlayer(), e.getRightClicked().getLocation(), Flags.HURT_ANIMALS); checkIsland(e, e.getPlayer(), e.getRightClicked().getLocation(), Flags.HURT_ANIMALS);
} }
} }
}
/** /**
* Checks for splash damage. Remove damage if it should not affect. * Checks for splash damage. Remove damage if it should not affect.
@ -139,6 +147,13 @@ public class HurtingListener extends FlagListener {
} }
} }
// Tamed animals being hurt
if (Util.isTamableEntity(entity) && !checkIsland(e, attacker, entity.getLocation(), Flags.HURT_TAMED_ANIMALS)) {
for (PotionEffect effect : e.getPotion().getEffects()) {
entity.removePotionEffect(effect.getType());
}
}
// Mobs being hurt // Mobs being hurt
if (Util.isPassiveEntity(entity) && !checkIsland(e, attacker, entity.getLocation(), Flags.HURT_ANIMALS)) { if (Util.isPassiveEntity(entity) && !checkIsland(e, attacker, entity.getLocation(), Flags.HURT_ANIMALS)) {
for (PotionEffect effect : e.getPotion().getEffects()) { for (PotionEffect effect : e.getPotion().getEffects()) {
@ -189,6 +204,10 @@ public class HurtingListener extends FlagListener {
if (Util.isHostileEntity(entity)) { if (Util.isHostileEntity(entity)) {
checkIsland(e, attacker, entity.getLocation(), Flags.HURT_MONSTERS); checkIsland(e, attacker, entity.getLocation(), Flags.HURT_MONSTERS);
} }
// Tamed animals being hurt
if (Util.isTamableEntity(entity)) {
checkIsland(e, attacker, entity.getLocation(), Flags.HURT_TAMED_ANIMALS);
}
// Mobs being hurt // Mobs being hurt
if (Util.isPassiveEntity(entity)) { if (Util.isPassiveEntity(entity)) {
checkIsland(e, attacker, entity.getLocation(), Flags.HURT_ANIMALS); checkIsland(e, attacker, entity.getLocation(), Flags.HURT_ANIMALS);

View File

@ -283,6 +283,7 @@ public final class Flags {
public static final Flag HURT_ANIMALS = new Flag.Builder("HURT_ANIMALS", Material.STONE_SWORD).listener(new HurtingListener()).mode(Flag.Mode.ADVANCED).build(); public static final Flag HURT_ANIMALS = new Flag.Builder("HURT_ANIMALS", Material.STONE_SWORD).listener(new HurtingListener()).mode(Flag.Mode.ADVANCED).build();
public static final Flag HURT_MONSTERS = new Flag.Builder("HURT_MONSTERS", Material.WOODEN_SWORD).mode(Flag.Mode.BASIC).build(); public static final Flag HURT_MONSTERS = new Flag.Builder("HURT_MONSTERS", Material.WOODEN_SWORD).mode(Flag.Mode.BASIC).build();
public static final Flag HURT_VILLAGERS = new Flag.Builder("HURT_VILLAGERS", Material.GOLDEN_SWORD).mode(Flag.Mode.ADVANCED).build(); public static final Flag HURT_VILLAGERS = new Flag.Builder("HURT_VILLAGERS", Material.GOLDEN_SWORD).mode(Flag.Mode.ADVANCED).build();
public static final Flag HURT_TAMED_ANIMALS = new Flag.Builder("HURT_TAMABLE_ENTITIES", Material.DIAMOND_SWORD).mode(Flag.Mode.ADVANCED).build();
// Leashes // Leashes
public static final Flag LEASH = new Flag.Builder("LEASH", Material.LEAD).listener(new LeashListener()).build(); public static final Flag LEASH = new Flag.Builder("LEASH", Material.LEAD).listener(new LeashListener()).build();

View File

@ -28,20 +28,7 @@ import org.bukkit.World.Environment;
import org.bukkit.attribute.Attribute; import org.bukkit.attribute.Attribute;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.entity.Allay; import org.bukkit.entity.*;
import org.bukkit.entity.Animals;
import org.bukkit.entity.Bat;
import org.bukkit.entity.EnderDragon;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Flying;
import org.bukkit.entity.IronGolem;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Player;
import org.bukkit.entity.PufferFish;
import org.bukkit.entity.Shulker;
import org.bukkit.entity.Slime;
import org.bukkit.entity.Snowman;
import org.bukkit.entity.WaterMob;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.NonNull;
@ -370,6 +357,10 @@ public class Util {
entity instanceof Allay; entity instanceof Allay;
} }
public static boolean isTamableEntity(Entity entity) {
return entity instanceof Tameable && ((Tameable) entity).isTamed();
}
/* /*
* PaperLib methods for addons to call * PaperLib methods for addons to call
*/ */

View File

@ -1231,6 +1231,10 @@ protection:
description: '&a Toggle hive harvesting.' description: '&a Toggle hive harvesting.'
name: Hive harvesting name: Hive harvesting
hint: Harvesting disabled hint: Harvesting disabled
HURT_TAMED_ANIMALS:
description: Toggle hurting. Enabled means that tamed animals can take damage. Disabled means they are invincible.
name: Hurt tamed animals
hint: Tamed animal hurting disabled
HURT_ANIMALS: HURT_ANIMALS:
description: Toggle hurting description: Toggle hurting
name: Hurt animals name: Hurt animals