예제 #1
0
  @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
  public void EntityDamageByEntityEvent(EntityDamageByEntityEvent e) {

    Entity damager = e.getDamager();
    Entity damaged = e.getEntity();

    if (damaged instanceof Player) CEventHandler.handleEvent((Player) damaged, e, damageTaken);
    if (damager instanceof Player) CEventHandler.handleEvent((Player) damager, e, damageGiven);
    else if (damager instanceof Arrow)
      if (damager.hasMetadata("ce.bow.item") || damager.hasMetadata("ce.bow.enchantment"))
        CEventHandler.handleBows((Player) ((Projectile) damager).getShooter(), e);
  }
예제 #2
0
  /**
   * Handle EntityExplode events that involve modifying the event.
   *
   * @param event The event to modify
   */
  @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
  public void onEnitityExplode(EntityExplodeEvent event) {
    Entity entity = event.getEntity();

    if (!(entity instanceof TNTPrimed) || !entity.hasMetadata(mcMMO.tntMetadataKey)) {
      return;
    }

    // We can make this assumption because we (should) be the only ones using this exact metadata
    Player player =
        plugin
            .getServer()
            .getPlayerExact(entity.getMetadata(mcMMO.tntMetadataKey).get(0).asString());

    if (Misc.isNPCEntity(player)) {
      return;
    }

    MiningManager miningManager = UserManager.getPlayer(player).getMiningManager();

    if (miningManager.canUseBlastMining()) {
      miningManager.blastMiningDropProcessing(event.getYield(), event.blockList());
      event.setYield(0);
    }
  }
예제 #3
0
  /**
   * Handle EntityExplode events that involve modifying the event.
   *
   * @param event The event to modify
   */
  @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
  public void onEntityExplodeMonitor(EntityExplodeEvent event) {
    Entity entity = event.getEntity();

    if (!(entity instanceof TNTPrimed) || !entity.hasMetadata(mcMMO.tntsafeMetadataKey)) {
      return;
    }

    event.blockList().clear();
  }
예제 #4
0
  @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
  public void EntityDamageEvent(EntityDamageEvent e) {

    Entity damaged = e.getEntity();

    if (damaged instanceof Player) {

      CEventHandler.handleEvent((Player) damaged, e, damageNature);

      if (damaged.hasMetadata("ce.springs")) {
        e.setCancelled(true);
        Vector vel = damaged.getVelocity();
        vel.setY((vel.getY() * -0.75) > 1 ? vel.getY() * -0.75 : 0);
        damaged.setVelocity(vel);
      }
    }
  }
예제 #5
0
  /**
   * Monitor EntityChangeBlock events.
   *
   * @param event The event to watch
   */
  @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
  public void onEntityChangeBlock(EntityChangeBlockEvent event) {
    Entity entity = event.getEntity();

    if (!(entity instanceof FallingBlock)) {
      return;
    }

    Block block = event.getBlock();
    boolean isTracked = entity.hasMetadata(mcMMO.entityMetadataKey);

    if (mcMMO.getPlaceStore().isTrue(block) && !isTracked) {
      mcMMO.getPlaceStore().setFalse(block);
      entity.setMetadata(mcMMO.entityMetadataKey, mcMMO.metadataValue);
    } else if (isTracked) {
      mcMMO.getPlaceStore().setTrue(block);
    }
  }
예제 #6
0
  /** On creeper death, drop fireworks and heads with a configurable chance. */
  @EventHandler(ignoreCancelled = true)
  public void onCreeperDeath(EntityDeathEvent event) {
    if (!CONFIG.isAffectedWorld(event)) {
      return;
    }

    Entity entity = event.getEntity();
    if (entity.getType() == EntityType.CREEPER && entity.hasMetadata(SPECIAL_KEY)) {
      Creeper creeper = (Creeper) entity;

      // Require recent player damage on the creeper for special drops.
      Long damageTime = getPlayerDamageTime(entity);
      if (damageTime != null) {
        Location loc = creeper.getLocation();
        if (loc.getWorld().getFullTime() - damageTime < PLAYER_DAMAGE_TICKS) {
          if (Math.random() < CONFIG.FIREWORK_DROP_CHANCE) {
            // Replace the default drops.
            event.getDrops().clear();
            final int amount = random(CONFIG.MIN_FIREWORK_DROPS, CONFIG.MAX_FIREWORK_DROPS);
            for (int i = 0; i < amount; ++i) {
              ItemStack firework = new ItemStack(Material.FIREWORK);
              FireworkMeta meta = (FireworkMeta) firework.getItemMeta();
              meta.setPower(random(0, 3));
              meta.addEffect(randomFireworkFffect(false));
              firework.setItemMeta(meta);
              event.getDrops().add(firework);
            }
          }

          // Powered creepers may drop a creeper skull in addition to
          // fireworks.
          if (creeper.isPowered() && Math.random() < CONFIG.CHARGED_CREEPER_SKULL_CHANCE) {
            event.getDrops().add(new ItemStack(Material.SKULL_ITEM, 1, (short) 4));
          }
        }
      }
    }
  } // onCreeperDeath
예제 #7
0
 @EventHandler
 public final void BEE(final BlockExplodeEvent event) {
   if (event.blockList().size() <= 0) return;
   final Block block = event.getBlock();
   for (final Entity entity :
       block.getWorld().getNearbyEntities(block.getLocation(), 1.5, 1.5, 1.5)) {
     if (entity.hasMetadata("isminebomb")) {
       final Player player =
           getServer().getPlayerExact(entity.getMetadata("isminebomb").get(0).asString());
       if (player != null) {
         final PlayerInventory inv = player.getInventory();
         for (final Block b : event.blockList()) {
           for (final ItemStack item : b.getDrops(dropItem)) {
             inv.addItem(item);
           }
           b.setType(Material.AIR);
         }
       }
       event.blockList().clear();
       entity.remove();
     }
   }
 }
예제 #8
0
  /**
   * Handle ExplosionPrime events that involve modifying the event.
   *
   * @param event The event to modify
   */
  @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
  public void onExplosionPrime(ExplosionPrimeEvent event) {
    Entity entity = event.getEntity();

    if (!(entity instanceof TNTPrimed) || !entity.hasMetadata(mcMMO.tntMetadataKey)) {
      return;
    }

    // We can make this assumption because we (should) be the only ones using this exact metadata
    Player player =
        plugin
            .getServer()
            .getPlayerExact(entity.getMetadata(mcMMO.tntMetadataKey).get(0).asString());

    if (Misc.isNPCEntity(player)) {
      return;
    }

    MiningManager miningManager = UserManager.getPlayer(player).getMiningManager();

    if (miningManager.canUseBiggerBombs()) {
      event.setRadius(miningManager.biggerBombs(event.getRadius()));
    }
  }
 @SuppressWarnings("deprecation")
 public WorldCounter(World wld, String[] div, int j, int l) {
   if (div[4 + j].equalsIgnoreCase("player")) {
     if (wld.getPlayers() != null) {
       if (div.length == 6 + l) {
         for (Player p : wld.getPlayers()) {
           if (p.getName().equalsIgnoreCase(div[5 + j])) {
             count++;
           }
         }
       } else {
         count = wld.getPlayers().size();
       }
     }
   } else if (div[4 + j].equalsIgnoreCase("mob")) {
     if (div.length == 6 + l) {
       if (Utils.isEntity(div[5 + j])) {
         for (Entity e : wld.getEntities()) {
           if (e.getType().name().toLowerCase().equalsIgnoreCase(div[5 + j])) {
             count++;
           }
         }
       }
     } else {
       for (Entity e : wld.getEntities()) {
         if (e instanceof Monster) {
           count++;
         }
       }
     }
   } else if (div[4 + j].equalsIgnoreCase("animal")) {
     if (div.length == 6 + l) {
       if (Utils.isEntity(div[5 + j])) {
         for (Entity e : wld.getEntities()) {
           if (e.getType().name().toLowerCase().equalsIgnoreCase(div[5 + j])) {
             count++;
           }
         }
       }
     } else {
       for (Entity e : wld.getEntities()) {
         if (e instanceof Animals) {
           count++;
         }
       }
     }
   } else if (div[4 + j].equalsIgnoreCase("item")) {
     if (div.length == 6 + l) {
       if (Utils.isInteger(div[5 + j])
           && Material.getMaterial(Integer.parseInt(div[5 + j])) != null) {
         for (Entity e : wld.getEntities()) {
           if (e instanceof Item) {
             Item i = (Item) e;
             if (i.getItemStack()
                 .getType()
                 .equals(Material.getMaterial(Integer.parseInt(div[5 + j])))) {
               count += i.getItemStack().getAmount();
             }
           }
         }
       }
     } else {
       for (Entity e : wld.getEntities()) {
         if (e instanceof Item) {
           Item i = (Item) e;
           count += i.getItemStack().getAmount();
         }
       }
     }
   } else if (div[4 + j].equalsIgnoreCase("custommob")) {
     if (div.length == 6 + l) {
       if (Utils.isCustomEntity(div[5 + j])) {
         for (Entity e : wld.getEntities()) {
           if (e.hasMetadata("IAmFromConsoleScript")) {
             if (e.getMetadata("IAmFromConsoleScript")
                 .get(0)
                 .asString()
                 .equalsIgnoreCase(div[5 + j])) {
               count++;
             }
           }
         }
       }
     }
   } else if (div[4 + j].equalsIgnoreCase("customitem")) {
     if (div.length == 6 + l) {
       for (Entity e : wld.getEntities()) {
         if (e instanceof Item) {
           if (e.hasMetadata("IAmFromConsoleScript")) {
             if (e.getMetadata("IAmFromConsoleScript")
                 .get(0)
                 .asString()
                 .equalsIgnoreCase(div[5 + j])) {
               count++;
             }
           }
         }
       }
     }
   }
 }
예제 #10
0
  /**
   * 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;
        }
      }
    }
  }
예제 #11
0
  /**
   * Handle EntityDamageByEntity events that involve modifying the event.
   *
   * @param event The event to watch
   */
  @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
  public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
    if (event instanceof FakeEntityDamageByEntityEvent) {
      return;
    }

    double damage = event.getDamage();

    if (damage <= 0) {
      return;
    }

    Entity defender = event.getEntity();

    if (defender.hasMetadata(mcMMO.customDamageKey)) {
      defender.removeMetadata(mcMMO.customDamageKey, plugin);
      return;
    }

    if (Misc.isNPCEntity(defender) || !defender.isValid() || !(defender instanceof LivingEntity)) {
      return;
    }

    LivingEntity target = (LivingEntity) defender;

    if (CombatUtils.isInvincible(target, damage)) {
      return;
    }

    Entity attacker = event.getDamager();

    if (Misc.isNPCEntity(attacker)) {
      return;
    }

    if (attacker instanceof Projectile) {
      attacker = ((Projectile) attacker).getShooter();
    } else if (attacker instanceof Tameable) {
      AnimalTamer animalTamer = ((Tameable) attacker).getOwner();

      if (animalTamer != null && ((OfflinePlayer) animalTamer).isOnline()) {
        attacker = (Entity) animalTamer;
      }
    }

    if (defender instanceof Player && attacker instanceof Player) {
      Player defendingPlayer = (Player) defender;
      Player attackingPlayer = (Player) attacker;

      // We want to make sure we're not gaining XP or applying abilities when we hit ourselves
      if (defendingPlayer.equals(attackingPlayer)) {
        return;
      }

      if (PartyManager.inSameParty(defendingPlayer, attackingPlayer)
          && !(Permissions.friendlyFire(attackingPlayer)
              && Permissions.friendlyFire(defendingPlayer))) {
        event.setCancelled(true);
        return;
      }
    }

    CombatUtils.processCombatAttack(event, attacker, target);
  }