Example #1
0
  @EventHandler(priority = EventPriority.NORMAL)
  private void onProjectileHit(ProjectileHitEvent evt) {
    if (!(evt.getEntity() instanceof Arrow)) {
      return;
    }
    Arrow arrow = (Arrow) evt.getEntity();
    if (arrow.hasMetadata("rocket")) {
      plugin
          .getServer()
          .getWorld("world")
          .createExplosion(
              arrow.getLocation().getX(),
              arrow.getLocation().getY(),
              arrow.getLocation().getZ(),
              7,
              false,
              false);

      for (Entity nearby : arrow.getNearbyEntities(3, 3, 3)) {
        if (!(nearby instanceof Player)) {
          return;
        }
        Player player = (Player) nearby;
        if (player == (Player) arrow.getShooter()) {
          player.damage(2, arrow.getShooter());
        } else {
          player.damage(8, arrow.getShooter());
        }
      }
      plugin.getArrowsFired().remove(evt.getEntity());
      arrow.remove();
    }
  }
Example #2
0
 @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
 public void antiArrowSpam(ProjectileHitEvent event) { // Destroys the Arrows of the Minigun
   if (event.getEntityType().equals(EntityType.ARROW)) {
     Arrow arrow = (Arrow) event.getEntity();
     ProjectileSource shooter = arrow.getShooter();
     if (shooter instanceof Player)
       if (arrow.hasMetadata("ce.minigunarrow"))
         if (((Player) shooter).getGameMode().equals(GameMode.CREATIVE)) arrow.remove();
   }
 }
Example #3
0
 @EventHandler(priority = EventPriority.HIGHEST)
 private void onProjectileLaunch(ProjectileLaunchEvent evt) {
   if (evt.getEntity() instanceof Arrow) {
     Arrow arrow = (Arrow) evt.getEntity();
     if (arrow.getShooter() instanceof Player) {
       Player shooter = (Player) arrow.getShooter();
       PlayerDataClass shooterData =
           plugin.getPlayerHandler().findPlayer(shooter.getDisplayName());
       if (shooterData != null) {
         if (shooter.getInventory().contains(Material.ARROW)) {
           if (shooterData.getType().equalsIgnoreCase("sniper") && arrow.hasMetadata("charged")) {
             evt.setCancelled(true);
             // shooter.getInventory().removeItem(new ItemStack (Material.ARROW, 1));
             // shooter.updateInventory();
             // ItemStack is = shooter.getInventory().getItem(Material.ARROW.getId());
             // is.setAmount(is.getAmount() - 1);
             // shooter.getInventory().setItem(Material.ARROW.getId(), is);
             // Location loc = shooter.getLocation();
             // loc.add(0,1,0);
             Location arrowLocation = shooter.getEyeLocation();
             arrowLocation.setY(arrowLocation.getY() + 0.1);
             Arrow sniperArrow =
                 shooter
                     .getWorld()
                     .spawnArrow(arrowLocation, shooter.getLocation().getDirection(), 0.6f, 1);
             sniperArrow.setShooter(shooter);
             sniperArrow.setBounce(false);
             sniperArrow.setVelocity(
                 shooter.getLocation().getDirection().normalize().multiply(10));
           }
           if (shooterData.getType().equalsIgnoreCase("soldier")) {
             arrow.setMetadata("rocket", new FixedMetadataValue(plugin, true));
             ArrowDataClass arrowData = new ArrowDataClass();
             arrowData.setArrow(arrow);
             arrow.setTicksLived(30);
             arrowData.setVector(shooter.getLocation().getDirection());
             plugin.getArrowsFired().add(arrowData);
           }
         }
       }
     }
   }
 }