use of org.bukkit.FireworkEffect in project Village_Defense by Plajer.
the class Util method spawnRandomFirework.
public static void spawnRandomFirework(Location location) {
Firework fw = (Firework) location.getWorld().spawnEntity(location, EntityType.FIREWORK);
FireworkMeta fwm = fw.getFireworkMeta();
// Our random generator
Random r = new Random();
// Get the type
int rt = r.nextInt(4) + 1;
FireworkEffect.Type type = FireworkEffect.Type.BALL;
if (rt == 1)
type = FireworkEffect.Type.BALL;
if (rt == 2)
type = FireworkEffect.Type.BALL_LARGE;
if (rt == 3)
type = FireworkEffect.Type.BURST;
if (rt == 4)
type = FireworkEffect.Type.CREEPER;
if (rt == 5)
type = FireworkEffect.Type.STAR;
// Get our random colours
int r1i = r.nextInt(250) + 1;
int r2i = r.nextInt(250) + 1;
Color c1 = Color.fromBGR(r1i);
Color c2 = Color.fromBGR(r2i);
// Create our effect with this
FireworkEffect effect = FireworkEffect.builder().flicker(r.nextBoolean()).withColor(c1).withFade(c2).with(type).trail(r.nextBoolean()).build();
// Then apply the effect to the meta
fwm.addEffect(effect);
// Generate some random power and set it
int rp = r.nextInt(2) + 1;
fwm.setPower(rp);
fw.setFireworkMeta(fwm);
}
use of org.bukkit.FireworkEffect in project Essentials by EssentialsX.
the class Commandfirework method run.
@Override
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
final ItemStack stack = user.getBase().getItemInHand();
if (stack.getType() == Material.FIREWORK) {
if (args.length > 0) {
if (args[0].equalsIgnoreCase("clear")) {
FireworkMeta fmeta = (FireworkMeta) stack.getItemMeta();
fmeta.clearEffects();
stack.setItemMeta(fmeta);
user.sendMessage(tl("fireworkEffectsCleared"));
} else if (args.length > 1 && (args[0].equalsIgnoreCase("power") || (args[0].equalsIgnoreCase("p")))) {
FireworkMeta fmeta = (FireworkMeta) stack.getItemMeta();
try {
int power = Integer.parseInt(args[1]);
fmeta.setPower(power > 3 ? 4 : power);
} catch (NumberFormatException e) {
throw new Exception(tl("invalidFireworkFormat", args[1], args[0]));
}
stack.setItemMeta(fmeta);
} else if ((args[0].equalsIgnoreCase("fire") || (args[0].equalsIgnoreCase("f"))) && user.isAuthorized("essentials.firework.fire")) {
int amount = 1;
boolean direction = false;
if (args.length > 1) {
if (NumberUtil.isInt(args[1])) {
final int serverLimit = ess.getSettings().getSpawnMobLimit();
amount = Integer.parseInt(args[1]);
if (amount > serverLimit) {
amount = serverLimit;
user.sendMessage(tl("mobSpawnLimit"));
}
} else {
direction = true;
}
}
for (int i = 0; i < amount; i++) {
Firework firework = (Firework) user.getWorld().spawnEntity(user.getLocation(), EntityType.FIREWORK);
FireworkMeta fmeta = (FireworkMeta) stack.getItemMeta();
if (direction) {
final Vector vector = user.getBase().getEyeLocation().getDirection().multiply(0.070);
if (fmeta.getPower() > 1) {
fmeta.setPower(1);
}
firework.setVelocity(vector);
}
firework.setFireworkMeta(fmeta);
}
} else {
final MetaItemStack mStack = new MetaItemStack(stack);
for (String arg : args) {
try {
mStack.addFireworkMeta(user.getSource(), true, arg, ess);
} catch (Exception e) {
user.sendMessage(tl("fireworkSyntax"));
throw e;
}
}
if (mStack.isValidFirework()) {
FireworkMeta fmeta = (FireworkMeta) mStack.getItemStack().getItemMeta();
FireworkEffect effect = mStack.getFireworkBuilder().build();
if (fmeta.getEffects().size() > 0 && !user.isAuthorized("essentials.firework.multiple")) {
throw new Exception(tl("multipleCharges"));
}
fmeta.addEffect(effect);
stack.setItemMeta(fmeta);
} else {
user.sendMessage(tl("fireworkSyntax"));
throw new Exception(tl("fireworkColor"));
}
}
} else {
throw new NotEnoughArgumentsException();
}
} else {
throw new Exception(tl("holdFirework"));
}
}
use of org.bukkit.FireworkEffect in project Essentials by EssentialsX.
the class MetaItemStack method addFireworkMeta.
public void addFireworkMeta(final CommandSource sender, final boolean allowShortName, final String string, final IEssentials ess) throws Exception {
if (stack.getType() == Material.FIREWORK) {
final String[] split = splitPattern.split(string, 2);
if (split.length < 2) {
return;
}
if (split[0].equalsIgnoreCase("color") || split[0].equalsIgnoreCase("colour") || (allowShortName && split[0].equalsIgnoreCase("c"))) {
if (validFirework) {
if (!hasMetaPermission(sender, "firework", true, true, ess)) {
throw new Exception(tl("noMetaFirework"));
}
FireworkEffect effect = builder.build();
FireworkMeta fmeta = (FireworkMeta) stack.getItemMeta();
fmeta.addEffect(effect);
if (fmeta.getEffects().size() > 1 && !hasMetaPermission(sender, "firework-multiple", true, true, ess)) {
throw new Exception(tl("multipleCharges"));
}
stack.setItemMeta(fmeta);
builder = FireworkEffect.builder();
}
List<Color> primaryColors = new ArrayList<Color>();
String[] colors = split[1].split(",");
for (String color : colors) {
if (colorMap.containsKey(color.toUpperCase())) {
validFirework = true;
primaryColors.add(colorMap.get(color.toUpperCase()).getFireworkColor());
} else {
throw new Exception(tl("invalidFireworkFormat", split[1], split[0]));
}
}
builder.withColor(primaryColors);
} else if (split[0].equalsIgnoreCase("shape") || split[0].equalsIgnoreCase("type") || (allowShortName && (split[0].equalsIgnoreCase("s") || split[0].equalsIgnoreCase("t")))) {
FireworkEffect.Type finalEffect = null;
split[1] = (split[1].equalsIgnoreCase("large") ? "BALL_LARGE" : split[1]);
if (fireworkShape.containsKey(split[1].toUpperCase())) {
finalEffect = fireworkShape.get(split[1].toUpperCase());
} else {
throw new Exception(tl("invalidFireworkFormat", split[1], split[0]));
}
if (finalEffect != null) {
builder.with(finalEffect);
}
} else if (split[0].equalsIgnoreCase("fade") || (allowShortName && split[0].equalsIgnoreCase("f"))) {
List<Color> fadeColors = new ArrayList<Color>();
String[] colors = split[1].split(",");
for (String color : colors) {
if (colorMap.containsKey(color.toUpperCase())) {
fadeColors.add(colorMap.get(color.toUpperCase()).getFireworkColor());
} else {
throw new Exception(tl("invalidFireworkFormat", split[1], split[0]));
}
}
if (!fadeColors.isEmpty()) {
builder.withFade(fadeColors);
}
} else if (split[0].equalsIgnoreCase("effect") || (allowShortName && split[0].equalsIgnoreCase("e"))) {
String[] effects = split[1].split(",");
for (String effect : effects) {
if (effect.equalsIgnoreCase("twinkle")) {
builder.flicker(true);
} else if (effect.equalsIgnoreCase("trail")) {
builder.trail(true);
} else {
throw new Exception(tl("invalidFireworkFormat", split[1], split[0]));
}
}
}
}
}
use of org.bukkit.FireworkEffect in project Essentials by EssentialsX.
the class MetaItemStack method parseStringMeta.
public void parseStringMeta(final CommandSource sender, final boolean allowUnsafe, String[] string, int fromArg, final IEssentials ess) throws Exception {
if (string[fromArg].startsWith("{") && hasMetaPermission(sender, "vanilla", false, true, ess)) {
try {
stack = ess.getServer().getUnsafe().modifyItemStack(stack, Joiner.on(' ').join(Arrays.asList(string).subList(fromArg, string.length)));
} catch (NullPointerException npe) {
if (ess.getSettings().isDebug()) {
ess.getLogger().log(Level.INFO, "Itemstack is invalid", npe);
}
} catch (NoSuchMethodError nsme) {
throw new Exception(tl("noMetaJson"), nsme);
} catch (Throwable throwable) {
throw new Exception(throwable.getMessage(), throwable);
}
} else {
for (int i = fromArg; i < string.length; i++) {
addStringMeta(sender, allowUnsafe, string[i], ess);
}
if (validFirework) {
if (!hasMetaPermission(sender, "firework", true, true, ess)) {
throw new Exception(tl("noMetaFirework"));
}
FireworkEffect effect = builder.build();
FireworkMeta fmeta = (FireworkMeta) stack.getItemMeta();
fmeta.addEffect(effect);
if (fmeta.getEffects().size() > 1 && !hasMetaPermission(sender, "firework-multiple", true, true, ess)) {
throw new Exception(tl("multipleCharges"));
}
stack.setItemMeta(fmeta);
}
}
}
use of org.bukkit.FireworkEffect in project Prism-Bukkit by prism.
the class ItemStackAction method applyFireWorksMetaToActionData.
private void applyFireWorksMetaToActionData(ItemMeta meta) {
final FireworkEffectMeta fireworkMeta = (FireworkEffectMeta) meta;
if (fireworkMeta.hasEffect()) {
final FireworkEffect effect = fireworkMeta.getEffect();
if (effect != null) {
if (!effect.getColors().isEmpty()) {
final int[] effectColors = new int[effect.getColors().size()];
int i = 0;
for (final Color effectColor : effect.getColors()) {
effectColors[i] = effectColor.asRGB();
i++;
}
actionData.effectColors = effectColors;
}
if (!effect.getFadeColors().isEmpty()) {
final int[] fadeColors = new int[effect.getColors().size()];
final int i = 0;
for (final Color fadeColor : effect.getFadeColors()) {
fadeColors[i] = fadeColor.asRGB();
}
actionData.fadeColors = fadeColors;
}
if (effect.hasFlicker()) {
actionData.hasFlicker = true;
}
if (effect.hasTrail()) {
actionData.hasTrail = true;
}
}
}
}
Aggregations