mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-12 04:20:41 +00:00
[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:
parent
d93719ebcf
commit
4d9685e10d
1 changed files with 26 additions and 20 deletions
|
@ -99,14 +99,14 @@ public class MetaItemStack
|
||||||
}
|
}
|
||||||
if (validFirework)
|
if (validFirework)
|
||||||
{
|
{
|
||||||
if (!hasMetaPermission(sender, "firework", true, ess))
|
if (!hasMetaPermission(sender, "firework", true, true, ess))
|
||||||
{
|
{
|
||||||
throw new Exception(_("noMetaFirework"));
|
throw new Exception(_("noMetaFirework"));
|
||||||
}
|
}
|
||||||
FireworkEffect effect = builder.build();
|
FireworkEffect effect = builder.build();
|
||||||
FireworkMeta fmeta = (FireworkMeta)stack.getItemMeta();
|
FireworkMeta fmeta = (FireworkMeta)stack.getItemMeta();
|
||||||
fmeta.addEffect(effect);
|
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"));
|
throw new Exception(_("multipleCharges"));
|
||||||
}
|
}
|
||||||
|
@ -122,14 +122,14 @@ public class MetaItemStack
|
||||||
return;
|
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 String displayName = Util.replaceFormat(split[1].replace('_', ' '));
|
||||||
final ItemMeta meta = stack.getItemMeta();
|
final ItemMeta meta = stack.getItemMeta();
|
||||||
meta.setDisplayName(displayName);
|
meta.setDisplayName(displayName);
|
||||||
stack.setItemMeta(meta);
|
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>();
|
final List<String> lore = new ArrayList<String>();
|
||||||
for (String line : split[1].split("\\|"))
|
for (String line : split[1].split("\\|"))
|
||||||
|
@ -140,7 +140,7 @@ public class MetaItemStack
|
||||||
meta.setLore(lore);
|
meta.setLore(lore);
|
||||||
stack.setItemMeta(meta);
|
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)
|
if (stack.getDurability() == 3)
|
||||||
{
|
{
|
||||||
|
@ -154,13 +154,13 @@ public class MetaItemStack
|
||||||
throw new Exception(_("onlyPlayerSkulls"));
|
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 BookMeta meta = (BookMeta)stack.getItemMeta();
|
||||||
final IText input = new BookInput("book", true, ess);
|
final IText input = new BookInput("book", true, ess);
|
||||||
final BookPager pager = new BookPager(input);
|
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]);
|
List<String> pages = pager.getPages(split[1]);
|
||||||
meta.setPages(pages);
|
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 String author = split[1];
|
||||||
final BookMeta meta = (BookMeta)stack.getItemMeta();
|
final BookMeta meta = (BookMeta)stack.getItemMeta();
|
||||||
meta.setAuthor(author);
|
meta.setAuthor(author);
|
||||||
stack.setItemMeta(meta);
|
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 String title = Util.replaceFormat(split[1].replace('_', ' '));
|
||||||
final BookMeta meta = (BookMeta)stack.getItemMeta();
|
final BookMeta meta = (BookMeta)stack.getItemMeta();
|
||||||
meta.setTitle(title);
|
meta.setTitle(title);
|
||||||
stack.setItemMeta(meta);
|
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 int power = Util.isInt(split[1]) ? Integer.parseInt(split[1]) : 0;
|
||||||
final FireworkMeta meta = (FireworkMeta)stack.getItemMeta();
|
final FireworkMeta meta = (FireworkMeta)stack.getItemMeta();
|
||||||
|
@ -243,14 +243,14 @@ public class MetaItemStack
|
||||||
{
|
{
|
||||||
if (validFirework)
|
if (validFirework)
|
||||||
{
|
{
|
||||||
if (!hasMetaPermission(sender, "firework", true, ess))
|
if (!hasMetaPermission(sender, "firework", true, true, ess))
|
||||||
{
|
{
|
||||||
throw new Exception(_("noMetaFirework"));
|
throw new Exception(_("noMetaFirework"));
|
||||||
}
|
}
|
||||||
FireworkEffect effect = builder.build();
|
FireworkEffect effect = builder.build();
|
||||||
FireworkMeta fmeta = (FireworkMeta)stack.getItemMeta();
|
FireworkMeta fmeta = (FireworkMeta)stack.getItemMeta();
|
||||||
fmeta.addEffect(effect);
|
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"));
|
throw new Exception(_("multipleCharges"));
|
||||||
}
|
}
|
||||||
|
@ -337,7 +337,6 @@ public class MetaItemStack
|
||||||
{
|
{
|
||||||
if (stack.getType() == Material.POTION)
|
if (stack.getType() == Material.POTION)
|
||||||
{
|
{
|
||||||
final User user = ess.getUser(sender);
|
|
||||||
final String[] split = splitPattern.split(string, 2);
|
final String[] split = splitPattern.split(string, 2);
|
||||||
|
|
||||||
if (split.length < 2)
|
if (split.length < 2)
|
||||||
|
@ -350,7 +349,7 @@ public class MetaItemStack
|
||||||
pEffectType = Potions.getByName(split[1]);
|
pEffectType = Potions.getByName(split[1]);
|
||||||
if (pEffectType != null)
|
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;
|
validPotionEffect = true;
|
||||||
canceledEffect = false;
|
canceledEffect = false;
|
||||||
|
@ -388,7 +387,7 @@ public class MetaItemStack
|
||||||
{
|
{
|
||||||
PotionMeta pmeta = (PotionMeta)stack.getItemMeta();
|
PotionMeta pmeta = (PotionMeta)stack.getItemMeta();
|
||||||
pEffect = pEffectType.createEffect(duration, power);
|
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"));
|
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
|
private void parseEnchantmentStrings(final CommandSender sender, final boolean allowUnsafe, final String[] split, final IEssentials ess) throws Exception
|
||||||
{
|
{
|
||||||
final Enchantment enchantment = Enchantments.getByName(split[0]);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -476,19 +475,26 @@ public class MetaItemStack
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String enchantmentName = enchantment.getName().toLowerCase(Locale.ENGLISH);
|
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));
|
throw new Exception(_("enchantmentPerm", enchantmentName));
|
||||||
}
|
}
|
||||||
return enchantment;
|
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);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue