@@ -388,6 +388,17 @@ default WorldArchetype worldArchetype() {
388388
389389 /**
390390 * Customize the load process of a {@link ServerWorldProperties}.
391+ *
392+ * <p>Each {@link LoadOptions load options} can define
393+ * multiple operations at once that will be exhausted
394+ * until one of them succeeds.</p>
395+ *
396+ * <p>The operations will be consumed in the following order:</p>
397+ * <ul>
398+ * <li>Get</li>
399+ * <li>Load</li>
400+ * <li>Create</li>
401+ * </ul>
391402 */
392403 interface LoadOptions {
393404
@@ -459,6 +470,7 @@ static LoadOptions get() {
459470 static LoadOptions get (Consumer <ServerWorldProperties > getCallback ) {
460471 return LoadOptions .builder ()
461472 .get ()
473+ .getCallback (getCallback )
462474 .build ();
463475 }
464476
@@ -500,126 +512,6 @@ static LoadOptions getOrLoad(Consumer<ServerWorldProperties> getCallback, Consum
500512 .build ();
501513 }
502514
503- /**
504- * Load a new {@link ServerWorldProperties} from disk
505- * or create a new one with the provided {@link WorldArchetype}.
506- * Do not attempt to use the already loaded instance.
507- *
508- * <p>This operation fails if properties were already loaded.</p>
509- *
510- * @param worldArchetype The archetype to use for creation.
511- * @return The load options.
512- */
513- static LoadOptions loadOrCreate (WorldArchetype worldArchetype ) {
514- return LoadOptions .builder ()
515- .load ()
516- .create (worldArchetype )
517- .build ();
518- }
519-
520- /**
521- * Load a new {@link ServerWorldProperties} from disk
522- * or create a new one with the provided {@link WorldArchetype}.
523- * Do not attempt to use the already loaded instance.
524- *
525- * <p>This operation fails if properties were already loaded.</p>
526- *
527- * @param worldArchetype The archetype to use for creation.
528- * @param createCallback The consumer to call after successful
529- * creation for additional configuration.
530- * @return The load options.
531- */
532- static LoadOptions loadOrCreate (WorldArchetype worldArchetype , Consumer <ServerWorldProperties > createCallback ) {
533- return LoadOptions .builder ()
534- .load ()
535- .create (worldArchetype )
536- .createCallback (createCallback )
537- .build ();
538- }
539-
540- /**
541- * Load a new {@link ServerWorldProperties} from disk
542- * or create a new one with the provided {@link WorldArchetype}.
543- * Do not attempt to use the already loaded instance.
544- *
545- * <p>This operation fails if properties were already loaded.</p>
546- *
547- * @param loadCallback The consumer to call after successful
548- * load operation for additional configuration.
549- * @param worldArchetype The archetype to use for creation.
550- * @param createCallback The consumer to call after successful
551- * creation for additional configuration.
552- * @return The load options.
553- */
554- static LoadOptions loadOrCreate (Consumer <ServerWorldProperties > loadCallback , WorldArchetype worldArchetype , Consumer <ServerWorldProperties > createCallback ) {
555- return LoadOptions .builder ()
556- .load ()
557- .loadCallback (loadCallback )
558- .create (worldArchetype )
559- .createCallback (createCallback )
560- .build ();
561- }
562-
563- /**
564- * Get the already loaded {@link ServerWorldProperties} or
565- * attempt to load it from disk. If not found, create a new one
566- * with the provided {@link WorldArchetype}.
567- *
568- * @param worldArchetype The archetype to use for creation.
569- * @return The load options.
570- */
571- static LoadOptions getLoadOrCreate (WorldArchetype worldArchetype ) {
572- return LoadOptions .builder ()
573- .get ()
574- .load ()
575- .create (worldArchetype )
576- .build ();
577- }
578-
579- /**
580- * Get the already loaded {@link ServerWorldProperties} or
581- * attempt to load it from disk. If not found, create a new one
582- * with the provided {@link WorldArchetype}.
583- *
584- * @param worldArchetype The archetype to use for creation.
585- * @param createCallback The consumer to call after successful
586- * creation for additional configuration.
587- * @return The load options.
588- */
589- static LoadOptions getLoadOrCreate (WorldArchetype worldArchetype , Consumer <ServerWorldProperties > createCallback ) {
590- return LoadOptions .builder ()
591- .get ()
592- .load ()
593- .create (worldArchetype )
594- .createCallback (createCallback )
595- .build ();
596- }
597-
598- /**
599- * Get the already loaded {@link ServerWorldProperties} or
600- * attempt to load it from disk. If not found, create a new one
601- * with the provided {@link WorldArchetype}.
602- *
603- * @param getCallback The consumer to call after successful
604- * get operation for additional configuration.
605- * @param loadCallback The consumer to call after successful
606- * load operation for additional configuration.
607- * @param worldArchetype The archetype to use for creation.
608- * @param createCallback The consumer to call after successful
609- * creation for additional configuration.
610- * @return The load options.
611- */
612- static LoadOptions getLoadOrCreate (Consumer <ServerWorldProperties > getCallback , Consumer <ServerWorldProperties > loadCallback , WorldArchetype worldArchetype , Consumer <ServerWorldProperties > createCallback ) {
613- return LoadOptions .builder ()
614- .get ()
615- .getCallback (getCallback )
616- .load ()
617- .loadCallback (loadCallback )
618- .create (worldArchetype )
619- .createCallback (createCallback )
620- .build ();
621- }
622-
623515 /**
624516 * Create a new {@link ServerWorldProperties} with the given
625517 * {@link WorldArchetype} but do not attempt to load
@@ -689,6 +581,10 @@ interface GetOperation {
689581
690582 interface LoadOperation {
691583
584+ Optional <WorldArchetype > overrideWorldArchetype ();
585+
586+ Optional <WorldArchetype > fallbackWorldArchetype ();
587+
692588 Optional <Consumer <ServerWorldProperties >> loadCallback ();
693589 }
694590
@@ -699,12 +595,37 @@ interface CreateOperation {
699595 Optional <Consumer <ServerWorldProperties >> createCallback ();
700596 }
701597
598+ /**
599+ * A builder to create {@link LoadOptions}.
600+ */
702601 interface Builder extends org .spongepowered .api .util .Builder <LoadOptions , Builder > {
703602
603+ /**
604+ * Appends a get operation to this option
605+ * which will attempt to find an already
606+ * loaded instance.
607+ *
608+ * @return This builder, for chaining
609+ */
704610 Builder .GetStep get ();
705611
612+ /**
613+ * Appends a load operation to this option
614+ * which will attempt to load an existing
615+ * world from the disk.
616+ *
617+ * @return This builder, for chaining
618+ */
706619 Builder .LoadStep load ();
707620
621+ /**
622+ * Appends a create operation to this option
623+ * which will attempt to create a new world
624+ * with the given {@link WorldArchetype}.
625+ *
626+ * @param worldArchetype The archetype to use for world creation
627+ * @return This builder, for chaining
628+ */
708629 Builder .CreateStep create (WorldArchetype worldArchetype );
709630
710631 interface GetStep extends Builder {
@@ -714,6 +635,32 @@ interface GetStep extends Builder {
714635
715636 interface LoadStep extends Builder {
716637
638+ /**
639+ * Sets the {@link WorldArchetype} to use instead of the
640+ * one that was persisted on the disk.
641+ *
642+ * <p><strong>Note:</strong> This may impact world generation,
643+ * causing new terrain to not blend seamlessly with existing terrain.
644+ * Additionally, the world will be saved with the new {@link WorldArchetype}.</p>
645+ *
646+ * @param worldArchetype The new archetype
647+ * @return This builder, for chaining
648+ */
649+ LoadStep overrideWorldArchetype (WorldArchetype worldArchetype );
650+
651+ /**
652+ * Sets the {@link WorldArchetype} that will be used as fallback
653+ * in case no valid archetype could be determined.
654+ *
655+ * <p><strong>Note:</strong> This may impact world generation,
656+ * causing new terrain to not blend seamlessly with existing terrain.
657+ * Additionally, the world will be saved with the new {@link WorldArchetype}.</p>
658+ *
659+ * @param worldArchetype The archetype to use as fallback
660+ * @return This builder, for chaining
661+ */
662+ LoadStep fallbackWorldArchetype (WorldArchetype worldArchetype );
663+
717664 LoadStep loadCallback (Consumer <ServerWorldProperties > loadCallback );
718665 }
719666
0 commit comments