org.bukkit.Particle Java Examples

The following examples show how to use org.bukkit.Particle. 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: CheckConfig.java    From WildernessTp with MIT License 6 votes vote down vote up
public boolean checkParticle(){
    if(wild.getConfig().getBoolean("DoParticle")) {
        try {
            String[] tmp = Bukkit.getVersion().split("MC: ");
            String version = tmp[tmp.length - 1].substring(0, 3);
            if (version.equals("1.9") || version.equals("1.1"))
                Particle.valueOf(wild.getConfig().getString("Particle").toUpperCase());
            else
                Effect.valueOf(wild.getConfig().getString("Particle").toUpperCase());
        } catch (IllegalArgumentException e) {
            return false;
        }
    }else
        return true;
    return true;
}
 
Example #2
Source File: CraftParticle.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
public static int[] toData(Particle particle, Object obj) {
    if (particle.getDataType().equals(Void.class)) {
        return new int[0];
    }
    if (particle.getDataType().equals(ItemStack.class)) {
        if (obj == null) {
            return new int[]{0, 0};
        }
        ItemStack itemStack = (ItemStack) obj;
        return new int[]{itemStack.getType().getId(), itemStack.getDurability()};
    }
    if (particle.getDataType().equals(MaterialData.class)) {
        if (obj == null) {
            return new int[]{0};
        }
        MaterialData data = (MaterialData) obj;
        return new int[]{data.getItemTypeId() + ((int) (data.getData()) << 12)};
    }
    throw new IllegalArgumentException(particle.getDataType().toString());
}
 
Example #3
Source File: CropGrowthAccelerator.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
private boolean grow(Block machine, BlockMenu inv, Block crop) {
    Ageable ageable = (Ageable) crop.getBlockData();

    if (ageable.getAge() < ageable.getMaximumAge()) {
        for (int slot : getInputSlots()) {
            if (SlimefunUtils.isItemSimilar(inv.getItemInSlot(slot), organicFertilizer, false)) {
                ChargableBlock.addCharge(machine, -getEnergyConsumption());
                inv.consumeItem(slot);

                ageable.setAge(ageable.getAge() + 1);
                crop.setBlockData(ageable);

                crop.getWorld().spawnParticle(Particle.VILLAGER_HAPPY, crop.getLocation().add(0.5D, 0.5D, 0.5D), 4, 0.1F, 0.1F, 0.1F);
                return true;
            }
        }
    }

    return false;
}
 
Example #4
Source File: Duct.java    From Transport-Pipes with MIT License 6 votes vote down vote up
/**
 * just for the purpose of dropping inside items or other baseDuctType specific stuff
 */
public List<ItemStack> destroyed(TransportPipes transportPipes, DuctManager ductManager, Player destroyer) {
    List<ItemStack> dropItems = new ArrayList<>();
    if (destroyer == null || destroyer.getGameMode() != GameMode.CREATIVE) {
        dropItems.add(getDuctType().getBaseDuctType().getItemManager().getClonedItem(getDuctType()));
    }

    if (settingsInv != null) {
        settingsInv.closeForAllPlayers(transportPipes);
    }

    //break particles
    if (destroyer != null && getBreakParticleData() != null) {
        transportPipes.runTaskSync(() -> destroyer.getWorld().spawnParticle(Particle.ITEM_CRACK, getBlockLoc().getX() + 0.5f, getBlockLoc().getY() + 0.5f, getBlockLoc().getZ() + 0.5f, 30, 0.25f, 0.25f, 0.25f, 0.05f, new ItemStack(getBreakParticleData())));
    }

    return dropItems;
}
 
Example #5
Source File: ParticleDisplay.java    From XSeries with MIT License 6 votes vote down vote up
/**
 * Displays the particle in the specified location.
 * This method does not support rotations if used directly.
 *
 * @param loc the location to display the particle at.
 * @see #spawn(double, double, double)
 * @since 2.1.0
 */
public void spawn(@Nonnull Location loc, boolean rotate) {
    if (rotate) loc = rotate(location, loc.getX(), loc.getY(), loc.getZ(), rotation);
    if (data != null) {
        if (data instanceof float[]) {
            float[] datas = (float[]) data;
            if (ISFLAT) {
                Particle.DustOptions dust = new Particle.DustOptions(org.bukkit.Color
                        .fromRGB((int) datas[0], (int) datas[1], (int) datas[2]), datas[3]);
                loc.getWorld().spawnParticle(particle, loc, count, offsetx, offsety, offsetz, extra, dust);
            } else {
                loc.getWorld().spawnParticle(particle, loc, count, (int) datas[0], (int) datas[1], (int) datas[2], datas[3]);
            }
        }
    } else {
        loc.getWorld().spawnParticle(particle, loc, count, offsetx, offsety, offsetz, extra);
    }
}
 
Example #6
Source File: ParticleHandlers.java    From QualityArmory with GNU General Public License v3.0 6 votes vote down vote up
public static void spawnMuzzleSmoke(Player shooter, Location loc) {
	try {
		double theta = Math.atan2(shooter.getLocation().getDirection().getX(),
				shooter.getLocation().getDirection().getZ());

		theta -= (Math.PI / 8);

		double x = Math.sin(theta);
		double z = Math.cos(theta);

		Location l = loc.clone().add(x, 0, z);

		for (int i = 0; i < 2; i++)
			loc.getWorld().spawnParticle(Particle.SPELL, l, 0);
	} catch (Error | Exception e4) {
	}
}
 
Example #7
Source File: TreeGrowthAccelerator.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
private boolean grow(Block machine, Block block, BlockMenu inv, Sapling sapling) {
    for (int slot : getInputSlots()) {
        if (SlimefunUtils.isItemSimilar(inv.getItemInSlot(slot), organicFertilizer, false)) {
            ChargableBlock.addCharge(machine, -ENERGY_CONSUMPTION);

            sapling.setStage(sapling.getStage() + 1);
            block.setBlockData(sapling);

            inv.consumeItem(slot);
            block.getWorld().spawnParticle(Particle.VILLAGER_HAPPY, block.getLocation().add(0.5D, 0.5D, 0.5D), 4, 0.1F, 0.1F, 0.1F);
            return true;
        }
    }

    return false;
}
 
Example #8
Source File: AutoBreeder.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
protected void tick(Block b) {
    BlockMenu inv = BlockStorage.getInventory(b);

    for (Entity n : b.getWorld().getNearbyEntities(b.getLocation(), 4.0, 2.0, 4.0, this::canBreed)) {
        for (int slot : getInputSlots()) {
            if (SlimefunUtils.isItemSimilar(inv.getItemInSlot(slot), organicFood, false)) {
                if (ChargableBlock.getCharge(b) < ENERGY_CONSUMPTION) {
                    return;
                }

                ChargableBlock.addCharge(b, -ENERGY_CONSUMPTION);
                inv.consumeItem(slot);

                ((Animals) n).setLoveModeTicks(600);
                n.getWorld().spawnParticle(Particle.HEART, ((LivingEntity) n).getEyeLocation(), 8, 0.2F, 0.2F, 0.2F);
                return;
            }
        }
    }
}
 
Example #9
Source File: ParticleDisplay.java    From EffectLib with MIT License 6 votes vote down vote up
protected void displayLegacyColored(Particle particle, Location center, float speed, Color color, double range, List<Player> targetPlayers) {
    int amount = 0;
    // Colored particles can't have a speed of 0.
    if (speed == 0) {
        speed = 1;
    }
    float offsetX = (float) color.getRed() / 255;
    float offsetY = (float) color.getGreen() / 255;
    float offsetZ = (float) color.getBlue() / 255;

    // The redstone particle reverts to red if R is 0!
    if (offsetX < Float.MIN_NORMAL) {
        offsetX = Float.MIN_NORMAL;
    }

    display(particle, center, offsetX, offsetY, offsetZ, speed, amount, null, range, targetPlayers);
}
 
Example #10
Source File: EffParticlesV1_13.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void execute(Event evt) {
    double hx = 0;
    double hy = 0;
    double hz = 0;
    //float id = 0;
    //int[] array = new int[0];
    if (xoffset != null) {
        hx = xoffset.getSingle(evt).doubleValue();
    }
    if (yoffset != null) {
        hy = yoffset.getSingle(evt).doubleValue();
    }
    if (zoffset != null) {
        hz = zoffset.getSingle(evt).doubleValue();
    }
    String core = type.getSingle(evt);
/*
if (core.toUpperCase().replace(" ", "_").contains("BLOCK_CRACK")
    || core.toUpperCase().replace(" ", "_").contains("BLOCK_DUST")) {
  int index = type.getSingle(evt).lastIndexOf("_");
  try {
    id = Integer.parseInt(type.getSingle(evt).substring(index + 1));
  } catch (Exception exception) {
    Skript.error("Could not parse datavalue!");
    id = 0;
  }
  core = core.substring(0, index);
  array = new int[1];
}*/
    Particle particle;
    try {
        particle = Particle.valueOf(core);
    } catch (Exception e) {
        Skript.error("Could not parse particle value!");
        return;
    }
    player.getSingle(evt).spawnParticle(particle, location.getSingle(evt),
            partNum.getSingle(evt).intValue(), hx, hy, hz);
}
 
Example #11
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 #12
Source File: ParticleDisplay.java    From EffectLib with MIT License 5 votes vote down vote up
protected void displayItem(Particle particle, Location center, float offsetX, float offsetY, float offsetZ, float speed, int amount, Material material, byte materialData, double range, List<Player> targetPlayers) {
    if (material == null || material == Material.AIR) {
        return;
    }

    ItemStack item = new ItemStack(material);
    item.setDurability(materialData);
    display(particle, center, offsetX, offsetY, offsetZ, speed, amount, item, range, targetPlayers);
}
 
Example #13
Source File: EffParticlesV1_14.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void execute(Event evt) {
    double hx = 0;
    double hy = 0;
    double hz = 0;
    //float id = 0;
    //int[] array = new int[0];
    if (xoffset != null) {
        hx = xoffset.getSingle(evt).doubleValue();
    }
    if (yoffset != null) {
        hy = yoffset.getSingle(evt).doubleValue();
    }
    if (zoffset != null) {
        hz = zoffset.getSingle(evt).doubleValue();
    }
    String core = type.getSingle(evt);
/*
if (core.toUpperCase().replace(" ", "_").contains("BLOCK_CRACK")
    || core.toUpperCase().replace(" ", "_").contains("BLOCK_DUST")) {
  int index = type.getSingle(evt).lastIndexOf("_");
  try {
    id = Integer.parseInt(type.getSingle(evt).substring(index + 1));
  } catch (Exception exception) {
    Skript.error("Could not parse datavalue!");
    id = 0;
  }
  core = core.substring(0, index);
  array = new int[1];
}*/
    Particle particle;
    try {
        particle = Particle.valueOf(core);
    } catch (Exception e) {
        Skript.error("Could not parse particle value!");
        return;
    }
    player.getSingle(evt).spawnParticle(particle, location.getSingle(evt),
            partNum.getSingle(evt).intValue(), hx, hy, hz);
}
 
Example #14
Source File: ParticleDisplay_13.java    From EffectLib with MIT License 5 votes vote down vote up
@Override
public void display(Particle particle, Location center, float offsetX, float offsetY, float offsetZ, float speed, int amount, float size, Color color, Material material, byte materialData, double range, List<Player> targetPlayers) {
    // Legacy colorizeable particles
    if (color != null && (particle == Particle.SPELL_MOB || particle == Particle.SPELL_MOB_AMBIENT)) {
        displayLegacyColored(particle, center, speed, color, range, targetPlayers);
        return;
    }

    if (particle == Particle.ITEM_CRACK) {
        displayItem(particle, center, offsetX, offsetY, offsetZ, speed, amount, material, materialData, range, targetPlayers);
        return;
    }

    Object data = null;
    if (particle == Particle.BLOCK_CRACK || particle == Particle.BLOCK_DUST || particle == Particle.FALLING_DUST) {
        if (material == null || material == Material.AIR) {
            return;
        }
        data = material.createBlockData();
        if (data == null) {
            return;
        }
    }

    if (particle == Particle.REDSTONE) {
        // color is required for 1.13
        if (color == null) {
            color = Color.RED;
        }
        data = new Particle.DustOptions(color, size);
    }

    display(particle, center, offsetX, offsetY, offsetZ, speed, amount, data, range, targetPlayers);
}
 
Example #15
Source File: NMSHandler.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
public boolean isValueParticle(String string) {
	try {
		Particle.valueOf(string);
	} catch (IllegalArgumentException e) {
		return false;
	}
	return true;
}
 
Example #16
Source File: NMSImpl.java    From TabooLib with MIT License 5 votes vote down vote up
@Override
public Object toPacketPlayOutWorldParticles(Particle var1, boolean var2, float var3, float var4, float var5, float var6, float var7, float var8, float var9, int var10, Object var11) {
    if (is11300) {
        return new net.minecraft.server.v1_13_R2.PacketPlayOutWorldParticles(org.bukkit.craftbukkit.v1_13_R2.CraftParticle.toNMS(var1, var11), var2, var3, var4, var5, var6, var7, var8, var9, var10);
    } else {
        return new net.minecraft.server.v1_12_R1.PacketPlayOutWorldParticles(CraftParticle.toNMS(var1), var2, var3, var4, var5, var6, var7, var8, var9, var10, CraftParticle.toData(var1, var11));
    }
}
 
Example #17
Source File: TeleportationManager.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
private void updateProgress(UUID uuid, int speed, int progress, Location source, Location destination, boolean resistance) {
    Player p = Bukkit.getPlayer(uuid);

    if (isValid(p, source)) {
        if (progress > 99) {
            p.sendTitle(ChatColors.color(SlimefunPlugin.getLocalization().getMessage(p, "machines.TELEPORTER.teleported")), ChatColors.color("&b100%"), 20, 60, 20);
            p.teleport(destination);

            if (resistance) {
                p.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 600, 20));
                SlimefunPlugin.getLocalization().sendMessage(p, "machines.TELEPORTER.invulnerability");
            }

            destination.getWorld().spawnParticle(Particle.PORTAL, new Location(destination.getWorld(), destination.getX(), destination.getY() + 1, destination.getZ()), progress * 2, 0.2F, 0.8F, 0.2F);
            destination.getWorld().playSound(destination, Sound.BLOCK_BEACON_ACTIVATE, 1F, 1F);
            teleporterUsers.remove(uuid);
        }
        else {
            p.sendTitle(ChatColors.color(SlimefunPlugin.getLocalization().getMessage(p, "machines.TELEPORTER.teleporting")), ChatColors.color("&b" + progress + "%"), 0, 60, 0);

            source.getWorld().spawnParticle(Particle.PORTAL, source, progress * 2, 0.2F, 0.8F, 0.2F);
            source.getWorld().playSound(source, Sound.BLOCK_BEACON_AMBIENT, 1F, 0.6F);

            Slimefun.runSync(() -> updateProgress(uuid, speed, progress + speed, source, destination, resistance), 10L);
        }
    }
    else {
        cancel(uuid, p);
    }
}
 
Example #18
Source File: Implosion.java    From EliteMobs with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onDeath(EntityDeathEvent event) {

    EliteMobEntity eliteMob = EntityTracker.getEliteMobEntity(event.getEntity());

    if (eliteMob == null) return;

    if (!eliteMob.hasPower(this)) return;

    new BukkitRunnable() {
        int counter = 0;

        @Override
        public void run() {

            if (counter < 20)
                for (int i = 0; i < 20; i++)
                    event.getEntity().getLocation().getWorld().spawnParticle(Particle.PORTAL, event.getEntity().getLocation(), 1, 0.1, 0.1, 0.1, 1);

            if (counter > 20 * 3) {
                for (Entity entity : event.getEntity().getWorld().getNearbyEntities(event.getEntity().getLocation(), 10, 10, 10))
                    if (entity instanceof LivingEntity)
                        entity.setVelocity(event.getEntity().getLocation().clone().subtract(entity.getLocation()).toVector().multiply(0.5));
                cancel();
            }

            counter++;
        }
    }.runTaskTimer(MetadataHandler.PLUGIN, 1, 0);

}
 
Example #19
Source File: ParticleSign.java    From DungeonsXL with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean validate() {
    particle = EnumUtil.getEnumIgnoreCase(Particle.class, getLine(1));
    if (particle == null) {
        markAsErroneous("Unknown particle type: " + getLine(1));
        return false;
    }
    return true;
}
 
Example #20
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 #21
Source File: ParticleType.java    From Chimera with MIT License 5 votes vote down vote up
@Override
public Particle parse(StringReader reader) throws CommandSyntaxException {
    var name = reader.readUnquotedString().toLowerCase();
    var particles = PARTICLES.get(name);
    
    if (particles == null) {
        throw EXCEPTION.createWithContext(reader, name);
    }
    
    return particles;
}
 
Example #22
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 #23
Source File: Players.java    From helper with MIT License 4 votes vote down vote up
public static void spawnParticleOffset(Location location, Particle particle, int amount, double offset) {
    Preconditions.checkArgument(amount > 0, "amount > 0");
    location.getWorld().spawnParticle(particle, location, amount, offset, offset, offset);
}
 
Example #24
Source File: ParticleDisplay.java    From XSeries with MIT License 4 votes vote down vote up
/**
 * Builds particle settings from a configuration section.
 *
 * @param location the location for this particle settings.
 * @param config   the config section for the settings.
 * @return a parsed ParticleDisplay.
 * @since 1.0.0
 */
@Nonnull
public static ParticleDisplay fromConfig(@Nullable Location location, @Nonnull ConfigurationSection config) {
    Objects.requireNonNull(config, "Cannot parse ParticleDisplay from a null config section");
    Particle particle = XParticle.getParticle(config.getString("particle"));
    if (particle == null) particle = Particle.FLAME;
    int count = config.getInt("count");
    double extra = config.getDouble("extra");
    double offsetx = 0, offsety = 0, offsetz = 0;

    String offset = config.getString("offset");
    if (offset != null) {
        String[] offsets = StringUtils.split(offset, ',');
        if (offsets.length > 0) {
            offsetx = NumberUtils.toDouble(offsets[0]);
            if (offsets.length > 1) {
                offsety = NumberUtils.toDouble(offsets[1]);
                if (offsets.length > 2) {
                    offsetz = NumberUtils.toDouble(offsets[2]);
                }
            }
        }
    }

    double x = 0, y = 0, z = 0;
    String rotation = config.getString("rotation");
    if (rotation != null) {
        String[] rotations = StringUtils.split(rotation, ',');
        if (rotations.length > 0) {
            x = NumberUtils.toDouble(rotations[0]);
            if (rotations.length > 1) {
                y = NumberUtils.toDouble(rotations[1]);
                if (rotations.length > 2) {
                    z = NumberUtils.toDouble(rotations[2]);
                }
            }
        }
    }

    float[] rgbs = null;
    String color = config.getString("color");
    if (color != null) {
        String[] colors = StringUtils.split(rotation, ',');
        if (colors.length >= 3) rgbs = new float[]
                {NumberUtils.toInt(colors[0]), NumberUtils.toInt(colors[1]), NumberUtils.toInt(colors[2]),
                        (colors.length > 3 ? NumberUtils.toFloat(colors[0]) : 1.0f)};
    }

    Vector rotate = new Vector(x, y, z);
    ParticleDisplay display = new ParticleDisplay(particle, location, count, offsetx, offsety, offsetz, extra);
    display.rotation = rotate;
    display.data = rgbs;
    return display;
}
 
Example #25
Source File: VersionHelper112.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
public boolean existParticle(String particle) {
    return Arrays.stream(Particle.values()).anyMatch((it) -> it.name().equalsIgnoreCase(particle));
}
 
Example #26
Source File: EffectManager.java    From EffectLib with MIT License 4 votes vote down vote up
public void display(Particle particle, Location center, float offsetX, float offsetY, float offsetZ, float speed, int amount, float size, Color color, Material material, byte materialData, double range, List<Player> targetPlayers) {
    getDisplay().display(particle, center, offsetX, offsetY, offsetZ, speed, amount, size, color, material, materialData, range, targetPlayers);
}
 
Example #27
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 #28
Source File: CraftAreaEffectCloud.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setParticle(Particle particle) {
    getHandle().setParticle(CraftParticle.toNMS(particle));
}
 
Example #29
Source File: ZombieKing.java    From EliteMobs with GNU General Public License v3.0 4 votes vote down vote up
private void spawnUnholySmitePhaseOneParticle(Vector directionVector, LivingEntity livingEntity, Particle particle) {

        for (int i = 0; i < 10; i++) {

            double offsetVelocity = ThreadLocalRandom.current().nextDouble() * 2;

            double offsetLocationX = (ThreadLocalRandom.current().nextDouble() - 0.5) * 0.5 + livingEntity.getLocation().getX();
            double offsetLocationZ = (ThreadLocalRandom.current().nextDouble() - 0.5) * 0.5 + livingEntity.getLocation().getZ();

            Location offsetLocation = new Location(livingEntity.getWorld(), offsetLocationX, livingEntity.getLocation().getY(), offsetLocationZ);

            livingEntity.getLocation().getWorld().spawnParticle(particle, offsetLocation, 0, directionVector.getX(), directionVector.getY(), directionVector.getZ(), offsetVelocity);

        }

    }
 
Example #30
Source File: ParticleCommands.java    From NyaaUtils with MIT License 4 votes vote down vote up
@SubCommand(value = "add", permission = "nu.particles.editor")
public void commandAdd(CommandSender sender, Arguments args) {
    int id = args.nextInt();
    ParticleSet set = plugin.cfg.particleConfig.particleSets.get(id);
    if (set == null) {
        throw new BadCommandException("user.particle.not_exist", id);
    }
    checkEnabledParticleType(set.getType());
    if (!isAdminOrAuthor(asPlayer(sender), set)) {
        throw new BadCommandException("user.particle.no_permission");
    }
    ParticleLimit limit = plugin.cfg.particlesLimits.get(set.getType());
    Particle particle = args.nextEnum(Particle.class);
    if (!plugin.cfg.particles_enabled.contains(particle.name())) {
        throw new BadCommandException("user.particle.not_enabled", particle.name());
    }
    if (set.contents.size() >= limit.getSet()) {
        throw new BadCommandException("user.particle.add.limit");
    }
    ParticleData data = new ParticleData();
    data.setParticle(particle);
    data.setCount(args.nextInt());
    data.setFreq(args.nextInt());
    data.setOffsetX(args.nextDouble());
    data.setOffsetY(args.nextDouble());
    data.setOffsetZ(args.nextDouble());
    data.setExtra(args.nextDouble());
    if (!particle.getDataType().equals(Void.class)) {
        if (particle.getDataType().equals(Particle.DustOptions.class)) {
            if (args.length() < 12) {
                msg(sender, "user.particle.add.dust_options", I18n.format("manual.particle.add.usage"));
                return;
            }
            data.dustOptions_color = args.nextInt();
            data.dustOptions_size = (float) args.nextDouble();
        } else {
            if (args.length() < 11) {
                msg(sender, "user.particle.add.need_material", I18n.format("manual.particle.add.usage"));
                return;
            }
            data.setMaterial(args.nextEnum(Material.class));
            if ((particle.getDataType().equals(ItemStack.class) && !data.getMaterial().isItem()) ||
                    (particle.getDataType().equals(BlockData.class) && !data.getMaterial().isBlock())) {
                msg(sender, "user.particle.invalid_material");
                return;
            }
        }
    }
    set.contents.add(data);
    plugin.cfg.save();
    printParticleSetInfo(sender, set);
}