From 6d7881f8769227fb9f98f0087c79230bcd787458 Mon Sep 17 00:00:00 2001 From: GunfighterJ Date: Wed, 16 Jan 2013 20:36:33 -0600 Subject: Added /firework command --- Essentials/src/messages.properties | 5 ++++- Essentials/src/messages_cs.properties | 6 +++++- Essentials/src/messages_da.properties | 5 ++++- Essentials/src/messages_de.properties | 5 ++++- Essentials/src/messages_en.properties | 5 ++++- Essentials/src/messages_es.properties | 5 ++++- Essentials/src/messages_fi.properties | 5 ++++- Essentials/src/messages_fr.properties | 5 ++++- Essentials/src/messages_it.properties | 5 ++++- Essentials/src/messages_nl.properties | 5 ++++- Essentials/src/messages_pl.properties | 5 ++++- Essentials/src/messages_pt.properties | 5 ++++- Essentials/src/messages_se.properties | 5 ++++- Essentials/src/plugin.yml | 6 +++++- 14 files changed, 58 insertions(+), 14 deletions(-) diff --git a/Essentials/src/messages.properties b/Essentials/src/messages.properties index b5bdfc340..ceca9beb4 100644 --- a/Essentials/src/messages.properties +++ b/Essentials/src/messages.properties @@ -485,4 +485,7 @@ denyChangeAuthor=\u00a74You cannot change the author of this book denyChangeTitle=\u00a74You cannot change the title of this book denyBookEdit=\u00a74You cannot unlock this book bookLocked=\u00a7cThis book is now locked -holdBook=\u00a74You are not holding a writable book \ No newline at end of file +holdBook=\u00a74You are not holding a writable book +fireworkColor=\u00a74You must apply a color to the firework to add an effect +holdFirework=\u00a74You must be holding a firework to add effects +invalidFireworkFormat=\u00a76The option \u00a74{0} \u00a76is not a valid value for \u00a74{1} diff --git a/Essentials/src/messages_cs.properties b/Essentials/src/messages_cs.properties index 56772abc7..5178598e8 100644 --- a/Essentials/src/messages_cs.properties +++ b/Essentials/src/messages_cs.properties @@ -488,4 +488,8 @@ denyChangeAuthor=\u00a74You cannot change the author of this book denyChangeTitle=\u00a74You cannot change the title of this book denyBookEdit=\u00a74You cannot unlock this book bookLocked=\u00a7cThis book is now locked -holdBook=\u00a74You are not holding a writable book \ No newline at end of file +holdBook=\u00a74You are not holding a writable book +fireworkColor=\u00a74You must apply a color to the firework to add an effect +holdFirework=\u00a74You must be holding a firework to add effects +invalidFireworkFormat=\u00a76The option \u00a74{0} \u00a76is not a valid value for \u00a74{1} + diff --git a/Essentials/src/messages_da.properties b/Essentials/src/messages_da.properties index 3e13c65f5..106bea42a 100644 --- a/Essentials/src/messages_da.properties +++ b/Essentials/src/messages_da.properties @@ -485,4 +485,7 @@ denyChangeAuthor=\u00a74You cannot change the author of this book denyChangeTitle=\u00a74You cannot change the title of this book denyBookEdit=\u00a74You cannot unlock this book bookLocked=\u00a7cThis book is now locked -holdBook=\u00a74You are not holding a writable book \ No newline at end of file +holdBook=\u00a74You are not holding a writable book +fireworkColor=\u00a74You must apply a color to the firework to add an effect +holdFirework=\u00a74You must be holding a firework to add effects +invalidFireworkFormat=\u00a76The option \u00a74{0} \u00a76is not a valid value for \u00a74{1} diff --git a/Essentials/src/messages_de.properties b/Essentials/src/messages_de.properties index 568b7f760..6f02ec613 100644 --- a/Essentials/src/messages_de.properties +++ b/Essentials/src/messages_de.properties @@ -485,4 +485,7 @@ denyChangeAuthor=\u00a74You cannot change the author of this book denyChangeTitle=\u00a74You cannot change the title of this book denyBookEdit=\u00a74You cannot unlock this book bookLocked=\u00a7cThis book is now locked -holdBook=\u00a74You are not holding a writable book \ No newline at end of file +holdBook=\u00a74You are not holding a writable book +fireworkColor=\u00a74You must apply a color to the firework to add an effect +holdFirework=\u00a74You must be holding a firework to add effects +invalidFireworkFormat=\u00a76The option \u00a74{0} \u00a76is not a valid value for \u00a74{1} diff --git a/Essentials/src/messages_en.properties b/Essentials/src/messages_en.properties index b5bdfc340..ceca9beb4 100644 --- a/Essentials/src/messages_en.properties +++ b/Essentials/src/messages_en.properties @@ -485,4 +485,7 @@ denyChangeAuthor=\u00a74You cannot change the author of this book denyChangeTitle=\u00a74You cannot change the title of this book denyBookEdit=\u00a74You cannot unlock this book bookLocked=\u00a7cThis book is now locked -holdBook=\u00a74You are not holding a writable book \ No newline at end of file +holdBook=\u00a74You are not holding a writable book +fireworkColor=\u00a74You must apply a color to the firework to add an effect +holdFirework=\u00a74You must be holding a firework to add effects +invalidFireworkFormat=\u00a76The option \u00a74{0} \u00a76is not a valid value for \u00a74{1} diff --git a/Essentials/src/messages_es.properties b/Essentials/src/messages_es.properties index 983bbb70b..25ae737ed 100644 --- a/Essentials/src/messages_es.properties +++ b/Essentials/src/messages_es.properties @@ -485,4 +485,7 @@ denyChangeAuthor=\u00a74You cannot change the author of this book denyChangeTitle=\u00a74You cannot change the title of this book denyBookEdit=\u00a74You cannot unlock this book bookLocked=\u00a7cThis book is now locked -holdBook=\u00a74You are not holding a writable book \ No newline at end of file +holdBook=\u00a74You are not holding a writable book +fireworkColor=\u00a74You must apply a color to the firework to add an effect +holdFirework=\u00a74You must be holding a firework to add effects +invalidFireworkFormat=\u00a76The option \u00a74{0} \u00a76is not a valid value for \u00a74{1} diff --git a/Essentials/src/messages_fi.properties b/Essentials/src/messages_fi.properties index f64ad8cf2..6a18d49a1 100644 --- a/Essentials/src/messages_fi.properties +++ b/Essentials/src/messages_fi.properties @@ -485,4 +485,7 @@ denyChangeAuthor=\u00a74You cannot change the author of this book denyChangeTitle=\u00a74You cannot change the title of this book denyBookEdit=\u00a74You cannot unlock this book bookLocked=\u00a7cThis book is now locked -holdBook=\u00a74You are not holding a writable book \ No newline at end of file +holdBook=\u00a74You are not holding a writable book +fireworkColor=\u00a74You must apply a color to the firework to add an effect +holdFirework=\u00a74You must be holding a firework to add effects +invalidFireworkFormat=\u00a76The option \u00a74{0} \u00a76is not a valid value for \u00a74{1} diff --git a/Essentials/src/messages_fr.properties b/Essentials/src/messages_fr.properties index 8d4116697..40deed6bd 100644 --- a/Essentials/src/messages_fr.properties +++ b/Essentials/src/messages_fr.properties @@ -485,4 +485,7 @@ denyChangeAuthor=\u00a74You cannot change the author of this book denyChangeTitle=\u00a74You cannot change the title of this book denyBookEdit=\u00a74You cannot unlock this book bookLocked=\u00a7cThis book is now locked -holdBook=\u00a74You are not holding a writable book \ No newline at end of file +holdBook=\u00a74You are not holding a writable book +fireworkColor=\u00a74You must apply a color to the firework to add an effect +holdFirework=\u00a74You must be holding a firework to add effects +invalidFireworkFormat=\u00a76The option \u00a74{0} \u00a76is not a valid value for \u00a74{1} diff --git a/Essentials/src/messages_it.properties b/Essentials/src/messages_it.properties index 02ce6c483..addc32c3e 100644 --- a/Essentials/src/messages_it.properties +++ b/Essentials/src/messages_it.properties @@ -485,4 +485,7 @@ denyChangeAuthor=\u00a74You cannot change the author of this book denyChangeTitle=\u00a74You cannot change the title of this book denyBookEdit=\u00a74You cannot unlock this book bookLocked=\u00a7cThis book is now locked -holdBook=\u00a74You are not holding a writable book \ No newline at end of file +holdBook=\u00a74You are not holding a writable book +fireworkColor=\u00a74You must apply a color to the firework to add an effect +holdFirework=\u00a74You must be holding a firework to add effects +invalidFireworkFormat=\u00a76The option \u00a74{0} \u00a76is not a valid value for \u00a74{1} diff --git a/Essentials/src/messages_nl.properties b/Essentials/src/messages_nl.properties index 81ae25e03..de37ddd68 100644 --- a/Essentials/src/messages_nl.properties +++ b/Essentials/src/messages_nl.properties @@ -485,4 +485,7 @@ denyChangeAuthor=\u00a74You cannot change the author of this book denyChangeTitle=\u00a74You cannot change the title of this book denyBookEdit=\u00a74You cannot unlock this book bookLocked=\u00a7cThis book is now locked -holdBook=\u00a74You are not holding a writable book \ No newline at end of file +holdBook=\u00a74You are not holding a writable book +fireworkColor=\u00a74You must apply a color to the firework to add an effect +holdFirework=\u00a74You must be holding a firework to add effects +invalidFireworkFormat=\u00a76The option \u00a74{0} \u00a76is not a valid value for \u00a74{1} diff --git a/Essentials/src/messages_pl.properties b/Essentials/src/messages_pl.properties index 923e125f5..de9388897 100644 --- a/Essentials/src/messages_pl.properties +++ b/Essentials/src/messages_pl.properties @@ -485,4 +485,7 @@ denyChangeAuthor=\u00a74You cannot change the author of this book denyChangeTitle=\u00a74You cannot change the title of this book denyBookEdit=\u00a74You cannot unlock this book bookLocked=\u00a7cThis book is now locked -holdBook=\u00a74You are not holding a writable book \ No newline at end of file +holdBook=\u00a74You are not holding a writable book +fireworkColor=\u00a74You must apply a color to the firework to add an effect +holdFirework=\u00a74You must be holding a firework to add effects +invalidFireworkFormat=\u00a76The option \u00a74{0} \u00a76is not a valid value for \u00a74{1} diff --git a/Essentials/src/messages_pt.properties b/Essentials/src/messages_pt.properties index f7ea1a220..028ea280f 100644 --- a/Essentials/src/messages_pt.properties +++ b/Essentials/src/messages_pt.properties @@ -485,4 +485,7 @@ denyChangeAuthor=\u00a74You cannot change the author of this book denyChangeTitle=\u00a74You cannot change the title of this book denyBookEdit=\u00a74You cannot unlock this book bookLocked=\u00a7cThis book is now locked -holdBook=\u00a74You are not holding a writable book \ No newline at end of file +holdBook=\u00a74You are not holding a writable book +fireworkColor=\u00a74You must apply a color to the firework to add an effect +holdFirework=\u00a74You must be holding a firework to add effects +invalidFireworkFormat=\u00a76The option \u00a74{0} \u00a76is not a valid value for \u00a74{1} diff --git a/Essentials/src/messages_se.properties b/Essentials/src/messages_se.properties index a110218a3..d47289567 100644 --- a/Essentials/src/messages_se.properties +++ b/Essentials/src/messages_se.properties @@ -485,4 +485,7 @@ denyChangeAuthor=\u00a74You cannot change the author of this book denyChangeTitle=\u00a74You cannot change the title of this book denyBookEdit=\u00a74You cannot unlock this book bookLocked=\u00a7cThis book is now locked -holdBook=\u00a74You are not holding a writable book \ No newline at end of file +holdBook=\u00a74You are not holding a writable book +fireworkColor=\u00a74You must apply a color to the firework to add an effect +holdFirework=\u00a74You must be holding a firework to add effects +invalidFireworkFormat=\u00a76The option \u00a74{0} \u00a76is not a valid value for \u00a74{1} diff --git a/Essentials/src/plugin.yml b/Essentials/src/plugin.yml index c7dd232e1..e830e77be 100644 --- a/Essentials/src/plugin.yml +++ b/Essentials/src/plugin.yml @@ -119,6 +119,10 @@ commands: description: Throw a fireball. usage: / [small|skull] aliases: [efireball,fireskull,efireskull,fireentity,efireentity] + firework: + description: Add or clears effects to a firework + usage: / [clear|params] + aliases: [efirework] gamemode: description: Change player gamemode. usage: / [player] @@ -462,4 +466,4 @@ commands: permissions: essentials.*: default: op - description: Give players with op everything by default + description: Give players with op everything by default \ No newline at end of file -- cgit v1.2.3 From 214d9414dabe9555e5e4bfe2b3245bdca0572cfe Mon Sep 17 00:00:00 2001 From: GunfighterJ Date: Wed, 16 Jan 2013 20:39:09 -0600 Subject: Adds the actual /firework command --- .../essentials/commands/Commandfirework.java | 180 +++++++++++++++++++++ 1 file changed, 180 insertions(+) create mode 100644 Essentials/src/com/earth2me/essentials/commands/Commandfirework.java diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandfirework.java b/Essentials/src/com/earth2me/essentials/commands/Commandfirework.java new file mode 100644 index 000000000..91cfef741 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/commands/Commandfirework.java @@ -0,0 +1,180 @@ +package com.earth2me.essentials.commands; + +import com.earth2me.essentials.User; +import static com.earth2me.essentials.I18n._; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Pattern; +import org.bukkit.Color; +import org.bukkit.DyeColor; +import org.bukkit.FireworkEffect; +import org.bukkit.Material; +import org.bukkit.Server; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.FireworkMeta; + + +public class Commandfirework extends EssentialsCommand +{ + private final transient Pattern splitPattern = Pattern.compile("[:+',;.]"); + private final static Map colorMap = new HashMap(); + private final static Map fireworkShape = new HashMap(); + + 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 + { + + if (args.length > 0) + { + ItemStack stack = user.getItemInHand(); + if (stack.getType() == Material.FIREWORK) + { + FireworkEffect.Builder builder = FireworkEffect.builder(); + FireworkMeta fmeta = (FireworkMeta)stack.getItemMeta(); + + if (args.length > 0) + { + if (args[0].equalsIgnoreCase("clear")) + { + fmeta.clearEffects(); + stack.setItemMeta(fmeta); + user.setItemInHand(stack); + } + else + { + List primaryColors = new ArrayList(); + List fadeColors = new ArrayList(); + FireworkEffect.Type finalEffect = null; + + boolean valid = false; + for (String arg : args) + { + final String[] split = splitPattern.split(arg, 2); + if (split[0].equalsIgnoreCase("color") || split[0].equalsIgnoreCase("colour") || split[0].equalsIgnoreCase("c")) + { + String[] colors = split[1].split(","); + for (String color : colors) + { + if (colorMap.containsKey(color.toUpperCase())) + { + valid = true; + primaryColors.add(colorMap.get(color.toUpperCase()).getFireworkColor()); + } + else + { + user.sendMessage(_("invalidFireworkFormat", split[1], split[0])); + } + } + builder.withColor(primaryColors); + } + if (split[0].equalsIgnoreCase("shape") || split[0].equalsIgnoreCase("s") || split[0].equalsIgnoreCase("type") || split[0].equalsIgnoreCase("t")) + { + split[1] = (split[1].equalsIgnoreCase("large") ? "BALL_LARGE" : split[1]); + if (fireworkShape.containsKey(split[1].toUpperCase())) + { + finalEffect = fireworkShape.get(split[1].toUpperCase()); + } + else + { + user.sendMessage(_("invalidFireworkFormat", split[1], split[0])); + } + if (finalEffect != null) + { + builder.with(finalEffect); + } + } + if (split[0].equalsIgnoreCase("fade") || split[0].equalsIgnoreCase("f")) + { + String[] colors = split[1].split(","); + for (String color : colors) + { + if (colorMap.containsKey(color.toUpperCase())) + { + fadeColors.add(colorMap.get(color.toUpperCase()).getFireworkColor()); + } + else + { + user.sendMessage(_("invalidFireworkFormat", split[1], split[0])); + } + } + if (!fadeColors.isEmpty()) + { + builder.withFade(fadeColors); + } + } + if (split[0].equalsIgnoreCase("effect") || 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 + { + user.sendMessage(_("invalidFireworkFormat", split[1], split[0])); + } + } + } + if (split[0].equalsIgnoreCase("power") || split[0].equalsIgnoreCase("p")) + { + try + { + fmeta.setPower(Integer.parseInt(split[1])); + } + catch (NumberFormatException e) + { + user.sendMessage(_("invalidFireworkFormat", split[1], split[0])); + } + } + } + if (valid) + { + final FireworkEffect effect = builder.build(); + fmeta.addEffect(effect); + stack.setItemMeta(fmeta); + user.setItemInHand(stack); + } + else + { + user.sendMessage(_("fireworkColor")); + } + + } + } + } + else + { + user.sendMessage(_("holdFirework")); + } + } + else + { + throw new NotEnoughArgumentsException(); + } + } +} \ No newline at end of file -- cgit v1.2.3 From 8e663b53ceb12400f8cb38a224e34e3a53e565c0 Mon Sep 17 00:00:00 2001 From: GunfighterJ Date: Wed, 16 Jan 2013 20:40:29 -0600 Subject: Now it adds the right firework command --- .../essentials/commands/Commandfirework.java | 46 +++++++++++++++++++--- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandfirework.java b/Essentials/src/com/earth2me/essentials/commands/Commandfirework.java index 91cfef741..ddd1fc705 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandfirework.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandfirework.java @@ -12,6 +12,8 @@ import org.bukkit.DyeColor; import org.bukkit.FireworkEffect; import org.bukkit.Material; import org.bukkit.Server; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Firework; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.FireworkMeta; @@ -57,7 +59,6 @@ public class Commandfirework extends EssentialsCommand { fmeta.clearEffects(); stack.setItemMeta(fmeta); - user.setItemInHand(stack); } else { @@ -66,6 +67,8 @@ public class Commandfirework extends EssentialsCommand FireworkEffect.Type finalEffect = null; boolean valid = false; + boolean fire = false; + int amount = 1; for (String arg : args) { final String[] split = splitPattern.split(arg, 2); @@ -151,13 +154,44 @@ public class Commandfirework extends EssentialsCommand user.sendMessage(_("invalidFireworkFormat", split[1], split[0])); } } + if ((split[0].equalsIgnoreCase("fire") || split[0].equalsIgnoreCase("f")) && user.isAuthorized("essentials.firework.fire")) + { + fire = true; + try + { + amount = Integer.parseInt(split[1]); + int serverLimit = ess.getSettings().getSpawnMobLimit(); + if(amount > serverLimit) + { + amount = serverLimit; + user.sendMessage(_("mobSpawnLimit")); + } + } + catch (NumberFormatException e) + { + amount = 1; + } + } } if (valid) { - final FireworkEffect effect = builder.build(); - fmeta.addEffect(effect); - stack.setItemMeta(fmeta); - user.setItemInHand(stack); + if (fire) + { + for (int i = 0; i < amount; i++ ) + { + Firework firework = (Firework)user.getWorld().spawnEntity(user.getLocation(), EntityType.FIREWORK); + FireworkMeta ffmeta = firework.getFireworkMeta(); + ffmeta.addEffect(builder.build()); + ffmeta.setPower(fmeta.getPower()); + firework.setFireworkMeta(ffmeta); + } + } + else + { + final FireworkEffect effect = builder.build(); + fmeta.addEffect(effect); + stack.setItemMeta(fmeta); + } } else { @@ -177,4 +211,4 @@ public class Commandfirework extends EssentialsCommand throw new NotEnoughArgumentsException(); } } -} \ No newline at end of file +} -- cgit v1.2.3