Start work on firework effect - syntax in flux

This commit is contained in:
KHobbits 2013-01-14 23:11:19 +00:00
parent 4807fb39e5
commit fdc262a205
2 changed files with 40 additions and 2 deletions

View File

@ -7,6 +7,9 @@ import java.util.List;
import java.util.Locale;
import java.util.regex.Pattern;
import org.bukkit.Color;
import org.bukkit.DyeColor;
import org.bukkit.FireworkEffect;
import org.bukkit.FireworkEffect.Builder;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
@ -31,6 +34,7 @@ public class MetaItemStack
//TODO: TL this
public void addStringMeta(final User user, final boolean allowUnsafe, final String string, final IEssentials ess) throws Exception
{
ess.getLogger().info("Adding meta to " + stack.getType().name());
final String[] split = splitPattern.split(string, 2);
if (split.length < 1)
{
@ -94,13 +98,47 @@ public class MetaItemStack
meta.setTitle(title);
stack.setItemMeta(meta);
}
else if (split.length > 1 && split[0].equalsIgnoreCase("power") && stack.getType() == Material.FIREWORK)
{
final int power = Integer.parseInt(split[1]);
final FireworkMeta meta = (FireworkMeta)stack.getItemMeta();
meta.setPower(power);
stack.setItemMeta(meta);
}
else if (split.length > 1 && split[0].equalsIgnoreCase("effect") && stack.getType() == Material.FIREWORK)
{
//TODO: Add validation messages
final FireworkMeta meta = (FireworkMeta)stack.getItemMeta();
Builder builder = FireworkEffect.builder();
String[] effectData = split[1].toUpperCase(Locale.ENGLISH).split("\\|");
builder.with(FireworkEffect.Type.valueOf(effectData[0]));
String[] primaryColorStrings = effectData[1].split(",");
List<Color> primaryColors = new ArrayList<Color>();
for (String primaryColorString : primaryColorStrings) {
primaryColors.add(DyeColor.valueOf(primaryColorString).getFireworkColor());
}
//if (effectData.length > 2) {
//}
builder.withColor(primaryColors);
final FireworkEffect effect = builder.build();
meta.addEffect(effect);
stack.setItemMeta(meta);
}
else if (split.length > 1 && (split[0].equalsIgnoreCase("color") || split[0].equalsIgnoreCase("colour"))
&& (stack.getType() == Material.LEATHER_BOOTS
|| stack.getType() == Material.LEATHER_CHESTPLATE
|| stack.getType() == Material.LEATHER_HELMET
|| stack.getType() == Material.LEATHER_LEGGINGS))
{
final String[] color = split[1].split("\\|");
final String[] color = split[1].split(",");
if (color.length == 3)
{
final int red = Util.isInt(color[0]) ? Integer.parseInt(color[0]) : 0;

View File

@ -222,7 +222,7 @@ kits:
items:
- 278 1 efficiency:1 durability:1 fortune:1 name:&4Gigadrill lore:The_drill_that_&npierces|the_heavens
- 277 1 digspeed:3 name:Dwarf lore:Diggy|Diggy|Hole
- 298 1 color:255|255|255 name:Top_Hat lore:Good_day,_Good_day
- 298 1 color:255,255,255 name:Top_Hat lore:Good_day,_Good_day
- 279:780 1
notch:
delay: 6000