mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-26 23:26:45 +01:00
Cancel EntityTargetEvent for when an entity wishes to target a party member without the friendly fire permission being enabled for both.
Not sure this can happen except for when an entity is made agressive to a player, then friendly fire is removed later and the player returns in range of the agressive tamed entity. Thought: Move the permissions check for friendly fire into isFriendlyPet? Not sure where else this is used, but if we always do a permissions check for friendly fire afterwards, it would make sense to move that check.
This commit is contained in:
parent
af1288b6f8
commit
911f036723
@ -23,6 +23,7 @@ import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
|||||||
import org.bukkit.event.entity.EntityDeathEvent;
|
import org.bukkit.event.entity.EntityDeathEvent;
|
||||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
import org.bukkit.event.entity.EntityTameEvent;
|
import org.bukkit.event.entity.EntityTameEvent;
|
||||||
|
import org.bukkit.event.entity.EntityTargetEvent;
|
||||||
import org.bukkit.event.entity.ExplosionPrimeEvent;
|
import org.bukkit.event.entity.ExplosionPrimeEvent;
|
||||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||||
|
|
||||||
@ -350,4 +351,22 @@ public class EntityListener implements Listener {
|
|||||||
TamingManager tamingManager = new TamingManager(Users.getPlayer(player));
|
TamingManager tamingManager = new TamingManager(Users.getPlayer(player));
|
||||||
tamingManager.awardTamingXP(event);
|
tamingManager.awardTamingXP(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler (ignoreCancelled = true)
|
||||||
|
public void onEntityTarget(EntityTargetEvent event) {
|
||||||
|
if (event.getEntity() instanceof Tameable && event.getTarget() instanceof Player) {
|
||||||
|
Player player = (Player) event.getTarget();
|
||||||
|
Tameable tameable = (Tameable) event.getEntity();
|
||||||
|
|
||||||
|
if (Misc.isFriendlyPet(player, tameable)) {
|
||||||
|
// isFriendlyPet ensures that the Tameable is: Tamed, owned by a player, and the owner is in the same party
|
||||||
|
// So we can make some assumptions here, about our casting and our check
|
||||||
|
Player owner = (Player) tameable.getOwner();
|
||||||
|
if (!(Permissions.friendlyFire(player) && Permissions.friendlyFire(owner))) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user