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

The following examples show how to use org.bukkit.event.entity.ProjectileLaunchEvent#setCancelled() . 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: 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 2
Source File: MainListener.java    From HolographicDisplays with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler (priority = EventPriority.MONITOR, ignoreCancelled = false)
public void onProjectileLaunch(ProjectileLaunchEvent event) {
	if (nmsManager.isNMSEntityBase(event.getEntity())) {
		if (event.isCancelled()) {
			event.setCancelled(false);
		}
	}
}
 
Example 3
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 4
Source File: LivingEntityShopListener.java    From Shopkeepers with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
void onEntityLaunchProjectile(ProjectileLaunchEvent event) {
	ProjectileSource source = event.getEntity().getShooter();
	if (source instanceof LivingEntity && plugin.isShopkeeper((LivingEntity) source)) {
		event.setCancelled(true);
	}
}
 
Example 5
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
}