@@ -321,7 +321,8 @@ public Plot(
321321 }
322322
323323 /**
324- * Get the plot from a string.
324+ * Get the plot from a string. Performs a check to ensure Plot#getBottomAbs is not outside world bounds
325+ * (x/z +/- 30,000,000) to prevent crashes
325326 *
326327 * @param player Provides a context for what world to search in. Prefixing the term with 'world_name;' will override this context.
327328 * @param arg The search term
@@ -332,6 +333,31 @@ public Plot(
332333 final @ Nullable PlotPlayer <?> player ,
333334 final @ Nullable String arg ,
334335 final boolean message
336+ ) {
337+ Plot plot = getPlotFromStringUnchecked (player , arg , message );
338+ if (plot != null && !WorldUtil .isValidLocation (plot .getBottomAbs ())) {
339+ if (message ) {
340+ (player == null ? ConsolePlayer .getConsole () : player ).sendMessage (TranslatableCaption .of (
341+ "invalid.world_location_plot" ));
342+ }
343+ return null ;
344+ }
345+ return plot ;
346+ }
347+
348+ /**
349+ * Get the plot from a string. Does not perform a check on world bounds.
350+ *
351+ * @param player Provides a context for what world to search in. Prefixing the term with 'world_name;' will override this context.
352+ * @param arg The search term
353+ * @param message If a message should be sent to the player if a plot cannot be found
354+ * @return The plot if only 1 result is found, or null
355+ * @since TODO
356+ */
357+ public static @ Nullable Plot getPlotFromStringUnchecked (
358+ final @ Nullable PlotPlayer <?> player ,
359+ final @ Nullable String arg ,
360+ final boolean message
335361 ) {
336362 if (arg == null ) {
337363 if (player == null ) {
@@ -389,13 +415,51 @@ public Plot(
389415 }
390416
391417 /**
392- * Gets a plot from a string e.g. [area];[id]
418+ * Gets a plot from a string e.g. [area];[id]. Performs a check to ensure Plot#getBottomAbs is not outside world bounds
419+ * (x/z +/- 30,000,000) to prevent crashes
393420 *
394421 * @param defaultArea if no area is specified
395422 * @param string plot id/area + id
396423 * @return New or existing plot object
397424 */
398425 public static @ Nullable Plot fromString (final @ Nullable PlotArea defaultArea , final @ NonNull String string ) {
426+ return fromString (defaultArea , string , null );
427+ }
428+
429+ /**
430+ * Gets a plot from a string e.g. [area];[id]. Performs a check to ensure Plot#getBottomAbs is not outside world bounds
431+ * (x/z +/- 30,000,000) to prevent crashes
432+ *
433+ * @param defaultArea if no area is specified
434+ * @param string plot id/area + id
435+ * @param player {@link PlotPlayer} player to notify if plot is invalid (outside bounds)
436+ * @return New or existing plot object
437+ * @since TODO
438+ */
439+ public static @ Nullable Plot fromString (
440+ final @ Nullable PlotArea defaultArea ,
441+ final @ NonNull String string ,
442+ final @ Nullable PlotPlayer <?> player
443+ ) {
444+ Plot plot = fromStringUnchecked (defaultArea , string );
445+ if (plot != null && !WorldUtil .isValidLocation (plot .getBottomAbs ())) {
446+ if (player != null ) {
447+ player .sendMessage (TranslatableCaption .of ("invalid.world_location_plot" ));
448+ }
449+ return null ;
450+ }
451+ return plot ;
452+ }
453+
454+ /**
455+ * Gets a plot from a string e.g. [area];[id]. Does not perform a check on world bounds.
456+ *
457+ * @param defaultArea if no area is specified
458+ * @param string plot id/area + id
459+ * @return New or existing plot object
460+ * @since TODO
461+ */
462+ public static @ Nullable Plot fromStringUnchecked (final @ Nullable PlotArea defaultArea , final @ NonNull String string ) {
399463 final String [] split = string .split ("[;,]" );
400464 if (split .length == 2 ) {
401465 if (defaultArea != null ) {
@@ -419,7 +483,8 @@ public Plot(
419483 }
420484
421485 /**
422- * Return a new/cached plot object at a given location.
486+ * Return a new/cached plot object at a given location. Does not check world bounds for potential crashes, these should be
487+ * performed before (or after) this method is used.
423488 *
424489 * <p>
425490 * Use {@link PlotPlayer#getCurrentPlot()} if a player is expected here.
0 commit comments