Esempio n. 1
0
  @Override
  public void shoot(PlayerInteractEvent event) {
    if (event.getMaterial() == null) return;
    final List<String> itemLore = event.getItem().getItemMeta().getLore();

    if (WeaponWatch.durability.get(itemLore) == null) WeaponWatch.durability.put(itemLore, 4);
    if (WeaponWatch.durability.get(itemLore) == 0) return;
    if (WeaponWatch.cooldown.contains(itemLore)) return;

    if (shotsLeft.get(itemLore) != null && shotsLeft.get(itemLore) == 0) {
      WeaponWatch.cooldown.add(itemLore);
      shotsLeft.remove(itemLore);
      new BukkitRunnable() {
        @Override
        public void run() {
          WeaponWatch.durability.put(itemLore, WeaponWatch.durability.get(itemLore) - 1);
          WeaponWatch.cooldown.remove(itemLore);
        }
      }.runTaskLater(DuckMain.getPlugin(), 80);
    }

    int shotsPerRound = 6; // @Balancing: Specify shots per round here

    if (shotsLeft.get(itemLore) == null) shotsLeft.put(itemLore, shotsPerRound);
    else shotsLeft.put(itemLore, shotsLeft.get(itemLore) - 1);

    DuckMain.getWorld().playSound(event.getPlayer().getLocation(), Sound.ENTITY_BLAZE_HURT, 10, 1);
    Arrow a =
        event
            .getPlayer()
            .launchProjectile(Arrow.class, event.getPlayer().getLocation().getDirection());
    a.setShooter(event.getPlayer());
    a.setVelocity(a.getVelocity().multiply(6));
    a.setCustomName("MachineGun");
  }
Esempio n. 2
0
 @EventHandler
 public void DodgeHit(EntityDamageByEntityEvent e) {
   if (e.getCause() == DamageCause.PROJECTILE) {
     if (e.getEntity() instanceof Player) {
       Player p = (Player) e.getEntity();
       if (PDUtils.getByName(p.getName()).getKit() != null
           && PDUtils.getByName(p.getName()).getKit().equalsIgnoreCase("Dodge")) {
         PData pd = PDUtils.getByName(p.getName());
         Arrow a = p.launchProjectile(Arrow.class);
         a.setShooter(p);
         a.setVelocity(e.getDamager().getVelocity().multiply(-1));
         e.setCancelled(true);
       }
     }
   }
 }
Esempio n. 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);
           }
         }
       }
     }
   }
 }
Esempio n. 4
0
 @EventHandler
 public void ProjectileHit(ProjectileHitEvent e) {
   List<Entity> nbe =
       e.getEntity()
           .getNearbyEntities(
               e.getEntity().getLocation().getX(),
               e.getEntity().getLocation().getY(),
               e.getEntity().getLocation().getZ());
   for (Entity ee : nbe) {
     if (ee instanceof Player) {
       Player ph = (Player) ee;
       PData pd = PDUtils.getByName(ph.getName());
       if (pd.getKit() != null && pd.getKit().equalsIgnoreCase("Dodge")) {
         Arrow a = ph.launchProjectile(Arrow.class);
         a.setShooter(ph);
         a.setVelocity(e.getEntity().getShooter().getLocation().toVector());
       }
     }
   }
 }
Esempio n. 5
0
  @EventHandler(ignoreCancelled = true)
  public void onEntityDamageEntity(EntityDamageByEntityEvent e) {
    if (e.getEntity() instanceof Player) { // Hit player
      Player damaged = (Player) e.getEntity();
      if (e.getDamager() instanceof Player) { // Player
        Player damager = (Player) e.getDamager();
        if (cancelBothIngame(damaged, damager)) {
          e.setCancelled(true);
          return;
        }
        if (checkForShadowBlade(damager)) {
          e.setCancelled(true);
          return;
        }
        if (pl.ingameList.get(damager).getAttackType() == 2) {
          if (damager.getItemInHand().getType().equals(Material.IRON_SWORD)
              || damager.getItemInHand().getType().equals(Material.DIAMOND_SWORD)
              || damager.getItemInHand().getType().equals(Material.GOLD_SWORD)) {
            e.setCancelled(true);
            return;
          }
        }
        if (!e.isCancelled()) {
          checkTeleport(damager);
        }
      } else if (e.getDamager() instanceof Projectile) { // Arrow
        Projectile proj = (Projectile) e.getDamager();
        if (proj.getShooter() instanceof Player) {
          Player shooter = (Player) proj.getShooter();
          if (cancelBothIngame(damaged, shooter)) {
            e.setCancelled(true);
            return;
          }
          if (pl.ingameList.get(shooter).getAttackType() == 1) {
            e.setCancelled(true);
            return;
          }
          if (checkForShadowBlade(shooter)) {
            e.setCancelled(true);
            return;
          }

          checkTeleport(shooter);
          if (!e.isCancelled()) {
            if (!checkIngame(damaged)
                && checkIngame(shooter)) { // spectator wont get hurt, and the arrow wont stop
              proj.setBounce(false);
              Vector vel = proj.getVelocity();
              damaged.teleport(damaged.getLocation().add(0, 3, 0));
              damaged.setFlying(true);
              Arrow newArrow = shooter.launchProjectile(Arrow.class);
              newArrow.setShooter(shooter);
              newArrow.setVelocity(vel);
              e.setCancelled(true);
              proj.remove();
            } else if (checkIngame(damaged) && checkIngame(shooter)) {
              // e.setCancelled(true);
              // damaged.damage(e.getDamage());
              checkTarrasque(damaged);
              checkTeleport(damaged);
              checkTeleport(shooter);
              pl.breakEffect(damaged.getLocation(), 3, 11);
            }
          }
        }
      }
    } else { // Hit a non-player
      if (e.getDamager() instanceof Player) { // Player
        Player damager = (Player) e.getDamager();
        if (checkSpectator(damager)) {
          e.setCancelled(true);
          return;
        }
        if (checkForShadowBlade(damager)) {
          e.setCancelled(true);
          return;
        }
        if (pl.ingameList.get(damager).getAttackType() == 2) {
          if (damager.getItemInHand().getType().equals(Material.IRON_SWORD)
              || damager.getItemInHand().getType().equals(Material.DIAMOND_SWORD)
              || damager.getItemInHand().getType().equals(Material.GOLD_SWORD)) {
            e.setCancelled(true);
            return;
          }
        }
        checkTeleport(damager);
      } else if (e.getDamager() instanceof Projectile) { // Arrow
        Projectile proj = (Projectile) e.getDamager();
        if (proj.getShooter() instanceof Player) {
          Player shooter = (Player) proj.getShooter();
          if (!checkIngame(shooter)) {
            if (checkSpectator(shooter)) {
              e.setCancelled(true);
              return;
            }
          } else {
            if (pl.ingameList.get(shooter).getAttackType() == 1) {
              e.setCancelled(true);
              return;
            }
            if (checkForShadowBlade(shooter)) {
              e.setCancelled(true);
              return;
            }
            checkTeleport(shooter);
          }
        }
      }
      if (!e.isCancelled()) {
        pl.breakEffect(e.getEntity().getLocation(), 2, 55);
      }
    }
  }
Esempio n. 6
0
 @EventHandler
 public void onBowShoot(final EntityShootBowEvent e) {
   if (!Api.allowsPVP(e.getEntity())) return;
   if (e.getBow().hasItemMeta()) {
     if (e.getBow().getItemMeta().hasLore()) {
       for (String lore : e.getBow().getItemMeta().getLore()) {
         if (lore.contains(Api.getEnchName("Boom"))) {
           if (Api.isEnchantmentEnabled("Boom")) {
             Arrow.put(
                 (Projectile) e.getProjectile(), Api.getPower(lore, Api.getEnchName("Boom")));
             P.put((Projectile) e.getProjectile(), e.getEntity());
             Enchant.put((Projectile) e.getProjectile(), "Boom");
           }
         }
         if (lore.contains(Api.getEnchName("Doctor"))) {
           if (Api.isEnchantmentEnabled("Doctor")) {
             Arrow.put(
                 (Projectile) e.getProjectile(), Api.getPower(lore, Api.getEnchName("Doctor")));
             P.put((Projectile) e.getProjectile(), e.getEntity());
             Enchant.put((Projectile) e.getProjectile(), "Doctor");
           }
         }
         if (lore.contains(Api.getEnchName("IceFreeze"))) {
           if (Api.isEnchantmentEnabled("IceFreeze")) {
             Arrow.put(
                 (Projectile) e.getProjectile(), Api.getPower(lore, Api.getEnchName("IceFreeze")));
             P.put((Projectile) e.getProjectile(), e.getEntity());
             Enchant.put((Projectile) e.getProjectile(), "IceFreeze");
           }
         }
         if (lore.contains(Api.getEnchName("Lightning"))) {
           if (Api.isEnchantmentEnabled("Lightning")) {
             Arrow.put(
                 (Projectile) e.getProjectile(), Api.getPower(lore, Api.getEnchName("Lightning")));
             P.put((Projectile) e.getProjectile(), e.getEntity());
             Enchant.put((Projectile) e.getProjectile(), "Lightning");
           }
         }
         if (lore.contains(Api.getEnchName("Piercing"))) {
           if (Api.isEnchantmentEnabled("Piercing")) {
             Arrow.put(
                 (Projectile) e.getProjectile(), Api.getPower(lore, Api.getEnchName("Piercing")));
             P.put((Projectile) e.getProjectile(), e.getEntity());
             Enchant.put((Projectile) e.getProjectile(), "Piercing");
           }
         }
         if (lore.contains(Api.getEnchName("Venom"))) {
           if (Api.isEnchantmentEnabled("Venom")) {
             Arrow.put(
                 (Projectile) e.getProjectile(), Api.getPower(lore, Api.getEnchName("Venom")));
             P.put((Projectile) e.getProjectile(), e.getEntity());
             Enchant.put((Projectile) e.getProjectile(), "Venom");
           }
         }
         if (lore.contains(Api.getEnchName("MultiArrow"))) {
           if (Api.isEnchantmentEnabled("MultiArrow")) {
             int power = Api.getPower(lore, Api.getEnchName("MultiArrow"));
             if (Api.randomPicker(2)) {
               for (int i = 1; i <= power; i++) {
                 Arrow arrow =
                     e.getEntity().getWorld().spawn(e.getProjectile().getLocation(), Arrow.class);
                 arrow.setShooter(e.getEntity());
                 arrow.setBounce(false);
                 Vector v = new Vector(Vec(), 0, Vec());
                 arrow.setVelocity(e.getProjectile().getVelocity().add(v));
                 if (((Arrow) e.getProjectile()).isCritical()) arrow.setCritical(true);
               }
             }
           }
         }
       }
     }
   }
 }