99import org .bukkit .configuration .serialization .ConfigurationSerializable ;
1010import org .bukkit .configuration .serialization .SerializableAs ;
1111import org .bukkit .util .NumberConversions ;
12+ import org .jetbrains .annotations .ApiStatus ;
1213import org .jetbrains .annotations .NotNull ;
1314import org .jetbrains .annotations .Nullable ;
1415import org .mvplugins .multiverse .external .vavr .control .Try ;
1819import java .util .Map ;
1920import java .util .Objects ;
2021
21- //TODO: This should extend UnloadedWorldLocation, but that class is currently a final class!!!
22+ /**
23+ * Location information with respawn type. See also {@link RespawnLocationType}.
24+ * <br />
25+ * TODO: This should extend UnloadedWorldLocation, but that class is currently a final class!!!
26+ */
2227@ SerializableAs ("RespawnLocation" )
23- public final class RespawnLocation extends Location {
28+ @ ApiStatus .AvailableSince ("5.2" )
29+ public class RespawnLocation extends Location {
2430
2531 private @ Nullable String worldName ;
2632 private @ NotNull RespawnLocationType respawnType = RespawnLocationType .UNKNOWN ;
@@ -66,7 +72,7 @@ public void setWorldName(@Nullable String worldName) {
6672 this .worldName = worldName ;
6773 }
6874
69- public String getWorldName () {
75+ public @ Nullable String getWorldName () {
7076 return worldName ;
7177 }
7278
@@ -160,19 +166,20 @@ public boolean equals(Object obj) {
160166 if (Float .floatToIntBits (this .getYaw ()) != Float .floatToIntBits (other .getYaw ())) {
161167 return false ;
162168 }
163- if (this .respawnType != RespawnLocationType .UNKNOWN && other instanceof RespawnLocation otherRespawnLocation ) {
164- return this .respawnType == otherRespawnLocation .respawnType ;
169+ if (other instanceof RespawnLocation otherRespawnLocation
170+ && this .respawnType != otherRespawnLocation .respawnType ) {
171+ return false ;
165172 }
166173 return true ;
167174 }
168175
169176 @ Override
170177 public int hashCode () {
171178 int hash = 3 ;
172- hash = 19 * hash + worldName .hashCode ();
173- hash = 19 * hash + ( int ) ( Double . doubleToLongBits ( this . getX ()) ^ ( Double .doubleToLongBits (this .getX ()) >>> 32 ));
174- hash = 19 * hash + ( int ) ( Double . doubleToLongBits ( this . getY ()) ^ ( Double .doubleToLongBits (this .getY ()) >>> 32 ));
175- hash = 19 * hash + ( int ) ( Double . doubleToLongBits ( this . getZ ()) ^ ( Double .doubleToLongBits (this .getZ ()) >>> 32 ));
179+ hash = 19 * hash + String . valueOf ( worldName ) .hashCode ();
180+ hash = 19 * hash + Long . hashCode ( Double .doubleToLongBits (this .getX ()));
181+ hash = 19 * hash + Long . hashCode ( Double .doubleToLongBits (this .getY ()));
182+ hash = 19 * hash + Long . hashCode ( Double .doubleToLongBits (this .getZ ()));
176183 hash = 19 * hash + Float .floatToIntBits (this .getPitch ());
177184 hash = 19 * hash + Float .floatToIntBits (this .getYaw ());
178185 hash = 19 * hash + this .respawnType .hashCode ();
@@ -188,9 +195,20 @@ public String toString() {
188195 ",z=" + getZ () +
189196 ",pitch=" + getPitch () +
190197 ",yaw=" + getYaw () +
198+ ",respawnType=" + this .respawnType +
191199 '}' ;
192200 }
193201
202+ /**
203+ * Checks if the respawn location is valid based on the respawn type.
204+ * <br />
205+ * For {@link RespawnLocationType#BED}, checks if the block at the location is a bed block.
206+ * <br />
207+ * For {@link RespawnLocationType#ANCHOR}, checks if the block at the location is a respawn anchor block.
208+ * <br />
209+ * @return true if the respawn location is valid, false otherwise.
210+ */
211+ @ ApiStatus .AvailableSince ("5.2" )
194212 public boolean isValidRespawnLocation () {
195213 World world = getWorld ();
196214 if (world == null ) {
@@ -209,15 +227,47 @@ public boolean isValidRespawnLocation() {
209227 }
210228 }
211229
212- @ NotNull
213- public RespawnLocationType getRespawnType () {
230+ /**
231+ * Gets the respawn location type.
232+ *
233+ * @return the respawn location type
234+ */
235+ @ ApiStatus .AvailableSince ("5.2" )
236+ public @ NotNull RespawnLocationType getRespawnType () {
214237 return respawnType ;
215238 }
216239
240+ /**
241+ * Sets the respawn location type.
242+ *
243+ * @param respawnType the respawn location type
244+ */
245+ @ ApiStatus .AvailableSince ("5.2" )
246+ public void setRespawnType (@ NotNull RespawnLocationType respawnType ) {
247+ this .respawnType = respawnType ;
248+ }
249+
250+ /**
251+ * The type of respawn location.
252+ */
253+ @ ApiStatus .AvailableSince ("5.2" )
217254 public enum RespawnLocationType {
218- WORLD_SPAWN ,
255+ /**
256+ * The respawn location is a bed, and the location should have a bed block.
257+ */
258+ @ ApiStatus .AvailableSince ("5.2" )
219259 BED ,
260+
261+ /**
262+ * The respawn location is a respawn anchor, and the location should have a respawn anchor block.
263+ */
264+ @ ApiStatus .AvailableSince ("5.2" )
220265 ANCHOR ,
266+
267+ /**
268+ * All other possible respawn types, such as custom /spawnpoint or specific location set by other plugins.
269+ */
270+ @ ApiStatus .AvailableSince ("5.2" )
221271 UNKNOWN
222272 }
223273}
0 commit comments