|
1 | | -package ch.njol.skript.effects; |
| 1 | +package org.skriptlang.skript.bukkit.misc.effects; |
2 | 2 |
|
3 | | -import org.bukkit.Location; |
4 | | -import org.bukkit.event.Event; |
5 | | -import org.jetbrains.annotations.Nullable; |
6 | | - |
7 | | -import ch.njol.skript.Skript; |
8 | 3 | import ch.njol.skript.doc.Description; |
9 | 4 | import ch.njol.skript.doc.Example; |
10 | 5 | import ch.njol.skript.doc.Name; |
|
15 | 10 | import ch.njol.skript.util.Direction; |
16 | 11 | import ch.njol.skript.util.StructureType; |
17 | 12 | import ch.njol.util.Kleenean; |
| 13 | +import org.bukkit.Location; |
| 14 | +import org.bukkit.event.Event; |
| 15 | +import org.jetbrains.annotations.Nullable; |
| 16 | +import org.skriptlang.skript.registration.SyntaxInfo; |
| 17 | +import org.skriptlang.skript.registration.SyntaxRegistry; |
18 | 18 |
|
19 | | -/** |
20 | | - * @author Peter Güttinger |
21 | | - */ |
22 | 19 | @Name("Tree") |
23 | 20 | @Description({"Creates a tree.", |
24 | 21 | "This may require that there is enough space above the given location and that the block below is dirt/grass, but it is possible that the tree will just grow anyways, possibly replacing every block in its path."}) |
25 | 22 | @Example("grow a tall redwood tree above the clicked block") |
26 | 23 | @Since("1.0") |
27 | 24 | public class EffTree extends Effect { |
28 | | - |
29 | | - static { |
30 | | - Skript.registerEffect(EffTree.class, |
31 | | - "(grow|create|generate) tree [of type %structuretype%] %directions% %locations%", |
32 | | - "(grow|create|generate) %structuretype% %directions% %locations%"); |
| 25 | + |
| 26 | + public static void register(SyntaxRegistry registry) { |
| 27 | + registry.register( |
| 28 | + SyntaxRegistry.EFFECT, |
| 29 | + SyntaxInfo.builder(EffTree.class) |
| 30 | + .addPattern("(grow|create|generate) tree [of type %structuretype%] %directions% %locations%") |
| 31 | + .addPattern("(grow|create|generate) %structuretype% %directions% %locations%") |
| 32 | + .supplier(EffTree::new) |
| 33 | + .priority(SyntaxInfo.PATTERN_MATCHES_EVERYTHING) |
| 34 | + .build() |
| 35 | + ); |
33 | 36 | } |
34 | | - |
35 | | - @SuppressWarnings("null") |
| 37 | + |
36 | 38 | private Expression<Location> blocks; |
37 | | - @SuppressWarnings("null") |
38 | 39 | private Expression<StructureType> type; |
39 | | - |
40 | | - @SuppressWarnings({"unchecked", "null"}) |
| 40 | + |
41 | 41 | @Override |
42 | | - public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parser) { |
| 42 | + @SuppressWarnings("unchecked") |
| 43 | + public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parser) { |
43 | 44 | type = (Expression<StructureType>) exprs[0]; |
44 | 45 | blocks = Direction.combine((Expression<? extends Direction>) exprs[1], (Expression<? extends Location>) exprs[2]); |
45 | 46 | return true; |
46 | 47 | } |
47 | 48 |
|
48 | 49 | @Override |
49 | | - public void execute(final Event e) { |
50 | | - final StructureType type = this.type.getSingle(e); |
| 50 | + public void execute(Event event) { |
| 51 | + StructureType type = this.type.getSingle(event); |
51 | 52 | if (type == null) |
52 | 53 | return; |
53 | | - for (final Location l : blocks.getArray(e)) { |
54 | | - assert l != null : blocks; |
55 | | - type.grow(l.getBlock()); |
| 54 | + for (Location location : blocks.getArray(event)) { |
| 55 | + assert location != null : blocks; |
| 56 | + type.grow(location.getBlock()); |
56 | 57 | } |
57 | 58 | } |
58 | 59 |
|
59 | 60 | @Override |
60 | | - public String toString(final @Nullable Event e, final boolean debug) { |
61 | | - return "grow tree of type " + type.toString(e, debug) + " " + blocks.toString(e, debug); |
| 61 | + public String toString(@Nullable Event event, boolean debug) { |
| 62 | + return "grow tree of type " + type.toString(event, debug) + " " + blocks.toString(event, debug); |
62 | 63 | } |
63 | 64 |
|
64 | 65 | } |
0 commit comments