Skip to content

Commit 57720b3

Browse files
Add region property conditions
1 parent d49a572 commit 57720b3

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package org.skriptlang.skriptworldguard.elements.conditions;
2+
3+
import ch.njol.skript.conditions.base.PropertyCondition;
4+
import ch.njol.skript.doc.Description;
5+
import ch.njol.skript.doc.Example;
6+
import ch.njol.skript.doc.Name;
7+
import ch.njol.skript.doc.Since;
8+
import org.skriptlang.skript.registration.SyntaxRegistry;
9+
import org.skriptlang.skriptworldguard.worldguard.WorldGuardRegion;
10+
11+
@Name("Is Region Temporary")
12+
@Description({
13+
"A condition to test whether a region is temporary.",
14+
"Temporary regions are those that are removed when the server restarts."
15+
})
16+
@Example("""
17+
on region enter:
18+
if the region is temporary:
19+
message "Be ready! This protected region will expire when the server restarts."
20+
""")
21+
@Since("1.0")
22+
public class CondIsRegionTemporary extends PropertyCondition<WorldGuardRegion> {
23+
24+
public static void register(SyntaxRegistry registry) {
25+
register(registry, CondIsRegionTemporary.class, "(temporary|transient)", "worldguardregions");
26+
}
27+
28+
@Override
29+
public boolean check(WorldGuardRegion region) {
30+
return region.region().isTransient();
31+
}
32+
33+
@Override
34+
protected String getPropertyName() {
35+
return "temporary";
36+
}
37+
38+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package org.skriptlang.skriptworldguard.elements.conditions;
2+
3+
import ch.njol.skript.conditions.base.PropertyCondition;
4+
import ch.njol.skript.doc.Description;
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.Expression;
9+
import ch.njol.skript.lang.SkriptParser.ParseResult;
10+
import ch.njol.util.Kleenean;
11+
import com.sk89q.worldguard.protection.regions.RegionType;
12+
import org.skriptlang.skript.registration.SyntaxRegistry;
13+
import org.skriptlang.skriptworldguard.worldguard.WorldGuardRegion;
14+
15+
import java.util.Locale;
16+
17+
@Name("Is Region Type")
18+
@Description("A condition to test what type/shape a region is.")
19+
@Example("""
20+
on region enter:
21+
if the region is polygonal:
22+
message "Welcome to my wacky region!"
23+
""")
24+
@Since("1.0")
25+
public class CondIsRegionType extends PropertyCondition<WorldGuardRegion> {
26+
27+
public static void register(SyntaxRegistry registry) {
28+
register(registry, CondIsRegionType.class, "[a] (:global|:cuboid[s]|:polygon[s|al]) [region[s]]", "worldguardregions");
29+
}
30+
31+
private RegionType regionType;
32+
33+
@Override
34+
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
35+
regionType = RegionType.valueOf(parseResult.tags.get(0).toUpperCase(Locale.ENGLISH));
36+
return super.init(expressions, matchedPattern, isDelayed, parseResult);
37+
}
38+
39+
@Override
40+
public boolean check(WorldGuardRegion region) {
41+
return region.region().getType() == regionType;
42+
}
43+
44+
@Override
45+
protected String getPropertyName() {
46+
return switch (regionType) {
47+
case CUBOID -> "cuboid";
48+
case POLYGON -> "polygonal";
49+
case GLOBAL -> "global";
50+
};
51+
}
52+
53+
}

0 commit comments

Comments
 (0)