*CLEANUP* - mcEntityListener.java

This commit is contained in:
GJ 2012-03-10 20:15:55 -05:00
parent 989f12e65b
commit 28c590f079

View File

@ -38,260 +38,279 @@ import com.gmail.nossr50.skills.BlastMining;
import com.gmail.nossr50.skills.Skills; import com.gmail.nossr50.skills.Skills;
import com.gmail.nossr50.skills.Taming; import com.gmail.nossr50.skills.Taming;
public class mcEntityListener implements Listener public class mcEntityListener implements Listener {
{ private final mcMMO plugin;
private final mcMMO plugin;
public mcEntityListener(final mcMMO plugin) { public mcEntityListener(final mcMMO plugin) {
this.plugin = plugin; this.plugin = plugin;
} }
/**
* Monitor EntityDamageByEntity events.
*
* @param event The event to monitor
*/
@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) {
//Lets just put this here...
if(event instanceof FakeEntityDamageByEntityEvent)
return; return;
}
Entity defender = event.getEntity(); Entity defender = event.getEntity();
Entity attacker = event.getDamager(); Entity attacker = event.getDamager();
if(attacker instanceof Player && defender instanceof Player) if (attacker instanceof Player && defender instanceof Player) {
{ if (!defender.getWorld().getPVP()) {
if(!defender.getWorld().getPVP()) return;
return; }
if(Party.getInstance().inSameParty((Player)defender, (Player)attacker)) {
event.setCancelled(true);
return;
}
}
//Make sure defender is not invincible if (Party.getInstance().inSameParty((Player)defender, (Player)attacker)) {
if(defender instanceof LivingEntity) event.setCancelled(true);
{ return;
LivingEntity livingDefender = (LivingEntity)defender; }
if(!m.isInvincible(livingDefender, event)) }
Combat.combatChecks(event, plugin);
} /* Check for invincibility */
if (defender instanceof LivingEntity) {
LivingEntity livingDefender = (LivingEntity)defender;
if (!m.isInvincible(livingDefender, event)) {
Combat.combatChecks(event, plugin);
}
}
} }
/**
* Monitor EntityDamage events.
*
* @param event The event to monitor
*/
@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) {
if(event instanceof FakeEntityDamageEvent)
return; return;
}
Entity entity = event.getEntity(); Entity entity = event.getEntity();
EntityType type = entity.getType(); EntityType type = entity.getType();
DamageCause cause = event.getCause(); DamageCause cause = event.getCause();
switch(type) switch(type) {
{ case PLAYER:
case PLAYER:
/* /* Check for invincibility */
* CHECK FOR INVULNERABILITY Player player = (Player) entity;
*/ PlayerProfile PP = Users.getProfile(player);
Player player = (Player) entity;
PlayerProfile PP = Users.getProfile(player); if (PP.getGodMode()) {
if(PP.getGodMode()) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if(!m.isInvincible(player, event)) if (!m.isInvincible(player, event)) {
{ if (cause == DamageCause.FALL && mcPermissions.getInstance().acrobatics(player)) {
if(cause == DamageCause.FALL && mcPermissions.getInstance().acrobatics(player)) Acrobatics.acrobaticsCheck(player, event);
Acrobatics.acrobaticsCheck(player, event); }
if(cause == DamageCause.BLOCK_EXPLOSION && mcPermissions.getInstance().blastMining(player)) else if (cause == DamageCause.BLOCK_EXPLOSION && mcPermissions.getInstance().blastMining(player)) {
BlastMining.demolitionsExpertise(player, event); BlastMining.demolitionsExpertise(player, event);
if(event.getDamage() >= 1) }
PP.setRecentlyHurt(System.currentTimeMillis());
} if (event.getDamage() >= 1) {
break; PP.setRecentlyHurt(System.currentTimeMillis());
case WOLF: }
Wolf wolf = (Wolf) entity; }
if((!m.isInvincible(wolf, event)) && wolf.isTamed() && (wolf.getOwner() instanceof Player)) break;
Taming.preventDamage(event, plugin);
break; case WOLF:
} Wolf wolf = (Wolf) entity;
if ((!m.isInvincible(wolf, event)) && wolf.isTamed() && (wolf.getOwner() instanceof Player)) {
Taming.preventDamage(event, plugin);
}
break;
default:
break;
}
} }
@EventHandler /**
public void onEntityDeath(EntityDeathEvent event) * Monitor EntityDeath events.
{ *
LivingEntity x = event.getEntity(); * @param event The event to monitor
x.setFireTicks(0); */
@EventHandler (priority = EventPriority.MONITOR)
public void onEntityDeath(EntityDeathEvent event) {
LivingEntity x = event.getEntity();
x.setFireTicks(0);
//Remove mob from mob spawner list /* Remove mob from mob spawner list */
if(plugin.misc.mobSpawnerList.contains(x.getEntityId())) if (plugin.misc.mobSpawnerList.contains(x.getEntityId())) {
plugin.misc.mobSpawnerList.remove((Object)x.getEntityId()); plugin.misc.mobSpawnerList.remove((Object)x.getEntityId());
}
//Remove bleed track /* Remove bleed track */
if(plugin.misc.bleedTracker.contains(x)) if(plugin.misc.bleedTracker.contains(x)) {
plugin.misc.addToBleedRemovalQue(x); plugin.misc.addToBleedRemovalQue(x);
}
Archery.arrowRetrievalCheck(x, plugin); Archery.arrowRetrievalCheck(x, plugin);
if(x instanceof Player) if (x instanceof Player) {
Users.getProfile((Player)x).setBleedTicks(0); Users.getProfile((Player)x).setBleedTicks(0);
}
} }
@EventHandler /**
public void onCreatureSpawn(CreatureSpawnEvent event) * Monitor CreatureSpawn events.
{ *
SpawnReason reason = event.getSpawnReason(); * @param event The event to monitor
*/
if(reason == SpawnReason.SPAWNER && !LoadProperties.xpGainsMobSpawners) @EventHandler (priority = EventPriority.MONITOR)
plugin.misc.mobSpawnerList.add(event.getEntity().getEntityId()); public void onCreatureSpawn(CreatureSpawnEvent event) {
if (event.getSpawnReason().equals(SpawnReason.SPAWNER) && !LoadProperties.xpGainsMobSpawners) {
plugin.misc.mobSpawnerList.add(event.getEntity().getEntityId());
}
} }
@EventHandler (priority = EventPriority.LOW) /**
public void onExplosionPrime(ExplosionPrimeEvent event) * Monitor ExplosionPrime events.
{ *
Entity entity = event.getEntity(); * @param event The event to monitor
if(entity instanceof TNTPrimed) */
{ @EventHandler (priority = EventPriority.LOW)
int id = entity.getEntityId(); public void onExplosionPrime(ExplosionPrimeEvent event) {
if(plugin.misc.tntTracker.containsKey(id)) Entity entity = event.getEntity();
{
Player player = plugin.misc.tntTracker.get(id);
BlastMining.biggerBombs(player, event);
}
}
}
@EventHandler (priority = EventPriority.LOW) if (entity instanceof TNTPrimed) {
public void onEnitityExplode(EntityExplodeEvent event) int id = entity.getEntityId();
{
Entity entity = event.getEntity();
if(event.getEntity() instanceof TNTPrimed)
{
int id = entity.getEntityId();
if(plugin.misc.tntTracker.containsKey(id))
{
Player player = plugin.misc.tntTracker.get(id);
BlastMining.dropProcessing(player, event, plugin);
plugin.misc.tntTracker.remove(id);
}
}
}
@EventHandler (priority = EventPriority.LOW) if (plugin.misc.tntTracker.containsKey(id)) {
public void onFoodLevelChange(FoodLevelChangeEvent event) Player player = plugin.misc.tntTracker.get(id);
{ BlastMining.biggerBombs(player, event);
if(LoadProperties.herbalismHungerBonus) }
{ }
if(event.getEntity() instanceof Player) }
{
Player player = (Player) event.getEntity();
PlayerProfile PP = Users.getProfile(player);
int currentFoodLevel = player.getFoodLevel();
int newFoodLevel = event.getFoodLevel();
//Some foods have 3 ranks /**
//Some foods have 5 ranks * Monitor EntityExplode events.
//The number of ranks is based on how 'common' the item is *
//We can adjust this quite easily if we find something is giving too much of a bonus * @param event The event to monitor
*/
@EventHandler (priority = EventPriority.LOW)
public void onEnitityExplode(EntityExplodeEvent event) {
Entity entity = event.getEntity();
if(newFoodLevel > currentFoodLevel) if (event.getEntity() instanceof TNTPrimed) {
{ int id = entity.getEntityId();
Material food = player.getItemInHand().getType();
int herbLevel = PP.getSkillLevel(SkillType.HERBALISM);
int foodChange = newFoodLevel - currentFoodLevel;
switch(food) if (plugin.misc.tntTracker.containsKey(id)) {
{ Player player = plugin.misc.tntTracker.get(id);
case BREAD: BlastMining.dropProcessing(player, event, plugin);
{ plugin.misc.tntTracker.remove(id);
//BREAD RESTORES 2 1/2 HUNGER }
//Restores 5 HUNGER @ 1000 }
if(herbLevel >= 200 && herbLevel < 400) }
foodChange = foodChange + 1;
else if(herbLevel >= 400 && herbLevel < 600) /**
foodChange = foodChange + 2; * Monitor FoodLevelChange events.
else if(herbLevel >= 600 && herbLevel < 800) *
foodChange = foodChange + 3; * @param event The event to monitor
else if(herbLevel >= 800 && herbLevel < 1000) */
foodChange = foodChange + 4; @EventHandler (priority = EventPriority.LOW)
else if(herbLevel >= 1000) public void onFoodLevelChange(FoodLevelChangeEvent event) {
foodChange = foodChange + 5; if (LoadProperties.herbalismHungerBonus) {
if (event.getEntity() instanceof Player) {
Player player = (Player) event.getEntity();
PlayerProfile PP = Users.getProfile(player);
int currentFoodLevel = player.getFoodLevel();
int newFoodLevel = event.getFoodLevel();
/* Some foods have 3 ranks
* Some foods have 5 ranks
* The number of ranks is based on how 'common' the item is
* We can adjust this quite easily if we find something is giving too much of a bonus
*/
if (newFoodLevel > currentFoodLevel) {
Material food = player.getItemInHand().getType();
int herbLevel = PP.getSkillLevel(SkillType.HERBALISM);
int foodChange = newFoodLevel - currentFoodLevel;
int rankChange = 0;
switch (food) {
case BREAD:
/* BREAD RESTORES 2 1/2 HUNGER - RESTORES 5 HUNGER @ 1000 */
rankChange = 200;
break; break;
}
case COOKIE:
{
//COOKIE RESTORES 1/2 HUNGER
//RESTORES 2 HUNGER @ 1000
if(herbLevel >= 200 && herbLevel < 600)
foodChange = foodChange + 1;
else if(herbLevel >= 600 && herbLevel < 1000)
foodChange = foodChange + 2;
else if(herbLevel >= 1000)
foodChange = foodChange + 3;
break;
}
case MELON:
{
//MELON RESTORES 1 HUNGER
//RESTORES 2 1/2 HUNGER @ 1000
if(herbLevel >= 200 && herbLevel < 600)
foodChange = foodChange + 1;
else if(herbLevel >= 600 && herbLevel < 1000)
foodChange = foodChange + 2;
else if(herbLevel >= 1000)
foodChange = foodChange + 3;
break;
}
case MUSHROOM_SOUP:
{
//MUSHROOM SOUP RESTORES 4 HUNGER
//RESTORES 6 1/2 HUNGER @ 1000
if(herbLevel >= 200 && herbLevel < 400)
foodChange = foodChange + 1;
else if(herbLevel >= 400 && herbLevel < 600)
foodChange = foodChange + 2;
else if(herbLevel >= 600 && herbLevel < 800)
foodChange = foodChange + 3;
else if(herbLevel >= 800 && herbLevel < 1000)
foodChange = foodChange + 4;
else if(herbLevel >= 1000)
foodChange = foodChange + 5;
break;
}
}
//Make sure we don't go over the max value case COOKIE:
newFoodLevel = currentFoodLevel + foodChange; /* COOKIE RESTORES 1/2 HUNGER - RESTORES 2 HUNGER @ 1000 */
if(newFoodLevel > 20) rankChange = 400;
break;
case MELON:
/* MELON RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */
rankChange = 400;
break;
case MUSHROOM_SOUP:
/* MUSHROOM SOUP RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @ 1000 */
rankChange = 200;
break;
default:
break;
}
for (int i = 200; i <= 1000; i += rankChange) {
if (herbLevel >= i) {
foodChange++;
}
}
/* Make sure we don't go over the max value */
newFoodLevel = currentFoodLevel + foodChange;
if (newFoodLevel > 20) {
event.setFoodLevel(20); event.setFoodLevel(20);
if(newFoodLevel <= 20) }
else {
event.setFoodLevel(newFoodLevel); event.setFoodLevel(newFoodLevel);
} }
} }
} }
} }
}
@EventHandler (priority = EventPriority.MONITOR) /**
public void onEntityTame(EntityTameEvent event) * Monitor EntityTame events.
{ *
Player player = (Player) event.getOwner(); * @param event The event to watch
if(mcPermissions.getInstance().taming(player)) */
{ @EventHandler (priority = EventPriority.MONITOR)
PlayerProfile PP = Users.getProfile(player); public void onEntityTame(EntityTameEvent event) {
EntityType type = event.getEntityType(); Player player = (Player) event.getOwner();
int xp = 0;
switch(type) if (mcPermissions.getInstance().taming(player)) {
{ PlayerProfile PP = Users.getProfile(player);
case WOLF: EntityType type = event.getEntityType();
xp = LoadProperties.mtameWolf; int xp = 0;
break;
case OCELOT:
xp = LoadProperties.mtameOcelot;
break;
}
PP.addXP(SkillType.TAMING, xp, player); switch (type) {
Skills.XpCheckSkill(SkillType.TAMING, player); case WOLF:
} xp = LoadProperties.mtameWolf;
} break;
case OCELOT:
xp = LoadProperties.mtameOcelot;
break;
default:
break;
}
PP.addXP(SkillType.TAMING, xp, player);
Skills.XpCheckSkill(SkillType.TAMING, player);
}
}
} }