/** * Monitor PlayerInteract events. * * @param event The event to watch */ @EventHandler(priority = EventPriority.LOW) public void onPlayerInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); Action action = event.getAction(); Block block = event.getClickedBlock(); ItemStack inHand = player.getItemInHand(); Material material; /* Fix for NPE on interacting with air */ if (block == null) { material = Material.AIR; } else { material = block.getType(); } switch (action) { case RIGHT_CLICK_BLOCK: /* REPAIR CHECKS */ if (Permissions.getInstance().repair(player) && block.getTypeId() == Config.getInstance().getRepairAnvilId()) { if (mcMMO.repairManager.isRepairable(inHand)) { mcMMO.repairManager.handleRepair(player, inHand); event.setCancelled(true); player.updateInventory(); } } /* ACTIVATION CHECKS */ if (Config.getInstance().getAbilitiesEnabled() && BlockChecks.abilityBlockCheck(block)) { if (!material.equals(Material.DIRT) && !material.equals(Material.GRASS) && !material.equals(Material.SOIL)) { Skills.activationCheck(player, SkillType.HERBALISM); } Skills.activationCheck(player, SkillType.AXES); Skills.activationCheck(player, SkillType.EXCAVATION); Skills.activationCheck(player, SkillType.MINING); Skills.activationCheck(player, SkillType.SWORDS); Skills.activationCheck(player, SkillType.UNARMED); Skills.activationCheck(player, SkillType.WOODCUTTING); } /* GREEN THUMB CHECK */ if (inHand.getType().equals(Material.SEEDS) && BlockChecks.makeMossy(block) && Permissions.getInstance().greenThumbBlocks(player)) { Herbalism.greenThumbBlocks(inHand, player, block); } /* ITEM CHECKS */ if (BlockChecks.abilityBlockCheck(block)) { Item.itemChecks(player); } /* BLAST MINING CHECK */ if (player.isSneaking() && inHand.getTypeId() == Config.getInstance().getDetonatorItemID() && Permissions.getInstance().blastMining(player)) { BlastMining.detonate(event, player, plugin); } break; case RIGHT_CLICK_AIR: /* ACTIVATION CHECKS */ if (Config.getInstance().getAbilitiesEnabled()) { Skills.activationCheck(player, SkillType.AXES); Skills.activationCheck(player, SkillType.EXCAVATION); Skills.activationCheck(player, SkillType.HERBALISM); Skills.activationCheck(player, SkillType.MINING); Skills.activationCheck(player, SkillType.SWORDS); Skills.activationCheck(player, SkillType.UNARMED); Skills.activationCheck(player, SkillType.WOODCUTTING); } /* ITEM CHECKS */ Item.itemChecks(player); /* BLAST MINING CHECK */ if (player.isSneaking() && inHand.getTypeId() == Config.getInstance().getDetonatorItemID() && Permissions.getInstance().blastMining(player)) { BlastMining.detonate(event, player, plugin); } break; case LEFT_CLICK_AIR: case LEFT_CLICK_BLOCK: /* CALL OF THE WILD CHECKS */ if (player.isSneaking()) { Material type = inHand.getType(); if (type == Material.RAW_FISH) { TamingManager tamingManager = new TamingManager(player); tamingManager.summonOcelot(); } else if (type == Material.BONE) { TamingManager tamingManager = new TamingManager(player); tamingManager.summonWolf(); } } break; default: break; } }
/** * Handle EntityDamage events that involve modifying the event. * * @param event The event to modify */ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onEntityDamage(EntityDamageEvent event) { if (event instanceof FakeEntityDamageEvent) { return; } double damage = event.getDamage(); if (damage <= 0) { return; } Entity entity = event.getEntity(); if (entity.hasMetadata(mcMMO.customDamageKey)) { entity.removeMetadata(mcMMO.customDamageKey, plugin); return; } if (Misc.isNPCEntity(entity) || !entity.isValid() || !(entity instanceof LivingEntity)) { return; } LivingEntity livingEntity = (LivingEntity) entity; if (CombatUtils.isInvincible(livingEntity, damage)) { return; } DamageCause cause = event.getCause(); if (livingEntity instanceof Player) { Player player = (Player) entity; McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); /* Check for invincibility */ if (mcMMOPlayer.getGodMode()) { event.setCancelled(true); return; } switch (cause) { case FALL: if (Config.getInstance().getPreventXPAfterTeleport() && SkillUtils.calculateTimeLeft( (long) mcMMOPlayer.getTeleportATS() * Misc.TIME_CONVERSION_FACTOR, 5, player) > 0) { return; } AcrobaticsManager acrobaticsManager = mcMMOPlayer.getAcrobaticsManager(); if (acrobaticsManager.canRoll()) { event.setDamage(acrobaticsManager.rollCheck(event.getDamage())); if (event.getDamage() == 0) { event.setCancelled(true); return; } } break; case BLOCK_EXPLOSION: MiningManager miningManager = mcMMOPlayer.getMiningManager(); if (miningManager.canUseDemolitionsExpertise()) { event.setDamage(miningManager.processDemolitionsExpertise(event.getDamage())); if (event.getDamage() == 0) { event.setCancelled(true); return; } } break; default: break; } if (event.getDamage() >= 1) { mcMMOPlayer.actualizeRecentlyHurt(); } } else if (livingEntity instanceof Tameable) { Tameable pet = (Tameable) livingEntity; AnimalTamer owner = pet.getOwner(); if (Taming.canPreventDamage(pet, owner)) { Player player = (Player) owner; Wolf wolf = (Wolf) pet; TamingManager tamingManager = UserManager.getPlayer(player).getTamingManager(); switch (cause) { case CONTACT: case FIRE: case LAVA: if (tamingManager.canUseEnvironmentallyAware()) { tamingManager.processEnvironmentallyAware(wolf, event.getDamage()); } return; case FALL: if (tamingManager.canUseEnvironmentallyAware()) { event.setCancelled(true); } return; case ENTITY_ATTACK: case PROJECTILE: if (tamingManager.canUseThickFur()) { event.setDamage(Taming.processThickFur(wolf, event.getDamage())); if (event.getDamage() == 0) { event.setCancelled(true); } } return; case FIRE_TICK: if (tamingManager.canUseThickFur()) { Taming.processThickFurFire(wolf); } return; case MAGIC: case POISON: case WITHER: if (tamingManager.canUseHolyHound()) { Taming.processHolyHound(wolf, event.getDamage()); } return; case BLOCK_EXPLOSION: case ENTITY_EXPLOSION: case LIGHTNING: if (tamingManager.canUseShockProof()) { event.setDamage(Taming.processShockProof(wolf, event.getDamage())); if (event.getDamage() == 0) { event.setCancelled(true); } } return; default: return; } } } }