Jump to content

Is there a way to get the path to the current worlds folder?


4pwnda

Recommended Posts

Haha I had the exact same problem just this morning :) I figured it out though, so don't worry.

 

Explanation via words:

First, you're going to need to get the server instance from ModLoader ( ModLoader.getMinecraftServerInstance() ). Then, you're going to need to get the folder name of the server instance ( .getFolderName() ). Store that for later. Next, get the ISaveFormat from the server instance ( .getActiveAnvilConverter() ). After that, obtain the SaveHandler from the ISaveFormat and give it the folder name we stored earlier as well as a boolean as to whether or not to mkdirs for the player folder (I just use false) ( .getSaveLoader(folderName, false) ). Then, just get the saveDirectory from the SaveHandler ( .getSaveDirectory() ).

 

Explanation via code:

MinecraftServer mcServerInstance = ModLoader.getMinecraftServerInstance();
String folderName = mcServerInstance.getFolderName();
ISaveFormat saveFormat = mcServerInstance.getActiveAnvilConverter();
SaveHandler saveHandler = (SaveHandler)saveFormat.getSaveLoader(folderName, false); // You will have to typecast here
File saveDir = saveHandler.getSaveDirectory();

 

Hope this helps! Ask any questions if you have them and I'll try to answer them.

Link to comment
Share on other sites

Haha I had the exact same problem just this morning :) I figured it out though, so don't worry.

 

Explanation via words:

First, you're going to need to get the server instance from ModLoader ( ModLoader.getMinecraftServerInstance() ). Then, you're going to need to get the folder name of the server instance ( .getFolderName() ). Store that for later. Next, get the ISaveFormat from the server instance ( .getActiveAnvilConverter() ). After that, obtain the SaveHandler from the ISaveFormat and give it the folder name we stored earlier as well as a boolean as to whether or not to mkdirs for the player folder (I just use false) ( .getSaveLoader(folderName, false) ). Then, just get the saveDirectory from the SaveHandler ( .getSaveDirectory() ).

 

Explanation via code:

MinecraftServer mcServerInstance = ModLoader.getMinecraftServerInstance();
String folderName = mcServerInstance.getFolderName();
ISaveFormat saveFormat = mcServerInstance.getActiveAnvilConverter();
SaveHandler saveHandler = (SaveHandler)saveFormat.getSaveLoader(folderName, false); // You will have to typecast here
File saveDir = saveHandler.getSaveDirectory();

 

Hope this helps! Ask any questions if you have them and I'll try to answer them.

Thanks a lot for your answer. However I still got an error, and after printing the file path I saw it contained

a folder called MpServer. So I check when that occurs and return null, works so I'm happy.

No 5 row long documentation = account on the help forums

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.