mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-26 23:26:45 +01:00
*CLEANUP* - mcEntityListener.java
This commit is contained in:
parent
989f12e65b
commit
28c590f079
@ -38,137 +38,173 @@ 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)) {
|
if (Party.getInstance().inSameParty((Player)defender, (Player)attacker)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Make sure defender is not invincible
|
/* Check for invincibility */
|
||||||
if(defender instanceof LivingEntity)
|
if (defender instanceof LivingEntity) {
|
||||||
{
|
|
||||||
LivingEntity livingDefender = (LivingEntity)defender;
|
LivingEntity livingDefender = (LivingEntity)defender;
|
||||||
if(!m.isInvincible(livingDefender, event))
|
|
||||||
|
if (!m.isInvincible(livingDefender, event)) {
|
||||||
Combat.combatChecks(event, plugin);
|
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 INVULNERABILITY
|
/* Check for invincibility */
|
||||||
*/
|
|
||||||
Player player = (Player) entity;
|
Player player = (Player) entity;
|
||||||
PlayerProfile PP = Users.getProfile(player);
|
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)
|
}
|
||||||
|
|
||||||
|
if (event.getDamage() >= 1) {
|
||||||
PP.setRecentlyHurt(System.currentTimeMillis());
|
PP.setRecentlyHurt(System.currentTimeMillis());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WOLF:
|
case WOLF:
|
||||||
Wolf wolf = (Wolf) entity;
|
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);
|
Taming.preventDamage(event, plugin);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
break;
|
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();
|
LivingEntity x = event.getEntity();
|
||||||
x.setFireTicks(0);
|
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)
|
|
||||||
{
|
|
||||||
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)
|
@EventHandler (priority = EventPriority.LOW)
|
||||||
public void onExplosionPrime(ExplosionPrimeEvent event)
|
public void onExplosionPrime(ExplosionPrimeEvent event) {
|
||||||
{
|
|
||||||
Entity entity = event.getEntity();
|
Entity entity = event.getEntity();
|
||||||
if(entity instanceof TNTPrimed)
|
|
||||||
{
|
if (entity instanceof TNTPrimed) {
|
||||||
int id = entity.getEntityId();
|
int id = entity.getEntityId();
|
||||||
if(plugin.misc.tntTracker.containsKey(id))
|
|
||||||
{
|
if (plugin.misc.tntTracker.containsKey(id)) {
|
||||||
Player player = plugin.misc.tntTracker.get(id);
|
Player player = plugin.misc.tntTracker.get(id);
|
||||||
BlastMining.biggerBombs(player, event);
|
BlastMining.biggerBombs(player, event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Monitor EntityExplode events.
|
||||||
|
*
|
||||||
|
* @param event The event to monitor
|
||||||
|
*/
|
||||||
@EventHandler (priority = EventPriority.LOW)
|
@EventHandler (priority = EventPriority.LOW)
|
||||||
public void onEnitityExplode(EntityExplodeEvent event)
|
public void onEnitityExplode(EntityExplodeEvent event) {
|
||||||
{
|
|
||||||
Entity entity = event.getEntity();
|
Entity entity = event.getEntity();
|
||||||
if(event.getEntity() instanceof TNTPrimed)
|
|
||||||
{
|
if (event.getEntity() instanceof TNTPrimed) {
|
||||||
int id = entity.getEntityId();
|
int id = entity.getEntityId();
|
||||||
if(plugin.misc.tntTracker.containsKey(id))
|
|
||||||
{
|
if (plugin.misc.tntTracker.containsKey(id)) {
|
||||||
Player player = plugin.misc.tntTracker.get(id);
|
Player player = plugin.misc.tntTracker.get(id);
|
||||||
BlastMining.dropProcessing(player, event, plugin);
|
BlastMining.dropProcessing(player, event, plugin);
|
||||||
plugin.misc.tntTracker.remove(id);
|
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)
|
@EventHandler (priority = EventPriority.LOW)
|
||||||
public void onFoodLevelChange(FoodLevelChangeEvent event)
|
public void onFoodLevelChange(FoodLevelChangeEvent event) {
|
||||||
{
|
if (LoadProperties.herbalismHungerBonus) {
|
||||||
if(LoadProperties.herbalismHungerBonus)
|
if (event.getEntity() instanceof Player) {
|
||||||
{
|
|
||||||
if(event.getEntity() instanceof Player)
|
|
||||||
{
|
|
||||||
Player player = (Player) event.getEntity();
|
Player player = (Player) event.getEntity();
|
||||||
PlayerProfile PP = Users.getProfile(player);
|
PlayerProfile PP = Users.getProfile(player);
|
||||||
int currentFoodLevel = player.getFoodLevel();
|
int currentFoodLevel = player.getFoodLevel();
|
||||||
int newFoodLevel = event.getFoodLevel();
|
int newFoodLevel = event.getFoodLevel();
|
||||||
|
|
||||||
//Some foods have 3 ranks
|
/* Some foods have 3 ranks
|
||||||
//Some foods have 5 ranks
|
* Some foods have 5 ranks
|
||||||
//The number of ranks is based on how 'common' the item is
|
* 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
|
* 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();
|
Material food = player.getItemInHand().getType();
|
||||||
int herbLevel = PP.getSkillLevel(SkillType.HERBALISM);
|
int herbLevel = PP.getSkillLevel(SkillType.HERBALISM);
|
||||||
int foodChange = newFoodLevel - currentFoodLevel;
|
int foodChange = newFoodLevel - currentFoodLevel;
|
||||||
|
int rankChange = 0;
|
||||||
|
|
||||||
switch(food)
|
switch (food) {
|
||||||
{
|
|
||||||
case BREAD:
|
case BREAD:
|
||||||
{
|
/* BREAD RESTORES 2 1/2 HUNGER - RESTORES 5 HUNGER @ 1000 */
|
||||||
//BREAD RESTORES 2 1/2 HUNGER
|
rankChange = 200;
|
||||||
//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;
|
|
||||||
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
|
break;
|
||||||
if(herbLevel >= 200 && herbLevel < 600)
|
|
||||||
foodChange = foodChange + 1;
|
case MUSHROOM_SOUP:
|
||||||
else if(herbLevel >= 600 && herbLevel < 1000)
|
/* MUSHROOM SOUP RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @ 1000 */
|
||||||
foodChange = foodChange + 2;
|
rankChange = 200;
|
||||||
else if(herbLevel >= 1000)
|
break;
|
||||||
foodChange = foodChange + 3;
|
|
||||||
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MUSHROOM_SOUP:
|
|
||||||
{
|
for (int i = 200; i <= 1000; i += rankChange) {
|
||||||
//MUSHROOM SOUP RESTORES 4 HUNGER
|
if (herbLevel >= i) {
|
||||||
//RESTORES 6 1/2 HUNGER @ 1000
|
foodChange++;
|
||||||
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
|
/* Make sure we don't go over the max value */
|
||||||
newFoodLevel = currentFoodLevel + foodChange;
|
newFoodLevel = currentFoodLevel + foodChange;
|
||||||
if(newFoodLevel > 20)
|
if (newFoodLevel > 20) {
|
||||||
event.setFoodLevel(20);
|
event.setFoodLevel(20);
|
||||||
if(newFoodLevel <= 20)
|
}
|
||||||
|
else {
|
||||||
event.setFoodLevel(newFoodLevel);
|
event.setFoodLevel(newFoodLevel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Monitor EntityTame events.
|
||||||
|
*
|
||||||
|
* @param event The event to watch
|
||||||
|
*/
|
||||||
@EventHandler (priority = EventPriority.MONITOR)
|
@EventHandler (priority = EventPriority.MONITOR)
|
||||||
public void onEntityTame(EntityTameEvent event)
|
public void onEntityTame(EntityTameEvent event) {
|
||||||
{
|
|
||||||
Player player = (Player) event.getOwner();
|
Player player = (Player) event.getOwner();
|
||||||
if(mcPermissions.getInstance().taming(player))
|
|
||||||
{
|
if (mcPermissions.getInstance().taming(player)) {
|
||||||
PlayerProfile PP = Users.getProfile(player);
|
PlayerProfile PP = Users.getProfile(player);
|
||||||
EntityType type = event.getEntityType();
|
EntityType type = event.getEntityType();
|
||||||
int xp = 0;
|
int xp = 0;
|
||||||
|
|
||||||
switch(type)
|
switch (type) {
|
||||||
{
|
|
||||||
case WOLF:
|
case WOLF:
|
||||||
xp = LoadProperties.mtameWolf;
|
xp = LoadProperties.mtameWolf;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OCELOT:
|
case OCELOT:
|
||||||
xp = LoadProperties.mtameOcelot;
|
xp = LoadProperties.mtameOcelot;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
PP.addXP(SkillType.TAMING, xp, player);
|
PP.addXP(SkillType.TAMING, xp, player);
|
||||||
|
Loading…
Reference in New Issue
Block a user