*CLEANUP* - mcEntityListener.java

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

View File

@ -38,137 +38,173 @@ import com.gmail.nossr50.skills.BlastMining;
import com.gmail.nossr50.skills.Skills;
import com.gmail.nossr50.skills.Taming;
public class mcEntityListener implements Listener
{
public class mcEntityListener implements Listener {
private final mcMMO plugin;
public mcEntityListener(final mcMMO plugin) {
this.plugin = plugin;
}
/**
* Monitor EntityDamageByEntity events.
*
* @param event The event to monitor
*/
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEntityDamageByEntity(EntityDamageByEntityEvent event)
{
//Lets just put this here...
if(event instanceof FakeEntityDamageByEntityEvent)
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
if (event instanceof FakeEntityDamageByEntityEvent) {
return;
}
Entity defender = event.getEntity();
Entity attacker = event.getDamager();
if(attacker instanceof Player && defender instanceof Player)
{
if(!defender.getWorld().getPVP())
if (attacker instanceof Player && defender instanceof Player) {
if (!defender.getWorld().getPVP()) {
return;
if(Party.getInstance().inSameParty((Player)defender, (Player)attacker)) {
}
if (Party.getInstance().inSameParty((Player)defender, (Player)attacker)) {
event.setCancelled(true);
return;
}
}
//Make sure defender is not invincible
if(defender instanceof LivingEntity)
{
/* Check for invincibility */
if (defender instanceof LivingEntity) {
LivingEntity livingDefender = (LivingEntity)defender;
if(!m.isInvincible(livingDefender, event))
if (!m.isInvincible(livingDefender, event)) {
Combat.combatChecks(event, plugin);
}
}
}
/**
* Monitor EntityDamage events.
*
* @param event The event to monitor
*/
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEntityDamage(EntityDamageEvent event)
{
if(event instanceof FakeEntityDamageEvent)
public void onEntityDamage(EntityDamageEvent event) {
if (event instanceof FakeEntityDamageEvent) {
return;
}
Entity entity = event.getEntity();
EntityType type = entity.getType();
DamageCause cause = event.getCause();
switch(type)
{
switch(type) {
case PLAYER:
/*
* CHECK FOR INVULNERABILITY
*/
/* Check for invincibility */
Player player = (Player) entity;
PlayerProfile PP = Users.getProfile(player);
if(PP.getGodMode()) {
if (PP.getGodMode()) {
event.setCancelled(true);
return;
}
if(!m.isInvincible(player, event))
{
if(cause == DamageCause.FALL && mcPermissions.getInstance().acrobatics(player))
if (!m.isInvincible(player, event)) {
if (cause == DamageCause.FALL && mcPermissions.getInstance().acrobatics(player)) {
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);
if(event.getDamage() >= 1)
}
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))
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.
*
* @param event The event to monitor
*/
@EventHandler (priority = EventPriority.MONITOR)
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()))
/* 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))
/* Remove bleed track */
if(plugin.misc.bleedTracker.contains(x)) {
plugin.misc.addToBleedRemovalQue(x);
}
Archery.arrowRetrievalCheck(x, plugin);
if(x instanceof Player)
if (x instanceof Player) {
Users.getProfile((Player)x).setBleedTicks(0);
}
@EventHandler
public void onCreatureSpawn(CreatureSpawnEvent event)
{
SpawnReason reason = event.getSpawnReason();
if(reason == SpawnReason.SPAWNER && !LoadProperties.xpGainsMobSpawners)
plugin.misc.mobSpawnerList.add(event.getEntity().getEntityId());
}
/**
* Monitor CreatureSpawn events.
*
* @param event The event to monitor
*/
@EventHandler (priority = EventPriority.MONITOR)
public void onCreatureSpawn(CreatureSpawnEvent event) {
if (event.getSpawnReason().equals(SpawnReason.SPAWNER) && !LoadProperties.xpGainsMobSpawners) {
plugin.misc.mobSpawnerList.add(event.getEntity().getEntityId());
}
}
/**
* Monitor ExplosionPrime events.
*
* @param event The event to monitor
*/
@EventHandler (priority = EventPriority.LOW)
public void onExplosionPrime(ExplosionPrimeEvent event)
{
public void onExplosionPrime(ExplosionPrimeEvent event) {
Entity entity = event.getEntity();
if(entity instanceof TNTPrimed)
{
if (entity instanceof TNTPrimed) {
int id = entity.getEntityId();
if(plugin.misc.tntTracker.containsKey(id))
{
if (plugin.misc.tntTracker.containsKey(id)) {
Player player = plugin.misc.tntTracker.get(id);
BlastMining.biggerBombs(player, event);
}
}
}
/**
* Monitor EntityExplode events.
*
* @param event The event to monitor
*/
@EventHandler (priority = EventPriority.LOW)
public void onEnitityExplode(EntityExplodeEvent event)
{
public void onEnitityExplode(EntityExplodeEvent event) {
Entity entity = event.getEntity();
if(event.getEntity() instanceof TNTPrimed)
{
if (event.getEntity() instanceof TNTPrimed) {
int id = entity.getEntityId();
if(plugin.misc.tntTracker.containsKey(id))
{
if (plugin.misc.tntTracker.containsKey(id)) {
Player player = plugin.misc.tntTracker.get(id);
BlastMining.dropProcessing(player, event, plugin);
plugin.misc.tntTracker.remove(id);
@ -176,118 +212,101 @@ public class mcEntityListener implements Listener
}
}
/**
* Monitor FoodLevelChange events.
*
* @param event The event to monitor
*/
@EventHandler (priority = EventPriority.LOW)
public void onFoodLevelChange(FoodLevelChangeEvent event)
{
if(LoadProperties.herbalismHungerBonus)
{
if(event.getEntity() instanceof Player)
{
public void onFoodLevelChange(FoodLevelChangeEvent 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
//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
/* 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)
{
if (newFoodLevel > currentFoodLevel) {
Material food = player.getItemInHand().getType();
int herbLevel = PP.getSkillLevel(SkillType.HERBALISM);
int foodChange = newFoodLevel - currentFoodLevel;
int rankChange = 0;
switch(food)
{
switch (food) {
case BREAD:
{
//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;
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;
/* BREAD RESTORES 2 1/2 HUNGER - RESTORES 5 HUNGER @ 1000 */
rankChange = 200;
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;
/* COOKIE RESTORES 1/2 HUNGER - RESTORES 2 HUNGER @ 1000 */
rankChange = 400;
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;
/* 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;
}
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;
for (int i = 200; i <= 1000; i += rankChange) {
if (herbLevel >= i) {
foodChange++;
}
}
//Make sure we don't go over the max value
/* Make sure we don't go over the max value */
newFoodLevel = currentFoodLevel + foodChange;
if(newFoodLevel > 20)
if (newFoodLevel > 20) {
event.setFoodLevel(20);
if(newFoodLevel <= 20)
}
else {
event.setFoodLevel(newFoodLevel);
}
}
}
}
}
/**
* Monitor EntityTame events.
*
* @param event The event to watch
*/
@EventHandler (priority = EventPriority.MONITOR)
public void onEntityTame(EntityTameEvent event)
{
public void onEntityTame(EntityTameEvent event) {
Player player = (Player) event.getOwner();
if(mcPermissions.getInstance().taming(player))
{
if (mcPermissions.getInstance().taming(player)) {
PlayerProfile PP = Users.getProfile(player);
EntityType type = event.getEntityType();
int xp = 0;
switch(type)
{
switch (type) {
case WOLF:
xp = LoadProperties.mtameWolf;
break;
case OCELOT:
xp = LoadProperties.mtameOcelot;
break;
default:
break;
}
PP.addXP(SkillType.TAMING, xp, player);