Java Code Examples for org.bukkit.entity.Player#spawnParticle()

The following examples show how to use org.bukkit.entity.Player#spawnParticle() . 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: ParticleData.java    From NyaaUtils with MIT License 6 votes vote down vote up
public void sendParticle(UUID uuid, Location loc, ParticleLimit limit, long time) {
    if (!lastSend.containsKey(uuid)) {
        lastSend.put(uuid, 0L);
    }
    if (time - lastSend.get(uuid) >= (freq < limit.getFreq() ? limit.getFreq() : freq) &&
            NyaaUtils.instance.cfg.particles_enabled.contains(particle.name())) {
        lastSend.put(uuid, time);
        double distance = Bukkit.getViewDistance() * 16;
        distance *= distance;
        for (Player player : loc.getWorld().getPlayers()) {
            if (player.isValid() && !NyaaUtils.instance.particleTask.bypassPlayers.contains(player.getUniqueId())
                    && loc.distanceSquared(player.getLocation()) <= distance) {
                player.spawnParticle(particle, loc,
                        count > limit.getAmount() ? limit.getAmount() : count,
                        offsetX > limit.getOffsetX() ? limit.getOffsetX() : offsetX,
                        offsetY > limit.getOffsetY() ? limit.getOffsetY() : offsetY,
                        offsetZ > limit.getOffsetZ() ? limit.getOffsetZ() : offsetZ,
                        extra > limit.getExtra() ? limit.getExtra() : extra,
                        getData());
            }
        }
    }
}
 
Example 2
Source File: Particles.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void sendParticles(List<Player> viewers, String particleName, Location loc, int count, double offsetX,
	double offsetY, double offsetZ, double extra) {
	for (Player player : viewers) {
		try {
			player.spawnParticle(Particle.valueOf(particleName.toUpperCase()), loc.getX(), loc.getY(), loc.getZ(),
				count, offsetX, offsetY, offsetZ, extra);
		} catch (Throwable t) {
			try {
				Object selectedParticle = null;
				particleName = particleName.toUpperCase();
				for (Object obj : EnumParticle.getEnumConstants()) {
					if (particleName.equalsIgnoreCase((String) getMethod(obj, "b").invoke())) {
						selectedParticle = obj;
						break;
					}
				}
				Object packet = PacketPlayOutWorldParticles
					.getConstructor(EnumParticle, boolean.class, float.class, float.class, float.class, float.class,
						float.class, float.class, float.class, int.class, int[].class)
					.newInstance(selectedParticle, true, loc.getX(), loc.getY(), loc.getZ(), offsetX, offsetY,
						offsetZ, extra, count, new int[] {});
				sendPacket(player, packet);
			} catch (Throwable ignored) {

			}
		}
	}
}
 
Example 3
Source File: Particles.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void sendParticles(List<Player> viewers, String particleName, Location loc, int count, double offsetX,
	double offsetY, double offsetZ, double extra) {
	for (Player player : viewers) {
		try {
			player.spawnParticle(Particle.valueOf(particleName.toUpperCase()), loc.getX(), loc.getY(), loc.getZ(),
				count, offsetX, offsetY, offsetZ, extra);
		} catch (Throwable t) {
			try {
				Object selectedParticle = null;
				particleName = particleName.toUpperCase();
				for (Object obj : EnumParticle.getEnumConstants()) {
					if (particleName.equalsIgnoreCase((String) getMethod(obj, "b").invoke())) {
						selectedParticle = obj;
						break;
					}
				}
				Object packet = PacketPlayOutWorldParticles
					.getConstructor(EnumParticle, boolean.class, float.class, float.class, float.class, float.class,
						float.class, float.class, float.class, int.class, int[].class)
					.newInstance(selectedParticle, true, loc.getX(), loc.getY(), loc.getZ(), offsetX, offsetY,
						offsetZ, extra, count, new int[] {});
				sendPacket(player, packet);
			} catch (Throwable ignored) {

			}
		}
	}
}
 
Example 4
Source File: StructureUtil.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
private static void spawnParticle(World world, double x, double y, double z, Color color, Player player,
                                  Map<Location, Color> boundingBox) {
    Location location = new Location(world, x, y, z);
    if (location.getBlock().getType() != Material.AIR) {
        return;
    }
    player.spawnParticle(Particle.REDSTONE, location, 1, 0, 0, 0, 1,
            new Particle.DustOptions(color, 1));

    boundingBox.put(location, color);
}
 
Example 5
Source File: ParticleHandler.java    From ClaimChunk with MIT License 5 votes vote down vote up
private static void spawn(Location loc, Player[] players, Particles particle) {
    final Particle bukkitParticle = Particle.valueOf(particle.name());
    //noinspection ConstantConditions
    if (bukkitParticle == null) {
        Utils.err("Invalid particle: %s", particle.name());
        return;
    }
    for (Player p : players) p.spawnParticle(bukkitParticle, loc, 1, 0.0d, 0.0d, 0.0d, 0.0d, null);
}
 
Example 6
Source File: Players.java    From helper with MIT License 4 votes vote down vote up
public static void spawnParticle(Player player, Location location, Particle particle) {
    player.spawnParticle(particle, location, 1);
}
 
Example 7
Source File: Players.java    From helper with MIT License 4 votes vote down vote up
public static void spawnParticle(Player player, Location location, Particle particle, int amount) {
    Preconditions.checkArgument(amount > 0, "amount > 0");
    player.spawnParticle(particle, location, amount);
}
 
Example 8
Source File: Players.java    From helper with MIT License 4 votes vote down vote up
public static void spawnParticleOffset(Player player, Location location, Particle particle, double offset) {
    player.spawnParticle(particle, location, 1, offset, offset, offset);
}
 
Example 9
Source File: Players.java    From helper with MIT License 4 votes vote down vote up
public static void spawnParticleOffset(Player player, Location location, Particle particle, int amount, double offset) {
    Preconditions.checkArgument(amount > 0, "amount > 0");
    player.spawnParticle(particle, location, amount, offset, offset, offset);
}