creating new worlds?

Discussion in 'Plugin Development' started by bkleinman1, Sep 12, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    bkleinman1

    Is there some way to make it so if a player does a command, it will, duplicate an existing world and teleport them to the new one?

    PS. please dont post if there is a way to do this using another plugin i would like to know how/if this is possible. thanks!
     
  2. have you tried the multi-verse API?

    you would need to use it in some shape or form by the way :)

    if you could copy the folder of the world and everything in it with a name called lets say world2, you would then use multi-verse's API to import the world and teleport to that world. unless multi-verse allows copying of worlds using it's API I'm not sure.
     
  3. Offline

    bkleinman1

    teozfrank ok thanks, do you know where i can find the java docs?
     
  4. im pretty sure you can with Java IO classes,

    take a look at this -->
    Code:java
    1. import java.io.File;
    2.  
    3. import java.io.FileInputStream;
    4.  
    5. import java.io.FileOutputStream;
    6.  
    7. import java.io.IOException;
    8.  
    9. import java.nio.channels.FileChannel;
    10.  
    11.  
    12.  
    13. public class FileUtilities {
    14.  
    15.  
    16.  
    17. private FileUtilities() {}
    18.  
    19.  
    20.  
    21. public static final void copy( File source, File destination ) throws IOException {
    22.  
    23. if( source.isDirectory() ) {
    24.  
    25. copyDirectory( source, destination );
    26.  
    27. } else {
    28.  
    29. copyFile( source, destination );
    30.  
    31. }
    32.  
    33. }
    34.  
    35.  
    36.  
    37. public static final void copyDirectory( File source, File destination ) throws IOException {
    38.  
    39. if( !source.isDirectory() ) {
    40.  
    41. throw new IllegalArgumentException( "Source (" + source.getPath() + ") must be a directory." );
    42.  
    43. }
    44.  
    45.  
    46.  
    47. if( !source.exists() ) {
    48.  
    49. throw new IllegalArgumentException( "Source directory (" + source.getPath() + ") doesn't exist." );
    50.  
    51. }
    52.  
    53.  
    54.  
    55. if( destination.exists() ) {
    56.  
    57. throw new IllegalArgumentException( "Destination (" + destination.getPath() + ") exists." );
    58.  
    59. }
    60.  
    61.  
    62.  
    63. destination.mkdirs();
    64.  
    65. File[] files = source.listFiles();
    66.  
    67.  
    68.  
    69. for( File file : files ) {
    70.  
    71. if( file.isDirectory() ) {
    72.  
    73. copyDirectory( file, new File( destination, file.getName() ) );
    74.  
    75. } else {
    76.  
    77. copyFile( file, new File( destination, file.getName() ) );
    78.  
    79. }
    80.  
    81. }
    82.  
    83. }
    84.  
    85.  
    86.  
    87. public static final void copyFile( File source, File destination ) throws IOException {
    88.  
    89. FileChannel sourceChannel = new FileInputStream( source ).getChannel();
    90.  
    91. FileChannel targetChannel = new FileOutputStream( destination ).getChannel();
    92.  
    93. sourceChannel.transferTo(0, sourceChannel.size(), targetChannel);
    94.  
    95. sourceChannel.close();
    96.  
    97. targetChannel.close();
    98.  
    99. }
    100.  
    101. }



    or you could take a look at apache's fileUtil (google it)

    i would check out multiverse's API first tho, but it seems the link to the java doc is down :/ unless you can find another link.
     
  5. Offline

    bkleinman1

    what will that do?

    @teozfrank would it just copy a folder?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  6. using the copy directory method should copy the whole folder to another location, i don't know how this comes to play in a plugin, it could be the complete wrong way of approaching it, I'm just thinking out loud.
     
Thread Status:
Not open for further replies.

Share This Page