Make class pets aggro hostile mobs who attack their owners.

When a player takes damage from a hostile mob, the player's class pets will have their target set to that mob. This means that even zombies can function as "real" pets!
This commit is contained in:
Andreas Troelsen 2019-08-05 16:08:53 +02:00
parent ab031e3e63
commit b44b808d38
2 changed files with 15 additions and 1 deletions

View File

@ -13,7 +13,7 @@ These changes will (most likely) be included in the next version.
## [Unreleased] ## [Unreleased]
- Extended and upgraded potions are now supported in the item syntax by prepending `long_` or `strong_` to the data portion of a potion item (e.g. `potion:strong_instant_heal:1` will yield a Potion of Healing II). Check the wiki for details. - Extended and upgraded potions are now supported in the item syntax by prepending `long_` or `strong_` to the data portion of a potion item (e.g. `potion:strong_instant_heal:1` will yield a Potion of Healing II). Check the wiki for details.
- MobArena now has basic tab completion support for most of the commands that take arguments. - MobArena now has basic tab completion support for most of the commands that take arguments.
- The `pet-items` node in `global-settings` now supports any living entity as a pet (but only tameable entities will _behave_ as pets). This should allow 1.14 servers to replace `ocelot` with `cat` in their `pet-items` node to get cat pets working again. - The `pet-items` node in `global-settings` now supports any living entity as a pet - even zombies! Pets will aggro hostile mobs that damage their owner, but only tameable pets (wolves, cats, etc.) will properly follow their owners around. This should also allow 1.14 servers to replace `ocelot` with `cat` in their `pet-items` node to get cat pets working again.
- Pets now have custom names that denote who their owner is, e.g. "garbagemule's pet". - Pets now have custom names that denote who their owner is, e.g. "garbagemule's pet".
- Tridents and crossbows are now considered weapons with regards to the `unbreakable-weapons` flag. All class items that have durability now have their unbreakable flag set to true unless the `unbreakable-weapons` and/or `unbreakable-armor` flags are set to `false`. - Tridents and crossbows are now considered weapons with regards to the `unbreakable-weapons` flag. All class items that have durability now have their unbreakable flag set to true unless the `unbreakable-weapons` and/or `unbreakable-armor` flags are set to `false`.
- Leaderboards now work again on servers running Minecraft 1.14+. - Leaderboards now work again on servers running Minecraft 1.14+.

View File

@ -32,6 +32,7 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Horse; import org.bukkit.entity.Horse;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Mob;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile; import org.bukkit.entity.Projectile;
import org.bukkit.entity.Slime; import org.bukkit.entity.Slime;
@ -706,6 +707,19 @@ public class ArenaListener
} }
event.setCancelled(false); event.setCancelled(false);
arena.getArenaPlayer(player).getStats().add("dmgTaken", event.getDamage()); arena.getArenaPlayer(player).getStats().add("dmgTaken", event.getDamage());
// Redirect pet aggro (but not at players)
if (damager instanceof LivingEntity && !(damager instanceof Player)) {
LivingEntity target = (LivingEntity) damager;
monsters.getPets(player).forEach(pet -> {
if (pet instanceof Mob) {
Mob mob = (Mob) pet;
if (mob.getTarget() == null) {
mob.setTarget(target);
}
}
});
}
} }
} }