|
| 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.Since; |
| 8 | +import ch.njol.skript.lang.Effect; |
| 9 | +import ch.njol.skript.lang.Expression; |
| 10 | +import ch.njol.skript.lang.SkriptParser; |
| 11 | +import ch.njol.util.Kleenean; |
| 12 | +import org.bukkit.event.Event; |
| 13 | +import dev.lone.itemsadder.api.CustomFurniture; |
| 14 | +import org.bukkit.Location; |
| 15 | + |
| 16 | +import javax.annotation.Nullable; |
| 17 | + |
| 18 | +@Name("Replace Custom Furniture") |
| 19 | +@Description({"Replace a custom furniture at a location."}) |
| 20 | +@Examples({"replace custom furniture \"comfy_chair\" at player's location"}) |
| 21 | +@Since("1.4") |
| 22 | +public class EffReplaceCustomFurniture extends Effect { |
| 23 | + |
| 24 | + private Expression<String> furnitureId; |
| 25 | + private Expression<Location> location; |
| 26 | + |
| 27 | + static { |
| 28 | + Skript.registerEffect(EffReplaceCustomFurniture.class, "replace (custom|ia|itemsadder) furniture %string% at %location%"); |
| 29 | + } |
| 30 | + |
| 31 | + @Override |
| 32 | + protected void execute(Event e) { |
| 33 | + String id = furnitureId.getSingle(e); |
| 34 | + Location loc = location.getSingle(e); |
| 35 | + |
| 36 | + if (id != null && loc != null) { |
| 37 | + CustomFurniture existingFurniture = CustomFurniture.byAlreadySpawned(loc.getBlock()); |
| 38 | + |
| 39 | + if (existingFurniture != null) { |
| 40 | + existingFurniture.remove(false); |
| 41 | + } |
| 42 | + CustomFurniture.spawn(id, loc.getBlock()); |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + @Override |
| 47 | + public String toString(@Nullable Event e, boolean debug) { |
| 48 | + return "replace (custom|ia|itemsadder) furniture " + furnitureId.toString(e, debug) + " at " + location.toString(e, debug); |
| 49 | + } |
| 50 | + |
| 51 | + @Override |
| 52 | + public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { |
| 53 | + furnitureId = (Expression<String>) exprs[0]; |
| 54 | + location = (Expression<Location>) exprs[1]; |
| 55 | + return true; |
| 56 | + } |
| 57 | +} |
0 commit comments