mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-29 16:46:46 +01:00
Try to clean up our poor EntityListener...
This commit is contained in:
parent
38ba2c21e5
commit
d9926bab4e
@ -61,10 +61,16 @@ public class EntityListener implements Listener {
|
|||||||
public void onEntityShootBow(EntityShootBowEvent event) {
|
public void onEntityShootBow(EntityShootBowEvent event) {
|
||||||
ItemStack bow = event.getBow();
|
ItemStack bow = event.getBow();
|
||||||
|
|
||||||
if (bow != null) {
|
if (bow == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Entity projectile = event.getProjectile();
|
Entity projectile = event.getProjectile();
|
||||||
|
|
||||||
if (projectile instanceof Arrow) {
|
if (!(projectile instanceof Arrow)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (bow.containsEnchantment(Enchantment.ARROW_INFINITE)) {
|
if (bow.containsEnchantment(Enchantment.ARROW_INFINITE)) {
|
||||||
projectile.setMetadata(mcMMO.infiniteArrowKey, mcMMO.metadataValue);
|
projectile.setMetadata(mcMMO.infiniteArrowKey, mcMMO.metadataValue);
|
||||||
}
|
}
|
||||||
@ -72,8 +78,6 @@ public class EntityListener implements Listener {
|
|||||||
projectile.setMetadata(mcMMO.bowForceKey, new FixedMetadataValue(plugin, Math.min(event.getForce() * AdvancedConfig.getInstance().getForceMultiplier(), 1.0)));
|
projectile.setMetadata(mcMMO.bowForceKey, new FixedMetadataValue(plugin, Math.min(event.getForce() * AdvancedConfig.getInstance().getForceMultiplier(), 1.0)));
|
||||||
projectile.setMetadata(mcMMO.arrowDistanceKey, new FixedMetadataValue(plugin, Archery.locationToString(projectile.getLocation())));
|
projectile.setMetadata(mcMMO.arrowDistanceKey, new FixedMetadataValue(plugin, Archery.locationToString(projectile.getLocation())));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Monitor EntityChangeBlock events.
|
* Monitor EntityChangeBlock events.
|
||||||
@ -81,7 +85,7 @@ public class EntityListener implements Listener {
|
|||||||
* @param event The event to watch
|
* @param event The event to watch
|
||||||
*/
|
*/
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onEntityChangeBlockEvent(EntityChangeBlockEvent event) {
|
public void onEntityChangeBlock(EntityChangeBlockEvent event) {
|
||||||
Entity entity = event.getEntity();
|
Entity entity = event.getEntity();
|
||||||
|
|
||||||
if (!(entity instanceof FallingBlock)) {
|
if (!(entity instanceof FallingBlock)) {
|
||||||
@ -107,7 +111,13 @@ public class EntityListener implements Listener {
|
|||||||
*/
|
*/
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
||||||
if (event instanceof FakeEntityDamageByEntityEvent || event.getDamage() <= 0) {
|
if (event instanceof FakeEntityDamageByEntityEvent) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int damage = event.getDamage();
|
||||||
|
|
||||||
|
if (damage <= 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,13 +127,14 @@ public class EntityListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Entity attacker = event.getDamager();
|
|
||||||
LivingEntity target = (LivingEntity) defender;
|
LivingEntity target = (LivingEntity) defender;
|
||||||
|
|
||||||
if (CombatUtils.isInvincible(target, event.getDamage())) {
|
if (CombatUtils.isInvincible(target, damage)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Entity attacker = event.getDamager();
|
||||||
|
|
||||||
if (attacker instanceof Projectile) {
|
if (attacker instanceof Projectile) {
|
||||||
attacker = ((Projectile) attacker).getShooter();
|
attacker = ((Projectile) attacker).getShooter();
|
||||||
}
|
}
|
||||||
@ -160,7 +171,13 @@ public class EntityListener implements Listener {
|
|||||||
*/
|
*/
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onEntityDamage(EntityDamageEvent event) {
|
public void onEntityDamage(EntityDamageEvent event) {
|
||||||
if (event instanceof FakeEntityDamageEvent || event.getDamage() <= 0) {
|
if (event instanceof FakeEntityDamageEvent) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int damage = event.getDamage();
|
||||||
|
|
||||||
|
if (damage <= 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,13 +187,14 @@ public class EntityListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DamageCause cause = event.getCause();
|
|
||||||
LivingEntity livingEntity = (LivingEntity) entity;
|
LivingEntity livingEntity = (LivingEntity) entity;
|
||||||
|
|
||||||
if (CombatUtils.isInvincible(livingEntity, event.getDamage())) {
|
if (CombatUtils.isInvincible(livingEntity, damage)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DamageCause cause = event.getCause();
|
||||||
|
|
||||||
if (livingEntity instanceof Player) {
|
if (livingEntity instanceof Player) {
|
||||||
Player player = (Player) entity;
|
Player player = (Player) entity;
|
||||||
|
|
||||||
@ -309,7 +327,6 @@ public class EntityListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
entity.setFireTicks(0);
|
|
||||||
BleedTimerTask.remove(entity);
|
BleedTimerTask.remove(entity);
|
||||||
Archery.arrowRetrievalCheck(entity);
|
Archery.arrowRetrievalCheck(entity);
|
||||||
}
|
}
|
||||||
@ -348,7 +365,10 @@ public class EntityListener implements Listener {
|
|||||||
public void onExplosionPrime(ExplosionPrimeEvent event) {
|
public void onExplosionPrime(ExplosionPrimeEvent event) {
|
||||||
Entity entity = event.getEntity();
|
Entity entity = event.getEntity();
|
||||||
|
|
||||||
if (entity instanceof TNTPrimed && entity.hasMetadata(mcMMO.tntMetadataKey)) {
|
if (!(entity instanceof TNTPrimed) || !entity.hasMetadata(mcMMO.tntMetadataKey)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// We can make this assumption because we (should) be the only ones using this exact metadata
|
// We can make this assumption because we (should) be the only ones using this exact metadata
|
||||||
Player player = plugin.getServer().getPlayer(entity.getMetadata(mcMMO.tntMetadataKey).get(0).asString());
|
Player player = plugin.getServer().getPlayer(entity.getMetadata(mcMMO.tntMetadataKey).get(0).asString());
|
||||||
|
|
||||||
@ -362,7 +382,6 @@ public class EntityListener implements Listener {
|
|||||||
event.setRadius(miningManager.biggerBombs(event.getRadius()));
|
event.setRadius(miningManager.biggerBombs(event.getRadius()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle EntityExplode events that involve modifying the event.
|
* Handle EntityExplode events that involve modifying the event.
|
||||||
@ -373,7 +392,10 @@ public class EntityListener implements Listener {
|
|||||||
public void onEnitityExplode(EntityExplodeEvent event) {
|
public void onEnitityExplode(EntityExplodeEvent event) {
|
||||||
Entity entity = event.getEntity();
|
Entity entity = event.getEntity();
|
||||||
|
|
||||||
if (entity instanceof TNTPrimed && entity.hasMetadata(mcMMO.tntMetadataKey)) {
|
if (!(entity instanceof TNTPrimed) || !entity.hasMetadata(mcMMO.tntMetadataKey)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// We can make this assumption because we (should) be the only ones using this exact metadata
|
// We can make this assumption because we (should) be the only ones using this exact metadata
|
||||||
Player player = plugin.getServer().getPlayer(entity.getMetadata(mcMMO.tntMetadataKey).get(0).asString());
|
Player player = plugin.getServer().getPlayer(entity.getMetadata(mcMMO.tntMetadataKey).get(0).asString());
|
||||||
|
|
||||||
@ -388,7 +410,6 @@ public class EntityListener implements Listener {
|
|||||||
event.setYield(0);
|
event.setYield(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle FoodLevelChange events that involve modifying the event.
|
* Handle FoodLevelChange events that involve modifying the event.
|
||||||
@ -399,7 +420,10 @@ public class EntityListener implements Listener {
|
|||||||
public void onFoodLevelChange(FoodLevelChangeEvent event) {
|
public void onFoodLevelChange(FoodLevelChangeEvent event) {
|
||||||
Entity entity = event.getEntity();
|
Entity entity = event.getEntity();
|
||||||
|
|
||||||
if (entity instanceof Player) {
|
if (!(entity instanceof Player)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Player player = (Player) entity;
|
Player player = (Player) entity;
|
||||||
|
|
||||||
if (Misc.isNPCEntity(player)) {
|
if (Misc.isNPCEntity(player)) {
|
||||||
@ -457,7 +481,6 @@ public class EntityListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Monitor EntityTame events.
|
* Monitor EntityTame events.
|
||||||
|
@ -575,16 +575,11 @@ public final class CombatUtils {
|
|||||||
* @return true if the entity is invincible, false otherwise
|
* @return true if the entity is invincible, false otherwise
|
||||||
*/
|
*/
|
||||||
public static boolean isInvincible(LivingEntity entity, int eventDamage) {
|
public static boolean isInvincible(LivingEntity entity, int eventDamage) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* So apparently if you do more damage to a LivingEntity than its last damage int you bypass the invincibility.
|
* So apparently if you do more damage to a LivingEntity than its last damage int you bypass the invincibility.
|
||||||
* So yeah, this is for that.
|
* So yeah, this is for that.
|
||||||
*/
|
*/
|
||||||
if ((entity.getNoDamageTicks() > entity.getMaximumNoDamageTicks() / 2.0F) && (eventDamage <= entity.getLastDamage())) {
|
return (entity.getNoDamageTicks() > entity.getMaximumNoDamageTicks() / 2.0F) && (eventDamage <= entity.getLastDamage());
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user