Skip to content

Commit 03da8b6

Browse files
committed
reduce priority of EffTree and modernize a bit
1 parent 571c281 commit 03da8b6

2 files changed

Lines changed: 30 additions & 27 deletions

File tree

src/main/java/org/skriptlang/skript/bukkit/misc/MiscModule.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.skriptlang.skript.addon.AddonModule;
44
import org.skriptlang.skript.addon.SkriptAddon;
5+
import org.skriptlang.skript.bukkit.misc.effects.EffTree;
56
import org.skriptlang.skript.bukkit.misc.expressions.ExprWithYawPitch;
67
import org.skriptlang.skript.registration.SyntaxRegistry;
78

@@ -11,6 +12,7 @@ public class MiscModule implements AddonModule {
1112
public void load(SkriptAddon addon) {
1213
SyntaxRegistry registry = addon.syntaxRegistry();
1314
ExprWithYawPitch.register(registry);
15+
EffTree.register(registry);
1416
}
1517

1618
@Override

src/main/java/ch/njol/skript/effects/EffTree.java renamed to src/main/java/org/skriptlang/skript/bukkit/misc/effects/EffTree.java

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
package ch.njol.skript.effects;
1+
package org.skriptlang.skript.bukkit.misc.effects;
22

3-
import org.bukkit.Location;
4-
import org.bukkit.event.Event;
5-
import org.jetbrains.annotations.Nullable;
6-
7-
import ch.njol.skript.Skript;
83
import ch.njol.skript.doc.Description;
94
import ch.njol.skript.doc.Example;
105
import ch.njol.skript.doc.Name;
@@ -15,50 +10,56 @@
1510
import ch.njol.skript.util.Direction;
1611
import ch.njol.skript.util.StructureType;
1712
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;
1818

19-
/**
20-
* @author Peter Güttinger
21-
*/
2219
@Name("Tree")
2320
@Description({"Creates a tree.",
2421
"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."})
2522
@Example("grow a tall redwood tree above the clicked block")
2623
@Since("1.0")
2724
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+
);
3336
}
34-
35-
@SuppressWarnings("null")
37+
3638
private Expression<Location> blocks;
37-
@SuppressWarnings("null")
3839
private Expression<StructureType> type;
39-
40-
@SuppressWarnings({"unchecked", "null"})
40+
4141
@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) {
4344
type = (Expression<StructureType>) exprs[0];
4445
blocks = Direction.combine((Expression<? extends Direction>) exprs[1], (Expression<? extends Location>) exprs[2]);
4546
return true;
4647
}
4748

4849
@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);
5152
if (type == null)
5253
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());
5657
}
5758
}
5859

5960
@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);
6263
}
6364

6465
}

0 commit comments

Comments
 (0)