[Fix] Move all enchant type perms to: essentials.enchantments.<enchant>

[Fix] Move all potion effect perms to: essentials.potions.<effect>
[Fix] Move multiple potion perm to: essentials.potions.multiple
Other perms: essentials.itemspawn.meta-(firework|firework-multiple|firework-power|name|lore|head|book|chapter|chapter-<chapter>|author|title)
This commit is contained in:
KHobbits 2013-03-09 13:56:38 +00:00
parent d93719ebcf
commit 4d9685e10d

View File

@ -99,14 +99,14 @@ public class MetaItemStack
}
if (validFirework)
{
if (!hasMetaPermission(sender, "firework", true, ess))
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, ess))
if (fmeta.getEffects().size() > 1 && !hasMetaPermission(sender, "firework-multiple", true, true, ess))
{
throw new Exception(_("multipleCharges"));
}
@ -122,14 +122,14 @@ public class MetaItemStack
return;
}
if (split.length > 1 && split[0].equalsIgnoreCase("name") && hasMetaPermission(sender, "name", false, ess))
if (split.length > 1 && split[0].equalsIgnoreCase("name") && hasMetaPermission(sender, "name", false, true, ess))
{
final String displayName = Util.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, ess))
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("\\|"))
@ -140,7 +140,7 @@ public class MetaItemStack
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, ess))
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)
{
@ -154,13 +154,13 @@ public class MetaItemStack
throw new Exception(_("onlyPlayerSkulls"));
}
}
else if (split.length > 1 && split[0].equalsIgnoreCase("book") && stack.getType() == Material.WRITTEN_BOOK && hasMetaPermission(sender, "book", false, ess))
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, ess) || hasMetaPermission(sender, "chapter-" + split[1].toLowerCase(), true, ess))
if (hasMetaPermission(sender, "chapter", true, true, ess) || hasMetaPermission(sender, "chapter-" + split[1].toLowerCase(), true, true, ess))
{
List<String> pages = pager.getPages(split[1]);
meta.setPages(pages);
@ -172,21 +172,21 @@ public class MetaItemStack
}
}
else if (split.length > 1 && split[0].equalsIgnoreCase("author") && stack.getType() == Material.WRITTEN_BOOK && hasMetaPermission(sender, "author", false, ess))
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, ess))
else if (split.length > 1 && split[0].equalsIgnoreCase("title") && stack.getType() == Material.WRITTEN_BOOK && hasMetaPermission(sender, "title", false, true, ess))
{
final String title = Util.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, ess))
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();
@ -243,14 +243,14 @@ public class MetaItemStack
{
if (validFirework)
{
if (!hasMetaPermission(sender, "firework", true, ess))
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", false, ess))
if (fmeta.getEffects().size() > 1 && !hasMetaPermission(sender, "firework-multiple", true, true, ess))
{
throw new Exception(_("multipleCharges"));
}
@ -337,7 +337,6 @@ public class MetaItemStack
{
if (stack.getType() == Material.POTION)
{
final User user = ess.getUser(sender);
final String[] split = splitPattern.split(string, 2);
if (split.length < 2)
@ -350,7 +349,7 @@ public class MetaItemStack
pEffectType = Potions.getByName(split[1]);
if (pEffectType != null)
{
if (user != null && user.isAuthorized("essentials.potion." + pEffectType.getName().toLowerCase()))
if (!hasMetaPermission(sender, "potions." + pEffectType.getName().toLowerCase(), false, false, ess))
{
validPotionEffect = true;
canceledEffect = false;
@ -388,7 +387,7 @@ public class MetaItemStack
{
PotionMeta pmeta = (PotionMeta)stack.getItemMeta();
pEffect = pEffectType.createEffect(duration, power);
if (pmeta.getCustomEffects().size() > 1 && !hasMetaPermission(sender, "potion-multiple", true, ess))
if (pmeta.getCustomEffects().size() > 1 && !hasMetaPermission(sender, "potions.multiple", true, false, ess))
{
throw new Exception(_("multiplePotionEffects"));
}
@ -402,7 +401,7 @@ public class MetaItemStack
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, "enchant-" + enchantment.getName().toLowerCase(Locale.ENGLISH), false, ess))
if (enchantment == null || !hasMetaPermission(sender, "enchantments." + enchantment.getName().toLowerCase(Locale.ENGLISH), false, false, ess))
{
return;
}
@ -478,17 +477,24 @@ public class MetaItemStack
}
final String enchantmentName = enchantment.getName().toLowerCase(Locale.ENGLISH);
if (user != null && !user.isAuthorized("essentials.enchant." + enchantmentName))
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 IEssentials ess) throws Exception
private boolean hasMetaPermission(final CommandSender sender, final String metaPerm, final boolean graceful, final boolean includeBase, final IEssentials ess) throws Exception
{
final User user = ess.getUser(sender);
if (user == null || user.isAuthorized("essentials.itemspawn.meta-" + metaPerm))
return hasMetaPermission(user, metaPerm, graceful, includeBase);
}
private boolean hasMetaPermission(final User user, final String metaPerm, final boolean graceful, final boolean includeBase) throws Exception
{
final String permBase = includeBase ? "essentials.itemspawn.meta-" : "essentials.";
if (user == null || user.isAuthorized(permBase + metaPerm))
{
return true;
}