|
| 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