11package org .skriptlang .skriptworldguard .worldguard ;
22
3- import ch .njol .skript .lang .util .common .AnyContains ;
4- import ch .njol .skript .lang .util .common .AnyNamed ;
53import com .sk89q .worldedit .bukkit .BukkitAdapter ;
64import com .sk89q .worldedit .math .BlockVector2 ;
75import com .sk89q .worldedit .regions .CuboidRegion ;
1412import org .bukkit .Location ;
1513import org .bukkit .World ;
1614import org .jetbrains .annotations .NotNull ;
17- import org .skriptlang .skript .lang .converter .Converters ;
1815
1916/**
2017 * A utility record for associating a {@link ProtectedRegion} with a {@link World}.
2118 * @param world The world {@code region} is within.
2219 * @param region WorldGuard region.
2320 */
24- public record WorldGuardRegion (World world , ProtectedRegion region )
25- implements Comparable <WorldGuardRegion >, AnyNamed , AnyContains <Object > {
21+ public record WorldGuardRegion (World world , ProtectedRegion region ) implements Comparable <WorldGuardRegion > {
2622
2723 /**
2824 * A helper method to provide a standardized way to stringify a {@link WorldGuardRegion} from its components.
@@ -37,52 +33,31 @@ public static String toString(World world, String id) {
3733
3834 @ Override
3935 public boolean equals (Object other ) {
40- if (other instanceof WorldGuardRegion otherRegion ) {
41- return otherRegion . world () == world && otherRegion . region () .getId ().equals (region .getId ());
36+ if (other instanceof WorldGuardRegion ( World otherWorld , ProtectedRegion otherRegion ) ) {
37+ return world == otherWorld && region .getId ().equals (otherRegion .getId ());
4238 }
4339 return false ;
4440 }
4541
4642 @ Override
47- public String toString () {
43+ public @ NotNull String toString () {
4844 return toString (world , region .getId ());
4945 }
5046
51- /*
52- * Comparable
53- */
54-
55- @ Override
56- public int compareTo (@ NotNull WorldGuardRegion other ) {
57- return Integer .compare (this .region .getPriority (), other .region .getPriority ());
58- }
59-
60- /*
61- * AnyNamed
47+ /**
48+ * @return The name (ID) of this region.
6249 */
63-
64- @ Override
6550 public String name () {
6651 return region .getId ();
6752 }
6853
6954 /*
70- * AnyContains
55+ * Comparable
7156 */
7257
7358 @ Override
74- public boolean contains (Object object ) {
75- if (object instanceof Chunk chunk ) {
76- BlockVector2 chunkVector = BlockVector2 .at (chunk .getX (), chunk .getZ ());
77- return asWorldEditRegion ().getChunks ().contains (chunkVector );
78- }
79- Location location = Converters .convert (object , Location .class );
80- return location != null && region .contains (BukkitAdapter .asBlockVector (location ));
81- }
82-
83- @ Override
84- public boolean isSafeToCheck (Object value ) {
85- return value != null ;
59+ public int compareTo (@ NotNull WorldGuardRegion other ) {
60+ return Integer .compare (this .region .getPriority (), other .region .getPriority ());
8661 }
8762
8863 /*
@@ -108,4 +83,21 @@ public Region asWorldEditRegion() {
10883 return worldEditRegion ;
10984 }
11085
86+ /**
87+ * @param chunk The chunk to check for.
88+ * @return Whether {@code chunk} is within this region.
89+ */
90+ public boolean contains (Chunk chunk ) {
91+ BlockVector2 chunkVector = BlockVector2 .at (chunk .getX (), chunk .getZ ());
92+ return asWorldEditRegion ().getChunks ().contains (chunkVector );
93+ }
94+
95+ /**
96+ * @param location The location to check for.
97+ * @return Whether {@code location} is within this region.
98+ */
99+ public boolean contains (Location location ) {
100+ return region .contains (BukkitAdapter .asBlockVector (location ));
101+ }
102+
111103}
0 commit comments