mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-02 14:37:46 +01:00
commit
0014d5cfcb
@ -0,0 +1,214 @@
|
|||||||
|
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.entity.EntityType;
|
||||||
|
import org.bukkit.entity.Firework;
|
||||||
|
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<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
|
||||||
|
{
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
List<Color> primaryColors = new ArrayList<Color>();
|
||||||
|
List<Color> fadeColors = new ArrayList<Color>();
|
||||||
|
FireworkEffect.Type finalEffect = null;
|
||||||
|
|
||||||
|
boolean valid = false;
|
||||||
|
boolean fire = false;
|
||||||
|
int amount = 1;
|
||||||
|
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 ((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)
|
||||||
|
{
|
||||||
|
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
|
||||||
|
{
|
||||||
|
user.sendMessage(_("fireworkColor"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
user.sendMessage(_("holdFirework"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new NotEnoughArgumentsException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -485,4 +485,7 @@ denyChangeAuthor=\u00a74You cannot change the author of this book
|
|||||||
denyChangeTitle=\u00a74You cannot change the title of this book
|
denyChangeTitle=\u00a74You cannot change the title of this book
|
||||||
denyBookEdit=\u00a74You cannot unlock this book
|
denyBookEdit=\u00a74You cannot unlock this book
|
||||||
bookLocked=\u00a7cThis book is now locked
|
bookLocked=\u00a7cThis book is now locked
|
||||||
holdBook=\u00a74You are not holding a writable book
|
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}
|
||||||
|
@ -488,4 +488,8 @@ denyChangeAuthor=\u00a74You cannot change the author of this book
|
|||||||
denyChangeTitle=\u00a74You cannot change the title of this book
|
denyChangeTitle=\u00a74You cannot change the title of this book
|
||||||
denyBookEdit=\u00a74You cannot unlock this book
|
denyBookEdit=\u00a74You cannot unlock this book
|
||||||
bookLocked=\u00a7cThis book is now locked
|
bookLocked=\u00a7cThis book is now locked
|
||||||
holdBook=\u00a74You are not holding a writable book
|
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}
|
||||||
|
|
||||||
|
@ -485,4 +485,7 @@ denyChangeAuthor=\u00a74You cannot change the author of this book
|
|||||||
denyChangeTitle=\u00a74You cannot change the title of this book
|
denyChangeTitle=\u00a74You cannot change the title of this book
|
||||||
denyBookEdit=\u00a74You cannot unlock this book
|
denyBookEdit=\u00a74You cannot unlock this book
|
||||||
bookLocked=\u00a7cThis book is now locked
|
bookLocked=\u00a7cThis book is now locked
|
||||||
holdBook=\u00a74You are not holding a writable book
|
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}
|
||||||
|
@ -485,4 +485,7 @@ denyChangeAuthor=\u00a74You cannot change the author of this book
|
|||||||
denyChangeTitle=\u00a74You cannot change the title of this book
|
denyChangeTitle=\u00a74You cannot change the title of this book
|
||||||
denyBookEdit=\u00a74You cannot unlock this book
|
denyBookEdit=\u00a74You cannot unlock this book
|
||||||
bookLocked=\u00a7cThis book is now locked
|
bookLocked=\u00a7cThis book is now locked
|
||||||
holdBook=\u00a74You are not holding a writable book
|
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}
|
||||||
|
@ -485,4 +485,7 @@ denyChangeAuthor=\u00a74You cannot change the author of this book
|
|||||||
denyChangeTitle=\u00a74You cannot change the title of this book
|
denyChangeTitle=\u00a74You cannot change the title of this book
|
||||||
denyBookEdit=\u00a74You cannot unlock this book
|
denyBookEdit=\u00a74You cannot unlock this book
|
||||||
bookLocked=\u00a7cThis book is now locked
|
bookLocked=\u00a7cThis book is now locked
|
||||||
holdBook=\u00a74You are not holding a writable book
|
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}
|
||||||
|
@ -485,4 +485,7 @@ denyChangeAuthor=\u00a74You cannot change the author of this book
|
|||||||
denyChangeTitle=\u00a74You cannot change the title of this book
|
denyChangeTitle=\u00a74You cannot change the title of this book
|
||||||
denyBookEdit=\u00a74You cannot unlock this book
|
denyBookEdit=\u00a74You cannot unlock this book
|
||||||
bookLocked=\u00a7cThis book is now locked
|
bookLocked=\u00a7cThis book is now locked
|
||||||
holdBook=\u00a74You are not holding a writable book
|
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}
|
||||||
|
@ -485,4 +485,7 @@ denyChangeAuthor=\u00a74You cannot change the author of this book
|
|||||||
denyChangeTitle=\u00a74You cannot change the title of this book
|
denyChangeTitle=\u00a74You cannot change the title of this book
|
||||||
denyBookEdit=\u00a74You cannot unlock this book
|
denyBookEdit=\u00a74You cannot unlock this book
|
||||||
bookLocked=\u00a7cThis book is now locked
|
bookLocked=\u00a7cThis book is now locked
|
||||||
holdBook=\u00a74You are not holding a writable book
|
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}
|
||||||
|
@ -485,4 +485,7 @@ denyChangeAuthor=\u00a74You cannot change the author of this book
|
|||||||
denyChangeTitle=\u00a74You cannot change the title of this book
|
denyChangeTitle=\u00a74You cannot change the title of this book
|
||||||
denyBookEdit=\u00a74You cannot unlock this book
|
denyBookEdit=\u00a74You cannot unlock this book
|
||||||
bookLocked=\u00a7cThis book is now locked
|
bookLocked=\u00a7cThis book is now locked
|
||||||
holdBook=\u00a74You are not holding a writable book
|
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}
|
||||||
|
@ -485,4 +485,7 @@ denyChangeAuthor=\u00a74You cannot change the author of this book
|
|||||||
denyChangeTitle=\u00a74You cannot change the title of this book
|
denyChangeTitle=\u00a74You cannot change the title of this book
|
||||||
denyBookEdit=\u00a74You cannot unlock this book
|
denyBookEdit=\u00a74You cannot unlock this book
|
||||||
bookLocked=\u00a7cThis book is now locked
|
bookLocked=\u00a7cThis book is now locked
|
||||||
holdBook=\u00a74You are not holding a writable book
|
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}
|
||||||
|
@ -485,4 +485,7 @@ denyChangeAuthor=\u00a74You cannot change the author of this book
|
|||||||
denyChangeTitle=\u00a74You cannot change the title of this book
|
denyChangeTitle=\u00a74You cannot change the title of this book
|
||||||
denyBookEdit=\u00a74You cannot unlock this book
|
denyBookEdit=\u00a74You cannot unlock this book
|
||||||
bookLocked=\u00a7cThis book is now locked
|
bookLocked=\u00a7cThis book is now locked
|
||||||
holdBook=\u00a74You are not holding a writable book
|
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}
|
||||||
|
@ -485,4 +485,7 @@ denyChangeAuthor=\u00a74You cannot change the author of this book
|
|||||||
denyChangeTitle=\u00a74You cannot change the title of this book
|
denyChangeTitle=\u00a74You cannot change the title of this book
|
||||||
denyBookEdit=\u00a74You cannot unlock this book
|
denyBookEdit=\u00a74You cannot unlock this book
|
||||||
bookLocked=\u00a7cThis book is now locked
|
bookLocked=\u00a7cThis book is now locked
|
||||||
holdBook=\u00a74You are not holding a writable book
|
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}
|
||||||
|
@ -485,4 +485,7 @@ denyChangeAuthor=\u00a74You cannot change the author of this book
|
|||||||
denyChangeTitle=\u00a74You cannot change the title of this book
|
denyChangeTitle=\u00a74You cannot change the title of this book
|
||||||
denyBookEdit=\u00a74You cannot unlock this book
|
denyBookEdit=\u00a74You cannot unlock this book
|
||||||
bookLocked=\u00a7cThis book is now locked
|
bookLocked=\u00a7cThis book is now locked
|
||||||
holdBook=\u00a74You are not holding a writable book
|
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}
|
||||||
|
@ -485,4 +485,7 @@ denyChangeAuthor=\u00a74You cannot change the author of this book
|
|||||||
denyChangeTitle=\u00a74You cannot change the title of this book
|
denyChangeTitle=\u00a74You cannot change the title of this book
|
||||||
denyBookEdit=\u00a74You cannot unlock this book
|
denyBookEdit=\u00a74You cannot unlock this book
|
||||||
bookLocked=\u00a7cThis book is now locked
|
bookLocked=\u00a7cThis book is now locked
|
||||||
holdBook=\u00a74You are not holding a writable book
|
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}
|
||||||
|
@ -119,6 +119,10 @@ commands:
|
|||||||
description: Throw a fireball.
|
description: Throw a fireball.
|
||||||
usage: /<command> [small|skull]
|
usage: /<command> [small|skull]
|
||||||
aliases: [efireball,fireskull,efireskull,fireentity,efireentity]
|
aliases: [efireball,fireskull,efireskull,fireentity,efireentity]
|
||||||
|
firework:
|
||||||
|
description: Add or clears effects to a firework
|
||||||
|
usage: /<command> [clear|params]
|
||||||
|
aliases: [efirework]
|
||||||
gamemode:
|
gamemode:
|
||||||
description: Change player gamemode.
|
description: Change player gamemode.
|
||||||
usage: /<command> <survival|creative|adventure> [player]
|
usage: /<command> <survival|creative|adventure> [player]
|
||||||
@ -462,4 +466,4 @@ commands:
|
|||||||
permissions:
|
permissions:
|
||||||
essentials.*:
|
essentials.*:
|
||||||
default: op
|
default: op
|
||||||
description: Give players with op everything by default
|
description: Give players with op everything by default
|
Loading…
Reference in New Issue
Block a user