Skip to content

Commit

Permalink
itemtag method minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Dec 27, 2020
1 parent 0275526 commit 0e5137a
Show file tree
Hide file tree
Showing 19 changed files with 53 additions and 53 deletions.
Expand Up @@ -679,7 +679,7 @@ public boolean tryItem(ItemTag item, String comparedto) {
if (comparedto.equals("item")) {
return true;
}
if (comparedto.equals("potion") && CoreUtilities.toLowerCase(item.getItemStack().getType().name()).contains("potion")) {
if (comparedto.equals("potion") && CoreUtilities.toLowerCase(item.getBukkitMaterial().name()).contains("potion")) {
return true;
}
MatchHelper matcher = createMatcher(comparedto);
Expand Down
Expand Up @@ -384,12 +384,16 @@ public void setItemScript(ItemScriptContainer script) {
}
}

public Material getBukkitMaterial() {
return getItemStack().getType();
}

public MaterialTag getMaterial() {
return new MaterialTag(getItemStack().getType());
return new MaterialTag(getBukkitMaterial());
}

public String getMaterialName() {
return CoreUtilities.toLowerCase(getItemStack().getType().name());
return CoreUtilities.toLowerCase(getBukkitMaterial().name());
}

public void setAmount(int value) {
Expand Down Expand Up @@ -653,7 +657,7 @@ public static void registerTags() {
return object;
}
if (object.getItemMeta() instanceof BlockStateMeta) {
if (object.getItemStack().getType() == Material.SHIELD) {
if (object.getBukkitMaterial() == Material.SHIELD) {
MaterialTag material = new MaterialTag(Material.SHIELD);
material.setModernData(new ModernBlockData(((BlockStateMeta) object.getItemMeta()).getBlockState()));
return material;
Expand Down
Expand Up @@ -61,7 +61,7 @@ else if (item.getBukkitEntityType() == EntityType.TRIDENT) {
@Override
public String getPropertyString() {
ItemTag item = getItem();
if (item.getItemStack().getType() != Material.AIR) {
if (item.getBukkitMaterial() != Material.AIR) {
return item.identify();
}
else {
Expand Down
Expand Up @@ -17,7 +17,7 @@ public class ItemBaseColor implements Property {

public static boolean describes(ObjectTag item) {
if (item instanceof ItemTag) {
return ((ItemTag) item).getItemStack().getType() == Material.SHIELD;
return ((ItemTag) item).getBukkitMaterial() == Material.SHIELD;
}
return false;
}
Expand Down Expand Up @@ -48,7 +48,7 @@ private ItemBaseColor(ItemTag item) {
private DyeColor getBaseColor() {
ItemMeta itemMeta = item.getItemMeta();
if (itemMeta instanceof BlockStateMeta) {
if (item.getItemStack().getType() == Material.SHIELD) { // Hack to avoid blank shields misdisplaying as white
if (item.getBukkitMaterial() == Material.SHIELD) { // Hack to avoid blank shields misdisplaying as white
if (!itemMeta.serialize().containsKey("internal")) {
return null;
}
Expand Down
Expand Up @@ -57,7 +57,7 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
if (attribute.startsWith("block_material")) {
BlockDataMeta meta = (BlockDataMeta) item.getItemMeta();
if (meta.hasBlockData()) {
return new MaterialTag(new ModernBlockData(meta.getBlockData(item.getItemStack().getType())))
return new MaterialTag(new ModernBlockData(meta.getBlockData(item.getBukkitMaterial())))
.getObjectAttribute(attribute.fulfill(1));
}
}
Expand All @@ -69,7 +69,7 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
public String getPropertyString() {
BlockDataMeta meta = (BlockDataMeta) item.getItemMeta();
if (meta.hasBlockData()) {
return new MaterialTag(new ModernBlockData(meta.getBlockData(item.getItemStack().getType()))).identify();
return new MaterialTag(new ModernBlockData(meta.getBlockData(item.getBukkitMaterial()))).identify();
}
return null;
}
Expand Down
Expand Up @@ -24,7 +24,7 @@
public class ItemBook implements Property {

public static boolean describes(ObjectTag item) {
Material material = ((ItemTag) item).getItemStack().getType();
Material material = ((ItemTag) item).getBukkitMaterial();
return (material == Material.WRITTEN_BOOK || material == Material.WRITABLE_BOOK);
}

Expand Down Expand Up @@ -70,7 +70,7 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
// @description
// Returns the author of the book.
// -->
if (attribute.startsWith("book_author") && item.getItemStack().getType() == Material.WRITTEN_BOOK) {
if (attribute.startsWith("book_author") && item.getBukkitMaterial() == Material.WRITTEN_BOOK) {
return new ElementTag(getBookInfo().getAuthor())
.getObjectAttribute(attribute.fulfill(1));
}
Expand All @@ -83,7 +83,7 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
// @description
// Returns the title of the book.
// -->
if (attribute.startsWith("book_title") && item.getItemStack().getType() == Material.WRITTEN_BOOK) {
if (attribute.startsWith("book_title") && item.getBukkitMaterial() == Material.WRITTEN_BOOK) {
return new ElementTag(getBookInfo().getTitle())
.getObjectAttribute(attribute.fulfill(1));
}
Expand Down Expand Up @@ -121,7 +121,7 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
BookMeta bookInfo = (BookMeta) item.getItemMeta();
attribute = attribute.fulfill(1);

if (item.getItemStack().getType() == Material.WRITTEN_BOOK) {
if (item.getBukkitMaterial() == Material.WRITTEN_BOOK) {
if (attribute.startsWith("author")) {
return new ElementTag(bookInfo.getAuthor())
.getObjectAttribute(attribute.fulfill(1));
Expand Down Expand Up @@ -179,7 +179,7 @@ public String getPropertyString() {
public MapTag getBookMap() {
MapTag outMap = new MapTag();
BookMeta bookInfo = (BookMeta) item.getItemMeta();
if (item.getItemStack().getType().equals(Material.WRITTEN_BOOK) && bookInfo.hasAuthor() && bookInfo.hasTitle()) {
if (item.getBukkitMaterial().equals(Material.WRITTEN_BOOK) && bookInfo.hasAuthor() && bookInfo.hasTitle()) {
outMap.putObject("author", new ElementTag(bookInfo.getAuthor()));
outMap.putObject("title", new ElementTag(bookInfo.getTitle()));
}
Expand All @@ -198,7 +198,7 @@ public MapTag getBookMap() {
public String getOutputString() {
StringBuilder output = new StringBuilder(128);
BookMeta bookInfo = (BookMeta) item.getItemMeta();
if (item.getItemStack().getType().equals(Material.WRITTEN_BOOK) && bookInfo.hasAuthor() && bookInfo.hasTitle()) {
if (item.getBukkitMaterial().equals(Material.WRITTEN_BOOK) && bookInfo.hasAuthor() && bookInfo.hasTitle()) {
output.append("author|").append(EscapeTagBase.escape(bookInfo.getAuthor()))
.append("|title|").append(EscapeTagBase.escape(bookInfo.getTitle())).append("|");
}
Expand Down Expand Up @@ -262,7 +262,7 @@ public void adjust(Mechanism mechanism) {
// <ItemTag.book_author>
// -->
if (mechanism.matches("book_author")) {
if (!item.getItemStack().getType().equals(Material.WRITTEN_BOOK)) {
if (!item.getBukkitMaterial().equals(Material.WRITTEN_BOOK)) {
Debug.echoError("Only WRITTEN_BOOK (not WRITABLE_BOOK) can have a title or author!");
}
else {
Expand All @@ -282,7 +282,7 @@ public void adjust(Mechanism mechanism) {
// <ItemTag.book_title>
// -->
if (mechanism.matches("book_title")) {
if (!item.getItemStack().getType().equals(Material.WRITTEN_BOOK)) {
if (!item.getBukkitMaterial().equals(Material.WRITTEN_BOOK)) {
Debug.echoError("Only WRITTEN_BOOK (not WRITABLE_BOOK) can have a title or author!");
}
else {
Expand Down Expand Up @@ -312,7 +312,7 @@ public void adjust(Mechanism mechanism) {
ObjectTag author = mapData.getObject("author");
ObjectTag title = mapData.getObject("title");
if (author != null && title != null) {
if (!item.getItemStack().getType().equals(Material.WRITTEN_BOOK)) {
if (!item.getBukkitMaterial().equals(Material.WRITTEN_BOOK)) {
Debug.echoError("Only WRITTEN_BOOK (not WRITABLE_BOOK) can have a title or author!");
}
else {
Expand Down Expand Up @@ -343,7 +343,7 @@ public void adjust(Mechanism mechanism) {
}
if (data.size() > 4 && data.get(0).equalsIgnoreCase("author")
&& data.get(2).equalsIgnoreCase("title")) {
if (!item.getItemStack().getType().equals(Material.WRITTEN_BOOK)) {
if (!item.getBukkitMaterial().equals(Material.WRITTEN_BOOK)) {
Debug.echoError("Only WRITTEN_BOOK (not WRITABLE_BOOK) can have a title or author!");
}
else {
Expand Down
Expand Up @@ -12,7 +12,7 @@
public class ItemBookGeneration implements Property {

public static boolean describes(ObjectTag item) {
return item instanceof ItemTag && ((ItemTag) item).getItemStack().getType() == Material.WRITTEN_BOOK;
return item instanceof ItemTag && ((ItemTag) item).getBukkitMaterial() == Material.WRITTEN_BOOK;
}

public static ItemBookGeneration getFrom(ObjectTag _item) {
Expand Down
Expand Up @@ -16,7 +16,7 @@ public class ItemChargedProjectile implements Property {

public static boolean describes(ObjectTag item) {
return item instanceof ItemTag
&& ((ItemTag) item).getItemStack().getType() == Material.CROSSBOW;
&& ((ItemTag) item).getBukkitMaterial() == Material.CROSSBOW;
}

public static ItemChargedProjectile getFrom(ObjectTag item) {
Expand Down
Expand Up @@ -16,13 +16,13 @@ public class ItemColor implements Property {
public static boolean describes(ObjectTag item) {
// Leather armor and potions
return item instanceof ItemTag
&& (((ItemTag) item).getItemStack().getType() == Material.LEATHER_BOOTS
|| ((ItemTag) item).getItemStack().getType() == Material.LEATHER_CHESTPLATE
|| ((ItemTag) item).getItemStack().getType() == Material.LEATHER_HELMET
|| ((ItemTag) item).getItemStack().getType() == Material.LEATHER_LEGGINGS
|| ((ItemTag) item).getItemStack().getType() == Material.POTION
|| ((ItemTag) item).getItemStack().getType() == Material.SPLASH_POTION
|| ((ItemTag) item).getItemStack().getType() == Material.LINGERING_POTION);
&& (((ItemTag) item).getBukkitMaterial() == Material.LEATHER_BOOTS
|| ((ItemTag) item).getBukkitMaterial() == Material.LEATHER_CHESTPLATE
|| ((ItemTag) item).getBukkitMaterial() == Material.LEATHER_HELMET
|| ((ItemTag) item).getBukkitMaterial() == Material.LEATHER_LEGGINGS
|| ((ItemTag) item).getBukkitMaterial() == Material.POTION
|| ((ItemTag) item).getBukkitMaterial() == Material.SPLASH_POTION
|| ((ItemTag) item).getBukkitMaterial() == Material.LINGERING_POTION);
}

public static ItemColor getFrom(ObjectTag _item) {
Expand Down Expand Up @@ -64,7 +64,7 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
// Returns the color of the leather armor item or potion item.
// -->
if (attribute.startsWith("color") || attribute.startsWith("dye_color")) {
Material mat = item.getItemStack().getType();
Material mat = item.getBukkitMaterial();
if (mat == Material.POTION
|| mat == Material.LINGERING_POTION
|| mat == Material.SPLASH_POTION) {
Expand All @@ -82,7 +82,7 @@ public ObjectTag getObjectAttribute(Attribute attribute) {

@Override
public String getPropertyString() {
Material mat = item.getItemStack().getType();
Material mat = item.getBukkitMaterial();
if (mat == Material.POTION
|| mat == Material.LINGERING_POTION
|| mat == Material.SPLASH_POTION) {
Expand Down Expand Up @@ -115,7 +115,7 @@ public void adjust(Mechanism mechanism) {
if ((mechanism.matches("dye") || mechanism.matches("dye_color")
|| mechanism.matches("color")) && (mechanism.requireObject(ColorTag.class))) {
ColorTag color = mechanism.valueAsType(ColorTag.class);
Material mat = item.getItemStack().getType();
Material mat = item.getBukkitMaterial();
if (mat == Material.POTION || mat == Material.LINGERING_POTION || mat == Material.SPLASH_POTION) {
PotionMeta meta = (PotionMeta) item.getItemMeta();
meta.setColor(color.getColor());
Expand Down
Expand Up @@ -194,7 +194,7 @@ public void adjust(Mechanism mechanism) {
names.add(CoreUtilities.toLowerCase(ench));
}
}
if (item.getItemStack().getType() == Material.ENCHANTED_BOOK) {
if (item.getBukkitMaterial() == Material.ENCHANTED_BOOK) {
EnchantmentStorageMeta meta = (EnchantmentStorageMeta) item.getItemMeta();
for (Enchantment ench : new ArrayList<>(meta.getStoredEnchants().keySet())) {
if (names == null || names.contains(CoreUtilities.toLowerCase(ench.getName())) ||
Expand Down Expand Up @@ -231,7 +231,7 @@ public void adjust(Mechanism mechanism) {
Enchantment ench = Utilities.getEnchantmentByName(enchantments.getKey().low);
int level = enchantments.getValue().asType(ElementTag.class, mechanism.context).asInt();
if (ench != null) {
if (item.getItemStack().getType() == Material.ENCHANTED_BOOK) {
if (item.getBukkitMaterial() == Material.ENCHANTED_BOOK) {
EnchantmentStorageMeta meta = (EnchantmentStorageMeta) item.getItemMeta();
meta.addStoredEnchant(ench, level, true);
item.setItemMeta(meta);
Expand All @@ -256,7 +256,7 @@ public void adjust(Mechanism mechanism) {
try {
Enchantment ench = Utilities.getEnchantmentByName(data[0]);
if (ench != null) {
if (item.getItemStack().getType() == Material.ENCHANTED_BOOK) {
if (item.getBukkitMaterial() == Material.ENCHANTED_BOOK) {
EnchantmentStorageMeta meta = (EnchantmentStorageMeta) item.getItemMeta();
meta.addStoredEnchant(ench, Integer.valueOf(data[1]), true);
item.setItemMeta(meta);
Expand Down
Expand Up @@ -15,7 +15,7 @@ public class ItemHidden implements Property {

public static boolean describes(ObjectTag item) {
// All items can have hides
return item instanceof ItemTag && ((ItemTag) item).getItemStack().getType() != Material.AIR;
return item instanceof ItemTag && ((ItemTag) item).getBukkitMaterial() != Material.AIR;
}

public static ItemHidden getFrom(ObjectTag _item) {
Expand Down
Expand Up @@ -17,7 +17,7 @@
public class ItemKnowledgeBookRecipes implements Property {

public static boolean describes(ObjectTag item) {
return item instanceof ItemTag && ((ItemTag) item).getItemStack().getType() == Material.KNOWLEDGE_BOOK;
return item instanceof ItemTag && ((ItemTag) item).getBukkitMaterial() == Material.KNOWLEDGE_BOOK;
}

public static ItemKnowledgeBookRecipes getFrom(ObjectTag _item) {
Expand Down
Expand Up @@ -15,7 +15,7 @@ public class ItemMap implements Property {

public static boolean describes(ObjectTag item) {
return item instanceof ItemTag
&& (((ItemTag) item).getItemStack().getType() == MAP_MATERIAL);
&& (((ItemTag) item).getBukkitMaterial() == MAP_MATERIAL);
}

public static ItemMap getFrom(ObjectTag _item) {
Expand Down
Expand Up @@ -25,7 +25,7 @@ public class ItemPatterns implements Property {

public static boolean describes(ObjectTag item) {
if (item instanceof ItemTag) {
Material material = ((ItemTag) item).getItemStack().getType();
Material material = ((ItemTag) item).getBukkitMaterial();
return MaterialCompat.isBannerOrShield(material);
}
return false;
Expand Down
Expand Up @@ -24,10 +24,10 @@ public class ItemPotion implements Property {

public static boolean describes(ObjectTag item) {
return item instanceof ItemTag
&& (((ItemTag) item).getItemStack().getType() == Material.POTION
|| ((ItemTag) item).getItemStack().getType() == Material.SPLASH_POTION
|| ((ItemTag) item).getItemStack().getType() == Material.LINGERING_POTION
|| ((ItemTag) item).getItemStack().getType() == Material.TIPPED_ARROW);
&& (((ItemTag) item).getBukkitMaterial() == Material.POTION
|| ((ItemTag) item).getBukkitMaterial() == Material.SPLASH_POTION
|| ((ItemTag) item).getBukkitMaterial() == Material.LINGERING_POTION
|| ((ItemTag) item).getBukkitMaterial() == Material.TIPPED_ARROW);
}

public static ItemPotion getFrom(ObjectTag _item) {
Expand Down Expand Up @@ -148,7 +148,7 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
if (attribute.startsWith("potion_base") && item.getItemMeta() instanceof PotionMeta) {
PotionMeta meta = ((PotionMeta) item.getItemMeta());
return new ElementTag(meta.getBasePotionData().getType().name() + "," + (meta.getBasePotionData().isUpgraded() ? 2 : 1)
+ "," + meta.getBasePotionData().isExtended() + "," + (item.getItemStack().getType() == Material.SPLASH_POTION)
+ "," + meta.getBasePotionData().isExtended() + "," + (item.getBukkitMaterial() == Material.SPLASH_POTION)
+ (meta.hasColor() ? "," + new ColorTag(meta.getColor()).identify() : "")
).getObjectAttribute(attribute.fulfill(1));
}
Expand Down Expand Up @@ -203,7 +203,7 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
// Returns whether the potion is a splash potion.
// -->
if (attribute.startsWith("is_splash")) {
return new ElementTag(item.getItemStack().getType() == Material.SPLASH_POTION)
return new ElementTag(item.getBukkitMaterial() == Material.SPLASH_POTION)
.getObjectAttribute(attribute.fulfill(1));
}

Expand Down Expand Up @@ -327,7 +327,7 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
// In the format Effect,Level,Extended,Splash
// -->
return new ElementTag(meta.getBasePotionData().getType().name() + "," + (meta.getBasePotionData().isUpgraded() ? 2 : 1)
+ "," + meta.getBasePotionData().isExtended() + "," + (item.getItemStack().getType() == Material.SPLASH_POTION))
+ "," + meta.getBasePotionData().isExtended() + "," + (item.getBukkitMaterial() == Material.SPLASH_POTION))
.getObjectAttribute(attribute);
}
}
Expand Down

0 comments on commit 0e5137a

Please sign in to comment.