Java Code Examples for org.bukkit.entity.Arrow#remove()

The following examples show how to use org.bukkit.entity.Arrow#remove() . 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: 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 2
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 3
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 4
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 5
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 6
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 7
Source File: ArrowRemovalMatchModule.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
private void removeOldArrows() {
  for (Arrow arrow : match.getWorld().getEntitiesByClass(Arrow.class)) {
    if (arrow.getTicksLived() >= maxTicks) arrow.remove();
  }
}
 
Example 8
Source File: ArrowRemovalMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@Repeatable(interval = @Time(seconds = 1))
public void repeat() {
    for(Arrow arrow : getMatch().getWorld().getEntitiesByClass(Arrow.class)) {
        if(arrow.getTicksLived() >= this.maxTicks && arrow.getPickupStatus() != Arrow.PickupStatus.ALLOWED) arrow.remove();
    }
}
 
Example 9
Source File: ArrowFiredCache.java    From civcraft with GNU General Public License v2.0 4 votes vote down vote up
public void destroy(Arrow arrow) {
	arrow.remove();
	this.arrow = null;
	CivCache.arrowsFired.remove(this.getUUID());
	this.uuid = null;
}