11package org .mvplugins .multiverse .core .world ;
22
33import java .io .File ;
4+ import java .lang .reflect .Method ;
45import java .util .ArrayList ;
56import java .util .Arrays ;
67import java .util .Collection ;
4546import org .mvplugins .multiverse .core .permissions .CorePermissions ;
4647import org .mvplugins .multiverse .core .teleportation .BlockSafety ;
4748import org .mvplugins .multiverse .core .teleportation .LocationManipulation ;
49+ import org .mvplugins .multiverse .core .utils .ReflectHelper ;
4850import org .mvplugins .multiverse .core .utils .ServerProperties ;
4951import org .mvplugins .multiverse .core .utils .result .Attempt ;
5052import org .mvplugins .multiverse .core .utils .result .FailureReason ;
@@ -688,7 +690,7 @@ private Attempt<CloneWorldOptions, CloneFailureReason> cloneWorldValidateWorld(
688690 private Attempt <CloneWorldOptions , CloneFailureReason > cloneWorldCopyFolder (@ NotNull CloneWorldOptions options ) {
689691 if (options .saveBukkitWorld ()) {
690692 Logging .finer ("Saving bukkit world before cloning: " + options .world ().getName ());
691- options .world ().getBukkitWorld ().peek (World :: save );
693+ options .world ().getBukkitWorld ().peek (this :: saveWorldWithFlush );
692694 }
693695 File worldFolder = options .world ().getBukkitWorld ().map (World ::getWorldFolder ).get ();
694696 File newWorldFolder = new File (Bukkit .getWorldContainer (), options .newWorldName ());
@@ -698,6 +700,17 @@ private Attempt<CloneWorldOptions, CloneFailureReason> cloneWorldCopyFolder(@Not
698700 success -> worldActionResult (options ));
699701 }
700702
703+ // This method is only available since 1.21
704+ private final Method saveWithFlush = ReflectHelper .getMethod (World .class , "save" , boolean .class );
705+ private void saveWorldWithFlush (World world ) {
706+ if (saveWithFlush != null ) {
707+ Logging .fine ("Using world save method with flush..." );
708+ ReflectHelper .invokeMethod (world , saveWithFlush , true );
709+ } else {
710+ world .save ();
711+ }
712+ }
713+
701714 private void cloneWorldTransferData (@ NotNull CloneWorldOptions options , @ NotNull LoadedMultiverseWorld newWorld ) {
702715 DataTransfer <LoadedMultiverseWorld > dataTransfer = transferData (options , options .world ());
703716 dataTransfer .pasteAllTo (newWorld );
0 commit comments