Add itemflag support to kits. Resolves #795.

Syntax is "itemflags:HIDE_ATTRIBUTES,HIDE_ENCHANTS"
This commit is contained in:
Trent Hensler 2018-01-18 00:25:19 -08:00
parent cd43355d4c
commit 377c716d52
26 changed files with 67 additions and 4 deletions

View File

@ -1,11 +1,9 @@
package com.earth2me.essentials;
import com.earth2me.essentials.utils.NumberUtil;
import net.ess3.nms.refl.ReflUtil;
import net.ess3.nms.updatedmeta.BasePotionDataProvider;
import com.earth2me.essentials.utils.StringUtil;
import net.ess3.api.IEssentials;
import net.ess3.nms.refl.ReflUtil;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.Color;
@ -14,6 +12,7 @@ import org.bukkit.Material;
import org.bukkit.block.Banner;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.*;
import org.bukkit.potion.Potion;
@ -197,7 +196,7 @@ public class ItemDb implements IConf, net.ess3.api.IItemDb {
}
retval = ess.getSpawnEggProvider().createEggItem(type);
} else if (mat.name().endsWith("POTION")
&& ReflUtil.getNmsVersionObject().isLowerThan(ReflUtil.V1_11_R1)) { // Only apply this to pre-1.11 as items.csv might only work in 1.11
&& ReflUtil.getNmsVersionObject().isLowerThan(ReflUtil.V1_11_R1)) { // Only apply this to pre-1.11 as items.csv might only work in 1.11
retval = ess.getPotionMetaProvider().createPotionItem(mat, metaData);
} else {
retval.setDurability(metaData);
@ -308,6 +307,19 @@ public class ItemDb implements IConf, net.ess3.api.IItemDb {
sb.append(e.getName().toLowerCase()).append(":").append(meta.getEnchantLevel(e)).append(" ");
}
}
Set<ItemFlag> flags = meta.getItemFlags();
if (flags != null) {
sb.append("itemflags:");
boolean first = true;
for (ItemFlag flag : flags) {
if (!first) {
sb.append(",");
}
sb.append(flag.name());
first = false;
}
}
}
switch (is.getType()) {

View File

@ -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);

View File

@ -191,6 +191,7 @@ invalidCharge=\u00a74Invalid charge.
invalidFireworkFormat=\u00a74The option \u00a7c{0} \u00a74is not a valid value for \u00a7c{1}\u00a74.
invalidHome=\u00a74Home\u00a7c {0} \u00a74doesn''t exist\!
invalidHomeName=\u00a74Invalid home name\!
invalidItemFlagMeta=\u00a74Invalid itemflag meta\: \u00a7c{0}\u00a74.
invalidMob=\u00a74Invalid mob type.
invalidNumber=Invalid Number.
invalidPotion=\u00a74Invalid Potion.

View File

@ -191,6 +191,7 @@ invalidCharge=\u00a74Neplatny poplatek.
invalidFireworkFormat=\u00a74Nastaveni \u00a7c{0} \u00a74neni platna hodnota pro \u00a7c{1}\u00a74.
invalidHome=\u00a74Domov\u00a7c {0} \u00a74neexistuje\!
invalidHomeName=\u00a74Spatny nazev domova\!
invalidItemFlagMeta=\u00a74Invalid itemflag meta\: \u00a7c{0}\u00a74.
invalidMob=\u00a74Neplatny druh moba\!
invalidNumber=Neplatne cislo.
invalidPotion=\u00a74Spatny lektvar.

View File

@ -191,6 +191,7 @@ invalidCharge=\u00a74Ugyldig ladning.
invalidFireworkFormat=\u00a74Muligheden \u00a7c{0} \u00a74er ikke en gyldig v\u00e6rdi til \u00a7c{1}\u00a74.
invalidHome=\u00a74Hjemmet\u00a7c {0} \u00a74eksisterer ikke\!
invalidHomeName=\u00a74Ugyldigt navn til dit hjem.
invalidItemFlagMeta=\u00a74Invalid itemflag meta\: \u00a7c{0}\u00a74.
invalidMob=\u00a74Ugyldig mob type.
invalidNumber=Ugyldigt nummer.
invalidPotion=\u00a74Ugyldig eliksir.

View File

@ -191,6 +191,7 @@ invalidCharge=\u00a74Ung\u00fcltige Kosten.
invalidFireworkFormat=\u00a76Die Option \u00a74{0} \u00a76ist kein g\u00fcltiger Wert f\u00fcr \u00a74{1}\u00a76.
invalidHome=\u00a74Zuhause\u00a7c {0} \u00a74existiert nicht\!
invalidHomeName=\u00a74Ung\u00fcltiger Name\!
invalidItemFlagMeta=\u00a74Invalid itemflag meta\: \u00a7c{0}\u00a74.
invalidMob=\u00a74Unbekannter Mob-Typ.
invalidNumber=Ung\u00fcltige Nummer.
invalidPotion=\u00a74Ung\u00fcltiger Trank.

View File

@ -191,6 +191,7 @@ invalidCharge=\u00a74Invalid charge.
invalidFireworkFormat=\u00a74The option \u00a7c{0} \u00a74is not a valid value for \u00a7c{1}\u00a74.
invalidHome=\u00a74Home\u00a7c {0} \u00a74doesn''t exist\!
invalidHomeName=\u00a74Invalid home name\!
invalidItemFlagMeta=\u00a74Invalid itemflag meta\: \u00a7c{0}\u00a74.
invalidMob=\u00a74Invalid mob type.
invalidNumber=Invalid Number.
invalidPotion=\u00a74Invalid Potion.

View File

@ -191,6 +191,7 @@ invalidCharge=\u00a74Carga no v\u00e1lida.
invalidFireworkFormat=\u00a74La opci\u00f3n \u00a7c{0} \u00a74no es un valor v\u00e1lido para \u00a7c{1}\u00a74.
invalidHome=\u00a74\u00a1El hogar\u00a7c {0} \u00a74no existe\!
invalidHomeName=\u00a74\u00a1Nombre de hogar inv\u00e1lido\!
invalidItemFlagMeta=\u00a74Invalid itemflag meta\: \u00a7c{0}\u00a74.
invalidMob=\u00a74Tipo de mob inv\u00e1lido.
invalidNumber=N\u00famero inv\u00e1lido.
invalidPotion=\u00a74Poci\u00f3n inv\u00e1lida.

View File

@ -191,6 +191,7 @@ invalidCharge=\u00a74Vigane tasu.
invalidFireworkFormat=\u00a74Valik \u00a7c{0} \u00a74ei ole sobiv v\u00e4\u00e4rtus \u00a7c{1}\u00a74 jaoks.
invalidHome=\u00a74Kodu\u00a7c {0} \u00a74ei ole m\u00e4\u00e4ratud\!
invalidHomeName=\u00a74Vigane kodu nimi\!
invalidItemFlagMeta=\u00a74Invalid itemflag meta\: \u00a7c{0}\u00a74.
invalidMob=\u00a74Kehtetu eluka liik.
invalidNumber=Vigane Number.
invalidPotion=\u00a74Vigane n\u00f5iajook.

View File

@ -191,6 +191,7 @@ invalidCharge=\u00a7cMit\u00e4t\u00f6n m\u00e4\u00e4r\u00e4ys.
invalidFireworkFormat=\u00a74The option \u00a7c{0} \u00a74is not a valid value for \u00a7c{1}\u00a74.
invalidHome=Kotia {0} ei ole olemassa
invalidHomeName=\u00a74Invalid home name\!
invalidItemFlagMeta=\u00a74Invalid itemflag meta\: \u00a7c{0}\u00a74.
invalidMob=\u00a74Invalid mob type.
invalidNumber=Virheellinen numero.
invalidPotion=\u00a74Invalid Potion.

View File

@ -191,6 +191,7 @@ invalidCharge=\u00a7cCharge invalide.
invalidFireworkFormat=\u00a74L''option \u00a7c{0} \u00a74n''est pas une valeur valide pour \u00a7c{1}\u00a74.
invalidHome=La r\u00e9sidence {0} n''existe pas
invalidHomeName=\u00a74Nom de r\u00e9sindence invalide.
invalidItemFlagMeta=\u00a74Invalid itemflag meta\: \u00a7c{0}\u00a74.
invalidMob=\u00a74Type de mob invalide.
invalidNumber=\u00a74Nombre invalide.
invalidPotion=\u00a74Potion invalide.

View File

@ -191,6 +191,7 @@ invalidCharge=\u00a74Invalid charge.
invalidFireworkFormat=\u00a76Ez az opci\u00f3\: \u00a74{0} \u00a76nem \u00e9rv\u00e9nyes \u00a74{1}\u00a76-ra/re.
invalidHome=\u00a74Home\u00a7c {0} \u00a74doesn''t exist\!
invalidHomeName=\u00a74Invalid home name\!
invalidItemFlagMeta=\u00a74Invalid itemflag meta\: \u00a7c{0}\u00a74.
invalidMob=\u00a74Hat\u00e1rozatlan mob t\u00edpus
invalidNumber=Invalid Number.
invalidPotion=\u00a74Invalid Potion.

View File

@ -191,6 +191,7 @@ invalidCharge=\u00a7cCosto non corretto.
invalidFireworkFormat=\u00a74L''opzione \u00a7c{0} \u00a74non \u00e8 un valore valido per \u00a7c{1}\u00a74.
invalidHome=La casa {0} non esiste\!
invalidHomeName=\u00a74Nome casa non valido\!
invalidItemFlagMeta=\u00a74Invalid itemflag meta\: \u00a7c{0}\u00a74.
invalidMob=\u00a74Tipo mob non valido.
invalidNumber=Numero non valido.
invalidPotion=\u00a74Pozione non valida.

View File

@ -191,6 +191,7 @@ invalidCharge=\u00a74Invalid charge.
invalidFireworkFormat=\u00a7c{0} \u00a74\uc635\uc158\uc740 \u00a7c{1} \u00a74\ub77c\ub294 \uac12\uc774 \uc874\uc7ac\ud558\uc9c0 \uc54a\uc2b5\ub2c8\ub2e4.
invalidHome=\u00a7c{0}\u00a74 \uc9d1\uc774 \uc874\uc7ac\ud558\uc9c0\uc54a\uc2b5\ub2c8\ub2e4\!
invalidHomeName=\u00a74\uc9d1 \uc774\ub984\uc774 \ub9de\uc9c0 \uc54a\uc2b5\ub2c8\ub2e4\!
invalidItemFlagMeta=\u00a74Invalid itemflag meta\: \u00a7c{0}\u00a74.
invalidMob=\u00a74\uc798\ubabb\ub41c \ubab9 \ud0c0\uc785\uc785\ub2c8\ub2e4.
invalidNumber=\uc798\ubabb\ub41c \uc22b\uc790\uc785\ub2c8\ub2e4.
invalidPotion=\u00a74\uc798\ubabb\ub41c \ud3ec\uc158.

View File

@ -191,6 +191,7 @@ invalidCharge=\u00a74Invalid charge.
invalidFireworkFormat=\u00a74Pasirinkimas \u00a7c{0} \u00a74n\u0117ra galimas \u00a7c{1}\u00a74.
invalidHome=\u00a74Namas\u00a7c {0} \u00a74neegzistuoja\!
invalidHomeName=\u00a74Neteisingas namo pavadinimas\!
invalidItemFlagMeta=\u00a74Invalid itemflag meta\: \u00a7c{0}\u00a74.
invalidMob=Neteisingas tipas.
invalidNumber=Invalid Number.
invalidPotion=\u00a74Invalid Potion.

View File

@ -191,6 +191,7 @@ invalidCharge=\u00a7cOngeldige prijs.
invalidFireworkFormat=\u00a74De optie \u00a7c{0} \u00a74is geen geldige waarde \u00a7c{1}\u00a74.\n
invalidHome=Home {0} Bestaat niet.
invalidHomeName=\u00a74Ongeldige home naam.
invalidItemFlagMeta=\u00a74Invalid itemflag meta\: \u00a7c{0}\u00a74.
invalidMob=\u00a74Ongeldig mob type.
invalidNumber=Ongeldig Nummer.
invalidPotion=\u00a74Ongeldige Toverdrank.

View File

@ -191,6 +191,7 @@ invalidCharge=\u00a74Nieprawid\u0142owa op\u0142ata.
invalidFireworkFormat=\u00a76Opcja \u00a74{0} \u00a76nie jest prawid\u0142ow\u0105 warto\u015bci\u0105 dla \u00a74{1}\u00a76.
invalidHome=\u00a74Dom\u00a7c {0} \u00a74nie istnieje.
invalidHomeName=\u00a74Niepoprawna nazwa domu.
invalidItemFlagMeta=\u00a74Invalid itemflag meta\: \u00a7c{0}\u00a74.
invalidMob=\u00a74Niepoprawny typ moba.
invalidNumber=Niepoprawna liczba.
invalidPotion=\u00a74Niepoprawna mikstura.

View File

@ -191,6 +191,7 @@ invalidCharge=\u00A74Argumento inv\u00E1lido.
invalidFireworkFormat=\u00A74A op\u00E7\u00E3o \u00A7c{0} \u00A74n\u00E3o \u00E9 v\u00E1lida para \u00A7c{1}\u00A74.
invalidHome=\u00A74A casa\u00A7c {0} \u00A74n\u00E3o existe!
invalidHomeName=\u00A74Nome de casa inv\u00E1lido!
invalidItemFlagMeta=\u00a74Invalid itemflag meta\: \u00a7c{0}\u00a74.
invalidMob=\u00A74Tipo de mob inv\u00E1lido.
invalidNumber=Numero inv\u00E1lido.
invalidPotion=\u00A74Po\u00E7\u00E3o inv\u00E1lida.

View File

@ -191,6 +191,7 @@ invalidCharge=\u00A74Argumento inv\u00E1lido.
invalidFireworkFormat=\u00A74A op\u00E7\u00E3o \u00A7c{0} \u00A74n\u00E3o \u00E9 v\u00E1lida para \u00A7c{1}\u00A74.
invalidHome=\u00A74Casa\u00A7c {0} \u00A74n\u00E3o existe\!
invalidHomeName=\u00A74Nome de casa inv\u00E1lido\!
invalidItemFlagMeta=\u00a74Invalid itemflag meta\: \u00a7c{0}\u00a74.
invalidMob=\u00A74Tipo de mob inv\u00E1lido.
invalidNumber=Numero inv\u00E1lido.
invalidPotion=\u00A74Po\u00E7\u00E3o inv\u00E1lida.

View File

@ -191,6 +191,7 @@ invalidCharge=\u00a74Incarcare invalida.
invalidFireworkFormat=\u00a74The option \u00a7c{0} \u00a74is not a valid value for \u00a7c{1}\u00a74.
invalidHome=\u00a74Casa\u00a7c {0} \u00a74nu exista\!
invalidHomeName=\u00a74Numele casei este invalida\!
invalidItemFlagMeta=\u00a74Invalid itemflag meta\: \u00a7c{0}\u00a74.
invalidMob=Tip de mob invalid.
invalidNumber=Numar invalid.
invalidPotion=\u00a74Potiune invalida.

View File

@ -192,6 +192,7 @@ invalidFireworkFormat=\u00a74\u041e\u043f\u0446\u0438\u044f \u00a7c{0} \u00a74\u
invalidHome=\u00a74\u0414\u043e\u043c\u0430\u00a7c {0} \u00a74\u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442\!
invalidHomeName=\u00a74\u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0434\u043e\u043c\u0430\!
invalidMob=\u00a74\u041d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0439 \u0442\u0438\u043f \u043c\u043e\u0431\u0430.
invalidItemFlagMeta=\u00a74Invalid itemflag meta\: \u00a7c{0}\u00a74.
invalidNumber=\u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e.
invalidPotion=\u00a74\u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0435 \u0437\u0435\u043b\u044c\u0435.
invalidPotionMeta=\u00a74\u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435 \u043c\u0435\u0442\u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0437\u0435\u043b\u044c\u044f\: \u00a7c{0}\u00a74.

View File

@ -191,6 +191,7 @@ invalidCharge=\u00a7cOgiltig laddning.
invalidFireworkFormat=\u00a74V\u00e4rdet \u00a7c{0} \u00a74\u00e4r inte ett korrekt v\u00e4rde f\u00f6r \u00a7c{1}\u00a74.
invalidHome=Hemmet {0} finns inte
invalidHomeName=\u00a74Ogiltigt hemnamn
invalidItemFlagMeta=\u00a74Invalid itemflag meta\: \u00a7c{0}\u00a74.
invalidMob=Ogiltigt mob
invalidNumber=Felaktigt nummer.
invalidPotion=\u00a74Ogiltig brygd.

View File

@ -192,6 +192,7 @@ invalidFireworkFormat=\u00a74Gecersiz Havaifisek Formati\!
invalidHome=\u00a7c {0} \u00a76adli Bir Eviniz Yok\!
invalidHomeName=\u00a7cUygun Olmayan Ev Ismi\!
invalidMob=\u00a74Bilinmeyen Yaratik T\u00fcr\u00fc.
invalidItemFlagMeta=\u00a74Invalid itemflag meta\: \u00a7c{0}\u00a74.
invalidNumber=Gecersiz Numara.
invalidPotion=\u00a74Gecersiz Iksir.
invalidPotionMeta=\u00a74Gecersiz Iksir Turu \u00a7c{0}\u00a74.\n

View File

@ -191,6 +191,7 @@ invalidCharge=\u00a74\u65e0\u6548\u7684\u4ef7\u683c
invalidFireworkFormat=\u00a74\u8fd9\u4e2a\u9009\u9879 \u00a7c{0} \u00a74\u5bf9 \u00a7c{1}\u00a74 \u4e0d\u662f\u4e00\u4e2a\u6709\u6548\u7684\u503c\u00a74.
invalidHome=\u00a74\u5bb6\u00a7c {0} \u00a74\u4e0d\u5b58\u5728\!
invalidHomeName=\u00a74\u65e0\u6548\u7684\u5bb6\u540d\u79f0\!
invalidItemFlagMeta=\u00a74Invalid itemflag meta\: \u00a7c{0}\u00a74.
invalidMob=\u00a74\u65e0\u6548\u7684\u602a\u7269\u7c7b\u578b.
invalidNumber=\u65e0\u6548\u7684\u6570\u5b57.
invalidPotion=\u00a74\u65e0\u6548\u7684\u836f\u6c34.

View File

@ -191,6 +191,7 @@ invalidCharge=\u00a74\u7121\u6548\u7684\u50f9\u683c
invalidFireworkFormat=\u00a74The option \u00a7c{0} \u00a74is not a valid value for \u00a7c{1}\u00a74.
invalidHome=\u00a74\u5bb6\u00a7c {0} \u00a74\u4e0d\u5b58\u5728\!
invalidHomeName=\u00a74\u7121\u6548\u7684\u5bb6\u540d\u7a31\!
invalidItemFlagMeta=\u00a74Invalid itemflag meta\: \u00a7c{0}\u00a74.
invalidMob=\u00a74\u7121\u6548\u751f\u7269\u985e\u578b
invalidNumber=\u7121\u6548\u7684\u6578\u5b57.
invalidPotion=\u00a74\u7121\u6548\u7684\u85e5\u6c34.

View File

@ -191,6 +191,7 @@ invalidCharge=\u00a74\u7121\u6548\u7684\u50f9\u683c
invalidFireworkFormat=\u00a74The option \u00a7c{0} \u00a74is not a valid value for \u00a7c{1}\u00a74.
invalidHome=\u00a74\u5bb6\u00a7c {0} \u00a74\u4e0d\u5b58\u5728\!
invalidHomeName=\u00a74\u7121\u6548\u7684\u5bb6\u540d\u7a31\!
invalidItemFlagMeta=\u00a74Invalid itemflag meta\: \u00a7c{0}\u00a74.
invalidMob=\u00a74\u7121\u6548\u751f\u7269\u985e\u578b
invalidNumber=\u7121\u6548\u7684\u6578\u5b57.
invalidPotion=\u00a74\u7121\u6548\u7684\u85e5\u6c34.