Skip to content

Commit 41e50e9

Browse files
committed
Changed to use 2.15 registersyntax system and moved from simplevents and expressions into bukkit/entity/
1 parent 942d51e commit 41e50e9

3 files changed

Lines changed: 194 additions & 1 deletion

File tree

src/main/java/org/skriptlang/skript/bukkit/entity/EntityModule.java

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,27 @@
22

33
import ch.njol.skript.Skript;
44
import ch.njol.skript.entity.SimpleEntityData;
5+
import ch.njol.skript.lang.util.SimpleEvent;
6+
import com.destroystokyo.paper.event.entity.EntityPathfindEvent;
7+
import io.papermc.paper.event.player.AsyncChatEvent;
8+
import org.bukkit.Location;
59
import org.bukkit.entity.AbstractNautilus;
10+
import org.bukkit.entity.Entity;
611
import org.skriptlang.skript.addon.AddonModule;
712
import org.skriptlang.skript.addon.HierarchicalAddonModule;
813
import org.skriptlang.skript.addon.SkriptAddon;
914
import org.skriptlang.skript.bukkit.entity.displays.DisplayModule;
15+
import org.skriptlang.skript.bukkit.entity.elements.expressions.ExprPathfindingLocation;
16+
import org.skriptlang.skript.bukkit.entity.elements.expressions.ExprPathfindingTarget;
1017
import org.skriptlang.skript.bukkit.entity.interactions.InteractionModule;
1118
import org.skriptlang.skript.bukkit.entity.elements.expressions.ExprDeathMessage;
1219
import org.skriptlang.skript.bukkit.entity.entitydata.NautilusData;
1320
import org.skriptlang.skript.bukkit.entity.entitydata.ZombieNautilusData;
1421
import org.skriptlang.skript.bukkit.entity.player.PlayerModule;
22+
import org.skriptlang.skript.bukkit.lang.eventvalue.EventValue;
23+
import org.skriptlang.skript.bukkit.lang.eventvalue.EventValueRegistry;
24+
import org.skriptlang.skript.bukkit.registration.BukkitSyntaxInfos;
25+
import org.skriptlang.skript.registration.SyntaxRegistry;
1526

1627
import java.util.List;
1728

@@ -36,7 +47,33 @@ protected void loadSelf(SkriptAddon addon) {
3647
ZombieNautilusData.register();
3748
SimpleEntityData.addSuperEntity("any nautilus", AbstractNautilus.class);
3849
}
39-
50+
SyntaxRegistry syntaxRegistry = moduleRegistry(addon);
51+
EventValueRegistry registry = addon.registry(EventValueRegistry.class);
52+
syntaxRegistry.register(BukkitSyntaxInfos.Event.KEY, BukkitSyntaxInfos.Event.builder(SimpleEvent.class, "PathFind")
53+
.addDescription("Called whenever an entity tries to pathfind to a location or another entity.")
54+
.addExample("""
55+
on pathfind:
56+
broadcast "%event-entity%'s is about to move to %event-location%!"
57+
""")
58+
.addSince("INSERT VERSION")
59+
.addPattern("[entity] [start[s]] pathfind[ing]")
60+
.addEvent(EntityPathfindEvent.class)
61+
.build());
62+
registry.register(EventValue.builder(EntityPathfindEvent.class, Location.class)
63+
.getter(EntityPathfindEvent::getLoc)
64+
.patterns("target location")
65+
.build());
66+
registry.register(EventValue.builder(EntityPathfindEvent.class, Entity.class)
67+
.getter(EntityPathfindEvent::getTargetEntity)
68+
.patterns("target entity")
69+
.build());
70+
registry.register(EventValue.builder(EntityPathfindEvent.class, Location.class)
71+
.getter(event -> event.getEntity().getLocation())
72+
.build());
73+
register(addon,
74+
ExprPathfindingTarget::register,
75+
ExprPathfindingLocation::register
76+
);
4077
register(addon,
4178
ExprDeathMessage::register
4279
);
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package org.skriptlang.skript.bukkit.entity.elements.expressions;
2+
3+
import ch.njol.skript.doc.Description;
4+
import ch.njol.skript.doc.Events;
5+
import ch.njol.skript.doc.Example;
6+
import ch.njol.skript.doc.Name;
7+
import ch.njol.skript.doc.Since;
8+
import ch.njol.skript.lang.EventRestrictedSyntax;
9+
import ch.njol.skript.lang.Expression;
10+
import ch.njol.skript.lang.SkriptParser.ParseResult;
11+
import ch.njol.skript.lang.util.SimpleExpression;
12+
import ch.njol.util.Kleenean;
13+
import com.destroystokyo.paper.event.entity.EntityPathfindEvent;
14+
import org.bukkit.Location;
15+
import org.bukkit.event.Event;
16+
import org.jetbrains.annotations.Nullable;
17+
import org.skriptlang.skript.registration.SyntaxInfo;
18+
import org.skriptlang.skript.registration.SyntaxRegistry;
19+
20+
@Name("Pathfinding Target")
21+
@Description("The location that the entity is pathfinding towards.")
22+
@Example("""
23+
on pathfind:
24+
if the pathfinding location is {mylocation}:
25+
broadcast "A mob tried to pathfind to a forbidden location!"
26+
cancel event
27+
""")
28+
@Since("INSERT VERSION")
29+
@Events("pathfind")
30+
public class ExprPathfindingLocation extends SimpleExpression<Location> implements EventRestrictedSyntax {
31+
32+
public static void register(SyntaxRegistry syntaxRegistry) {
33+
syntaxRegistry.register(SyntaxRegistry.EXPRESSION, SyntaxInfo.Expression.builder(ExprPathfindingLocation.class, Location.class)
34+
.supplier(ExprPathfindingLocation::new)
35+
.priority(SyntaxInfo.SIMPLE)
36+
.addPattern("[the] path[ ]finding location")
37+
.build());
38+
}
39+
40+
@Override
41+
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
42+
return true;
43+
}
44+
45+
@Override
46+
public Class<? extends Event>[] supportedEvents() {
47+
return new Class[]{EntityPathfindEvent.class};
48+
}
49+
50+
@Override
51+
protected Location[] get(Event event) {
52+
if (!(event instanceof EntityPathfindEvent pathfindEvent))
53+
return new Location[0];
54+
Location location = pathfindEvent.getLoc();
55+
return new Location[]{location};
56+
}
57+
58+
@Override
59+
public boolean isSingle() {
60+
return true;
61+
}
62+
63+
@Override
64+
public Class<? extends Location> getReturnType() {
65+
return Location.class;
66+
}
67+
68+
@Override
69+
public String toString(@Nullable Event event, boolean debug) {
70+
return "the pathfinding location";
71+
}
72+
73+
}
74+
75+
76+
77+
78+
79+
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package org.skriptlang.skript.bukkit.entity.elements.expressions;
2+
3+
import ch.njol.skript.doc.Description;
4+
import ch.njol.skript.doc.Events;
5+
import ch.njol.skript.doc.Example;
6+
import ch.njol.skript.doc.Name;
7+
import ch.njol.skript.doc.Since;
8+
import ch.njol.skript.lang.EventRestrictedSyntax;
9+
import ch.njol.skript.lang.Expression;
10+
import ch.njol.skript.lang.SkriptParser.ParseResult;
11+
import ch.njol.skript.lang.util.SimpleExpression;
12+
import ch.njol.util.Kleenean;
13+
import com.destroystokyo.paper.event.entity.EntityPathfindEvent;
14+
import org.bukkit.entity.Entity;
15+
import org.bukkit.event.Event;
16+
import org.jetbrains.annotations.Nullable;
17+
import org.skriptlang.skript.registration.SyntaxInfo;
18+
import org.skriptlang.skript.registration.SyntaxRegistry;
19+
20+
@Name("Pathfinding Target")
21+
@Description("The target entity that another entity is pathfinding towards in a pathfinding event.")
22+
@Example("""
23+
on pathfind:
24+
if the pathfinding target entity is a villager:
25+
broadcast "I suspect a zombie is going towards a villager right now.."
26+
""")
27+
@Since("INSERT VERSION")
28+
@Events("pathfind")
29+
public class ExprPathfindingTarget extends SimpleExpression<Entity> implements EventRestrictedSyntax {
30+
31+
public static void register(SyntaxRegistry syntaxRegistry) {
32+
syntaxRegistry.register(SyntaxRegistry.EXPRESSION, SyntaxInfo.Expression.builder(ExprPathfindingTarget.class, Entity.class)
33+
.supplier(ExprPathfindingTarget::new)
34+
.priority(SyntaxInfo.SIMPLE)
35+
.addPattern("[the] path[ ]finding target [entity]")
36+
.build());
37+
}
38+
39+
@Override
40+
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
41+
return true;
42+
}
43+
44+
@Override
45+
public Class<? extends Event>[] supportedEvents() {
46+
return new Class[]{EntityPathfindEvent.class};
47+
}
48+
49+
@Override
50+
protected Entity[] get(Event event) {
51+
if (!(event instanceof EntityPathfindEvent pathfindEvent))
52+
return new Entity[0];
53+
Entity target = pathfindEvent.getTargetEntity();
54+
return target != null ? new Entity[]{target} : new Entity[0];
55+
}
56+
57+
@Override
58+
public boolean isSingle() {
59+
return true;
60+
}
61+
62+
@Override
63+
public Class<? extends Entity> getReturnType() {
64+
return Entity.class;
65+
}
66+
67+
@Override
68+
public String toString(@Nullable Event event, boolean debug) {
69+
return "the pathfinding target";
70+
}
71+
72+
}
73+
74+
75+
76+
77+

0 commit comments

Comments
 (0)