Skip to content

Commit 84e9182

Browse files
More runtime errors
1 parent 95d790b commit 84e9182

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/main/java/org/skriptlang/skriptworldguard/elements/effects/EffCreateRegion.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import ch.njol.skript.doc.Description;
44
import ch.njol.skript.doc.Example;
55
import ch.njol.skript.doc.Name;
6-
import ch.njol.skript.doc.RequiredPlugins;
76
import ch.njol.skript.doc.Since;
87
import ch.njol.skript.lang.Effect;
98
import ch.njol.skript.lang.Expression;
@@ -38,7 +37,7 @@
3837
" Then, with the provided heights, the shape is extended vertically to form the region." +
3938
" At least three points must be provided to create a polygonal region.",
4039
"Note that if you do not specify the world for a region, you must be sure that the locations provided all have the same world.",
41-
"Note that Region IDs are only valid if they contain letters, numbers, underscores, commas, single quotation marks, dashes, pluses, or forward slashes.",
40+
"Note that Region IDs are only valid if they contain letters, numbers, underscores, commas, single quotation marks, dashes, pluses, and forward slashes.",
4241
"Note that if you attempt to create a region in a world where a region with the same ID already exists, that region will be replaced."
4342
})
4443
@Example("create a temporary global region named \"temporary_global_region\" in the player's world")
@@ -88,7 +87,12 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
8887
@Override
8988
protected void execute(Event event) {
9089
String id = this.id.getSingle(event);
91-
if (id == null || !ProtectedRegion.isValidId(id)) {
90+
if (id == null) {
91+
return;
92+
}
93+
if (!ProtectedRegion.isValidId(id)) {
94+
error("'" + id + "' is an invalid region ID. Region IDs can only contain" +
95+
" letters, numbers, underscores, commas, single quotation marks, dashes, pluses, and forward slashes");
9296
return;
9397
}
9498

@@ -109,6 +113,8 @@ protected void execute(Event event) {
109113
World secondCornerWorld = secondCorner.getWorld();
110114
// We want the locations to have matching worlds
111115
if (firstCornerWorld == null || firstCornerWorld != secondCornerWorld) {
116+
error("A world to create the region in was not specified,"
117+
+ " but the provided corner points have different worlds");
112118
return;
113119
}
114120
world = firstCornerWorld;
@@ -121,7 +127,11 @@ protected void execute(Event event) {
121127
Number minY = this.minY.getSingle(event);
122128
Number maxY = this.maxY.getSingle(event);
123129
Location[] points = this.points.getArray(event);
124-
if (minY == null || maxY == null || points.length < 3) {
130+
if (minY == null || maxY == null || points.length == 0) {
131+
return;
132+
}
133+
if (points.length < 3) {
134+
error("A polygonal region needs at least 3 points, but only " + points.length + " points were provided");
125135
return;
126136
}
127137

@@ -130,6 +140,10 @@ protected void execute(Event event) {
130140
for (Location point : points) { // We want the locations to have matching worlds
131141
World pointWorld = point.getWorld();
132142
if (pointWorld == null || pointWorld != world) {
143+
if (this.world == null) { // only error if the user didn't specify a world
144+
error("A world to create the region in was not specified,"
145+
+ " but the provided points have different worlds");
146+
}
133147
return;
134148
}
135149
}

src/main/java/org/skriptlang/skriptworldguard/elements/events/EvtRegionEnterLeave.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import com.sk89q.worldguard.session.MoveType;
1111
import org.bukkit.Bukkit;
1212
import org.bukkit.World;
13-
import org.bukkit.entity.Player;
1413
import org.bukkit.event.Event;
1514
import org.jetbrains.annotations.Nullable;
1615
import org.skriptlang.skript.bukkit.registration.BukkitRegistryKeys;
@@ -31,7 +30,7 @@ public static void register(SyntaxRegistry registry) {
3130
.addPatterns("region enter[ing]",
3231
"enter[ing] of " + regionPattern,
3332
"region (exit[ing]|leav(e|ing))",
34-
"exit[ing] of " + regionPattern)
33+
"(exit[ing]|leav(e|ing)) of " + regionPattern)
3534
.addDescription("Called when a player enters or leaves a region.")
3635
.addExample("""
3736
on region enter:
@@ -40,7 +39,6 @@ public static void register(SyntaxRegistry registry) {
4039
.addSince("1.0")
4140
.build());
4241
EventValues.registerEventValue(RegionEnterLeaveEvent.class, WorldGuardRegion.class, RegionEnterLeaveEvent::getRegion);
43-
EventValues.registerEventValue(RegionEnterLeaveEvent.class, Player.class, RegionEnterLeaveEvent::getPlayer);
4442
EventValues.registerEventValue(RegionEnterLeaveEvent.class, MoveType.class, RegionEnterLeaveEvent::getMoveType);
4543
}
4644

0 commit comments

Comments
 (0)