2013-01-17 02:39:09 +00:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
|
|
|
import static com.earth2me.essentials.I18n._;
|
2013-01-19 23:35:59 +00:00
|
|
|
import com.earth2me.essentials.MetaItemStack;
|
|
|
|
import com.earth2me.essentials.User;
|
2013-01-27 15:26:46 +00:00
|
|
|
import com.earth2me.essentials.Util;
|
2013-01-17 02:39:09 +00:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
import org.bukkit.DyeColor;
|
|
|
|
import org.bukkit.FireworkEffect;
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.Server;
|
2013-01-17 02:40:29 +00:00
|
|
|
import org.bukkit.entity.EntityType;
|
|
|
|
import org.bukkit.entity.Firework;
|
2013-01-17 02:39:09 +00:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
import org.bukkit.inventory.meta.FireworkMeta;
|
2013-01-27 15:26:46 +00:00
|
|
|
import org.bukkit.util.Vector;
|
2013-01-17 02:39:09 +00:00
|
|
|
|
2013-01-27 15:26:46 +00:00
|
|
|
//This command has quite a complicated syntax, in theory it has 4 seperate syntaxes which are all variable:
|
|
|
|
//
|
|
|
|
//1: /firework clear - This clears all of the effects on a firework stack
|
|
|
|
//
|
|
|
|
//2: /firework power <int> - This changes the base power of a firework
|
|
|
|
//
|
|
|
|
//3: /firework fire - This 'fires' a copy of the firework held.
|
|
|
|
//3: /firework fire <int> - This 'fires' a number of copies of the firework held.
|
|
|
|
//3: /firework fire <other> - This 'fires' a copy of the firework held, in the direction you are looking, #easteregg
|
|
|
|
//
|
|
|
|
//4: /firework [meta] - This will add an effect to the firework stack held
|
|
|
|
//4: /firework color:<color> - The minimum you need to set an effect is 'color'
|
|
|
|
//4: Full Syntax: color:<color[,color,..]> [fade:<color[,color,..]>] [shape:<shape>] [effect:<effect[,effect]>]
|
|
|
|
//4: Possible Shapes: star, ball, large, creeper, burst
|
|
|
|
//4: Possible Effects trail, twinkle
|
2013-01-17 02:39:09 +00:00
|
|
|
|
|
|
|
public class Commandfirework extends EssentialsCommand
|
|
|
|
{
|
|
|
|
private final transient Pattern splitPattern = Pattern.compile("[:+',;.]");
|
|
|
|
private final static Map<String, DyeColor> colorMap = new HashMap<String, DyeColor>();
|
|
|
|
private final static Map<String, FireworkEffect.Type> fireworkShape = new HashMap<String, FireworkEffect.Type>();
|
|
|
|
|
|
|
|
static
|
|
|
|
{
|
|
|
|
for (DyeColor color : DyeColor.values())
|
|
|
|
{
|
|
|
|
colorMap.put(color.name(), color);
|
|
|
|
}
|
|
|
|
for (FireworkEffect.Type type : FireworkEffect.Type.values())
|
|
|
|
{
|
|
|
|
fireworkShape.put(type.name(), type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Commandfirework()
|
|
|
|
{
|
|
|
|
super("firework");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
|
|
|
|
{
|
2013-01-21 19:17:14 +00:00
|
|
|
final ItemStack stack = user.getItemInHand();
|
|
|
|
if (stack.getType() == Material.FIREWORK)
|
2013-01-17 02:39:09 +00:00
|
|
|
{
|
2013-01-21 19:17:14 +00:00
|
|
|
if (args.length > 0)
|
2013-01-17 02:39:09 +00:00
|
|
|
{
|
2013-01-21 19:17:14 +00:00
|
|
|
if (args[0].equalsIgnoreCase("clear"))
|
2013-01-17 02:39:09 +00:00
|
|
|
{
|
2013-01-21 19:17:14 +00:00
|
|
|
FireworkMeta fmeta = (FireworkMeta)stack.getItemMeta();
|
|
|
|
fmeta.clearEffects();
|
|
|
|
stack.setItemMeta(fmeta);
|
|
|
|
user.sendMessage(_("fireworkEffectsCleared"));
|
|
|
|
}
|
|
|
|
else if (args.length > 1 && (args[0].equalsIgnoreCase("power") || (args[0].equalsIgnoreCase("p"))))
|
|
|
|
{
|
|
|
|
FireworkMeta fmeta = (FireworkMeta)stack.getItemMeta();
|
|
|
|
try
|
2013-01-17 02:39:09 +00:00
|
|
|
{
|
2013-01-21 19:17:14 +00:00
|
|
|
int power = Integer.parseInt(args[1]);
|
|
|
|
fmeta.setPower(power > 3 ? 4 : power);
|
2013-01-17 02:39:09 +00:00
|
|
|
}
|
2013-01-21 19:17:14 +00:00
|
|
|
catch (NumberFormatException e)
|
|
|
|
{
|
|
|
|
throw new Exception(_("invalidFireworkFormat", args[1], args[0]));
|
|
|
|
}
|
|
|
|
stack.setItemMeta(fmeta);
|
|
|
|
}
|
|
|
|
else if ((args[0].equalsIgnoreCase("fire") || (args[0].equalsIgnoreCase("p")))
|
|
|
|
&& user.isAuthorized("essentials.firework.fire"))
|
|
|
|
{
|
2013-01-27 15:26:46 +00:00
|
|
|
int amount = 1;
|
|
|
|
boolean direction = false;
|
|
|
|
if (Util.isInt(args[1]))
|
2013-01-17 02:39:09 +00:00
|
|
|
{
|
2013-01-21 19:17:14 +00:00
|
|
|
final int serverLimit = ess.getSettings().getSpawnMobLimit();
|
|
|
|
amount = Integer.parseInt(args[1]);
|
|
|
|
if (amount > serverLimit)
|
2013-01-17 02:39:09 +00:00
|
|
|
{
|
2013-01-21 19:17:14 +00:00
|
|
|
amount = serverLimit;
|
|
|
|
user.sendMessage(_("mobSpawnLimit"));
|
2013-01-17 02:39:09 +00:00
|
|
|
}
|
2013-01-21 19:17:14 +00:00
|
|
|
}
|
2013-01-27 15:26:46 +00:00
|
|
|
else
|
2013-01-21 19:17:14 +00:00
|
|
|
{
|
2013-01-27 15:26:46 +00:00
|
|
|
direction = true;
|
2013-01-21 19:17:14 +00:00
|
|
|
}
|
|
|
|
for (int i = 0; i < amount; i++)
|
|
|
|
{
|
|
|
|
Firework firework = (Firework)user.getWorld().spawnEntity(user.getLocation(), EntityType.FIREWORK);
|
|
|
|
FireworkMeta fmeta = (FireworkMeta)stack.getItemMeta();
|
2013-01-27 15:26:46 +00:00
|
|
|
if (direction)
|
|
|
|
{
|
|
|
|
final Vector vector = user.getEyeLocation().getDirection().multiply(0.075);
|
|
|
|
if (fmeta.getPower() > 1)
|
|
|
|
{
|
|
|
|
fmeta.setPower(1);
|
|
|
|
}
|
|
|
|
firework.setVelocity(vector);
|
|
|
|
}
|
2013-01-21 19:17:14 +00:00
|
|
|
firework.setFireworkMeta(fmeta);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
final MetaItemStack mStack = new MetaItemStack(stack);
|
|
|
|
for (String arg : args)
|
|
|
|
{
|
|
|
|
final String[] split = splitPattern.split(arg, 2);
|
|
|
|
mStack.addFireworkMeta(user, true, arg, ess);
|
|
|
|
}
|
2013-01-19 23:35:59 +00:00
|
|
|
|
2013-01-21 19:17:14 +00:00
|
|
|
if (mStack.isValidFirework())
|
|
|
|
{
|
|
|
|
FireworkMeta fmeta = (FireworkMeta)mStack.getItemStack().getItemMeta();
|
|
|
|
FireworkEffect effect = mStack.getFireworkBuilder().build();
|
|
|
|
fmeta.addEffect(effect);
|
|
|
|
stack.setItemMeta(fmeta);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
user.sendMessage(_("fireworkSyntax"));
|
|
|
|
throw new Exception(_("fireworkColor"));
|
2013-01-17 02:39:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-01-21 19:17:14 +00:00
|
|
|
throw new NotEnoughArgumentsException();
|
2013-01-17 02:39:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-01-21 19:17:14 +00:00
|
|
|
throw new Exception(_("holdFirework"));
|
2013-01-17 02:39:09 +00:00
|
|
|
}
|
|
|
|
}
|
2013-01-17 02:40:29 +00:00
|
|
|
}
|