Example #1
0
 /** @return the type */
 public Type getType() {
   if (type == null) {
     return Type.values()[r.nextInt(Type.values().length)];
   } else {
     return type;
   }
 }
 public static void shootRandomFirework(Location loc, int height) {
   Firework f = (Firework) loc.getWorld().spawnEntity(loc, EntityType.FIREWORK);
   FireworkMeta fm = f.getFireworkMeta();
   fm.setPower(height);
   int effectAmount = random.nextInt(3) + 1;
   for (int i = 0; i < effectAmount; i++) {
     Builder b = FireworkEffect.builder();
     int colorAmount = random.nextInt(3) + 1;
     for (int ii = 0; ii < colorAmount; ii++) {
       b.withColor(Color.fromBGR(random.nextInt(256), random.nextInt(256), random.nextInt(256)));
     }
     b.with(Type.values()[random.nextInt(Type.values().length)]);
     b.flicker(random.nextInt(2) == 0 ? false : true);
     b.trail(random.nextInt(2) == 0 ? false : true);
     fm.addEffect(b.build());
   }
   f.setFireworkMeta(fm);
 }
Example #3
0
  /**
   * @param red
   * @param green
   * @param blue
   * @param type
   */
  public ConfigFirework(String type, boolean flicker, int red, int green, int blue) {
    super(red, green, blue);

    this.flicker = flicker;
    try {
      this.type = Type.valueOf(type);
    } catch (Exception e) {
    }

    if (type == null && r == null) {
      r = new Random();
    }
  }
	@Override
	public boolean setOptions(final String[] options) {
		// target;power;type;R;G;B

		if (options.length < 6)
			return false;

		target = options[0];
		power = Integer.parseInt(options[1]);
		type = Type.valueOf(options[2].toUpperCase().replace(" ", "_"));
		colour = Color.fromRGB(Integer.parseInt(options[3]), Integer.parseInt(options[4]),
				Integer.parseInt(options[5]));
		// Colour is RGB code

		return target != null;
	}