use of org.bukkit.FireworkEffect.Type in project Glowstone by GlowstoneMC.
the class GlowChargeMatcher method getResult.
@Override
public ItemStack getResult(ItemStack[] matrix) {
boolean hasGunpowder = false;
boolean trail = false;
boolean twinkle = false;
List<Color> colors = new ArrayList<>();
Type type = Type.BALL;
for (ItemStack item : matrix) {
if (item == null)
continue;
switch(item.getType()) {
case SULPHUR:
// Only 1 gunpowder allowed
if (hasGunpowder)
return null;
hasGunpowder = true;
break;
case INK_SACK:
Dye dye = (Dye) item.getData();
colors.add(dye.getColor().getFireworkColor());
break;
case DIAMOND:
// Only 1 diamond allowed
if (trail)
return null;
trail = true;
break;
case GLOWSTONE_DUST:
// Only 1 dust allowed
if (twinkle)
return null;
twinkle = true;
break;
case FIREBALL:
if (type != Type.BALL)
return null;
type = Type.BALL_LARGE;
break;
case GOLD_NUGGET:
if (type != Type.BALL)
return null;
type = Type.STAR;
break;
case FEATHER:
if (type != Type.BALL)
return null;
type = Type.BURST;
break;
case SKULL_ITEM:
if (type != Type.BALL)
return null;
type = Type.CREEPER;
break;
default:
// Non firework item on matrix
return null;
}
}
// Not enough ingredients
if (!hasGunpowder || colors.isEmpty())
return null;
FireworkEffect effect = FireworkEffect.builder().withColor(colors).trail(trail).flicker(twinkle).with(type).build();
ItemStack charge = new ItemStack(Material.FIREWORK_CHARGE, 1);
FireworkEffectMeta meta = (FireworkEffectMeta) charge.getItemMeta();
meta.setEffect(effect);
charge.setItemMeta(meta);
return charge;
}
use of org.bukkit.FireworkEffect.Type in project Minigames by AddstarMC.
the class PlayerData method partyMode.
public void partyMode(MinigamePlayer player) {
if (onPartyMode()) {
Location loc = player.getPlayer().getLocation();
Firework firework = (Firework) player.getPlayer().getWorld().spawnEntity(loc, EntityType.FIREWORK);
FireworkMeta fwm = firework.getFireworkMeta();
Random chance = new Random();
Type type = Type.BALL_LARGE;
if (chance.nextInt(100) < 50) {
type = Type.BALL;
}
Color col = Color.fromRGB(chance.nextInt(255), chance.nextInt(255), chance.nextInt(255));
FireworkEffect effect = FireworkEffect.builder().with(type).withColor(col).flicker(chance.nextBoolean()).trail(chance.nextBoolean()).build();
fwm.addEffect(effect);
fwm.setPower(1);
firework.setFireworkMeta(fwm);
}
}
use of org.bukkit.FireworkEffect.Type in project Glowstone by GlowstoneMC.
the class GlowMetaFireworkEffect method toEffect.
static FireworkEffect toEffect(CompoundTag explosion) {
boolean flicker = false;
boolean trail = false;
Type type;
List<Color> colors = new ArrayList<>();
List<Color> fadeColors = new ArrayList<>();
int[] colorInts = explosion.getIntArray("Colors");
for (int color : colorInts) {
colors.add(Color.fromRGB(color));
}
type = Type.values()[explosion.getByte("Type")];
if (explosion.isByte("Flicker"))
flicker = explosion.getBool("Flicker");
if (explosion.isByte("Trail"))
trail = explosion.getBool("Trail");
if (explosion.isIntArray("FadeColors")) {
int[] fadeInts = explosion.getIntArray("FadeColors");
for (int fade : fadeInts) {
fadeColors.add(Color.fromRGB(fade));
}
}
return FireworkEffect.builder().flicker(flicker).trail(trail).with(type).withColor(colors).withFade(fadeColors).build();
}
Aggregations