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