Java Code Examples for org.bukkit.event.entity.ProjectileLaunchEvent#getEntity()

The following examples show how to use org.bukkit.event.entity.ProjectileLaunchEvent#getEntity() . 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: TridentListener.java    From MineTinker with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onTridentLaunch(ProjectileLaunchEvent event) {
	if (!(event.getEntity().getShooter() instanceof Player)) {
		return;
	}

	if (!(event.getEntity() instanceof Trident)) {
		return;
	}

	Player player = (Player) event.getEntity().getShooter();
	ItemStack trident = player.getInventory().getItemInMainHand().clone();

	if (!ModManager.instance().isToolViable(trident)) {
		return;
	}

	ModManager.instance().addExp(player, trident, -20000);
	//trident is a item clone and only for triggering modifier effects
	//this makes sure that the item duplicate does not get any level ups
	TridentToItemStack.put((Trident) event.getEntity(), trident);
}
 
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: 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 4
Source File: ArcherySymptom.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void onShoot(ProjectileLaunchEvent event) {
    super.onShoot(event);

    if(event.getEntity() instanceof Arrow) {
        Arrow arrow = (Arrow) event.getEntity();
        arrow.setDamage(modifier.apply(arrow.getDamage()));
        arrow.setVelocity(arrow.getVelocity().multiply(modifier.apply(1d)));
    }
}
 
Example 5
Source File: ParticleListener.java    From NyaaUtils with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onProjectileLaunch(ProjectileLaunchEvent event) {
    if (plugin.cfg.particles_type_other && event.getEntity() != null && event.getEntity().getShooter() instanceof Player) {
        if (!plugin.particleTask.bypassPlayers.contains(((Player) event.getEntity().getShooter()).getUniqueId())) {
            projectiles.add(event.getEntity().getUniqueId());
        }
    }
}
 
Example 6
Source File: ExpCapListener.java    From NyaaUtils with MIT License 5 votes vote down vote up
@EventHandler
public void onExpCapThrown(ProjectileLaunchEvent event) {
    if (!cfg.expcap_thron_enabled) return;
    if (event.getEntity() instanceof ThrownExpBottle) {
        ProjectileSource shooter = event.getEntity().getShooter();
        if (shooter instanceof Player) {
            event.getEntity().setMetadata("nu_expcap_exp",
                    new FixedMetadataValue(plugin,
                            thrownExpMap.computeIfAbsent(((Player) shooter).getUniqueId(), uuid -> 0)
                    )
            );
        }
    }
}
 
Example 7
Source File: ServerListener.java    From ZombieEscape with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler
public void onThrow(ProjectileLaunchEvent event) {
    Projectile projectile = event.getEntity();

    if (projectile instanceof Snowball && projectile.getShooter() instanceof Player) {
        Player player = (Player) projectile.getShooter();
        if (player.getItemInHand().getType() == Material.SNOW_BALL && player.getItemInHand().getAmount() == 0) {
            // ran out of snowballs
            new ReloadTask(player).runTaskLater(plugin, 20 * 3);
            Messages.RELOADING.send(player);
        }
    }
}
 
Example 8
Source File: BukkitPlotListener.java    From PlotMe-Core with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onProjectileLaunchEvent(ProjectileLaunchEvent event) {
    if (event.getEntity() instanceof Player) {
        PlotMapInfo pmi = manager.getMap(BukkitUtil.adapt(event.getEntity().getWorld()));
        if (pmi != null && !pmi.canUseProjectiles()) {
            event.getEntity().sendMessage(api.C("ErrCannotUseEggs"));
            event.setCancelled(true);
        }
    }
}
 
Example 9
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 10
Source File: EntityListener.java    From AuthMeReloaded with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onProjectileLaunch(ProjectileLaunchEvent event) {
    final Projectile projectile = event.getEntity();

    ProjectileSource shooter = projectile.getShooter();
    if (shooter instanceof Player && listenerService.shouldCancelEvent((Player) shooter)) {
        event.setCancelled(true);
    }
}
 
Example 11
Source File: Fiery.java    From MineTinker with GNU General Public License v3.0 4 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.fiery.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;

	arrow.setFireTicks(2000);
}
 
Example 12
Source File: Magical.java    From MineTinker with GNU General Public License v3.0 4 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.magical.use")) return;

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

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

	int modLevel = modManager.getModLevel(tool, this);
	if (modLevel <= 0) return;

	if (PlayerInfo.getPlayerExp(player) < this.experienceCost) {
		event.setCancelled(true);
		return;
	}

	player.giveExp(- this.experienceCost);

	arrow.setBounce(true);
	((Arrow) arrow).setColor(Color.PURPLE);
	((Arrow) arrow).setPickupStatus(AbstractArrow.PickupStatus.CREATIVE_ONLY);
	arrow.setGravity(false);
	//arrow.setGlowing(true);

	Entity entity = player.getLocation().getWorld().spawnEntity(arrow.getLocation().add(arrow.getVelocity().normalize().multiply(-0.5)), EntityType.ENDERMITE);
	if (entity instanceof LivingEntity) {
		((LivingEntity) entity).setRemoveWhenFarAway(true);
		//((LivingEntity) entity).setAI(false); can not move
		entity.setGravity(false);
		entity.setVelocity(arrow.getVelocity().multiply(this.multiplierArrowSpeed)); //does not work
		entity.setInvulnerable(true);
		entity.setSilent(true);
		((LivingEntity) entity).setCollidable(false);

		for (int i = 5; i < 10 * 20; i = i + 5) {
			Bukkit.getScheduler().runTaskLater(MineTinker.getPlugin(), () -> {
				entity.teleport(arrow.getLocation().add(arrow.getVelocity().normalize().multiply(-0.4)));
				entity.setVelocity(arrow.getVelocity()); //does not work
			}, i);
		}
	}
	arrow.setCustomName(this.getKey() + ":" + modLevel + ":" + entity.getUniqueId());

	arrow.addAttachment(MineTinker.getPlugin(), this.getKey() + ":" + modLevel, true);

	arrow.setVelocity(arrow.getVelocity().multiply(this.multiplierArrowSpeed));

	((Arrow) arrow).setDamage(((Arrow) arrow).getDamage() * Math.pow(this.multiplierDamagePerLevel, modLevel));

	ChatWriter.logModifier(player, event, this, tool, "Cost(" + this.experienceCost + ")");

	Bukkit.getScheduler().runTaskLater(MineTinker.getPlugin(), () -> {
		entity.remove();
		arrow.remove();
	}, 10 * 20L);

	//TODO: Find a way to hide the arrow from clients
}
 
Example 13
Source File: MultiShot.java    From MineTinker with GNU General Public License v3.0 4 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.multishot.use")) {
		return;
	}

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

	if (ToolType.CROSSBOW.contains(tool.getType()) && getConfig().getBoolean("UseEnchantOnCrossbow")) {
		return;
	}

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

	int modLevel = modManager.getModLevel(tool, this);

	if (modLevel <= 0) {
		return;
	}

	Vector vel = arrow.getVelocity().clone();
	Location loc = arrow.getLocation().clone();

	boolean hasInfinity = modManager.hasMod(tool, Infinity.instance());

	boolean hasFiery = modManager.hasMod(tool, Fiery.instance()) && player.hasPermission("minetinker.modifiers.fiery.use");
	ChatWriter.logModifier(player, event, this, tool,
			Fiery.instance().getKey() + "(" + hasFiery + ")",
			Infinity.instance().getKey() + "(" + hasInfinity + ")");

	for (int i = 1; i <= modLevel; i++) {
		if (!player.getGameMode().equals(GameMode.CREATIVE)) {
			if (!hasInfinity && needsArrows) {
				if (!player.getInventory().contains(Material.ARROW)) {
					break;
				}

				for (ItemStack item : player.getInventory().getContents()) {
					if (item == null) {
						continue;
					}

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

		Bukkit.getScheduler().runTaskLater(MineTinker.getPlugin(), () -> {
			Arrow arr = loc.getWorld().spawnArrow(loc, vel, (float) vel.length(), (float) spread);
			if(hasFiery) arr.setFireTicks(2000);
			arr.setShooter(player);

			if (hasInfinity || player.getGameMode().equals(GameMode.CREATIVE)) {
				arr.setPickupStatus(AbstractArrow.PickupStatus.CREATIVE_ONLY);
			}

			arr.setCritical(((Arrow) arrow).isCritical());
			arr.setDamage(((Arrow) arrow).getDamage());
		}, i);
	}
}