mirror of
https://github.com/essentials/Essentials.git
synced 2025-08-16 11:37:30 +02:00
Add firework command.
Add missing book.txt. Update permissions.
This commit is contained in:
18
Essentials/src/book.txt
Normal file
18
Essentials/src/book.txt
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
This is the book file.
|
||||||
|
|
||||||
|
This file format works similar to the info.txt, motd.txt and rules.txt
|
||||||
|
|
||||||
|
Place content in here that you would like to be used by books ingame.
|
||||||
|
|
||||||
|
You can use this content by using the book:<section> meta option in kits or item spawning.
|
||||||
|
|
||||||
|
#Colors
|
||||||
|
Minecraft colors:
|
||||||
|
&0 &&0 &1 &&1 &2 &&2 &3 &&3
|
||||||
|
&4 &&4 &5 &&5 &6 &&6 &7 &&7
|
||||||
|
&8 &&8 &9 &&9 &a &&a &b &&b
|
||||||
|
&c &&c &d &&d &e &&e &f &&f
|
||||||
|
&0
|
||||||
|
&&k &kMagic&r &&l &lBold
|
||||||
|
&&m &mStrike&r &&n &nUline
|
||||||
|
&&o &oItalic&r &&r &rReset
|
531
Essentials/src/net/ess3/MetaItemStack.java
Normal file
531
Essentials/src/net/ess3/MetaItemStack.java
Normal file
@@ -0,0 +1,531 @@
|
|||||||
|
package net.ess3;
|
||||||
|
|
||||||
|
import static net.ess3.I18n._;
|
||||||
|
|
||||||
|
import net.ess3.api.IEssentials;
|
||||||
|
import net.ess3.api.IUser;
|
||||||
|
import net.ess3.bukkit.Enchantments;
|
||||||
|
import net.ess3.permissions.Permissions;
|
||||||
|
import net.ess3.utils.FormatUtil;
|
||||||
|
import net.ess3.utils.Util;
|
||||||
|
import net.ess3.utils.textreader.BookInput;
|
||||||
|
import net.ess3.utils.textreader.BookPager;
|
||||||
|
import net.ess3.utils.textreader.IText;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import org.bukkit.Color;
|
||||||
|
import org.bukkit.DyeColor;
|
||||||
|
import org.bukkit.FireworkEffect;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.*;
|
||||||
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
|
|
||||||
|
public class MetaItemStack
|
||||||
|
{
|
||||||
|
private final transient Pattern splitPattern = Pattern.compile("[:+',;.]");
|
||||||
|
private final ItemStack stack;
|
||||||
|
private final static Map<String, DyeColor> colorMap = new HashMap<String, DyeColor>();
|
||||||
|
private final static Map<String, FireworkEffect.Type> fireworkShape = new HashMap<String, FireworkEffect.Type>();
|
||||||
|
private FireworkEffect.Builder builder = FireworkEffect.builder();
|
||||||
|
private PotionEffectType pEffectType;
|
||||||
|
private PotionEffect pEffect;
|
||||||
|
private boolean validFirework = false;
|
||||||
|
private boolean validPotionEffect = false;
|
||||||
|
private boolean validPotionDuration = false;
|
||||||
|
private boolean validPotionPower = false;
|
||||||
|
private boolean completePotion = false;
|
||||||
|
private int power = 1;
|
||||||
|
private int duration = 120;
|
||||||
|
|
||||||
|
static
|
||||||
|
{
|
||||||
|
for (DyeColor color : DyeColor.values())
|
||||||
|
{
|
||||||
|
colorMap.put(color.name(), color);
|
||||||
|
}
|
||||||
|
for (FireworkEffect.Type type : FireworkEffect.Type.values())
|
||||||
|
{
|
||||||
|
fireworkShape.put(type.name(), type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public MetaItemStack(final ItemStack stack)
|
||||||
|
{
|
||||||
|
this.stack = stack.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack getItemStack()
|
||||||
|
{
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isValidFirework()
|
||||||
|
{
|
||||||
|
return validFirework;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isValidPotion()
|
||||||
|
{
|
||||||
|
return validPotionEffect && validPotionDuration && validPotionPower;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FireworkEffect.Builder getFireworkBuilder()
|
||||||
|
{
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PotionEffect getPotionEffect()
|
||||||
|
{
|
||||||
|
return pEffect;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean completePotion()
|
||||||
|
{
|
||||||
|
return completePotion;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resetPotionMeta()
|
||||||
|
{
|
||||||
|
pEffect = null;
|
||||||
|
pEffectType = null;
|
||||||
|
validPotionEffect = false;
|
||||||
|
validPotionDuration = false;
|
||||||
|
validPotionPower = false;
|
||||||
|
completePotion = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void parseStringMeta(final CommandSender sender, final boolean allowUnsafe, String[] string, int fromArg, final IEssentials ess) throws Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
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(_("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(_("multipleCharges"));
|
||||||
|
}
|
||||||
|
stack.setItemMeta(fmeta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addStringMeta(final CommandSender sender, final boolean allowUnsafe, final String string, final IEssentials ess) throws Exception
|
||||||
|
{
|
||||||
|
final String[] split = splitPattern.split(string, 2);
|
||||||
|
if (split.length < 1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (split.length > 1 && split[0].equalsIgnoreCase("name") && hasMetaPermission(sender, "name", false, true, ess))
|
||||||
|
{
|
||||||
|
final String displayName = FormatUtil.replaceFormat(split[1].replace('_', ' '));
|
||||||
|
final ItemMeta meta = stack.getItemMeta();
|
||||||
|
meta.setDisplayName(displayName);
|
||||||
|
stack.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
else if (split.length > 1 && (split[0].equalsIgnoreCase("lore") || split[0].equalsIgnoreCase("desc")) && hasMetaPermission(sender, "lore", false, true, ess))
|
||||||
|
{
|
||||||
|
final List<String> lore = new ArrayList<String>();
|
||||||
|
for (String line : split[1].split("\\|"))
|
||||||
|
{
|
||||||
|
lore.add(FormatUtil.replaceFormat(line.replace('_', ' ')));
|
||||||
|
}
|
||||||
|
final ItemMeta meta = stack.getItemMeta();
|
||||||
|
meta.setLore(lore);
|
||||||
|
stack.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
else if (split.length > 1 && (split[0].equalsIgnoreCase("player") || split[0].equalsIgnoreCase("owner")) && stack.getType() == Material.SKULL_ITEM && hasMetaPermission(sender, "head", false, true, ess))
|
||||||
|
{
|
||||||
|
if (stack.getDurability() == 3)
|
||||||
|
{
|
||||||
|
final String owner = split[1];
|
||||||
|
final SkullMeta meta = (SkullMeta)stack.getItemMeta();
|
||||||
|
boolean result = meta.setOwner(owner);
|
||||||
|
stack.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception(_("onlyPlayerSkulls"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (split.length > 1 && split[0].equalsIgnoreCase("book") && stack.getType() == Material.WRITTEN_BOOK && hasMetaPermission(sender, "book", false, true, ess))
|
||||||
|
{
|
||||||
|
final BookMeta meta = (BookMeta)stack.getItemMeta();
|
||||||
|
final IText input = new BookInput("book", true, ess);
|
||||||
|
final BookPager pager = new BookPager(input);
|
||||||
|
|
||||||
|
if (hasMetaPermission(sender, "chapter", true, true, ess) || hasMetaPermission(sender, "chapter-" + split[1].toLowerCase(Locale.ENGLISH), true, true, ess))
|
||||||
|
{
|
||||||
|
List<String> pages = pager.getPages(split[1]);
|
||||||
|
meta.setPages(pages);
|
||||||
|
stack.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception(_("noChapterMeta"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (split.length > 1 && split[0].equalsIgnoreCase("author") && stack.getType() == Material.WRITTEN_BOOK && hasMetaPermission(sender, "author", false, true, ess))
|
||||||
|
{
|
||||||
|
final String author = split[1];
|
||||||
|
final BookMeta meta = (BookMeta)stack.getItemMeta();
|
||||||
|
meta.setAuthor(author);
|
||||||
|
stack.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
else if (split.length > 1 && split[0].equalsIgnoreCase("title") && stack.getType() == Material.WRITTEN_BOOK && hasMetaPermission(sender, "title", false, true, ess))
|
||||||
|
{
|
||||||
|
final String title = FormatUtil.replaceFormat(split[1].replace('_', ' '));
|
||||||
|
final BookMeta meta = (BookMeta)stack.getItemMeta();
|
||||||
|
meta.setTitle(title);
|
||||||
|
stack.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
else if (split.length > 1 && split[0].equalsIgnoreCase("power") && stack.getType() == Material.FIREWORK && hasMetaPermission(sender, "firework-power", false, true, ess))
|
||||||
|
{
|
||||||
|
final int power = Util.isInt(split[1]) ? Integer.parseInt(split[1]) : 0;
|
||||||
|
final FireworkMeta meta = (FireworkMeta)stack.getItemMeta();
|
||||||
|
meta.setPower(power > 3 ? 4 : power);
|
||||||
|
stack.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
else if (stack.getType() == Material.FIREWORK) //WARNING - Meta for fireworks will be ignored after this point.
|
||||||
|
{
|
||||||
|
addFireworkMeta(sender, false, string, ess);
|
||||||
|
}
|
||||||
|
else if (stack.getType() == Material.POTION) //WARNING - Meta for potions will be ignored after this point.
|
||||||
|
{
|
||||||
|
addPotionMeta(sender, false, string, ess);
|
||||||
|
}
|
||||||
|
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("(\\||,)");
|
||||||
|
if (color.length == 3)
|
||||||
|
{
|
||||||
|
final int red = Util.isInt(color[0]) ? Integer.parseInt(color[0]) : 0;
|
||||||
|
final int green = Util.isInt(color[1]) ? Integer.parseInt(color[1]) : 0;
|
||||||
|
final int blue = Util.isInt(color[2]) ? Integer.parseInt(color[2]) : 0;
|
||||||
|
final LeatherArmorMeta meta = (LeatherArmorMeta)stack.getItemMeta();
|
||||||
|
meta.setColor(Color.fromRGB(red, green, blue));
|
||||||
|
stack.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception(_("leatherSyntax"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
parseEnchantmentStrings(sender, allowUnsafe, split, ess);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addFireworkMeta(final CommandSender 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(_("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(_("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(_("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(_("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(_("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(_("invalidFireworkFormat", split[1], split[0]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addPotionMeta(final CommandSender sender, final boolean allowShortName, final String string, final IEssentials ess) throws Exception
|
||||||
|
{
|
||||||
|
if (stack.getType() == Material.POTION)
|
||||||
|
{
|
||||||
|
final String[] split = splitPattern.split(string, 2);
|
||||||
|
|
||||||
|
if (split.length < 2)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (split[0].equalsIgnoreCase("effect") || (allowShortName && split[0].equalsIgnoreCase("e")))
|
||||||
|
{
|
||||||
|
pEffectType = Potions.getByName(split[1]);
|
||||||
|
if (pEffectType != null && pEffectType.getName() != null)
|
||||||
|
{
|
||||||
|
if (hasMetaPermission(sender, "potions." + pEffectType.getName().toLowerCase(Locale.ENGLISH), true, false, ess))
|
||||||
|
{
|
||||||
|
validPotionEffect = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception(_("noPotionEffectPerm", pEffectType.getName().toLowerCase(Locale.ENGLISH)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception(_("invalidPotionMeta", split[1]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (split[0].equalsIgnoreCase("power") || (allowShortName && split[0].equalsIgnoreCase("p")))
|
||||||
|
{
|
||||||
|
if (Util.isInt(split[1]))
|
||||||
|
{
|
||||||
|
validPotionPower = true;
|
||||||
|
power = Integer.parseInt(split[1]);
|
||||||
|
if (power > 0 && power < 4)
|
||||||
|
{
|
||||||
|
power -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception(_("invalidPotionMeta", split[1]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (split[0].equalsIgnoreCase("duration") || (allowShortName && split[0].equalsIgnoreCase("d")))
|
||||||
|
{
|
||||||
|
if (Util.isInt(split[1]))
|
||||||
|
{
|
||||||
|
validPotionDuration = true;
|
||||||
|
duration = Integer.parseInt(split[1]) * 20; //Duration is in ticks by default, converted to seconds
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception(_("invalidPotionMeta", split[1]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isValidPotion())
|
||||||
|
{
|
||||||
|
PotionMeta pmeta = (PotionMeta)stack.getItemMeta();
|
||||||
|
pEffect = pEffectType.createEffect(duration, power);
|
||||||
|
if (pmeta.getCustomEffects().size() > 1 && !hasMetaPermission(sender, "potions.multiple", true, false, ess))
|
||||||
|
{
|
||||||
|
throw new Exception(_("multiplePotionEffects"));
|
||||||
|
}
|
||||||
|
pmeta.addCustomEffect(pEffect, true);
|
||||||
|
stack.setItemMeta(pmeta);
|
||||||
|
resetPotionMeta();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void parseEnchantmentStrings(final CommandSender sender, final boolean allowUnsafe, final String[] split, final IEssentials ess) throws Exception
|
||||||
|
{
|
||||||
|
final Enchantment enchantment = Enchantments.getByName(split[0]);
|
||||||
|
if (enchantment == null || !hasMetaPermission(sender, "enchantments." + enchantment.getName().toLowerCase(Locale.ENGLISH), false, false, ess))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int level = -1;
|
||||||
|
if (split.length > 1)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
level = Integer.parseInt(split[1]);
|
||||||
|
}
|
||||||
|
catch (NumberFormatException ex)
|
||||||
|
{
|
||||||
|
level = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (level < 0 || (!allowUnsafe && level > enchantment.getMaxLevel()))
|
||||||
|
{
|
||||||
|
level = enchantment.getMaxLevel();
|
||||||
|
}
|
||||||
|
addEnchantment(sender, allowUnsafe, enchantment, level);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addEnchantment(final CommandSender sender, final boolean allowUnsafe, final Enchantment enchantment, final int level) throws Exception
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (stack.getType().equals(Material.ENCHANTED_BOOK))
|
||||||
|
{
|
||||||
|
EnchantmentStorageMeta meta = (EnchantmentStorageMeta)stack.getItemMeta();
|
||||||
|
if (level == 0)
|
||||||
|
{
|
||||||
|
meta.removeStoredEnchant(enchantment);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
meta.addStoredEnchant(enchantment, level, allowUnsafe);
|
||||||
|
}
|
||||||
|
stack.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
else // all other material types besides ENCHANTED_BOOK
|
||||||
|
{
|
||||||
|
if (level == 0)
|
||||||
|
{
|
||||||
|
stack.removeEnchantment(enchantment);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (allowUnsafe)
|
||||||
|
{
|
||||||
|
stack.addUnsafeEnchantment(enchantment, level);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
stack.addEnchantment(enchantment, level);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new Exception("Enchantment " + enchantment.getName() + ": " + ex.getMessage(), ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Enchantment getEnchantment(final IUser user, final String name) throws Exception
|
||||||
|
{
|
||||||
|
final Enchantment enchantment = Enchantments.getByName(name);
|
||||||
|
if (enchantment == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String enchantmentName = enchantment.getName().toLowerCase(Locale.ENGLISH);
|
||||||
|
|
||||||
|
if (!hasMetaPermission(user, "enchantments." + enchantmentName, true, false))
|
||||||
|
{
|
||||||
|
throw new Exception(_("enchantmentPerm", enchantmentName));
|
||||||
|
}
|
||||||
|
return enchantment;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasMetaPermission(final CommandSender sender, final String metaPerm, final boolean graceful, final boolean includeBase, final IEssentials ess) throws Exception
|
||||||
|
{
|
||||||
|
final IUser user = ess.getUserMap().getUser((Player)sender);
|
||||||
|
|
||||||
|
return hasMetaPermission(user, metaPerm, graceful, includeBase);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasMetaPermission(final IUser user, final String metaPerm, final boolean graceful, final boolean includeBase) throws Exception
|
||||||
|
{
|
||||||
|
final String permBase = includeBase ? "essentials.itemspawn.meta-" : "essentials.";
|
||||||
|
if (user == null || (includeBase ? Permissions.ITEMSPAWN.isAuthorized(user, "meta-" + metaPerm) : Permissions.ESSENTIALS.isAuthorized(user, metaPerm)))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (graceful)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception(_("noMetaPerm", metaPerm));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
132
Essentials/src/net/ess3/Potions.java
Normal file
132
Essentials/src/net/ess3/Potions.java
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
package net.ess3;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import net.ess3.utils.Util;
|
||||||
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
|
|
||||||
|
public class Potions
|
||||||
|
{
|
||||||
|
private static final Map<String, PotionEffectType> POTIONS = new HashMap<String, PotionEffectType>();
|
||||||
|
private static final Map<String, PotionEffectType> ALIASPOTIONS = new HashMap<String, PotionEffectType>();
|
||||||
|
|
||||||
|
static
|
||||||
|
{
|
||||||
|
|
||||||
|
POTIONS.put("speed", PotionEffectType.SPEED);
|
||||||
|
ALIASPOTIONS.put("fast", PotionEffectType.SPEED);
|
||||||
|
ALIASPOTIONS.put("runfast", PotionEffectType.SPEED);
|
||||||
|
ALIASPOTIONS.put("sprint", PotionEffectType.SPEED);
|
||||||
|
ALIASPOTIONS.put("swift", PotionEffectType.SPEED);
|
||||||
|
|
||||||
|
POTIONS.put("slowness", PotionEffectType.SLOW);
|
||||||
|
ALIASPOTIONS.put("slow", PotionEffectType.SLOW);
|
||||||
|
ALIASPOTIONS.put("sluggish", PotionEffectType.SLOW);
|
||||||
|
|
||||||
|
POTIONS.put("haste", PotionEffectType.FAST_DIGGING);
|
||||||
|
ALIASPOTIONS.put("superpick", PotionEffectType.FAST_DIGGING);
|
||||||
|
ALIASPOTIONS.put("quickmine", PotionEffectType.FAST_DIGGING);
|
||||||
|
ALIASPOTIONS.put("digspeed", PotionEffectType.FAST_DIGGING);
|
||||||
|
ALIASPOTIONS.put("digfast", PotionEffectType.FAST_DIGGING);
|
||||||
|
ALIASPOTIONS.put("sharp", PotionEffectType.FAST_DIGGING);
|
||||||
|
|
||||||
|
POTIONS.put("fatigue", PotionEffectType.SLOW_DIGGING);
|
||||||
|
ALIASPOTIONS.put("slow", PotionEffectType.SLOW_DIGGING);
|
||||||
|
ALIASPOTIONS.put("dull", PotionEffectType.SLOW_DIGGING);
|
||||||
|
|
||||||
|
POTIONS.put("strength", PotionEffectType.INCREASE_DAMAGE);
|
||||||
|
ALIASPOTIONS.put("strong", PotionEffectType.INCREASE_DAMAGE);
|
||||||
|
ALIASPOTIONS.put("bull", PotionEffectType.INCREASE_DAMAGE);
|
||||||
|
ALIASPOTIONS.put("attack", PotionEffectType.INCREASE_DAMAGE);
|
||||||
|
|
||||||
|
POTIONS.put("heal", PotionEffectType.HEAL);
|
||||||
|
ALIASPOTIONS.put("healthy", PotionEffectType.HEAL);
|
||||||
|
ALIASPOTIONS.put("instaheal", PotionEffectType.HEAL);
|
||||||
|
|
||||||
|
POTIONS.put("harm", PotionEffectType.HARM);
|
||||||
|
ALIASPOTIONS.put("harming", PotionEffectType.HARM);
|
||||||
|
ALIASPOTIONS.put("injure", PotionEffectType.HARM);
|
||||||
|
ALIASPOTIONS.put("damage", PotionEffectType.HARM);
|
||||||
|
ALIASPOTIONS.put("inflict", PotionEffectType.HARM);
|
||||||
|
|
||||||
|
POTIONS.put("jump", PotionEffectType.JUMP);
|
||||||
|
ALIASPOTIONS.put("leap", PotionEffectType.JUMP);
|
||||||
|
|
||||||
|
POTIONS.put("nausea", PotionEffectType.CONFUSION);
|
||||||
|
ALIASPOTIONS.put("sick", PotionEffectType.CONFUSION);
|
||||||
|
ALIASPOTIONS.put("sickness", PotionEffectType.CONFUSION);
|
||||||
|
ALIASPOTIONS.put("confusion", PotionEffectType.CONFUSION);
|
||||||
|
|
||||||
|
POTIONS.put("regeneration", PotionEffectType.REGENERATION);
|
||||||
|
ALIASPOTIONS.put("regen", PotionEffectType.REGENERATION);
|
||||||
|
|
||||||
|
POTIONS.put("resistance", PotionEffectType.DAMAGE_RESISTANCE);
|
||||||
|
ALIASPOTIONS.put("dmgresist", PotionEffectType.DAMAGE_RESISTANCE);
|
||||||
|
ALIASPOTIONS.put("armor", PotionEffectType.DAMAGE_RESISTANCE);
|
||||||
|
ALIASPOTIONS.put("dmgresist", PotionEffectType.DAMAGE_RESISTANCE);
|
||||||
|
|
||||||
|
POTIONS.put("fireresist", PotionEffectType.FIRE_RESISTANCE);
|
||||||
|
ALIASPOTIONS.put("fireresistance", PotionEffectType.FIRE_RESISTANCE);
|
||||||
|
ALIASPOTIONS.put("resistfire", PotionEffectType.FIRE_RESISTANCE);
|
||||||
|
|
||||||
|
POTIONS.put("waterbreath", PotionEffectType.WATER_BREATHING);
|
||||||
|
ALIASPOTIONS.put("waterbreathing", PotionEffectType.WATER_BREATHING);
|
||||||
|
|
||||||
|
POTIONS.put("invisibility", PotionEffectType.INVISIBILITY);
|
||||||
|
ALIASPOTIONS.put("invisible", PotionEffectType.INVISIBILITY);
|
||||||
|
ALIASPOTIONS.put("invis", PotionEffectType.INVISIBILITY);
|
||||||
|
ALIASPOTIONS.put("vanish", PotionEffectType.INVISIBILITY);
|
||||||
|
ALIASPOTIONS.put("disappear", PotionEffectType.INVISIBILITY);
|
||||||
|
|
||||||
|
POTIONS.put("blindness", PotionEffectType.BLINDNESS);
|
||||||
|
ALIASPOTIONS.put("blind", PotionEffectType.BLINDNESS);
|
||||||
|
|
||||||
|
POTIONS.put("nightvision", PotionEffectType.NIGHT_VISION);
|
||||||
|
ALIASPOTIONS.put("vision", PotionEffectType.NIGHT_VISION);
|
||||||
|
|
||||||
|
POTIONS.put("hunger", PotionEffectType.HUNGER);
|
||||||
|
ALIASPOTIONS.put("hungry", PotionEffectType.HUNGER);
|
||||||
|
ALIASPOTIONS.put("starve", PotionEffectType.HUNGER);
|
||||||
|
|
||||||
|
POTIONS.put("weakness", PotionEffectType.WEAKNESS);
|
||||||
|
ALIASPOTIONS.put("weak", PotionEffectType.WEAKNESS);
|
||||||
|
|
||||||
|
POTIONS.put("poison", PotionEffectType.POISON);
|
||||||
|
ALIASPOTIONS.put("venom", PotionEffectType.POISON);
|
||||||
|
|
||||||
|
POTIONS.put("wither", PotionEffectType.WITHER);
|
||||||
|
ALIASPOTIONS.put("decay", PotionEffectType.WITHER);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PotionEffectType getByName(String name)
|
||||||
|
{
|
||||||
|
PotionEffectType peffect;
|
||||||
|
if (Util.isInt(name))
|
||||||
|
{
|
||||||
|
peffect = PotionEffectType.getById(Integer.parseInt(name));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
peffect = PotionEffectType.getByName(name.toUpperCase(Locale.ENGLISH));
|
||||||
|
}
|
||||||
|
if (peffect == null)
|
||||||
|
{
|
||||||
|
peffect = POTIONS.get(name.toLowerCase(Locale.ENGLISH));
|
||||||
|
}
|
||||||
|
if (peffect == null)
|
||||||
|
{
|
||||||
|
peffect = ALIASPOTIONS.get(name.toLowerCase(Locale.ENGLISH));
|
||||||
|
}
|
||||||
|
return peffect;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Set<Entry<String, PotionEffectType>> entrySet()
|
||||||
|
{
|
||||||
|
return POTIONS.entrySet();
|
||||||
|
}
|
||||||
|
}
|
154
Essentials/src/net/ess3/commands/Commandfirework.java
Normal file
154
Essentials/src/net/ess3/commands/Commandfirework.java
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
package net.ess3.commands;
|
||||||
|
|
||||||
|
import static net.ess3.I18n._;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import net.ess3.MetaItemStack;
|
||||||
|
import net.ess3.api.ISettings;
|
||||||
|
import net.ess3.api.IUser;
|
||||||
|
import net.ess3.permissions.Permissions;
|
||||||
|
import net.ess3.utils.Util;
|
||||||
|
import org.bukkit.FireworkEffect;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.Firework;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.FireworkMeta;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
|
||||||
|
//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
|
||||||
|
|
||||||
|
public class Commandfirework extends EssentialsCommand
|
||||||
|
{
|
||||||
|
private final transient Pattern splitPattern = Pattern.compile("[:+',;.]");
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void run(final IUser user, final String commandLabel, final String[] args) throws Exception
|
||||||
|
{
|
||||||
|
final Player player = user.getPlayer();
|
||||||
|
final ItemStack stack = user.getPlayer().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(_("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(_("invalidFireworkFormat", args[1], args[0]));
|
||||||
|
}
|
||||||
|
stack.setItemMeta(fmeta);
|
||||||
|
}
|
||||||
|
else if ((args[0].equalsIgnoreCase("fire") || (args[0].equalsIgnoreCase("f")))
|
||||||
|
&& Permissions.FIREWORK_FIRE.isAuthorized(user))
|
||||||
|
{
|
||||||
|
int amount = 1;
|
||||||
|
boolean direction = false;
|
||||||
|
if (args.length > 1)
|
||||||
|
{
|
||||||
|
if (Util.isInt(args[1]))
|
||||||
|
{
|
||||||
|
ISettings settings = ess.getSettings();
|
||||||
|
int serverLimit = settings.getData().getCommands().getSpawnmob().getLimit();
|
||||||
|
amount = Integer.parseInt(args[1]);
|
||||||
|
if (amount > serverLimit)
|
||||||
|
{
|
||||||
|
amount = serverLimit;
|
||||||
|
user.sendMessage(_("mobSpawnLimit"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
direction = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i = 0; i < amount; i++)
|
||||||
|
{
|
||||||
|
Firework firework = (Firework)player.getWorld().spawnEntity(player.getLocation(), EntityType.FIREWORK);
|
||||||
|
FireworkMeta fmeta = (FireworkMeta)stack.getItemMeta();
|
||||||
|
if (direction)
|
||||||
|
{
|
||||||
|
final Vector vector = player.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, true, arg, ess);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
user.sendMessage(_("fireworkSyntax"));
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mStack.isValidFirework())
|
||||||
|
{
|
||||||
|
FireworkMeta fmeta = (FireworkMeta)mStack.getItemStack().getItemMeta();
|
||||||
|
FireworkEffect effect = mStack.getFireworkBuilder().build();
|
||||||
|
if (fmeta.getEffects().size() > 0 && !Permissions.FIREWORK_MULTIPLE.isAuthorized(user))
|
||||||
|
{
|
||||||
|
throw new Exception(_("multipleCharges"));
|
||||||
|
}
|
||||||
|
fmeta.addEffect(effect);
|
||||||
|
stack.setItemMeta(fmeta);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
user.sendMessage(_("fireworkSyntax"));
|
||||||
|
throw new Exception(_("fireworkColor"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new NotEnoughArgumentsException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception(_("holdFirework"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -39,6 +39,8 @@ public enum Permissions implements IPermission
|
|||||||
EXP_SET_OTHERS,
|
EXP_SET_OTHERS,
|
||||||
EXP_OTHERS,
|
EXP_OTHERS,
|
||||||
FEED_OTHERS,
|
FEED_OTHERS,
|
||||||
|
FIREWORK_FIRE,
|
||||||
|
FIREWORK_MULTIPLE,
|
||||||
FLY_EXEMPT,
|
FLY_EXEMPT,
|
||||||
FLY_OTHERS,
|
FLY_OTHERS,
|
||||||
FLY_SAFELOGIN,
|
FLY_SAFELOGIN,
|
||||||
|
@@ -39,6 +39,10 @@ commands:
|
|||||||
description: Bans an IP address.
|
description: Bans an IP address.
|
||||||
usage: /<command> <address>
|
usage: /<command> <address>
|
||||||
aliases: [ebanip]
|
aliases: [ebanip]
|
||||||
|
book:
|
||||||
|
description: Allows reopening and editing of sealed books.
|
||||||
|
usage: /<command> [title|author [name]]
|
||||||
|
aliases: [ebook]
|
||||||
break:
|
break:
|
||||||
description: Breaks the block you are looking at.
|
description: Breaks the block you are looking at.
|
||||||
usage: /<command>
|
usage: /<command>
|
||||||
@@ -119,6 +123,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: Allows you to modify a stack of fireworks.
|
||||||
|
usage: /<command> <<meta param>|power [amount]|clear|fire [amount]>
|
||||||
|
aliases: [efirework]
|
||||||
gamemode:
|
gamemode:
|
||||||
description: Change player gamemode.
|
description: Change player gamemode.
|
||||||
usage: /<command> [player]
|
usage: /<command> [player]
|
||||||
|
Reference in New Issue
Block a user