mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-07-02 20:11:44 +00:00
Add itemflag support to kits. Resolves #795.
Syntax is "itemflags:HIDE_ATTRIBUTES,HIDE_ENCHANTS"
This commit is contained in:
parent
cd43355d4c
commit
377c716d52
26 changed files with 67 additions and 4 deletions
|
@ -17,6 +17,7 @@ import org.bukkit.Material;
|
|||
import org.bukkit.block.Banner;
|
||||
import org.bukkit.block.banner.PatternType;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.*;
|
||||
import org.bukkit.potion.Potion;
|
||||
|
@ -216,6 +217,8 @@ public class MetaItemStack {
|
|||
final FireworkMeta meta = (FireworkMeta) stack.getItemMeta();
|
||||
meta.setPower(power > 3 ? 4 : power);
|
||||
stack.setItemMeta(meta);
|
||||
} else if (split.length > 1 && split[0].equalsIgnoreCase("itemflags") && hasMetaPermission(sender, "itemflags", false, true, ess)) {
|
||||
addItemFlags(string);
|
||||
} else if (stack.getType() == Material.FIREWORK) {//WARNING - Meta for fireworks will be ignored after this point.
|
||||
addFireworkMeta(sender, false, string, ess);
|
||||
} else if (isPotion(stack.getType())) { //WARNING - Meta for potions will be ignored after this point.
|
||||
|
@ -253,6 +256,30 @@ public class MetaItemStack {
|
|||
}
|
||||
}
|
||||
|
||||
public void addItemFlags(final String string) throws Exception {
|
||||
String[] separate = splitPattern.split(string, 2);
|
||||
if(separate.length != 2) {
|
||||
throw new Exception(tl("invalidItemFlagMeta", string));
|
||||
}
|
||||
|
||||
String[] split = separate[1].split(",");
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
|
||||
for (String s : split) {
|
||||
for (ItemFlag flag : ItemFlag.values()) {
|
||||
if (s.equalsIgnoreCase(flag.name())) {
|
||||
meta.addItemFlags(flag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (meta.getItemFlags().isEmpty()) {
|
||||
throw new Exception(tl("invalidItemFlagMeta", string));
|
||||
}
|
||||
|
||||
stack.setItemMeta(meta);
|
||||
}
|
||||
|
||||
public void addFireworkMeta(final CommandSource sender, final boolean allowShortName, final String string, final IEssentials ess) throws Exception {
|
||||
if (stack.getType() == Material.FIREWORK) {
|
||||
final String[] split = splitPattern.split(string, 2);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue