Skip to content

ParticlesUtils

Fulminazzo edited this page Oct 17, 2023 · 2 revisions

ParticlesUtils is a utility class that allows to work with particles regardless of the version you are on. It was created to fight the inconsistencies between versions prior 1.13 and post 1.13.

public class ParticlesUtils extends NMSUtils {

    /**
     * Spawn particles in the given position making them visible only for
     * players in a certain radius (view-distance * 16 blocks) and can see a certain player.
     * Uses #spawnParticle() to spawn.
     * @param player: the player that should be seen;
     * @param location: the location to spawn in;
     * @param particleName: the name of the particle (taken from the corresponding enum field).
     */
    public static void spawnParticleNearPlayer(Player player, Location location, String particleName);

    /**
     * Spawn particles in the given position making them visible only for
     * players in a certain radius (view-distance * 16 blocks) and can see a certain player.
     * Uses #spawnParticle() to spawn.
     * @param player: the player that should be seen;
     * @param location: the location to spawn in;
     * @param particleName: the name of the particle (taken from the corresponding enum field).
     * @param showErrors: whether to display errors in console if no particle is found or not.
     */
    public static void spawnParticleNearPlayer(Player player, Location location, String particleName, boolean showErrors);

    /**
     * Uses reflections to spawn particles for the specified player in the given location.
     * @param player: the player to spawn particles for;
     * @param location: the location to spawn in;
     * @param particleName: the name of the particle (taken from the corresponding enum field).
     */
    public static void spawnParticle(Player player, Location location, String particleName);

    /**
     * Uses reflections to spawn particles for the specified player in the given location.
     * @param player: the player to spawn particles for;
     * @param location: the location to spawn in;
     * @param particleName: the name of the particle (taken from the corresponding enum field);
     * @param showErrors: whether to display errors in console if no particle is found or not.
     */
    public static void spawnParticle(Player player, Location location, String particleName, boolean showErrors);

    /**
     * Spawns a particle of type REDSTONE_DUST for the specified player in the given location.
     * Uses the block and blockData objects to color the particle according to the block color.
     * @param player: the player to spawn particles for;
     * @param particleLocation: the location to spawn in;
     * @param block: the block to take the color from;
     * @param blockData: the blockData to take the color from;
     * @param plugin: the calling plugin.
     */
    public static void spawnBlockParticle(Player player, Location particleLocation, Block block, Object blockData, JavaPlugin plugin);

    /**
     * Spawns a particle of type REDSTONE_DUST for the specified player in the given location.
     * Uses blockColor to color the particle.
     * @param player: the player to spawn particles for;
     * @param particleLocation: the location to spawn in;
     * @param blockColor: the color of the particle.
     */
    public static void spawnBlockParticle(Player player, Location particleLocation, int blockColor);

    /**
     * Returns the color of a block. Used by spawnBlockParticle(Player player, Location particleLocation, int blockColor).
     * @param block: the block to take the color from;
     * @param material: the material of the block;
     * @param plugin: the calling plugin.
     * @return the color of the block.
     */
    public static int getBlockColor(Block block, Material material, JavaPlugin plugin);

    /**
     * Returns the color of a block. Used by spawnBlockParticle(Player player, Location particleLocation, int blockColor).
     * @param block: the block to take the color from;
     * @param blockData: the blockData of the block;
     * @param plugin: the calling plugin.
     * @return the color of the block.
     */
    public static int getBlockColor(Block block, Object blockData, JavaPlugin plugin);
}