diff --git a/src/main/java/com/shanebeestudios/skbee/elements/display/expressions/ExprBlockDisplayItemType.java b/src/main/java/com/shanebeestudios/skbee/elements/display/expressions/ExprBlockDisplayItemType.java deleted file mode 100644 index 617bc1348..000000000 --- a/src/main/java/com/shanebeestudios/skbee/elements/display/expressions/ExprBlockDisplayItemType.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.shanebeestudios.skbee.elements.display.expressions; - -import ch.njol.skript.aliases.ItemType; -import ch.njol.skript.classes.Changer.ChangeMode; -import ch.njol.skript.doc.Description; -import ch.njol.skript.doc.Examples; -import ch.njol.skript.doc.Name; -import ch.njol.skript.doc.Since; -import ch.njol.skript.expressions.base.SimplePropertyExpression; -import ch.njol.util.coll.CollectionUtils; -import com.shanebeestudios.skbee.elements.display.types.Types; -import org.bukkit.Material; -import org.bukkit.block.data.BlockData; -import org.bukkit.entity.BlockDisplay; -import org.bukkit.entity.Entity; -import org.bukkit.event.Event; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -@Name("DisplayEntity - Block Display Item Type") -@Description({"Represents the block type of a Block Display Entity.", - "I HIGHLY recommend not using this, use the block data method instead.", Types.McWIKI}) -@Examples("set display block item type of {_omgPleaseStopUsingItemTypesForThisPleaseUseBlockDataInstead} to diamond ore") -@Since("2.8.0") -public class ExprBlockDisplayItemType extends SimplePropertyExpression { - - private static final BlockData STONE = Material.STONE.createBlockData(); - - static { - register(ExprBlockDisplayItemType.class, ItemType.class, - "display block item[ ]type", "entities"); - } - - @Override - public @Nullable ItemType convert(Entity entity) { - if (entity instanceof BlockDisplay blockDisplay) { - return new ItemType(blockDisplay.getBlock().getMaterial()); - } - return null; - } - - @SuppressWarnings("NullableProblems") - @Override - public @Nullable Class[] acceptChange(ChangeMode mode) { - if (mode == ChangeMode.SET) return CollectionUtils.array(ItemType.class); - return null; - } - - @SuppressWarnings({"NullableProblems", "ConstantValue"}) - @Override - public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { - if (delta != null && delta[0] instanceof ItemType itemType) { - Material material = itemType.getMaterial(); - BlockData blockData = material.isBlock() ? material.createBlockData() : STONE; - for (Entity entity : getExpr().getArray(event)) { - if (entity instanceof BlockDisplay blockDisplay) { - blockDisplay.setBlock(blockData); - } - } - } - } - - @Override - public @NotNull Class getReturnType() { - return ItemType.class; - } - - @Override - protected @NotNull String getPropertyName() { - return "display block item type"; - } - -} diff --git a/src/main/java/com/shanebeestudios/skbee/elements/display/expressions/ExprItemDisplayItem.java b/src/main/java/com/shanebeestudios/skbee/elements/display/expressions/ExprItemDisplayItem.java index 028eba0f3..72323e96f 100644 --- a/src/main/java/com/shanebeestudios/skbee/elements/display/expressions/ExprItemDisplayItem.java +++ b/src/main/java/com/shanebeestudios/skbee/elements/display/expressions/ExprItemDisplayItem.java @@ -9,6 +9,9 @@ import ch.njol.skript.expressions.base.SimplePropertyExpression; import ch.njol.util.coll.CollectionUtils; import com.shanebeestudios.skbee.elements.display.types.Types; +import org.bukkit.Material; +import org.bukkit.block.data.BlockData; +import org.bukkit.entity.BlockDisplay; import org.bukkit.entity.Entity; import org.bukkit.entity.ItemDisplay; import org.bukkit.event.Event; @@ -17,29 +20,33 @@ import org.jetbrains.annotations.Nullable; @Name("DisplayEntity - Display Item") -@Description({"Represents the display item of an Item Display Entity", Types.McWIKI}) +@Description({"Represents the display ItemType of an Item/Block Display Entity", Types.McWIKI}) @Examples({"set display item of {_display} to diamond sword", - "set display item of {_display} to air", - "delete display item of {_display}"}) + "set display item of {_display} to air", + "delete display item of {_display}"}) @Since("2.8.0") public class ExprItemDisplayItem extends SimplePropertyExpression { static { - register(ExprItemDisplayItem.class, ItemType.class, "display item", "entities"); + register(ExprItemDisplayItem.class, ItemType.class, "display item[[ ]type]", "entities"); } + @SuppressWarnings("ConstantValue") @Override public @Nullable ItemType convert(Entity entity) { + ItemType itemType = null; if (entity instanceof ItemDisplay itemDisplay) { ItemStack itemStack = itemDisplay.getItemStack(); - if (itemStack != null) return new ItemType(itemStack); + if (itemStack != null) itemType = new ItemType(itemStack); + } else if (entity instanceof BlockDisplay blockDisplay) { + itemType = new ItemType(blockDisplay.getBlock().getMaterial()); } - return null; + return itemType; } @SuppressWarnings("NullableProblems") @Override - public @Nullable Class[] acceptChange(ChangeMode mode) { + public Class @Nullable [] acceptChange(ChangeMode mode) { if (mode == ChangeMode.SET || mode == ChangeMode.DELETE) return CollectionUtils.array(ItemType.class); return null; } @@ -49,9 +56,16 @@ public class ExprItemDisplayItem extends SimplePropertyExpression