org.bukkit.entity.Arrow Java Examples

The following examples show how to use org.bukkit.entity.Arrow. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProjectileModule.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public @Nullable ProjectileModule parse(MapModuleContext context, Logger logger, Document doc) throws InvalidXMLException {
    final ItemParser itemParser = context.needModule(ItemParser.class);
    FilterParser filterParser = context.needModule(FilterParser.class);

    for(Element projectileElement : XMLUtils.flattenElements(doc.getRootElement(), "projectiles", "projectile")) {
        String name = projectileElement.getAttributeValue("name");
        Double damage = XMLUtils.parseNumber(projectileElement.getAttribute("damage"), Double.class, (Double) null);
        double velocity = XMLUtils.parseNumber(Node.fromChildOrAttr(projectileElement, "velocity"), Double.class, 1.0);
        ClickAction clickAction = XMLUtils.parseEnum(Node.fromAttr(projectileElement, "click"), ClickAction.class, "click action", ClickAction.BOTH);
        Class<? extends Entity> entity = XMLUtils.parseEntityTypeAttribute(projectileElement, "projectile", Arrow.class);
        List<PotionEffect> potionKit = itemParser.parsePotionEffects(projectileElement);
        Filter destroyFilter = filterParser.parseOptionalProperty(projectileElement, "destroy-filter").orElse(null);
        Duration coolDown = XMLUtils.parseDuration(projectileElement.getAttribute("cooldown"));
        boolean throwable = XMLUtils.parseBoolean(projectileElement.getAttribute("throwable"), true);

        context.features().define(projectileElement, new ProjectileDefinitionImpl(name, damage, velocity, clickAction, entity, potionKit, destroyFilter, coolDown, throwable));
    }

    return null;
}
 
Example #2
Source File: ParticleEffectListener.java    From SkyWarsReloaded with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void projectileLaunch(ProjectileLaunchEvent e) {
	 Projectile projectile = e.getEntity();
	 if (projectile instanceof Snowball || projectile instanceof Egg || projectile instanceof Arrow) {
		 if (projectile.getShooter() instanceof Player) {
			 Player player = (Player) projectile.getShooter();
			 GameMap gMap = MatchManager.get().getPlayerMap(player);
			 if (gMap != null) {
			 	PlayerStat ps = PlayerStat.getPlayerStats(player.getUniqueId());
			 	if (ps != null) {
                       String key = ps.getProjectileEffect();
                       ProjectileEffectOption peo = (ProjectileEffectOption) ProjectileEffectOption.getPlayerOptionByKey(key);
                       if (peo != null) {
                           List<ParticleEffect> effects = peo.getEffects();
                           if (key != null && effects != null) {
                               if (!key.equalsIgnoreCase("none")) {
                                   SkyWarsReloaded.getOM().addProjectile(projectile, effects);
                               }
                           }
                       }
                   }
			 }
		 }
	 }
}
 
Example #3
Source File: CEListener.java    From ce with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void EntityDamageByEntityEvent(EntityDamageByEntityEvent e) {

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

    // Block self damaging (Enderpearls cause weird behavior)
    if (damager.getUniqueId().equals(damaged.getUniqueId()))
        return;

    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);

}
 
Example #4
Source File: Compat19.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onEntityDamageByEntity(EntityDamageByEntityEvent e) {
    // Deny arrow booster
    Region r = RedProtect.get().rm.getTopRegion(e.getEntity().getLocation());
    if (r == null && e.getEntity() instanceof Player && e.getDamager() instanceof Arrow) {
        Player p = (Player) e.getEntity();
        Arrow arrow = (Arrow)e.getDamager();
        if (arrow.getShooter() instanceof Player && p.isGliding()) {
            if (arrow.getShooter().equals(p) && !p.hasPermission("redprotect.bypass.glide") &&
                    !RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).player_glide.allow_boost) {
                e.setCancelled(true);
                arrow.remove();
                RedProtect.get().lang.sendMessage(p, "globallistener.elytra.cantboost");
            }
        }
    }
}
 
Example #5
Source File: PlayerDamageListener.java    From UhcCore with GNU General Public License v3.0 6 votes vote down vote up
private void handleArrow(EntityDamageByEntityEvent event){

		PlayersManager pm = GameManager.getGameManager().getPlayersManager();
		
		if(event.getEntity() instanceof Player && event.getDamager() instanceof Arrow){
			Projectile arrow = (Projectile) event.getDamager();
			final Player shot = (Player) event.getEntity();
			if(arrow.getShooter() instanceof Player){
				
				if(!GameManager.getGameManager().getPvp()){
					event.setCancelled(true);
					return;
				}

				UhcPlayer uhcDamager = pm.getUhcPlayer((Player) arrow.getShooter());
				UhcPlayer uhcDamaged = pm.getUhcPlayer(shot);

				if(!friendlyFire && uhcDamager.getState().equals(PlayerState.PLAYING) && uhcDamager.isInTeamWith(uhcDamaged)){
					uhcDamager.sendMessage(Lang.PLAYERS_FF_OFF);
					event.setCancelled(true);
				}
			}
		}
	}
 
Example #6
Source File: ProjectileArrowComponent.java    From civcraft with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void fire(Location turretLoc, Entity targetEntity) {
	if (!buildable.isValid()) {
		return;
	}
	
	Location playerLoc = targetEntity.getLocation();
	playerLoc.setY(playerLoc.getY()+1); //Target the head instead of feet.
				
	turretLoc = adjustTurretLocation(turretLoc, playerLoc);
	Vector dir = getVectorBetween(playerLoc, turretLoc).normalize();
	Arrow arrow = buildable.getCorner().getLocation().getWorld().spawnArrow(turretLoc, dir, (float)power, 0.0f);
	arrow.setVelocity(dir.multiply(power));
	
	if (buildable.getTown().getBuffManager().hasBuff(Buff.FIRE_BOMB)) {
		arrow.setFireTicks(1000);
	}
	
	CivCache.arrowsFired.put(arrow.getUniqueId(), new ArrowFiredCache(this, targetEntity, arrow));
}
 
Example #7
Source File: GrapplingHookListener.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
public void addGrapplingHook(Player p, Arrow arrow, Bat bat, boolean dropItem, long despawnTicks) {
    GrapplingHookEntity hook = new GrapplingHookEntity(p, arrow, bat, dropItem);
    UUID uuid = p.getUniqueId();

    activeHooks.put(uuid, hook);

    // To fix issue #253
    Slimefun.runSync(() -> {
        GrapplingHookEntity entity = activeHooks.get(uuid);

        if (entity != null) {
            SlimefunPlugin.getBowListener().getProjectileData().remove(uuid);
            entity.remove();

            Slimefun.runSync(() -> {
                activeHooks.remove(uuid);
                invulnerability.remove(uuid);
            }, 20L);
        }
    }, despawnTicks);
}
 
Example #8
Source File: ModifyBowProjectileModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public ModifyBowProjectileModule parse(MapFactory factory, Logger logger, Document doc)
    throws InvalidXMLException {
  boolean changed = false;
  Class<? extends Entity> projectile = Arrow.class;
  float velocityMod = 1;
  Set<PotionEffect> potionEffects = new HashSet<>();

  for (Element parent : doc.getRootElement().getChildren("modifybowprojectile")) {
    if (factory.getProto().isNoOlderThan(MapProtos.FILTER_FEATURES)) {
      throw new InvalidXMLException(
          "Module is discontinued as of " + MapProtos.FILTER_FEATURES.toString(),
          doc.getRootElement().getChild("modifybowprojectile"));
    }

    Element projectileElement = parent.getChild("projectile");
    if (projectileElement != null) {
      projectile = XMLUtils.parseEntityType(projectileElement);
      changed = true;
    }

    Element velocityModElement = parent.getChild("velocityMod");
    if (velocityModElement != null) {
      velocityMod = XMLUtils.parseNumber(velocityModElement, Float.class);
      changed = true;
    }

    for (Element potionElement : parent.getChildren("potion")) {
      potionEffects.add(XMLUtils.parsePotionEffect(potionElement));
      changed = true;
    }
  }

  return !changed
      ? null
      : new ModifyBowProjectileModule(projectile, velocityMod, potionEffects);
}
 
Example #9
Source File: ProjectileTrailMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onProjectileHit(ProjectileHitEvent event) {
    match.player(event.getActor()).ifPresent(shooter -> {
        final Projectile projectile = event.getEntity();
        projectile.removeMetadata(TRAIL_META, PGM.get());
        // Restore critical metadata to arrows if applicable
        if(projectile instanceof Arrow) {
            final Arrow arrow = (Arrow) projectile;
            if(arrow.hasMetadata(CRITICAL_META)) {
                arrow.setCritical(arrow.getMetadata(CRITICAL_META, PGM.get()).asBoolean());
            }
        }
    });
}
 
Example #10
Source File: GrapplingHook.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ItemUseHandler getItemHandler() {
    return e -> {
        Player p = e.getPlayer();
        UUID uuid = p.getUniqueId();

        if (!e.getClickedBlock().isPresent() && !SlimefunPlugin.getGrapplingHookListener().isGrappling(uuid)) {
            e.cancel();

            if (p.getInventory().getItemInOffHand().getType() == Material.BOW) {
                // Cancel, to fix dupe #740
                return;
            }

            ItemStack item = e.getItem();

            if (item.getType() == Material.LEAD) {
                item.setAmount(item.getAmount() - 1);
            }

            Vector direction = p.getEyeLocation().getDirection().multiply(2.0);
            Arrow arrow = p.getWorld().spawn(p.getEyeLocation().add(direction.getX(), direction.getY(), direction.getZ()), Arrow.class);
            arrow.setShooter(p);
            arrow.setVelocity(direction);

            Bat bat = (Bat) p.getWorld().spawnEntity(p.getLocation(), EntityType.BAT);
            bat.setCanPickupItems(false);
            bat.setAI(false);
            bat.setSilent(true);
            bat.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 100000, 100000));
            bat.setLeashHolder(arrow);

            boolean state = item.getType() != Material.SHEARS;
            SlimefunPlugin.getGrapplingHookListener().addGrapplingHook(p, arrow, bat, state, despawnTicks.getValue());
        }
    };
}
 
Example #11
Source File: RageMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
private boolean isRage(Entity damager) {
  if (damager instanceof Player) {
    Player player = (Player) damager;
    return player.getItemInHand().containsEnchantment(Enchantment.DAMAGE_ALL);
  } else if (damager instanceof Arrow) {
    Arrow arrow = (Arrow) damager; // Arrows with damage > 2 are from power bows.
    return arrow.getShooter() instanceof Player && arrow.spigot().getDamage() > 2.0D;
  }
  return false;
}
 
Example #12
Source File: Volley.java    From ce with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void volley(EntityShootBowEvent e, ItemStack item, int lvl) {
    Player p = (Player) e.getEntity();
    int amount = 1 + 2 * lvl; // Keep amount of arrows uneven, 2 extra arrows in a volley per level.

    Arrow oldArrow = (Arrow) e.getProjectile();
    int fireTicks = oldArrow.getFireTicks();
    int knockbackStrength = oldArrow.getKnockbackStrength();
    boolean critical = oldArrow.isCritical();
    String metadata = oldArrow.getMetadata("ce.bow.enchantment").get(0).asString();

    double angleBetweenArrows = (CONE_DEGREES / (amount - 1)) * Math.PI / 180;
    double pitch = (p.getLocation().getPitch() + 90) * Math.PI / 180;
    double yaw = (p.getLocation().getYaw() + 90 - CONE_DEGREES / 2) * Math.PI / 180;

    // Starting direction values for the cone, each arrow increments it's direction on these values.
    double sZ = Math.cos(pitch);

    for (int i = 0; i < amount; i++) { // spawn all arrows in a cone of 90 degrees (equally distributed).;
        double nX = Math.sin(pitch) * Math.cos(yaw + angleBetweenArrows * i);
        double nY = Math.sin(pitch) * Math.sin(yaw + angleBetweenArrows * i);
        Vector newDir = new Vector(nX, sZ, nY);

        Arrow arrow = p.launchProjectile(Arrow.class);
        arrow.setShooter(p);
        arrow.setVelocity(newDir.normalize().multiply(oldArrow.getVelocity().length())); // Need to make sure arrow has same speed as original arrow.
        arrow.setFireTicks(fireTicks); // Set the new arrows on fire if the original one was 
        arrow.setKnockbackStrength(knockbackStrength);
        arrow.setCritical(critical);

        if (i == 0) {
            if (p.getGameMode().equals(GameMode.CREATIVE))
                arrow.setMetadata("ce.Volley", new FixedMetadataValue(getPlugin(), null)); //Control metadata to prevent players from duplicating arrows
        } else {
            arrow.setMetadata("ce.Volley", new FixedMetadataValue(getPlugin(), null)); //Control metadata to prevent players from duplicating arrows
        }
        arrow.setMetadata("ce.bow.enchantment", new FixedMetadataValue(getPlugin(), metadata));
    }
    oldArrow.remove(); // Remove original arrow.
}
 
Example #13
Source File: CEListener.java    From ce with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 #14
Source File: SwitcherooListener.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onPlayerDamage(EntityDamageByEntityEvent e){
    if (!(e.getEntity() instanceof Player)){
        return;
    }

    Player player = ((Player) e.getEntity()).getPlayer();

    if (!(e.getDamager() instanceof Arrow)){
        return;
    }

    Arrow arrow = (Arrow) e.getDamager();

    if (!(arrow.getShooter() instanceof  Player)){
        return;
    }

    Player shooter = ((Player) arrow.getShooter()).getPlayer();

    if (player.equals(shooter)){
        return;
    }

    arrow.remove();

    Location playerLoc = player.getLocation();
    Location shooterLoc = shooter.getLocation();

    player.teleport(shooterLoc);
    shooter.teleport(playerLoc);

    player.sendMessage(Lang.SCENARIO_SWITCHEROO_SWITCH.replace("%player%", shooter.getName()));
    shooter.sendMessage(Lang.SCENARIO_SWITCHEROO_SWITCH.replace("%player%", player.getName()));
}
 
Example #15
Source File: ProjectileParticlesModule.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onArrowLaunch(ProjectileLaunchEvent event) {
    if (event.getEntity() instanceof Arrow)
        ((Arrow) event.getEntity()).setCritical(false);
    if (event.getActor() instanceof Player)
        createParticlesFor(event.getEntity(), (Player) event.getActor());
}
 
Example #16
Source File: Infinity.java    From MineTinker with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onShoot(ProjectileLaunchEvent event) {
	if (!this.isAllowed()) return;

	Projectile arrow = event.getEntity();
	if (!(arrow instanceof Arrow)) return;

	if (!(arrow.getShooter() instanceof Player)) return;

	Player player = (Player) arrow.getShooter();
	if (!player.hasPermission("minetinker.modifiers.infinity.use")) return;

	ItemStack tool = player.getInventory().getItemInMainHand();

	if (!ToolType.CROSSBOW.contains(tool.getType())) return;

	if (!modManager.isToolViable(tool)) return;

	if (!modManager.hasMod(tool, this)) return;

	if(!((Arrow) arrow).hasCustomEffects()) {
		if (player.getInventory().addItem(new ItemStack(Material.ARROW, 1)).size() != 0) { //adds items to (full) inventory
			player.getWorld().dropItem(player.getLocation(), new ItemStack(Material.ARROW, 1)); //drops item when inventory is full
		} // no else as it gets added in if

		((Arrow) arrow).setPickupStatus(AbstractArrow.PickupStatus.CREATIVE_ONLY);
		ChatWriter.logModifier(player, event, this, tool);
	}
}
 
Example #17
Source File: ItemListener.java    From Carbon with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEntityKilled(EntityDeathEvent e) {
    if (e.getEntity().getType() != EntityType.SHEEP || !plugin.getConfig().getBoolean("options.sheep.dropMutton", true) || !e.getEntity().getWorld().isGameRule("doMobLoot") || !(e.getEntity() instanceof Ageable)) {
        return;
    }
    Ageable entity = (Ageable) e.getEntity();
    if (!entity.isAdult()) {
        return;
    }
    boolean fireaspect = false;
    int looting = 1;
    if (entity.getLastDamageCause() instanceof EntityDamageByEntityEvent) {
        EntityDamageByEntityEvent dEvent = (EntityDamageByEntityEvent) entity.getLastDamageCause();
        if (dEvent.getDamager() != null && dEvent.getDamager() instanceof Player) {
            ItemStack hand = ((Player) dEvent.getDamager()).getItemInHand();
            fireaspect = hand.containsEnchantment(Enchantment.FIRE_ASPECT);
            if (hand.containsEnchantment(Enchantment.LOOT_BONUS_MOBS))
                looting += hand.getEnchantmentLevel(Enchantment.LOOT_BONUS_MOBS);
            if (looting < 1) //Incase a plugin sets an enchantment level to be negative
                looting = 1;
        } else if (dEvent.getDamager() != null && dEvent.getDamager() instanceof Arrow) {
            Arrow a = (Arrow) dEvent.getDamager();
            if (a.getFireTicks() > 0)
                fireaspect = true;
        }
    }
    if (entity.getLastDamageCause().getCause() == DamageCause.FIRE_TICK || entity.getLastDamageCause().getCause() == DamageCause.FIRE
            || entity.getLastDamageCause().getCause() == DamageCause.LAVA || fireaspect)
        e.getDrops().add(new ItemStack(Carbon.injector().cookedMuttonItemMat, random.nextInt(2) + 1 + random.nextInt(looting)));
    else
        e.getDrops().add(new ItemStack(Carbon.injector().muttonItemMat, random.nextInt(2) + 1 + random.nextInt(looting)));
}
 
Example #18
Source File: FriendlyFireRefundMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void handleFriendlyFire(EntityDamageByEntityEvent event) {
    if(event.isCancelled() && event.getDamager() instanceof Arrow) {
        Arrow arrow = (Arrow) event.getDamager();
        if(arrow.getPickupStatus() == Arrow.PickupStatus.ALLOWED && arrow.getShooter() != null && arrow.getShooter() instanceof Player){
            Player owner = (Player) arrow.getShooter();
            owner.getInventory().addItem(new ItemStack(Material.ARROW));
            arrow.remove();
        }
    }
}
 
Example #19
Source File: BlockTransformListener.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventWrapper
public void onEntityChangeBlock(final EntityChangeBlockEvent event) {
    // Igniting TNT with an arrow is already handled from the ExplosionPrimeEvent
    if(event.getEntity() instanceof Arrow &&
       event.getBlock().getType() == Material.TNT &&
       event.getTo() == Material.AIR) return;

    callEvent(event, event.getBlock().getState(), BlockStateUtils.cloneWithMaterial(event.getBlock(), event.getToData()), entityResolver.getOwner(event.getEntity()));
}
 
Example #20
Source File: RageMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void handlePlayerDamage(EntityDamageByEntityEvent event) {
    if(event.getDamager() instanceof Player) {
        if(((Player) event.getDamager()).getItemInHand().containsEnchantment(Enchantment.DAMAGE_ALL)) event.setDamage(1000);
    } else if(event.getDamager() instanceof Arrow && ((Arrow) event.getDamager()).getShooter() instanceof Player) {
        if(((Arrow) event.getDamager()).getDamage() > 2D) event.setDamage(1000);
    }
}
 
Example #21
Source File: EntityListener.java    From Guilds with MIT License 5 votes vote down vote up
/**
 * Handles flame arrows
 *
 * @param event
 */
@EventHandler
public void onFlameArrow(EntityCombustByEntityEvent event) {

    if (!(event.getEntity() instanceof Player))
        return;

    if (!(event.getCombuster() instanceof Arrow))
        return;

    Arrow arrow = (Arrow) event.getCombuster();

    if (!(arrow.getShooter() instanceof Player))
        return;

    Player damagee = (Player) event.getEntity();
    Player damager = (Player) arrow.getShooter();

    if (settingsManager.getProperty(GuildSettings.RESPECT_WG_PVP_FLAG)) {
        event.setCancelled(ClaimUtils.checkPvpDisabled(damagee));
        return;
    }

    if (guildHandler.isSameGuild(damagee, damager)) {
        arrow.setFireTicks(0);
        event.setCancelled(!settingsManager.getProperty(GuildSettings.GUILD_DAMAGE));
        return;
    }

    if (guildHandler.isAlly(damagee, damager)) {
        arrow.setFireTicks(0);
        event.setCancelled(!settingsManager.getProperty(GuildSettings.ALLY_DAMAGE));
    }
}
 
Example #22
Source File: Rage.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
    if (event.getDamager() instanceof Player) {
        ItemStack item = ((Player) event.getDamager()).getItemInHand();
        if (item != null) {
            if (item.containsEnchantment(Enchantment.DAMAGE_ALL) && item.getEnchantmentLevel(Enchantment.DAMAGE_ALL) > 1) {
                event.setDamage(1000);
            }
        }
    } else if (event.getDamager() instanceof Arrow) {
        if (event.getDamager().hasMetadata("rage")) {
            event.setDamage(1000);
        }
    }
}
 
Example #23
Source File: SlimefunBowListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onArrowSuccessfulHit(EntityDamageByEntityEvent e) {
    if (e.getDamager() instanceof Arrow && e.getEntity() instanceof LivingEntity && e.getCause() != EntityDamageEvent.DamageCause.ENTITY_EXPLOSION) {
        SlimefunBow bow = projectiles.get(e.getDamager().getUniqueId());

        if (bow != null) {
            bow.callItemHandler(BowShootHandler.class, handler -> handler.onHit(e, (LivingEntity) e.getEntity()));
        }

        projectiles.remove(e.getDamager().getUniqueId());
    }
}
 
Example #24
Source File: SlimefunBowListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onArrowHit(ProjectileHitEvent e) {
    Slimefun.runSync(() -> {
        if (e.getEntity().isValid() && e.getEntity() instanceof Arrow) {
            projectiles.remove(e.getEntity().getUniqueId());
        }
    }, 4L);
}
 
Example #25
Source File: SlimefunBowListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onBowUse(EntityShootBowEvent e) {
    if (e.getEntity() instanceof Player && e.getProjectile() instanceof Arrow) {
        SlimefunItem bow = SlimefunItem.getByItem(e.getBow());

        if (bow instanceof SlimefunBow) {
            projectiles.put(e.getProjectile().getUniqueId(), (SlimefunBow) bow);
        }
    }
}
 
Example #26
Source File: EliteMobs.java    From EliteMobs with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDisable() {

    Bukkit.getServer().getScheduler().cancelTasks(MetadataHandler.PLUGIN);

    EntityTracker.shutdownPurger();

    for (World world : validWorldList) {
        world.save();
    }

    /*
    Flush lingering arrows from the arrow tracking power
     */
    for (Arrow arrow : SkeletonTrackingArrow.trackingArrowList)
        arrow.remove();
    SkeletonTrackingArrow.trackingArrowList.clear();

    /*
    todo: Flush lingering blocks
     */


    CustomItemConstructor.customItemList.clear();
    CustomItemConstructor.staticCustomItemHashMap.clear();
    CustomItemConstructor.dynamicRankedItemStacks.clear();
    UniqueItemInitializer.uniqueItemsList.clear();
    validWorldList.clear();

    //save cached data
    Bukkit.getScheduler().cancelTask(PlayerData.databaseSyncTaskID);
    Bukkit.getLogger().info("[EliteMobs] Saving EliteMobs databases...");
    PlayerData.saveDatabases();
    Bukkit.getLogger().info("[EliteMobs] All saved! Good night.");
    PlayerData.clearPlayerData();

}
 
Example #27
Source File: CraftEventFactory.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
/**
 * EntityShootBowEvent
 */
public static EntityShootBowEvent callEntityShootBowEvent(net.minecraft.entity.EntityLivingBase who, net.minecraft.item.ItemStack itemstack, net.minecraft.entity.projectile.EntityArrow entityArrow, float force) {
    LivingEntity shooter = (LivingEntity) who.getBukkitEntity();
    CraftItemStack itemInHand = CraftItemStack.asCraftMirror(itemstack);
    Arrow arrow = (Arrow) entityArrow.getBukkitEntity();

    if (itemInHand != null && (itemInHand.getType() == Material.AIR || itemInHand.getAmount() == 0)) {
        itemInHand = null;
    }

    EntityShootBowEvent event = new EntityShootBowEvent(shooter, itemInHand, arrow, force);
    Bukkit.getPluginManager().callEvent(event);

    return event;
}
 
Example #28
Source File: AsyncWorld.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Arrow spawnArrow(final Location location, final Vector direction, final float speed, final float spread) {
    return TaskManager.IMP.sync(new RunnableVal<Arrow>() {
        @Override
        public void run(Arrow value) {
            this.value = parent.spawnArrow(location, direction, speed, spread);
        }
    });
}
 
Example #29
Source File: BlockListener.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void onProjectileHitEvent(ProjectileHitEvent event) {
	if (event.getEntity() instanceof Arrow) {
		ArrowFiredCache afc = CivCache.arrowsFired.get(event.getEntity().getUniqueId());
		if (afc != null) {
			afc.setHit(true);
		}
	}

	if (event.getEntity() instanceof Fireball) {
		CannonFiredCache cfc = CivCache.cannonBallsFired.get(event.getEntity().getUniqueId());
		if (cfc != null) {

			cfc.setHit(true);

			FireworkEffect fe = FireworkEffect.builder().withColor(Color.RED).withColor(Color.BLACK).flicker(true).with(Type.BURST).build();

			Random rand = new Random();
			int spread = 30;
			for (int i = 0; i < 15; i++) {
				int x = rand.nextInt(spread) - spread/2;
				int y = rand.nextInt(spread) - spread/2;
				int z = rand.nextInt(spread) - spread/2;


				Location loc = event.getEntity().getLocation();
				Location location = new Location(loc.getWorld(), loc.getX(),loc.getY(), loc.getZ());
				location.add(x, y, z);

				TaskMaster.syncTask(new FireWorkTask(fe, loc.getWorld(), loc, 5), rand.nextInt(30));
			}

		}
	}
}
 
Example #30
Source File: ArrowFiredCache.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
public ArrowFiredCache(ProjectileArrowComponent tower, Entity targetEntity, Arrow arrow) {
	this.setFromTower(tower);
	this.target = targetEntity.getLocation();
	this.targetEntity = targetEntity;
	this.setArrow(arrow);
	this.uuid = arrow.getUniqueId();
	expired = Calendar.getInstance();
	expired.add(Calendar.SECOND, 5);
}