File Manager

Published by Goldorion on Wed, 07/29/2020 - 04:42
Upvotes: 80
Supported MCreator versions
2021.2
Tags / plugin type
Procedures
Plugin forum topic
Icon
About the plugin

File Manager is a plugin adding new procedure blocks allowing you to create and read your files! Adding support for JSON files, it gives you the possibility to create a config file or files to save data for your mod. This plugin has also more usage, but this it to you to find them! :)

File Types

  • JSON
  • TXT (simple file reader/writer)

Important Information

  • This plugin supports Forge 1.15.2, Forge 1.16.5 and Fabric 1.16.5
  • Versions:
    • Version 3.1: You need to use on the full release of the 2021.1.
    • Version 4.0: You need to use MCreator EAP 2021.2.26215.

Credits/License

Icon by Tobi-Wan#0482

Licensed under the GNU Lesser General Public License, version 2.1  

  • Appropriate credit must be provided to the creators and maintainers of this plugin.
  • Forked versions of this plugin must be distributed under the same license as this with attribution if distributed.
  • Changes must be stated if any modified works are to be distributed.
  • Under no circumstances you can state that modified works are endorsed by the original creator.

Changelog

To see a complete changelog of the plugin, check this file.

4.0.2

Note: The ZIP file has been updated to the right version. Sorry for the mistake.

* [Bugfix #16] Write txt file and Write line procedure blocks didn't generate their code

4.0.1

* [Bugfix #9] Writing to global files resulted in a build error

Thank you @sperly for the bug fix!

4.0

**This update will cause build errors in your workspace. You now have to use a variable as usually.**
* Updated to MCreator 2021.2.26215
* Changed a bit the block color
* Added a new `File` variable
  * Local and Global session
* Updated procedure blocks to use the new variable type
  * Use the getter block to use your `File` variable
  * Current procedures need to be updated to use this new system. 
    Build errors will appear the first time you open your workspace.
* Added a new logic procedure block: Does file exists

3.1

* Updated to MCreator 2021.1.16710
* Updated to Forge & Fabric 1.16.5
* Removed support for Forge 1.14.4
* Added a new block to create sub JSON objects
* Updated current JSON property getters to read sub JSON objects
* JSON related blocks now require a JSON object variable name
* [Bugfix] Get game directory could not be used on Forge servers
 // The block still does not with Fabric servers

 

Project members
Lead developer
License
GNU Lesser General Public License version 2.1 (LGPLv2.1)
Plugin downloads

Comments

I ran into the same issue and couldn't find any way to set the variable so that the file not found message would go away. I used a variable for the filename (in the example above and my use case). Details are in Issue-11 on Github. In short, I got the logic to read/write working be editing the code to explicitly set myFile variable in java: File myFile = new File("serverconfig.json");

Once I had that done first, then everything worked fine after that. I tried using a global variable to set the value but there wasn't any option in File Manager to use an element that allows setting of a variable's value.

Hello
im only able to create files with File Manager but if i try write things in the files i get a silent error with
https://pastebin.com/reAnj4Hb

If i do it like your example picture in the plugin description it wont work.
if i remove the write part it works.
it wont generate or change the code of the class with the write parts.

Already tested the latest build of file manager and one version lower too and also installed all snapshots of mcreator for 1.16.5 to test it with all versions.
Also builded the file manager with gradle on my own to test if uploaded version is maybe broken but nothing help.

Same error everytime.

What im doing wrong xD

since I cannot add screenshots here, take a look at the git hub issues report: https://github.com/Goldorion/File-Manager-MCreator/issues/11 where I provided screenshots and what was done to get it working. Yes, working on latest update as well :-)
-Steve

Okayy,
But im pretty sure there's still no option to check which file doesn't exist (that if condition). It'd be good add it cause right now this condition is pretty useless (before creating file)

Yes that is the case. There isn't a SET option for FileManager variables so the only way I found was to unlock the code for the procedure and update: File myFile = new File("serverbasicsconfig.json");
with the actual name. This sets the filename before checking if it exists or not. Not ideal, but a workaround for now. Just have to check it in/out again when making changes to that procedure which is a pain initially.

Okay, we are wrong tho. There is a block to set file variable, just it's name is kinda misleading.

This block is "Create the file with name located at directory".

It creates a variable File and puts the directory into it.

When u used read blocks in procedure it checks if file exists in the directory and if it doesn't exist, it creates it. If it exists it does nothing, you have full access to info inside it.

When i try to use the Write text in the file block it makes a folder instead. Is this intended?

I can't have this working. Anything I do (I also copy your tutorial) my config file is not created
Im using Mcreator 2021.2 - forge 1.16.5

Could you create one with a read json file? The two examples for writing the file look great, but that assumes the file is already present. There is a [Set Local: configFile to _____] element (purple), but no way to attach the text of the filename. I cannot find any element that can be used to set the file name to read the json file (or check if the file exists) without locking the code and manually updating File file = new File("configfile.json);
Thanks!!

Hey,
I think there's an mistake in File.mkdirs(); method.
File object is a directory and not a file.
As the result of this program creates a folder named file.json instead of file with json expansion xdd.

You can change it to something like:
File file = new File(filePath);
file.getParentFile().mkdirs();

Sorry, my small mistake.
Yes, file variable is file or directory.

But mkdirs() method is only directory so when you want to create file AND new folder hierarchy to it, it creates a folder instead of the file. In that situation it is a mistake, but you just have to add .getParentFile() before .mkdirs() to fix it.

I just read javadoc to be sure >:3.