|
| 1 | +package me.asleepp.SkriptItemsAdder.elements.effects; |
| 2 | + |
| 3 | +import ch.njol.skript.Skript; |
| 4 | +import ch.njol.skript.doc.Description; |
| 5 | +import ch.njol.skript.doc.Examples; |
| 6 | +import ch.njol.skript.doc.Name; |
| 7 | +import ch.njol.skript.doc.RequiredPlugins; |
| 8 | +import ch.njol.skript.doc.Since; |
| 9 | +import ch.njol.skript.lang.Effect; |
| 10 | +import ch.njol.skript.lang.Expression; |
| 11 | +import ch.njol.skript.lang.SkriptParser; |
| 12 | +import ch.njol.util.Kleenean; |
| 13 | +import dev.lone.itemsadder.api.CustomBlock; |
| 14 | + |
| 15 | +import org.bukkit.block.Block; |
| 16 | +import org.bukkit.event.Event; |
| 17 | + |
| 18 | +import javax.annotation.Nullable; |
| 19 | + |
| 20 | +@Name("Play Break Effect") |
| 21 | +@Description("Plays the breaking effect on an ItemsAdder block, (not the cracking in case you were wondering.)") |
| 22 | +@Examples("play break effect on target block") |
| 23 | +@Since("1.5") |
| 24 | +@RequiredPlugins("ItemsAdder") |
| 25 | +public class EffPlayBreakEffect extends Effect { |
| 26 | + |
| 27 | + private Expression<Block> blocks; |
| 28 | + |
| 29 | + static { |
| 30 | + Skript.registerEffect(EffPlayBreakEffect.class, "(show|play) break[ing] effect on [custom|ia|itemsadder] %blocks%"); |
| 31 | + } |
| 32 | + |
| 33 | + @SuppressWarnings("unchecked") |
| 34 | + @Override |
| 35 | + public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { |
| 36 | + blocks = (Expression<Block>) exprs[0]; |
| 37 | + return true; |
| 38 | + } |
| 39 | + |
| 40 | + @Override |
| 41 | + protected void execute(Event e) { |
| 42 | + Block[] blocksArray = blocks.getArray(e); |
| 43 | + for (Block block : blocksArray) { |
| 44 | + CustomBlock customBlock = CustomBlock.byAlreadyPlaced(block); |
| 45 | + if (customBlock != null) { |
| 46 | + customBlock.playBreakEffect(block); |
| 47 | + } |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + @Override |
| 52 | + public String toString(@Nullable Event e, boolean debug) { |
| 53 | + return "(show|play) break[ing] effect on " + blocks.toString(e, debug); |
| 54 | + } |
| 55 | +} |
0 commit comments